diff --git a/source/gameengine/Ketsji/KX_FontObject.cpp b/source/gameengine/Ketsji/KX_FontObject.cpp index 4d37937c2006..57b21dbbed66 100644 --- a/source/gameengine/Ketsji/KX_FontObject.cpp +++ b/source/gameengine/Ketsji/KX_FontObject.cpp @@ -136,8 +136,7 @@ void KX_FontObject::AddMeshUser() RAS_BucketManager *bucketManager = GetScene()->GetBucketManager(); RAS_DisplayArrayBucket *arrayBucket = bucketManager->GetTextDisplayArrayBucket(); - RAS_MeshSlot *ms = new RAS_MeshSlot(m_meshUser, arrayBucket); - m_meshUser->AddMeshSlot(ms); + m_meshUser->NewMeshSlot(arrayBucket); } void KX_FontObject::UpdateBuckets() diff --git a/source/gameengine/Rasterizer/RAS_BatchGroup.cpp b/source/gameengine/Rasterizer/RAS_BatchGroup.cpp index f1a0bd9160b8..5f42ee4726d3 100644 --- a/source/gameengine/Rasterizer/RAS_BatchGroup.cpp +++ b/source/gameengine/Rasterizer/RAS_BatchGroup.cpp @@ -70,14 +70,14 @@ RAS_BatchGroup *RAS_BatchGroup::RemoveMeshUser() return this; } -bool RAS_BatchGroup::MergeMeshSlot(RAS_BatchGroup::Batch& batch, RAS_MeshSlot *slot, const mt::mat4& mat) +bool RAS_BatchGroup::MergeMeshSlot(RAS_BatchGroup::Batch& batch, RAS_MeshSlot& slot, const mt::mat4& mat) { - RAS_DisplayArrayBucket *origArrayBucket = slot->m_displayArrayBucket; + RAS_DisplayArrayBucket *origArrayBucket = slot.m_displayArrayBucket; RAS_IDisplayArray *origArray = origArrayBucket->GetDisplayArray(); RAS_DisplayArrayBucket *arrayBucket = batch.m_displayArrayBucket; RAS_IBatchDisplayArray *array = batch.m_displayArray; - if (batch.m_originalDisplayArrayBucketList.find(slot) != batch.m_originalDisplayArrayBucketList.end()) { + if (batch.m_originalDisplayArrayBucketList.find(&slot) != batch.m_originalDisplayArrayBucketList.end()) { CM_Error("could not merge twice a mesh"); return false; } @@ -89,21 +89,21 @@ bool RAS_BatchGroup::MergeMeshSlot(RAS_BatchGroup::Batch& batch, RAS_MeshSlot *s } // Store original display array bucket. - batch.m_originalDisplayArrayBucketList[slot] = origArrayBucket; - batch.m_meshSlots.push_back(slot); + batch.m_originalDisplayArrayBucketList[&slot] = origArrayBucket; + batch.m_meshSlots.push_back(&slot); // Merge display array. const unsigned int index = array->Merge(origArray, mat); - slot->m_batchPartIndex = index; + slot.m_batchPartIndex = index; - slot->SetDisplayArrayBucket(arrayBucket); + slot.SetDisplayArrayBucket(arrayBucket); return true; } -bool RAS_BatchGroup::SplitMeshSlot(RAS_MeshSlot *slot) +bool RAS_BatchGroup::SplitMeshSlot(RAS_MeshSlot& slot) { - RAS_MaterialBucket *bucket = slot->m_displayArrayBucket->GetBucket(); + RAS_MaterialBucket *bucket = slot.m_displayArrayBucket->GetBucket(); RAS_IPolyMaterial *material = bucket->GetPolyMaterial(); std::map::iterator bit = m_batchs.find(material); @@ -114,23 +114,23 @@ bool RAS_BatchGroup::SplitMeshSlot(RAS_MeshSlot *slot) Batch& batch = bit->second; - RAS_DisplayArrayBucket *origArrayBucket = batch.m_originalDisplayArrayBucketList[slot]; + RAS_DisplayArrayBucket *origArrayBucket = batch.m_originalDisplayArrayBucketList[&slot]; if (!origArrayBucket) { CM_Error("could not restore mesh"); return false; } - slot->SetDisplayArrayBucket(origArrayBucket); + slot.SetDisplayArrayBucket(origArrayBucket); - batch.m_displayArray->Split(slot->m_batchPartIndex); + batch.m_displayArray->Split(slot.m_batchPartIndex); - batch.m_originalDisplayArrayBucketList.erase(slot); + batch.m_originalDisplayArrayBucketList.erase(&slot); - slot->m_batchPartIndex = -1; + slot.m_batchPartIndex = -1; // One part is removed and then all the part after must use an index smaller of one. - RAS_MeshSlotList::iterator mit = batch.m_meshSlots.erase(std::find(batch.m_meshSlots.begin(), batch.m_meshSlots.end(), slot)); + RAS_MeshSlotList::iterator mit = batch.m_meshSlots.erase(std::find(batch.m_meshSlots.begin(), batch.m_meshSlots.end(), &slot)); for (RAS_MeshSlotList::iterator it = mit, end = batch.m_meshSlots.end(); it != end; ++it) { RAS_MeshSlot *meshSlot = *it; --meshSlot->m_batchPartIndex; @@ -141,8 +141,8 @@ bool RAS_BatchGroup::SplitMeshSlot(RAS_MeshSlot *slot) bool RAS_BatchGroup::MergeMeshUser(RAS_MeshUser *meshUser, const mt::mat4& mat) { - for (RAS_MeshSlot *meshSlot : meshUser->GetMeshSlots()) { - RAS_DisplayArrayBucket *arrayBucket = meshSlot->m_displayArrayBucket; + for (RAS_MeshSlot& meshSlot : meshUser->GetMeshSlots()) { + RAS_DisplayArrayBucket *arrayBucket = meshSlot.m_displayArrayBucket; RAS_MaterialBucket *bucket = arrayBucket->GetBucket(); RAS_IPolyMaterial *material = bucket->GetPolyMaterial(); @@ -167,7 +167,7 @@ bool RAS_BatchGroup::MergeMeshUser(RAS_MeshUser *meshUser, const mt::mat4& mat) bool RAS_BatchGroup::SplitMeshUser(RAS_MeshUser *meshUser) { - for (RAS_MeshSlot *meshSlot : meshUser->GetMeshSlots()) { + for (RAS_MeshSlot& meshSlot : meshUser->GetMeshSlots()) { if (!SplitMeshSlot(meshSlot)) { return false; } diff --git a/source/gameengine/Rasterizer/RAS_BatchGroup.h b/source/gameengine/Rasterizer/RAS_BatchGroup.h index 4e1d6423593a..9fe12080786c 100644 --- a/source/gameengine/Rasterizer/RAS_BatchGroup.h +++ b/source/gameengine/Rasterizer/RAS_BatchGroup.h @@ -63,13 +63,13 @@ class RAS_BatchGroup * \param mat The transform matrix to apply to vertices during merging. * \return false on failure. */ - bool MergeMeshSlot(Batch& batch, RAS_MeshSlot *slot, const mt::mat4& mat); + bool MergeMeshSlot(Batch& batch, RAS_MeshSlot& slot, const mt::mat4& mat); /** Split the part representing the display array containing in the passed mesh slot. * \param slot The mesh slot using the display array to split. * \return false on failure. */ - bool SplitMeshSlot(RAS_MeshSlot *slot); + bool SplitMeshSlot(RAS_MeshSlot& slot); public: RAS_BatchGroup(); diff --git a/source/gameengine/Rasterizer/RAS_Mesh.cpp b/source/gameengine/Rasterizer/RAS_Mesh.cpp index fc1db15a3c19..81528fd29769 100644 --- a/source/gameengine/Rasterizer/RAS_Mesh.cpp +++ b/source/gameengine/Rasterizer/RAS_Mesh.cpp @@ -213,8 +213,7 @@ RAS_MeshUser *RAS_Mesh::AddMeshUser(void *clientobj, RAS_Deformer *deformer) for (unsigned short i = 0, nummat = m_materials.size(); i < nummat; ++i) { RAS_DisplayArrayBucket *arrayBucket = (deformer) ? deformer->GetDisplayArrayBucket(i) : m_materials[i]->GetDisplayArrayBucket(); - RAS_MeshSlot *ms = new RAS_MeshSlot(meshUser, arrayBucket); - meshUser->AddMeshSlot(ms); + meshUser->NewMeshSlot(arrayBucket); } return meshUser; } diff --git a/source/gameengine/Rasterizer/RAS_MeshSlot.cpp b/source/gameengine/Rasterizer/RAS_MeshSlot.cpp index a5c776c6a073..50d8c830c360 100644 --- a/source/gameengine/Rasterizer/RAS_MeshSlot.cpp +++ b/source/gameengine/Rasterizer/RAS_MeshSlot.cpp @@ -60,6 +60,14 @@ RAS_MeshSlot::~RAS_MeshSlot() { } +RAS_MeshSlot::RAS_MeshSlot(const RAS_MeshSlot& other) + :m_node(this, &dummyNodeData, &RAS_MeshSlot::RunNode, nullptr), + m_displayArrayBucket(other.m_displayArrayBucket), + m_meshUser(other.m_meshUser), + m_batchPartIndex(other.m_batchPartIndex) +{ +} + void RAS_MeshSlot::SetDisplayArrayBucket(RAS_DisplayArrayBucket *arrayBucket) { m_displayArrayBucket = arrayBucket; diff --git a/source/gameengine/Rasterizer/RAS_MeshSlot.h b/source/gameengine/Rasterizer/RAS_MeshSlot.h index c6f881af005c..5bfe5c8ced0f 100644 --- a/source/gameengine/Rasterizer/RAS_MeshSlot.h +++ b/source/gameengine/Rasterizer/RAS_MeshSlot.h @@ -53,6 +53,7 @@ class RAS_MeshSlot short m_batchPartIndex; RAS_MeshSlot(RAS_MeshUser *meshUser, RAS_DisplayArrayBucket *arrayBucket); + RAS_MeshSlot(const RAS_MeshSlot& other); virtual ~RAS_MeshSlot(); void SetDisplayArrayBucket(RAS_DisplayArrayBucket *arrayBucket); diff --git a/source/gameengine/Rasterizer/RAS_MeshUser.cpp b/source/gameengine/Rasterizer/RAS_MeshUser.cpp index 3328ca5b22b7..5c7e9a0bc639 100644 --- a/source/gameengine/Rasterizer/RAS_MeshUser.cpp +++ b/source/gameengine/Rasterizer/RAS_MeshUser.cpp @@ -44,9 +44,6 @@ RAS_MeshUser::RAS_MeshUser(void *clientobj, RAS_BoundingBox *boundingBox) RAS_MeshUser::~RAS_MeshUser() { - for (RAS_MeshSlot *ms : m_meshSlots) { - delete ms; - } m_meshSlots.clear(); m_boundingBox->RemoveUser(); @@ -57,9 +54,9 @@ RAS_MeshUser::~RAS_MeshUser() } } -void RAS_MeshUser::AddMeshSlot(RAS_MeshSlot *meshSlot) +void RAS_MeshUser::NewMeshSlot(RAS_DisplayArrayBucket *arrayBucket) { - m_meshSlots.push_back(meshSlot); + m_meshSlots.emplace_back(this, arrayBucket); } bool RAS_MeshUser::GetFrontFace() const @@ -87,7 +84,7 @@ void *RAS_MeshUser::GetClientObject() const return m_clientObject; } -RAS_MeshSlotList& RAS_MeshUser::GetMeshSlots() +std::vector& RAS_MeshUser::GetMeshSlots() { return m_meshSlots; } @@ -122,7 +119,7 @@ void RAS_MeshUser::SetBatchGroup(RAS_BatchGroup *batchGroup) void RAS_MeshUser::ActivateMeshSlots() { - for (RAS_MeshSlot *ms : m_meshSlots) { - ms->m_displayArrayBucket->ActivateMesh(ms); + for (RAS_MeshSlot& ms : m_meshSlots) { + ms.m_displayArrayBucket->ActivateMesh(&ms); } } diff --git a/source/gameengine/Rasterizer/RAS_MeshUser.h b/source/gameengine/Rasterizer/RAS_MeshUser.h index 7c5aeedaf24d..85ab68af36d1 100644 --- a/source/gameengine/Rasterizer/RAS_MeshUser.h +++ b/source/gameengine/Rasterizer/RAS_MeshUser.h @@ -48,7 +48,7 @@ class RAS_MeshUser : public mt::SimdClassAllocator /// Client object owner of this mesh user. void *m_clientObject; /// Unique mesh slots used for render of this object. - RAS_MeshSlotList m_meshSlots; + std::vector m_meshSlots; /// Possible batching groups shared between mesh users. RAS_BatchGroup *m_batchGroup; @@ -56,13 +56,13 @@ class RAS_MeshUser : public mt::SimdClassAllocator RAS_MeshUser(void *clientobj, RAS_BoundingBox *boundingBox); virtual ~RAS_MeshUser(); - void AddMeshSlot(RAS_MeshSlot *meshSlot); + void NewMeshSlot(RAS_DisplayArrayBucket *arrayBucket); bool GetFrontFace() const; const mt::vec4& GetColor() const; float *GetMatrix(); RAS_BoundingBox *GetBoundingBox() const; void *GetClientObject() const; - RAS_MeshSlotList& GetMeshSlots(); + std::vector& GetMeshSlots(); RAS_BatchGroup *GetBatchGroup() const; void SetFrontFace(bool frontFace);