Blender  V2.59
SCA_LogicManager.h
Go to the documentation of this file.
00001 /*
00002  * $Id: SCA_LogicManager.h 36523 2011-05-06 20:18:42Z blendix $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00021  * All rights reserved.
00022  *
00023  * The Original Code is: all of this file.
00024  *
00025  * Contributor(s): none yet.
00026  *
00027  * ***** END GPL LICENSE BLOCK *****
00028  */
00033 #ifndef __KX_LOGICMANAGER
00034 #define __KX_LOGICMANAGER
00035 
00036 #if defined(WIN32) && !defined(FREE_WINDOWS)
00037 #pragma warning (disable:4786)
00038 #endif 
00039 
00040 #include <vector>
00041 //#include "CTR_Map.h"
00042 #include <set>
00043 #include <map>
00044 #include <list>
00045 
00046 #include "CTR_Map.h"
00047 #include "STR_HashedString.h"
00048 #include "Value.h"
00049 #include "SG_QList.h"
00050 
00051 #include "KX_HashedPtr.h"
00052 
00053 using namespace std;
00054 typedef std::list<class SCA_IController*> controllerlist;
00055 typedef std::map<class SCA_ISensor*,controllerlist > sensormap_t;
00056 
00070 #include "SCA_ILogicBrick.h"
00071 #include "SCA_IActuator.h"
00072 #include "SCA_EventManager.h"
00073 
00074 
00075 class SCA_LogicManager
00076 {
00077         vector<class SCA_EventManager*>         m_eventmanagers;
00078         
00079         // SG_DList: Head of objects having activated actuators
00080         //           element: SCA_IObject::m_activeActuators
00081         SG_DList                                                        m_activeActuators;
00082         // SG_DList: Head of objects having activated controllers
00083         //           element: SCA_IObject::m_activeControllers
00084         SG_DList                                                        m_triggeredControllerSet;
00085 
00086         // need to find better way for this
00087         // also known as FactoryManager...
00088         CTR_Map<STR_HashedString,CValue*>       m_mapStringToGameObjects;
00089         CTR_Map<STR_HashedString,void*>         m_mapStringToMeshes;
00090         CTR_Map<STR_HashedString,void*>         m_mapStringToActions;
00091 
00092         CTR_Map<STR_HashedString,void*>         m_map_gamemeshname_to_blendobj;
00093         CTR_Map<CHashedPtr,void*>                       m_map_blendobj_to_gameobj;
00094 public:
00095         SCA_LogicManager();
00096         virtual ~SCA_LogicManager();
00097 
00098         //void  SetKeyboardManager(SCA_KeyboardManager* keyboardmgr) { m_keyboardmgr=keyboardmgr;}
00099         void    RegisterEventManager(SCA_EventManager* eventmgr);
00100         void    RegisterToSensor(SCA_IController* controller,
00101                                                          class SCA_ISensor* sensor);
00102         void    RegisterToActuator(SCA_IController* controller,
00103                                                            class SCA_IActuator* actuator);
00104         
00105         void    BeginFrame(double curtime, double fixedtime);
00106         void    UpdateFrame(double curtime, bool frame);
00107         void    EndFrame();
00108         void    AddActiveActuator(SCA_IActuator* actua,bool event)
00109         {
00110                 actua->SetActive(true);
00111                 actua->Activate(m_activeActuators);
00112                 actua->AddEvent(event);
00113         }
00114 
00115         void    AddTriggeredController(SCA_IController* controller, SCA_ISensor* sensor);
00116         SCA_EventManager*       FindEventManager(int eventmgrtype);
00117         vector<class SCA_EventManager*> GetEventManagers() { return m_eventmanagers; }
00118         
00119         void    RemoveGameObject(const STR_String& gameobjname);
00120 
00124         void    RemoveSensor(SCA_ISensor* sensor);
00125         void    RemoveController(SCA_IController* controller);
00126         void    RemoveActuator(SCA_IActuator* actuator);
00127         
00128 
00129         // for the scripting... needs a FactoryManager later (if we would have time... ;)
00130         void    RegisterMeshName(const STR_String& meshname,void* mesh);
00131         void    UnregisterMeshName(const STR_String& meshname,void* mesh);
00132         CTR_Map<STR_HashedString,void*>&        GetMeshMap() { return m_mapStringToMeshes; };
00133         CTR_Map<STR_HashedString,void*>&        GetActionMap() { return m_mapStringToActions; };
00134         
00135         void    RegisterActionName(const STR_String& actname,void* action);
00136 
00137         void*   GetActionByName (const STR_String& actname);
00138         void*   GetMeshByName(const STR_String& meshname);
00139 
00140         void    RegisterGameObjectName(const STR_String& gameobjname,CValue* gameobj);
00141         class CValue*   GetGameObjectByName(const STR_String& gameobjname);
00142 
00143         void    RegisterGameMeshName(const STR_String& gamemeshname, void* blendobj);
00144         void*   FindBlendObjByGameMeshName(const STR_String& gamemeshname);
00145 
00146         void    RegisterGameObj(void* blendobj, CValue* gameobj);
00147         void    UnregisterGameObj(void* blendobj, CValue* gameobj);
00148         CValue* FindGameObjByBlendObj(void* blendobj);
00149         
00150         
00151 #ifdef WITH_CXX_GUARDEDALLOC
00152 public:
00153         void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:SCA_LogicManager"); }
00154         void operator delete( void *mem ) { MEM_freeN(mem); }
00155 #endif
00156 };
00157 
00158 #endif //__KX_LOGICMANAGER
00159