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