Monday, May 21, 2012 06:04

Posts Tagged ‘ZAMF’

Almost ready to maze

Wednesday, April 22nd, 2009

So I’ve updated yet another uhh…update. This time around I’ve neatened things up, fixed some bugs, and added some polish. Here’s what’s changed:

  • Objects now snap-to-grid
  • Weapons, walls, zombies and player all properly collide / slide (sliding is a little jumpy atm, but not too bad)
  • Fixed some crashing that was happening due to physics objects not being properly removed
  • Tried it out on linux – I get segfaults at random, and I have no idea how to debug properly on linux *sigh*

So the reason I’ve done the snap-to-grid feature is so I can work on mazing. Try it out now – You can build mazes with magnets or turrets, and you can walk through it. However, that is kind of useless without some shortest path algorithm.

The best algorithm for this application will be A* – it can find the shortest path to a destination node (the fridge) from every other node. I only need to run it once for every blocking object that gets added, so performance is good, and with proper heuristics, no problemo!

I was pondering the idea of using fluid dynamics for the pathfinding. See, the pressure stabalisation step of fluid dynamics essentialls “smooths” things out, and makes the fluid run along boundaries. All I’d have to do is initialise every grid position with a vector pointing to the destination node, and run a few jacobian iterations over the domain, and voila! Done! I want to try it out and see how it goes, seems like a novel approach that could work. The main problems I see are with very complex mazes (fluid would virtually stand still due to compression/numerical accuracy), very thin mazes (if walls are on either side of a single cell, it’s hard to solve), and U shaped areas (the fluid may end up just going in circles once inside which would be funny, but not good for gameplay). I’ll let you know how it goes :)

The only other thing I’ve done is update the ZAMF page to have the link to the latest at the top, beneath the picture, rather than the bottom. Woohoo!! As always, click the link on the right to check it out

Largest Update Yet!

Wednesday, April 8th, 2009

Whew, I’ve just finished my biggest update yet, feature wise. I was surprised at how fast this one came out, but I’m quite pleased with the state of this product – it seems to be rock solid, fast, accurate and *gasp* even a little bit fun!

So, since this seems almost like a milestone release, I think I’ll write a bit about what’s been done. Most of the content of this post will be over on the project’s page, too, which will be updated as I go on.

As you know, I had this project done a fair bit using my own custom rolled engine, but maintenance became just a tad extreme, and I figured that other people have already done stuff, so why should I have to reinvent the wheel? Some research found me Ogre

The hardest thing about changing to Ogre was the way the main loop is done. In my own system, every scene node had an overrideable “Update” function, where I implemented my AI and everything. Basically, I extended scene nodes for every type of actor there was. In Ogre, you can’t really extend the scene node class, without overriding the scene manager as well (which I didn’t want to do) – instead, “frame listeners” are used – a function is called every tick on a frame listener, and they have to update the scene node. So I wrote a wrapper around all this so I can simply register my own AI classes, and this handled all the keyboard and mouse events

While I was at it, I put in a game state manager and level loader – this time actually thinking about the transitions between levels. There’s functionality in place now to put loading screens in (but not actually used), and properly clear any cache or anything that I have lying around. Woohoo!

The next big task was deciding on a physics engine. My first instincts told me to go for PhysX (aka Nx) – there were binding classes around to do some of the integration work for me, and it wasn’t long before I had a dummy app in Ogre that I could throw boxes around and watch them smash each other up.

However, after trying to get it into my engine, it became apparent that the binding classes included were too restrictive – it tried to wrap every single function up, and so I was left with a half of a physics engine that I could actually use, with the overhead of the whole library, and it lacked very VERY important features – such as a simulation tick callback, or listeners.

I decided to scrap Nx and go for bullet. The first set of bindings I used was similar to the nx bindings – tried to wrap every function – so I had issues with that straight away. Then I found a second set, far more slim – more of a converter than integration. It allowed me to throw entities at it, and get back bullet representations of those – cylinders, boxes, spheres, convex hulls, trimeshes, you name it. Brilliant! I now have a physics engine.

Ahh, physics is difficult. I’ll give a brief rundown on how things work here, but it’s a very complicated topic. It took me several forum posts, hours of reading, and hours of “DARGH WHY ISN’T THIS WORKING” until I got it down. So here goes.

The bullet physics engine is governed by 4 parts – the world, dispatcher, solver and broadphase. The idea is we create a world (which holds physics objects) and attach a dispatcher to it (which stores and moves collision information around). We also need to set up the broadphase – a topic in and of itself, but this handles the broadphase part of the collisions (checks bounding boxes, or whatever – cull lots of objects quickly). The solver is responsible for resolving collisions – if a truck hits a tennis ball, what is the result?

So, how does one set up bullet physics? Simply:

  • Set up the world, dispatcher, solver and broadphase
  • Attach some form of internal callback function, to handle the results of the collision
  • As the game is going, add collision objects/rigid bodies to the world. Each object should have a motionstate attached to it – which synchronises the scene node position/orientation with the physics object
  • At each timestep, tell bullet to step the simulation

This will get everything set up, and even make things bounce of each other properly. However, that last bullet point is a doozy. I’ll put what I think happens inside that step to clarify:

  • Simulation step is started
  • The broadphase goes through and finds all possible collisions, creating a contact manifold for each and throwing it at the dispatcher
  • The dispatcher looks at each manifold, and performs a low-level collision detection on each primitive (ie. box, sphere), storing the information of any contact points in the contact manifold
  • If dynamics is enabled, solves any collision responses, making each object interact
  • Calls the internal tick function specified by the user, with the collision world as a parameter
  • Here, the user must loop through the manifolds, find all the contact objects and points, and perform any custom collision responses (playing sounds, losing health, whatever). To make this step more possible, one can set up a user pointer (void*!!!), which can hold anything. I chose to make it hold a physics response interface which I can subclass, it works really well. I just need to cast it to this IPhysicsResponse, and call my Collide function. Yay!

And that’s that! Physics was definitely the hardest thing to set up – harder than the graphics engine, I would say. The main reason it’s so hard is because documentation is really, really bad. It’s written by a bunch of academics, and it’s more fun to make the physics engine than it is to document it. Oh well. The forums are absolutely awesome though, hurrah!

Once I got the physics sorted out, I could move on to implenting decent gameplay. Here’s where things sped up somewhat. I was able to perfect the collisions between bullets and zombies, and stop the zombies running through each other, and add a magnetised weapon, and stuff. I tried to add a kinematic player controller (basically, the user is governed by physics rather than by moving it), but it seems I should wait until the next Bullet release for that.

My most recent additions to the engine include a config file, so I can much more easily tweak things like zombie health, cooldown rates and starting money, and sound. That’s right, the sound that added so much to the previous version is now in this one! And improved – I now have a dying sound, 2 sets of music and a zombie hitting sound.

All in all, I’m quite pleased with my progress. Check it out here, and let me know any suggestions/ideas/critcism/anything! Feedback is most welcome!

Getting there…

Friday, April 3rd, 2009

Whew, so I’m 90% done moving to Ogre.

Check it out here. Ignore what that page says, I haven’t updated it yet.

Time for sleep. I shall edit this post later.

Status Update and New Page

Wednesday, March 4th, 2009

So I’ve been working on moving engines – bigger job than I thought. I’ve put a state manager in, so I can easily allow the game to be paused, have a menu etc. – it adds quite a bit of polish, really. I’ve also put in a message dispatcher, so there’s no one central hub for all messages, and components can register themselves there in order to receive messages – it makes message handling much easier, and allows me to customise input quite easily.

But as for the game itself, well I have a zombie running around in circles, and the ability to create turrets which destroys the zombie that runs around. It shouldn’t be long before I have a replica of the old stuff – I only have to add zombie behaviour and scoring, really, and it’s done! (ish).

In other news, I’ve updated the ZAMF page – it now includes a downloadable version. I figured there’s no harm in sharing it with the world! :-)

Be sure to give me feedback by commenting here! Tell me what you’d like to see, what you’d like to not see, things to add/remove and all that, I’ll do what I can :-)

Moving Engines

Sunday, February 22nd, 2009

So, it seems I’ve bitten the bullet – being so close to the core (working straight from DirectX, and using no wrapper libraries besides what I create myself) has finally done me in. While I know can get the project working continuing on with my current engine, it doesn’t seem very efficient for me to do so.

For example, for me to get shadows working on my project, it took several days of coding (I was trying out an omni-directional shadow mapping technique). To get it working in Ogre 3D, it took 5secs – a call to setShadowTechnique, and then a call setCastShadows(true) for each node I want to cast a shadow. Simple! Time saving!

So in order to be able to get results in the project in a timely fashion, I’ll be porting all my code over to another engine. At the moment, I’m erring towards Ogre3D – the only drawback is it’s graphics only, not sound/input/network/physics as well. But it has a nice plugin system, and can apparently support things like PhysX quite nicely. I was going to use Torque, but it costs money, and I don’t too much of that lying around for something that I don’t even have example code for to see how good it is…

Sound DOES help

Friday, February 13th, 2009

So, I spent today wasting time playing tower defense, and writing a sound manager to plug in to my engine.

The way it currently it works is simple. The sound manager has a play sound method, which takes a wav filename as a parameter. This method loops through all the current buffers, and compares the file names, to see if they’re the same. If it’s not the same, it creates a new buffer, which contains the information to play the file. It then loop though all the sources and tries to find one that is currently not busy playing something. If it can’t find one it also creats a new source.

Then after figuring out all these sources and buffers, i get the source to play the buffer – and it’s done!

This still causes some issues though because, apparently, I can’t have more than 30 sources at a time, and so I need to prioritise the sound so that closer objects get more priority over further away objects.

It’s also a little bit annoying because there’s no way of stopping sounds part way through as it stands – I may want to cut out a zombie attack sound if he gets shot mid attack, or whatever. Not really possible.

The only other thing that I should really do is set this stuff up in some sort of config file, so I can say “play zombie attack sound” instead of “play zombie_attack.wav”. Not a huge issue for this game though, be nice for the engine as a whole.

Apparently Sound Helps…

Friday, February 13th, 2009

So, I figure it’s about time I figured out how to put sound effects into my game.  I’ve heard good things about OpenAL, so I thought I’d give that a go for this project.

Starting out with OpenAL is really quite easy, and I got a sound happening in the game (gunshot firing) in an hour or so, not bad for someone who has never dealt with sound before. Turns out OpenAL is very similar to OpenGL in framework, so I’m sure that helped a lot.

Anyway, the main problem with what I’ve got now is that I currently have 1 sound playing at a time, if I send it another sound, the previous sound will stop and this one will take priority – and it sounds really lame when I have 10 turrets firing at the same time. So I need to work out how to get multiple sources playing at the same time. Of course, this means I have to make a sound manager, so instead of just saying “play this sound”, I say “this object wants to request playing this sound”, and then only play it if there are enough sources available to play it.

And the sound manager has to keep track of what sources are playing, and which have finished – so I can free that source up for another sound when it’s ready. So that’s what I’m up to now, writing a sound manager. I think it will be a while – especially since I can’t find any tutorials or anything.