diff --git a/source/gameengine/Converter/BL_ActionActuator.cpp b/source/gameengine/Converter/BL_ActionActuator.cpp index 3ff5c8ed4c17..147a361a14da 100644 --- a/source/gameengine/Converter/BL_ActionActuator.cpp +++ b/source/gameengine/Converter/BL_ActionActuator.cpp @@ -168,10 +168,8 @@ CValue* BL_ActionActuator::GetReplica() return replica; } -bool BL_ActionActuator::Update(double curtime, bool frame) +bool BL_ActionActuator::Update(double curtime) { - bool bNegativeEvent = false; - bool bPositiveEvent = false; bool bUseContinue = false; KX_GameObject *obj = (KX_GameObject*)GetParent(); short playtype = BL_Action::ACT_MODE_PLAY; @@ -219,12 +217,9 @@ bool BL_ActionActuator::Update(double curtime, bool frame) // Handle events - if (frame) - { - bNegativeEvent = m_negevent; - bPositiveEvent = m_posevent; - RemoveAllEvents(); - } + bool bNegativeEvent = m_negevent; + bool bPositiveEvent = m_posevent; + RemoveAllEvents(); // "Active" actions need to keep updating their current frame if (bUseContinue && (m_flag & ACT_FLAG_ACTIVE)) diff --git a/source/gameengine/Converter/BL_ActionActuator.h b/source/gameengine/Converter/BL_ActionActuator.h index 7ff0b6b4aaf3..5dbb06321f1d 100644 --- a/source/gameengine/Converter/BL_ActionActuator.h +++ b/source/gameengine/Converter/BL_ActionActuator.h @@ -57,7 +57,7 @@ class BL_ActionActuator : public SCA_IActuator float stride); virtual ~BL_ActionActuator(); - virtual bool Update(double curtime, bool frame); + virtual bool Update(double curtime); virtual CValue* GetReplica(); virtual void ProcessReplica(); diff --git a/source/gameengine/Converter/BL_ArmatureActuator.cpp b/source/gameengine/Converter/BL_ArmatureActuator.cpp index 7296761f89c9..5117b7454cd6 100644 --- a/source/gameengine/Converter/BL_ArmatureActuator.cpp +++ b/source/gameengine/Converter/BL_ArmatureActuator.cpp @@ -143,7 +143,7 @@ void BL_ArmatureActuator::FindConstraint() } } -bool BL_ArmatureActuator::Update(double curtime, bool frame) +bool BL_ArmatureActuator::Update(double curtime) { // the only role of this actuator is to ensure that the armature pose will be evaluated bool result = false; diff --git a/source/gameengine/Converter/BL_ArmatureActuator.h b/source/gameengine/Converter/BL_ArmatureActuator.h index 027107f5ecea..eb4672b3e246 100644 --- a/source/gameengine/Converter/BL_ArmatureActuator.h +++ b/source/gameengine/Converter/BL_ArmatureActuator.h @@ -67,7 +67,7 @@ class BL_ArmatureActuator : public SCA_IActuator virtual void ProcessReplica(); virtual bool UnlinkObject(SCA_IObject* clientobj); virtual void Relink(std::map& obj_map); - virtual bool Update(double curtime, bool frame); + virtual bool Update(double curtime); virtual void ReParent(SCA_IObject* parent); #ifdef WITH_PYTHON diff --git a/source/gameengine/Converter/KX_ConvertActuators.cpp b/source/gameengine/Converter/KX_ConvertActuators.cpp index c46af879bb18..9d1281797d80 100644 --- a/source/gameengine/Converter/KX_ConvertActuators.cpp +++ b/source/gameengine/Converter/KX_ConvertActuators.cpp @@ -136,7 +136,6 @@ void BL_ConvertActuators(const char* maggiename, actcount++; bact = bact->next; } - gameobj->ReserveActuator(actcount); bact = (bActuator*) blenderobject->actuators.first; while (bact) { diff --git a/source/gameengine/Converter/KX_ConvertControllers.cpp b/source/gameengine/Converter/KX_ConvertControllers.cpp index e6a41905ef45..a87ffcceb4ab 100644 --- a/source/gameengine/Converter/KX_ConvertControllers.cpp +++ b/source/gameengine/Converter/KX_ConvertControllers.cpp @@ -78,7 +78,6 @@ LinkControllerToActuators( // Iterate through the actuators of the game blender // controller and find the corresponding ketsji actuator. - game_controller->ReserveActuator(bcontr->totlinks); for (int i=0;itotlinks;i++) { bActuator* bact = (bActuator*) bcontr->links[i]; @@ -108,7 +107,6 @@ void BL_ConvertControllers( bcontr = bcontr->next; count++; } - gameobj->ReserveController(count); bcontr = (bController*)blenderobject->controllers.first; while (bcontr) { diff --git a/source/gameengine/Converter/KX_ConvertSensors.cpp b/source/gameengine/Converter/KX_ConvertSensors.cpp index 9ff3c35cdb72..7bc52dff99b5 100644 --- a/source/gameengine/Converter/KX_ConvertSensors.cpp +++ b/source/gameengine/Converter/KX_ConvertSensors.cpp @@ -115,7 +115,6 @@ void BL_ConvertSensors(struct Object* blenderobject, sens = sens->next; count++; } - gameobj->ReserveSensor(count); sens = (bSensor*)blenderobject->sensors.first; while (sens) { @@ -624,12 +623,6 @@ void BL_ConvertSensors(struct Object* blenderobject, gameobj->AddSensor(gamesensor); - // only register to manager if it's in an active layer - // Make registration dynamic: only when sensor is activated - //if (isInActiveLayer) - // gamesensor->RegisterToManager(); - - gamesensor->ReserveController(sens->totlinks); for (int i=0;itotlinks;i++) { bController* linkedcont = (bController*) sens->links[i]; diff --git a/source/gameengine/GameLogic/SCA_IActuator.cpp b/source/gameengine/GameLogic/SCA_IActuator.cpp index 845673823da3..26956b34eb36 100644 --- a/source/gameengine/GameLogic/SCA_IActuator.cpp +++ b/source/gameengine/GameLogic/SCA_IActuator.cpp @@ -55,13 +55,9 @@ bool SCA_IActuator::UnlinkObject(SCA_IObject *clientobj) return false; } -bool SCA_IActuator::Update(double curtime, bool frame) +bool SCA_IActuator::Update(double curtime) { - if (frame) { - return Update(); - } - - return true; + return Update(); } bool SCA_IActuator::Update() diff --git a/source/gameengine/GameLogic/SCA_IActuator.h b/source/gameengine/GameLogic/SCA_IActuator.h index 2de536c3792a..8a27f479ab44 100644 --- a/source/gameengine/GameLogic/SCA_IActuator.h +++ b/source/gameengine/GameLogic/SCA_IActuator.h @@ -110,7 +110,7 @@ class SCA_IActuator : public SCA_ILogicBrick */ - virtual bool Update(double curtime, bool frame); + virtual bool Update(double curtime); virtual bool Update(); /** diff --git a/source/gameengine/GameLogic/SCA_IController.cpp b/source/gameengine/GameLogic/SCA_IController.cpp index 9a29adf1f9d6..7b622b2f8641 100644 --- a/source/gameengine/GameLogic/SCA_IController.cpp +++ b/source/gameengine/GameLogic/SCA_IController.cpp @@ -59,11 +59,6 @@ std::vector& SCA_IController::GetLinkedActuators() return m_linkedactuators; } -void SCA_IController::ReserveActuator(int num) -{ - m_linkedactuators.reserve(num); -} - void SCA_IController::UnlinkAllSensors() { for (SCA_ISensor *sensor : m_linkedsensors) { diff --git a/source/gameengine/GameLogic/SCA_IController.h b/source/gameengine/GameLogic/SCA_IController.h index b0d28a4f9278..590e71ba0842 100644 --- a/source/gameengine/GameLogic/SCA_IController.h +++ b/source/gameengine/GameLogic/SCA_IController.h @@ -60,7 +60,6 @@ class SCA_IController : public SCA_ILogicBrick void LinkToActuator(SCA_IActuator *); std::vector& GetLinkedSensors(); std::vector& GetLinkedActuators(); - void ReserveActuator(int num); void UnlinkAllSensors(); void UnlinkAllActuators(); void UnlinkActuator(SCA_IActuator *actua); diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp index dde0a56dab98..f1b553281b43 100644 --- a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp +++ b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp @@ -81,27 +81,6 @@ void SCA_ILogicBrick::Relink(std::map& obj_map) // nothing to do } -CValue* SCA_ILogicBrick::Calc(VALUE_OPERATOR op, CValue *val) -{ - CValue* temp = new CBoolValue(false,""); - CValue* result = temp->Calc(op,val); - temp->Release(); - - return result; -} - -CValue* SCA_ILogicBrick::CalcFinal(VALUE_DATA_TYPE dtype, - VALUE_OPERATOR op, - CValue *val) -{ - // same as bool implementation, so... - CValue* temp = new CBoolValue(false,""); - CValue* result = temp->CalcFinal(dtype,op,val); - temp->Release(); - - return result; -} - const std::string SCA_ILogicBrick::GetText() { if (m_name.size()) @@ -120,13 +99,6 @@ void SCA_ILogicBrick::SetName(const std::string& name) m_name = name; } -bool SCA_ILogicBrick::LessComparedTo(SCA_ILogicBrick* other) -{ - return (this->m_Execute_Ueber_Priority < other->m_Execute_Ueber_Priority) - || ((this->m_Execute_Ueber_Priority == other->m_Execute_Ueber_Priority) && - (this->m_Execute_Priority < other->m_Execute_Priority)); -} - void SCA_ILogicBrick::SetLogicManager(SCA_LogicManager *logicmgr) { m_logicManager = logicmgr; @@ -212,21 +184,4 @@ PyObject *SCA_ILogicBrick::pyattr_get_owner(PyObjectPlus *self_v, const KX_PYATT Py_RETURN_NONE; } - - -/* Conversions for making life better. */ -bool SCA_ILogicBrick::PyArgToBool(int boolArg) -{ - if (boolArg) { - return true; - } else { - return false; - } -} - -PyObject *SCA_ILogicBrick::BoolToPyArg(bool boolarg) -{ - return PyLong_FromLong(boolarg ? KX_TRUE: KX_FALSE); -} - #endif // WITH_PYTHON diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.h b/source/gameengine/GameLogic/SCA_ILogicBrick.h index abebc10b8a7b..a316a78b2287 100644 --- a/source/gameengine/GameLogic/SCA_ILogicBrick.h +++ b/source/gameengine/GameLogic/SCA_ILogicBrick.h @@ -69,10 +69,6 @@ class SCA_ILogicBrick : public CValue, public SG_QList virtual void Relink(std::map& obj_map); virtual void Delete() { Release(); } - // act as a BoolValue (with value IsPositiveTrigger) - virtual CValue* Calc(VALUE_OPERATOR op, CValue *val); - virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val); - virtual const std::string GetText(); virtual std::string GetName(); virtual void SetName(const std::string& name); @@ -122,8 +118,6 @@ class SCA_ILogicBrick : public CValue, public SG_QList it.add_back(this); } - virtual bool LessComparedTo(SCA_ILogicBrick* other); - virtual void SetLogicManager(SCA_LogicManager *logicmgr); SCA_LogicManager *GetLogicManager(); @@ -145,16 +139,6 @@ class SCA_ILogicBrick : public CValue, public SG_QList KX_FALSE, KX_BOOL_MAX }; - - -protected: - /* Some conversions to go with the bool type. */ - /** Convert a KX_TRUE, KX_FALSE in Python to a c++ value. */ - bool PyArgToBool(int boolArg); - - /** Convert a a c++ value to KX_TRUE, KX_FALSE in Python. */ - PyObject *BoolToPyArg(bool); - #endif /* WITH_PYTHON */ }; diff --git a/source/gameengine/GameLogic/SCA_IObject.h b/source/gameengine/GameLogic/SCA_IObject.h index 5123d752e8f7..5429a199ca4c 100644 --- a/source/gameengine/GameLogic/SCA_IObject.h +++ b/source/gameengine/GameLogic/SCA_IObject.h @@ -134,20 +134,8 @@ class SCA_IObject : public CValue } 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); @@ -215,8 +203,6 @@ class SCA_IObject : public CValue */ unsigned int GetState(void) { return m_state; } -// const class MT_Vector3& ConvertPythonPylist(PyObject *pylist); - virtual int GetGameObjectType() const {return -1;} typedef enum ObjectTypes { diff --git a/source/gameengine/GameLogic/SCA_ISensor.cpp b/source/gameengine/GameLogic/SCA_ISensor.cpp index 122aba305bb1..5398b7981589 100644 --- a/source/gameengine/GameLogic/SCA_ISensor.cpp +++ b/source/gameengine/GameLogic/SCA_ISensor.cpp @@ -211,11 +211,6 @@ void SCA_ISensor::Replace_EventManager(class SCA_LogicManager *logicmgr) } } -void SCA_ISensor::ReserveController(int num) -{ - m_linkedcontrollers.reserve(num); -} - void SCA_ISensor::LinkToController(SCA_IController *controller) { m_linkedcontrollers.push_back(controller); @@ -412,17 +407,17 @@ PyObject *SCA_ISensor::pyattr_get_positive(PyObjectPlus *self_v, const KX_PYATTR PyObject *SCA_ISensor::pyattr_get_status(PyObjectPlus *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { SCA_ISensor *self = static_cast(self_v); - int status = 0; + int status = KX_SENSOR_INACTIVE; if (self->GetState()) { if (self->GetState() == self->GetPrevState()) { - status = 2; + status = KX_SENSOR_ACTIVE; } else { - status = 1; + status = KX_SENSOR_JUST_ACTIVATED; } } else if (self->GetState() != self->GetPrevState()) { - status = 3; + status = KX_SENSOR_JUST_DEACTIVATED; } return PyLong_FromLong(status); } diff --git a/source/gameengine/GameLogic/SCA_ISensor.h b/source/gameengine/GameLogic/SCA_ISensor.h index 8f35b23d0f5a..2f5cd2551bb6 100644 --- a/source/gameengine/GameLogic/SCA_ISensor.h +++ b/source/gameengine/GameLogic/SCA_ISensor.h @@ -135,7 +135,6 @@ class SCA_ISensor : public SCA_ILogicBrick virtual void RegisterToManager(); virtual void UnregisterToManager(); void Replace_EventManager(SCA_LogicManager *logicmgr); - void ReserveController(int num); void LinkToController(SCA_IController *controller); void UnlinkController(SCA_IController *controller); void UnlinkAllControllers(); diff --git a/source/gameengine/GameLogic/SCA_LogicManager.cpp b/source/gameengine/GameLogic/SCA_LogicManager.cpp index aedff0c2ab38..4890c4163704 100644 --- a/source/gameengine/GameLogic/SCA_LogicManager.cpp +++ b/source/gameengine/GameLogic/SCA_LogicManager.cpp @@ -56,30 +56,6 @@ SCA_LogicManager::~SCA_LogicManager() BLI_assert(m_activeActuators.Empty()); } -#if 0 -// this kind of fixes bug 398 but breakes games, so better leave it out for now. -// a removed object's gameobject (and logicbricks and stuff) didn't get released -// because it was still in the m_mapStringToGameObjects map. -void SCA_LogicManager::RemoveGameObject(const std::string& gameobjname) -{ - int numgameobj = m_mapStringToGameObjects.size(); - for (int i = 0; i < numgameobj; i++) - { - CValue** gameobjptr = m_mapStringToGameObjects.at(i); - BLI_assert(gameobjptr); - - if (gameobjptr) - { - if ((*gameobjptr)->GetName() == gameobjname) - (*gameobjptr)->Release(); - } - } - - m_mapStringToGameObjects.remove(gameobjname); -} -#endif - - void SCA_LogicManager::RegisterEventManager(SCA_EventManager* eventmgr) { m_eventmanagers.push_back(eventmgr); @@ -203,7 +179,7 @@ void SCA_LogicManager::BeginFrame(double curtime, double fixedtime) -void SCA_LogicManager::UpdateFrame(double curtime, bool frame) +void SCA_LogicManager::UpdateFrame(double curtime) { for (std::vector::const_iterator ie=m_eventmanagers.begin(); !(ie==m_eventmanagers.end()); ie++) (*ie)->UpdateFrame(); @@ -220,7 +196,7 @@ void SCA_LogicManager::UpdateFrame(double curtime, bool frame) SCA_IActuator* actua = *ia; // increment first to allow removal of inactive actuators. ++ia; - if (!actua->Update(curtime, frame)) + if (!actua->Update(curtime)) { // this actuator is not active anymore, remove actua->QDelink(); diff --git a/source/gameengine/GameLogic/SCA_LogicManager.h b/source/gameengine/GameLogic/SCA_LogicManager.h index 7722a82ac843..d7978a4fa0a7 100644 --- a/source/gameengine/GameLogic/SCA_LogicManager.h +++ b/source/gameengine/GameLogic/SCA_LogicManager.h @@ -95,7 +95,7 @@ class SCA_LogicManager class SCA_IActuator* actuator); void BeginFrame(double curtime, double fixedtime); - void UpdateFrame(double curtime, bool frame); + void UpdateFrame(double curtime); void EndFrame(); void AddActiveActuator(SCA_IActuator* actua,bool event) { @@ -107,8 +107,6 @@ class SCA_LogicManager void AddTriggeredController(SCA_IController* controller, SCA_ISensor* sensor); SCA_EventManager* FindEventManager(int eventmgrtype); std::vector GetEventManagers() { return m_eventmanagers; } - - void RemoveGameObject(const std::string& gameobjname); /** * remove Logic Bricks from the running logicmanager diff --git a/source/gameengine/Ketsji/KX_CameraActuator.cpp b/source/gameengine/Ketsji/KX_CameraActuator.cpp index be2dd8787533..bd6a8fb18225 100644 --- a/source/gameengine/Ketsji/KX_CameraActuator.cpp +++ b/source/gameengine/Ketsji/KX_CameraActuator.cpp @@ -179,7 +179,7 @@ static void Kx_VecUpMat3(float vec[3], float mat[3][3], short axis) cross_v3_v3v3(mat[cox], mat[coy], mat[coz]); } -bool KX_CameraActuator::Update(double curtime, bool frame) +bool KX_CameraActuator::Update(double curtime) { /* wondering... is it really necessary/desirable to suppress negative */ /* events here? */ diff --git a/source/gameengine/Ketsji/KX_CameraActuator.h b/source/gameengine/Ketsji/KX_CameraActuator.h index 91941a1dff7a..15faabeb8fe0 100644 --- a/source/gameengine/Ketsji/KX_CameraActuator.h +++ b/source/gameengine/Ketsji/KX_CameraActuator.h @@ -106,10 +106,7 @@ private : /** Methods inherited from SCA_IActuator */ - virtual bool Update( - double curtime, - bool frame - ); + virtual bool Update(double curtime); virtual bool UnlinkObject(SCA_IObject* clientobj); /** Methods inherited from SCA_ILogicBrick */ diff --git a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp index a29b4563a01a..4ca477783ac6 100644 --- a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp +++ b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp @@ -166,7 +166,7 @@ bool KX_ConstraintActuator::NeedRayCast(KX_ClientObjectInfo *client, void *UNUSE return true; } -bool KX_ConstraintActuator::Update(double curtime, bool frame) +bool KX_ConstraintActuator::Update(double curtime) { bool result = false; diff --git a/source/gameengine/Ketsji/KX_ConstraintActuator.h b/source/gameengine/Ketsji/KX_ConstraintActuator.h index be0fe10b0048..203d8eaec6b1 100644 --- a/source/gameengine/Ketsji/KX_ConstraintActuator.h +++ b/source/gameengine/Ketsji/KX_ConstraintActuator.h @@ -137,7 +137,7 @@ class KX_ConstraintActuator : public SCA_IActuator return replica; }; - virtual bool Update(double curtime, bool frame); + virtual bool Update(double curtime); /* --------------------------------------------------------------------- */ /* Python interface ---------------------------------------------------- */ diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index 3c4140bccd2a..7c2a6047b05f 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -431,7 +431,7 @@ bool KX_KetsjiEngine::NextFrame() // Do some cleanup work for this logic frame m_logger.StartLog(tc_logic, m_kxsystem->GetTimeInSeconds(), true); - scene->LogicUpdateFrame(m_frameTime, true); + scene->LogicUpdateFrame(m_frameTime); scene->LogicEndFrame(); diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 19bce0379f58..2b57bf91d87f 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -1585,7 +1585,7 @@ void KX_Scene::UpdateAnimations(double curtime) BLI_task_pool_work_and_wait(m_animationPool); } -void KX_Scene::LogicUpdateFrame(double curtime, bool frame) +void KX_Scene::LogicUpdateFrame(double curtime) { /* Update object components, we copy the object pointer in a second list to make sure that we iterate on a list * which will not be modified, indeed components can add objects in theirs initialization. @@ -1600,7 +1600,7 @@ void KX_Scene::LogicUpdateFrame(double curtime, bool frame) (*it)->UpdateComponents(); } - m_logicmgr->UpdateFrame(curtime, frame); + m_logicmgr->UpdateFrame(curtime); } void KX_Scene::LogicEndFrame() diff --git a/source/gameengine/Ketsji/KX_Scene.h b/source/gameengine/Ketsji/KX_Scene.h index 495bb0df92e7..20628466a8f4 100644 --- a/source/gameengine/Ketsji/KX_Scene.h +++ b/source/gameengine/Ketsji/KX_Scene.h @@ -361,7 +361,7 @@ class KX_Scene : public CValue, public SCA_IScene * Initiate an update of the logic system. */ void LogicBeginFrame(double curtime, double framestep); - void LogicUpdateFrame(double curtime, bool frame); + void LogicUpdateFrame(double curtime); void UpdateAnimations(double curtime); void diff --git a/source/gameengine/Ketsji/KX_SoundActuator.cpp b/source/gameengine/Ketsji/KX_SoundActuator.cpp index 1890f4648cf4..03c65e06c508 100644 --- a/source/gameengine/Ketsji/KX_SoundActuator.cpp +++ b/source/gameengine/Ketsji/KX_SoundActuator.cpp @@ -173,10 +173,8 @@ void KX_SoundActuator::ProcessReplica() #endif // WITH_AUDASPACE } -bool KX_SoundActuator::Update(double curtime, bool frame) +bool KX_SoundActuator::Update(double curtime) { - if (!frame) - return true; bool result = false; #ifdef WITH_AUDASPACE diff --git a/source/gameengine/Ketsji/KX_SoundActuator.h b/source/gameengine/Ketsji/KX_SoundActuator.h index ef61fd07ebe6..2c529f792699 100644 --- a/source/gameengine/Ketsji/KX_SoundActuator.h +++ b/source/gameengine/Ketsji/KX_SoundActuator.h @@ -95,7 +95,7 @@ class KX_SoundActuator : public SCA_IActuator ~KX_SoundActuator(); - virtual bool Update(double curtime, bool frame); + virtual bool Update(double curtime); CValue* GetReplica(); void ProcessReplica(); diff --git a/source/gameengine/Ketsji/KX_SteeringActuator.cpp b/source/gameengine/Ketsji/KX_SteeringActuator.cpp index ebcd9ffcbc3a..d02b1ea1f76c 100644 --- a/source/gameengine/Ketsji/KX_SteeringActuator.cpp +++ b/source/gameengine/Ketsji/KX_SteeringActuator.cpp @@ -162,160 +162,157 @@ void KX_SteeringActuator::Relink(std::map& obj_map } } -bool KX_SteeringActuator::Update(double curtime, bool frame) +bool KX_SteeringActuator::Update(double curtime) { - if (frame) + double delta = curtime - m_updateTime; + m_updateTime = curtime; + + if (m_posevent && !m_isActive) { - double delta = curtime - m_updateTime; + delta = 0.0; + m_pathUpdateTime = -1.0; m_updateTime = curtime; - - if (m_posevent && !m_isActive) - { - delta = 0.0; - m_pathUpdateTime = -1.0; - m_updateTime = curtime; - m_isActive = true; - } - bool bNegativeEvent = IsNegativeEvent(); - if (bNegativeEvent) - m_isActive = false; - - RemoveAllEvents(); - - if (!delta) - return true; - - if (bNegativeEvent || !m_target) - return false; // do nothing on negative events - - KX_GameObject *obj = (KX_GameObject*) GetParent(); - const MT_Vector3& mypos = obj->NodeGetWorldPosition(); - const MT_Vector3& targpos = m_target->NodeGetWorldPosition(); - MT_Vector3 vectotarg = targpos - mypos; - MT_Vector3 vectotarg2d = vectotarg; - vectotarg2d.z() = 0.0f; - m_steerVec = MT_Vector3(0.0f, 0.0f, 0.0f); - bool apply_steerforce = false; - bool terminate = true; - - switch (m_mode) { - case KX_STEERING_SEEK: - if (vectotarg2d.length2()>m_distance*m_distance) - { - terminate = false; - m_steerVec = vectotarg; - m_steerVec.normalize(); - apply_steerforce = true; - } - break; - case KX_STEERING_FLEE: - if (vectotarg2d.length2()m_distance*m_distance) - { - terminate = false; + m_isActive = true; + } + bool bNegativeEvent = IsNegativeEvent(); + if (bNegativeEvent) + m_isActive = false; - static const MT_Scalar WAYPOINT_RADIUS(0.25f); + RemoveAllEvents(); - if (m_pathUpdateTime<0 || (m_pathUpdatePeriod>=0 && - curtime - m_pathUpdateTime>((double)m_pathUpdatePeriod/1000.0))) - { - m_pathUpdateTime = curtime; - m_pathLen = m_navmesh->FindPath(mypos, targpos, m_path, MAX_PATH_LENGTH); - m_wayPointIdx = m_pathLen > 1 ? 1 : -1; - } + if (!delta) + return true; - if (m_wayPointIdx>0) - { - MT_Vector3 waypoint(&m_path[3*m_wayPointIdx]); - if ((waypoint-mypos).length2()=m_pathLen) - { - m_wayPointIdx = -1; - terminate = true; - } - else - waypoint.setValue(&m_path[3*m_wayPointIdx]); - } + if (bNegativeEvent || !m_target) + return false; // do nothing on negative events + + KX_GameObject *obj = (KX_GameObject*) GetParent(); + const MT_Vector3& mypos = obj->NodeGetWorldPosition(); + const MT_Vector3& targpos = m_target->NodeGetWorldPosition(); + MT_Vector3 vectotarg = targpos - mypos; + MT_Vector3 vectotarg2d = vectotarg; + vectotarg2d.z() = 0.0f; + m_steerVec = MT_Vector3(0.0f, 0.0f, 0.0f); + bool apply_steerforce = false; + bool terminate = true; + + switch (m_mode) { + case KX_STEERING_SEEK: + if (vectotarg2d.length2()>m_distance*m_distance) + { + terminate = false; + m_steerVec = vectotarg; + m_steerVec.normalize(); + apply_steerforce = true; + } + break; + case KX_STEERING_FLEE: + if (vectotarg2d.length2()m_distance*m_distance) + { + terminate = false; - m_steerVec = waypoint - mypos; - apply_steerforce = true; + static const MT_Scalar WAYPOINT_RADIUS(0.25f); + + if (m_pathUpdateTime<0 || (m_pathUpdatePeriod>=0 && + curtime - m_pathUpdateTime>((double)m_pathUpdatePeriod/1000.0))) + { + m_pathUpdateTime = curtime; + m_pathLen = m_navmesh->FindPath(mypos, targpos, m_path, MAX_PATH_LENGTH); + m_wayPointIdx = m_pathLen > 1 ? 1 : -1; + } - - if (m_enableVisualization) + if (m_wayPointIdx>0) + { + MT_Vector3 waypoint(&m_path[3*m_wayPointIdx]); + if ((waypoint-mypos).length2()=m_pathLen) { - //debug draw - static const MT_Vector4 PATH_COLOR(1.0f, 0.0f, 0.0f, 1.0f); - m_navmesh->DrawPath(m_path, m_pathLen, PATH_COLOR); + m_wayPointIdx = -1; + terminate = true; } + else + waypoint.setValue(&m_path[3*m_wayPointIdx]); } - - } - break; - } - if (apply_steerforce) - { - bool isdyna = obj->IsDynamic(); - if (isdyna) - m_steerVec.z() = 0; - if (!m_steerVec.fuzzyZero()) - m_steerVec.normalize(); - MT_Vector3 newvel = m_velocity * m_steerVec; + m_steerVec = waypoint - mypos; + apply_steerforce = true; - //adjust velocity to avoid obstacles - if (m_simulation && m_obstacle /*&& !newvel.fuzzyZero()*/) - { - if (m_enableVisualization) - KX_RasterizerDrawDebugLine(mypos, mypos + newvel, MT_Vector4(1.0f, 0.0f, 0.0f, 1.0f)); - m_simulation->AdjustObstacleVelocity(m_obstacle, m_mode!=KX_STEERING_PATHFOLLOWING ? m_navmesh : nullptr, - newvel, m_acceleration*(float)delta, m_turnspeed/(180.0f*(float)(M_PI*delta))); - if (m_enableVisualization) - KX_RasterizerDrawDebugLine(mypos, mypos + newvel, MT_Vector4(0.0f, 1.0f, 0.0f, 1.0f)); + + if (m_enableVisualization) + { + //debug draw + static const MT_Vector4 PATH_COLOR(1.0f, 0.0f, 0.0f, 1.0f); + m_navmesh->DrawPath(m_path, m_pathLen, PATH_COLOR); + } + } + } + break; + } - HandleActorFace(newvel); - if (isdyna) - { - //temporary solution: set 2D steering velocity directly to obj - //correct way is to apply physical force - MT_Vector3 curvel = obj->GetLinearVelocity(); + if (apply_steerforce) + { + bool isdyna = obj->IsDynamic(); + if (isdyna) + m_steerVec.z() = 0; + if (!m_steerVec.fuzzyZero()) + m_steerVec.normalize(); + MT_Vector3 newvel = m_velocity * m_steerVec; + + //adjust velocity to avoid obstacles + if (m_simulation && m_obstacle /*&& !newvel.fuzzyZero()*/) + { + if (m_enableVisualization) + KX_RasterizerDrawDebugLine(mypos, mypos + newvel, MT_Vector4(1.0f, 0.0f, 0.0f, 1.0f)); + m_simulation->AdjustObstacleVelocity(m_obstacle, m_mode!=KX_STEERING_PATHFOLLOWING ? m_navmesh : nullptr, + newvel, m_acceleration*(float)delta, m_turnspeed/(180.0f*(float)(M_PI*delta))); + if (m_enableVisualization) + KX_RasterizerDrawDebugLine(mypos, mypos + newvel, MT_Vector4(0.0f, 1.0f, 0.0f, 1.0f)); + } - if (m_lockzvel) - newvel.z() = 0.0f; - else - newvel.z() = curvel.z(); + HandleActorFace(newvel); + if (isdyna) + { + //temporary solution: set 2D steering velocity directly to obj + //correct way is to apply physical force + MT_Vector3 curvel = obj->GetLinearVelocity(); - obj->setLinearVelocity(newvel, false); - } + if (m_lockzvel) + newvel.z() = 0.0f; else - { - MT_Vector3 movement = delta*newvel; - obj->ApplyMovement(movement, false); - } + newvel.z() = curvel.z(); + + obj->setLinearVelocity(newvel, false); } else { - if (m_simulation && m_obstacle) - { - m_obstacle->dvel[0] = 0.f; - m_obstacle->dvel[1] = 0.f; - } - + MT_Vector3 movement = delta*newvel; + obj->ApplyMovement(movement, false); } - - if (terminate && m_isSelfTerminated) - return false; } + else + { + if (m_simulation && m_obstacle) + { + m_obstacle->dvel[0] = 0.f; + m_obstacle->dvel[1] = 0.f; + } + + } + + if (terminate && m_isSelfTerminated) + return false; return true; } diff --git a/source/gameengine/Ketsji/KX_SteeringActuator.h b/source/gameengine/Ketsji/KX_SteeringActuator.h index 25ea9aeb96ab..6b1049ddfd57 100644 --- a/source/gameengine/Ketsji/KX_SteeringActuator.h +++ b/source/gameengine/Ketsji/KX_SteeringActuator.h @@ -93,7 +93,7 @@ class KX_SteeringActuator : public SCA_IActuator bool enableVisualization, bool lockzvel); virtual ~KX_SteeringActuator(); - virtual bool Update(double curtime, bool frame); + virtual bool Update(double curtime); virtual CValue* GetReplica(); virtual void ProcessReplica(); diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.cpp b/source/gameengine/Ketsji/KX_TrackToActuator.cpp index 276ff907839e..660ac26f1573 100644 --- a/source/gameengine/Ketsji/KX_TrackToActuator.cpp +++ b/source/gameengine/Ketsji/KX_TrackToActuator.cpp @@ -303,7 +303,7 @@ void KX_TrackToActuator::Relink(std::map& obj_map) } -bool KX_TrackToActuator::Update(double curtime, bool frame) +bool KX_TrackToActuator::Update(double curtime) { bool result = false; bool bNegativeEvent = IsNegativeEvent(); diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.h b/source/gameengine/Ketsji/KX_TrackToActuator.h index 948889fbe914..28d0554e3347 100644 --- a/source/gameengine/Ketsji/KX_TrackToActuator.h +++ b/source/gameengine/Ketsji/KX_TrackToActuator.h @@ -66,7 +66,7 @@ class KX_TrackToActuator : public SCA_IActuator virtual void ProcessReplica(); virtual bool UnlinkObject(SCA_IObject* clientobj); virtual void Relink(std::map& obj_map); - virtual bool Update(double curtime, bool frame); + virtual bool Update(double curtime); //Python Interface enum UpAxis {