WIP: GameController
This commit is contained in:
parent
c755d39677
commit
5e580af16f
@ -255,8 +255,8 @@ target_link_libraries(Engine PUBLIC OpenGL::GL glfw glad glm::glm imgui spdlog::
|
||||
add_library(GameLib STATIC
|
||||
game/src/ColorRaceApp.cpp
|
||||
game/src/ColorRaceApp.h
|
||||
game/src/GameLayer.cpp
|
||||
game/src/GameLayer.h
|
||||
game/src/gameLayer/GameLayer.cpp
|
||||
game/src/gameLayer/GameLayer.h
|
||||
game/src/GameScene.cpp
|
||||
game/src/GameScene.h
|
||||
game/src/ludo/LudoGameState.cpp
|
||||
@ -278,6 +278,15 @@ add_library(GameLib STATIC
|
||||
game/src/ludo/DiceSource.h
|
||||
game/src/ludo/PresentationGameState.cpp
|
||||
game/src/ludo/PresentationGameState.h
|
||||
game/src/gameLayer/GameRenderer.cpp
|
||||
game/src/gameLayer/GameRenderer.h
|
||||
game/src/gameLayer/gameController/LudoGameController.cpp
|
||||
game/src/gameLayer/gameController/LudoGameController.h
|
||||
game/src/gameLayer/LudoHud.cpp
|
||||
game/src/gameLayer/LudoHud.h
|
||||
game/src/gameLayer/GameInput.cpp
|
||||
game/src/gameLayer/GameInput.h
|
||||
game/src/gameLayer/gameController/LudoGameControllerContext.h
|
||||
)
|
||||
target_include_directories(GameLib PUBLIC game/src)
|
||||
target_link_libraries(GameLib PUBLIC Engine)
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
|
||||
#ifndef COLORRACE_COLORRACEAPP_H
|
||||
#define COLORRACE_COLORRACEAPP_H
|
||||
#include "GameLayer.h"
|
||||
#include "gameLayer/GameLayer.h"
|
||||
#include "GameScene.h"
|
||||
#include "core/Application.h"
|
||||
#include "ecs/EntityRegistry.h"
|
||||
|
||||
@ -1,116 +0,0 @@
|
||||
//
|
||||
// Created by sebastian on 29.07.26.
|
||||
//
|
||||
|
||||
#include "GameLayer.h"
|
||||
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
|
||||
#include "ecs/standardComponents/MeshComponent.h"
|
||||
#include "ecs/standardComponents/TransformComponent.h"
|
||||
#include "renderer/MeshRenderer.h"
|
||||
#include "renderer/MeshRenderSystem.h"
|
||||
#define GLM_ENABLE_EXPERIMENTAL
|
||||
#include <glm/gtx/string_cast.hpp>
|
||||
|
||||
#include "core/animation/components/BlockingAnimationComponent.h"
|
||||
#include "core/audio/SoundSource.h"
|
||||
#include "core/audio/ecs/BlockingSoundComponent.h"
|
||||
#include "core/audio/ecs/PlaySoundComponent.h"
|
||||
#include "GLFW/glfw3.h"
|
||||
using namespace engine;
|
||||
void GameLayer::onAttachImpl() {
|
||||
m_renderState.depthTesting = false;
|
||||
m_renderState.backfaceCulling = false;
|
||||
|
||||
m_renderer = std::make_unique<engine::MeshRenderer>();
|
||||
|
||||
m_cameraController = std::make_unique<engine::CameraController>(getInputStack(), getInputContext());
|
||||
m_piecePresenter.spawnPieces(m_gameMode->getState());
|
||||
|
||||
this->m_presentationGameState = std::make_unique<ludo::PresentationGameState>(*m_gameMode, m_gameMode->getState());
|
||||
}
|
||||
|
||||
void GameLayer::onDetachImpl() {
|
||||
|
||||
}
|
||||
|
||||
void GameLayer::renderHud() {
|
||||
const auto& state = m_gameMode->getState();
|
||||
|
||||
|
||||
|
||||
ImGui::SetNextWindowPos(ImVec2(20, 20), ImGuiCond_FirstUseEver);
|
||||
ImGui::Begin("Ludo", nullptr, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize);
|
||||
|
||||
auto currentPlayerColor = m_gameMode->getColorOf(m_presentationGameState->getCurrentPlayer());
|
||||
int currentDiceValue = m_presentationGameState->getDiceValue();
|
||||
ImGui::Text("Am Zug: %s", toString(currentPlayerColor).data());
|
||||
ImGui::Text("Wuerfel: %d", currentDiceValue);
|
||||
|
||||
ImGui::BeginDisabled(m_presentationGameState->isDiceRollEnabled() == false && m_gameMode->getState().getPhase() == ludo::TurnPhase::AwaitingRoll);
|
||||
if (ImGui::Button("Wuerfeln")) {
|
||||
m_gameMode->sendCommand(ludo::RollDiceCommand{m_localPlayer});
|
||||
}
|
||||
//
|
||||
// if (!m_lastEventMessage.empty()) ImGui::Text("%s", m_lastEventMessage.c_str());
|
||||
|
||||
ImGui::EndDisabled();
|
||||
|
||||
ImGui::End();
|
||||
|
||||
}
|
||||
|
||||
bool GameLayer::isAnimationBlocking() const {
|
||||
return m_entityRegistry.getPool<animation::BlockingAnimationComponent>().size() > 0;
|
||||
}
|
||||
|
||||
bool GameLayer::isSoundBlocking() const {
|
||||
return m_entityRegistry.getPool<audio::BlockingSoundComponent>().size() > 0;
|
||||
}
|
||||
|
||||
void GameLayer::onUpdate(float deltaTime) {
|
||||
Layer::onUpdate(deltaTime);
|
||||
m_cameraController->update(getKeyboard(), *m_camera, deltaTime);
|
||||
m_animationSystem.update(deltaTime);
|
||||
if (isAnimationBlocking() || isSoundBlocking()) return;
|
||||
m_presentationGameState->commitGameState(m_gameMode->getCurrentPlayer(), m_gameMode->getState().getDiceValue(), m_gameMode->getState().getPhase() == ludo::TurnPhase::AwaitingRoll && m_localPlayer == m_gameMode->getCurrentPlayer());
|
||||
for (auto& ai : aiControllers) {
|
||||
ai.update(deltaTime);
|
||||
}
|
||||
|
||||
for (const auto& event : m_gameMode->pollEvents()) {
|
||||
std::visit([this]<typename T>(const T& e) {
|
||||
if constexpr (std::is_same_v<T, ludo::PieceMovedEvent>) {
|
||||
m_piecePresenter.onPieceMoved(e, m_gameMode->getState());
|
||||
}
|
||||
if constexpr (std::is_same_v<T, ludo::DiceRolledEvent>) {
|
||||
// m_lastEventMessage = std::format("Wuerfel geworfen: {}", e.diceValue);
|
||||
}
|
||||
// DiceRolledEvent/TurnChangedEvent -> ImGui-State aktualisieren
|
||||
}, event);
|
||||
}
|
||||
|
||||
m_highlightSystem.update(getMouse(), m_entityRegistry);
|
||||
|
||||
if (auto entity = m_pickingSystem.update(getMouse(), m_entityRegistry)) {
|
||||
if (auto pieceIndex = m_piecePresenter.getPieceIndex(*entity)) {
|
||||
spdlog::info("Sende MovePieceCommand fuer pieceIndex={}", *pieceIndex);
|
||||
m_gameMode->sendCommand(ludo::MovePieceCommand{m_localPlayer, *pieceIndex});
|
||||
} else {
|
||||
spdlog::warn("Entity {} getroffen, aber keine bekannte Spielfigur (getPieceIndex = nullopt)", entity->value());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GameLayer::onRender() {
|
||||
m_renderQueue.clear();
|
||||
|
||||
MeshRenderSystem meshRenderSystem;
|
||||
meshRenderSystem.update(m_entityRegistry, m_renderQueue);
|
||||
m_renderer->render(m_renderQueue, *m_camera, *m_pointLight);
|
||||
|
||||
renderHud();
|
||||
}
|
||||
@ -1,78 +0,0 @@
|
||||
//
|
||||
// Created by sebastian on 29.07.26.
|
||||
//
|
||||
|
||||
#ifndef COLORRACE_GAMELAYER_H
|
||||
#define COLORRACE_GAMELAYER_H
|
||||
#include <utility>
|
||||
|
||||
#include "core/animation/AnimationSystem.h"
|
||||
#include "core/audio/AudioDevice.h"
|
||||
#include "core/audio/SoundBuffer.h"
|
||||
#include "core/inputsOutputs/controller/CameraController.h"
|
||||
#include "ecs/EntityRegistry.h"
|
||||
#include "ecs/systems/PickingSystem.h"
|
||||
#include "layer/Layer.h"
|
||||
#include "ludo/BoardLayout.h"
|
||||
#include "ludo/LudoAiController.h"
|
||||
#include "ludo/PiecePresenter.h"
|
||||
#include "renderer/MeshRenderer.h"
|
||||
#include "renderer/RenderQueue.h"
|
||||
#include "utils/openglWrapper/GLRenderState.h"
|
||||
#include "ludo/LudoGameMode.h"
|
||||
#include "ludo/PresentationGameState.h"
|
||||
#include "ludo/ecs/highlight/HighlightSystem.h"
|
||||
|
||||
class GameLayer: public engine::Layer {
|
||||
public:
|
||||
GameLayer(engine::EventBus<engine::animation::AnimationMarkerEvent>& animationEventbus, std::shared_ptr<ludo::LudoGameMode> gameMode, engine::EntityRegistry& entityRegistry, std::shared_ptr<engine::Camera> cam, std::shared_ptr<engine::PointLight> light,
|
||||
engine::Keyboard& keyboard, engine::Mouse& mouse, std::shared_ptr<engine::Model> boardModel, std::unordered_map<std::string, std::shared_ptr<engine::Model>> pieceModdels, std::unordered_map<std::string, std::shared_ptr<engine::audio::SoundBuffer>> pieceSounds,
|
||||
engine::EventBus<ludo::LudoEvent>& eventBus)
|
||||
: Layer(keyboard, mouse, animationEventbus), m_gameMode(std::move(gameMode)), 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)), m_piecePresenter(animationEventbus, m_entityRegistry, std::move(pieceModdels), std::move(pieceSounds), m_boardLayout),
|
||||
m_pickingSystem(*m_camera), m_highlightSystem(*m_camera), m_animationSystem(m_entityRegistry), m_eventBus(eventBus) {
|
||||
for (auto playerID : m_gameMode->getPlayerOrder()) {
|
||||
if (playerID != m_localPlayer) {
|
||||
aiControllers.emplace_back(m_gameMode, playerID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void onUpdate(float deltaTime) override;
|
||||
void onRender() override;
|
||||
protected:
|
||||
void onAttachImpl() override;
|
||||
void onDetachImpl() override;
|
||||
private:
|
||||
engine::GLRenderState m_renderState;
|
||||
engine::RenderQueue m_renderQueue;
|
||||
engine::EntityRegistry& m_entityRegistry;
|
||||
engine::EventBus<ludo::LudoEvent>& m_eventBus;
|
||||
std::shared_ptr<engine::PointLight> m_pointLight;
|
||||
std::shared_ptr<engine::Camera> m_camera;
|
||||
std::unique_ptr<engine::MeshRenderer> m_renderer;
|
||||
std::unique_ptr<engine::CameraController> m_cameraController;
|
||||
|
||||
ludo::BoardLayout m_boardLayout;
|
||||
ludo::PiecePresenter m_piecePresenter;
|
||||
engine::PlayerID m_localPlayer = 0;
|
||||
std::shared_ptr<ludo::LudoGameMode> m_gameMode;
|
||||
std::unique_ptr<ludo::PresentationGameState> m_presentationGameState;
|
||||
engine::PickingSystem m_pickingSystem;
|
||||
ludo::HighlightSystem m_highlightSystem;
|
||||
|
||||
|
||||
std::vector<ludo::LudoAiController> aiControllers;
|
||||
engine::animation::AnimationSystem m_animationSystem;
|
||||
|
||||
|
||||
std::unique_ptr<engine::audio::SoundBuffer> m_soundBuffer;
|
||||
|
||||
|
||||
void renderHud();
|
||||
bool isAnimationBlocking() const;
|
||||
|
||||
bool isSoundBlocking() const;
|
||||
};
|
||||
|
||||
#endif //COLORRACE_GAMELAYER_H
|
||||
@ -5,7 +5,7 @@
|
||||
#include "GameScene.h"
|
||||
|
||||
#include "AudioLayer.h"
|
||||
#include "GameLayer.h"
|
||||
#include "gameLayer/GameLayer.h"
|
||||
#include "core/inputsOutputs/inputs/Mouse.h"
|
||||
#include "ecs/standardComponents/MeshComponent.h"
|
||||
#include "ecs/standardComponents/TransformComponent.h"
|
||||
@ -44,7 +44,7 @@ void GameScene::onEnter() {
|
||||
|
||||
addLayer(std::make_unique<ludo::AudioLayer>(*assetManager, m_keyboard, m_mouse, m_gameMode, entityRegistry, m_eventBus, getAnimationEventBus()));
|
||||
addLayer(std::make_unique<engine::DebugLayer>(getAnimationEventBus(), *m_camera, entityRegistry, m_keyboard, m_mouse, engine::SphereFactory::createUVSphere(1.0f)));
|
||||
addLayer(std::make_unique<GameLayer>(getAnimationEventBus(), m_gameMode, entityRegistry, m_camera, m_pointLight, m_keyboard, m_mouse, assetManager->getModel("gameboard"), pieceModels, pieceSounds, m_eventBus));
|
||||
addLayer(std::make_unique<GameLayer>(getAnimationEventBus(), m_gameMode, entityRegistry, m_camera, m_pointLight, m_keyboard, m_mouse, m_eventBus, *assetManager));
|
||||
}
|
||||
|
||||
void GameScene::onExit() {
|
||||
|
||||
5
game/src/gameLayer/GameInput.cpp
Normal file
5
game/src/gameLayer/GameInput.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
//
|
||||
// Created by sebastian on 05.08.26.
|
||||
//
|
||||
|
||||
#include "GameInput.h"
|
||||
13
game/src/gameLayer/GameInput.h
Normal file
13
game/src/gameLayer/GameInput.h
Normal file
@ -0,0 +1,13 @@
|
||||
//
|
||||
// Created by sebastian on 05.08.26.
|
||||
//
|
||||
|
||||
#ifndef COLORRACE_GAMEINPUT_H
|
||||
#define COLORRACE_GAMEINPUT_H
|
||||
|
||||
|
||||
class GameInput {
|
||||
};
|
||||
|
||||
|
||||
#endif //COLORRACE_GAMEINPUT_H
|
||||
101
game/src/gameLayer/GameLayer.cpp
Normal file
101
game/src/gameLayer/GameLayer.cpp
Normal file
@ -0,0 +1,101 @@
|
||||
//
|
||||
// Created by sebastian on 29.07.26.
|
||||
//
|
||||
|
||||
#include "GameLayer.h"
|
||||
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
|
||||
#include "ecs/standardComponents/MeshComponent.h"
|
||||
#include "ecs/standardComponents/TransformComponent.h"
|
||||
#include "renderer/MeshRenderer.h"
|
||||
#include "renderer/MeshRenderSystem.h"
|
||||
#define GLM_ENABLE_EXPERIMENTAL
|
||||
#include <glm/gtx/string_cast.hpp>
|
||||
|
||||
#include "core/animation/components/BlockingAnimationComponent.h"
|
||||
#include "core/audio/SoundSource.h"
|
||||
#include "core/audio/ecs/BlockingSoundComponent.h"
|
||||
#include "core/audio/ecs/PlaySoundComponent.h"
|
||||
#include "GLFW/glfw3.h"
|
||||
using namespace engine;
|
||||
void GameLayer::onAttachImpl() {
|
||||
m_renderState.depthTesting = false;
|
||||
m_renderState.backfaceCulling = false;
|
||||
|
||||
m_renderer = std::make_unique<engine::MeshRenderer>();
|
||||
|
||||
m_cameraController = std::make_unique<engine::CameraController>(getInputStack(), getInputContext());
|
||||
|
||||
|
||||
std::unordered_map<std::string, std::shared_ptr<engine::Model>> pieceModels = std::unordered_map<std::string, std::shared_ptr<engine::Model>>();
|
||||
pieceModels["Red"] = m_assetManager.getModel("pawn_red");
|
||||
pieceModels["Blue"] = m_assetManager.getModel("pawn_blue");
|
||||
pieceModels["Green"] = m_assetManager.getModel("pawn_green");
|
||||
pieceModels["Yellow"] = m_assetManager.getModel("pawn_yellow");
|
||||
|
||||
std::unordered_map<std::string, std::shared_ptr<engine::audio::SoundBuffer>> pieceSounds;
|
||||
pieceSounds["step"] = m_assetManager.getSound("pawn_step");
|
||||
|
||||
auto boardLayout = ludo::BoardLayout(m_assetManager.getModel("gameboard"));
|
||||
|
||||
ludo::GameController::LudoGameControllerContext context = {
|
||||
.gameMode = m_gameMode,
|
||||
.registry = m_entityRegistry,
|
||||
.camera = *m_camera,
|
||||
.boardLayout = boardLayout,
|
||||
.eventBus = m_eventBus,
|
||||
.animationEventBus = getAnimationEventBus(),
|
||||
.pieceModels = pieceModels,
|
||||
.pieceSounds = pieceSounds,
|
||||
.localPlayer = 0
|
||||
};
|
||||
this->m_GameController = std::move( ludo::GameController::LudoGameController::create(context));
|
||||
|
||||
}
|
||||
|
||||
void GameLayer::onDetachImpl() {
|
||||
|
||||
}
|
||||
|
||||
void GameLayer::renderHud() {
|
||||
ImGui::SetNextWindowPos(ImVec2(20, 20), ImGuiCond_FirstUseEver);
|
||||
ImGui::Begin("Ludo", nullptr, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize);
|
||||
|
||||
auto currentPlayerColor = m_GameController->getPresentationGameState().getCurrentPlayerColor();
|
||||
int currentDiceValue = m_GameController->getPresentationGameState().getDiceValue();
|
||||
ImGui::Text("Am Zug: %s", toString(currentPlayerColor).data());
|
||||
ImGui::Text("Wuerfel: %d", currentDiceValue);
|
||||
|
||||
ImGui::BeginDisabled(m_GameController->isBlocking() || !m_GameController->getPresentationGameState().isDiceRollEnabled());
|
||||
if (ImGui::Button("Wuerfeln")) {
|
||||
m_gameMode->sendCommand(ludo::RollDiceCommand{m_GameController->getLocalPlayer()});
|
||||
}
|
||||
//
|
||||
// if (!m_lastEventMessage.empty()) ImGui::Text("%s", m_lastEventMessage.c_str());
|
||||
|
||||
ImGui::EndDisabled();
|
||||
|
||||
ImGui::End();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void GameLayer::onUpdate(float deltaTime) {
|
||||
Layer::onUpdate(deltaTime);
|
||||
m_cameraController->update(getKeyboard(), *m_camera, deltaTime);
|
||||
|
||||
m_GameController->update(deltaTime, getMouse(), getKeyboard());
|
||||
}
|
||||
|
||||
void GameLayer::onRender() {
|
||||
m_renderQueue.clear();
|
||||
|
||||
MeshRenderSystem meshRenderSystem;
|
||||
meshRenderSystem.update(m_entityRegistry, m_renderQueue);
|
||||
m_renderer->render(m_renderQueue, *m_camera, *m_pointLight);
|
||||
|
||||
renderHud();
|
||||
}
|
||||
73
game/src/gameLayer/GameLayer.h
Normal file
73
game/src/gameLayer/GameLayer.h
Normal file
@ -0,0 +1,73 @@
|
||||
//
|
||||
// Created by sebastian on 29.07.26.
|
||||
//
|
||||
|
||||
#ifndef COLORRACE_GAMELAYER_H
|
||||
#define COLORRACE_GAMELAYER_H
|
||||
#include <utility>
|
||||
|
||||
#include "core/animation/AnimationSystem.h"
|
||||
#include "core/audio/AudioDevice.h"
|
||||
#include "core/audio/SoundBuffer.h"
|
||||
#include "core/inputsOutputs/controller/CameraController.h"
|
||||
#include "ecs/EntityRegistry.h"
|
||||
#include "ecs/systems/PickingSystem.h"
|
||||
#include "layer/Layer.h"
|
||||
#include "../ludo/BoardLayout.h"
|
||||
#include "../ludo/LudoAiController.h"
|
||||
#include "../ludo/PiecePresenter.h"
|
||||
#include "renderer/MeshRenderer.h"
|
||||
#include "renderer/RenderQueue.h"
|
||||
#include "utils/openglWrapper/GLRenderState.h"
|
||||
#include "../ludo/LudoGameMode.h"
|
||||
#include "../ludo/PresentationGameState.h"
|
||||
#include "../ludo/ecs/highlight/HighlightSystem.h"
|
||||
#include "gameController/LudoGameController.h"
|
||||
|
||||
class GameLayer: public engine::Layer {
|
||||
public:
|
||||
GameLayer(
|
||||
engine::EventBus<engine::animation::AnimationMarkerEvent>& animationEventbus,
|
||||
std::shared_ptr<ludo::LudoGameMode> gameMode,
|
||||
engine::EntityRegistry& entityRegistry,
|
||||
std::shared_ptr<engine::Camera> cam,
|
||||
std::shared_ptr<engine::PointLight> light,
|
||||
engine::Keyboard& keyboard, engine::Mouse& mouse,
|
||||
engine::EventBus<ludo::LudoEvent>& eventBus,
|
||||
engine::AssetManager& assetManager
|
||||
)
|
||||
:
|
||||
Layer(keyboard, mouse, animationEventbus),
|
||||
m_gameMode(gameMode),
|
||||
m_eventBus(eventBus),
|
||||
m_entityRegistry(entityRegistry),
|
||||
m_camera(std::move(cam)),
|
||||
m_pointLight(std::move(light)),
|
||||
m_assetManager(assetManager)
|
||||
{}
|
||||
|
||||
|
||||
void onUpdate(float deltaTime) override;
|
||||
void onRender() override;
|
||||
protected:
|
||||
void onAttachImpl() override;
|
||||
void onDetachImpl() override;
|
||||
private:
|
||||
engine::GLRenderState m_renderState;
|
||||
engine::RenderQueue m_renderQueue;
|
||||
engine::EntityRegistry& m_entityRegistry;
|
||||
engine::EventBus<ludo::LudoEvent>& m_eventBus;
|
||||
std::shared_ptr<engine::PointLight> m_pointLight;
|
||||
std::shared_ptr<engine::Camera> m_camera;
|
||||
std::unique_ptr<engine::MeshRenderer> m_renderer;
|
||||
std::unique_ptr<engine::CameraController> m_cameraController;
|
||||
std::shared_ptr<ludo::LudoGameMode> m_gameMode;
|
||||
std::unique_ptr<engine::audio::SoundBuffer> m_soundBuffer;
|
||||
|
||||
|
||||
void renderHud();
|
||||
std::unique_ptr<ludo::GameController::LudoGameController> m_GameController;
|
||||
engine::AssetManager& m_assetManager;
|
||||
};
|
||||
|
||||
#endif //COLORRACE_GAMELAYER_H
|
||||
5
game/src/gameLayer/GameRenderer.cpp
Normal file
5
game/src/gameLayer/GameRenderer.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
//
|
||||
// Created by sebastian on 05.08.26.
|
||||
//
|
||||
|
||||
#include "GameRenderer.h"
|
||||
13
game/src/gameLayer/GameRenderer.h
Normal file
13
game/src/gameLayer/GameRenderer.h
Normal file
@ -0,0 +1,13 @@
|
||||
//
|
||||
// Created by sebastian on 05.08.26.
|
||||
//
|
||||
|
||||
#ifndef COLORRACE_GAMERENDERER_H
|
||||
#define COLORRACE_GAMERENDERER_H
|
||||
|
||||
|
||||
class GameRenderer {
|
||||
};
|
||||
|
||||
|
||||
#endif //COLORRACE_GAMERENDERER_H
|
||||
5
game/src/gameLayer/LudoHud.cpp
Normal file
5
game/src/gameLayer/LudoHud.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
//
|
||||
// Created by sebastian on 05.08.26.
|
||||
//
|
||||
|
||||
#include "LudoHud.h"
|
||||
13
game/src/gameLayer/LudoHud.h
Normal file
13
game/src/gameLayer/LudoHud.h
Normal file
@ -0,0 +1,13 @@
|
||||
//
|
||||
// Created by sebastian on 05.08.26.
|
||||
//
|
||||
|
||||
#ifndef COLORRACE_LUDOHUD_H
|
||||
#define COLORRACE_LUDOHUD_H
|
||||
|
||||
|
||||
class LudoHud {
|
||||
};
|
||||
|
||||
|
||||
#endif //COLORRACE_LUDOHUD_H
|
||||
96
game/src/gameLayer/gameController/LudoGameController.cpp
Normal file
96
game/src/gameLayer/gameController/LudoGameController.cpp
Normal file
@ -0,0 +1,96 @@
|
||||
//
|
||||
// Created by sebastian on 05.08.26.
|
||||
//
|
||||
|
||||
#include "LudoGameController.h"
|
||||
|
||||
#include "core/animation/components/BlockingAnimationComponent.h"
|
||||
#include "core/audio/ecs/BlockingSoundComponent.h"
|
||||
|
||||
std::unique_ptr<ludo::GameController::LudoGameController> ludo::GameController::LudoGameController::create(LudoGameControllerContext& context) {
|
||||
auto controller = std::make_unique<LudoGameController>(context);
|
||||
controller->m_piecePresenter.spawnPieces(context.gameMode->getState());
|
||||
std::vector<engine::PlayerID> playerOrder = controller->m_gameMode->getPlayerOrder();
|
||||
for (engine::PlayerID player : playerOrder) {
|
||||
if (player == context.localPlayer) continue;
|
||||
|
||||
controller->m_aiControllers.emplace_back(LudoAiController(controller->m_gameMode, player));
|
||||
}
|
||||
return controller;
|
||||
}
|
||||
|
||||
void ludo::GameController::LudoGameController::update(float deltaTime, const engine::Mouse &mouse, const engine::Keyboard &keyboard) {
|
||||
m_animationSystem.update(deltaTime);
|
||||
|
||||
if (isBlocking()) return;
|
||||
|
||||
processEvents();
|
||||
|
||||
m_presentationGameState.commitGameState(
|
||||
m_gameMode->getCurrentPlayer(),
|
||||
m_gameMode->getColorOf(m_gameMode->getCurrentPlayer()),
|
||||
m_gameMode->getState().getDiceValue(),
|
||||
m_gameMode->getCurrentPlayer() == 0 //Todo: Replace through real m_localPlayer variable
|
||||
);
|
||||
|
||||
for (auto& ai : m_aiControllers) {
|
||||
ai.update(deltaTime);
|
||||
}
|
||||
|
||||
handleInput(mouse, keyboard);
|
||||
}
|
||||
|
||||
void ludo::GameController::LudoGameController::handleInput(const engine::Mouse &mouse, const engine::Keyboard &keyboard) {
|
||||
m_highlightSystem.update(mouse, m_registry);
|
||||
|
||||
auto entity = m_pickingSystem.update(mouse, m_registry);
|
||||
if (!entity) return;
|
||||
|
||||
auto pieceIndex = m_piecePresenter.getPieceIndex(*entity);
|
||||
if (!pieceIndex) return;
|
||||
|
||||
m_gameMode->sendCommand(MovePieceCommand(m_localPlayer, *pieceIndex));
|
||||
}
|
||||
|
||||
void ludo::GameController::LudoGameController::processEvents() {
|
||||
for (const auto& event : m_gameMode->pollEvents()) {
|
||||
std::visit([this]<typename T>(const T& e) {
|
||||
if constexpr (std::is_same_v<T, ludo::PieceMovedEvent>) {
|
||||
m_piecePresenter.onPieceMoved(e, m_gameMode->getState());
|
||||
}
|
||||
if constexpr (std::is_same_v<T, ludo::DiceRolledEvent>) {
|
||||
// m_lastEventMessage = std::format("Wuerfel geworfen: {}", e.diceValue);
|
||||
}
|
||||
// DiceRolledEvent/TurnChangedEvent -> ImGui-State aktualisieren
|
||||
}, event);
|
||||
}
|
||||
}
|
||||
|
||||
bool ludo::GameController::LudoGameController::isBlocking() const {
|
||||
const bool isSoundBlocking = m_registry.getPool<engine::audio::BlockingSoundComponent>().size() > 0;
|
||||
const bool isAnimationBlocking = m_registry.getPool<engine::animation::BlockingAnimationComponent>().size() > 0;
|
||||
|
||||
return isSoundBlocking || isAnimationBlocking;
|
||||
}
|
||||
|
||||
ludo::GameController::LudoGameController::LudoGameController(
|
||||
LudoGameControllerContext deps
|
||||
)
|
||||
:
|
||||
m_gameMode(std::move(deps.gameMode)),
|
||||
m_registry(deps.registry),
|
||||
m_piecePresenter(
|
||||
deps.animationEventBus,
|
||||
m_registry,
|
||||
std::move(deps.pieceModels),
|
||||
std::move(deps.pieceSounds),
|
||||
deps.boardLayout
|
||||
),
|
||||
m_presentationGameState(*m_gameMode, m_gameMode->getState()),
|
||||
m_animationSystem(m_registry),
|
||||
m_highlightSystem(deps.camera),
|
||||
m_pickingSystem(deps.camera),
|
||||
m_localPlayer(deps.localPlayer)
|
||||
{
|
||||
}
|
||||
|
||||
49
game/src/gameLayer/gameController/LudoGameController.h
Normal file
49
game/src/gameLayer/gameController/LudoGameController.h
Normal file
@ -0,0 +1,49 @@
|
||||
//
|
||||
// Created by sebastian on 05.08.26.
|
||||
//
|
||||
|
||||
#ifndef COLORRACE_LUDOGAMECONTROLLER_H
|
||||
#define COLORRACE_LUDOGAMECONTROLLER_H
|
||||
#include <memory>
|
||||
|
||||
#include "LudoGameControllerContext.h"
|
||||
#include "core/animation/AnimationSystem.h"
|
||||
#include "core/inputsOutputs/inputs/Keyboard.h"
|
||||
#include "ecs/systems/PickingSystem.h"
|
||||
#include "ludo/LudoAiController.h"
|
||||
#include "ludo/LudoGameMode.h"
|
||||
#include "ludo/PiecePresenter.h"
|
||||
#include "ludo/PresentationGameState.h"
|
||||
#include "ludo/ecs/highlight/HighlightSystem.h"
|
||||
|
||||
|
||||
namespace ludo::GameController {
|
||||
class LudoGameController {
|
||||
public:
|
||||
explicit LudoGameController(LudoGameControllerContext context);
|
||||
static std::unique_ptr<LudoGameController> create(LudoGameControllerContext& context);
|
||||
void update(float deltaTime, const engine::Mouse& mouse, const engine::Keyboard& keyboard);
|
||||
void processEvents();
|
||||
bool isBlocking() const;
|
||||
const PresentationGameState& getPresentationGameState() const { return m_presentationGameState; }
|
||||
engine::PlayerID getLocalPlayer() const { return m_localPlayer; }
|
||||
private:
|
||||
std::shared_ptr<LudoGameMode> m_gameMode;
|
||||
engine::EntityRegistry& m_registry;
|
||||
|
||||
PiecePresenter m_piecePresenter;
|
||||
PresentationGameState m_presentationGameState;
|
||||
|
||||
engine::animation::AnimationSystem m_animationSystem;
|
||||
HighlightSystem m_highlightSystem;
|
||||
engine::PickingSystem m_pickingSystem;
|
||||
|
||||
std::vector<LudoAiController> m_aiControllers;
|
||||
engine::PlayerID m_localPlayer;
|
||||
|
||||
void handleInput(const engine::Mouse& mouse, const engine::Keyboard& keyboard);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif //COLORRACE_LUDOGAMECONTROLLER_H
|
||||
@ -0,0 +1,35 @@
|
||||
//
|
||||
// Created by sebastian on 05.08.26.
|
||||
//
|
||||
|
||||
#ifndef COLORRACE_LUDOGAMECONTROLLERCONTEXT_H
|
||||
#define COLORRACE_LUDOGAMECONTROLLERCONTEXT_H
|
||||
#include <memory>
|
||||
|
||||
#include "core/animation/events/AnimationMarkerEvent.h"
|
||||
#include "core/audio/SoundBuffer.h"
|
||||
#include "ecs/EntityRegistry.h"
|
||||
#include "ludo/BoardLayout.h"
|
||||
#include "ludo/LudoGameMode.h"
|
||||
#include "renderer/entities/Camera.h"
|
||||
|
||||
namespace ludo::GameController {
|
||||
struct LudoGameControllerContext {
|
||||
std::shared_ptr<LudoGameMode> gameMode;
|
||||
|
||||
engine::EntityRegistry& registry;
|
||||
engine::Camera& camera;
|
||||
|
||||
ludo::BoardLayout& boardLayout;
|
||||
|
||||
engine::EventBus<ludo::LudoEvent>& eventBus;
|
||||
engine::EventBus<engine::animation::AnimationMarkerEvent>& animationEventBus;
|
||||
|
||||
std::unordered_map<std::string, std::shared_ptr<engine::Model>> pieceModels;
|
||||
|
||||
std::unordered_map<std::string, std::shared_ptr<engine::audio::SoundBuffer>> pieceSounds;
|
||||
int localPlayer;
|
||||
};
|
||||
}
|
||||
|
||||
#endif //COLORRACE_LUDOGAMECONTROLLERCONTEXT_H
|
||||
@ -7,11 +7,12 @@
|
||||
#include "LudoGameMode.h"
|
||||
|
||||
ludo::PresentationGameState::PresentationGameState(const LudoGameMode& gameMode, const LudoGameState &originalGameState) :
|
||||
m_currentPlayer(gameMode.getCurrentPlayer()), m_diceValue(originalGameState.getDiceValue()), m_enableDiceRoll(false) {
|
||||
m_currentPlayer(gameMode.getCurrentPlayer()), m_diceValue(originalGameState.getDiceValue()), m_enableDiceRoll(false), m_currentPlayerColor(gameMode.getColorOf(gameMode.getCurrentPlayer())) {
|
||||
}
|
||||
|
||||
void ludo::PresentationGameState::commitGameState(const engine::PlayerID currentPlayer, const int diceValue, const bool enableDiceRoll) {
|
||||
void ludo::PresentationGameState::commitGameState(const engine::PlayerID currentPlayer, const ludo::PlayerColor color, const int diceValue, const bool enableDiceRoll) {
|
||||
m_currentPlayer = currentPlayer;
|
||||
m_diceValue = diceValue;
|
||||
m_enableDiceRoll = enableDiceRoll;
|
||||
m_currentPlayerColor = color;
|
||||
}
|
||||
|
||||
@ -11,13 +11,15 @@ namespace ludo {
|
||||
class PresentationGameState {
|
||||
public:
|
||||
explicit PresentationGameState(const LudoGameMode& gameMode, const LudoGameState& originalGameState);
|
||||
void commitGameState(engine::PlayerID currentPlayer, int diceValue, bool enableDiceRoll);
|
||||
void commitGameState(engine::PlayerID currentPlayer, ludo::PlayerColor color, int diceValue, bool enableDiceRoll);
|
||||
|
||||
[[nodiscard]] engine::PlayerID getCurrentPlayer() const { return m_currentPlayer; }
|
||||
[[nodiscard]] int getDiceValue() const { return m_diceValue; }
|
||||
[[nodiscard]] bool isDiceRollEnabled() const { return m_enableDiceRoll; }
|
||||
[[nodiscard]] ludo::PlayerColor getCurrentPlayerColor() const { return m_currentPlayerColor; }
|
||||
private:
|
||||
engine::PlayerID m_currentPlayer ;
|
||||
engine::PlayerID m_currentPlayer;
|
||||
ludo::PlayerColor m_currentPlayerColor;
|
||||
int m_diceValue;
|
||||
bool m_enableDiceRoll;
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user