wxMaxThe title of this article says it all. I’m currently working on the next ‘iteration’ of Gunstyle with a fellow developer and over the past weekend we were in need of a GUI library to help develop our map editor. In the past maxGUI ‘worked’ more or less….emphasis on the less. The design of maxGUI left me with a bad taste in my mouth. It’s a procedural library that is cobbled together with some weak OO on top that didn’t provide much flexibility (not to mention it wasn’t exactly ‘native’ UI on different platforms). Either way, it was a good library for small projects and prototypes.

Now we’re working on something of a little bit bigger in scale, and needing a more heavy duty gui library to go with it. So we chose Brucey’s wxMax GUI Module for Blitzmax. Just picking it up over the weekend has been a joy to work with. It’s object-oriented from the get go so it’s a bit easier to integrate into already established OO code.  It also boasts being cross-platform (Win/Linux/Mac), but I’ve yet to test or need this functionality yet. It’s also wrapping a rather solid and established library, wxWidgets.

One of the main requirements was for us to develop a GUI around a game framework that would allow us to switch in and out of an editor on the fly. To test this type of functionality I whipped up a basic test file that switches from the standard Blitzmax graphics window to a wxMax GUI with a GLCanvas and back again several times. Below is the actual source for doing that type of switching, in case anyone wants to do something similar:

[blitzmax2]
SuperStrict

Framework wx.wxApp
Import brl.glmax2d
Import brl.standardio
Import wx.wxFrame
Import wx.wxPanel
Import wx.wxGLCanvas
Import wx.wxglmax2d
Import brl.max2d
Import wx.wxTimer
Import brl.pngloader

Global app:TestApp = New TestApp
Global imgTest:TImage
Global imgPath:String = “myTestImage.png”

SetGraphicsDriver(brl.GLMax2D.GLMax2DDriver()) ‘ needed in order for the normal gfx driver to run
SetGraphics(Graphics(800, 600)) ‘ set context back to main window

‘ test switching between max2D and wxMax
‘ while loading an image that is shared between the two modes
If FileType(imgPath) = 0 Then
Notify “invalid path for image. file does not exist”
EndGraphics()
End
End If

imgTest = LoadImage(imgPath)
SetBlend(ALPHABLEND)

RunBmaxGraphics()
app.Run()
RunBmaxGraphics()
app.Run()

Function RunBmaxGraphics()
SetGraphicsDriver(brl.GLMax2D.GLMax2DDriver()) ‘ needed in order for the normal gfx driver to run
SetGraphics(Graphics(800, 600)) ‘ set context back to main window
While Not(KeyHit(KEY_ESCAPE))
Cls
If KeyHit(KEY_D) Then
Exit
End If
DrawImage(imgTest, 100, 100)
Flip
WEnd
EndGraphics()
End Function

Type TestApp Extends wxApp
Field frame:wxFrame
Field panel:wxPanel
Field canvas:TMax2DCanvas

Method OnInit:Int()
frame = New wxFrame.Create(,, “Test”, 0, 0, 1024, 768)
frame.Center()

panel = New wxPanel.Create(frame, wxID_ANY, 160, 0, 1024, 768)
canvas = TMax2DCanvas(New TMax2DCanvas.Create(panel, wxID_ANY, GRAPHICS_BACKBUFFER | GRAPHICS_DEPTHBUFFER, 0, 0, 1024, 768))

frame.Show()

Return True
End Method

End Type

Type GLFrame Extends wxFrame
Field canvas:TMax2DCanvas

Method OnInit()
canvas = TMax2DCanvas(New TMax2DCanvas.Create(Self, -1, GRAPHICS_BACKBUFFER | GRAPHICS_DEPTHBUFFER))
ConnectAny(wxEVT_CLOSE, OnClose)

End Method

Function OnClose(event:wxEvent)
GLFrame(event.parent).canvas.timer.Stop()
event.Skip()

End Function
End Type

Type TMax2DCanvas Extends wxGLCanvas
Field timer:wxTimer

Method OnInit()
SetBackgroundStyle(wxBG_STYLE_CUSTOM)
timer = New wxTimer.Create(Self)
wx.wxglmax2d.GLMax2DDriver().SetBlend(ALPHABLEND)
timer.Start(100)
ConnectAny(wxEVT_TIMER, OnTick)
End Method

Method OnPaint(event:wxPaintEvent)
Render()
End Method

Method Render()
SetGraphics CanvasGraphics2D(Self)

Cls
DrawImage(imgTest, 100, 100)
Flip

End Method
Function OnTick(event:wxEvent)
wxWindow(event.parent).Refresh()
End Function
End Type
[/blitzmax2]

The main benefit of the above setup is seen in the switching between ‘RunBmaxGraphics()‘ and ‘app.run()‘. I can switch from my normal game logic, to an editor logic, but still use the same rendering routines! Now I’m not 100% positive that resources such as TImage will persist after a graphics change (in my case they do, but I don’t think that’s universal) so you may be required to reload textures.

I’ve been working on a few projects that require blitzmax and a web-server (php/mysql) to communicate. Along came the need to hash files. This code archive entry was very useful :). I decided to wrap it into  an object and add a new method to it. Even though it’s a series of functions I still tend to make types with functions in them to help me organize them (it’s like a cheap way of  namespacing). I needed the ability to hash a file using Sha-1 hashing. Seeing that php has a function called sha1_file($pathToFile) I figured I’d implement the equivalent on blitzmax. With this THasher type, I’ve added a SHA1_File(path) function also.

Why hash files?

There are many reasons to use hashes, but recently I used it to check for file changes. If you’ve ever wanted to find out if some arbitrary file has ‘changed’ since the last time you’ve opened it this can prove to be useful. If you save the hash beforehand then recompute the hash now and if they are different, then something’s changed! Some applications of this are:

  • Write a file-updater to quickly find out which new files need to be downloaded. Just comparing hashes would be sufficient in most cases, instead of having to go individually byte-by-byte or traversing the file structure to find a difference.
  • help stop cheating. If you don’t want users changing texture files to gain an advantage or don’t want them ‘mucking’ with any other data file. If you check the current hash against a previously approved one and it doesn’t check out then the file has more than likely been tampered with.

How Do I Use THasher?

If you want to hash a string using SHA-1 then:

[blitzmax2]
Local hashedFoo:String = THasher.sha1(“Foo”)
[/blitzmax2]

Want to hash a whole file? Then:

[blitzmax2]
Local filehash:String = THasher.SHA1_File(“someFile.txt”)
[/blitzmax2]
Keep in mind you can hash any file, not just text files like in the above example.

Anyway, read on for the whole file. With the exception of SHA1_File() I did not write these hashing functions for Blitzmax. They were simply taken from Yan’s very helpful code archives post :).
Continue reading

Yes, yes I know the documentation is lacking at the moment for Farseer.BMX. I’m still working on it on a few fronts. First, I’m trying to do api documentation (bbdoc mostly). Secondly, I’m trying to write tutorials/guides that help show how to use some of farseer’s features. I had hoped that releasing the demo application source code would’ve covered this aspect as the demos cover pretty much each feature, but I guess since the demo source is a bit more complex in design (handling a lot of graphics related mumbo jumbo), the actual ‘needed content’ wasn’t particularly easy to find. So I’m going to try to write up very simplified versions of some of farseer’s basic features (minimal graphics, minimal code).

I’ve uploaded the first of these tutorials to the articles section. It covers creating concave polygons in farseer :). More to come soon…

Hey again! Two updates in less than a month! Wonder if I can keep this up :). Anyway, just finished another article for Ziggy’s site. This one shows you how to do those cool, seamless ribbon trails you sometimes see trailing behind melee weapons (swords, sticks, etc) and other objects. I’ve also included a sample with full source code that works on both the PC and Xbox 360. So go check it out!

January 28th, 2010 Update:

Ziggyware.com seems to be down indefinitely. As a temporary solution until I get back around to hosting this tutorial myself you can find the Google cached version of it here. If you wish to look at the sample code and illustrations in full you can download the XNA sample from my site here. Note, that the XNA sample was built on a very old version of XNA so my guess is it will not compile out of the box, but the general logic for the ribbon trails should be the same regardless of XNA version.

Wow it has been a while! School is back into full swing so I’m spending time at school and in labs longer than should be legally allowed :|. I managed to scrounge up some spare time to write up this distortion shader article and some explanation of how things work for Ziggyware.com. Go check it out! Feedback is welcome as I’m still somewhat new to the world of shaders. Below is an example picture of the post-process shader in action.

Distortion Shader

I’ve written networked games in the past, but never in XNA. So after writing the networking logic for Gunstyle I figured I could write a blurb about general networking in games for XNA, which in reality isn’t that much different from any other API. I do not claim to be some expert in networking and I only present to you what I know based off prior experience from a few multiplayer networked games. Oh, and yes I am aware the diagrams are not completely correct UML diagrams, I am simply trying to illustrate a point. This isn’t a How-To guide to networking either, just food-for-thought for those just starting out with networked games.

Continue reading

For some reason I’ve been listening to APC a lot lately (can you tell?). Maybe it’s been the numerous all-nighters I’ve pulled recently and this music soothes me late at night. It’s been too busy the past few weeks for me to sit down and gather some thoughts for a post. Been hard at work with the new game for Dream Build Play, along with life’s other issues. Don’t have much to show at the moment as everything is a bit too early in development, but I figured I’d at least post one of the concepts by Adam (below).

For those that didn’t notice the comments in the previous post, several XNA developers were featured in the April issue of OXM (Official XBox Magazine), including me :). It’s kinda cool seeing your name in print. Go check it out if you want to read up on some more XNA goodness!

I’ve noticed quiet a few people have been wanting an updated version of my simple Camera2D tutorial that would work with XNA 1.0. This week is looking pretty busy so no promises, but I’ll try to get one up. Well, I got to get back to work. Look for more news about our game in the coming month or so as we edge ever closer to completion.

What?! Two posts in one day? Yea well, this one actually has some content to go along with it. I’ll make it short and sweet. You can find more info at my dev blog. I’ve got some cool stuff to share for this weekend’s update so stay tuned!

I put up my first tutorial! Hurrah! Go check it out in the tutorials section. I’ve also posted my game’s project plan for anyone to follow it as the game progresses. You can find that here. Peace.