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.