Skip to content

Commit c6f26f0

Browse files
authored
Code review for ModelMeshPart collection (#532)
1 parent c7fa8f8 commit c6f26f0

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

Src/ModelLoadCMO.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromCMO(
767767

768768
auto& mat = materials[sm.MaterialIndex];
769769

770-
auto part = new ModelMeshPart();
770+
auto part = std::make_unique<ModelMeshPart>();
771771

772772
if (mat.pMaterial->Diffuse.w < 1)
773773
part->isAlpha = true;
@@ -781,7 +781,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromCMO(
781781
part->effect = mat.effect;
782782
part->vbDecl = enableSkinning ? g_vbdeclSkinning : g_vbdecl;
783783

784-
mesh->meshParts.emplace_back(part);
784+
mesh->meshParts.emplace_back(std::move(part));
785785
}
786786

787787
model->meshes.emplace_back(mesh);

Src/ModelLoadSDKMESH.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromSDKMESH(
704704

705705
SetDebugObjectName(il.Get(), "ModelSDKMESH");
706706

707-
auto part = new ModelMeshPart();
707+
auto part = std::make_unique<ModelMeshPart>();
708708
part->isAlpha = mat.alpha;
709709

710710
part->indexCount = static_cast<uint32_t>(subset.IndexCount);
@@ -719,7 +719,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromSDKMESH(
719719
part->effect = mat.effect;
720720
part->vbDecl = vbDecls[mh.VertexBuffers[0]];
721721

722-
mesh->meshParts.emplace_back(part);
722+
mesh->meshParts.emplace_back(std::move(part));
723723
}
724724

725725
model->meshes.emplace_back(mesh);

Src/ModelLoadVBO.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ std::unique_ptr<Model> DirectX::Model::CreateFromVBO(
152152

153153
SetDebugObjectName(il.Get(), "ModelVBO");
154154

155-
auto part = new ModelMeshPart();
155+
auto part = std::make_unique<ModelMeshPart>();
156156
part->indexCount = header->numIndices;
157157
part->startIndex = 0;
158158
part->vertexStride = static_cast<UINT>(sizeof(VertexPositionNormalTexture));
@@ -167,9 +167,11 @@ std::unique_ptr<Model> DirectX::Model::CreateFromVBO(
167167
mesh->pmalpha = (flags & ModelLoader_PremultipledAlpha) != 0;
168168
BoundingSphere::CreateFromPoints(mesh->boundingSphere, header->numVertices, &verts->position, sizeof(VertexPositionNormalTexture));
169169
BoundingBox::CreateFromPoints(mesh->boundingBox, header->numVertices, &verts->position, sizeof(VertexPositionNormalTexture));
170-
mesh->meshParts.emplace_back(part);
170+
mesh->meshParts.reserve(1);
171+
mesh->meshParts.emplace_back(std::move(part));
171172

172173
auto model = std::make_unique<Model>();
174+
model->meshes.reserve(1);
173175
model->meshes.emplace_back(mesh);
174176

175177
return model;

0 commit comments

Comments
 (0)