From 5a546f6e984e10bc380382274cf4d8d80edda946 Mon Sep 17 00:00:00 2001 From: Porteries Tristan Date: Fri, 29 Dec 2017 16:08:48 +0100 Subject: [PATCH] UPBGE: Use std::unique_ptr in KX_GameObject. Some pointer in KX_GameObject corresponded to data owned by the game object or inexistant. In this case std::unique_ptr could be used to ensure the free of data. The only drawback is the requierment of a copy constructor to duplicate the data or set they to nullptr. Also m_clientInfo is now not anymore a pointer as it is never nullptr and owned by the game object. --- .../Converter/BL_BlenderDataConversion.cpp | 4 +- source/gameengine/GameLogic/SCA_IObject.cpp | 18 +- source/gameengine/GameLogic/SCA_IObject.h | 1 + source/gameengine/Ketsji/KX_Camera.cpp | 12 +- source/gameengine/Ketsji/KX_Camera.h | 8 +- .../gameengine/Ketsji/KX_CollisionSensor.cpp | 8 +- source/gameengine/Ketsji/KX_FontObject.cpp | 2 +- source/gameengine/Ketsji/KX_GameObject.cpp | 215 +++++++++--------- source/gameengine/Ketsji/KX_GameObject.h | 50 ++-- source/gameengine/Ketsji/KX_KetsjiEngine.cpp | 4 +- source/gameengine/Ketsji/KX_NearSensor.cpp | 2 +- source/gameengine/Ketsji/KX_Scene.cpp | 11 +- source/gameengine/Ketsji/KX_Scene.h | 2 +- .../Ketsji/KX_TextureRendererManager.cpp | 2 +- .../Physics/Bullet/CcdPhysicsEnvironment.cpp | 2 +- .../gameengine/VideoTexture/ImageRender.cpp | 2 +- 16 files changed, 153 insertions(+), 190 deletions(-) diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index e93706ffaa15..1500ddc3d31e 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -623,7 +623,7 @@ static void BL_CreateGraphicObjectNew(KX_GameObject *gameobj, KX_Scene *kxscene, PHY_IMotionState *motionstate = new KX_MotionState(gameobj->GetSGNode()); CcdGraphicController *ctrl = new CcdGraphicController(env, motionstate); gameobj->SetGraphicController(ctrl); - ctrl->SetNewClientInfo(gameobj->getClientInfo()); + ctrl->SetNewClientInfo(&gameobj->GetClientInfo()); if (isActive) { // add first, this will create the proxy handle, only if the object is visible if (gameobj->GetVisible()) { @@ -684,7 +684,7 @@ static void BL_CreatePhysicsObjectNew(KX_GameObject *gameobj, Object *blenderobj bool isActor = (blenderobject->gameflag & OB_ACTOR) != 0; bool isSensor = (blenderobject->gameflag & OB_SENSOR) != 0; - gameobj->getClientInfo()->m_type = + gameobj->GetClientInfo().m_type = (isSensor) ? ((isActor) ? KX_ClientObjectInfo::OBACTORSENSOR : KX_ClientObjectInfo::OBSENSOR) : (isActor) ? KX_ClientObjectInfo::ACTOR : KX_ClientObjectInfo::STATIC; } diff --git a/source/gameengine/GameLogic/SCA_IObject.cpp b/source/gameengine/GameLogic/SCA_IObject.cpp index d84df9e38e01..7e389ad58550 100644 --- a/source/gameengine/GameLogic/SCA_IObject.cpp +++ b/source/gameengine/GameLogic/SCA_IObject.cpp @@ -48,6 +48,20 @@ SCA_IObject::SCA_IObject() { } +SCA_IObject::SCA_IObject(const SCA_IObject& other) + :EXP_Value(other), + m_sensors(other.m_sensors), + m_controllers(other.m_controllers), + m_actuators(other.m_actuators), + m_suspended(other.m_suspended), + m_initState(other.m_initState), + m_state(0), + m_firstState(other.m_firstState) +{ + /* Registered objects and actuator are intentionally left empty. + * A new object cannot be client of any actuator. */ +} + SCA_IObject::~SCA_IObject() { for (SCA_ISensor *sensor : m_sensors) { @@ -201,10 +215,6 @@ void SCA_IObject::ReParentLogic() newsensor->ClrLink(); oldsensors[i] = newsensor; } - - // A new object cannot be client of any actuator. - m_registeredActuators.clear(); - m_registeredObjects.clear(); } SCA_ISensor *SCA_IObject::FindSensor(const std::string& sensorname) diff --git a/source/gameengine/GameLogic/SCA_IObject.h b/source/gameengine/GameLogic/SCA_IObject.h index e562d3604997..636ef3e4a6f5 100644 --- a/source/gameengine/GameLogic/SCA_IObject.h +++ b/source/gameengine/GameLogic/SCA_IObject.h @@ -97,6 +97,7 @@ class SCA_IObject : public EXP_Value public: SCA_IObject(); + SCA_IObject(const SCA_IObject& other); virtual ~SCA_IObject(); SCA_ControllerList& GetControllers(); diff --git a/source/gameengine/Ketsji/KX_Camera.cpp b/source/gameengine/Ketsji/KX_Camera.cpp index fe724f848321..472a6a454e27 100644 --- a/source/gameengine/Ketsji/KX_Camera.cpp +++ b/source/gameengine/Ketsji/KX_Camera.cpp @@ -45,8 +45,7 @@ KX_Camera::KX_Camera(void* sgReplicationInfo, SG_Callbacks callbacks, const RAS_CameraData& camdata, - bool frustum_culling, - bool delete_node) + bool frustum_culling) : KX_GameObject(sgReplicationInfo,callbacks), m_camdata(camdata), @@ -56,7 +55,6 @@ KX_Camera::KX_Camera(void* sgReplicationInfo, m_normalized(false), m_frustum_culling(frustum_culling), m_set_projection_matrix(false), - m_delete_node(delete_node), m_lodDistanceFactor(1.0f), m_activityCulling(false), m_showDebugCameraFrustum(false) @@ -68,12 +66,6 @@ KX_Camera::KX_Camera(void* sgReplicationInfo, KX_Camera::~KX_Camera() { - if (m_delete_node && m_sgNode) - { - // for shadow camera, avoids memleak - delete m_sgNode; - m_sgNode = nullptr; - } } @@ -90,8 +82,6 @@ EXP_Value* KX_Camera::GetReplica() void KX_Camera::ProcessReplica() { KX_GameObject::ProcessReplica(); - // replicated camera are always registered in the scene - m_delete_node = false; } mt::mat3x4 KX_Camera::GetWorldToCamera() const diff --git a/source/gameengine/Ketsji/KX_Camera.h b/source/gameengine/Ketsji/KX_Camera.h index f2dcd41f78e9..8e77583cdd3d 100644 --- a/source/gameengine/Ketsji/KX_Camera.h +++ b/source/gameengine/Ketsji/KX_Camera.h @@ -93,12 +93,6 @@ class KX_Camera : public KX_GameObject */ bool m_set_projection_matrix; - /** - * whether the camera should delete the node itself (only for shadow camera) - */ - bool m_delete_node; - - /** Distance factor for level of detail*/ float m_lodDistanceFactor; @@ -118,7 +112,7 @@ class KX_Camera : public KX_GameObject enum { INSIDE, INTERSECT, OUTSIDE }; - KX_Camera(void* sgReplicationInfo,SG_Callbacks callbacks,const RAS_CameraData& camdata, bool frustum_culling = true, bool delete_node = false); + KX_Camera(void* sgReplicationInfo,SG_Callbacks callbacks,const RAS_CameraData& camdata, bool frustum_culling = true); virtual ~KX_Camera(); /** diff --git a/source/gameengine/Ketsji/KX_CollisionSensor.cpp b/source/gameengine/Ketsji/KX_CollisionSensor.cpp index e35ca9cd7475..eeb2194da2d5 100644 --- a/source/gameengine/Ketsji/KX_CollisionSensor.cpp +++ b/source/gameengine/Ketsji/KX_CollisionSensor.cpp @@ -109,8 +109,8 @@ KX_CollisionSensor::KX_CollisionSensor(SCA_EventManager *eventmgr, KX_GameObject { m_colliders = new EXP_ListValue(); - KX_ClientObjectInfo *client_info = gameobj->getClientInfo(); - client_info->m_sensors.push_back(this); + KX_ClientObjectInfo& clientInfo = gameobj->GetClientInfo(); + clientInfo.m_sensors.push_back(this); m_physCtrl = gameobj->GetPhysicsController(); BLI_assert(!gameobj->GetPhysicsController() || m_physCtrl); @@ -155,9 +155,9 @@ void KX_CollisionSensor::ReParent(SCA_IObject *parent) m_physCtrl = sphy; } - KX_ClientObjectInfo *client_info = gameobj->getClientInfo(); + KX_ClientObjectInfo& clientInfo = gameobj->GetClientInfo(); - client_info->m_sensors.push_back(this); + clientInfo.m_sensors.push_back(this); SCA_ISensor::ReParent(parent); } diff --git a/source/gameengine/Ketsji/KX_FontObject.cpp b/source/gameengine/Ketsji/KX_FontObject.cpp index 75c6407994fe..88179a737eba 100644 --- a/source/gameengine/Ketsji/KX_FontObject.cpp +++ b/source/gameengine/Ketsji/KX_FontObject.cpp @@ -128,7 +128,7 @@ void KX_FontObject::ProcessReplica() void KX_FontObject::AddMeshUser() { - m_meshUser = new RAS_TextUser(m_client_info, m_boundingBox); + m_meshUser = new RAS_TextUser(&m_clientInfo, m_boundingBox); // Make sure the mesh user get the matrix even if the object doesn't move. NodeGetWorldTransform().PackFromAffineTransform(m_meshUser->GetMatrix()); diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index a85053fd0120..5ee886c9c001 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -106,37 +106,82 @@ KX_GameObject::ActivityCullingInfo::ActivityCullingInfo() KX_GameObject::KX_GameObject( void* sgReplicationInfo, SG_Callbacks callbacks) - : SCA_IObject(), - m_layer(0), - m_lodManager(nullptr), - m_currentLodLevel(0), - m_meshUser(nullptr), - m_convertInfo(nullptr), - m_bIsNegativeScaling(false), - m_objectColor(mt::one4), - m_bVisible(true), - m_bOccluder(false), - m_autoUpdateBounds(false), - m_physicsController(nullptr), - m_graphicController(nullptr), - m_components(nullptr), - m_instanceObjects(nullptr), - m_dupliGroupObject(nullptr), - m_actionManager(nullptr) + :m_clientInfo(this, KX_ClientObjectInfo::ACTOR), + m_layer(0), + m_lodManager(nullptr), + m_currentLodLevel(0), + m_meshUser(nullptr), + m_convertInfo(nullptr), + m_bIsNegativeScaling(false), + m_objectColor(mt::one4), + m_bVisible(true), + m_bOccluder(false), + m_autoUpdateBounds(false), + m_physicsController(nullptr), + m_graphicController(nullptr), + m_sgNode(new SG_Node(this,sgReplicationInfo,callbacks)), + m_components(nullptr), + m_instanceObjects(nullptr), + m_dupliGroupObject(nullptr), + m_actionManager(nullptr) #ifdef WITH_PYTHON - , m_attr_dict(nullptr), - m_collisionCallbacks(nullptr) + , m_attr_dict(nullptr), + m_collisionCallbacks(nullptr) #endif { - m_client_info = new KX_ClientObjectInfo(this, KX_ClientObjectInfo::ACTOR); - m_sgNode = new SG_Node(this,sgReplicationInfo,callbacks); - // define the relationship between this node and it's parent. KX_NormalParentRelation *parent_relation = new KX_NormalParentRelation(); m_sgNode->SetParentRelation(parent_relation); -}; +} +KX_GameObject::KX_GameObject(const KX_GameObject& other) + :SCA_IObject(other), + m_clientInfo(this, other.m_clientInfo.m_type), + m_name(other.m_name), + m_layer(other.m_layer), + m_meshes(other.m_meshes), + m_lodManager(other.m_lodManager), + m_currentLodLevel(0), + m_meshUser(nullptr), + m_convertInfo(other.m_convertInfo), + m_bIsNegativeScaling(other.m_bIsNegativeScaling), + m_objectColor(other.m_objectColor), + m_bVisible(other.m_bVisible), + m_bOccluder(other.m_bOccluder), + m_activityCullingInfo(other.m_activityCullingInfo), + m_autoUpdateBounds(other.m_autoUpdateBounds), + m_physicsController(nullptr), + m_graphicController(nullptr), + m_sgNode(nullptr), + m_components(nullptr), + m_instanceObjects(nullptr), + m_dupliGroupObject(nullptr), + m_actionManager(nullptr) +#ifdef WITH_PYTHON + , m_attr_dict(other.m_attr_dict), + m_collisionCallbacks(other.m_collisionCallbacks) +#endif // WITH_PYTHON +{ + if (m_lodManager) { + m_lodManager->AddRef(); + } +#ifdef WITH_PYTHON + if (m_attr_dict) { + m_attr_dict = PyDict_Copy(m_attr_dict); + } + + Py_XINCREF(m_collisionCallbacks); + + if (other.m_components) { + m_components = static_cast *>(other.m_components->GetReplica()); + + for (KX_PythonComponent *component : m_components) { + component->SetGameObject(this); + } + } +#endif // WITH_PYTHON +} KX_GameObject::~KX_GameObject() { @@ -147,7 +192,7 @@ KX_GameObject::~KX_GameObject() Py_CLEAR(m_attr_dict); } // Unregister collision callbacks - // Do this before we start freeing physics information like m_client_info + // Do this before we start freeing physics information like m_clientInfo if (m_collisionCallbacks) { UnregisterCollisionCallbacks(); Py_CLEAR(m_collisionCallbacks); @@ -160,50 +205,11 @@ KX_GameObject::~KX_GameObject() RemoveMeshes(); - // is this delete somewhere ? - //if (m_sumoObj) - // delete m_sumoObj; - delete m_client_info; - - //if (m_sgNode) - // delete m_sgNode; - if (m_sgNode) - { - // must go through controllers and make sure they will not use us anymore - // This is important for KX_BulletPhysicsControllers that unregister themselves - // from the object when they are deleted. - SGControllerList::iterator contit; - SGControllerList& controllers = m_sgNode->GetSGControllerList(); - for (contit = controllers.begin();contit!=controllers.end();++contit) - { - (*contit)->ClearNode(); - } - m_sgNode->SetSGClientObject(nullptr); - - /* m_sgNode is freed in KX_Scene::RemoveNodeDestructObject */ - } - if (m_graphicController) - { - delete m_graphicController; - } - - if (m_physicsController) - { - delete m_physicsController; - } - - if (m_actionManager) - { - delete m_actionManager; - } - - if (m_dupliGroupObject) - { + if (m_dupliGroupObject) { m_dupliGroupObject->Release(); } - if (m_instanceObjects) - { + if (m_instanceObjects) { m_instanceObjects->Release(); } if (m_lodManager) { @@ -231,11 +237,26 @@ void KX_GameObject::SetName(const std::string& name) PHY_IPhysicsController* KX_GameObject::GetPhysicsController() { - return m_physicsController; + return m_physicsController.get(); } -KX_GameObject* KX_GameObject::GetDupliGroupObject() +void KX_GameObject::SetPhysicsController(PHY_IPhysicsController *physicscontroller) { + m_physicsController.reset(physicscontroller); +} + +PHY_IGraphicController *KX_GameObject::GetGraphicController() +{ + return m_graphicController.get(); +} + +void KX_GameObject::SetGraphicController(PHY_IGraphicController *graphiccontroller) +{ + m_graphicController.reset(graphiccontroller); +} + +KX_GameObject* KX_GameObject::GetDupliGroupObject() +{ return m_dupliGroupObject; } @@ -300,7 +321,7 @@ void KX_GameObject::ReplicateConstraints(PHY_IPhysicsEnvironment *physEnv, const KX_GameObject* KX_GameObject::GetParent() { KX_GameObject* result = nullptr; - SG_Node* node = m_sgNode; + SG_Node* node = m_sgNode.get(); while (node && !result) { @@ -372,7 +393,7 @@ void KX_GameObject::SetParent(KX_GameObject* obj, bool addToCompound, bool ghost rootobj->m_physicsController != nullptr && rootobj->m_physicsController->IsCompound()) { - rootobj->m_physicsController->AddCompoundChild(m_physicsController); + rootobj->m_physicsController->AddCompoundChild(m_physicsController.get()); } } // graphically, the object hasn't change place, no need to update m_graphicController @@ -408,7 +429,7 @@ void KX_GameObject::RemoveParent() rootobj->m_physicsController != nullptr && rootobj->m_physicsController->IsCompound()) { - rootobj->m_physicsController->RemoveCompoundChild(m_physicsController); + rootobj->m_physicsController->RemoveCompoundChild(m_physicsController.get()); } m_physicsController->RestoreDynamics(); if (m_physicsController->IsDynamic() && (rootobj != nullptr && rootobj->m_physicsController)) @@ -433,9 +454,9 @@ BL_ActionManager* KX_GameObject::GetActionManager() // We only want to create an action manager if we need it if (!m_actionManager) { GetScene()->AddAnimatedObject(this); - m_actionManager = new BL_ActionManager(this); + m_actionManager.reset(new BL_ActionManager(this)); } - return m_actionManager; + return m_actionManager.get(); } bool KX_GameObject::PlayAction(const std::string& name, @@ -503,43 +524,6 @@ void KX_GameObject::SetPlayMode(short layer, short mode) GetActionManager()->SetPlayMode(layer, mode); } -void KX_GameObject::ProcessReplica() -{ - SCA_IObject::ProcessReplica(); - - m_graphicController = nullptr; - m_physicsController = nullptr; - m_sgNode = nullptr; - - /* Dupli group and instance list are set later in replication. - * See KX_Scene::DupliGroupRecurse. */ - m_dupliGroupObject = nullptr; - m_instanceObjects = nullptr; - m_client_info = new KX_ClientObjectInfo(*m_client_info); - m_client_info->m_gameobject = this; - m_actionManager = nullptr; - m_state = 0; - - m_meshUser = nullptr; - if (m_lodManager) { - m_lodManager->AddRef(); - } - -#ifdef WITH_PYTHON - - if (m_attr_dict) - m_attr_dict= PyDict_Copy(m_attr_dict); - - if (m_components) { - m_components = (EXP_ListValue *)m_components->GetReplica(); - for (KX_PythonComponent *component : m_components) { - component->SetGameObject(this); - } - } - -#endif -} - static void setGraphicController_recursive(SG_Node* node) { const NodeList& children = node->GetSGChildren(); @@ -703,7 +687,7 @@ void KX_GameObject::UpdateBlenderObjectMatrix(Object* blendobj) void KX_GameObject::AddMeshUser() { for (size_t i = 0; i < m_meshes.size(); ++i) { - m_meshUser = m_meshes[i]->AddMeshUser(m_client_info, GetDeformer()); + m_meshUser = m_meshes[i]->AddMeshUser(&m_clientInfo, GetDeformer()); // Make sure the mesh user get the matrix even if the object doesn't move. NodeGetWorldTransform().PackFromAffineTransform(m_meshUser->GetMatrix()); } @@ -1395,6 +1379,11 @@ void KX_GameObject::SetConvertObjectInfo(BL_ConvertObjectInfo *info) m_convertInfo = info; } +void KX_GameObject::SetSGNode(SG_Node *node) +{ + m_sgNode.reset(node); +} + void KX_GameObject::UpdateBounds(bool force) { if ((!m_autoUpdateBounds && !force) || !m_meshUser) { @@ -1493,7 +1482,7 @@ void KX_GameObject::UnregisterCollisionCallbacks() // If we are the last to unregister on this physics controller if (pe->RemoveCollisionCallback(spc)) { // If we are a sensor object - if (m_client_info->isSensor()) + if (m_clientInfo.isSensor()) // Remove sensor body from physics world pe->RemoveSensor(spc); } @@ -1513,7 +1502,7 @@ void KX_GameObject::RegisterCollisionCallbacks() // If we are the first to register on this physics controller if (pe->RequestCollisionCallback(spc)) { // If we are a sensor object - if (m_client_info->isSensor()) + if (m_clientInfo.isSensor()) // Add sensor body to physics world pe->AddSensor(spc); } @@ -3607,7 +3596,7 @@ PyObject *KX_GameObject::PyCollide(PyObject *value) } PHY_IPhysicsEnvironment *env = scene->GetPhysicsEnvironment(); - PHY_CollisionTestResult testResult = env->CheckCollision(m_physicsController, other->GetPhysicsController()); + PHY_CollisionTestResult testResult = env->CheckCollision(m_physicsController.get(), other->GetPhysicsController()); PyObject *result = PyTuple_New(2); if (!testResult.collide) { diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index d533cbac4585..52f7ed99a282 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -47,12 +47,11 @@ #include "mathfu.h" #include "KX_Scene.h" #include "KX_KetsjiEngine.h" /* for m_anim_framerate */ +#include "KX_ClientObjectInfo.h" #include "DNA_constraint_types.h" /* for constraint replication */ #include "DNA_object_types.h" #include "SCA_LogicManager.h" /* for ConvertPythonToGameObject to search object names */ -//Forward declarations. -struct KX_ClientObjectInfo; class KX_RayCast; class KX_LodManager; class KX_PythonComponent; @@ -102,7 +101,7 @@ class KX_GameObject : public SCA_IObject, public mt::SimdClassAllocator protected: - KX_ClientObjectInfo* m_client_info; + KX_ClientObjectInfo m_clientInfo; std::string m_name; int m_layer; std::vector m_meshes; @@ -125,11 +124,11 @@ class KX_GameObject : public SCA_IObject, public mt::SimdClassAllocator bool m_autoUpdateBounds; - PHY_IPhysicsController* m_physicsController; - PHY_IGraphicController* m_graphicController; + std::unique_ptr m_physicsController; + std::unique_ptr m_graphicController; SG_CullingNode m_cullingNode; - SG_Node* m_sgNode; + std::unique_ptr m_sgNode; EXP_ListValue *m_components; @@ -137,7 +136,7 @@ class KX_GameObject : public SCA_IObject, public mt::SimdClassAllocator KX_GameObject* m_dupliGroupObject; // The action manager is used to play/stop/update actions - BL_ActionManager* m_actionManager; + std::unique_ptr m_actionManager; BL_ActionManager* GetActionManager(); @@ -328,6 +327,8 @@ class KX_GameObject : public SCA_IObject, public mt::SimdClassAllocator SG_Callbacks callbacks ); + KX_GameObject(const KX_GameObject& other); + virtual ~KX_GameObject( ); @@ -360,12 +361,6 @@ class KX_GameObject : public SCA_IObject, public mt::SimdClassAllocator */ virtual EXP_Value *GetReplica(); - /** - * Makes sure any internal - * data owned by this class is deep copied. Called internally - */ - virtual void ProcessReplica(); - /** * Return the linear velocity of the game object. */ @@ -439,11 +434,7 @@ class KX_GameObject : public SCA_IObject, public mt::SimdClassAllocator */ PHY_IPhysicsController* GetPhysicsController(); - - void SetPhysicsController(PHY_IPhysicsController *physicscontroller) - { - m_physicsController = physicscontroller; - } + void SetPhysicsController(PHY_IPhysicsController *physicscontroller); virtual class RAS_Deformer* GetDeformer() { @@ -462,15 +453,9 @@ class KX_GameObject : public SCA_IObject, public mt::SimdClassAllocator /** * \return a pointer to the graphic controller owner by this class */ - PHY_IGraphicController* GetGraphicController() - { - return m_graphicController; - } + PHY_IGraphicController* GetGraphicController(); + void SetGraphicController(PHY_IGraphicController* graphiccontroller); - void SetGraphicController(PHY_IGraphicController* graphiccontroller) - { - m_graphicController = graphiccontroller; - } /* * @add/remove the graphic controller to the physic system */ @@ -482,7 +467,7 @@ class KX_GameObject : public SCA_IObject, public mt::SimdClassAllocator void SetCollisionGroup(unsigned short filter); /** Set the object's collison mask - * \param filter The mask bitfield + * \param mask The mask bitfield */ void SetCollisionMask(unsigned short mask); unsigned short GetCollisionGroup() const; @@ -523,12 +508,12 @@ class KX_GameObject : public SCA_IObject, public mt::SimdClassAllocator SG_Node* GetSGNode( ) { - return m_sgNode; + return m_sgNode.get(); } const SG_Node* GetSGNode( ) const { - return m_sgNode; + return m_sgNode.get(); } Object *GetBlenderObject() const; @@ -552,10 +537,7 @@ class KX_GameObject : public SCA_IObject, public mt::SimdClassAllocator * old node. This class takes ownership of the new * node. */ - void SetSGNode(SG_Node* node ) - { - m_sgNode = node; - } + void SetSGNode(SG_Node *node); /// Is it a dynamic/physics object ? bool IsDynamic() const; @@ -867,7 +849,7 @@ class KX_GameObject : public SCA_IObject, public mt::SimdClassAllocator */ void SetUseDebugProperties(bool debug, bool recursive); - KX_ClientObjectInfo* getClientInfo() { return m_client_info; } + KX_ClientObjectInfo& GetClientInfo() { return m_clientInfo; } std::vector GetChildren() const; std::vector GetChildrenRecursive() const; diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index a279b1341f00..69ee0f891e5f 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -499,7 +499,7 @@ KX_KetsjiEngine::CameraRenderData KX_KetsjiEngine::GetCameraRenderData(KX_Scene */ const bool usestereo = (stereoMode != RAS_Rasterizer::RAS_STEREO_NOSTEREO); if (usestereo) { - rendercam = new KX_Camera(scene, scene->m_callbacks, *camera->GetCameraData(), true, true); + rendercam = new KX_Camera(scene, scene->m_callbacks, *camera->GetCameraData(), true); rendercam->SetName("__stereo_" + camera->GetName() + "_" + std::to_string(eye) + "__"); rendercam->NodeSetGlobalOrientation(camera->NodeGetWorldOrientation()); rendercam->NodeSetWorldPosition(camera->NodeGetWorldPosition()); @@ -854,7 +854,7 @@ void KX_KetsjiEngine::RenderShadowBuffers(KX_Scene *scene) if (light->GetVisible() && raslight->HasShadowBuffer() && raslight->NeedShadowUpdate()) { /* make temporary camera */ RAS_CameraData camdata = RAS_CameraData(); - KX_Camera *cam = new KX_Camera(scene, scene->m_callbacks, camdata, true, true); + KX_Camera *cam = new KX_Camera(scene, scene->m_callbacks, camdata, true); cam->SetName("__shadow__cam__"); mt::mat3x4 camtrans; diff --git a/source/gameengine/Ketsji/KX_NearSensor.cpp b/source/gameengine/Ketsji/KX_NearSensor.cpp index 301dbefbda7c..361ed8360469 100644 --- a/source/gameengine/Ketsji/KX_NearSensor.cpp +++ b/source/gameengine/Ketsji/KX_NearSensor.cpp @@ -59,7 +59,7 @@ KX_NearSensor::KX_NearSensor(SCA_EventManager* eventmgr, { - gameobj->getClientInfo()->m_sensors.remove(this); + gameobj->GetClientInfo().m_sensors.remove(this); m_client_info = new KX_ClientObjectInfo(gameobj, KX_ClientObjectInfo::SENSOR); m_client_info->m_sensors.push_back(this); diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 6639c8060e3e..8918e1a85a1b 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -120,7 +120,7 @@ static void *KX_SceneReplicationFunc(SG_Node *node, void *gameobj, void *scene) static void *KX_SceneDestructionFunc(SG_Node *node, void *gameobj, void *scene) { - ((KX_Scene *)scene)->RemoveNodeDestructObject(node, (KX_GameObject *)gameobj); + ((KX_Scene *)scene)->RemoveNodeDestructObject((KX_GameObject *)gameobj); return nullptr; } @@ -443,7 +443,7 @@ void KX_Scene::AddObjectDebugProperties(KX_GameObject *gameobj) } } -void KX_Scene::RemoveNodeDestructObject(SG_Node *node, KX_GameObject *gameobj) +void KX_Scene::RemoveNodeDestructObject(KX_GameObject *gameobj) { if (NewRemoveObject(gameobj)) { /* Object is not yet deleted because a reference is hanging somewhere. @@ -451,9 +451,6 @@ void KX_Scene::RemoveNodeDestructObject(SG_Node *node, KX_GameObject *gameobj) CM_Error("zombie object! name=" << gameobj->GetName()); BLI_assert(false); } - if (node) { - delete node; - } } KX_GameObject *KX_Scene::AddNodeReplicaObject(SG_Node *node, KX_GameObject *gameobj) @@ -555,7 +552,7 @@ KX_GameObject *KX_Scene::AddNodeReplicaObject(SG_Node *node, KX_GameObject *game if (gameobj->GetGraphicController()) { PHY_IMotionState *motionstate = new KX_MotionState(newobj->GetSGNode()); PHY_IGraphicController *newctrl = gameobj->GetGraphicController()->GetReplica(motionstate); - newctrl->SetNewClientInfo(newobj->getClientInfo()); + newctrl->SetNewClientInfo(&newobj->GetClientInfo()); newobj->SetGraphicController(newctrl); } @@ -567,7 +564,7 @@ KX_GameObject *KX_Scene::AddNodeReplicaObject(SG_Node *node, KX_GameObject *game KX_GameObject *parent = newobj->GetParent(); PHY_IPhysicsController *parentctrl = (parent) ? parent->GetPhysicsController() : nullptr; - newctrl->SetNewClientInfo(newobj->getClientInfo()); + newctrl->SetNewClientInfo(&newobj->GetClientInfo()); newobj->SetPhysicsController(newctrl); newctrl->PostProcessReplica(motionstate, parentctrl); diff --git a/source/gameengine/Ketsji/KX_Scene.h b/source/gameengine/Ketsji/KX_Scene.h index 999bf760de8f..07eb2d01359a 100644 --- a/source/gameengine/Ketsji/KX_Scene.h +++ b/source/gameengine/Ketsji/KX_Scene.h @@ -283,7 +283,7 @@ class KX_Scene : public EXP_Value, public SCA_IScene KX_GameObject *AddReplicaObject(KX_GameObject *gameobj, KX_GameObject *locationobj, float lifespan = 0.0f); KX_GameObject *AddNodeReplicaObject(SG_Node *node, KX_GameObject *gameobj); - void RemoveNodeDestructObject(SG_Node *node, KX_GameObject *gameobj); + void RemoveNodeDestructObject(KX_GameObject *gameobj); void RemoveObject(KX_GameObject *gameobj); void RemoveDupliGroup(KX_GameObject *gameobj); void DelayedRemoveObject(KX_GameObject *gameobj); diff --git a/source/gameengine/Ketsji/KX_TextureRendererManager.cpp b/source/gameengine/Ketsji/KX_TextureRendererManager.cpp index 4fed50671c24..1e7b19576756 100644 --- a/source/gameengine/Ketsji/KX_TextureRendererManager.cpp +++ b/source/gameengine/Ketsji/KX_TextureRendererManager.cpp @@ -43,7 +43,7 @@ KX_TextureRendererManager::KX_TextureRendererManager(KX_Scene *scene) :m_scene(scene) { const RAS_CameraData& camdata = RAS_CameraData(); - m_camera = new KX_Camera(m_scene, KX_Scene::m_callbacks, camdata, true, true); + m_camera = new KX_Camera(m_scene, KX_Scene::m_callbacks, camdata, true); m_camera->SetName("__renderer_cam__"); } diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index 6efa06317abe..7c2786021443 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -3110,7 +3110,7 @@ void CcdPhysicsEnvironment::ConvertObject(BL_SceneConverter& converter, KX_GameO gameobj->SetPhysicsController(physicscontroller); - physicscontroller->SetNewClientInfo(gameobj->getClientInfo()); + physicscontroller->SetNewClientInfo(&gameobj->GetClientInfo()); // don't add automatically sensor object, they are added when a collision sensor is registered if (!isbulletsensor && (blenderobject->lay & activeLayerBitInfo) != 0) { diff --git a/source/gameengine/VideoTexture/ImageRender.cpp b/source/gameengine/VideoTexture/ImageRender.cpp index 070ce3c28f57..850d24d3b0fa 100644 --- a/source/gameengine/VideoTexture/ImageRender.cpp +++ b/source/gameengine/VideoTexture/ImageRender.cpp @@ -894,7 +894,7 @@ ImageRender::ImageRender (KX_Scene *scene, KX_GameObject *observer, KX_GameObjec float mirrorMat[3][3]; float left, right, top, bottom, back; // make sure this camera will delete its node - m_camera= new KX_Camera(scene, KX_Scene::m_callbacks, camdata, true, true); + m_camera= new KX_Camera(scene, KX_Scene::m_callbacks, camdata, true); m_camera->SetName("__mirror__cam__"); // don't add the camera to the scene object list, it doesn't need to be accessible m_owncamera = true;