From 64f02afbc2be290994315dff2d133f27bb089c73 Mon Sep 17 00:00:00 2001 From: Ravbug Date: Sun, 16 Jun 2024 17:51:14 -0700 Subject: [PATCH] Update PerfC mesh exchange system --- Samples/Perf_Draw/Level.cpp | 28 +++++++++++++++++++++++----- Samples/Perf_Draw/Level.hpp | 36 +++--------------------------------- 2 files changed, 26 insertions(+), 38 deletions(-) diff --git a/Samples/Perf_Draw/Level.cpp b/Samples/Perf_Draw/Level.cpp index f8e9a75..d2b6c51 100644 --- a/Samples/Perf_Draw/Level.cpp +++ b/Samples/Perf_Draw/Level.cpp @@ -8,6 +8,7 @@ #include #include #include "CustomMaterials.hpp" +#include using namespace std; using namespace RavEngine; @@ -20,7 +21,7 @@ static constexpr uint32_t num_entities = #endif struct InstanceEntity : public RavEngine::GameObject { - void Create(Ref mesh, Ref matinst) { + void Create(Ref mesh, Ref matinst) { GameObject::Create(); auto& ism = EmplaceComponent(mesh, LitMeshMaterialInstance(matinst)); } @@ -45,21 +46,20 @@ PerfB_World::PerfB_World() { Debug::Log("Loading Assets"); matinst = RavEngine::New(Material::Manager::Get()); - currentMesh = RavEngine::New(); cube = RavEngine::MeshAsset::Manager::Get("cube.obj"); cone = RavEngine::MeshAsset::Manager::Get("cone.obj"); sphere = RavEngine::MeshAsset::Manager::Get("sphere.obj"); cylinder = RavEngine::MeshAsset::Manager::Get("cylinder.obj"); - currentMesh->Exchange(cube); - currentMesh->destroyOnDestruction = false; // spawn demo entities int32_t range = 200; + meshCollection = New(cube); + Debug::Log("Spawning {} instances",num_entities); for (uint32_t i = 0; i < num_entities; i++) { - auto e = Instantiate(currentMesh, matinst); + auto e = Instantiate(meshCollection, matinst); auto& transform = e.GetTransform(); vector3 pos; @@ -132,6 +132,24 @@ PerfB_World::PerfB_World() { EmplaceTimedSystem(std::chrono::seconds(1)); } +void PerfB_World::SwitchMesh(meshes nextMesh) +{ + switch (nextMesh) { + case meshes::cube: + meshCollection->SetMeshForLOD(0, cube); + break; + case meshes::cone: + meshCollection->SetMeshForLOD(0, cone); + break; + case meshes::cylinder: + meshCollection->SetMeshForLOD(0, cylinder); + break; + case meshes::sphere: + meshCollection->SetMeshForLOD(0, sphere); + break; + } +} + void PerfB_World::PreTick(float fpsscale) { auto time = GetApp()->GetCurrentTime(); diff --git a/Samples/Perf_Draw/Level.hpp b/Samples/Perf_Draw/Level.hpp index e51915a..ba27516 100644 --- a/Samples/Perf_Draw/Level.hpp +++ b/Samples/Perf_Draw/Level.hpp @@ -11,40 +11,10 @@ struct PerfB_World : public RavEngine::World { sphere } prevMesh = meshes::cube; - void SwitchMesh(meshes nextMesh){ - switch (prevMesh){ - case meshes::cube: - cube->Exchange(currentMesh,false); - break; - case meshes::cone: - cone->Exchange(currentMesh,false); - break; - case meshes::cylinder: - cylinder->Exchange(currentMesh,false); - break; - case meshes::sphere: - sphere->Exchange(currentMesh,false); - break; - } - prevMesh = nextMesh; - - switch(nextMesh){ - case meshes::cube: - currentMesh->Exchange(cube,false); - break; - case meshes::cone: - currentMesh->Exchange(cone,false); - break; - case meshes::cylinder: - currentMesh->Exchange(cylinder,false); - break; - case meshes::sphere: - currentMesh->Exchange(sphere,false); - break; - } - } + void SwitchMesh(meshes nextMesh); private: - Ref currentMesh, cube, cone, cylinder, sphere; + Ref cube, cone, cylinder, sphere; + Ref meshCollection; Ref matinst; void PreTick(float fpsscale) override; };