ADD: Generic GameMode and GameState
This commit is contained in:
parent
92e3092d3b
commit
7d1774e222
@ -147,6 +147,12 @@ add_library(Engine STATIC
|
|||||||
engine/src/core/inputsOutputs/context/InputContextStack.h
|
engine/src/core/inputsOutputs/context/InputContextStack.h
|
||||||
engine/src/core/inputsOutputs/controller/CameraController.cpp
|
engine/src/core/inputsOutputs/controller/CameraController.cpp
|
||||||
engine/src/core/inputsOutputs/controller/CameraController.h
|
engine/src/core/inputsOutputs/controller/CameraController.h
|
||||||
|
engine/src/game/GameState.cpp
|
||||||
|
engine/src/game/GameState.h
|
||||||
|
engine/src/game/GameMode.cpp
|
||||||
|
engine/src/game/GameMode.h
|
||||||
|
engine/src/game/TurnBasedGameMode.cpp
|
||||||
|
engine/src/game/TurnBasedGameMode.h
|
||||||
)
|
)
|
||||||
target_include_directories(Engine PUBLIC engine/src)
|
target_include_directories(Engine PUBLIC engine/src)
|
||||||
target_link_libraries(Engine PUBLIC OpenGL::GL glfw glad glm::glm imgui spdlog::spdlog tinyobjloader stb_image)
|
target_link_libraries(Engine PUBLIC OpenGL::GL glfw glad glm::glm imgui spdlog::spdlog tinyobjloader stb_image)
|
||||||
|
|||||||
5
engine/src/game/GameMode.cpp
Normal file
5
engine/src/game/GameMode.cpp
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
//
|
||||||
|
// Created by sebastian on 02.08.26.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "GameMode.h"
|
||||||
28
engine/src/game/GameMode.h
Normal file
28
engine/src/game/GameMode.h
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
//
|
||||||
|
// Created by sebastian on 02.08.26.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef COLORRACE_GAMEMODE_H
|
||||||
|
#define COLORRACE_GAMEMODE_H
|
||||||
|
#include <type_traits>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "GameState.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace engine {
|
||||||
|
template <typename Command, typename Event, typename State>
|
||||||
|
class GameMode {
|
||||||
|
public:
|
||||||
|
static_assert(std::is_base_of_v<GameState, State>, "State must be derived from GameState");
|
||||||
|
|
||||||
|
virtual ~GameMode() = default;
|
||||||
|
|
||||||
|
virtual void sendCommand(const Command& command) = 0;
|
||||||
|
virtual std::vector<Event> pollEvents() = 0;
|
||||||
|
[[nodiscard]] virtual const State& getState() const = 0;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif //COLORRACE_GAMEMODE_H
|
||||||
5
engine/src/game/GameState.cpp
Normal file
5
engine/src/game/GameState.cpp
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
//
|
||||||
|
// Created by sebastian on 02.08.26.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "GameState.h"
|
||||||
17
engine/src/game/GameState.h
Normal file
17
engine/src/game/GameState.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
//
|
||||||
|
// Created by sebastian on 02.08.26.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef COLORRACE_GAMESTATE_H
|
||||||
|
#define COLORRACE_GAMESTATE_H
|
||||||
|
|
||||||
|
|
||||||
|
namespace engine {
|
||||||
|
class GameState {
|
||||||
|
public:
|
||||||
|
virtual ~GameState() = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif //COLORRACE_GAMESTATE_H
|
||||||
5
engine/src/game/TurnBasedGameMode.cpp
Normal file
5
engine/src/game/TurnBasedGameMode.cpp
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
//
|
||||||
|
// Created by sebastian on 02.08.26.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "TurnBasedGameMode.h"
|
||||||
31
engine/src/game/TurnBasedGameMode.h
Normal file
31
engine/src/game/TurnBasedGameMode.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
//
|
||||||
|
// Created by sebastian on 02.08.26.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef COLORRACE_TURNBASEDGAMEMODE_H
|
||||||
|
#define COLORRACE_TURNBASEDGAMEMODE_H
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
#include "GameMode.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace engine {
|
||||||
|
using PlayerID = uint32_t;
|
||||||
|
|
||||||
|
template<typename Command, typename Event, typename State>
|
||||||
|
class TurnBasedGameMode : public GameMode<Command, Event, State> {
|
||||||
|
public:
|
||||||
|
explicit TurnBasedGameMode(std::vector<PlayerID> playerOrder) : m_playerOrder(std::move(playerOrder)) {}
|
||||||
|
[[nodiscard]] PlayerID getCurrentPlayer() const { return m_playerOrder[m_currentPlayerIndex]; }
|
||||||
|
[[nodiscard]] bool isCurrentPlayer(PlayerID playerID) const { return getCurrentPlayer() == playerID; }
|
||||||
|
protected:
|
||||||
|
void endTurn(bool extraTurn = false) {
|
||||||
|
if (!extraTurn) m_currentPlayerIndex = (m_currentPlayerIndex + 1) % m_playerOrder.size();
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
std::vector<PlayerID> m_playerOrder;
|
||||||
|
size_t m_currentPlayerIndex = 0;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //COLORRACE_TURNBASEDGAMEMODE_H
|
||||||
Loading…
Reference in New Issue
Block a user