WIP 2 : State Machine

Hey there,

Did I say I’ll comment my engine status monday ? Today is monday, huh ?

Actually it’s hard to work with a real planning, since I’m working on my project only during my spare time. But still, I’m doing my best.

I’ve been working on my “state  machine” editor during the whole month.  Since it’s not something I wanted to create at the beginning (I mean when I started the engine), I delayed the whole remaining work… 😦
And it took so much time… But still, I hope it was worth it.

My State Machine Editor is based on some architecture I was used to seeing while working in the game industry. The difference are : it’s graphic, and you can update it after compilation time. Instead of explaining the whole thing, I’ll put some examples :

First, every object “script” (such as characters, interactive objects etc.) may have one or several Action Bank(s). Here is an example of a player’s Action Bank :

The Action Bank defines what animation the script can use. Then, we create the state machine to trigger one or another…

Here is a simple state. The one called “State_Idle”. It just plays a looping animation (rank=0 in Action Bank). The first list box contains the list of the states (with their id). The second list box contains the list of “next possible states” (green states are the one you can trigger from the current state). Then, in this example you can’t go from “State_Idle” to “State_Dash”, but you can go to “State_Walk”, “State_Jump”, “State_Run”.

As you noticed there are two distinct branches in a same state. The yellow branch is the one I call “PreState” or “StateEnter”. This is the condition to enter in the state. The idle example could have “If no input is pressed etc.” in its yellow branch.
For each state in green (in the second list box) we execute the “PreState” (every frame).

The blue branch is what I call “StateUpdate”. That’s what is done if the state is the current one. Here is another example :

Since the “State_Walk” is one of the possible next state of  “State_Idle”, we will execute the “PreState” (yellow branch) every frame. Pressing Left or Right will push the “State_Walk” (means it’ll be the current state), then, its “StateUpdate” (blue branch) will be the one executed. The method “PopState()” changes the current state to the default one (the first in the top list box : State_Idle). By the way I did a mistake here… In the list of “Next possible states” of the State_Walk, the  State_Jump isn’t green, which means while walking you can’t jump.
Using only these two states, the player can move forward and backward. WAAAOOUH !! That’s awesome ! I know for sure it is. But since every “block” is a simple method invocation and conditions are fields/properties or function results comparisons, I can actually trigger every methods on the class holding the state machine (depends on the object) using different conditions, which means I can do tones of things, from AI movements to events management. In addition, you may have noticed in the previous example a state called “Gravity”. Actually it just contains a “PreState” :

Then, every state in which the “Gravity” is enabled will allow this “PreState” to be executed every frame.

I tried it to make a character move and jump. It’s working fine. But I didn’t do the serialization part yet… lol. So, yeah, every time I start my engine, I need to recreate the State Machine. Yeah, it’s easier and cleaner than coding it, but if it’s not saved it’s kind of useless… Need some tiiiime.

I’m also adding a light engine to my project. At first I thought I could make it on my own, but it’s a pain in the ass, man (I managed to get shadows on convex polygons, but if I want something cool and porwerfull, I’ll need looots of time)… Krypton is an awesome Light Engine. I tried it and started to integrate it in my engine as an external tool. Now I can create “Light objects”. I just need to make my colision maps compatible with Krypton and then, I should enjoy the lightning. Piece of a cake.


Once I’m done with the serialization and Krypton integration, I’ll work on a little demo showing different things (with no fx nor sound).


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s