Sign in to follow this  

The state machine in Singles2

This topic is 3864 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am learning lua recently and find Singles2 is a good source. All of the state machine is written in lua:
beginStateMachine()

	onEnter(function(msg)
	
		if this.animName then
			-- scene graph animation
			this.startAnimation(this.animName);
		end
		
		if this.hasMaterial("glowMat") then
			-- texture animation
			sendMsgThis("startAnim");
		end
	
	end )
	
	onMsg("startAnim", function(msg)
		preloadTextures(this, {"Glitzer_000", "Glitzer_001", "Glitzer_002", "Glitzer_003"});
		startAnim({"Glitzer_000", "Glitzer_001", "Glitzer_002", "Glitzer_003"}, 0.1);
	end )
	
	onMsg("showPic", function(msg)
		replaceTexture("glowMat", msg.data);
	end )
			
endStateMachine()
The syntax is like an article in Game programming gems 1. But in that article it is written in C. So I am wondering how Single2 utilize this lua code? Maybe they write some cpp functions like beginStateMachine() and onMsg()? And generate a cpp FSM class using the lua code?

Share this post


Link to post
Share on other sites

This topic is 3864 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this