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 »

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
Lacero
Halfling
Posts: 72
Joined: Tue Feb 13, 2007 1:57 am

Post by Lacero »

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

http://www.boost.org/libs/statechart/doc/index.html
User avatar
AticAtac
Halfling
Posts: 72
Joined: Sat Sep 24, 2005 10:19 am
Location: Germany

Post by AticAtac »

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.
User avatar
ahmedali
Gnome
Posts: 302
Joined: Fri Feb 20, 2004 8:52 pm
Location: Lahore, Pakistan

Post by ahmedali »

Middleware statemachines are rarely used practically. Yake implements a simple statemachine which can be used in Lua And C++, check it out.
Lacero
Halfling
Posts: 72
Joined: Tue Feb 13, 2007 1:57 am

Post by Lacero »

sorry aticatac, I didn't read your question properly. I can't help.
Rackle
Gnome
Posts: 375
Joined: Sat Jul 16, 2005 1:42 am
Location: Montreal

Post by Rackle »

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.
lXciD
Greenskin
Posts: 102
Joined: Mon Jul 31, 2006 7:56 pm
Location: Singapore
Contact:

Post by lXciD »

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. :)
turkeypotpie
Halfling
Posts: 53
Joined: Thu Apr 28, 2005 12:09 am
x 1

Post by turkeypotpie »

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.
Lacero
Halfling
Posts: 72
Joined: Tue Feb 13, 2007 1:57 am

Post by Lacero »

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.
User avatar
Lee04
Minaton
Posts: 945
Joined: Mon Jul 05, 2004 4:06 pm
Location: Sweden
x 1

Post by Lee04 »

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...
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 »

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.
User avatar
Lee04
Minaton
Posts: 945
Joined: Mon Jul 05, 2004 4:06 pm
Location: Sweden
x 1

Well the resorse is me, just send a PM

Post by Lee04 »

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.
Ph.D. student in game development
Post Reply