Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views


Sign in to follow this  


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
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
std::vector STATES;
std::vector::iterator iter;


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.

Sign in to follow this  


Recommended Comments

There are no comments to display.

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
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!