ActionHandler Class Reference

#include <action_handler.h>

Collaboration diagram for ActionHandler:

Collaboration graph
[legend]
List of all members.

Public Member Functions

void NewAction (Action *a, bool repeat_to_network=true)
void ExecActions ()
std::string GetActionName (Action::Action_t action)

Static Public Member Functions

static ActionHandlerGetInstance ()

Private Types

typedef void(*) callback_t (Action *a)
typedef std::map< Action::Action_t,
callback_t >::const_iterator 
handler_it
typedef std::map< Action::Action_t,
std::string >::const_iterator 
name_it

Private Member Functions

 ActionHandler ()
void Exec (Action *a)
void Register (Action::Action_t action, const std::string &name, callback_t fct)

Private Attributes

SDL_mutex * mutex
std::map< Action::Action_t,
callback_t
handler
std::map< Action::Action_t,
std::string > 
action_name
std::list< Action * > queue

Static Private Attributes

static ActionHandlersingleton = NULL

Detailed Description

Definition at line 32 of file action_handler.h.


Member Typedef Documentation

typedef void(*) ActionHandler::callback_t(Action *a) [private]

Definition at line 39 of file action_handler.h.

typedef std::map<Action::Action_t, callback_t>::const_iterator ActionHandler::handler_it [private]

Definition at line 41 of file action_handler.h.

typedef std::map<Action::Action_t, std::string>::const_iterator ActionHandler::name_it [private]

Definition at line 45 of file action_handler.h.


Constructor & Destructor Documentation

ActionHandler::ActionHandler (  )  [private]

Definition at line 551 of file action_handler.cpp.

00552 {
00553   mutex = SDL_CreateMutex();
00554   SDL_LockMutex(mutex);
00555   Register (Action::ACTION_MOVE_LEFT, "move_left", &Action_MoveLeft);
00556   Register (Action::ACTION_MOVE_RIGHT, "move_right", &Action_MoveRight);
00557   Register (Action::ACTION_UP, "up", &Action_Up);
00558   Register (Action::ACTION_DOWN, "down", &Action_Down);
00559   Register (Action::ACTION_JUMP, "jump", &Action_Jump);
00560   Register (Action::ACTION_HIGH_JUMP, "super_jump", &Action_HighJump);
00561   Register (Action::ACTION_BACK_JUMP, "back_jump", &Action_BackJump);
00562   Register (Action::ACTION_SHOOT, "shoot", &Action_Shoot);
00563   Register (Action::ACTION_CHANGE_WEAPON, "change_weapon", &Action_ChangeWeapon);
00564   Register (Action::ACTION_WIND, "wind", &Action_Wind);
00565   Register (Action::ACTION_NEXT_CHARACTER, "next_character", &Action_NextCharacter);
00566   Register (Action::ACTION_CHANGE_CHARACTER, "change_character", &Action_ChangeCharacter);
00567   Register (Action::ACTION_SET_GAME_MODE, "set_game_mode", &Action_SetGameMode);
00568   Register (Action::ACTION_SET_MAP, "set_map", &Action_SetMap);
00569   Register (Action::ACTION_UPDATE_TEAM, "update_team", &Action_UpdateTeam);
00570   Register (Action::ACTION_NEW_TEAM, "new_team", &Action_NewTeam);
00571   Register (Action::ACTION_DEL_TEAM, "del_team", &Action_DelTeam);
00572   Register (Action::ACTION_CHANGE_TEAM, "change_team", &Action_ChangeTeam);
00573   Register (Action::ACTION_SET_CHARACTER_PHYSICS, "set_character_physics", &Action_SetCharacterPhysics);
00574   Register (Action::ACTION_SET_SKIN, "set_skin", &Action_SetSkin);
00575   Register (Action::ACTION_SET_CHARACTER_DIRECTION, "set_character_direction", &Action_SetCharacterDirection);
00576   Register (Action::ACTION_CHANGE_STATE, "change_state", &Action_ChangeState);
00577   Register (Action::ACTION_ASK_VERSION, "ask_version", &Action_AskVersion);
00578   Register (Action::ACTION_SEND_VERSION, "send_version", &Action_SendVersion);
00579   Register (Action::ACTION_SEND_RANDOM, "send_random", &Action_SendRandom);
00580   Register (Action::ACTION_PING, "ping", &Action_Ping);
00581   Register (Action::ACTION_SYNC_BEGIN, "sync_begin", &Action_SyncBegin);
00582   Register (Action::ACTION_SYNC_END, "sync_end", &Action_SyncEnd);
00583   Register (Action::ACTION_EXPLOSION, "explosion", &Action_Explosion);
00584   Register (Action::ACTION_SET_TARGET, "set_target", &Action_SetTarget);
00585   Register (Action::ACTION_SUPERTUX_STATE, "supertux_state", &Action_SupertuxState);
00586   Register (Action::ACTION_SET_TIMEOUT, "set_timeout", &Action_SetTimeout);
00587   Register (Action::ACTION_CONSTRUCTION_UP, "construction_up", &Action_ConstructionUp);
00588   Register (Action::ACTION_CONSTRUCTION_DOWN, "construction_down", &Action_ConstructionDown);
00589   Register (Action::ACTION_WEAPON_STOP_USE, "weapon_stop_use", &Action_WeaponStopUse);
00590   Register (Action::ACTION_SET_CHARACTER_ENERGY, "set_character_energy", &Action_SetCharacterEnergy);
00591   Register (Action::ACTION_CHAT_MESSAGE, "chat_message", Action_ChatMessage);
00592   Register (Action::ACTION_NICKNAME, "nickname", Action_Nickname);
00593   Register (Action::ACTION_PAUSE, "pause", Action_Pause);
00594   SDL_UnlockMutex(mutex);
00595 }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Function Documentation

void ActionHandler::Exec ( Action a  )  [private]

Definition at line 533 of file action_handler.cpp.

00534 {
00535   MSG_DEBUG("action_handler", "Executing action %s",GetActionName(a->GetType()).c_str());
00536   handler_it it=handler.find(a->GetType());
00537   assert(it != handler.end());
00538   (*it->second) (a);
00539 }

Here is the call graph for this function:

Here is the caller graph for this function:

void ActionHandler::ExecActions (  ) 

Definition at line 485 of file action_handler.cpp.

00486 {
00487   Action * a;
00488   std::list<Action*> to_remove;
00489   std::list<Action*>::iterator it;
00490   assert(mutex!=NULL);
00491   for(it = queue.begin(); it != queue.end() ; ++it)
00492   {
00493     SDL_LockMutex(mutex);
00494     a = (*it);
00495     Time::GetInstance()->RefreshMaxTime((*it)->GetTimestamp());
00496     // If action is in the future, wait for next refresh
00497     if((*it)->GetTimestamp() > Time::GetInstance()->Read()) {
00498       SDL_UnlockMutex(mutex);
00499       continue;
00500     }
00501     SDL_UnlockMutex(mutex);
00502     Exec ((*it));
00503     to_remove.push_back((*it));
00504   }
00505   while(to_remove.size() != 0)
00506   {
00507     a = to_remove.front();
00508     to_remove.pop_front();
00509     queue.remove(a);
00510     delete(a);
00511   }
00512 }

Here is the call graph for this function:

Here is the caller graph for this function:

std::string ActionHandler::GetActionName ( Action::Action_t  action  ) 

Definition at line 541 of file action_handler.cpp.

00542 {
00543   assert(mutex!=NULL);
00544   SDL_LockMutex(mutex);
00545   name_it it=action_name.find(action);
00546   assert(it != action_name.end());
00547   SDL_UnlockMutex(mutex);
00548   return it->second;
00549 }

Here is the caller graph for this function:

ActionHandler * ActionHandler::GetInstance (  )  [static]

Definition at line 55 of file action_handler.cpp.

00056 {
00057   if (singleton == NULL)
00058     singleton = new ActionHandler();
00059   return singleton;
00060 }

Here is the call graph for this function:

Here is the caller graph for this function:

void ActionHandler::NewAction ( Action a,
bool  repeat_to_network = true 
)

Definition at line 514 of file action_handler.cpp.

00515 {
00516   assert(mutex!=NULL);
00517   SDL_LockMutex(mutex);
00518   //  MSG_DEBUG("action.handler","New action : %s",a.out());
00519   //  std::cout << "New action " << a->GetType() << std::endl ;
00520   queue.push_back(a);
00521   //  std::cout << "  queue_size " << queue.size() << std::endl;
00522   SDL_UnlockMutex(mutex);
00523   if (repeat_to_network) network.SendAction(a);
00524 }

Here is the call graph for this function:

Here is the caller graph for this function:

void ActionHandler::Register ( Action::Action_t  action,
const std::string &  name,
callback_t  fct 
) [private]

Definition at line 526 of file action_handler.cpp.

00528 {
00529   handler[action] = fct;
00530   action_name[action] = name;
00531 }

Here is the caller graph for this function:


Member Data Documentation

std::map<Action::Action_t, std::string> ActionHandler::action_name [private]

Definition at line 44 of file action_handler.h.

std::map<Action::Action_t, callback_t> ActionHandler::handler [private]

Definition at line 40 of file action_handler.h.

SDL_mutex* ActionHandler::mutex [private]

Definition at line 36 of file action_handler.h.

std::list<Action*> ActionHandler::queue [private]

Definition at line 48 of file action_handler.h.

ActionHandler * ActionHandler::singleton = NULL [static, private]

Definition at line 50 of file action_handler.h.


The documentation for this class was generated from the following files:
Generated on Mon Jan 1 13:32:15 2007 for Wormux by  doxygen 1.4.7