ADD: Boardlayout + Fix Section Name
This commit is contained in:
parent
5d1da184e0
commit
c82fc49aac
@ -203,6 +203,8 @@ add_executable(ColorRace
|
|||||||
game/src/ludo/LudoTypes.h
|
game/src/ludo/LudoTypes.h
|
||||||
game/src/ludo/LudoGameMode.cpp
|
game/src/ludo/LudoGameMode.cpp
|
||||||
game/src/ludo/LudoGameMode.h
|
game/src/ludo/LudoGameMode.h
|
||||||
|
game/src/ludo/BoardLayout.cpp
|
||||||
|
game/src/ludo/BoardLayout.h
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -12,6 +12,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "Material.h"
|
#include "Material.h"
|
||||||
|
#include "glm/glm.hpp"
|
||||||
|
|
||||||
namespace engine {
|
namespace engine {
|
||||||
|
|
||||||
|
|||||||
@ -66,6 +66,7 @@ engine::RawModelBundle engine::ModelImporter::importFromFile(const std::string&
|
|||||||
int materialId = shape.mesh.material_ids[f]; // -1 = kein Material zugewiesen
|
int materialId = shape.mesh.material_ids[f]; // -1 = kein Material zugewiesen
|
||||||
|
|
||||||
auto& section = sectionsByMaterial[materialId];
|
auto& section = sectionsByMaterial[materialId];
|
||||||
|
section.name = object.name;
|
||||||
if (materialId >= 0) section.materialName = tinyMaterials[materialId].name;
|
if (materialId >= 0) section.materialName = tinyMaterials[materialId].name;
|
||||||
|
|
||||||
for (int v = 0; v < faceVertexCount; ++v) {
|
for (int v = 0; v < faceVertexCount; ++v) {
|
||||||
|
|||||||
@ -87,7 +87,7 @@ engine::Model engine::ModelUploader::uploadSections(const std::vector<RawMeshSec
|
|||||||
unsigned int vertexOffset = 0;
|
unsigned int vertexOffset = 0;
|
||||||
for (const auto& section : sections) {
|
for (const auto& section : sections) {
|
||||||
MeshSection meshSection;
|
MeshSection meshSection;
|
||||||
meshSection.name = section.materialName.empty() ? section.name : section.materialName;
|
meshSection.name = section.name.empty() ? section.materialName : section.name;
|
||||||
meshSection.indexOffset = static_cast<unsigned int>(indices.size());
|
meshSection.indexOffset = static_cast<unsigned int>(indices.size());
|
||||||
meshSection.indexCount = static_cast<unsigned int>(section.indices.size());
|
meshSection.indexCount = static_cast<unsigned int>(section.indices.size());
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include "GameLayer.h"
|
#include "GameLayer.h"
|
||||||
|
|
||||||
|
#include <format>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
@ -12,6 +13,8 @@
|
|||||||
#include "renderer/MeshRenderer.h"
|
#include "renderer/MeshRenderer.h"
|
||||||
#include "renderer/MeshRenderSystem.h"
|
#include "renderer/MeshRenderSystem.h"
|
||||||
#include "renderer/primitives/CubeFactory.h"
|
#include "renderer/primitives/CubeFactory.h"
|
||||||
|
#define GLM_ENABLE_EXPERIMENTAL
|
||||||
|
#include <glm/gtx/string_cast.hpp>
|
||||||
using namespace engine;
|
using namespace engine;
|
||||||
void GameLayer::onAttachImpl() {
|
void GameLayer::onAttachImpl() {
|
||||||
m_renderState.depthTesting = false;
|
m_renderState.depthTesting = false;
|
||||||
@ -20,6 +23,10 @@ void GameLayer::onAttachImpl() {
|
|||||||
m_renderer = std::make_unique<engine::MeshRenderer>();
|
m_renderer = std::make_unique<engine::MeshRenderer>();
|
||||||
|
|
||||||
m_cameraController = std::make_unique<engine::CameraController>(getInputStack(), getInputContext());
|
m_cameraController = std::make_unique<engine::CameraController>(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() {
|
void GameLayer::onDetachImpl() {
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
#include "core/inputsOutputs/controller/CameraController.h"
|
#include "core/inputsOutputs/controller/CameraController.h"
|
||||||
#include "ecs/EntityRegistry.h"
|
#include "ecs/EntityRegistry.h"
|
||||||
#include "layer/Layer.h"
|
#include "layer/Layer.h"
|
||||||
|
#include "ludo/BoardLayout.h"
|
||||||
#include "renderer/MeshRenderer.h"
|
#include "renderer/MeshRenderer.h"
|
||||||
#include "renderer/RenderQueue.h"
|
#include "renderer/RenderQueue.h"
|
||||||
#include "utils/openglWrapper/GLRenderState.h"
|
#include "utils/openglWrapper/GLRenderState.h"
|
||||||
@ -17,8 +18,9 @@
|
|||||||
class GameLayer: public engine::Layer {
|
class GameLayer: public engine::Layer {
|
||||||
public:
|
public:
|
||||||
GameLayer(engine::EntityRegistry& entityRegistry, std::shared_ptr<engine::Camera> cam, std::shared_ptr<engine::PointLight> light,
|
GameLayer(engine::EntityRegistry& entityRegistry, std::shared_ptr<engine::Camera> cam, std::shared_ptr<engine::PointLight> light,
|
||||||
engine::Keyboard& keyboard, engine::Mouse& mouse)
|
engine::Keyboard& keyboard, engine::Mouse& mouse, std::shared_ptr<engine::Model> boardModel)
|
||||||
: Layer(keyboard, mouse), m_entityRegistry(entityRegistry), m_camera(std::move(cam)), m_renderer(std::make_unique<engine::MeshRenderer>()), m_pointLight(std::move(light)){}
|
: Layer(keyboard, mouse), m_entityRegistry(entityRegistry), m_camera(std::move(cam)), m_renderer(std::make_unique<engine::MeshRenderer>()),
|
||||||
|
m_pointLight(std::move(light)), m_boardLayout(std::move(boardModel)){}
|
||||||
|
|
||||||
void onUpdate(float deltaTime) override;
|
void onUpdate(float deltaTime) override;
|
||||||
void onRender() override;
|
void onRender() override;
|
||||||
@ -33,6 +35,8 @@ private:
|
|||||||
std::shared_ptr<engine::Camera> m_camera;
|
std::shared_ptr<engine::Camera> m_camera;
|
||||||
std::unique_ptr<engine::MeshRenderer> m_renderer;
|
std::unique_ptr<engine::MeshRenderer> m_renderer;
|
||||||
std::unique_ptr<engine::CameraController> m_cameraController;
|
std::unique_ptr<engine::CameraController> m_cameraController;
|
||||||
|
|
||||||
|
ludo::BoardLayout m_boardLayout;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //COLORRACE_GAMELAYER_H
|
#endif //COLORRACE_GAMELAYER_H
|
||||||
|
|||||||
@ -14,7 +14,7 @@ GameScene::GameScene(engine::InputContextStack& inputStack, engine::Keyboard& ke
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GameScene::onEnter() {
|
void GameScene::onEnter() {
|
||||||
addLayer(std::make_unique<GameLayer>(entityRegistry, m_camera, m_pointLight, m_keyboard, m_mouse));
|
|
||||||
|
|
||||||
m_camera->setPosition({0.0f, 0.0f, 5.0f});
|
m_camera->setPosition({0.0f, 0.0f, 5.0f});
|
||||||
m_camera->setYaw(0.0f);
|
m_camera->setYaw(0.0f);
|
||||||
@ -30,6 +30,8 @@ void GameScene::onEnter() {
|
|||||||
entityRegistry.addComponent<engine::TransformComponent>(gameboardEntity, transform);
|
entityRegistry.addComponent<engine::TransformComponent>(gameboardEntity, transform);
|
||||||
entityRegistry.addComponent<engine::MeshComponent>(gameboardEntity, mesh);
|
entityRegistry.addComponent<engine::MeshComponent>(gameboardEntity, mesh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addLayer(std::make_unique<GameLayer>(entityRegistry, m_camera, m_pointLight, m_keyboard, m_mouse, assetManager->getModel("gameboard")));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScene::onExit() {
|
void GameScene::onExit() {
|
||||||
|
|||||||
30
game/src/ludo/BoardLayout.cpp
Normal file
30
game/src/ludo/BoardLayout.cpp
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
//
|
||||||
|
// Created by sebastian on 02.08.26.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "BoardLayout.h"
|
||||||
|
|
||||||
|
#include <format>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
||||||
31
game/src/ludo/BoardLayout.h
Normal file
31
game/src/ludo/BoardLayout.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
//
|
||||||
|
// Created by sebastian on 02.08.26.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef COLORRACE_BOARDLAYOUT_H
|
||||||
|
#define COLORRACE_BOARDLAYOUT_H
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
#include "LudoTypes.h"
|
||||||
|
#include "glm/vec3.hpp"
|
||||||
|
#include "loader/models/Model.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace ludo {
|
||||||
|
class BoardLayout {
|
||||||
|
public:
|
||||||
|
explicit BoardLayout(std::shared_ptr<engine::Model> 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<engine::Model> m_boardModel;
|
||||||
|
std::unordered_map<std::string, glm::vec3> m_positions;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif //COLORRACE_BOARDLAYOUT_H
|
||||||
@ -8,12 +8,34 @@
|
|||||||
#include <variant>
|
#include <variant>
|
||||||
|
|
||||||
#include "game/TurnBasedGameMode.h"
|
#include "game/TurnBasedGameMode.h"
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
namespace ludo {
|
namespace ludo {
|
||||||
inline constexpr int kTrackLength = 40;
|
inline constexpr int kTrackLength = 40;
|
||||||
inline constexpr int kHomeStretchLength = 4;
|
inline constexpr int kHomeStretchLength = 4;
|
||||||
|
|
||||||
enum class PlayerColor : uint8_t { Red, Blue, Yellow, Green, Count};
|
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 PieceState : uint8_t { AtHome, OnTrack, InHomeStretch, Finished };
|
||||||
enum class TurnPhase : uint8_t { AwaitingRoll, AwaitingPieceSelection };
|
enum class TurnPhase : uint8_t { AwaitingRoll, AwaitingPieceSelection };
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user