Pages

Saturday, 14 January 2012

XNA BulletML implementation

I have been working on my own implementation of BulletML in XNA. Currently, I'm using a Content Importer to parse the entire BulletML document and create a logical object structure representing the BulletML document. I used TiledLib by Nick Gravelyn as an example on how to work with the Content Pipeline.

With the parsing down I started working on creating the actual implementation of the BulletML patterns. To "shoot" the bullets we call the bulletML.Run() this could we seen as one run through the BulletML document. One run through means start at the TopAction and loop through every Task defined in that Action. Tasks are everything in BulletML that require something to happen, like firing a bullet is a FireTask, changing the speed is ChangeSpeedTask. All logics for these Tasks is of course handled inside itself. This way everyone can understand what's happening after a simple read through the code. We also need to run bulletML.Update() to update our bullets, nothing else.

After the script is done and shot all it's bullets the BulletML pattern can not simply be shot again. In order to be able to shoot the pattern again we need to call the bulletML.Reset() method. The reason for this is that some Tasks in BulletML take longer than some and actually need to work for a couple of frames. Borrowing the idea from Bandle I made the Run() methods from Tasks return a BulletMLRunStatus containing an enum wether to continue on or break from the loop (WaitTasks). Also when a tasks is done, their Done property will to set to true and their action will be skipped by the bulletML.Run() call.

I might change the need to call Run(), Update() and Reset() separately because if you want to shoot the pattern every X seconds you'll want to call the Reset() function every X seconds, which is a little strange.

But anyway, here is a screenshot of a very simple BulletML document containing a couple of <fire> tasks with each their <direction type="absolute"> to plus 10. This should of course we by a repeat and <direction type="sequence"> but I started with just supported an easy script to I can be sure my design was actually working.


The counter tells us it's running at 60 frames a second, which it was with simulating around 1300 bullets in it's memory. I did however notice a slight hiccup every so seconds and the counter is showing 59FPS just for a brief second. But it also might just be an optical illusion but I hope it won't be any problem further down the road.

1 comment:

  1. Very cool. Any plans on sharing the code?

    First thing that comes to mind about the hiccup in frame rate would be garbage collection, but that's an obvious one. I'll be keeping an eye on the progress of this =)

    ReplyDelete