Saturday, August 23, 2008

Compression Depression

At work I've been coming up with a new method of managing monsters by giving them a Logo style script. It's a list of letters followed by numbers. The real tough part was nesting scripts within each other so I can have monsters spawn other monsters. This is tough because I have the new script in between brackets and regex can't do a balanced search. It's okay to spawn one monster, but what if that monster wants to spawn as well?

The solution was to match the deepest spawn that wasn't spawning itself and work back from there. I store that in an array, then replace it with a marker to that point in the array:

var path_string:String = "a bunch of commands go here"
// spawn commands look like: S(monster commands)
const SPAWN_COMMANDS:RegExp = /(?<=S \()[^\(\)]*(?=\))/;
const SPAWN_COMMANDS_REPLACE:RegExp = /S \([^\(\)]*\)/;
var subroutines:Array = new Array();

if (subroutines.length == 0){
// extract spawn instructions and replace with an index to the subroutine list
// matching works from the deepest nest up as the parenthesis is replaced
do{
var spawn:Array = path_string.match(SPAWN_COMMANDS);
if(spawn != null) subroutines = subroutines.concat(spawn);
path_string = path_string.replace(SPAWN_COMMANDS_REPLACE, "S "+(sub_index++));
} while (spawn != null);
}

I then give each spawn a reference to the subroutine array, which means I only have to parse subroutines once and I save on memory. Even if the parent monster is erased, the reference by the spawn to the subroutine array saves it from being garbage collected.

The crazy thing is that the first spawn command will get replaced with "S 1". If I'm wise to this when I write a monster's script, I can type "S 1" any where in the script and it will call that subroutine. Even inside the first spawn's own script. This means my monsters can recursively generate.

All well and good. But now I have a massive XML full of instructions for every monster. Chris Burt-Brown at work had already opted for an RLE compression method that I've also adopted (multiples of the same item you replace with a quantifier and the item), but this isn't enough for complicated instruction sets. Looking around I found an LZW compression algorithm in AS2. It even produces XML safe output! Problem solved right? Wrong. My level editor uses a javascript method to save the XML that I cribbed from Galasoft. That method only saves ANSI encoded text files. The LZW algorithm produces UTF-8 encoded output. Saving those strings as ANSI destroys all the data. I was lucky enough to find out that Mozilla browsers have the ability save XML with the XMLSerializer method in UTF-8. There's a thread on the topic here. A quick mod to the Galasoft script and I was home free.

Now if I could figure out how to operate FZip, then I could take the operation further and get more assets within the game packed down to size.

Self Aware Robots (TED talk)
Simplicity Patterns (TED talk)
Big Buck Bunny (Blender made cartoon)
Curved electronic eye created
Double Taker (Golan Levin)
A robot with a biological brain

Alternativa 3D for Flash
AS3 Mouse Gesture class

Thursday, July 24, 2008

Final Ninja

I'm quite pleased with this one and I hope people enjoy it:

Final Ninja

It started out as a sort of cross between the Dirk Valentine and Dangle engines. Then on the way to pick up my usual lunchtime Thai noodles the ninja theme suggested to me that he should be able to turn invisible as well. This is also my first project in AS3. The most tricky part of the transition is that they've completely buggered up animation control in AS3. Having complex nested animations is no longer possible due to gotoAndStop being processed at the end of a frame. I've also not noticed the fabled speed increase everyone is speaking of (and even in Processing I was a total speed whore). It is however refreshing to know when I'm being a bad programmer, and you can trick AS3 into behaving like AS2 when you need to.

Saturday, May 31, 2008

Ogre

Well I finally got Ogre to compile. Bugger knows how I'm going to graft Openframeworks libraries into it. I only really need sound and the VideoGrabber, but those are still tall orders.

If you want to play with Ogre on a PC you'll need the following:

Visual Studio 9. Trying to get it to work with Code Blocks is more trouble than it's worth, especially as it breaks Openframeworks when you get the bare minimum working. Plus VS9 is pretty damn good. I'm amazed that Microsoft made it.
The Ogre SDK
DirectX Runtime

Then you'll want to read the following:

Installing the Ogre SDK
Setting up an application. No the Ogre Application Wizard doesn't work on VS9. This means we have to do some twiddling with project settings to get it to work. But despite this being a pain, it teaches you how to set up projects properly and will help you in the long run.
My thread in the Ogre Forum about trying to get VC9 to compile Ogre. I didn't quite read the instructions in the previous link thoroughly, but those instructions also assumed some knowledge I didn't have. Most of the difficulty of getting Ogre to compile is down to correct project settings and correct file placement. So you have to use your initiative a little to figure it out. Now I'm at the following stage:

Ogre Tutorials

I'm going to settle in to this stuff now to put off the nightmare that combining Ogre and Openframeworks will be.

Bruce Sterling on the future of interaction design
Magic Pen
Artificial Stupidity
Fruit Mystery game
Cat with Bow Golf game
Floating Head
The Control Master (a Run Wrake film)
Metal Gear Solid 4 game play demo

C++ optimisation strategies
Processing for Javascript

As a side note I got a new phone recently. So I downloaded the latest Mobile Processing and spent one Sunday writing a new and more clever game of Snake vs the Computer for it. It uses the new A* algorithm I built and shows the Snake's thoughts about which path to take ahead of it.

Snake AI 2

Wednesday, May 21, 2008

Knuckleheads

Well. This is a weird one. Certainly an experimental system.

Knuckleheads

The trouble with this game is that basically moving was so difficult that it was hard to put any challenges in the game without making it bloody impossible.

Progress with C++ is slow but fruitfull. I've managed to port the basics of my Processing breakout project over and bloody hell is it fast. I'm now trying to get Ogre to work. I looked at OpenSceneGraph but the set up instructions are incomprehensible and the forum is in Chinese. Seeing as I have enough trouble getting a Hello World out of C++ with out spending a few hours picking the brains of a forum on how to do it, I doubt I'm going to get any where with that one.

Thursday, April 24, 2008

Snotput

We've made a snot flinging game.

Snot Put

Amazing the things you can do with verlet integration and a chain of springs.

Sunday, April 13, 2008

st33d++

Just had my first sucessful tinkering session yesterday with Openframeworks on Dev C++. I'm now going to try to get it working on Code Blocks. I'm also going to be trying to get Ogre to work as well.

It's tough work really because I need to know that I've got 3D model importing and visual analysis up and running before I press on with porting my Processing code. And none of the C++ I've learned will sink in till I'm doing that last part. It's not that I think Processing isn't up to the challenge. I did a polygon test on my laptop yesterday and the chug set in on both platforms past the 10,000 rectangle point using OpenGl. I was quite surprised that there was so little difference, but the issue isn't really drawing, it's reading 3D model files. It's just that Processing isn't set up to import models and render them efficiently. Plus I'm sure I could be doing a more detailed visual analysis in C++. We'll see. Any progress I make will be uploaded to the Experimentation section for now.

Escape Pod - sci fi pod cast
magnetic feedback joystick
snake robot
The Pearce Sisters (Bafta award winning animation)
Universal Automatism article
Robots that ellicit emotion
Burn The Rope (game)Lumines - javascript puzzle game
Sheep Films
Powder - A multi platform rogue-like (DS version too!)

box2d AS3 physics engine
wow as3 3D physics engine
MD5 hash look up (or why you should put numbers in your passwords)
How to cheat and hack flash based games
You Tube of how to hack flash games with cheat engine
Email address encryption for websites
Vector based 3D engine for AS2
Regular Expression generator
Mike Grundvig\'s blog
AS3 physics engine
Quarternions FAQ
Machine game learning

Note that though it seems paradoxical to post links on how to hack the scores on my Flash games, Cheat Engine proved useful in finding a way to make hacking very difficult. The last two games I've made feature a couple of different techniques to put people off. I know some people suggest encrypting the values, but there really is a much simpler solution, I'll leave it to the reader to figure it out for themselves.

Saturday, April 12, 2008

Magneboy

It might not be the hardest puzzle game in the world but it certainly was enjoyable to make:

Magneboy

I've knocked up a port of the A* code I used in it into Processing here. Not that the intelligence of the monsters was appreciated or noted, but I guess that's how good design works. If it works well then you don't pick up on it.

I'll be putting up the links I've harvested later - I've got quite a few useful ones regarding programming.