ADD: Gamesessions

This commit is contained in:
sebastian 2026-08-05 19:50:24 +02:00
parent 4ab4ea5262
commit dac70c0eed
7 changed files with 126 additions and 0 deletions

View File

@ -251,6 +251,19 @@ add_library(Engine STATIC
target_include_directories(Engine PUBLIC engine/src ${dr_libs_SOURCE_DIR})
target_link_libraries(Engine PUBLIC OpenGL::GL glfw glad glm::glm imgui spdlog::spdlog tinyobjloader stb_image OpenAL::OpenAL)
CPMAddPackage(
NAME asio
GITHUB_REPOSITORY chriskohlhoff/asio
GIT_TAG asio-1-30-2 # Eine stabile, aktuelle Version
DOWNLOAD_ONLY YES # Da Asio Header-only ist und kein CMake-Projekt hat
)
add_library(asio INTERFACE)
target_include_directories(asio INTERFACE ${asio_SOURCE_DIR}/asio/include)
# Definiere ASIO_STANDALONE, damit Asio weiß, dass es KEIN Boost benötigt
target_compile_definitions(asio INTERFACE ASIO_STANDALONE)
# --- GameLib: Spiel-Logik, unabhängig von main.cpp testbar ---
add_library(GameLib STATIC
game/src/ColorRaceApp.cpp
@ -303,6 +316,12 @@ add_executable(ColorRace
engine/src/core/audio/ecs/AudioSystem.cpp
engine/src/core/audio/ecs/AudioSystem.h
engine/src/core/audio/ecs/BlockingSoundComponent.h
game/src/ludo/multiplayer/IGameSession.cpp
game/src/ludo/multiplayer/IGameSession.h
game/src/ludo/multiplayer/LocalGameSession.cpp
game/src/ludo/multiplayer/LocalGameSession.h
game/src/ludo/multiplayer/RemoteGameSession.cpp
game/src/ludo/multiplayer/RemoteGameSession.h
)
target_link_libraries(ColorRace PRIVATE
@ -323,5 +342,15 @@ target_link_libraries(ColorRaceTests PRIVATE
GTest::gtest_main
)
if(WIN32)
# Windows benötigt zwingend die WinSock-Libraries und Win-Header-Anpassungen
target_link_libraries(ColorRace PRIVATE ws2_32 mswsock)
target_compile_definitions(ColorRace PRIVATE _WIN32_WINNT=0x0601) # Mindestens Windows 7 Target
else()
# Linux/macOS benötigt die Thread-Library für die Hintergrund-Worker
find_package(Threads REQUIRED)
target_link_libraries(ColorRace PRIVATE Threads::Threads)
endif()
include(GoogleTest)
gtest_discover_tests(ColorRaceTests)

View File

@ -0,0 +1,5 @@
//
// Created by sebastian on 05.08.26.
//
#include "IGameSession.h"

View File

@ -0,0 +1,23 @@
//
// Created by sebastian on 05.08.26.
//
#ifndef COLORRACE_IGAMESESSION_H
#define COLORRACE_IGAMESESSION_H
#include "ludo/LudoTypes.h"
class IGameSession {
public:
virtual ~IGameSession() = default;
// Befehle von der UI an das Spiel senden
virtual void sendCommand(const std::variant<ludo::MovePieceCommand, ludo::RollDiceCommand> &command) {
}
// Events vom Spiel abholen, um die UI zu aktualisieren
virtual std::vector<ludo::LudoEvent> pollEvents() = 0;
};
#endif //COLORRACE_IGAMESESSION_H

View File

@ -0,0 +1,14 @@
//
// Created by sebastian on 05.08.26.
//
#include "LocalGameSession.h"
void LocalGameSession::sendCommand(const std::variant<ludo::MovePieceCommand, ludo::RollDiceCommand> &command) {
IGameSession::sendCommand(command);
m_gameMode.sendCommand(command);
}
std::vector<ludo::LudoEvent> LocalGameSession::pollEvents() {
return m_gameMode.pollEvents();
}

View File

@ -0,0 +1,20 @@
//
// Created by sebastian on 05.08.26.
//
#ifndef COLORRACE_LOCALGAMESESSION_H
#define COLORRACE_LOCALGAMESESSION_H
#include "IGameSession.h"
#include "ludo/LudoGameMode.h"
class LocalGameSession : public IGameSession{
private:
ludo::LudoGameMode m_gameMode;
public:
void sendCommand(const std::variant<ludo::MovePieceCommand, ludo::RollDiceCommand> &command) override;
std::vector<ludo::LudoEvent> pollEvents() override;
};
#endif //COLORRACE_LOCALGAMESESSION_H

View File

@ -0,0 +1,17 @@
//
// Created by sebastian on 05.08.26.
//
#include "RemoteGameSession.h"
void RemoteGameSession::sendCommand(const std::variant<ludo::MovePieceCommand, ludo::RollDiceCommand> &command) {
// 1. In JSON / Bytes verpacken
// 2. Über den Socket asynchron an den Server senden
// m_socket.send(serializedCommand);
}
std::vector<ludo::LudoEvent> RemoteGameSession::pollEvents() {
// Holt die Events ab, die der Netzwerk-Thread im Hintergrund
// vom Server empfangen und in die Queue gelegt hat.
return std::vector<ludo::LudoEvent>();
}

View File

@ -0,0 +1,18 @@
//
// Created by sebastian on 05.08.26.
//
#ifndef COLORRACE_REMOTEGAMESESSION_H
#define COLORRACE_REMOTEGAMESESSION_H
#include "IGameSession.h"
class RemoteGameSession : public IGameSession{
private:
public:
void sendCommand(const std::variant<ludo::MovePieceCommand, ludo::RollDiceCommand> &command) override;
std::vector<ludo::LudoEvent> pollEvents() override;
};
#endif //COLORRACE_REMOTEGAMESESSION_H