4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): none yet.
27 * ***** END GPL LICENSE BLOCK *****
28 * Regulates the top-level logic behaviour for one scene.
30 #ifndef __KX_LOGICMANAGER
31 #define __KX_LOGICMANAGER
33 #if defined(WIN32) && !defined(FREE_WINDOWS)
34 #pragma warning (disable:4786)
38 //#include "GEN_Map.h"
44 #include "STR_HashedString.h"
48 #include "KX_HashedPtr.h"
51 typedef std::list<class SCA_IController*> controllerlist;
52 typedef std::map<class SCA_ISensor*,controllerlist > sensormap_t;
55 * This manager handles sensor, controllers and actuators.
56 * logic executes each frame the following way:
57 * find triggering sensors
58 * build list of controllers that are triggered by these triggering sensors
59 * process all triggered controllers
60 * during this phase actuators can be added to the active actuator list
61 * process all active actuators
62 * clear triggering sensors
63 * clear triggered controllers
64 * (actuators may be active during a longer timeframe)
67 #include "SCA_ILogicBrick.h"
68 #include "SCA_IActuator.h"
69 #include "SCA_EventManager.h"
72 class SCA_LogicManager
74 vector<class SCA_EventManager*> m_eventmanagers;
76 // SG_DList: Head of objects having activated actuators
77 // element: SCA_IObject::m_activeActuators
78 SG_DList m_activeActuators;
79 // SG_DList: Head of objects having activated controllers
80 // element: SCA_IObject::m_activeControllers
81 SG_DList m_triggeredControllerSet;
83 // need to find better way for this
84 // also known as FactoryManager...
85 GEN_Map<STR_HashedString,CValue*> m_mapStringToGameObjects;
86 GEN_Map<STR_HashedString,void*> m_mapStringToMeshes;
87 GEN_Map<STR_HashedString,void*> m_mapStringToActions;
89 GEN_Map<STR_HashedString,void*> m_map_gamemeshname_to_blendobj;
90 GEN_Map<CHashedPtr,void*> m_map_blendobj_to_gameobj;
93 virtual ~SCA_LogicManager();
95 //void SetKeyboardManager(SCA_KeyboardManager* keyboardmgr) { m_keyboardmgr=keyboardmgr;}
96 void RegisterEventManager(SCA_EventManager* eventmgr);
97 void RegisterToSensor(SCA_IController* controller,
98 class SCA_ISensor* sensor);
99 void RegisterToActuator(SCA_IController* controller,
100 class SCA_IActuator* actuator);
102 void BeginFrame(double curtime, double fixedtime);
103 void UpdateFrame(double curtime, bool frame);
105 void AddActiveActuator(SCA_IActuator* actua,bool event)
107 actua->SetActive(true);
108 actua->Activate(m_activeActuators);
109 actua->AddEvent(event);
112 void AddTriggeredController(SCA_IController* controller, SCA_ISensor* sensor);
113 SCA_EventManager* FindEventManager(int eventmgrtype);
114 vector<class SCA_EventManager*> GetEventManagers() { return m_eventmanagers; }
116 void RemoveGameObject(const STR_String& gameobjname);
119 * remove Logic Bricks from the running logicmanager
121 void RemoveSensor(SCA_ISensor* sensor);
122 void RemoveController(SCA_IController* controller);
123 void RemoveActuator(SCA_IActuator* actuator);
126 // for the scripting... needs a FactoryManager later (if we would have time... ;)
127 void RegisterMeshName(const STR_String& meshname,void* mesh);
128 void UnregisterMeshName(const STR_String& meshname,void* mesh);
129 GEN_Map<STR_HashedString,void*>& GetMeshMap() { return m_mapStringToMeshes; };
131 void RegisterActionName(const STR_String& actname,void* action);
133 void* GetActionByName (const STR_String& actname);
134 void* GetMeshByName(const STR_String& meshname);
136 void RegisterGameObjectName(const STR_String& gameobjname,CValue* gameobj);
137 class CValue* GetGameObjectByName(const STR_String& gameobjname);
139 void RegisterGameMeshName(const STR_String& gamemeshname, void* blendobj);
140 void* FindBlendObjByGameMeshName(const STR_String& gamemeshname);
142 void RegisterGameObj(void* blendobj, CValue* gameobj);
143 void UnregisterGameObj(void* blendobj, CValue* gameobj);
144 CValue* FindGameObjByBlendObj(void* blendobj);
147 #ifdef WITH_CXX_GUARDEDALLOC
149 void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:SCA_LogicManager"); }
150 void operator delete( void *mem ) { MEM_freeN(mem); }
154 #endif //__KX_LOGICMANAGER