game objects scripting state machines

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
User avatar
AticAtac
Halfling
Posts: 72
Joined: Sat Sep 24, 2005 10:19 am
Location: Germany

game objects scripting state machines

Post by AticAtac » Wed Oct 03, 2007 9:54 pm

Hi,

one method to control game objects in a game is to use finite state machines.
I am looking for examples which show how to do this in C++ and LUA.
So mainly, the state machine controller and message system is in C++ and the game objects and theier states and behaviour in LUA.

Any links, books, online resources are welcome
0 x

Lacero
Halfling
Posts: 72
Joined: Tue Feb 13, 2007 1:57 am

Post by Lacero » Wed Oct 03, 2007 10:14 pm

it's prety hardcore, but I don't know of a better c++ state machine.

http://www.boost.org/libs/statechart/doc/index.html
0 x

User avatar
AticAtac
Halfling
Posts: 72
Joined: Sat Sep 24, 2005 10:19 am
Location: Germany

Post by AticAtac » Wed Oct 03, 2007 10:37 pm

well, i know how to it entirly in c++.
my aim is to mix it with a scripting language like lua.
so a combination of c++/lua is that what i am looking for.
0 x

User avatar
ahmedali
Gnome
Posts: 302
Joined: Fri Feb 20, 2004 8:52 pm
Location: Lahore, Pakistan

Post by ahmedali » Thu Oct 04, 2007 7:13 pm

Middleware statemachines are rarely used practically. Yake implements a simple statemachine which can be used in Lua And C++, check it out.
0 x

Lacero
Halfling
Posts: 72
Joined: Tue Feb 13, 2007 1:57 am

Post by Lacero » Thu Oct 04, 2007 8:41 pm

sorry aticatac, I didn't read your question properly. I can't help.
0 x

Rackle
Gnome
Posts: 375
Joined: Sat Jul 16, 2005 1:42 am
Location: Montreal

Post by Rackle » Thu Oct 04, 2007 9:44 pm

These links may be of interest:

http://www.objectmentor.com/resources/a ... umlfsm.pdf
Mentions using the "State" design pattern to implement a C++ state machine.

The State Machine Compiler is a Java application to generate code in various languages. Worth investigating.
0 x

lXciD
Greenskin
Posts: 102
Joined: Mon Jul 31, 2006 7:56 pm
Location: Singapore
Contact:

Post by lXciD » Fri Oct 05, 2007 3:46 am

I like the idea that I can leverage boost fsm into a game. But how wise an idea is that? I been looking for a OO FSM solution for some time. I thinking of coding myself but if boost provide the functionality. I just use boost. :)
0 x

turkeypotpie
Halfling
Posts: 53
Joined: Thu Apr 28, 2005 12:09 am

Post by turkeypotpie » Fri Oct 05, 2007 6:06 am

I'm not sure how much luck you'll have using boost's implementation in lua. It uses a lot of templates, which don't bind very well.

We ended up writing our own implementation in lua, which is easier than writing it in c++ because you don't have all the static typing getting in your way. If you want a simple fsm, it's pretty easy, but if you want the extra bells and whistles (hierarchy, concurrency), be prepared to put some time into it.

Our fsm "language" is quite concise, and looks something like this:

Code: Select all

    function SInPlay()
        $State()
        :substate("ballTravelingToHitter", State()
            :substate("notBounced", State())
            :substate("bounced", State()
                :onEnter([
                    print("bounce!")
                ])
            )
            :tran("notBounced", "bounced", tBallContactedFloor())
        )
        :substate("ballTravelingToFrontWall")
        :substate("missed")
        :tran({"ballTravelingToHitter", "bounced"}, "missed",
            tBallContactedFloor(), [
                postMessage("showRuleMessage", { rule="Double Bounce" })
            ])
        :tran("ballTravelingToHitter", "ballTravelingToFrontWall",
            tMessage("playerHitBall"))
        :tran("ballTravelingToFrontWall", "ballTravelingToHitter",
            tBallContactedZone("frontWall"), rotateHittingAvatar)
        :tran("ballTravelingToFrontWall", "missed",
            tBallContactedFloor(), [
                postMessage("showRuleMessage", { rule="Floor hit" } )
            ])
    end
This is all lua, except for the [] and $ constructs, which were gained from applying a cool power patch:
http://svn.codekitchen.net/lua_patches/ ... readme.txt


A good book about state machines
A good book about uml and statecharts
Last edited by turkeypotpie on Fri Oct 05, 2007 7:37 pm, edited 1 time in total.
0 x

Lacero
Halfling
Posts: 72
Joined: Tue Feb 13, 2007 1:57 am

Post by Lacero » Fri Oct 05, 2007 10:09 am

lXciD wrote:I like the idea that I can leverage boost fsm into a game. But how wise an idea is that? I been looking for a OO FSM solution for some time. I thinking of coding myself but if boost provide the functionality. I just use boost. :)
The point of the boost fsm is that it uses templates to check the safety of the state machine at compile time. It would probably be impossible to make it work usefully with a scripting language as it wouldn't be able to check things at compile time anymore, I completely misunderstood the original question. If you don't want scripting I think it's the best there is, but scripting would probably be better in general.


turkeypotpie, that lua power patch looks really good.
0 x

User avatar
Lee04
Minaton
Posts: 944
Joined: Mon Jul 05, 2004 4:06 pm
Location: Sweden

Post by Lee04 » Sat Oct 06, 2007 7:57 pm

My outfit has done a HFSM middleware in C++ that uses simple state machine text files.
You can easily bind LUA to the basic API.

We also have d-trees... Even GPU computed ones...
0 x
Ph.D. student in game development

User avatar
Game_Ender
Ogre Magi
Posts: 1269
Joined: Wed May 25, 2005 2:31 am
Location: Rockville, MD, USA

Post by Game_Ender » Sat Oct 06, 2007 9:00 pm

Ok, so care to share some implementation details, location of white papers, links to source, usage examples? We all know this is possible, he wants resources.
0 x

User avatar
Lee04
Minaton
Posts: 944
Joined: Mon Jul 05, 2004 4:06 pm
Location: Sweden

Well the resorse is me, just send a PM

Post by Lee04 » Sun Oct 07, 2007 9:03 am

Well the resource is me, just send a PM

We will try it per case, depending what it it's in it for us.
What you are going to use it for if we can use you as a reference or not.
Maybe showcasing our middleware with your demo etc.
Getting good feedback.
Or other deals.

And there is a license, so the things we do don't grow legs unless we want it to.
0 x
Ph.D. student in game development

Post Reply