iDevGames Forums
[C++] How do you implement a state chart or state machine? - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: [C++] How do you implement a state chart or state machine? (/thread-964.html)



[C++] How do you implement a state chart or state machine? - riruilo - Jul 24, 2009 01:17 PM

Hi friends!

How do you implement a state chart or state machine in C++? I mean, which technique do you use? can you write a small example? How do you store transitions? Or any useful link.
I use a switch with a list of states, but I don't use transitions, so I guess I doing it bad.
Note: I would prefer in C++ without any library like Boost.
Is there any program opr IDE to draw state charts and then create its code in C++? Something like assitant.

Thanks a lot for your time, this is a very important part in every game.


[C++] How do you implement a state chart or state machine? - wadesworld - Jul 27, 2009 10:37 PM

I don't think there's any one formula for a state machine.

If the state change is immediate, then there's no need for a transition.

You do obviously want to be careful to guard against getting stuck in a state loop, or stuck in a single state. However, the details of how that can happen and how to avoid it would be totally dependent on what you're doing.