game objects scripting state machines
- AticAtac
- Halfling
- Posts: 72
- Joined: Sat Sep 24, 2005 10:19 am
- Location: Germany
game objects scripting state machines
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
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
-
- Halfling
- Posts: 72
- Joined: Tue Feb 13, 2007 1:57 am
it's prety hardcore, but I don't know of a better c++ state machine.
http://www.boost.org/libs/statechart/doc/index.html
http://www.boost.org/libs/statechart/doc/index.html
- ahmedali
- Gnome
- Posts: 302
- Joined: Fri Feb 20, 2004 8:52 pm
- Location: Lahore, Pakistan
-
- Gnome
- Posts: 375
- Joined: Sat Jul 16, 2005 1:42 am
- Location: Montreal
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.
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.
-
- Greenskin
- Posts: 102
- Joined: Mon Jul 31, 2006 7:56 pm
- Location: Singapore
- Contact:
-
- Halfling
- Posts: 53
- Joined: Thu Apr 28, 2005 12:09 am
- x 1
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:
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
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
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.
-
- Halfling
- Posts: 72
- Joined: Tue Feb 13, 2007 1:57 am
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.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.
turkeypotpie, that lua power patch looks really good.
- Game_Ender
- Ogre Magi
- Posts: 1269
- Joined: Wed May 25, 2005 2:31 am
- Location: Rockville, MD, USA
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.
Robotics @ Maryland AUV Team - Software Lead
- 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
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.
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