feat: add tracy / various fixes

This commit is contained in:
2026-06-24 03:00:53 +02:00
parent 067caf5fe6
commit 9d3d14a54d
33 changed files with 1492 additions and 336 deletions
+166 -133
View File
@@ -23,13 +23,16 @@
#include "destrum/Util/ModelDocUtils.h"
LightKeeper::LightKeeper() : App(), renderer(meshCache, materialCache) {
LightKeeper::LightKeeper() : App(), renderer(meshCache, materialCache)
{
}
LightKeeper::~LightKeeper() {
LightKeeper::~LightKeeper()
{
}
void LightKeeper::customInit() {
void LightKeeper::customInit()
{
materialCache.init(gfxDevice);
renderer.init(gfxDevice, m_params.renderSize);
@@ -48,7 +51,7 @@ void LightKeeper::customInit() {
);
ModelDocUtils::LogModelDocSummary(kittyModel, "kitty.glb");
const auto &kittyPrimitive = ModelDocUtils::GetFirstPrimitiveOrThrow(kittyModel, "game://kitty.glb");
const auto& kittyPrimitive = ModelDocUtils::GetFirstPrimitiveOrThrow(kittyModel, "game://kitty.glb");
testMesh = kittyPrimitive.mesh;
testMesh.name = "Test Mesh";
@@ -75,40 +78,7 @@ void LightKeeper::customInit() {
camera.SetRotation(glm::radians(glm::vec2(90.f, 0.f)));
auto &scene = SceneManager::GetInstance().CreateScene("Main");
// auto testCube = std::make_shared<GameObject>("TestCube");
// auto meshComp = testCube->AddComponent<MeshRendererComponent>();
// meshComp->SetMeshID(testMeshID);
// meshComp->SetMaterialID(testMaterialID);
const int count = 100;
const float radius = 5.0f;
const float orbitRadius = 5.0f;
for (int i = 0; i < count; ++i) {
// auto childCube = std::make_shared<GameObject>(fmt::format("ChildCube{}", i));
//
// auto childMeshComp = childCube->AddComponent<MeshRendererComponent>();
// childMeshComp->SetMeshID(testMeshID);
// childMeshComp->SetMaterialID(testMaterialID);
//
// childCube->GetTransform().SetWorldScale(glm::vec3(0.1f));
//
// // Add orbit + self spin
// auto orbit = childCube->AddComponent<OrbitAndSpin>(orbitRadius, glm::vec3(0.0f));
// orbit->Randomize(1337u + (uint32_t)i); // stable random per index
//
// scene.Add(childCube);
}
// testCube->AddComponent<Spinner>(glm::vec3(0, 1, 0), glm::radians(10.0f)); // spin around Y, rad/sec
//rotate 180 around X axis
// testCube->GetTransform().SetLocalRotation(glm::quat(glm::vec3(glm::radians(180.0f), 0.0f, 0.0f)));
//
auto globeRoot = std::make_shared<GameObject>("GlobeRoot");
globeRoot->GetTransform().SetWorldPosition(glm::vec3(0.0f));
globeRoot->AddComponent<Spinner>(glm::vec3(0, 1, 0), 1.0f); // spin around Y, rad/sec
scene.Add(globeRoot);
auto& scene = SceneManager::GetInstance().CreateScene("Main");
// scene.Add(testCube);
@@ -137,7 +107,7 @@ void LightKeeper::customInit() {
);
ModelDocUtils::LogModelDocSummary(planeModel, "plane.glb");
const auto &planePrimitive = ModelDocUtils::GetFirstPrimitiveOrThrow(planeModel, "game://plane.glb");
const auto& planePrimitive = ModelDocUtils::GetFirstPrimitiveOrThrow(planeModel, "game://plane.glb");
const auto planeMeshID = meshCache.addMesh(gfxDevice, planePrimitive.mesh);
const auto planeTexturePath = ModelDocUtils::PickTexturePath(
@@ -160,6 +130,11 @@ void LightKeeper::customInit() {
planeMeshComp->SetMaterialID(planeMaterialID);
planeObj->GetTransform().SetWorldPosition(glm::vec3(0.f, -1.0f, 0.f));
planeObj->GetTransform().SetWorldScale(glm::vec3(10.f, 1.f, 10.f));
planeObj->AddComponent<BoxCollider>(glm::vec3{10.0f, 0.5f, 10.0f});
auto* floorRb = planeObj->AddComponent<Rigidbody>();
floorRb->SetType(RigidbodyType::Static);
scene.GetPhysics().RegisterGameObject(*planeObj);
scene.Add(planeObj);
const auto CharObj = std::make_shared<GameObject>("Character");
@@ -284,112 +259,167 @@ void LightKeeper::customInit() {
// }
{
const auto CharObj = std::make_shared<GameObject>("Character");
ModelDoc::LoadOptions characterOptions{};
characterOptions.meshImportMode = ModelDoc::MeshImportMode::MergedPerNode;
characterOptions.loadMaterials = true;
characterOptions.loadSkeleton = true;
characterOptions.loadAnimations = false;
auto charModel = ModelDoc::LoadModel(
AssetFS::GetInstance()
.GetFullPath("engine://characterMedium.fbx")
.generic_string(),
characterOptions
);
const auto &charPrimitive =
ModelDocUtils::GetFirstSkinnedPrimitiveOrFirstOrThrow(
charModel,
"engine://characterMedium.fbx"
);
const auto charMeshID = meshCache.addMesh(gfxDevice, charPrimitive.mesh);
const auto charTextureID = gfxDevice.loadImageFromFile(
AssetFS::GetInstance().GetFullPath("engine://textures/criminalMaleA.png")
);
const auto charMaterialID = materialCache.addMaterial(gfxDevice, {
.baseColor = ModelDocUtils::GetImportedBaseColor(
charModel, charPrimitive),
.diffuseTexture = charTextureID,
.name = ModelDocUtils::GetImportedMaterialName(
charModel,
charPrimitive,
"CharacterMaterial"
),
});
const auto charMeshComp = CharObj->AddComponent<MeshRendererComponent>();
charMeshComp->SetMeshID(charMeshID);
charMeshComp->SetMaterialID(charMaterialID);
const auto animator = CharObj->AddComponent<Animator>();
animator->setSkeleton(charModel.skeleton);
auto runClips = ModelDoc::LoadAnimationClips(
AssetFS::GetInstance()
.GetFullPath("engine://run.fbx")
.generic_string(),
charModel.skeleton
);
for (auto &clip: runClips) {
spdlog::info("Loaded animation: '{}' ({:.2f}s)", clip.name, clip.duration);
animator->addClip(std::make_shared<SkeletalAnimation>(std::move(clip)));
}
if (!runClips.empty()) {
animator->play("Root|Run");
}
CharObj->GetTransform().SetWorldPosition(glm::vec3(0.f));
CharObj->GetTransform().SetWorldPosition(glm::vec3(5, 0, 0));
scene.Add(CharObj);
}
auto cubeModel = ModelDoc::LoadModel(
AssetFS::GetInstance()
.GetFullPath("engine://cube.fbx")
.generic_string(),
staticModelOptions
);
ModelDocUtils::LogModelDocSummary(cubeModel, "cube.fbx");
const auto& cubePrimitive = ModelDocUtils::GetFirstPrimitiveOrThrow(cubeModel, "game://cube.fbx");
const auto eliasTextuerPath = ModelDocUtils::PickTexturePath(
cubeModel,
cubePrimitive,
AssetFS::GetInstance().GetFullPath("game://grass.png")
);
const auto eliasTextueID = gfxDevice.loadImageFromFile(eliasTextuerPath);
const auto eliasMaterialID = materialCache.addMaterial(gfxDevice, {
.baseColor = ModelDocUtils::GetImportedBaseColor(
planeModel, planePrimitive),
.textureFilteringMode =
TextureFilteringMode::Anisotropic,
.diffuseTexture = eliasTextueID,
.name = ModelDocUtils::GetImportedMaterialName(
planeModel, planePrimitive, "GroundPlaneMaterial"),
});
const auto cubeMeshID = meshCache.addMesh(gfxDevice, cubePrimitive.mesh);
//
// for (int i{0}; i < 100; i++)
// {
// const auto CharObj = std::make_shared<GameObject>("Character");
// auto cube = std::make_shared<GameObject>("Cube");
//
// ModelDoc::LoadOptions characterOptions{};
// characterOptions.meshImportMode = ModelDoc::MeshImportMode::MergedPerNode;
// characterOptions.loadMaterials = true;
// characterOptions.loadSkeleton = true;
// characterOptions.loadAnimations = false;
// cube->AddComponent<BoxCollider>(glm::vec3{0.5f});
// cube->AddComponent<Rigidbody>();
//
// auto charModel = ModelDoc::LoadModel(
// AssetFS::GetInstance()
// .GetFullPath("engine://characterMedium.fbx")
// .generic_string(),
// characterOptions
// );
// auto meshComp = cube->AddComponent<MeshRendererComponent>();
// meshComp->SetMeshID(cubeMeshID);
// meshComp->SetMaterialID(eliasMaterialID);
//
// const auto &charPrimitive =
// ModelDocUtils::GetFirstSkinnedPrimitiveOrFirstOrThrow(
// charModel,
// "engine://characterMedium.fbx"
// );
// cube->GetTransform().SetWorldPosition(glm::vec3(0.0f, i, 0.0f));
// cube->GetTransform().SetWorldScale(glm::vec3(0.005f));
//
// const auto charMeshID = meshCache.addMesh(gfxDevice, charPrimitive.mesh);
//
// const auto charTextureID = gfxDevice.loadImageFromFile(
// AssetFS::GetInstance().GetFullPath("engine://textures/criminalMaleA.png")
// );
//
// const auto charMaterialID = materialCache.addMaterial(gfxDevice, {
// .baseColor = ModelDocUtils::GetImportedBaseColor(
// charModel, charPrimitive),
// .diffuseTexture = charTextureID,
// .name = ModelDocUtils::GetImportedMaterialName(
// charModel,
// charPrimitive,
// "CharacterMaterial"
// ),
// });
//
// const auto charMeshComp = CharObj->AddComponent<MeshRendererComponent>();
// charMeshComp->SetMeshID(charMeshID);
// charMeshComp->SetMaterialID(charMaterialID);
//
// const auto animator = CharObj->AddComponent<Animator>();
// animator->setSkeleton(charModel.skeleton);
//
// auto runClips = ModelDoc::LoadAnimationClips(
// AssetFS::GetInstance()
// .GetFullPath("engine://run.fbx")
// .generic_string(),
// charModel.skeleton
// );
//
// for (auto &clip: runClips) {
// spdlog::info("Loaded animation: '{}' ({:.2f}s)", clip.name, clip.duration);
// animator->addClip(std::make_shared<SkeletalAnimation>(std::move(clip)));
// }
//
// if (!runClips.empty()) {
// animator->play("Root|Run");
// }
//
// CharObj->GetTransform().SetWorldPosition(glm::vec3(0.f));
// CharObj->GetTransform().SetWorldPosition(glm::vec3(5, 0, 0));
// scene.Add(CharObj);
// scene.Add(cube);
// scene.GetPhysics().RegisterGameObject(*cube);
// }
{
auto cubeModel = ModelDoc::LoadModel(
AssetFS::GetInstance()
.GetFullPath("engine://cube.fbx")
.generic_string(),
staticModelOptions
);
ModelDocUtils::LogModelDocSummary(cubeModel, "cube.fbx");
const auto &cubePrimitive = ModelDocUtils::GetFirstPrimitiveOrThrow(cubeModel, "game://cube.fbx");
const auto cubeMeshID = meshCache.addMesh(gfxDevice, cubePrimitive.mesh);
auto cube = std::make_shared<GameObject>("Cube");
cube->AddComponent<BoxCollider>(glm::vec3{0.5f});
cube->AddComponent<Rigidbody>();
auto meshComp = cube->AddComponent<MeshRendererComponent>();
meshComp->SetMeshID(cubeMeshID);
meshComp->SetMaterialID(charMaterialID);
cube->GetTransform().SetWorldPosition(glm::vec3(0.0f, 2.0f, 0.0f));
cube->GetTransform().SetWorldScale(glm::vec3(0.005f));
scene.Add(cube);
scene.GetPhysics().RegisterGameObject(*cube);
}
// const int cubeCount = 10;
// const float spacing = 1.0f;
//
// for (int x = 0; x < cubeCount; x++)
// {
// for (int y = 0; y < cubeCount; y++)
// {
// for (int z = 0; z < cubeCount; z++)
// {
// auto cube = std::make_shared<GameObject>("Cube");
//
// cube->AddComponent<BoxCollider>(glm::vec3{0.5f});
// cube->AddComponent<Rigidbody>();
//
// auto meshComp = cube->AddComponent<MeshRendererComponent>();
// meshComp->SetMeshID(cubeMeshID);
// meshComp->SetMaterialID(eliasMaterialID);
//
// cube->GetTransform().SetWorldPosition(glm::vec3(
// (x - cubeCount / 2.0f) * spacing,
// y * spacing + 5,
// (z - cubeCount / 2.0f) * spacing
// ));
//
// cube->GetTransform().SetWorldScale(glm::vec3(0.005f));
//
// scene.Add(cube);
// scene.GetPhysics().RegisterGameObject(*cube);
// }
// }
// }
}
void LightKeeper::customUpdate(float dt) {
void LightKeeper::customUpdate(float dt)
{
camera.Update(dt);
SceneManager::GetInstance().Update();
if (InputManager::GetInstance().WasKeyPressed(SDL_SCANCODE_1)) {
if (InputManager::GetInstance().WasKeyPressed(SDL_SCANCODE_1))
{
renderer.setRenderWireframe(!renderer.getRenderWireframe());
}
}
void LightKeeper::customDraw() {
void LightKeeper::customDraw()
{
renderer.beginDrawing(gfxDevice);
const RenderContext ctx{
@@ -408,7 +438,7 @@ void LightKeeper::customDraw() {
renderer.endDrawing();
const auto cmd = gfxDevice.beginFrame();
const auto &drawImage = renderer.getDrawImage(gfxDevice);
const auto& drawImage = renderer.getDrawImage(gfxDevice);
renderer.draw(
cmd, gfxDevice, camera, GameRenderer::SceneData{
@@ -423,14 +453,16 @@ void LightKeeper::customDraw() {
});
}
void LightKeeper::customCleanup() {
void LightKeeper::customCleanup()
{
auto device = gfxDevice.getDevice().device;
vkDeviceWaitIdle(device);
SceneManager::GetInstance().Destroy();
if (skyboxCubemap) {
if (skyboxCubemap)
{
skyboxCubemap.reset();
}
@@ -445,7 +477,8 @@ void LightKeeper::customFixedUpdate(float dt)
SceneManager::GetInstance().FixedUpdate(dt);
}
void LightKeeper::onWindowResize(int newWidth, int newHeight) {
void LightKeeper::onWindowResize(int newWidth, int newHeight)
{
renderer.resize(gfxDevice, glm::ivec2{newWidth, newHeight});
const float aspectRatio = static_cast<float>(newWidth) / static_cast<float>(newHeight);
camera.setAspectRatio(aspectRatio);