Unique Ptrs, Const correctness

This commit is contained in:
2025-01-14 20:51:17 +01:00
parent 0d556f12b4
commit a3a6011e43
27 changed files with 128 additions and 130 deletions

View File

@@ -15,19 +15,20 @@ void DioramaScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *Devi
std::vector<std::unique_ptr<Utils::MaterialMesh>> materialMeshes;
Utils::LoadObjWithMaterials("resources/scene.obj", materialMeshes, true, DevicePtr);
for (const auto &mesh: materialMeshes) {
if (mesh->vertices.size() > 0) {
if (!mesh->vertices.empty()) {
std::shared_ptr<Material> material = std::make_shared<Material>();
BaseEffect *effect{nullptr};
std::unique_ptr<BaseEffect> effect{};
if (mesh->opacity_map != "") {
effect = new FireEffect(DevicePtr, L"resources/Fire.fx");
if (!mesh->opacity_map.empty()) {
effect = std::make_unique<FireEffect>(DevicePtr, L"resources/Fire.fx");
material->diffuseTexturePtr = Texture::LoadFromFile("./resources/diorama/" + mesh->diffuse_texture, DevicePtr);
} else {
material->diffuseTexturePtr = Texture::LoadFromFile("./resources/diorama/" + mesh->diffuse_texture, DevicePtr);
effect = new Effect(DevicePtr, L"resources/SimpleDiffuse.fx");
effect = std::make_unique<Effect>(DevicePtr, L"resources/SimpleDiffuse.fx");
}
auto newMesh = std::make_unique<Mesh>(DevicePtr, mesh->vertices, mesh->indices, material, std::move(effect));
m_meshes.push_back(std::move(newMesh));
m_meshes.push_back(new Mesh(DevicePtr, mesh->vertices, mesh->indices, material, effect));
Matrix worldMatrix = m_meshes.back()->GetWorldMatrix();
worldMatrix *= Matrix::CreateScale(2.f, 2.f, 2.f);
@@ -42,13 +43,15 @@ void DioramaScene::Initialize(ID3D11Device *DevicePtr, ID3D11DeviceContext *Devi
for (const auto &mesh: materialMeshes) {
if (!mesh->vertices.empty()) {
std::shared_ptr<Material> material = std::make_shared<Material>();
BaseEffect *effect{nullptr};
auto effect = std::make_unique<Effect>(DevicePtr, L"resources/SimpleDiffuse.fx");
effect = new Effect(DevicePtr, L"resources/SimpleDiffuse.fx");
material->diffuseTexturePtr = Texture::LoadFromFile("./resources/brok/" + mesh->diffuse_texture, DevicePtr);
m_meshes.push_back(new Mesh(DevicePtr, mesh->vertices, mesh->indices, material, effect));
m_brokMeshses.push_back(m_meshes.back());
auto brokMesh = std::make_unique<Mesh>(DevicePtr, mesh->vertices, mesh->indices, material, std::move(effect));
m_brokMeshses.push_back(brokMesh.get());
m_meshes.push_back(std::move(brokMesh));
Matrix worldMatrix = m_meshes.back()->GetWorldMatrix();
worldMatrix *= Matrix::CreateRotationY(3.14f / 2.f);
@@ -81,7 +84,7 @@ void DioramaScene::Render(ID3D11DeviceContext *devicePtr, ID3D11RenderTargetView
}
std::vector<Mesh *> &DioramaScene::GetMeshes() {
std::vector<std::unique_ptr<Mesh>> &DioramaScene::GetMeshes() {
return m_meshes;
}
@@ -90,9 +93,6 @@ std::vector<std::shared_ptr<Material>> &DioramaScene::GetMaterials() {
}
void DioramaScene::Cleanup() {
for (Mesh *mesh: m_meshes) {
delete mesh;
}
m_meshes.clear();
m_materials.clear();
}