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-03-12 01:11:52 +0300
committerBenoit Bolsee <benoit.bolsee@online.be>2009-03-12 01:11:52 +0300
commita37cec2802d96306426f41c64f6ed69ab3680355 (patch)
treed0ad9ba1a8fb64072a6427e82b0fc4aa2a153d83 /source/gameengine/GameLogic
parent0ac3e7016048a7e66285b3539c6e86cf83a4cb06 (diff)
BGE patch 18368: Modulus (ie %) expression controller in BGE. Implement a cache for the expression for better performance.
Diffstat (limited to 'source/gameengine/GameLogic')
-rw-r--r--source/gameengine/GameLogic/SCA_ExpressionController.cpp35
-rw-r--r--source/gameengine/GameLogic/SCA_ExpressionController.h6
-rw-r--r--source/gameengine/GameLogic/SCA_ILogicBrick.h1
-rw-r--r--source/gameengine/GameLogic/SCA_IObject.cpp4
-rw-r--r--source/gameengine/GameLogic/SCA_ISensor.h5
-rw-r--r--source/gameengine/GameLogic/SCA_PropertySensor.h4
6 files changed, 41 insertions, 14 deletions
diff --git a/source/gameengine/GameLogic/SCA_ExpressionController.cpp b/source/gameengine/GameLogic/SCA_ExpressionController.cpp
index e9a543c9f31..8ed46beb7f3 100644
--- a/source/gameengine/GameLogic/SCA_ExpressionController.cpp
+++ b/source/gameengine/GameLogic/SCA_ExpressionController.cpp
@@ -49,7 +49,8 @@ SCA_ExpressionController::SCA_ExpressionController(SCA_IObject* gameobj,
const STR_String& exprtext,
PyTypeObject* T)
:SCA_IController(gameobj,T),
- m_exprText(exprtext)
+ m_exprText(exprtext),
+ m_exprCache(NULL)
{
}
@@ -57,6 +58,8 @@ SCA_ExpressionController::SCA_ExpressionController(SCA_IObject* gameobj,
SCA_ExpressionController::~SCA_ExpressionController()
{
+ if (m_exprCache)
+ m_exprCache->Release();
}
@@ -65,6 +68,7 @@ CValue* SCA_ExpressionController::GetReplica()
{
SCA_ExpressionController* replica = new SCA_ExpressionController(*this);
replica->m_exprText = m_exprText;
+ replica->m_exprCache = NULL;
// this will copy properties and so on...
CValue::AddDataToReplica(replica);
@@ -72,18 +76,32 @@ CValue* SCA_ExpressionController::GetReplica()
}
+// Forced deletion of precalculated expression to break reference loop
+// Use this function when you know that you won't use the sensor anymore
+void SCA_ExpressionController::Delete()
+{
+ if (m_exprCache)
+ {
+ m_exprCache->Release();
+ m_exprCache = NULL;
+ }
+ Release();
+}
+
void SCA_ExpressionController::Trigger(SCA_LogicManager* logicmgr)
{
bool expressionresult = false;
-
- CParser parser;
- parser.SetContext(this->AddRef());
- CExpression* expr = parser.ProcessText(m_exprText);
- if (expr)
+ if (!m_exprCache)
+ {
+ CParser parser;
+ parser.SetContext(this->AddRef());
+ m_exprCache = parser.ProcessText(m_exprText);
+ }
+ if (m_exprCache)
{
- CValue* value = expr->Calculate();
+ CValue* value = m_exprCache->Calculate();
if (value)
{
if (value->IsError())
@@ -97,7 +115,8 @@ void SCA_ExpressionController::Trigger(SCA_LogicManager* logicmgr)
value->Release();
}
- expr->Release();
+ //m_exprCache->Release();
+ //m_exprCache = NULL;
}
/*
diff --git a/source/gameengine/GameLogic/SCA_ExpressionController.h b/source/gameengine/GameLogic/SCA_ExpressionController.h
index 20e1eb77771..79c26eea1e7 100644
--- a/source/gameengine/GameLogic/SCA_ExpressionController.h
+++ b/source/gameengine/GameLogic/SCA_ExpressionController.h
@@ -38,6 +38,7 @@ class SCA_ExpressionController : public SCA_IController
{
// Py_Header;
STR_String m_exprText;
+ CExpression* m_exprCache;
public:
SCA_ExpressionController(SCA_IObject* gameobj,
@@ -48,6 +49,11 @@ public:
virtual CValue* GetReplica();
virtual void Trigger(SCA_LogicManager* logicmgr);
virtual CValue* FindIdentifier(const STR_String& identifiername);
+ /**
+ * used to release the expression cache
+ * so that self references are removed before the controller itself is released
+ */
+ virtual void Delete();
/* --------------------------------------------------------------------- */
/* Python interface ---------------------------------------------------- */
diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.h b/source/gameengine/GameLogic/SCA_ILogicBrick.h
index cde1353275b..70d49941613 100644
--- a/source/gameengine/GameLogic/SCA_ILogicBrick.h
+++ b/source/gameengine/GameLogic/SCA_ILogicBrick.h
@@ -62,6 +62,7 @@ public:
SCA_IObject* GetParent();
virtual void ReParent(SCA_IObject* parent);
virtual void Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map);
+ virtual void Delete() { Release(); }
// act as a BoolValue (with value IsPositiveTrigger)
virtual CValue* Calc(VALUE_OPERATOR op, CValue *val);
diff --git a/source/gameengine/GameLogic/SCA_IObject.cpp b/source/gameengine/GameLogic/SCA_IObject.cpp
index d8f5f3eede5..debd62d44e6 100644
--- a/source/gameengine/GameLogic/SCA_IObject.cpp
+++ b/source/gameengine/GameLogic/SCA_IObject.cpp
@@ -59,7 +59,9 @@ SCA_IObject::~SCA_IObject()
SCA_ControllerList::iterator itc;
for (itc = m_controllers.begin(); !(itc == m_controllers.end()); ++itc)
{
- ((CValue*)(*itc))->Release();
+ //Use Delete for controller to ensure proper cleaning (expression controller)
+ (*itc)->Delete();
+ //((CValue*)(*itc))->Release();
}
SCA_ActuatorList::iterator ita;
for (ita = m_registeredActuators.begin(); !(ita==m_registeredActuators.end()); ++ita)
diff --git a/source/gameengine/GameLogic/SCA_ISensor.h b/source/gameengine/GameLogic/SCA_ISensor.h
index 5ae7ced2a2a..23f2c76c19f 100644
--- a/source/gameengine/GameLogic/SCA_ISensor.h
+++ b/source/gameengine/GameLogic/SCA_ISensor.h
@@ -105,11 +105,6 @@ public:
bool negmode,
int freq);
- /** Release sensor
- * For property sensor, it is used to release the pre-calculated expression
- * so that self references are removed before the sensor itself is released
- */
- virtual void Delete() { Release(); }
/** Set inversion of pulses on or off. */
void SetInvert(bool inv);
/** set the level detection on or off */
diff --git a/source/gameengine/GameLogic/SCA_PropertySensor.h b/source/gameengine/GameLogic/SCA_PropertySensor.h
index 933de49de18..2594e3fca9d 100644
--- a/source/gameengine/GameLogic/SCA_PropertySensor.h
+++ b/source/gameengine/GameLogic/SCA_PropertySensor.h
@@ -70,6 +70,10 @@ public:
KX_PROPSENSOR_TYPE checktype,
PyTypeObject* T=&Type );
+ /**
+ * For property sensor, it is used to release the pre-calculated expression
+ * so that self references are removed before the sensor itself is released
+ */
virtual void Delete();
virtual ~SCA_PropertySensor();
virtual CValue* GetReplica();