Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Bolsee <benoit.bolsee@online.be>2009-05-11 00:53:58 +0400
committerBenoit Bolsee <benoit.bolsee@online.be>2009-05-11 00:53:58 +0400
commit386122ada6432b29437c3ca7f1eea2b5b919d377 (patch)
tree88923d82aaf1b87c1498db6112d027297ff1c492 /source/gameengine/GameLogic
parent6f5ef6044dabdd383a91a14c65a2f9f454fb5c42 (diff)
BGE performance, 4th round: logic
This commit extends the technique of dynamic linked list to the logic system to eliminate as much as possible temporaries, map lookup or full scan. The logic engine is now free of memory allocation, which is an important stability factor. The overhead of the logic system is reduced by a factor between 3 and 6 depending on the logic setup. This is the speed-up you can expect on a logic setup using simple bricks. Heavy bricks like python controllers and ray sensors will still take about the same time to execute so the speed up will be less important. The core of the logic engine has been much reworked but the functionality is still the same except for one thing: the priority system on the execution of controllers. The exact same remark applies to actuators but I'll explain for controllers only: Previously, it was possible, with the "executePriority" attribute to set a controller to run before any other controllers in the game. Other than that, the sequential execution of controllers, as defined in Blender was guaranteed by default. With the new system, the sequential execution of controllers is still guaranteed but only within the controllers of one object. the user can no longer set a controller to run before any other controllers in the game. The "executePriority" attribute controls the execution of controllers within one object. The priority is a small number starting from 0 for the first controller and incrementing for each controller. If this missing feature is a must, a special method can be implemented to set a controller to run before all other controllers. Other improvements: - Systematic use of reference in parameter passing to avoid unnecessary data copy - Use pre increment in iterator instead of post increment to avoid temporary allocation - Use const char* instead of STR_String whenever possible to avoid temporary allocation - Fix reference counting bugs (memory leak) - Fix a crash in certain cases of state switching and object deletion - Minor speed up in property sensor - Removal of objects during the game is a lot faster
Diffstat (limited to 'source/gameengine/GameLogic')
-rw-r--r--source/gameengine/GameLogic/CMakeLists.txt1
-rw-r--r--source/gameengine/GameLogic/Makefile1
-rw-r--r--source/gameengine/GameLogic/SCA_2DFilterActuator.cpp2
-rw-r--r--source/gameengine/GameLogic/SCA_2DFilterActuator.h2
-rw-r--r--source/gameengine/GameLogic/SCA_ANDController.cpp11
-rw-r--r--source/gameengine/GameLogic/SCA_ActuatorEventManager.cpp10
-rw-r--r--source/gameengine/GameLogic/SCA_ActuatorSensor.cpp2
-rw-r--r--source/gameengine/GameLogic/SCA_ActuatorSensor.h2
-rw-r--r--source/gameengine/GameLogic/SCA_AlwaysEventManager.cpp5
-rw-r--r--source/gameengine/GameLogic/SCA_AlwaysSensor.cpp2
-rw-r--r--source/gameengine/GameLogic/SCA_AlwaysSensor.h2
-rw-r--r--source/gameengine/GameLogic/SCA_DelaySensor.cpp2
-rw-r--r--source/gameengine/GameLogic/SCA_DelaySensor.h2
-rw-r--r--source/gameengine/GameLogic/SCA_EventManager.cpp7
-rw-r--r--source/gameengine/GameLogic/SCA_EventManager.h5
-rw-r--r--source/gameengine/GameLogic/SCA_ExpressionController.cpp25
-rw-r--r--source/gameengine/GameLogic/SCA_IActuator.cpp75
-rw-r--r--source/gameengine/GameLogic/SCA_IActuator.h61
-rw-r--r--source/gameengine/GameLogic/SCA_IController.cpp88
-rw-r--r--source/gameengine/GameLogic/SCA_IController.h38
-rw-r--r--source/gameengine/GameLogic/SCA_ILogicBrick.cpp10
-rw-r--r--source/gameengine/GameLogic/SCA_ILogicBrick.h11
-rw-r--r--source/gameengine/GameLogic/SCA_IObject.cpp18
-rw-r--r--source/gameengine/GameLogic/SCA_IObject.h30
-rw-r--r--source/gameengine/GameLogic/SCA_IScene.cpp2
-rw-r--r--source/gameengine/GameLogic/SCA_IScene.h2
-rw-r--r--source/gameengine/GameLogic/SCA_ISensor.cpp87
-rw-r--r--source/gameengine/GameLogic/SCA_ISensor.h28
-rw-r--r--source/gameengine/GameLogic/SCA_JoystickManager.cpp11
-rw-r--r--source/gameengine/GameLogic/SCA_JoystickSensor.cpp2
-rw-r--r--source/gameengine/GameLogic/SCA_JoystickSensor.h2
-rw-r--r--source/gameengine/GameLogic/SCA_KeyboardManager.cpp7
-rw-r--r--source/gameengine/GameLogic/SCA_KeyboardSensor.cpp2
-rw-r--r--source/gameengine/GameLogic/SCA_KeyboardSensor.h2
-rw-r--r--source/gameengine/GameLogic/SCA_LogicManager.cpp320
-rw-r--r--source/gameengine/GameLogic/SCA_LogicManager.h50
-rw-r--r--source/gameengine/GameLogic/SCA_MouseManager.cpp6
-rw-r--r--source/gameengine/GameLogic/SCA_MouseSensor.cpp2
-rw-r--r--source/gameengine/GameLogic/SCA_MouseSensor.h2
-rw-r--r--source/gameengine/GameLogic/SCA_NANDController.cpp11
-rw-r--r--source/gameengine/GameLogic/SCA_NORController.cpp11
-rw-r--r--source/gameengine/GameLogic/SCA_ORController.cpp9
-rw-r--r--source/gameengine/GameLogic/SCA_PropertyEventManager.cpp5
-rw-r--r--source/gameengine/GameLogic/SCA_PropertySensor.cpp18
-rw-r--r--source/gameengine/GameLogic/SCA_PropertySensor.h2
-rw-r--r--source/gameengine/GameLogic/SCA_PythonController.cpp17
-rw-r--r--source/gameengine/GameLogic/SCA_RandomEventManager.cpp5
-rw-r--r--source/gameengine/GameLogic/SCA_RandomSensor.cpp2
-rw-r--r--source/gameengine/GameLogic/SCA_RandomSensor.h2
-rw-r--r--source/gameengine/GameLogic/SCA_TimeEventManager.cpp6
-rw-r--r--source/gameengine/GameLogic/SCA_XNORController.cpp11
-rw-r--r--source/gameengine/GameLogic/SCA_XORController.cpp11
-rw-r--r--source/gameengine/GameLogic/SConscript2
53 files changed, 455 insertions, 594 deletions
diff --git a/source/gameengine/GameLogic/CMakeLists.txt b/source/gameengine/GameLogic/CMakeLists.txt
index a7519196d50..449aae3ac84 100644
--- a/source/gameengine/GameLogic/CMakeLists.txt
+++ b/source/gameengine/GameLogic/CMakeLists.txt
@@ -31,6 +31,7 @@ SET(INC
../../../source/kernel/gen_system
../../../intern/string
../../../source/gameengine/Expressions
+ ../../../source/gameengine/Scenegraph
../../../intern/moto/include
../../../source/gameengine/Rasterizer
${PYTHON_INC}
diff --git a/source/gameengine/GameLogic/Makefile b/source/gameengine/GameLogic/Makefile
index 355ece6e8bd..6e9af674549 100644
--- a/source/gameengine/GameLogic/Makefile
+++ b/source/gameengine/GameLogic/Makefile
@@ -39,6 +39,7 @@ include nan_compile.mk
CCFLAGS += $(LEVEL_1_CPP_WARNINGS)
CPPFLAGS += -I../Expressions
+CPPFLAGS += -I../Scenegraph
CPPFLAGS += -I../Rasterizer
CPPFLAGS += -I$(NAN_STRING)/include
CPPFLAGS += -I$(NAN_MOTO)/include
diff --git a/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp b/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp
index fb72eefb4a4..1aaa59ee207 100644
--- a/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp
+++ b/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp
@@ -95,7 +95,7 @@ bool SCA_2DFilterActuator::Update()
}
-void SCA_2DFilterActuator::SetShaderText(STR_String text)
+void SCA_2DFilterActuator::SetShaderText(STR_String& text)
{
m_shaderText = text;
}
diff --git a/source/gameengine/GameLogic/SCA_2DFilterActuator.h b/source/gameengine/GameLogic/SCA_2DFilterActuator.h
index b43dc092ddb..aea3a35d404 100644
--- a/source/gameengine/GameLogic/SCA_2DFilterActuator.h
+++ b/source/gameengine/GameLogic/SCA_2DFilterActuator.h
@@ -60,7 +60,7 @@ public:
PyTypeObject* T=&Type
);
- void SetShaderText(STR_String text);
+ void SetShaderText(STR_String& text);
virtual ~SCA_2DFilterActuator();
virtual bool Update();
diff --git a/source/gameengine/GameLogic/SCA_ANDController.cpp b/source/gameengine/GameLogic/SCA_ANDController.cpp
index 7991e82168f..87f7c612e7c 100644
--- a/source/gameengine/GameLogic/SCA_ANDController.cpp
+++ b/source/gameengine/GameLogic/SCA_ANDController.cpp
@@ -73,19 +73,12 @@ void SCA_ANDController::Trigger(SCA_LogicManager* logicmgr)
}
}
- CValue* newevent = new CBoolValue(sensorresult);
-
for (vector<SCA_IActuator*>::const_iterator i=m_linkedactuators.begin();
!(i==m_linkedactuators.end());i++)
{
- SCA_IActuator* actua = *i;//m_linkedactuators.at(i);
- logicmgr->AddActiveActuator(actua,newevent);
+ SCA_IActuator* actua = *i;
+ logicmgr->AddActiveActuator(actua,sensorresult);
}
-
- // every actuator that needs the event, has a it's own reference to it now so
- // release it (so to be clear: if there is no actuator, it's deleted right now)
- newevent->Release();
-
}
diff --git a/source/gameengine/GameLogic/SCA_ActuatorEventManager.cpp b/source/gameengine/GameLogic/SCA_ActuatorEventManager.cpp
index 768a3a45937..a80b2af55c8 100644
--- a/source/gameengine/GameLogic/SCA_ActuatorEventManager.cpp
+++ b/source/gameengine/GameLogic/SCA_ActuatorEventManager.cpp
@@ -51,17 +51,19 @@ SCA_ActuatorEventManager::~SCA_ActuatorEventManager()
void SCA_ActuatorEventManager::NextFrame()
{
// check for changed actuator
- for (set<SCA_ISensor*>::const_iterator it = m_sensors.begin();!(it==m_sensors.end());it++)
+ SG_DList::iterator<SCA_ISensor> it(m_sensors);
+ for (it.begin();!it.end();++it)
{
- (*it)->Activate(m_logicmgr,NULL);
+ (*it)->Activate(m_logicmgr);
}
}
void SCA_ActuatorEventManager::UpdateFrame()
{
// update the state of actuator before executing them
- for (set<SCA_ISensor*>::const_iterator it = m_sensors.begin();!(it==m_sensors.end());it++)
+ SG_DList::iterator<SCA_ActuatorSensor> it(m_sensors);
+ for (it.begin();!it.end();++it)
{
- ((SCA_ActuatorSensor*)(*it))->Update();
+ (*it)->Update();
}
} \ No newline at end of file
diff --git a/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp b/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp
index 464797fd776..4dad65c5a25 100644
--- a/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp
+++ b/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp
@@ -89,7 +89,7 @@ SCA_ActuatorSensor::~SCA_ActuatorSensor()
-bool SCA_ActuatorSensor::Evaluate(CValue* event)
+bool SCA_ActuatorSensor::Evaluate()
{
if (m_actuator)
{
diff --git a/source/gameengine/GameLogic/SCA_ActuatorSensor.h b/source/gameengine/GameLogic/SCA_ActuatorSensor.h
index 974b2e43d78..6655e08dc70 100644
--- a/source/gameengine/GameLogic/SCA_ActuatorSensor.h
+++ b/source/gameengine/GameLogic/SCA_ActuatorSensor.h
@@ -52,7 +52,7 @@ public:
virtual ~SCA_ActuatorSensor();
virtual CValue* GetReplica();
virtual void Init();
- virtual bool Evaluate(CValue* event);
+ virtual bool Evaluate();
virtual bool IsPositiveTrigger();
virtual void ReParent(SCA_IObject* parent);
void Update();
diff --git a/source/gameengine/GameLogic/SCA_AlwaysEventManager.cpp b/source/gameengine/GameLogic/SCA_AlwaysEventManager.cpp
index 4cd2dfba994..dd3b55abcc9 100644
--- a/source/gameengine/GameLogic/SCA_AlwaysEventManager.cpp
+++ b/source/gameengine/GameLogic/SCA_AlwaysEventManager.cpp
@@ -51,9 +51,10 @@ SCA_AlwaysEventManager::SCA_AlwaysEventManager(class SCA_LogicManager* logicmgr)
void SCA_AlwaysEventManager::NextFrame()
{
- for (set<class SCA_ISensor*>::const_iterator i= m_sensors.begin();!(i==m_sensors.end());i++)
+ SG_DList::iterator<SCA_ISensor> it(m_sensors);
+ for (it.begin();!it.end();++it)
{
- (*i)->Activate(m_logicmgr, NULL);
+ (*it)->Activate(m_logicmgr);
}
}
diff --git a/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp b/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp
index 19d19b6e0be..ff02680f191 100644
--- a/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp
+++ b/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp
@@ -86,7 +86,7 @@ bool SCA_AlwaysSensor::IsPositiveTrigger()
-bool SCA_AlwaysSensor::Evaluate(CValue* event)
+bool SCA_AlwaysSensor::Evaluate()
{
/* Nice! :) */
//return true;
diff --git a/source/gameengine/GameLogic/SCA_AlwaysSensor.h b/source/gameengine/GameLogic/SCA_AlwaysSensor.h
index 769e1e883bc..0f85a641ef1 100644
--- a/source/gameengine/GameLogic/SCA_AlwaysSensor.h
+++ b/source/gameengine/GameLogic/SCA_AlwaysSensor.h
@@ -43,7 +43,7 @@ public:
PyTypeObject* T =&Type);
virtual ~SCA_AlwaysSensor();
virtual CValue* GetReplica();
- virtual bool Evaluate(CValue* event);
+ virtual bool Evaluate();
virtual bool IsPositiveTrigger();
virtual void Init();
diff --git a/source/gameengine/GameLogic/SCA_DelaySensor.cpp b/source/gameengine/GameLogic/SCA_DelaySensor.cpp
index 4752d0eb345..dcdae0b4e75 100644
--- a/source/gameengine/GameLogic/SCA_DelaySensor.cpp
+++ b/source/gameengine/GameLogic/SCA_DelaySensor.cpp
@@ -89,7 +89,7 @@ bool SCA_DelaySensor::IsPositiveTrigger()
return (m_invert ? !m_lastResult : m_lastResult);
}
-bool SCA_DelaySensor::Evaluate(CValue* event)
+bool SCA_DelaySensor::Evaluate()
{
bool trigger = false;
bool result;
diff --git a/source/gameengine/GameLogic/SCA_DelaySensor.h b/source/gameengine/GameLogic/SCA_DelaySensor.h
index 31394fdc961..5ccb33f8a16 100644
--- a/source/gameengine/GameLogic/SCA_DelaySensor.h
+++ b/source/gameengine/GameLogic/SCA_DelaySensor.h
@@ -51,7 +51,7 @@ public:
PyTypeObject* T =&Type);
virtual ~SCA_DelaySensor();
virtual CValue* GetReplica();
- virtual bool Evaluate(CValue* event);
+ virtual bool Evaluate();
virtual bool IsPositiveTrigger();
virtual void Init();
diff --git a/source/gameengine/GameLogic/SCA_EventManager.cpp b/source/gameengine/GameLogic/SCA_EventManager.cpp
index e4fd0379597..d1301541a0a 100644
--- a/source/gameengine/GameLogic/SCA_EventManager.cpp
+++ b/source/gameengine/GameLogic/SCA_EventManager.cpp
@@ -28,6 +28,7 @@
#include <assert.h>
#include "SCA_EventManager.h"
+#include "SCA_ISensor.h"
#ifdef HAVE_CONFIG_H
#include <config.h>
@@ -43,16 +44,18 @@ SCA_EventManager::SCA_EventManager(EVENT_MANAGER_TYPE mgrtype)
SCA_EventManager::~SCA_EventManager()
{
+ // all sensors should be removed
+ assert(m_sensors.Empty());
}
void SCA_EventManager::RegisterSensor(class SCA_ISensor* sensor)
{
- m_sensors.insert(sensor);
+ m_sensors.AddBack(sensor);
}
void SCA_EventManager::RemoveSensor(class SCA_ISensor* sensor)
{
- m_sensors.erase(sensor);
+ sensor->Delink();
}
void SCA_EventManager::NextFrame(double curtime, double fixedtime)
diff --git a/source/gameengine/GameLogic/SCA_EventManager.h b/source/gameengine/GameLogic/SCA_EventManager.h
index 9dbb5a6d24f..5ff55849bfe 100644
--- a/source/gameengine/GameLogic/SCA_EventManager.h
+++ b/source/gameengine/GameLogic/SCA_EventManager.h
@@ -33,11 +33,14 @@
#include <set>
#include <algorithm>
+#include "SG_DList.h"
+
class SCA_EventManager
{
protected:
// use a set to speed-up insertion/removal
- std::set <class SCA_ISensor*> m_sensors;
+ //std::set <class SCA_ISensor*> m_sensors;
+ SG_DList m_sensors;
public:
enum EVENT_MANAGER_TYPE {
diff --git a/source/gameengine/GameLogic/SCA_ExpressionController.cpp b/source/gameengine/GameLogic/SCA_ExpressionController.cpp
index a4e898a808f..8e044b89c71 100644
--- a/source/gameengine/GameLogic/SCA_ExpressionController.cpp
+++ b/source/gameengine/GameLogic/SCA_ExpressionController.cpp
@@ -115,37 +115,14 @@ void SCA_ExpressionController::Trigger(SCA_LogicManager* logicmgr)
value->Release();
}
- //m_exprCache->Release();
- //m_exprCache = NULL;
}
- /*
-
- for (vector<SCA_ISensor*>::const_iterator is=m_linkedsensors.begin();
- !(is==m_linkedsensors.end());is++)
- {
- SCA_ISensor* sensor = *is;
- if (!sensor->IsPositiveTrigger())
- {
- sensorresult = false;
- break;
- }
- }
-
- */
-
- CValue* newevent = new CBoolValue(expressionresult);
-
for (vector<SCA_IActuator*>::const_iterator i=m_linkedactuators.begin();
!(i==m_linkedactuators.end());i++)
{
SCA_IActuator* actua = *i;
- logicmgr->AddActiveActuator(actua,newevent);
+ logicmgr->AddActiveActuator(actua,expressionresult);
}
- //printf("expr %d.",expressionresult);
- // every actuator that needs the event, has a it's own reference to it now so
- // release it (so to be clear: if there is no actuator, it's deleted right now)
- newevent->Release();
}
diff --git a/source/gameengine/GameLogic/SCA_IActuator.cpp b/source/gameengine/GameLogic/SCA_IActuator.cpp
index 214c7dded76..5f71bb3f9e4 100644
--- a/source/gameengine/GameLogic/SCA_IActuator.cpp
+++ b/source/gameengine/GameLogic/SCA_IActuator.cpp
@@ -37,46 +37,13 @@ using namespace std;
SCA_IActuator::SCA_IActuator(SCA_IObject* gameobj,
PyTypeObject* T) :
SCA_ILogicBrick(gameobj,T),
- m_links(0)
+ m_links(0),
+ m_posevent(false),
+ m_negevent(false)
{
// nothing to do
}
-
-
-void SCA_IActuator::RemoveAllEvents()
-{ // remove event queue!
- for (vector<CValue*>::iterator i=m_events.begin(); !(i==m_events.end());i++)
- {
- (*i)->Release();
- }
- m_events.clear();
-}
-
-
-
-
-
-bool SCA_IActuator::IsNegativeEvent() const
-{
- bool bPositiveEvent(false);
- bool bNegativeEvent(false);
-
- for (vector<CValue*>::const_iterator i=m_events.begin(); i!=m_events.end();++i)
- {
- if ((*i)->GetNumber() == 0.0f)
- {
- bNegativeEvent = true;
- } else {
- bPositiveEvent = true;
- }
- }
-
- // if at least 1 positive event, return false
-
- return !bPositiveEvent && bNegativeEvent;
-}
-
bool SCA_IActuator::Update(double curtime, bool frame)
{
if (frame)
@@ -94,7 +61,8 @@ bool SCA_IActuator::Update()
void SCA_IActuator::ProcessReplica()
{
SCA_ILogicBrick::ProcessReplica();
- m_events.clear();
+ RemoveAllEvents();
+ m_linkedcontrollers.clear();
}
@@ -113,3 +81,36 @@ void SCA_IActuator::DecLink()
m_links = 0;
}
}
+
+void SCA_IActuator::LinkToController(SCA_IController* controller)
+{
+ m_linkedcontrollers.push_back(controller);
+}
+
+void SCA_IActuator::UnlinkController(SCA_IController* controller)
+{
+ std::vector<class SCA_IController*>::iterator contit;
+ for (contit = m_linkedcontrollers.begin();!(contit==m_linkedcontrollers.end());++contit)
+ {
+ if ((*contit) == controller)
+ {
+ *contit = m_linkedcontrollers.back();
+ m_linkedcontrollers.pop_back();
+ return;
+ }
+ }
+ printf("Missing link from actuator %s:%s to controller %s:%s\n",
+ m_gameobj->GetName().ReadPtr(), GetName().ReadPtr(),
+ controller->GetParent()->GetName().ReadPtr(), controller->GetName().ReadPtr());
+}
+
+void SCA_IActuator::UnlinkAllControllers()
+{
+ std::vector<class SCA_IController*>::iterator contit;
+ for (contit = m_linkedcontrollers.begin();!(contit==m_linkedcontrollers.end());++contit)
+ {
+ (*contit)->UnlinkActuator(this);
+ }
+ m_linkedcontrollers.clear();
+}
+
diff --git a/source/gameengine/GameLogic/SCA_IActuator.h b/source/gameengine/GameLogic/SCA_IActuator.h
index e5f0a2cf4cc..3055e1d946f 100644
--- a/source/gameengine/GameLogic/SCA_IActuator.h
+++ b/source/gameengine/GameLogic/SCA_IActuator.h
@@ -29,17 +29,33 @@
#ifndef __KX_IACTUATOR
#define __KX_IACTUATOR
-#include "SCA_ILogicBrick.h"
+#include "SCA_IController.h"
#include <vector>
+/*
+ * Use of SG_DList : element of actuator being deactivated
+ * Head: SCA_LogicManager::m_removedActuators
+ * Use of SG_QList : element of activated actuator list of their owner
+ * Head: SCA_IObject::m_activeActuators
+ */
class SCA_IActuator : public SCA_ILogicBrick
{
friend class SCA_LogicManager;
protected:
int m_links; // number of active links to controllers
// when 0, the actuator is automatically stopped
- std::vector<CValue*> m_events;
- void RemoveAllEvents();
+ //std::vector<CValue*> m_events;
+ bool m_posevent;
+ bool m_negevent;
+
+ std::vector<class SCA_IController*> m_linkedcontrollers;
+
+ void RemoveAllEvents()
+ {
+ m_posevent = false;
+ m_negevent = false;
+ }
+
public:
/**
@@ -75,9 +91,13 @@ public:
/**
* Add an event to an actuator.
*/
- void AddEvent(CValue* event)
+ //void AddEvent(CValue* event)
+ void AddEvent(bool event)
{
- m_events.push_back(event);
+ if (event)
+ m_posevent = true;
+ else
+ m_negevent = true;
}
virtual void ProcessReplica();
@@ -88,9 +108,38 @@ public:
* not immediately clear. But usually refers to key-up events
* or events where no action is required.
*/
- bool IsNegativeEvent() const;
+ bool IsNegativeEvent() const
+ {
+ return !m_posevent && m_negevent;
+ }
+
virtual ~SCA_IActuator();
+ /**
+ * remove this actuator from the list of active actuators
+ */
+ void Deactivate()
+ {
+ if (QDelink())
+ // the actuator was in the active list
+ if (m_gameobj->m_activeActuators.QEmpty())
+ // the owner object has no more active actuators, remove it from the global list
+ m_gameobj->m_activeActuators.Delink();
+ }
+
+ void Activate(SG_DList& head)
+ {
+ if (QEmpty())
+ {
+ InsertActiveQList(m_gameobj->m_activeActuators);
+ head.AddBack(&m_gameobj->m_activeActuators);
+ }
+ }
+
+ void LinkToController(SCA_IController* controller);
+ void UnlinkController(class SCA_IController* cont);
+ void UnlinkAllControllers();
+
void ClrLink() { m_links=0; }
void IncLink() { m_links++; }
void DecLink();
diff --git a/source/gameengine/GameLogic/SCA_IController.cpp b/source/gameengine/GameLogic/SCA_IController.cpp
index 24509f6e6ed..f8b081ef050 100644
--- a/source/gameengine/GameLogic/SCA_IController.cpp
+++ b/source/gameengine/GameLogic/SCA_IController.cpp
@@ -41,7 +41,8 @@ SCA_IController::SCA_IController(SCA_IObject* gameobj,
PyTypeObject* T)
:
SCA_ILogicBrick(gameobj,T),
- m_statemask(0)
+ m_statemask(0),
+ m_justActivated(false)
{
}
@@ -49,19 +50,19 @@ SCA_IController::SCA_IController(SCA_IObject* gameobj,
SCA_IController::~SCA_IController()
{
- UnlinkAllActuators();
+ //UnlinkAllActuators();
}
-const std::vector<class SCA_ISensor*>& SCA_IController::GetLinkedSensors()
+std::vector<class SCA_ISensor*>& SCA_IController::GetLinkedSensors()
{
return m_linkedsensors;
}
-const std::vector<class SCA_IActuator*>& SCA_IController::GetLinkedActuators()
+std::vector<class SCA_IActuator*>& SCA_IController::GetLinkedActuators()
{
return m_linkedactuators;
}
@@ -70,13 +71,14 @@ const std::vector<class SCA_IActuator*>& SCA_IController::GetLinkedActuators()
void SCA_IController::UnlinkAllSensors()
{
- if (IsActive())
+ std::vector<class SCA_ISensor*>::iterator sensit;
+ for (sensit = m_linkedsensors.begin();!(sensit==m_linkedsensors.end());++sensit)
{
- std::vector<class SCA_ISensor*>::iterator sensit;
- for (sensit = m_linkedsensors.begin();!(sensit==m_linkedsensors.end());++sensit)
+ if (IsActive())
{
(*sensit)->DecLink();
}
+ (*sensit)->UnlinkController(this);
}
m_linkedsensors.clear();
}
@@ -85,34 +87,18 @@ void SCA_IController::UnlinkAllSensors()
void SCA_IController::UnlinkAllActuators()
{
- if (IsActive())
+ std::vector<class SCA_IActuator*>::iterator actit;
+ for (actit = m_linkedactuators.begin();!(actit==m_linkedactuators.end());++actit)
{
- std::vector<class SCA_IActuator*>::iterator actit;
- for (actit = m_linkedactuators.begin();!(actit==m_linkedactuators.end());++actit)
+ if (IsActive())
{
(*actit)->DecLink();
}
+ (*actit)->UnlinkController(this);
}
m_linkedactuators.clear();
}
-
-
-/*
-void SCA_IController::Trigger(SCA_LogicManager* logicmgr)
-{
- //for (int i=0;i<m_linkedactuators.size();i++)
- for (vector<SCA_IActuator*>::const_iterator i=m_linkedactuators.begin();
- !(i==m_linkedactuators.end());i++)
- {
- SCA_IActuator* actua = *i;//m_linkedactuators.at(i);
-
- logicmgr->AddActiveActuator(actua);
- }
-
-}
-*/
-
void SCA_IController::LinkToActuator(SCA_IActuator* actua)
{
m_linkedactuators.push_back(actua);
@@ -129,18 +115,18 @@ void SCA_IController::UnlinkActuator(class SCA_IActuator* actua)
{
if ((*actit) == actua)
{
- break;
- }
-
- }
- if (!(actit==m_linkedactuators.end()))
- {
- if (IsActive())
- {
- (*actit)->DecLink();
+ if (IsActive())
+ {
+ (*actit)->DecLink();
+ }
+ *actit = m_linkedactuators.back();
+ m_linkedactuators.pop_back();
+ return;
}
- m_linkedactuators.erase(actit);
}
+ printf("Missing link from controller %s:%s to actuator %s:%s\n",
+ m_gameobj->GetName().ReadPtr(), GetName().ReadPtr(),
+ actua->GetParent()->GetName().ReadPtr(), actua->GetName().ReadPtr());
}
void SCA_IController::LinkToSensor(SCA_ISensor* sensor)
@@ -159,20 +145,21 @@ void SCA_IController::UnlinkSensor(class SCA_ISensor* sensor)
{
if ((*sensit) == sensor)
{
- break;
- }
-
- }
- if (!(sensit==m_linkedsensors.end()))
- {
- if (IsActive())
- {
- (*sensit)->DecLink();
+ if (IsActive())
+ {
+ sensor->DecLink();
+ }
+ *sensit = m_linkedsensors.back();
+ m_linkedsensors.pop_back();
+ return;
}
- m_linkedsensors.erase(sensit);
}
+ printf("Missing link from controller %s:%s to sensor %s:%s\n",
+ m_gameobj->GetName().ReadPtr(), GetName().ReadPtr(),
+ sensor->GetParent()->GetName().ReadPtr(), sensor->GetName().ReadPtr());
}
+
void SCA_IController::ApplyState(unsigned int state)
{
std::vector<class SCA_IActuator*>::iterator actit;
@@ -187,13 +174,13 @@ void SCA_IController::ApplyState(unsigned int state)
{
(*actit)->IncLink();
}
+
for (sensit = m_linkedsensors.begin();!(sensit==m_linkedsensors.end());++sensit)
{
(*sensit)->IncLink();
- // remember that this controller just activated that sensor
- (*sensit)->AddNewController(this);
}
SetActive(true);
+ m_justActivated = true;
}
} else if (IsActive())
{
@@ -206,6 +193,7 @@ void SCA_IController::ApplyState(unsigned int state)
(*sensit)->DecLink();
}
SetActive(false);
+ m_justActivated = false;
}
}
@@ -301,7 +289,7 @@ PyObject* SCA_IController::PyGetSensor(PyObject* value)
for (unsigned int index=0;index<m_linkedsensors.size();index++)
{
SCA_ISensor* sensor = m_linkedsensors[index];
- STR_String realname = sensor->GetName();
+ STR_String& realname = sensor->GetName();
if (realname == scriptArg)
{
return sensor->GetProxy();
diff --git a/source/gameengine/GameLogic/SCA_IController.h b/source/gameengine/GameLogic/SCA_IController.h
index 7ed83bc90b8..1b9d8fb0d2b 100644
--- a/source/gameengine/GameLogic/SCA_IController.h
+++ b/source/gameengine/GameLogic/SCA_IController.h
@@ -32,6 +32,11 @@
#include "SCA_ILogicBrick.h"
#include "PyObjectPlus.h"
+/*
+ * Use of SG_DList element: none
+ * Use of SG_QList element: build ordered list of activated controller on the owner object
+ * Head: SCA_IObject::m_activeControllers
+ */
class SCA_IController : public SCA_ILogicBrick
{
Py_Header;
@@ -39,21 +44,48 @@ protected:
std::vector<class SCA_ISensor*> m_linkedsensors;
std::vector<class SCA_IActuator*> m_linkedactuators;
unsigned int m_statemask;
+ bool m_justActivated;
public:
SCA_IController(SCA_IObject* gameobj,PyTypeObject* T);
virtual ~SCA_IController();
virtual void Trigger(class SCA_LogicManager* logicmgr)=0;
void LinkToSensor(SCA_ISensor* sensor);
void LinkToActuator(SCA_IActuator*);
- const std::vector<class SCA_ISensor*>& GetLinkedSensors();
- const std::vector<class SCA_IActuator*>& GetLinkedActuators();
+ std::vector<class SCA_ISensor*>& GetLinkedSensors();
+ std::vector<class SCA_IActuator*>& GetLinkedActuators();
+ void ReserveActuator(int num)
+ {
+ m_linkedactuators.reserve(num);
+ }
void UnlinkAllSensors();
void UnlinkAllActuators();
void UnlinkActuator(class SCA_IActuator* actua);
void UnlinkSensor(class SCA_ISensor* sensor);
void SetState(unsigned int state) { m_statemask = state; }
void ApplyState(unsigned int state);
-
+ void Deactivate()
+ {
+ // the controller can only be part of a sensor m_newControllers list
+ Delink();
+ }
+ bool IsJustActivated()
+ {
+ return m_justActivated;
+ }
+ void ClrJustActivated()
+ {
+ m_justActivated = false;
+ }
+
+ void Activate(SG_DList& head)
+ {
+ if (QEmpty())
+ {
+ InsertActiveQList(m_gameobj->m_activeControllers);
+ head.AddBack(&m_gameobj->m_activeControllers);
+ }
+ }
+
virtual PyObject* py_getattro(PyObject *attr);
virtual PyObject* py_getattro_dict();
virtual int py_setattro(PyObject *attr, PyObject *value);
diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp
index 6de9986b03a..2dc80f54568 100644
--- a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp
+++ b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp
@@ -123,14 +123,14 @@ double SCA_ILogicBrick::GetNumber()
-STR_String SCA_ILogicBrick::GetName()
+STR_String& SCA_ILogicBrick::GetName()
{
return m_name;
}
-void SCA_ILogicBrick::SetName(STR_String name)
+void SCA_ILogicBrick::SetName(const char *name)
{
m_name = name;
}
@@ -222,7 +222,7 @@ PyMethodDef SCA_ILogicBrick::Methods[] = {
PyAttributeDef SCA_ILogicBrick::Attributes[] = {
KX_PYATTRIBUTE_RO_FUNCTION("owner", SCA_ILogicBrick, pyattr_get_owner),
- KX_PYATTRIBUTE_INT_RW("executePriority",0,100000,false,SCA_ILogicBrick,m_Execute_Ueber_Priority),
+ KX_PYATTRIBUTE_INT_RW("executePriority",0,100000,false,SCA_ILogicBrick,m_Execute_Priority),
KX_PYATTRIBUTE_STRING_RO("name", SCA_ILogicBrick, m_name),
{NULL} //Sentinel
};
@@ -286,7 +286,7 @@ PyObject* SCA_ILogicBrick::PySetExecutePriority(PyObject* args)
return NULL;
}
- m_Execute_Ueber_Priority = priority;
+ m_Execute_Priority = priority;
Py_RETURN_NONE;
}
@@ -296,7 +296,7 @@ PyObject* SCA_ILogicBrick::PySetExecutePriority(PyObject* args)
PyObject* SCA_ILogicBrick::PyGetExecutePriority()
{
ShowDeprecationWarning("getExecutePriority()", "the executePriority property");
- return PyInt_FromLong(m_Execute_Ueber_Priority);
+ return PyInt_FromLong(m_Execute_Priority);
}
diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.h b/source/gameengine/GameLogic/SCA_ILogicBrick.h
index b1384e88826..90881c0536f 100644
--- a/source/gameengine/GameLogic/SCA_ILogicBrick.h
+++ b/source/gameengine/GameLogic/SCA_ILogicBrick.h
@@ -71,8 +71,8 @@ public:
virtual const STR_String & GetText();
virtual double GetNumber();
- virtual STR_String GetName();
- virtual void SetName(STR_String name);
+ virtual STR_String& GetName();
+ virtual void SetName(const char *);
bool IsActive()
{
@@ -84,6 +84,13 @@ public:
m_bActive=active;
}
+ // insert in a QList at position corresponding to m_Execute_Priority
+ void InsertActiveQList(SG_QList& head)
+ {
+ SG_QList::iterator<SCA_ILogicBrick> it(head);
+ for(it.begin(); !it.end() && m_Execute_Priority > (*it)->m_Execute_Priority; ++it);
+ it.add_back(this);
+ }
virtual bool LessComparedTo(SCA_ILogicBrick* other);
diff --git a/source/gameengine/GameLogic/SCA_IObject.cpp b/source/gameengine/GameLogic/SCA_IObject.cpp
index 7eaa5c607be..8962c8e8580 100644
--- a/source/gameengine/GameLogic/SCA_IObject.cpp
+++ b/source/gameengine/GameLogic/SCA_IObject.cpp
@@ -70,7 +70,7 @@ SCA_IObject::~SCA_IObject()
}
for (ita = m_actuators.begin(); !(ita==m_actuators.end()); ++ita)
{
- ((CValue*)(*ita))->Release();
+ (*ita)->Delete();
}
//T_InterpolatorList::iterator i;
@@ -110,7 +110,7 @@ void SCA_IObject::RegisterActuator(SCA_IActuator* act)
void SCA_IObject::UnregisterActuator(SCA_IActuator* act)
{
SCA_ActuatorList::iterator ita;
- for (ita = m_registeredActuators.begin(); ita != m_registeredActuators.end(); ita++)
+ for (ita = m_registeredActuators.begin(); ita != m_registeredActuators.end(); ++ita)
{
if ((*ita) == act) {
(*ita) = m_registeredActuators.back();
@@ -171,7 +171,7 @@ SCA_ISensor* SCA_IObject::FindSensor(const STR_String& sensorname)
{
SCA_ISensor* foundsensor = NULL;
- for (SCA_SensorList::iterator its = m_sensors.begin();!(its==m_sensors.end());its++)
+ for (SCA_SensorList::iterator its = m_sensors.begin();!(its==m_sensors.end());++its)
{
if ((*its)->GetName() == sensorname)
{
@@ -188,7 +188,7 @@ SCA_IController* SCA_IObject::FindController(const STR_String& controllername)
{
SCA_IController* foundcontroller = NULL;
- for (SCA_ControllerList::iterator itc = m_controllers.begin();!(itc==m_controllers.end());itc++)
+ for (SCA_ControllerList::iterator itc = m_controllers.begin();!(itc==m_controllers.end());++itc)
{
if ((*itc)->GetName() == controllername)
{
@@ -205,7 +205,7 @@ SCA_IActuator* SCA_IObject::FindActuator(const STR_String& actuatorname)
{
SCA_IActuator* foundactuator = NULL;
- for (SCA_ActuatorList::iterator ita = m_actuators.begin();!(ita==m_actuators.end());ita++)
+ for (SCA_ActuatorList::iterator ita = m_actuators.begin();!(ita==m_actuators.end());++ita)
{
if ((*ita)->GetName() == actuatorname)
{
@@ -272,7 +272,7 @@ void SCA_IObject::Suspend()
SCA_SensorList::iterator i = m_sensors.begin();
while (i != m_sensors.end()) {
(*i)->Suspend();
- i++;
+ ++i;
}
}
}
@@ -287,7 +287,7 @@ void SCA_IObject::Resume(void)
SCA_SensorList::iterator i = m_sensors.begin();
while (i != m_sensors.end()) {
(*i)->Resume();
- i++;
+ ++i;
}
}
}
@@ -307,7 +307,7 @@ void SCA_IObject::SetState(unsigned int state)
if (tmpstate != m_state)
{
// update the status of the controllers
- for (contit = m_controllers.begin(); contit != m_controllers.end(); contit++)
+ for (contit = m_controllers.begin(); contit != m_controllers.end(); ++contit)
{
(*contit)->ApplyState(tmpstate);
}
@@ -315,7 +315,7 @@ void SCA_IObject::SetState(unsigned int state)
m_state = state;
if (m_state != tmpstate)
{
- for (contit = m_controllers.begin(); contit != m_controllers.end(); contit++)
+ for (contit = m_controllers.begin(); contit != m_controllers.end(); ++contit)
{
(*contit)->ApplyState(m_state);
}
diff --git a/source/gameengine/GameLogic/SCA_IObject.h b/source/gameengine/GameLogic/SCA_IObject.h
index 10cf551aeb6..281c72ecd46 100644
--- a/source/gameengine/GameLogic/SCA_IObject.h
+++ b/source/gameengine/GameLogic/SCA_IObject.h
@@ -52,10 +52,24 @@ class SCA_IObject : public CValue
Py_Header;
protected:
+ friend class SCA_IActuator;
+ friend class SCA_IController;
SCA_SensorList m_sensors;
SCA_ControllerList m_controllers;
SCA_ActuatorList m_actuators;
SCA_ActuatorList m_registeredActuators; // actuators that use a pointer to this object
+
+ // SG_Dlist: element of objects with active actuators
+ // Head: SCA_LogicManager::m_activeActuators
+ // SG_QList: Head of active actuators list on this object
+ // Elements: SCA_IActuator
+ SG_QList m_activeActuators;
+ // SG_Dlist: element of objects with active controllers
+ // Head: SCA_LogicManager::m_activeControllers
+ // SG_QList: Head of active controller list on this object
+ // Elements: SCA_IController
+ SG_QList m_activeControllers;
+
static class MT_Point3 m_sDummy;
/**
@@ -95,10 +109,26 @@ public:
{
return m_actuators;
}
+ SG_QList& GetActiveActuators()
+ {
+ return m_activeActuators;
+ }
void AddSensor(SCA_ISensor* act);
+ void ReserveSensor(int num)
+ {
+ m_sensors.reserve(num);
+ }
void AddController(SCA_IController* act);
+ void ReserveController(int num)
+ {
+ m_controllers.reserve(num);
+ }
void AddActuator(SCA_IActuator* act);
+ void ReserveActuator(int num)
+ {
+ m_actuators.reserve(num);
+ }
void RegisterActuator(SCA_IActuator* act);
void UnregisterActuator(SCA_IActuator* act);
diff --git a/source/gameengine/GameLogic/SCA_IScene.cpp b/source/gameengine/GameLogic/SCA_IScene.cpp
index 9fbeb706910..86b176a38b0 100644
--- a/source/gameengine/GameLogic/SCA_IScene.cpp
+++ b/source/gameengine/GameLogic/SCA_IScene.cpp
@@ -50,7 +50,7 @@ SCA_IScene::SCA_IScene()
void SCA_IScene::RemoveAllDebugProperties()
{
for (std::vector<SCA_DebugProp*>::iterator it = m_debugList.begin();
- !(it==m_debugList.end());it++)
+ !(it==m_debugList.end());++it)
{
delete (*it);
}
diff --git a/source/gameengine/GameLogic/SCA_IScene.h b/source/gameengine/GameLogic/SCA_IScene.h
index d18778a37c2..b641efc6ee1 100644
--- a/source/gameengine/GameLogic/SCA_IScene.h
+++ b/source/gameengine/GameLogic/SCA_IScene.h
@@ -52,7 +52,7 @@ public:
int lifespan=0)=0;
virtual void RemoveObject(class CValue* gameobj)=0;
virtual void DelayedRemoveObject(class CValue* gameobj)=0;
- virtual void DelayedReleaseObject(class CValue* gameobj)=0;
+ //virtual void DelayedReleaseObject(class CValue* gameobj)=0;
virtual void ReplaceMesh(class CValue* gameobj,
void* meshobj)=0;
diff --git a/source/gameengine/GameLogic/SCA_ISensor.cpp b/source/gameengine/GameLogic/SCA_ISensor.cpp
index 1e9a4521df5..2783bf14600 100644
--- a/source/gameengine/GameLogic/SCA_ISensor.cpp
+++ b/source/gameengine/GameLogic/SCA_ISensor.cpp
@@ -45,7 +45,7 @@ void SCA_ISensor::ReParent(SCA_IObject* parent)
SCA_ILogicBrick::ReParent(parent);
// will be done when the sensor is activated
//m_eventmgr->RegisterSensor(this);
- this->SetActive(false);
+ //this->SetActive(false);
}
@@ -77,6 +77,12 @@ SCA_ISensor::~SCA_ISensor()
// intentionally empty
}
+void SCA_ISensor::ProcessReplica()
+{
+ SCA_ILogicBrick::ProcessReplica();
+ m_linkedcontrollers.clear();
+}
+
bool SCA_ISensor::IsPositiveTrigger() {
bool result = false;
@@ -150,29 +156,72 @@ void SCA_ISensor::RegisterToManager()
// sensor is just activated, initialize it
Init();
m_state = false;
- m_newControllers.erase(m_newControllers.begin(), m_newControllers.end());
m_eventmgr->RegisterSensor(this);
}
+void SCA_ISensor::LinkToController(SCA_IController* controller)
+{
+ m_linkedcontrollers.push_back(controller);
+}
+
+void SCA_ISensor::UnlinkController(SCA_IController* controller)
+{
+ std::vector<class SCA_IController*>::iterator contit;
+ for (contit = m_linkedcontrollers.begin();!(contit==m_linkedcontrollers.end());++contit)
+ {
+ if ((*contit) == controller)
+ {
+ *contit = m_linkedcontrollers.back();
+ m_linkedcontrollers.pop_back();
+ return;
+ }
+ }
+ printf("Missing link from sensor %s:%s to controller %s:%s\n",
+ m_gameobj->GetName().ReadPtr(), GetName().ReadPtr(),
+ controller->GetParent()->GetName().ReadPtr(), controller->GetName().ReadPtr());
+}
+
+void SCA_ISensor::UnlinkAllControllers()
+{
+ std::vector<class SCA_IController*>::iterator contit;
+ for (contit = m_linkedcontrollers.begin();!(contit==m_linkedcontrollers.end());++contit)
+ {
+ (*contit)->UnlinkSensor(this);
+ }
+ m_linkedcontrollers.clear();
+}
+
void SCA_ISensor::UnregisterToManager()
{
m_eventmgr->RemoveSensor(this);
+ m_links = 0;
}
-void SCA_ISensor::Activate(class SCA_LogicManager* logicmgr, CValue* event)
+void SCA_ISensor::ActivateControllers(class SCA_LogicManager* logicmgr)
+{
+ for(vector<SCA_IController*>::const_iterator c= m_linkedcontrollers.begin();
+ c!=m_linkedcontrollers.end();++c)
+ {
+ SCA_IController* contr = *c;
+ if (contr->IsActive())
+ logicmgr->AddTriggeredController(contr, this);
+ }
+}
+
+void SCA_ISensor::Activate(class SCA_LogicManager* logicmgr)
{
// calculate if a __triggering__ is wanted
// don't evaluate a sensor that is not connected to any controller
if (m_links && !m_suspended) {
- bool result = this->Evaluate(event);
+ bool result = this->Evaluate();
// store the state for the rest of the logic system
m_prev_state = m_state;
m_state = this->IsPositiveTrigger();
if (result) {
// the sensor triggered this frame
if (m_state || !m_tap) {
- logicmgr->AddActivatedSensor(this);
+ ActivateControllers(logicmgr);
// reset these counters so that pulse are synchronized with transition
m_pos_ticks = 0;
m_neg_ticks = 0;
@@ -190,7 +239,7 @@ void SCA_ISensor::Activate(class SCA_LogicManager* logicmgr, CValue* event)
if (m_pos_ticks > m_pulse_frequency) {
if ( m_state )
{
- logicmgr->AddActivatedSensor(this);
+ ActivateControllers(logicmgr);
result = true;
}
m_pos_ticks = 0;
@@ -203,7 +252,8 @@ void SCA_ISensor::Activate(class SCA_LogicManager* logicmgr, CValue* event)
if (m_neg_ticks > m_pulse_frequency) {
if (!m_state )
{
- logicmgr->AddActivatedSensor(this);
+ ActivateControllers(logicmgr);
+ result = true;
}
m_neg_ticks = 0;
}
@@ -218,27 +268,24 @@ void SCA_ISensor::Activate(class SCA_LogicManager* logicmgr, CValue* event)
if (m_prev_state)
{
// but it triggered on previous frame => send a negative pulse
- logicmgr->AddActivatedSensor(this);
+ ActivateControllers(logicmgr);
+ result = true;
}
// in any case, absence of trigger means sensor off
m_state = false;
}
}
- if (!m_newControllers.empty())
+ if (!result && m_level)
{
- if (!IsActive() && m_level)
+ // This level sensor is connected to at least one controller that was just made
+ // active but it did not generate an event yet, do it now to those controllers only
+ for(vector<SCA_IController*>::const_iterator c= m_linkedcontrollers.begin();
+ c!=m_linkedcontrollers.end();++c)
{
- // This level sensor is connected to at least one controller that was just made
- // active but it did not generate an event yet, do it now to those controllers only
- for (std::vector<SCA_IController*>::iterator ci=m_newControllers.begin();
- ci != m_newControllers.end(); ci++)
- {
- logicmgr->AddTriggeredController(*ci, this);
- }
+ SCA_IController* contr = *c;
+ if (contr->IsJustActivated())
+ logicmgr->AddTriggeredController(contr, this);
}
- // clear the list. Instead of using clear, which also release the memory,
- // use erase, which keeps the memory available for next time.
- m_newControllers.erase(m_newControllers.begin(), m_newControllers.end());
}
}
}
diff --git a/source/gameengine/GameLogic/SCA_ISensor.h b/source/gameengine/GameLogic/SCA_ISensor.h
index 7bbef5fef2f..9aeda728caf 100644
--- a/source/gameengine/GameLogic/SCA_ISensor.h
+++ b/source/gameengine/GameLogic/SCA_ISensor.h
@@ -32,16 +32,21 @@
#ifndef __SCA_ISENSOR
#define __SCA_ISENSOR
-#include "SCA_ILogicBrick.h"
+#include "SCA_IController.h"
#include <vector>
/**
* Interface Class for all logic Sensors. Implements
- * pulsemode,pulsefrequency */
+ * pulsemode,pulsefrequency
+ * Use of SG_DList element: link sensors to their respective event manager
+ * Head: SCA_EventManager::m_sensors
+ * Use of SG_QList element: not used
+ */
class SCA_ISensor : public SCA_ILogicBrick
{
Py_Header;
+protected:
class SCA_EventManager* m_eventmgr;
/** Pulse positive pulses? */
@@ -83,8 +88,7 @@ class SCA_ISensor : public SCA_ILogicBrick
/** previous state (for tap option) */
bool m_prev_state;
- /** list of controllers that have just activated this sensor because of a state change */
- std::vector<class SCA_IController*> m_newControllers;
+ std::vector<class SCA_IController*> m_linkedcontrollers;
public:
SCA_ISensor(SCA_IObject* gameobj,
@@ -97,8 +101,8 @@ public:
/* an implementation on this level. It requires an evaluate on the lower */
/* level of individual sensors. Mapping the old activate()s is easy. */
/* The IsPosTrig() also has to change, to keep things consistent. */
- void Activate(class SCA_LogicManager* logicmgr,CValue* event);
- virtual bool Evaluate(CValue* event) = 0;
+ void Activate(class SCA_LogicManager* logicmgr);
+ virtual bool Evaluate() = 0;
virtual bool IsPositiveTrigger();
virtual void Init();
@@ -121,6 +125,16 @@ public:
virtual void RegisterToManager();
virtual void UnregisterToManager();
+ void ReserveController(int num)
+ {
+ m_linkedcontrollers.reserve(num);
+ }
+ void LinkToController(SCA_IController* controller);
+ void UnlinkController(SCA_IController* controller);
+ void UnlinkAllControllers();
+ void ActivateControllers(class SCA_LogicManager* logicmgr);
+
+ virtual void ProcessReplica();
virtual double GetNumber();
@@ -139,8 +153,6 @@ public:
/** Resume sensing. */
void Resume();
- void AddNewController(class SCA_IController* controller)
- { m_newControllers.push_back(controller); }
void ClrLink()
{ m_links = 0; }
void IncLink()
diff --git a/source/gameengine/GameLogic/SCA_JoystickManager.cpp b/source/gameengine/GameLogic/SCA_JoystickManager.cpp
index f3ce549a637..ff8f3b1c81f 100644
--- a/source/gameengine/GameLogic/SCA_JoystickManager.cpp
+++ b/source/gameengine/GameLogic/SCA_JoystickManager.cpp
@@ -59,20 +59,21 @@ SCA_JoystickManager::~SCA_JoystickManager()
void SCA_JoystickManager::NextFrame(double curtime,double deltatime)
{
- if (m_sensors.size()==0) {
+ if (m_sensors.Empty()) {
return;
}
else {
- set<SCA_ISensor*>::iterator it;
+ ;
#ifndef DISABLE_SDL
SCA_Joystick::HandleEvents(); /* Handle all SDL Joystick events */
#endif
- for (it = m_sensors.begin(); it != m_sensors.end(); it++)
+ SG_DList::iterator<SCA_JoystickSensor> it(m_sensors);
+ for (it.begin();!it.end();++it)
{
- SCA_JoystickSensor* joysensor = (SCA_JoystickSensor*)(*it);
+ SCA_JoystickSensor* joysensor = *it;
if(!joysensor->IsSuspended())
{
- joysensor->Activate(m_logicmgr, NULL);
+ joysensor->Activate(m_logicmgr);
}
}
}
diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp
index 34d63a4ee2b..906d454b728 100644
--- a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp
+++ b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp
@@ -102,7 +102,7 @@ bool SCA_JoystickSensor::IsPositiveTrigger()
}
-bool SCA_JoystickSensor::Evaluate(CValue* event)
+bool SCA_JoystickSensor::Evaluate()
{
SCA_Joystick *js = m_pJoystickMgr->GetJoystickDevice(m_joyindex);
bool result = false;
diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.h b/source/gameengine/GameLogic/SCA_JoystickSensor.h
index 20fff66f66c..e8185d1911e 100644
--- a/source/gameengine/GameLogic/SCA_JoystickSensor.h
+++ b/source/gameengine/GameLogic/SCA_JoystickSensor.h
@@ -110,7 +110,7 @@ public:
virtual ~SCA_JoystickSensor();
virtual CValue* GetReplica();
- virtual bool Evaluate(CValue* event);
+ virtual bool Evaluate();
virtual bool IsPositiveTrigger();
virtual void Init();
diff --git a/source/gameengine/GameLogic/SCA_KeyboardManager.cpp b/source/gameengine/GameLogic/SCA_KeyboardManager.cpp
index 6a96442b124..279adab94d8 100644
--- a/source/gameengine/GameLogic/SCA_KeyboardManager.cpp
+++ b/source/gameengine/GameLogic/SCA_KeyboardManager.cpp
@@ -62,12 +62,11 @@ void SCA_KeyboardManager::NextFrame()
{
//const SCA_InputEvent& event = GetEventValue(SCA_IInputDevice::KX_EnumInputs inputcode)=0;
// cerr << "SCA_KeyboardManager::NextFrame"<< endl;
- set<SCA_ISensor*>::iterator it;
- for (it=m_sensors.begin(); it != m_sensors.end(); it++)
+ SG_DList::iterator<SCA_ISensor> it(m_sensors);
+ for (it.begin();!it.end();++it)
{
- (*it)->Activate(m_logicmanager,NULL);
+ (*it)->Activate(m_logicmanager);
}
-
}
bool SCA_KeyboardManager::IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode)
diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp
index a9ea4272531..f8ee8ed8b41 100644
--- a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp
+++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp
@@ -118,7 +118,7 @@ bool SCA_KeyboardSensor::TriggerOnAllKeys()
-bool SCA_KeyboardSensor::Evaluate(CValue* eventval)
+bool SCA_KeyboardSensor::Evaluate()
{
bool result = false;
bool reset = m_reset && m_level;
diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.h b/source/gameengine/GameLogic/SCA_KeyboardSensor.h
index 1dd6ea21fcd..033225cd9be 100644
--- a/source/gameengine/GameLogic/SCA_KeyboardSensor.h
+++ b/source/gameengine/GameLogic/SCA_KeyboardSensor.h
@@ -102,7 +102,7 @@ public:
short int GetHotkey();
- virtual bool Evaluate(CValue* event);
+ virtual bool Evaluate();
virtual bool IsPositiveTrigger();
bool TriggerOnAllKeys();
diff --git a/source/gameengine/GameLogic/SCA_LogicManager.cpp b/source/gameengine/GameLogic/SCA_LogicManager.cpp
index c43875a0047..74370f89cf2 100644
--- a/source/gameengine/GameLogic/SCA_LogicManager.cpp
+++ b/source/gameengine/GameLogic/SCA_LogicManager.cpp
@@ -49,42 +49,12 @@ SCA_LogicManager::SCA_LogicManager()
SCA_LogicManager::~SCA_LogicManager()
{
- /* AddRef() is not used when the objects are added to m_mapStringToGameObjects
- so Release() should not be used either. The memory leak big is fixed
- in BL_ConvertBlenderObjects()
-
- int numgameobj = m_mapStringToGameObjects.size();
- for (int i = 0; i < numgameobj; i++)
- {
- CValue** gameobjptr = m_mapStringToGameObjects.at(i);
- assert(gameobjptr);
- if (gameobjptr)
- (*gameobjptr)->Release();
-
- }
- */
- /*for (int i=0;i<m_sensorcontrollermap.size();i++)
- {
- vector<SCA_IController*>* controllerarray = *(m_sensorcontrollermap[i]);
- delete controllerarray;
- }
- */
- for (vector<SCA_EventManager*>::iterator it = m_eventmanagers.begin();!(it==m_eventmanagers.end());it++)
+ for (vector<SCA_EventManager*>::iterator it = m_eventmanagers.begin();!(it==m_eventmanagers.end());++it)
{
delete (*it);
}
m_eventmanagers.clear();
- m_sensorcontrollermapje.clear();
- m_removedActuators.clear();
- m_activeActuators.clear();
-}
-
-// this function is a performance helper when the scene is destoyed
-// without it, the map updated for each object... a massive slow down when there are
-// large number of objects. By clearing the map upfront we avoid the waster of time.
-void SCA_LogicManager::RemoveSensorMap()
-{
- m_sensorcontrollermapje.clear();
+ assert(m_activeActuators.Empty());
}
/*
@@ -178,62 +148,30 @@ void* SCA_LogicManager::FindBlendObjByGameMeshName(const STR_String& gamemeshnam
void SCA_LogicManager::RemoveSensor(SCA_ISensor* sensor)
{
- sensormap_t::const_iterator mit = m_sensorcontrollermapje.find(sensor);
- if (mit != m_sensorcontrollermapje.end())
- {
- const controllerlist& contlist = mit->second;
- for (controllerlist::const_iterator c= contlist.begin();!(c==contlist.end());c++)
- {
- (*c)->UnlinkSensor(sensor);
- }
- m_sensorcontrollermapje.erase(sensor);
- }
+ sensor->UnlinkAllControllers();
sensor->UnregisterToManager();
}
void SCA_LogicManager::RemoveController(SCA_IController* controller)
{
- sensormap_t::iterator sit;
- sit = m_sensorcontrollermapje.begin();
- if (sit==m_sensorcontrollermapje.end())
- {
- //TRICK: either there is no sensor at all, or the scene is being deleted
- //(see KX_Scene::~KX_Scene()). In the first case, this is harmless.
- //In the second case, we cannot rely on the sensor being still available,
- //make the controller inactive to avoid link count.
- //Need a better solution, maybe something similar to m_removedActuators.
- controller->SetActive(false);
- }
controller->UnlinkAllSensors();
controller->UnlinkAllActuators();
- for (;!(sit==m_sensorcontrollermapje.end());++sit)
- {
- (*sit).second.remove(controller);
- }
+ controller->Deactivate();
}
-void SCA_LogicManager::RemoveDestroyedActuator(SCA_IActuator* actuator)
+void SCA_LogicManager::RemoveActuator(SCA_IActuator* actuator)
{
- m_removedActuators.push_back(SmartActuatorPtr(actuator,0));
- // take care that no controller can use this actuator again !
-
- sensormap_t::const_iterator sit;
- for (sit = m_sensorcontrollermapje.begin();!(sit==m_sensorcontrollermapje.end());++sit)
- {
- const controllerlist& contlist = sit->second;
- for (list<SCA_IController*>::const_iterator c= contlist.begin();!(c==contlist.end());c++)
- {
- (*c)->UnlinkActuator(actuator);
- }
- }
+ actuator->UnlinkAllControllers();
+ actuator->Deactivate();
+ actuator->SetActive(false);
}
void SCA_LogicManager::RegisterToSensor(SCA_IController* controller,SCA_ISensor* sensor)
{
- m_sensorcontrollermapje[sensor].push_back(controller);
+ sensor->LinkToController(controller);
controller->LinkToSensor(sensor);
}
@@ -241,6 +179,7 @@ void SCA_LogicManager::RegisterToSensor(SCA_IController* controller,SCA_ISensor*
void SCA_LogicManager::RegisterToActuator(SCA_IController* controller,SCA_IActuator* actua)
{
+ actua->LinkToController(controller);
controller->LinkToActuator(actua);
}
@@ -251,88 +190,60 @@ void SCA_LogicManager::BeginFrame(double curtime, double fixedtime)
for (vector<SCA_EventManager*>::const_iterator ie=m_eventmanagers.begin(); !(ie==m_eventmanagers.end()); ie++)
(*ie)->NextFrame(curtime, fixedtime);
- // for this frame, look up for activated sensors, and build the collection of triggered controllers
- // int numsensors = this->m_activatedsensors.size(); /*unused*/
-
- for (vector<SCA_ISensor*>::const_iterator is=m_activatedsensors.begin();
- !(is==m_activatedsensors.end());is++)
+ for(SG_QList* obj = (SG_QList*)m_triggeredControllerSet.Remove();
+ obj != NULL;
+ obj = (SG_QList*)m_triggeredControllerSet.Remove())
{
- SCA_ISensor* sensor = *is;
- const controllerlist& contlist = m_sensorcontrollermapje[sensor];
- for (list<SCA_IController*>::const_iterator c= contlist.begin();
- !(c==contlist.end());c++)
+ for(SCA_IController* contr = (SCA_IController*)obj->QRemove();
+ contr != NULL;
+ contr = (SCA_IController*)obj->QRemove())
{
- SCA_IController* contr = *c;//controllerarray->at(c);
- if (contr->IsActive())
- {
- m_triggeredControllerSet.insert(SmartControllerPtr(contr,0));
- // So that the controller knows which sensor has activited it.
- // Only needed for the python controller though.
- if (contr->GetType() == &SCA_PythonController::Type)
- {
- SCA_PythonController* pythonController = (SCA_PythonController*)contr;
- pythonController->AddTriggeredSensor(sensor);
- }
- }
+ contr->Trigger(this);
+ contr->ClrJustActivated();
}
- //sensor->SetActive(false);
- }
-
-
- // int numtriggered = triggeredControllerSet.size(); /*unused*/
- for (set<SmartControllerPtr>::iterator tit=m_triggeredControllerSet.begin();
- !(tit==m_triggeredControllerSet.end());tit++)
- {
- (*tit)->Trigger(this);
}
- m_triggeredControllerSet.clear();
}
void SCA_LogicManager::UpdateFrame(double curtime, bool frame)
{
- vector<SmartActuatorPtr>::iterator ra;
- for (ra = m_removedActuators.begin(); !(ra == m_removedActuators.end()); ra++)
- {
- m_activeActuators.erase(*ra);
- (*ra)->SetActive(false);
- }
- m_removedActuators.clear();
-
- // About to run actuators, but before update the sensors for those which depends on actuators
for (vector<SCA_EventManager*>::const_iterator ie=m_eventmanagers.begin(); !(ie==m_eventmanagers.end()); ie++)
(*ie)->UpdateFrame();
- for (set<SmartActuatorPtr>::iterator ia = m_activeActuators.begin();!(ia==m_activeActuators.end());ia++)
+ SG_DList::iterator<SG_QList> io(m_activeActuators);
+ for (io.begin(); !io.end(); ++io)
{
- //SCA_IActuator* actua = *ia;
- if (!(*ia)->Update(curtime, frame))
- {
- //*ia = m_activeactuators.back();
- m_removedActuators.push_back(*ia);
-
- (*ia)->SetActive(false);
- //m_activeactuators.pop_back();
- } else if ((*ia)->IsNoLink())
+ SG_QList::iterator<SCA_IActuator> ia(*(*io));
+ for (ia.begin(); !ia.end(); ++ia)
{
- // This actuator has no more links but it still active
- // make sure it will get a negative event on next frame to stop it
- // Do this check after Update() rather than before to make sure
- // that all the actuators that are activated at same time than a state
- // actuator have a chance to execute.
- CValue* event = new CBoolValue(false);
- (*ia)->RemoveAllEvents();
- (*ia)->AddEvent(event);
+ SCA_IActuator* actua = *ia;
+ if (!actua->Update(curtime, frame))
+ {
+ // cannot deactive the actuator now as it will disturb the list
+ m_removedActuators.AddBack(actua);
+ actua->SetActive(false);
+ } else if (actua->IsNoLink())
+ {
+ // This actuator has no more links but it still active
+ // make sure it will get a negative event on next frame to stop it
+ // Do this check after Update() rather than before to make sure
+ // that all the actuators that are activated at same time than a state
+ // actuator have a chance to execute.
+ bool event = false;
+ actua->RemoveAllEvents();
+ actua->AddEvent(event);
+ }
}
}
-
- for ( ra = m_removedActuators.begin(); !(ra == m_removedActuators.end()); ra++)
+
+ for (SCA_IActuator* act = (SCA_IActuator*)m_removedActuators.Remove();
+ act != NULL;
+ act = (SCA_IActuator*)m_removedActuators.Remove())
{
- m_activeActuators.erase(*ra);
- (*ra)->SetActive(false);
+ act->Deactivate();
+ act->SetActive(false);
}
- m_removedActuators.clear();
}
@@ -381,39 +292,17 @@ void SCA_LogicManager::RegisterActionName(const STR_String& actname,void* action
void SCA_LogicManager::EndFrame()
{
- for (vector<SCA_ISensor*>::const_iterator is=m_activatedsensors.begin();
- !(is==m_activatedsensors.end());is++)
- {
- SCA_ISensor* sensor = *is;
- sensor->SetActive(false);
- }
- m_activatedsensors.clear();
-
for (vector<SCA_EventManager*>::const_iterator ie=m_eventmanagers.begin();
!(ie==m_eventmanagers.end());ie++)
{
(*ie)->EndFrame();
}
-
-
}
-
-void SCA_LogicManager::AddActivatedSensor(SCA_ISensor* sensor)
-{
- // each frame, only add sensor once, and to avoid a seek, or bloated container
- // hold a flag in each sensor, with the 'framenr'
- if (!sensor->IsActive())
- {
- sensor->SetActive(true);
- m_activatedsensors.push_back(sensor);
- }
-}
-
void SCA_LogicManager::AddTriggeredController(SCA_IController* controller, SCA_ISensor* sensor)
{
- m_triggeredControllerSet.insert(SmartControllerPtr(controller,0));
+ controller->Activate(m_triggeredControllerSet);
// so that the controller knows which sensor has activited it
// only needed for python controller
if (controller->GetType() == &SCA_PythonController::Type)
@@ -424,14 +313,11 @@ void SCA_LogicManager::AddTriggeredController(SCA_IController* controller, SCA_I
}
-void SCA_LogicManager::AddActiveActuator(SCA_IActuator* actua,CValue* event)
+void SCA_LogicManager::AddActiveActuator(SCA_IActuator* actua,bool event)
{
- if (!actua->IsActive())
- {
- actua->SetActive(true);
- m_activeActuators.insert(SmartActuatorPtr(actua,0));
- }
- actua->AddEvent(event->AddRef());
+ actua->SetActive(true);
+ actua->Activate(m_activeActuators);
+ actua->AddEvent(event);
}
@@ -453,109 +339,3 @@ SCA_EventManager* SCA_LogicManager::FindEventManager(int eventmgrtype)
}
return eventmgr;
}
-
-
-
-SmartActuatorPtr::SmartActuatorPtr(const SmartActuatorPtr& other)
-{
- this->m_actuator = other.m_actuator;
- this->m_actuator->AddRef();
-}
-
-
-
-SmartActuatorPtr::SmartActuatorPtr(SCA_IActuator* actua,int dummy)
-: m_actuator(actua)
-{
- actua->AddRef();
-}
-
-
-
-SmartActuatorPtr::~SmartActuatorPtr()
-{
- m_actuator->Release();
-}
-
-
-
-bool SmartActuatorPtr::operator <(const SmartActuatorPtr& other) const
-{
-
- return m_actuator->LessComparedTo(*other);
-}
-
-
-
-bool SmartActuatorPtr::operator ==(const SmartActuatorPtr& other) const
-{
- bool result2 = other->LessComparedTo(m_actuator);
- return (m_actuator->LessComparedTo(*other) && result2);
-}
-
-
-
-SCA_IActuator* SmartActuatorPtr::operator->() const
-{
- return m_actuator;
-}
-
-
-
-SCA_IActuator* SmartActuatorPtr::operator*() const
-{
- return m_actuator;
-}
-
-
-
-SmartControllerPtr::SmartControllerPtr(const SmartControllerPtr& copy)
-{
- this->m_controller = copy.m_controller;
- this->m_controller->AddRef();
-}
-
-
-
-SmartControllerPtr::SmartControllerPtr(SCA_IController* contr,int dummy)
-: m_controller(contr)
-{
- m_controller->AddRef();
-}
-
-
-
-SmartControllerPtr::~SmartControllerPtr()
-{
- m_controller->Release();
-}
-
-
-
-bool SmartControllerPtr::operator <(const SmartControllerPtr& other) const
-{
- return m_controller->LessComparedTo(*other);
-}
-
-
-
-bool SmartControllerPtr::operator ==(const SmartControllerPtr& other) const
-{
- return (m_controller->LessComparedTo(*other) && other->LessComparedTo(m_controller));
-}
-
-
-
-SCA_IController* SmartControllerPtr::operator->() const
-{
- return m_controller;
-}
-
-
-
-SCA_IController* SmartControllerPtr::operator*() const
-{
- return m_controller;
-}
-
-
diff --git a/source/gameengine/GameLogic/SCA_LogicManager.h b/source/gameengine/GameLogic/SCA_LogicManager.h
index 17971c219e5..0d610c9cc46 100644
--- a/source/gameengine/GameLogic/SCA_LogicManager.h
+++ b/source/gameengine/GameLogic/SCA_LogicManager.h
@@ -43,6 +43,7 @@
#include "GEN_Map.h"
#include "STR_HashedString.h"
#include "Value.h"
+#include "SG_QList.h"
#include "KX_HashedPtr.h"
@@ -65,44 +66,17 @@ typedef std::map<class SCA_ISensor*,controllerlist > sensormap_t;
#include "SCA_ILogicBrick.h"
-// todo: make this into a template, but first I want to think about what exactly to put in
-class SmartActuatorPtr
-{
- SCA_IActuator* m_actuator;
-public:
- SmartActuatorPtr(SCA_IActuator* actua,int dummy);
- SmartActuatorPtr(const SmartActuatorPtr& other);
- virtual ~SmartActuatorPtr();
- bool operator <(const SmartActuatorPtr& other) const;
- bool operator ==(const SmartActuatorPtr& other) const;
- SCA_IActuator* operator->() const;
- SCA_IActuator* operator*() const;
-
-};
-
-class SmartControllerPtr
-{
- SCA_IController* m_controller;
-public:
- SmartControllerPtr(const SmartControllerPtr& copy);
- SmartControllerPtr(SCA_IController* contr,int dummy);
- virtual ~SmartControllerPtr();
- bool operator <(const SmartControllerPtr& other) const;
- bool operator ==(const SmartControllerPtr& other) const;
- SCA_IController* operator->() const;
- SCA_IController* operator*() const;
-
-};
class SCA_LogicManager
{
vector<class SCA_EventManager*> m_eventmanagers;
- vector<class SCA_ISensor*> m_activatedsensors;
- set<class SmartActuatorPtr> m_activeActuators;
- set<class SmartControllerPtr> m_triggeredControllerSet;
-
- sensormap_t m_sensorcontrollermapje;
+ // SG_DList: Head of objects having activated actuators
+ // element: SCA_IObject::m_activeActuators
+ SG_DList m_activeActuators;
+ // SG_DList: Head of objects having activated controllers
+ // element: SCA_IObject::m_activeControllers
+ SG_DList m_triggeredControllerSet;
// need to find better way for this
// also known as FactoryManager...
@@ -113,12 +87,11 @@ class SCA_LogicManager
GEN_Map<STR_HashedString,void*> m_map_gamemeshname_to_blendobj;
GEN_Map<CHashedPtr,void*> m_map_blendobj_to_gameobj;
- vector<SmartActuatorPtr> m_removedActuators;
+ // head of actuators being deactivated during the logic update
+ SG_DList m_removedActuators;
public:
SCA_LogicManager();
virtual ~SCA_LogicManager();
- // can ONLY be used during scene destruction, avoid massive slow down when scene has many many objects
- void RemoveSensorMap();
//void SetKeyboardManager(SCA_KeyboardManager* keyboardmgr) { m_keyboardmgr=keyboardmgr;}
void RegisterEventManager(SCA_EventManager* eventmgr);
@@ -130,8 +103,7 @@ public:
void BeginFrame(double curtime, double fixedtime);
void UpdateFrame(double curtime, bool frame);
void EndFrame();
- void AddActivatedSensor(SCA_ISensor* sensor);
- void AddActiveActuator(SCA_IActuator* sensor,class CValue* event);
+ void AddActiveActuator(SCA_IActuator* sensor,bool event);
void AddTriggeredController(SCA_IController* controller, SCA_ISensor* sensor);
SCA_EventManager* FindEventManager(int eventmgrtype);
@@ -142,7 +114,7 @@ public:
*/
void RemoveSensor(SCA_ISensor* sensor);
void RemoveController(SCA_IController* controller);
- void RemoveDestroyedActuator(SCA_IActuator* actuator);
+ void RemoveActuator(SCA_IActuator* actuator);
// for the scripting... needs a FactoryManager later (if we would have time... ;)
diff --git a/source/gameengine/GameLogic/SCA_MouseManager.cpp b/source/gameengine/GameLogic/SCA_MouseManager.cpp
index ca875dad07c..d407647cec3 100644
--- a/source/gameengine/GameLogic/SCA_MouseManager.cpp
+++ b/source/gameengine/GameLogic/SCA_MouseManager.cpp
@@ -75,8 +75,8 @@ void SCA_MouseManager::NextFrame()
{
if (m_mousedevice)
{
- set<SCA_ISensor*>::iterator it;
- for (it=m_sensors.begin(); it!=m_sensors.end(); it++)
+ SG_DList::iterator<SCA_ISensor> it(m_sensors);
+ for (it.begin();!it.end();++it)
{
SCA_MouseSensor* mousesensor = (SCA_MouseSensor*)(*it);
// (0,0) is the Upper Left corner in our local window
@@ -93,7 +93,7 @@ void SCA_MouseManager::NextFrame()
mousesensor->setX(mx);
mousesensor->setY(my);
- mousesensor->Activate(m_logicmanager,NULL);
+ mousesensor->Activate(m_logicmanager);
}
}
}
diff --git a/source/gameengine/GameLogic/SCA_MouseSensor.cpp b/source/gameengine/GameLogic/SCA_MouseSensor.cpp
index 46be6ad9e16..c5e1c3c0441 100644
--- a/source/gameengine/GameLogic/SCA_MouseSensor.cpp
+++ b/source/gameengine/GameLogic/SCA_MouseSensor.cpp
@@ -144,7 +144,7 @@ SCA_IInputDevice::KX_EnumInputs SCA_MouseSensor::GetHotKey()
-bool SCA_MouseSensor::Evaluate(CValue* event)
+bool SCA_MouseSensor::Evaluate()
{
bool result = false;
bool reset = m_reset && m_level;
diff --git a/source/gameengine/GameLogic/SCA_MouseSensor.h b/source/gameengine/GameLogic/SCA_MouseSensor.h
index 528237475db..6d6302b514a 100644
--- a/source/gameengine/GameLogic/SCA_MouseSensor.h
+++ b/source/gameengine/GameLogic/SCA_MouseSensor.h
@@ -97,7 +97,7 @@ class SCA_MouseSensor : public SCA_ISensor
virtual ~SCA_MouseSensor();
virtual CValue* GetReplica();
- virtual bool Evaluate(CValue* event);
+ virtual bool Evaluate();
virtual void Init();
virtual bool IsPositiveTrigger();
short int GetModeKey();
diff --git a/source/gameengine/GameLogic/SCA_NANDController.cpp b/source/gameengine/GameLogic/SCA_NANDController.cpp
index df62f91aaed..d27aea5e6f7 100644
--- a/source/gameengine/GameLogic/SCA_NANDController.cpp
+++ b/source/gameengine/GameLogic/SCA_NANDController.cpp
@@ -73,19 +73,12 @@ void SCA_NANDController::Trigger(SCA_LogicManager* logicmgr)
}
}
- CValue* newevent = new CBoolValue(sensorresult);
-
for (vector<SCA_IActuator*>::const_iterator i=m_linkedactuators.begin();
!(i==m_linkedactuators.end());i++)
{
- SCA_IActuator* actua = *i;//m_linkedactuators.at(i);
- logicmgr->AddActiveActuator(actua,newevent);
+ SCA_IActuator* actua = *i;
+ logicmgr->AddActiveActuator(actua,sensorresult);
}
-
- // every actuator that needs the event, has a it's own reference to it now so
- // release it (so to be clear: if there is no actuator, it's deleted right now)
- newevent->Release();
-
}
diff --git a/source/gameengine/GameLogic/SCA_NORController.cpp b/source/gameengine/GameLogic/SCA_NORController.cpp
index b87af965a50..6c9141636b2 100644
--- a/source/gameengine/GameLogic/SCA_NORController.cpp
+++ b/source/gameengine/GameLogic/SCA_NORController.cpp
@@ -73,19 +73,12 @@ void SCA_NORController::Trigger(SCA_LogicManager* logicmgr)
}
}
- CValue* newevent = new CBoolValue(sensorresult);
-
for (vector<SCA_IActuator*>::const_iterator i=m_linkedactuators.begin();
!(i==m_linkedactuators.end());i++)
{
- SCA_IActuator* actua = *i;//m_linkedactuators.at(i);
- logicmgr->AddActiveActuator(actua,newevent);
+ SCA_IActuator* actua = *i;
+ logicmgr->AddActiveActuator(actua,sensorresult);
}
-
- // every actuator that needs the event, has a it's own reference to it now so
- // release it (so to be clear: if there is no actuator, it's deleted right now)
- newevent->Release();
-
}
diff --git a/source/gameengine/GameLogic/SCA_ORController.cpp b/source/gameengine/GameLogic/SCA_ORController.cpp
index 7aa58b6c320..42c0a67d657 100644
--- a/source/gameengine/GameLogic/SCA_ORController.cpp
+++ b/source/gameengine/GameLogic/SCA_ORController.cpp
@@ -80,17 +80,12 @@ void SCA_ORController::Trigger(SCA_LogicManager* logicmgr)
is++;
}
- CValue* newevent = new CBoolValue(sensorresult);
-
for (vector<SCA_IActuator*>::const_iterator i=m_linkedactuators.begin();
!(i==m_linkedactuators.end());i++)
{
- SCA_IActuator* actua = *i;//m_linkedactuators.at(i);
- logicmgr->AddActiveActuator(actua,newevent);
+ SCA_IActuator* actua = *i;
+ logicmgr->AddActiveActuator(actua,sensorresult);
}
-
-
- newevent->Release();
}
/* ------------------------------------------------------------------------- */
diff --git a/source/gameengine/GameLogic/SCA_PropertyEventManager.cpp b/source/gameengine/GameLogic/SCA_PropertyEventManager.cpp
index e5e3f9cced5..764465309df 100644
--- a/source/gameengine/GameLogic/SCA_PropertyEventManager.cpp
+++ b/source/gameengine/GameLogic/SCA_PropertyEventManager.cpp
@@ -50,8 +50,9 @@ SCA_PropertyEventManager::~SCA_PropertyEventManager()
void SCA_PropertyEventManager::NextFrame()
{
// check for changed properties
- for (set<SCA_ISensor*>::const_iterator it = m_sensors.begin();!(it==m_sensors.end());it++)
+ SG_DList::iterator<SCA_ISensor> it(m_sensors);
+ for (it.begin();!it.end();++it)
{
- (*it)->Activate(m_logicmgr,NULL);
+ (*it)->Activate(m_logicmgr);
}
}
diff --git a/source/gameengine/GameLogic/SCA_PropertySensor.cpp b/source/gameengine/GameLogic/SCA_PropertySensor.cpp
index e8a291b0a92..2632cbd3dac 100644
--- a/source/gameengine/GameLogic/SCA_PropertySensor.cpp
+++ b/source/gameengine/GameLogic/SCA_PropertySensor.cpp
@@ -37,6 +37,7 @@
#include "StringValue.h"
#include "SCA_EventManager.h"
#include "SCA_LogicManager.h"
+#include "BoolValue.h"
#ifdef HAVE_CONFIG_H
#include <config.h>
@@ -152,7 +153,7 @@ SCA_PropertySensor::~SCA_PropertySensor()
-bool SCA_PropertySensor::Evaluate(CValue* event)
+bool SCA_PropertySensor::Evaluate()
{
bool result = CheckPropertyCondition();
bool reset = m_reset && m_level;
@@ -182,17 +183,14 @@ bool SCA_PropertySensor::CheckPropertyCondition()
CValue* orgprop = GetParent()->FindIdentifier(m_checkpropname);
if (!orgprop->IsError())
{
- STR_String testprop = orgprop->GetText();
+ const STR_String& testprop = orgprop->GetText();
// Force strings to upper case, to avoid confusion in
// bool tests. It's stupid the prop's identity is lost
// on the way here...
- if ((testprop == "TRUE") || (testprop == "FALSE")) {
- STR_String checkprop = m_checkpropval;
- checkprop.Upper();
- result = (testprop == checkprop);
- } else {
- result = (orgprop->GetText() == m_checkpropval);
+ if ((&testprop == &CBoolValue::sTrueString) || (&testprop == &CBoolValue::sFalseString)) {
+ m_checkpropval.Upper();
}
+ result = (testprop == m_checkpropval);
}
orgprop->Release();
@@ -232,8 +230,8 @@ bool SCA_PropertySensor::CheckPropertyCondition()
CValue* vallie = m_range_expr->Calculate();
if (vallie)
{
- STR_String errtext = vallie->GetText();
- if (errtext == "TRUE")
+ const STR_String& errtext = vallie->GetText();
+ if (&errtext == &CBoolValue::sTrueString)
{
result = true;
} else
diff --git a/source/gameengine/GameLogic/SCA_PropertySensor.h b/source/gameengine/GameLogic/SCA_PropertySensor.h
index 7abf4d44a5b..538ecd65949 100644
--- a/source/gameengine/GameLogic/SCA_PropertySensor.h
+++ b/source/gameengine/GameLogic/SCA_PropertySensor.h
@@ -81,7 +81,7 @@ public:
void PrecalculateRangeExpression();
bool CheckPropertyCondition();
- virtual bool Evaluate(CValue* event);
+ virtual bool Evaluate();
virtual bool IsPositiveTrigger();
virtual CValue* FindIdentifier(const STR_String& identifiername);
diff --git a/source/gameengine/GameLogic/SCA_PythonController.cpp b/source/gameengine/GameLogic/SCA_PythonController.cpp
index 063a7b47321..212366e6526 100644
--- a/source/gameengine/GameLogic/SCA_PythonController.cpp
+++ b/source/gameengine/GameLogic/SCA_PythonController.cpp
@@ -178,7 +178,7 @@ SCA_IActuator* SCA_PythonController::LinkedActuatorFromPy(PyObject *value)
if (PyString_Check(value)) {
/* get the actuator from the name */
char *name= PyString_AsString(value);
- for(it = lacts.begin(); it!= lacts.end(); it++) {
+ for(it = lacts.begin(); it!= lacts.end(); ++it) {
if( name == (*it)->GetName() ) {
return *it;
}
@@ -186,7 +186,7 @@ SCA_IActuator* SCA_PythonController::LinkedActuatorFromPy(PyObject *value)
}
else if (BGE_PROXY_CHECK_TYPE(value)) {
PyObjectPlus *value_plus= BGE_PROXY_REF(value);
- for(it = lacts.begin(); it!= lacts.end(); it++) {
+ for(it = lacts.begin(); it!= lacts.end(); ++it) {
if( static_cast<SCA_IActuator*>(value_plus) == (*it) ) {
return *it;
}
@@ -215,9 +215,8 @@ PyObject* SCA_PythonController::sPyAddActiveActuator(PyObject* self, PyObject* a
if(actu==NULL)
return NULL;
- CValue* boolval = new CBoolValue(activate!=0);
+ bool boolval = (activate!=0);
m_sCurrentLogicManager->AddActiveActuator((SCA_IActuator*)actu,boolval);
- boolval->Release();
Py_RETURN_NONE;
}
@@ -473,7 +472,7 @@ void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr)
Py_DECREF(excdict);
}
- m_triggeredSensors.erase(m_triggeredSensors.begin(), m_triggeredSensors.end());
+ m_triggeredSensors.clear();
m_sCurrentController = NULL;
}
@@ -499,9 +498,7 @@ PyObject* SCA_PythonController::PyActivate(PyObject *value)
if(actu==NULL)
return NULL;
- CValue* boolval = new CBoolValue(true);
- m_sCurrentLogicManager->AddActiveActuator((SCA_IActuator*)actu, boolval);
- boolval->Release();
+ m_sCurrentLogicManager->AddActiveActuator((SCA_IActuator*)actu, true);
Py_RETURN_NONE;
}
@@ -511,9 +508,7 @@ PyObject* SCA_PythonController::PyDeActivate(PyObject *value)
if(actu==NULL)
return NULL;
- CValue* boolval = new CBoolValue(false);
- m_sCurrentLogicManager->AddActiveActuator((SCA_IActuator*)actu, boolval);
- boolval->Release();
+ m_sCurrentLogicManager->AddActiveActuator((SCA_IActuator*)actu, false);
Py_RETURN_NONE;
}
diff --git a/source/gameengine/GameLogic/SCA_RandomEventManager.cpp b/source/gameengine/GameLogic/SCA_RandomEventManager.cpp
index 156478d866d..976597aa812 100644
--- a/source/gameengine/GameLogic/SCA_RandomEventManager.cpp
+++ b/source/gameengine/GameLogic/SCA_RandomEventManager.cpp
@@ -50,9 +50,10 @@ SCA_RandomEventManager::SCA_RandomEventManager(class SCA_LogicManager* logicmgr)
void SCA_RandomEventManager::NextFrame()
{
- for (set<class SCA_ISensor*>::const_iterator i= m_sensors.begin();!(i==m_sensors.end());i++)
+ SG_DList::iterator<SCA_ISensor> it(m_sensors);
+ for (it.begin();!it.end();++it)
{
- (*i)->Activate(m_logicmgr, NULL);
+ (*it)->Activate(m_logicmgr);
}
}
diff --git a/source/gameengine/GameLogic/SCA_RandomSensor.cpp b/source/gameengine/GameLogic/SCA_RandomSensor.cpp
index 5c109bac024..1581a29480e 100644
--- a/source/gameengine/GameLogic/SCA_RandomSensor.cpp
+++ b/source/gameengine/GameLogic/SCA_RandomSensor.cpp
@@ -89,7 +89,7 @@ bool SCA_RandomSensor::IsPositiveTrigger()
}
-bool SCA_RandomSensor::Evaluate(CValue* event)
+bool SCA_RandomSensor::Evaluate()
{
/* Random generator is the generator from Line 25 of Table 1 in */
/* [KNUTH 1981, The Art of Computer Programming Vol. 2 */
diff --git a/source/gameengine/GameLogic/SCA_RandomSensor.h b/source/gameengine/GameLogic/SCA_RandomSensor.h
index 63a96dd72d0..27b41841f0b 100644
--- a/source/gameengine/GameLogic/SCA_RandomSensor.h
+++ b/source/gameengine/GameLogic/SCA_RandomSensor.h
@@ -52,7 +52,7 @@ public:
PyTypeObject* T=&Type);
virtual ~SCA_RandomSensor();
virtual CValue* GetReplica();
- virtual bool Evaluate(CValue* event);
+ virtual bool Evaluate();
virtual bool IsPositiveTrigger();
virtual void Init();
diff --git a/source/gameengine/GameLogic/SCA_TimeEventManager.cpp b/source/gameengine/GameLogic/SCA_TimeEventManager.cpp
index b7fadd3d62c..911ea772bef 100644
--- a/source/gameengine/GameLogic/SCA_TimeEventManager.cpp
+++ b/source/gameengine/GameLogic/SCA_TimeEventManager.cpp
@@ -52,7 +52,7 @@ SCA_TimeEventManager::SCA_TimeEventManager(SCA_LogicManager* logicmgr)
SCA_TimeEventManager::~SCA_TimeEventManager()
{
for (vector<CValue*>::iterator it = m_timevalues.begin();
- !(it == m_timevalues.end()); it++)
+ !(it == m_timevalues.end()); ++it)
{
(*it)->Release();
}
@@ -80,7 +80,7 @@ void SCA_TimeEventManager::NextFrame(double curtime, double fixedtime)
// update sensors, but ... need deltatime !
for (vector<CValue*>::iterator it = m_timevalues.begin();
- !(it == m_timevalues.end()); it++)
+ !(it == m_timevalues.end()); ++it)
{
float newtime = (*it)->GetNumber() + fixedtime;
floatval->SetFloat(newtime);
@@ -104,7 +104,7 @@ void SCA_TimeEventManager::AddTimeProperty(CValue* timeval)
void SCA_TimeEventManager::RemoveTimeProperty(CValue* timeval)
{
for (vector<CValue*>::iterator it = m_timevalues.begin();
- !(it == m_timevalues.end()); it++)
+ !(it == m_timevalues.end()); ++it)
{
if ((*it) == timeval)
{
diff --git a/source/gameengine/GameLogic/SCA_XNORController.cpp b/source/gameengine/GameLogic/SCA_XNORController.cpp
index 9b0fe51c5b8..aee8e26c21a 100644
--- a/source/gameengine/GameLogic/SCA_XNORController.cpp
+++ b/source/gameengine/GameLogic/SCA_XNORController.cpp
@@ -77,19 +77,12 @@ void SCA_XNORController::Trigger(SCA_LogicManager* logicmgr)
}
}
- CValue* newevent = new CBoolValue(sensorresult);
-
for (vector<SCA_IActuator*>::const_iterator i=m_linkedactuators.begin();
!(i==m_linkedactuators.end());i++)
{
- SCA_IActuator* actua = *i;//m_linkedactuators.at(i);
- logicmgr->AddActiveActuator(actua,newevent);
+ SCA_IActuator* actua = *i;
+ logicmgr->AddActiveActuator(actua,sensorresult);
}
-
- // every actuator that needs the event, has a it's own reference to it now so
- // release it (so to be clear: if there is no actuator, it's deleted right now)
- newevent->Release();
-
}
diff --git a/source/gameengine/GameLogic/SCA_XORController.cpp b/source/gameengine/GameLogic/SCA_XORController.cpp
index 9232120075f..5afb3a750f5 100644
--- a/source/gameengine/GameLogic/SCA_XORController.cpp
+++ b/source/gameengine/GameLogic/SCA_XORController.cpp
@@ -77,19 +77,12 @@ void SCA_XORController::Trigger(SCA_LogicManager* logicmgr)
}
}
- CValue* newevent = new CBoolValue(sensorresult);
-
for (vector<SCA_IActuator*>::const_iterator i=m_linkedactuators.begin();
!(i==m_linkedactuators.end());i++)
{
- SCA_IActuator* actua = *i;//m_linkedactuators.at(i);
- logicmgr->AddActiveActuator(actua,newevent);
+ SCA_IActuator* actua = *i;
+ logicmgr->AddActiveActuator(actua,sensorresult);
}
-
- // every actuator that needs the event, has a it's own reference to it now so
- // release it (so to be clear: if there is no actuator, it's deleted right now)
- newevent->Release();
-
}
diff --git a/source/gameengine/GameLogic/SConscript b/source/gameengine/GameLogic/SConscript
index ebf225f728f..189c39ee237 100644
--- a/source/gameengine/GameLogic/SConscript
+++ b/source/gameengine/GameLogic/SConscript
@@ -5,7 +5,7 @@ sources = env.Glob('*.cpp') + env.Glob('Joystick/*.cpp')
incs = '. #/source/kernel/gen_system #/intern/string'
incs += ' #/source/gameengine/Expressions #/intern/moto/include'
-incs += ' #/source/gameengine/Rasterizer'
+incs += ' #/source/gameengine/Rasterizer #/source/gameengine/Scenegraph'
incs += ' ' + env['BF_PYTHON_INC']