Skip to main content
gamedev.net
🔒 Locked

Processing Functions

Started by Darkor Jan 26, 2003 at 7:05 AM 1 replies 250+ views
Original Post
Darkor
Darkor
I have stumbled upon yet another design decision. I have been programming most of my project using OOP practices and methods where I see it most beneficial. For entities within my game, would it be wise to create a object-driven state machine? What I mean is using objects to represent states.
  

class EntityState; //a virtual state class


class Attack: public EntityState
{
public:
  void Process();
};

void Attack::Process()
{
//here contains the processing that is to be done for the entity

//including state changes though the actual implementation is not here

}

class SomeEntity
{
public:
  void Process();
private:
  EntityState State;
}

void SomeEntity::Process()
{
  State->Process();
}

  
I guess you can put in the details that''s not here. But basically state changes look like:
  
State = Action;
  
Or something similar. This is opposed to having a lot of nested switch statements like:
  
void SomeEntity::Process()
{
  switch (ActionState)
  {
    case SE_ATTACK:
      break;

    case SE_CASTINGSPELL:
      break;
  }
}
  
That could get awfully messy since it''s essentially having as many process subroutines in a single function seperated by case statements. I''d like some tips on how to go about this, thanks in advance!
Neophyte
Neophyte
Here is an interesting article on state management from CUJ.

-Neophyte
Darkor
Darkor
Thanks for the article, I''ve read it through.

It seems that the article suggests to use objects for states when there are a huge number of states and primitive switch statements for less states.

I guess that''s enough to answer my question. Also, since the entity classes are inherited by mostly everything in the game, doing a robust state class would be in order.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.