Jump to content
Sign in to follow this  
  • entries
    68
  • comments
    57
  • views
    42221

LGE

Sign in to follow this  
RanBlade

320 views

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.

Sign in to follow this  


0 Comments


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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!