src/include/action_handler.h

Go to the documentation of this file.
00001 /******************************************************************************
00002  *  Wormux is a convivial mass murder game.
00003  *  Copyright (C) 2001-2004 Lawrence Azzoug.
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
00018  ******************************************************************************
00019  * Define all Wormux actions.
00020  *****************************************************************************/
00021 
00022 #ifndef ACTION_HANDLER_H
00023 #define ACTION_HANDLER_H
00024 //-----------------------------------------------------------------------------
00025 #include <SDL_mutex.h>
00026 #include <map>
00027 #include <list>
00028 #include "action.h"
00029 #include "base.h"
00030 //-----------------------------------------------------------------------------
00031 
00032 class ActionHandler
00033 {
00034 private:
00035   // Mutex needed to be thread safe for the network
00036   SDL_mutex* mutex;
00037 
00038   // Handler for each action
00039   typedef void (*callback_t) (Action *a);
00040   std::map<Action::Action_t, callback_t> handler;
00041   typedef std::map<Action::Action_t, callback_t>::const_iterator handler_it;
00042 
00043   // Action strings
00044   std::map<Action::Action_t, std::string> action_name;
00045   typedef std::map<Action::Action_t, std::string>::const_iterator name_it;
00046 
00047   // Action queue
00048   std::list<Action*> queue;
00049 
00050   static ActionHandler * singleton;
00051 
00052 public:
00053   static ActionHandler * GetInstance();
00054 
00055   void NewAction (Action* a, bool repeat_to_network=true);
00056   void ExecActions ();
00057   std::string GetActionName(Action::Action_t action);
00058 
00059 private:
00060   ActionHandler();
00061 
00062   void Exec (Action *a);
00063   void Register (Action::Action_t action, const std::string &name, callback_t fct);
00064 };
00065 
00066 Action* BuildActionSendCharacterPhysics(int team_no, int char_no);
00067 void SendGameMode();
00068 void SyncCharacters();
00069 
00070 //-----------------------------------------------------------------------------
00071 #endif

Generated on Mon Jan 1 13:10:57 2007 for Wormux by  doxygen 1.4.7