LGE

Published October 18, 2006
Advertisement
Well my engine's state system moved forward today. The event system I made while I was working on this a year ago just looped through every current state that handled event and sent it the event. The problem was if two diffrent states used the same key for diffrent things it prossesed them both. So now I have adde some ID's to each of my event handling interfaces and make a CurrentID that is static among all the interface classes so each knows which one is in scope and then the only one that recives messages is the state that is in the focus of the program.

The event handling class:
class Event_Handler{	protected:		 int STATEID;	public:		virtual void HandleEvent( Event e ) = 0;		void         SetID(int tempID){ STATEID = tempID; }		int          GetID(){return STATEID;}		static int   CurrentSTATEID;		void         ChangeSTATE(int TempSTATE){CurrentSTATEID = TempSTATE;}			};


The main game loop and state manager:
class STATE_System {	protected:		std::vector STATES;		std::vector::iterator iter;			public:				void DispatchEvent( int Type, int Arg1 = 0 , int Arg2 = 0 );			void RegisterSTATE( Event_Handler* Interface, int defaultstate = -1 );				void ClearSTATES();								void Run();				};


and my DispatchEvent():
void STATE_System::DispatchEvent( int Type, int Arg1, int Arg2 ){	Event e;	e.Type = Type;	e.Arg1 = Arg1;	e.Arg2 = Arg2;	for(int i = 0; i < STATES.size(); ++i)	{		if(STATES->GetID() == STATES->CurrentSTATEID )		STATES->HandleEvent( e );	}}

I dont know if its VC++ 6.0(I know I need to update) but for some reason it dosent like iterators that much.. maybe Ill play with them later. but for now Iam just indexing everything.

Previous Entry Woot finnally got linux!
Next Entry Another Day.
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement