UPD: Move PlayerID inside Engine
All checks were successful
Tests / test (push) Successful in 2m32s

This commit is contained in:
Sebastian Böckelmann 2026-04-20 10:36:12 +02:00
parent 738d424df9
commit a9b155ffc8
22 changed files with 80 additions and 49 deletions

View File

@ -1,2 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="CIDR" type="CPP_MODULE" version="4" />
<module classpath="CMake" type="CPP_MODULE" version="4" />

View File

@ -17,7 +17,7 @@
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBoostFormatTooManyArgs/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppCStyleCast/@EntryIndexedValue" value="SUGGESTION" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppCVQualifierCanNotBeAppliedToReference/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassCanBeFinal/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassCanBeFinal/@EntryIndexedValue" value="HINT" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassIsIncomplete/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassNeedsConstructorBecauseOfUninitializedMember/@EntryIndexedValue" value="WARNING" type="string" />
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassNeverUsed/@EntryIndexedValue" value="WARNING" type="string" />
@ -257,7 +257,6 @@
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTILINE_TYPE_PARAMETER/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_MULTIPLE_DECLARATION/@EntryValue" value="false" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALIGN_TERNARY/@EntryValue" value="ALIGN_ALL" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ALLOW_FAR_ALIGNMENT/@EntryValue" value="true" type="bool" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/ANONYMOUS_METHOD_DECLARATION_BRACES/@EntryValue" value="END_OF_LINE" type="string" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_CLASS_DEFINITION/@EntryValue" value="1" type="int" />
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/BLANK_LINES_AROUND_DECLARATIONS/@EntryValue" value="0" type="int" />

View File

@ -289,6 +289,8 @@ if(BUILD_GAME)
src/game/GameWorldSystems.cpp
src/game/GameWorldSystems.h
src/engine/core/gui/uiComponent/layout/LayoutEngine.h
src/engine/renderer/config/MinimapConfig.h
src/engine/core/Types.h
)
target_compile_options(Dicewars_Siedler PRIVATE
-Wall

13
src/engine/core/Types.h Normal file
View File

@ -0,0 +1,13 @@
//
// Created by sebastian on 20.04.26.
//
#ifndef TYPES_H
#define TYPES_H
#include <cstdint>
namespace Engine {
using PlayerID = std::uint32_t;
}
#endif //TYPES_H

View File

@ -29,7 +29,7 @@ void MasterRenderer::render(const Light &light, const Camera &camera) {
worldSpriteRenderer->finalize();
worldSprites.clear();
std::unordered_map<PlayerID, glm::vec3> colorMapping;
std::unordered_map<Engine::PlayerID, glm::vec3> colorMapping;
colorMapping[0] = glm::vec3(1.0f, 0.0f, 0.0f);
colorMapping[1] = glm::vec3(0.0f, 1.0f, 0.0f);
colorMapping[2] = glm::vec3(0.0f, 0.0f, 1.0f);

View File

@ -13,7 +13,7 @@
#include "glm/ext/matrix_transform.hpp"
void MinimapRenderer::render(const std::vector<MinimapRenderData> &renderData, std::unordered_map<PlayerID, glm::vec3> colorMapping) {
void MinimapRenderer::render(const std::vector<MinimapRenderData> &renderData, std::unordered_map<Engine::PlayerID, glm::vec3> colorMapping) {
minimapFBO->bind();
glViewport(0,0, width, height);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
@ -92,7 +92,7 @@ void MinimapRenderer::finalizeShader() {
minimapShader.stop();
}
void MinimapRenderer::prepareInstance(const MinimapRenderData &data, const std::unordered_map<PlayerID, glm::vec3>& colorMapping) {
void MinimapRenderer::prepareInstance(const MinimapRenderData &data, const std::unordered_map<Engine::PlayerID, glm::vec3>& colorMapping) {
glm::mat4 model = MathUtils::createTransformationMatrix(data.transform->position, data.transform->rotation.x, data.transform->rotation.y, data.transform->rotation.z, data.transform->scale);
minimapShader.loadTransformationMatrix(model);

View File

@ -19,7 +19,7 @@ public:
minimapFBO = std::make_unique<FramebufferObject>(width, height);
}
void render(const std::vector<MinimapRenderData> &renderData, std::unordered_map<PlayerID, glm::vec3> colorMapping);
void render(const std::vector<MinimapRenderData> &renderData, std::unordered_map<Engine::PlayerID, glm::vec3> colorMapping);
GLuint getMinimapTexture();
@ -30,7 +30,7 @@ private:
void prepareShader();
void finalizeShader();
void prepareInstance(const MinimapRenderData &data, const std::unordered_map<PlayerID, glm::vec3>& colorMapping);
void prepareInstance(const MinimapRenderData &data, const std::unordered_map<Engine::PlayerID, glm::vec3>& colorMapping);
};

View File

@ -0,0 +1,16 @@
//
// Created by sebastian on 20.04.26.
//
#ifndef MINIMAPCONFIG_H
#define MINIMAPCONFIG_H
#include <unordered_map>
#include "../../../game/player/Player.h"
struct MinimapConfig {
int resolution;
std::unordered_map<Engine::PlayerID, glm::vec3> playerColors;
};
#endif //MINIMAPCONFIG_H

View File

@ -15,7 +15,7 @@ GameMode::GameMode() {
addPlayer(1, "Player 2");
}
bool GameMode::canBuild(PlayerID player, BuildingType buildingType) const {
bool GameMode::canBuild(Engine::PlayerID player, BuildingType buildingType) const {
const auto def = BuildingConfig::get(buildingType);
const auto buildingCosts = def.resourceCosts;
@ -27,33 +27,33 @@ bool GameMode::canBuild(PlayerID player, BuildingType buildingType) const {
return true;
}
bool GameMode::canAfford(const PlayerID player_id, RessourceType ressource, int amount) const {
bool GameMode::canAfford(const Engine::PlayerID player_id, RessourceType ressource, int amount) const {
if (players.contains(player_id)) {
return players.at(player_id).getInventory()->getAmount(ressource) >= amount;
}
return false;
}
void GameMode::build(PlayerID player, EntityID tileEntity, BuildingType buildingType) {
void GameMode::build(Engine::PlayerID player, EntityID tileEntity, BuildingType buildingType) {
if (canBuild(player, buildingType)) {
players[player].getInventory()->spend(RessourceType::WOOD, 10);
}
}
void GameMode::addPlayer(PlayerID playerID, std::string name) {
PlayerID id = static_cast<PlayerID>(players.size());
void GameMode::addPlayer(Engine::PlayerID playerID, std::string name) {
Engine::PlayerID id = static_cast<Engine::PlayerID>(players.size());
players[id] = Player(id, name);
}
PlayerID GameMode::getCurrentPlayer() {
Engine::PlayerID GameMode::getCurrentPlayer() {
return 0;
}
PlayerInventory& GameMode::getPlayerInventory(PlayerID playerID) {
PlayerInventory& GameMode::getPlayerInventory(Engine::PlayerID playerID) {
return *players[playerID].getInventory();
}
void GameMode::pay(PlayerID playerID, const std::unordered_map<RessourceType, int> &costs) {
void GameMode::pay(Engine::PlayerID playerID, const std::unordered_map<RessourceType, int> &costs) {
for (const auto &[resourceType, amount] : costs) {
players[playerID].getInventory()->spend(resourceType, amount);
}
@ -75,15 +75,15 @@ size_t GameMode::getPlayerCount() const {
return players.size();
}
bool GameMode::hasTurn(PlayerID playerID, int turn) const {
bool GameMode::hasTurn(Engine::PlayerID playerID, int turn) const {
return turn % static_cast<int>(getPlayerCount()) == static_cast<int>(playerID);
}
void GameMode::addResource(PlayerID playerID, RessourceType ressource, int amount) {
void GameMode::addResource(Engine::PlayerID playerID, RessourceType ressource, int amount) {
players[playerID].getInventory()->add(ressource, amount);
}
glm::vec3 GameMode::getColorOfPlayer(PlayerID playerID) {
glm::vec3 GameMode::getColorOfPlayer(Engine::PlayerID playerID) {
return players[playerID].getColor();
}

View File

@ -18,27 +18,27 @@ public:
GameMode();
bool canBuild(EntityID player, BuildingType buildingType) const;
bool canAfford(PlayerID player_id, RessourceType ressource, int amount) const;
bool canAfford(Engine::PlayerID player_id, RessourceType ressource, int amount) const;
void build(EntityID player, EntityID tileEntity, BuildingType buildingType);
void addPlayer(PlayerID playerID, std::string name);
void addPlayer(Engine::PlayerID playerID, std::string name);
PlayerID getCurrentPlayer();
PlayerInventory& getPlayerInventory(PlayerID playerID);
Engine::PlayerID getCurrentPlayer();
PlayerInventory& getPlayerInventory(Engine::PlayerID playerID);
void pay(PlayerID uint32, const std::unordered_map<RessourceType, int> & pairs);
void pay(Engine::PlayerID uint32, const std::unordered_map<RessourceType, int> & pairs);
std::optional<BuildingType> getActiveBuilding() const;
void clearActiveBuilding();
void setActiveBuilding(BuildingType buildingType);
size_t getPlayerCount() const;
bool hasTurn(PlayerID playerID, int turn) const;
bool hasTurn(Engine::PlayerID playerID, int turn) const;
bool getCurrentTurnPlayer(int turn) const;
void addResource(PlayerID uint32, RessourceType ressource, int get_storage);
glm::vec3 getColorOfPlayer(PlayerID playerID);
void addResource(Engine::PlayerID uint32, RessourceType ressource, int get_storage);
glm::vec3 getColorOfPlayer(Engine::PlayerID playerID);
void setUpgradeMode(bool upgradeMode);
bool isUpgradeMode() const;
@ -46,7 +46,7 @@ public:
void resetActiveBuilding();
private:
std::unordered_map<PlayerID, Player> players;
std::unordered_map<Engine::PlayerID, Player> players;
std::optional<BuildingType> activeBuilding;
bool upgradeMode = false;

View File

@ -122,7 +122,7 @@ void MapGenerator::assignOwners(EntityManager &entityManager, int numPlayers) {
bool changed = true;
while (changed) {
changed = false;
for (PlayerID player = 0; player < static_cast<uint32_t>(numPlayers); ++player) {
for (Engine::PlayerID player = 0; player < static_cast<uint32_t>(numPlayers); ++player) {
// Finde alle Tiles des Spielers
int ownedCount = 0;
for (TileInfo& tile : allTiles) {

View File

@ -16,7 +16,7 @@
#include "../ecs/components/ProducingComponent.h"
EntityID BuildingFactory::create(EntityManager &em, const BuildingDefinition &def,
const TransformComponent &tileTransform, EntityID tileEntity, PlayerID owner) {
const TransformComponent &tileTransform, EntityID tileEntity, Engine::PlayerID owner) {
EntityID e = em.createEntity();

View File

@ -10,7 +10,7 @@
class BuildingFactory {
public:
static EntityID create(EntityManager& em, const BuildingDefinition& def, const TransformComponent& tileTransform, EntityID tileEntity, PlayerID owner);
static EntityID create(EntityManager& em, const BuildingDefinition& def, const TransformComponent& tileTransform, EntityID tileEntity, Engine::PlayerID owner);
static EntityID createPreview(EntityManager& em, BuildingType buildingType, const TransformComponent& tileTransform, EntityID tileEntity);
};

View File

@ -9,7 +9,7 @@
#include "../ecs/components/TileGameplayComponent.h"
bool BuildingRules::canPlace(const BuildingDefinition &def, const TileGameplayComponent &tile, const GameMode &gameMode,
PlayerID playerID) {
Engine::PlayerID playerID) {
if (tile.hasBuilding()) return false;

View File

@ -10,7 +10,7 @@
class BuildingRules {
public:
static bool canPlace(const BuildingDefinition& def, const TileGameplayComponent& tile, const GameMode& gameMode, PlayerID playerID);
static bool canPlace(const BuildingDefinition& def, const TileGameplayComponent& tile, const GameMode& gameMode, Engine::PlayerID playerID);
};

View File

@ -10,8 +10,8 @@
class OwnerComponent : public Component{
public:
PlayerID playerID;
explicit OwnerComponent(PlayerID playerID) : playerID(playerID) {};
Engine::PlayerID playerID;
explicit OwnerComponent(Engine::PlayerID playerID) : playerID(playerID) {};
};

View File

@ -16,7 +16,7 @@
EntityID BuildPreviewSystem::previewEntity = 0;
void BuildPreviewSystem::updateBuildPreview(EntityManager &em, GameMode &gameMode, PlayerID player, const TurnState &turnState) {
void BuildPreviewSystem::updateBuildPreview(EntityManager &em, GameMode &gameMode, Engine::PlayerID player, const TurnState &turnState) {
if (gameMode.isUpgradeMode() || !gameMode.getActiveBuilding().has_value() || !gameMode.hasTurn(player, turnState.currentTurn)) {
for (EntityID e : em.getAllEntities()) {
const auto tileRenderComponent = em.getComponent<TileRenderComponent>(e);

View File

@ -12,7 +12,7 @@ class EntityManager;
class BuildPreviewSystem {
public:
static void updateBuildPreview(EntityManager& em, GameMode& gameMode, PlayerID player, const TurnState& turnState);
static void updateBuildPreview(EntityManager& em, GameMode& gameMode, Engine::PlayerID player, const TurnState& turnState);
static void disableBuildPreview(EntityManager& em);
private:
static EntityID previewEntity;

View File

@ -21,7 +21,7 @@
#include "../components/UpgradeComponent.h"
#include "GLFW/glfw3.h"
void BuildingPlacementSystem::update(EntityManager& entityManager, GameMode& gameMode, PlayerID player, const TurnState& turnState) {
void BuildingPlacementSystem::update(EntityManager& entityManager, GameMode& gameMode, Engine::PlayerID player, const TurnState& turnState) {
if (!gameMode.hasTurn(player, turnState.currentTurn)) {
return;
}

View File

@ -23,7 +23,7 @@
class AnimationComponent;
class WorldSpriteComponent;
void UpgradeSystem::tryUpdate(EntityManager &em, GameMode &gm, PlayerID player, const TurnState &turnState) {
void UpgradeSystem::tryUpdate(EntityManager &em, GameMode &gm, Engine::PlayerID player, const TurnState &turnState) {
EntityID tileEntityID = SelectionSystem::selectedEntity;
auto tileComponent = em.getComponent<TileGameplayComponent>(tileEntityID);
@ -61,7 +61,7 @@ void UpgradeSystem::tryUpdate(EntityManager &em, GameMode &gm, PlayerID player,
}
void UpgradeSystem::enableUpgradeMode(EntityManager &em, PlayerID player, GameMode& gameMode, const TurnState &turnState) {
void UpgradeSystem::enableUpgradeMode(EntityManager &em, Engine::PlayerID player, GameMode& gameMode, const TurnState &turnState) {
for (EntityID entityID : em.getAllEntities()) {
auto buildingComponent = em.getComponent<BuildingComponent>(entityID);
auto ownerComponent = em.getComponent<OwnerComponent>(entityID);
@ -75,7 +75,7 @@ void UpgradeSystem::enableUpgradeMode(EntityManager &em, PlayerID player, GameMo
}
}
void UpgradeSystem::disableUpgradeMode(EntityManager &em, PlayerID player, GameMode &gameMode) {
void UpgradeSystem::disableUpgradeMode(EntityManager &em, Engine::PlayerID player, GameMode &gameMode) {
for (EntityID entityID : em.getAllEntities()) {
const auto buildingComponent = em.getComponent<BuildingComponent>(entityID);
const auto ownerComponent = em.getComponent<OwnerComponent>(entityID);
@ -89,7 +89,7 @@ void UpgradeSystem::disableUpgradeMode(EntityManager &em, PlayerID player, GameM
}
}
UpgradeResult UpgradeSystem::canUpgrade(EntityManager &em, PlayerID player, GameMode& gameMode, EntityID buildingEntity, const TurnState &turnState) {
UpgradeResult UpgradeSystem::canUpgrade(EntityManager &em, Engine::PlayerID player, GameMode& gameMode, EntityID buildingEntity, const TurnState &turnState) {
if (!gameMode.hasTurn(player, turnState.currentTurn)) return UpgradeResult::NotPlayersTurn;
auto tier = em.getComponent<UpgradeComponent>(buildingEntity);

View File

@ -20,13 +20,13 @@ class EntityManager;
class UpgradeSystem {
public:
static void tryUpdate(EntityManager &em, GameMode &gm, PlayerID player, const TurnState &turnState);
static void enableUpgradeMode(EntityManager &em, PlayerID player, GameMode& gameMode, const TurnState &turnState);
static void disableUpgradeMode(EntityManager &em, PlayerID player, GameMode& gameMode);
static void tryUpdate(EntityManager &em, GameMode &gm, Engine::PlayerID player, const TurnState &turnState);
static void enableUpgradeMode(EntityManager &em, Engine::PlayerID player, GameMode& gameMode, const TurnState &turnState);
static void disableUpgradeMode(EntityManager &em, Engine::PlayerID player, GameMode& gameMode);
private:
static void createWorldSprite(EntityManager &em, EntityID e);
static UpgradeResult canUpgrade(EntityManager &em, PlayerID player, GameMode &gameMode, EntityID buildingEntity, const TurnState &turnState);
static UpgradeResult canUpgrade(EntityManager &em, Engine::PlayerID player, GameMode &gameMode, EntityID buildingEntity, const TurnState &turnState);
};

View File

@ -11,12 +11,13 @@
#include "PlayerInventory.h"
#include "glm/vec3.hpp"
#include "../../engine/core/Types.h"
using PlayerID = std::uint32_t;
class Player {
private:
PlayerID playerID;
Engine::PlayerID playerID;
std::string name;
std::unique_ptr<PlayerInventory> inventory = std::make_unique<PlayerInventory>();
bool isAI = false;
@ -24,7 +25,7 @@ private:
public:
Player() = default;
Player(const PlayerID playerID, std::string name) : playerID(playerID), name(std::move(name)) {
Player(const Engine::PlayerID playerID, std::string name) : playerID(playerID), name(std::move(name)) {
inventory->add(RessourceType::WOOD, 100);
inventory->add(RessourceType::STONE, 178);
};