diff --git a/source/gameengine/Rasterizer/RAS_MeshObject.cpp b/source/gameengine/Rasterizer/RAS_MeshObject.cpp index 585a92d11b52..e63b6f1570f3 100644 --- a/source/gameengine/Rasterizer/RAS_MeshObject.cpp +++ b/source/gameengine/Rasterizer/RAS_MeshObject.cpp @@ -112,11 +112,6 @@ RAS_MeshObject::RAS_MeshObject(Mesh *mesh, const LayersInfo& layersInfo) RAS_MeshObject::~RAS_MeshObject() { - std::vector::iterator it; - - for (it = m_polygons.begin(); it != m_polygons.end(); it++) - delete (*it); - m_sharedvertex_map.clear(); m_polygons.clear(); @@ -167,9 +162,9 @@ int RAS_MeshObject::NumPolygons() return m_polygons.size(); } -RAS_Polygon *RAS_MeshObject::GetPolygon(int num) const +RAS_Polygon *RAS_MeshObject::GetPolygon(int num) { - return m_polygons[num]; + return &m_polygons[num]; } std::string& RAS_MeshObject::GetName() @@ -216,15 +211,14 @@ RAS_Polygon *RAS_MeshObject::AddPolygon(RAS_MeshMaterial *meshmat, int numverts, // create a new polygon RAS_IDisplayArray *darray = meshmat->GetDisplayArray(); - RAS_Polygon *poly = new RAS_Polygon(bucket, darray, numverts); - m_polygons.push_back(poly); + RAS_Polygon poly(bucket, darray, numverts); - poly->SetVisible(visible); - poly->SetCollider(collider); - poly->SetTwoside(twoside); + poly.SetVisible(visible); + poly.SetCollider(collider); + poly.SetTwoside(twoside); for (unsigned short i = 0; i < numverts; ++i) { - poly->SetVertexOffset(i, indices[i]); + poly.SetVertexOffset(i, indices[i]); } if (visible && !bucket->IsWire()) { @@ -241,7 +235,8 @@ RAS_Polygon *RAS_MeshObject::AddPolygon(RAS_MeshMaterial *meshmat, int numverts, } } - return poly; + m_polygons.push_back(poly); + return &m_polygons.back(); } unsigned int RAS_MeshObject::AddVertex( @@ -459,10 +454,10 @@ void RAS_MeshObject::SortPolygons(RAS_IDisplayArray *array, const MT_Transform & bool RAS_MeshObject::HasColliderPolygon() { - int numpolys = NumPolygons(); - for (int p = 0; p < numpolys; p++) { - if (m_polygons[p]->IsCollider()) + for (const RAS_Polygon& poly : m_polygons) { + if (poly.IsCollider()) { return true; + } } return false; diff --git a/source/gameengine/Rasterizer/RAS_MeshObject.h b/source/gameengine/Rasterizer/RAS_MeshObject.h index 0ad188f4f497..34c1a33e6e81 100644 --- a/source/gameengine/Rasterizer/RAS_MeshObject.h +++ b/source/gameengine/Rasterizer/RAS_MeshObject.h @@ -92,7 +92,7 @@ class RAS_MeshObject LayersInfo m_layersInfo; - std::vector m_polygons; + std::vector m_polygons; /* polygon sorting */ struct polygonSlot; @@ -149,7 +149,7 @@ class RAS_MeshObject const float *GetVertexLocation(unsigned int orig_index); int NumPolygons(); - RAS_Polygon *GetPolygon(int num) const; + RAS_Polygon *GetPolygon(int num); RAS_BoundingBox *GetBoundingBox() const; // buckets diff --git a/source/gameengine/Rasterizer/RAS_Polygon.cpp b/source/gameengine/Rasterizer/RAS_Polygon.cpp index 7bcfe9c873eb..a6201d7fe103 100644 --- a/source/gameengine/Rasterizer/RAS_Polygon.cpp +++ b/source/gameengine/Rasterizer/RAS_Polygon.cpp @@ -46,7 +46,7 @@ RAS_Polygon::RAS_Polygon(RAS_MaterialBucket *bucket, RAS_IDisplayArray *darray, m_offset[0] = m_offset[1] = m_offset[2] = m_offset[3] = 0; } -int RAS_Polygon::VertexCount() +int RAS_Polygon::VertexCount() const { return m_numvert; } @@ -56,22 +56,22 @@ void RAS_Polygon::SetVertexOffset(int i, unsigned int offset) m_offset[i] = offset; } -RAS_ITexVert *RAS_Polygon::GetVertex(int i) +RAS_ITexVert *RAS_Polygon::GetVertex(int i) const { return m_darray->GetVertex(m_offset[i]); } -RAS_TexVertInfo& RAS_Polygon::GetVertexInfo(unsigned int i) +const RAS_TexVertInfo& RAS_Polygon::GetVertexInfo(unsigned int i) const { return m_darray->GetVertexInfo(m_offset[i]); } -unsigned int RAS_Polygon::GetVertexOffset(unsigned int i) +unsigned int RAS_Polygon::GetVertexOffset(unsigned int i) const { return m_offset[i]; } -bool RAS_Polygon::IsVisible() +bool RAS_Polygon::IsVisible() const { return (m_polyflags & VISIBLE) != 0; } @@ -86,7 +86,7 @@ void RAS_Polygon::SetVisible(bool visible) } } -bool RAS_Polygon::IsCollider() +bool RAS_Polygon::IsCollider() const { return (m_polyflags & COLLIDER) != 0; } @@ -101,7 +101,7 @@ void RAS_Polygon::SetCollider(bool visible) } } -bool RAS_Polygon::IsTwoside() +bool RAS_Polygon::IsTwoside() const { return (m_polyflags & TWOSIDE) != 0; } @@ -116,12 +116,12 @@ void RAS_Polygon::SetTwoside(bool twoside) } } -RAS_MaterialBucket *RAS_Polygon::GetMaterial() +RAS_MaterialBucket *RAS_Polygon::GetMaterial() const { return m_bucket; } -RAS_IDisplayArray *RAS_Polygon::GetDisplayArray() +RAS_IDisplayArray *RAS_Polygon::GetDisplayArray() const { return m_darray; } diff --git a/source/gameengine/Rasterizer/RAS_Polygon.h b/source/gameengine/Rasterizer/RAS_Polygon.h index 59c9c1c383c5..4c74c730ee9f 100644 --- a/source/gameengine/Rasterizer/RAS_Polygon.h +++ b/source/gameengine/Rasterizer/RAS_Polygon.h @@ -58,24 +58,24 @@ class RAS_Polygon { } - int VertexCount(); - RAS_ITexVert *GetVertex(int i); - RAS_TexVertInfo& GetVertexInfo(unsigned int i); + int VertexCount() const; + RAS_ITexVert *GetVertex(int i) const; + const RAS_TexVertInfo& GetVertexInfo(unsigned int i) const; void SetVertexOffset(int i, unsigned int offset); - unsigned int GetVertexOffset(unsigned int i); + unsigned int GetVertexOffset(unsigned int i) const; - bool IsVisible(); + bool IsVisible() const; void SetVisible(bool visible); - bool IsCollider(); + bool IsCollider() const; void SetCollider(bool collider); - bool IsTwoside(); + bool IsTwoside() const; void SetTwoside(bool twoside); - RAS_MaterialBucket *GetMaterial(); - RAS_IDisplayArray *GetDisplayArray(); + RAS_MaterialBucket *GetMaterial() const; + RAS_IDisplayArray *GetDisplayArray() const; }; #endif