We got GameObjects / Components and shit

This commit is contained in:
2026-01-10 06:09:50 +01:00
parent 10b00b0525
commit 0bfc5e0705
35 changed files with 1546 additions and 331 deletions

View File

@@ -1,4 +1,108 @@
#include "Lightkeeper.h"
LightKeeper::LightKeeper() {
#include <destrum/FS/AssetFS.h>
#include "glm/gtx/transform.hpp"
#include "spdlog/spdlog.h"
#include <destrum/Scene/Scene.h>
#include "destrum/Components/MeshRendererComponent.h"
#include "destrum/Components/Rotator.h"
#include "destrum/ObjectModel/GameObject.h"
LightKeeper::LightKeeper(): App(), renderer(meshCache, materialCache) {
}
LightKeeper::~LightKeeper() {
}
void LightKeeper::customInit() {
materialCache.init(gfxDevice);
renderer.init(gfxDevice, m_params.renderSize);
const float aspectRatio = static_cast<float>(m_params.renderSize.x) / static_cast<float>(m_params.renderSize.y);
camera.setAspectRatio(aspectRatio);
auto file = AssetFS::GetInstance().ReadBytes("engine://assetfstest.txt");
std::string fileStr(file.begin(), file.end());
spdlog::info("Read from assetfstest.txt: {}", fileStr);
testMesh.name = "Test Mesh";
testMesh.vertices = vertices;
testMesh.indices = indices;
testMeshID = meshCache.addMesh(gfxDevice, testMesh);
spdlog::info("TestMesh uploaded with id: {}", testMeshID);
const auto testimgpath = AssetFS::GetInstance().GetFullPath("engine://textures/kobe.png");
auto testimgID = gfxDevice.loadImageFromFile(testimgpath);
spdlog::info("Test image loaded with id: {}", testimgID);
testMaterialID = materialCache.addMaterial(gfxDevice, {
.baseColor = glm::vec3(1.f),
.diffuseTexture = testimgID,
});
spdlog::info("Test material created with id: {}", testMaterialID);
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);
testCube->AddComponent<Rotator>(10, 5);
scene.Add(testCube);
}
void LightKeeper::customUpdate(float dt) {
camera.Update(dt);
SceneManager::GetInstance().Update();
}
void LightKeeper::customDraw() {
renderer.beginDrawing(gfxDevice);
const RenderContext ctx{
.renderer = renderer,
.camera = camera,
.sceneData = {
.camera = camera,
.ambientColor = glm::vec3(0.1f),
.ambientIntensity = 0.5f,
.fogColor = glm::vec3(0.5f),
.fogDensity = 0.01f
}
};
SceneManager::GetInstance().Render(ctx);
renderer.endDrawing();
const auto cmd = gfxDevice.beginFrame();
const auto& drawImage = renderer.getDrawImage(gfxDevice);
renderer.draw(
cmd, gfxDevice, camera, GameRenderer::SceneData{
camera, glm::vec3(0.1f), 0.5f, glm::vec3(0.5f), 0.01f
});
gfxDevice.endFrame(
cmd, drawImage, {
.clearColor = {{0.f, 0.f, 0.5f, 1.f}},
.drawImageBlitRect = glm::ivec4{}
});
}
void LightKeeper::customCleanup() {
SceneManager::GetInstance().Destroy();
renderer.cleanup(gfxDevice.getDevice().device);
}
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);
}