From c82fc49aacc9a560eb11e8ba3b35887a79c9ff72 Mon Sep 17 00:00:00 2001 From: sebastian Date: Sun, 2 Aug 2026 17:38:07 +0200 Subject: [PATCH] ADD: Boardlayout + Fix Section Name --- CMakeLists.txt | 2 ++ engine/src/loader/models/MeshSection.h | 1 + engine/src/loader/models/ModelImporter.cpp | 1 + engine/src/loader/models/ModelUploader.cpp | 2 +- game/src/GameLayer.cpp | 7 +++++ game/src/GameLayer.h | 8 ++++-- game/src/GameScene.cpp | 4 ++- game/src/ludo/BoardLayout.cpp | 30 +++++++++++++++++++++ game/src/ludo/BoardLayout.h | 31 ++++++++++++++++++++++ game/src/ludo/LudoTypes.h | 22 +++++++++++++++ 10 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 game/src/ludo/BoardLayout.cpp create mode 100644 game/src/ludo/BoardLayout.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 14cd9d0..405612d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -203,6 +203,8 @@ add_executable(ColorRace game/src/ludo/LudoTypes.h game/src/ludo/LudoGameMode.cpp game/src/ludo/LudoGameMode.h + game/src/ludo/BoardLayout.cpp + game/src/ludo/BoardLayout.h ) diff --git a/engine/src/loader/models/MeshSection.h b/engine/src/loader/models/MeshSection.h index 32cfe79..55c628b 100644 --- a/engine/src/loader/models/MeshSection.h +++ b/engine/src/loader/models/MeshSection.h @@ -12,6 +12,7 @@ #include #include "Material.h" +#include "glm/glm.hpp" namespace engine { diff --git a/engine/src/loader/models/ModelImporter.cpp b/engine/src/loader/models/ModelImporter.cpp index c697e5d..bc2d1d3 100644 --- a/engine/src/loader/models/ModelImporter.cpp +++ b/engine/src/loader/models/ModelImporter.cpp @@ -66,6 +66,7 @@ engine::RawModelBundle engine::ModelImporter::importFromFile(const std::string& int materialId = shape.mesh.material_ids[f]; // -1 = kein Material zugewiesen auto& section = sectionsByMaterial[materialId]; + section.name = object.name; if (materialId >= 0) section.materialName = tinyMaterials[materialId].name; for (int v = 0; v < faceVertexCount; ++v) { diff --git a/engine/src/loader/models/ModelUploader.cpp b/engine/src/loader/models/ModelUploader.cpp index bf17ff4..4e8e7c3 100644 --- a/engine/src/loader/models/ModelUploader.cpp +++ b/engine/src/loader/models/ModelUploader.cpp @@ -87,7 +87,7 @@ engine::Model engine::ModelUploader::uploadSections(const std::vector(indices.size()); meshSection.indexCount = static_cast(section.indices.size()); diff --git a/game/src/GameLayer.cpp b/game/src/GameLayer.cpp index 5e0ef15..531a585 100644 --- a/game/src/GameLayer.cpp +++ b/game/src/GameLayer.cpp @@ -4,6 +4,7 @@ #include "GameLayer.h" +#include #include #include @@ -12,6 +13,8 @@ #include "renderer/MeshRenderer.h" #include "renderer/MeshRenderSystem.h" #include "renderer/primitives/CubeFactory.h" +#define GLM_ENABLE_EXPERIMENTAL +#include using namespace engine; void GameLayer::onAttachImpl() { m_renderState.depthTesting = false; @@ -20,6 +23,10 @@ void GameLayer::onAttachImpl() { m_renderer = std::make_unique(); m_cameraController = std::make_unique(getInputStack(), getInputContext()); + + for (int i = 0; i <= 3; i++) { + std::cout << glm::to_string( m_boardLayout.getWorldPosition(ludo::PlayerColor::Red, ludo::PieceState::AtHome, i)) << std::endl; + } } void GameLayer::onDetachImpl() { diff --git a/game/src/GameLayer.h b/game/src/GameLayer.h index f5753ea..39be3a4 100644 --- a/game/src/GameLayer.h +++ b/game/src/GameLayer.h @@ -9,6 +9,7 @@ #include "core/inputsOutputs/controller/CameraController.h" #include "ecs/EntityRegistry.h" #include "layer/Layer.h" +#include "ludo/BoardLayout.h" #include "renderer/MeshRenderer.h" #include "renderer/RenderQueue.h" #include "utils/openglWrapper/GLRenderState.h" @@ -17,8 +18,9 @@ class GameLayer: public engine::Layer { public: GameLayer(engine::EntityRegistry& entityRegistry, std::shared_ptr cam, std::shared_ptr light, - engine::Keyboard& keyboard, engine::Mouse& mouse) - : Layer(keyboard, mouse), m_entityRegistry(entityRegistry), m_camera(std::move(cam)), m_renderer(std::make_unique()), m_pointLight(std::move(light)){} + engine::Keyboard& keyboard, engine::Mouse& mouse, std::shared_ptr boardModel) + : Layer(keyboard, mouse), m_entityRegistry(entityRegistry), m_camera(std::move(cam)), m_renderer(std::make_unique()), + m_pointLight(std::move(light)), m_boardLayout(std::move(boardModel)){} void onUpdate(float deltaTime) override; void onRender() override; @@ -33,6 +35,8 @@ private: std::shared_ptr m_camera; std::unique_ptr m_renderer; std::unique_ptr m_cameraController; + + ludo::BoardLayout m_boardLayout; }; #endif //COLORRACE_GAMELAYER_H diff --git a/game/src/GameScene.cpp b/game/src/GameScene.cpp index 855295a..8b70d2c 100644 --- a/game/src/GameScene.cpp +++ b/game/src/GameScene.cpp @@ -14,7 +14,7 @@ GameScene::GameScene(engine::InputContextStack& inputStack, engine::Keyboard& ke } void GameScene::onEnter() { - addLayer(std::make_unique(entityRegistry, m_camera, m_pointLight, m_keyboard, m_mouse)); + m_camera->setPosition({0.0f, 0.0f, 5.0f}); m_camera->setYaw(0.0f); @@ -30,6 +30,8 @@ void GameScene::onEnter() { entityRegistry.addComponent(gameboardEntity, transform); entityRegistry.addComponent(gameboardEntity, mesh); } + + addLayer(std::make_unique(entityRegistry, m_camera, m_pointLight, m_keyboard, m_mouse, assetManager->getModel("gameboard"))); } void GameScene::onExit() { diff --git a/game/src/ludo/BoardLayout.cpp b/game/src/ludo/BoardLayout.cpp new file mode 100644 index 0000000..aac6a66 --- /dev/null +++ b/game/src/ludo/BoardLayout.cpp @@ -0,0 +1,30 @@ +// +// Created by sebastian on 02.08.26. +// + +#include "BoardLayout.h" + +#include + +#include "spdlog/spdlog.h" + +glm::vec3 ludo::BoardLayout::getWorldPosition(ludo::PlayerColor color, ludo::PieceState state, int position) const { + std::string fieldName; + switch (state) { + case ludo::PieceState::AtHome: + fieldName = std::format("Home_{}_{}", ludo::toString(color), position); break; + case ludo::PieceState::OnTrack: + fieldName = std::format("Track_{:02}", position); break; + case ludo::PieceState::InHomeStretch: + case ludo::PieceState::Finished: + fieldName = std::format("Ziel_{}_{}", toString(color), position); break; + + } + + auto it = m_positions.find(fieldName); + if (it == m_positions.end()) { + spdlog::warn("BoardLayout: Feld '{}' nicht gefunden", fieldName); + return glm::vec3(0.0f); + } + return it->second; +} diff --git a/game/src/ludo/BoardLayout.h b/game/src/ludo/BoardLayout.h new file mode 100644 index 0000000..b42b0fe --- /dev/null +++ b/game/src/ludo/BoardLayout.h @@ -0,0 +1,31 @@ +// +// Created by sebastian on 02.08.26. +// + +#ifndef COLORRACE_BOARDLAYOUT_H +#define COLORRACE_BOARDLAYOUT_H +#include + +#include "LudoTypes.h" +#include "glm/vec3.hpp" +#include "loader/models/Model.h" + + +namespace ludo { + class BoardLayout { + public: + explicit BoardLayout(std::shared_ptr boardModel): m_boardModel(std::move(boardModel)) { + for (const auto& section : m_boardModel->getSections()) { + m_positions[section.name] = section.centroid; + } + } + + [[nodiscard]] glm::vec3 getWorldPosition(ludo::PlayerColor color, ludo::PieceState state, int position) const; + private: + std::shared_ptr m_boardModel; + std::unordered_map m_positions; + }; +} + + +#endif //COLORRACE_BOARDLAYOUT_H diff --git a/game/src/ludo/LudoTypes.h b/game/src/ludo/LudoTypes.h index 0ebc3e0..ee5f77c 100644 --- a/game/src/ludo/LudoTypes.h +++ b/game/src/ludo/LudoTypes.h @@ -8,12 +8,34 @@ #include #include "game/TurnBasedGameMode.h" +#include namespace ludo { inline constexpr int kTrackLength = 40; inline constexpr int kHomeStretchLength = 4; enum class PlayerColor : uint8_t { Red, Blue, Yellow, Green, Count}; + constexpr std::string_view toString(PlayerColor color) + { + switch(color) + { + case PlayerColor::Blue: + return "Blue"; + + case PlayerColor::Green: + return "Green"; + + case PlayerColor::Red: + return "Red"; + + case PlayerColor::Yellow: + return "Yellow"; + case PlayerColor::Count: + break; + } + + return "Unknown"; + } enum class PieceState : uint8_t { AtHome, OnTrack, InHomeStretch, Finished }; enum class TurnPhase : uint8_t { AwaitingRoll, AwaitingPieceSelection };