Mar 24 2011

VectorStorm library update

Tag: Engine,Full Games,MMORPG Tycoon,VectorStormtrevor @ 10:51 pm

For the first time since getting my new job, I’ve finally sat down and written a little code on my home projects.  It’s not too much, but it felt pretty good to write it.

I’ve fixed the VectorStorm engine bug which was causing problems with the middle mouse button and right mouse buttons (often swapping the two, or causing them not to work at all).  It was an embarrassing mistake;  I had just mis-assigned labels for the controls, causing some minor swapping when loading saved control preferences.  I’ve made this bug fix both within MMORPG Tycoon 2 (where it was a major problem), and within the trunk VectorStorm library (where it was less of a problem, since no standard VectorStorm games were using mouse control).  If any of you have been looking at or using the VectorStorm library, you should go get those fixes.  If not, don’t worry about it too much, just be aware that I’m back to the compiler again.  :)

I’ve also begun poking with Tycoon code again.  Not a whole lot;  am just slowly easing myself back into it.


Jan 04 2011

Some bugfixes to VectorStorm

Tag: Engine,VectorStormtrevor @ 3:43 pm

I have no idea what this image is.

I’ve made a bunch of little tweaks to the VectorStorm engine today.  Most notably:

When doing a scene update, the camera now updates last, instead of first.  Previously, the camera would pick where to be before the game had a chance to take any actions, which usually led to the game camera lagging one frame behind whatever it was supposed to be following.  (Of course, now you’ll have the opposite problem;  the game will no longer be able to tell where the camera is, since it won’t have moved into position until after the game finishes its update)  In practice, the real solution is for the game itself to take responsibility for updating the camera whenever is appropriate for that game.  But as a default, having the camera update last is usually less-bad than having it update first.  So I’ve changed it.

I noticed that vsFont wasn’t applying text colors to strings which were justified as “centered” or “right”;  they were always coming through as pure white.  This is now fixed, in current trunk.

I also added another “primitive” function for creating renderable textured rectangles (as vsFragments that can be attached to a vsSprite or vsModel), this time supporting tiled textures.  You can specify how big the tiles should be, and can optionally specify a rotation for the texture.  Check for vsMakeTiledTexturedBox2D() in VS_Primitive.h, for that.

I’ve also been poking with the bloom effect again;  I noticed that the trunk version looks pretty ugly at large screen sizes.  I think I have it balanced nicely again, but haven’t committed these changes to the public repository yet;  probably later tonight or tomorrow, once I’m certain that performance is still okay.

Finally, I’ve just finished scaling down the Asteroids testbed game.  It’s been misbehaving ever since I converted it over to Box2D, because its objects were moving too fast for Box2D to cope with.  So I’ve reduced everything by a factor of ten, and now things are moving at a reasonable speed again.  I’ll be checking that in a bit later on as well.  Oddly, I’m still occasionally having shots bounce off of asteroids, without receiving a collision callback.  Mind you, I’m using an ancient version of Box2D;  maybe I should update that someday.


Nov 19 2010

Multitouch

Tag: Engine,General life,VectorStormtrevor @ 12:48 am

Today I set up Multitouch gestures for iPhone/iPad.

Again, this photo is using exactly the same graphics as the past few days, just now you can use multitouch gestures to zoom and rotate the interface.  (Most of my time went into the zooming.  Surprisingly difficult to get the maths right for that, in this case.)

It feels.. surprisingly natural.  I didn’t think it’d feel this good to move an object around on the screen this way.  There’s probably a bestselling game just in that interaction, if you could figure out a way to wrap a game around it (and if somebody else hasn’t already done it.  I’m sure someone has).  I’m not sure exactly what game you could wrap around this interaction, but it does feel really, really nice.

Right now, VectorStorm supports only two simultaneous touch events.  But now that I have two working, it’d be really easy to add up to about ten.  But in this case, I only need two for the pinch/zoom interface.  So I’ll probably make do with what’s in there now.

Tomorrow, I may take a stab at sound support.  Or more likely, I’ll spend time on the game code itself, again.


Sep 14 2010

Further dull development

Tag: Engine,Full Games,MMORPG Tycoon,VectorStormtrevor @ 10:58 pm

Oddly enough, these dry bits of engine development are often the most exciting to me, since they open up all sorts of exciting new possibilities, and make development substantially easier in the future.

I’ve been doing further development on the “automatic save/load” system that I’ve talked about before;  the system which automatically handles loading and saving of game data, without me having to write custom code for everything the way that I did back in previous games.  For comparison, in MMORPG Tycoon 1, nearly half of my total development time went into the save/load functionality — it’s extremely complicated, and extremely bug-prone, so anything that I can do to make the saving/loading process easier and safer is going to be a huge win, overall!

This “how do we load and save large amounts of data” issue, incidentally, is one that professional game development teams everywhere have struggled with forever, and I’ve seen a lot of different solutions to it.  But I’ve gotta say, this solution I’ve been working on is by far the best that I’ve ever seen within the C++ language;  it imposes few restrictions on the code I write, and can just automatically figure out how to save files out based upon inspecting the saveable variables I expose within each class.

What I’ve done today is to make this system recursive.  That is, you can now have an object which contains other objects, which contain other objects.  Or to give a more concrete example:

In MMORPG Tycoon 2, there’s an object for each of a character class’s abilities.  So if he has three different types of attack, that’s three code objects which store information about how much damage those types of attack do, etc.  Those three ability objects are stored inside another object, an “Ability Set”, which lists all the abilities available to one character class.

With this new stuff I’ve written today, it’s now possible for me to simply call “AbilitySet->Save(“Filename”)”, and have the AbilitySet save itself out, plus all of the Abilities which are inside of it, into a single neat data file.  Similarly, “AbilitySet->Load(“Filename”)” loads that data file from disk, recreating the AbilitySet object itself and all of the abilities that it should contain.  This is all typesafe — the AbilitySet can only contain objects of “Ability” type (or derived from that type), and no typecasting is required at any point during the process.

Of course, the next step is going to be to have the CharacterClassPrototype have an AbilitySet inside itself, so that when I load a class prototype from disk, it automatically loads the abilityset, and the abilityset’s contents.  And then a ClassManager will be set to contain ClassPrototypes, so that when I save the ClassManager, it automatically saves out all of the class prototypes inside it, and so forth and so on.  Eventually, everything in the game should be included within this data hierarchy, so a single call to “Save()” or “Load()” at the top level will be able to automatically handle saving or loading the complete game state, all from a single line of code.

So I’m pleased.  :)


Sep 05 2010

Major rendering restructure

Tag: Engine,Full Games,MMORPG Tycoon,VectorStormtrevor @ 8:38 pm

Today I spent the whole day doing just one thing:  a major restructuring of VectorStorm’s rendering architecture.  This is, without a doubt, the biggest change to how rendering works in VectorStorm since I first wrote it.

What you’re looking at in this screenshot is a not-yet-activated starting point, being rendered as a glowing outline, behind a tree.  Anyone who’s played with the MS1 build of Tycoon2 will know that one of the big rendering problems that it had was that glowing objects would often glow through opaque objects that were in front of them.  As you can see, this is no longer the case.  VectorStorm now automatically ensures that objects are drawn in the correct order, so you won’t incorrectly see obscured glowing effects.

To do this, I had to (warning:  the rest of this post contains dangerously boring technical details) change how VectorStorm renders.

Originally, VectorStorm was designed for rendering simple 2D vector graphic games.  As such, it was designed with a system of “layers”.  Your game could configure how many layers it wanted to use, and register sprites or other objects onto any layer you liked.  Within each layer, objects were drawn in order, with later objects (or later layers) drawn on top of previous layers.  With vector graphics, since you only had additive lines and no solid objects, the whole issue of which line was on top really didn’t matter;  the layers were really used just for putting objects under different cameras.  For example, in The Muncher’s Labyrinth, the game world was in one layer, and the HUD was in a different layer, just so the two could be rendered using different cameras and I didn’t need to worry about moving the HUD around to match the camera.  When I added solid rendering for ThunderStorm, the layers worked really well to ensure that some objects would always draw in front of other objects.

Each renderable object would have a “Draw()” function called on it, being given a pointer to a display list to which it could append its own rendering commands.  This was (in my own opinion) simple and elegant, and it was great for a while.

But now that VectorStorm is rendering in 3D, layers don’t really make sense any more.  We still have them, but in 3D we have a z buffer which automatically lets the closest object be drawn, regardless of whether it was drawn first or last, so it’s usually no longer important to manage which objects are drawn first or last, except for in special circumstances (glow effects, transparency, etc).

But the real problem is that we now often have objects which have different drawing styles within a single object.  For example, the cursor in MT2 (and MT1, for that matter) is made up of two parts;  a dark background, and a glowing outline.  Under the “just add your commands to this display list” approach, each object has to render all of its geometry at once.  This meant that I couldn’t (for example) draw the background portion of the cursor early, and the glowing part later on;  they’d both always render at the same time.

Another possible issue is that of rendering partially transparent objects.  These see-through objects are always a problem with modern 3D games, since z-buffers can’t be used to render them (z-buffers assume that everything is opaque, and so won’t allow you to draw anything behind a pane of glass, for example, if you draw the glass first).  The traditional way to handle these translucent objects is to sort them from back to front, then draw them in that order, after you’ve drawn all the non-translucent objects.  But with the simple-and-elegant way that I was handling drawing of objects, there was no way to sort the objects into any different order than they were already in.

Anyhow, enough of the problem statement.  :)

What I’ve changed is that renderable objects in VectorStorm are no longer given a pointer to the game’s vsDisplayList when it’s time for them to render.  Instead, they’re now given a vsRenderQueue object.  On that vsRenderQueue, they can provide their rendering instructions in one of several ways, and the vsRenderQueue can then reorder the drawing as required, to make sure that (for example) the glowing and transparent parts of objects are drawn last, while their opaque portions can still be drawn earlier.

The other change is that vsLayer is now completely gone.  Instead, we now have vsScenes, which work very much like vsLayers did;  they’re just collections of renderable objects.  Like before, your game can have any number of vsScenes, and they’re rendered in order.  Right now, they share a single z-buffer and render target between them all, but setting it up so that the different scenes can have separate renders is certainly possible in the future, if I ever need that feature.

You can probably tell by how I’m gushing, but I’m absolutely thrilled and relieved to have this all working at last.  Lots of stuff in MT2 (particularly the very old code) is currently working via a “compatibility” mode that I’ve put in the vsRenderQueue, and I do still need to convert those bits of code over to using the new systems instead.  But this change has illuminated a whole bunch of unreliable rendering code that was lurking in the GUI systems until now, and the stricter system should keep me from writing terrible code again in the future.

Right now, these changes are only in my MT2 development branch — they haven’t been propagated back into trunk, largely because I’d probably have to make a lot of big adjustments to the testbed apps to make them render under the new systems, and I’m feeling like taking a bit of a rest, after this ten-hour coding session.  But I’ll update trunk sometime in the foreseeable future, and will post about it when I do.


« Previous PageNext Page »