From ef8f92ffe63d76ec40d28f31660b22e12e4650be Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Fri, 15 May 2009 20:51:32 +0000 Subject: [PATCH] BGE: fix a compatibility problem since logic patch with YoFrankie (and other games I guess). State actuators will now execute before any other actuators to make sure that the actuators link count are up to date when they execute. --- source/gameengine/GameLogic/SCA_IActuator.cpp | 21 ++++++++++++++++ source/gameengine/GameLogic/SCA_IActuator.h | 19 ++------------ .../gameengine/GameLogic/SCA_LogicManager.cpp | 10 -------- .../gameengine/GameLogic/SCA_LogicManager.h | 9 ++++++- source/gameengine/Ketsji/KX_StateActuator.cpp | 25 +++++++++++++++++++ source/gameengine/Ketsji/KX_StateActuator.h | 4 +++ 6 files changed, 60 insertions(+), 28 deletions(-) diff --git a/source/gameengine/GameLogic/SCA_IActuator.cpp b/source/gameengine/GameLogic/SCA_IActuator.cpp index 5f71bb3f9e4..c2be36d5108 100644 --- a/source/gameengine/GameLogic/SCA_IActuator.cpp +++ b/source/gameengine/GameLogic/SCA_IActuator.cpp @@ -58,6 +58,27 @@ bool SCA_IActuator::Update() return false; } +void SCA_IActuator::Activate(SG_DList& head) +{ + if (QEmpty()) + { + InsertActiveQList(m_gameobj->m_activeActuators); + head.AddBack(&m_gameobj->m_activeActuators); + } +} + +void SCA_IActuator::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 SCA_IActuator::ProcessReplica() { SCA_ILogicBrick::ProcessReplica(); diff --git a/source/gameengine/GameLogic/SCA_IActuator.h b/source/gameengine/GameLogic/SCA_IActuator.h index 3055e1d946f..2bd92c343b9 100644 --- a/source/gameengine/GameLogic/SCA_IActuator.h +++ b/source/gameengine/GameLogic/SCA_IActuator.h @@ -118,23 +118,8 @@ public: /** * 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); - } - } + virtual void Deactivate(); + virtual void Activate(SG_DList& head); void LinkToController(SCA_IController* controller); void UnlinkController(class SCA_IController* cont); diff --git a/source/gameengine/GameLogic/SCA_LogicManager.cpp b/source/gameengine/GameLogic/SCA_LogicManager.cpp index 74370f89cf2..7acec465921 100644 --- a/source/gameengine/GameLogic/SCA_LogicManager.cpp +++ b/source/gameengine/GameLogic/SCA_LogicManager.cpp @@ -312,16 +312,6 @@ void SCA_LogicManager::AddTriggeredController(SCA_IController* controller, SCA_I } } - -void SCA_LogicManager::AddActiveActuator(SCA_IActuator* actua,bool event) -{ - actua->SetActive(true); - actua->Activate(m_activeActuators); - actua->AddEvent(event); -} - - - SCA_EventManager* SCA_LogicManager::FindEventManager(int eventmgrtype) { // find an eventmanager of a certain type diff --git a/source/gameengine/GameLogic/SCA_LogicManager.h b/source/gameengine/GameLogic/SCA_LogicManager.h index 0d610c9cc46..fe7b40b3ba4 100644 --- a/source/gameengine/GameLogic/SCA_LogicManager.h +++ b/source/gameengine/GameLogic/SCA_LogicManager.h @@ -65,6 +65,7 @@ typedef std::map sensormap_t; */ #include "SCA_ILogicBrick.h" +#include "SCA_IActuator.h" class SCA_LogicManager @@ -103,7 +104,13 @@ public: void BeginFrame(double curtime, double fixedtime); void UpdateFrame(double curtime, bool frame); void EndFrame(); - void AddActiveActuator(SCA_IActuator* sensor,bool event); + void AddActiveActuator(SCA_IActuator* actua,bool event) + { + actua->SetActive(true); + actua->Activate(m_activeActuators); + actua->AddEvent(event); + } + void AddTriggeredController(SCA_IController* controller, SCA_ISensor* sensor); SCA_EventManager* FindEventManager(int eventmgrtype); diff --git a/source/gameengine/Ketsji/KX_StateActuator.cpp b/source/gameengine/Ketsji/KX_StateActuator.cpp index 2cbb42b3311..5f9730d7e10 100644 --- a/source/gameengine/Ketsji/KX_StateActuator.cpp +++ b/source/gameengine/Ketsji/KX_StateActuator.cpp @@ -55,6 +55,9 @@ KX_StateActuator::~KX_StateActuator( // intentionally empty } +// used to put state actuator to be executed before any other actuators +SG_QList KX_StateActuator::m_stateActuatorHead; + CValue* KX_StateActuator::GetReplica( void @@ -99,6 +102,28 @@ KX_StateActuator::Update() return false; } +void KX_StateActuator::Deactivate() +{ + if (QDelink()) + { + // the actuator was in the active list + if (m_stateActuatorHead.QEmpty()) + // no more state object active + m_stateActuatorHead.Delink(); + } +} + +void KX_StateActuator::Activate(SG_DList& head) +{ + // no need to sort the state actuators + if (m_stateActuatorHead.QAddBack(this)) + { + // add front to make sure it runs before other actuators + head.AddFront(&m_stateActuatorHead); + } +} + + /* ------------------------------------------------------------------------- */ /* Python functions */ /* ------------------------------------------------------------------------- */ diff --git a/source/gameengine/Ketsji/KX_StateActuator.h b/source/gameengine/Ketsji/KX_StateActuator.h index 7e7056bd6af..57303ad403f 100644 --- a/source/gameengine/Ketsji/KX_StateActuator.h +++ b/source/gameengine/Ketsji/KX_StateActuator.h @@ -46,6 +46,7 @@ class KX_StateActuator : public SCA_IActuator OP_NEG, OP_COUNT }; + static SG_QList m_stateActuatorHead; int m_operation; int m_mask; @@ -71,6 +72,9 @@ class KX_StateActuator : public SCA_IActuator virtual bool Update(); + virtual void Deactivate(); + virtual void Activate(SG_DList& head); + /* --------------------------------------------------------------------- */ /* Python interface ---------------------------------------------------- */ /* --------------------------------------------------------------------- */