ADD: Minimap

This commit is contained in:
sebastian 2026-02-14 20:52:30 +01:00
parent e7094dd7de
commit 7476719bb2
23 changed files with 411 additions and 6 deletions

View File

@ -202,6 +202,15 @@ add_executable(Dicewars_Siedler src/main.cpp
src/engine/core/EngineTime.h src/engine/core/EngineTime.h
src/game/hexWorld/ecs/systems/CollectResourceSystem.cpp src/game/hexWorld/ecs/systems/CollectResourceSystem.cpp
src/game/hexWorld/ecs/systems/CollectResourceSystem.h src/game/hexWorld/ecs/systems/CollectResourceSystem.h
src/engine/renderer/model/FramebufferObject.cpp
src/engine/renderer/model/FramebufferObject.h
src/engine/renderer/MinimapRenderer.cpp
src/engine/renderer/MinimapRenderer.h
src/engine/renderer/components/MinimapRenderData.h
src/engine/renderer/shaders/MinimapShader.cpp
src/engine/renderer/shaders/MinimapShader.h
src/engine/renderer/model/RenderTargets.cpp
src/engine/renderer/model/RenderTargets.h
) )
target_compile_options(Dicewars_Siedler PRIVATE target_compile_options(Dicewars_Siedler PRIVATE

View File

@ -0,0 +1,9 @@
#version 400 core
uniform vec3 color;
out vec4 fragColor;
void main() {
fragColor = vec4(color, 1.0);
}

View File

@ -0,0 +1,10 @@
#version 400 core
layout(location = 0) in vec3 position;
uniform mat4 transformationMatrix;
uniform mat4 viewProjectionMatrix;
void main() {
gl_Position = viewProjectionMatrix * transformationMatrix * vec4(position, 1.0);
}

View File

@ -15,6 +15,8 @@ void Application::updateTime() {
EngineTime::deltaTime = now - lastFrame; EngineTime::deltaTime = now - lastFrame;
EngineTime::totalTime += EngineTime::deltaTime; EngineTime::totalTime += EngineTime::deltaTime;
lastFrame = now; lastFrame = now;
printf("Frametime: %f\n", EngineTime::deltaTime);
} }
void Application::pushLayer(Layer* layer) { void Application::pushLayer(Layer* layer) {

View File

@ -14,6 +14,7 @@ void RenderSystem::render(EntityManager &entityManager, MasterRenderer &renderer
auto model = entityManager.getComponent<ModelComponent>(id); auto model = entityManager.getComponent<ModelComponent>(id);
auto tileRenderingComponent = entityManager.getComponent<TileRenderComponent>(id); auto tileRenderingComponent = entityManager.getComponent<TileRenderComponent>(id);
auto modelStateComponent = entityManager.getComponent<ModelStateComponent>(id); auto modelStateComponent = entityManager.getComponent<ModelStateComponent>(id);
auto ownerComponent = entityManager.getComponent<OwnerComponent>(id);
auto worldSpriteComponent = entityManager.getComponent<WorldSpriteComponent>(id); auto worldSpriteComponent = entityManager.getComponent<WorldSpriteComponent>(id);
if (modelStateComponent) { if (modelStateComponent) {
@ -27,7 +28,7 @@ void RenderSystem::render(EntityManager &entityManager, MasterRenderer &renderer
} }
if (tileRenderingComponent) { if (tileRenderingComponent) {
renderer.submitTerrainTile(transform, model, tileRenderingComponent); renderer.submitTerrainTile(transform, model, tileRenderingComponent, ownerComponent);
} else { } else {
Entity entity = Entity(model->getActiveModel(), transform->position, transform->rotation.x, transform->rotation.y, transform->rotation.z, transform->scale); Entity entity = Entity(model->getActiveModel(), transform->position, transform->rotation.x, transform->rotation.y, transform->rotation.z, transform->scale);
renderer.submitEntity(std::make_unique<Entity>(entity)); renderer.submitEntity(std::make_unique<Entity>(entity));

View File

@ -29,6 +29,15 @@ void MasterRenderer::render(const Light &light, const Camera &camera) {
worldSpriteRenderer->finalize(); worldSpriteRenderer->finalize();
worldSprites.clear(); worldSprites.clear();
std::unordered_map<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);
colorMapping[3] = glm::vec3(1.0f, 1.0f, 0.0f);
minimapRenderer->render(minimapRenderData, colorMapping);
minimapRenderData.clear();
} }
void MasterRenderer::submitEntity(std::unique_ptr<Entity> entity) { void MasterRenderer::submitEntity(std::unique_ptr<Entity> entity) {
@ -36,11 +45,19 @@ void MasterRenderer::submitEntity(std::unique_ptr<Entity> entity) {
entities[entityModel].push_back(std::move(entity)); entities[entityModel].push_back(std::move(entity));
} }
void MasterRenderer::submitTerrainTile(std::shared_ptr<TransformComponent> transform, std::shared_ptr<ModelComponent> model, std::shared_ptr<TileRenderComponent> terrainTileComponent) { void MasterRenderer::submitTerrainTile(const std::shared_ptr<TransformComponent>& transform,
TerrainRenderingData terrain = TerrainRenderingData(std::move(transform), std::move(model), std::move(terrainTileComponent)); const std::shared_ptr<ModelComponent>& model,
terrainTiles[terrain.modelComponent->getActiveModel().get()].push_back(std::make_unique<TerrainRenderingData>(std::move(terrain))); const std::shared_ptr<TileRenderComponent>& terrainTileComponent,
const std::shared_ptr<OwnerComponent>& owner)
{
auto terrain = std::make_unique<TerrainRenderingData>(transform, model, terrainTileComponent);
terrainTiles[model->getActiveModel().get()].push_back(std::move(terrain));
minimapRenderData.emplace_back(model, transform, owner);
} }
void MasterRenderer::submitWorldSprite( void MasterRenderer::submitWorldSprite(
const std::shared_ptr<TransformComponent>& transform, const std::shared_ptr<TransformComponent>& transform,
const std::shared_ptr<WorldSpriteComponent>& sprite, const std::shared_ptr<WorldSpriteComponent>& sprite,

View File

@ -7,10 +7,12 @@
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include "MinimapRenderer.h"
#include "Renderer.h" #include "Renderer.h"
#include "TerrainRenderer.h" #include "TerrainRenderer.h"
#include "WorldSpriteRenderer.h" #include "WorldSpriteRenderer.h"
#include "../layer/entities/Entity.h" #include "../layer/entities/Entity.h"
#include "model/RenderTargets.h"
#include "model/TexturedModel.h" #include "model/TexturedModel.h"
@ -22,10 +24,12 @@ private:
std::unordered_map<TexturedModel*, std::vector<std::unique_ptr<Entity>>> entities; std::unordered_map<TexturedModel*, std::vector<std::unique_ptr<Entity>>> entities;
std::unordered_map<TexturedModel*, std::vector<std::unique_ptr<TerrainRenderingData>>> terrainTiles; std::unordered_map<TexturedModel*, std::vector<std::unique_ptr<TerrainRenderingData>>> terrainTiles;
std::unordered_map<ModelTexture*, std::vector<WorldSpriteRenderingData>> worldSprites; std::unordered_map<ModelTexture*, std::vector<WorldSpriteRenderingData>> worldSprites;
std::vector<MinimapRenderData> minimapRenderData;
glm::mat4 projectionMatrix; glm::mat4 projectionMatrix;
std::unique_ptr<Renderer> entityRenderer; std::unique_ptr<Renderer> entityRenderer;
std::unique_ptr<TerrainRenderer> terrainRenderer; std::unique_ptr<TerrainRenderer> terrainRenderer;
std::unique_ptr<WorldSpriteRenderer> worldSpriteRenderer; std::unique_ptr<WorldSpriteRenderer> worldSpriteRenderer;
std::unique_ptr<MinimapRenderer> minimapRenderer;
constexpr static float FOV = 70.0f; constexpr static float FOV = 70.0f;
constexpr static float NEAR_PLANE = 0.1f; constexpr static float NEAR_PLANE = 0.1f;
constexpr static float FAR_PLANE = 1000.0f; constexpr static float FAR_PLANE = 1000.0f;
@ -34,15 +38,20 @@ private:
public: public:
MasterRenderer() : projectionMatrix(createProjectionMatrix()), entityRenderer(std::make_unique<Renderer>(projectionMatrix)), MasterRenderer() : projectionMatrix(createProjectionMatrix()), entityRenderer(std::make_unique<Renderer>(projectionMatrix)),
terrainRenderer(std::make_unique<TerrainRenderer>(projectionMatrix)), worldSpriteRenderer(std::make_unique<WorldSpriteRenderer>(projectionMatrix)) terrainRenderer(std::make_unique<TerrainRenderer>(projectionMatrix)), worldSpriteRenderer(std::make_unique<WorldSpriteRenderer>(projectionMatrix)),
minimapRenderer(std::make_unique<MinimapRenderer>(600,400))
{ {
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
glCullFace(GL_BACK); glCullFace(GL_BACK);
RenderTargets::instance().setMinimapTexture(minimapRenderer->getMinimapTexture());
}; };
void render(const Light &light, const Camera &camera); void render(const Light &light, const Camera &camera);
void submitEntity(std::unique_ptr<Entity> entity); void submitEntity(std::unique_ptr<Entity> entity);
void submitTerrainTile(std::shared_ptr<TransformComponent> transform, std::shared_ptr<ModelComponent> model, std::shared_ptr<TileRenderComponent>); void submitTerrainTile(const std::shared_ptr<TransformComponent>& transform, const std::shared_ptr<ModelComponent>& model, const std::shared_ptr<
TileRenderComponent>&, const std::shared_ptr<OwnerComponent>& owner);
void submitWorldSprite(const std::shared_ptr<TransformComponent> &transform, const std::shared_ptr<WorldSpriteComponent> &sprite, const std:: void submitWorldSprite(const std::shared_ptr<TransformComponent> &transform, const std::shared_ptr<WorldSpriteComponent> &sprite, const std::
shared_ptr<ModelTexture> &texture); shared_ptr<ModelTexture> &texture);

View File

@ -0,0 +1,83 @@
//
// Created by sebastian on 14.02.26.
//
#include "MinimapRenderer.h"
#include "../../game/GameMode.h"
#include "../../game/hexWorld/MapGenerator.h"
#include "../core/ECS/ModelComponent.h"
#include "../core/ECS/TransformComponent.h"
#include "../toolbox/MathUtils.h"
#include "glm/ext/matrix_clip_space.hpp"
#include "glm/ext/matrix_transform.hpp"
void MinimapRenderer::render(const std::vector<MinimapRenderData> &renderData, std::unordered_map<PlayerID, glm::vec3> colorMapping) {
minimapFBO->bind();
glViewport(0,0, width, height);
glClear(GL_COLOR_BUFFER_BIT);
glDisable(GL_DEPTH_TEST);
prepareShader();
for (const MinimapRenderData& renderDatum : renderData) {
prepareInstance(renderDatum, colorMapping);
for (const auto& submodel : renderDatum.modelComponent->getActiveModel()->getSubModels()) {
glBindVertexArray(submodel.rawModel->vaoID);
glEnableVertexAttribArray(0);
glDrawElements(GL_TRIANGLES, submodel.rawModel->vertexCount, GL_UNSIGNED_INT, 0);
glDisableVertexAttribArray(0);
glBindVertexArray(0);
}
}
finalizeShader();
minimapFBO->unbind();
glViewport(0,0, Application::getInstance().getWindow().GetWidth(), Application::getInstance().getWindow().GetHeight());
glEnable(GL_DEPTH_TEST);
}
GLuint MinimapRenderer::getMinimapTexture() {
return minimapFBO->getColorTexture();
}
void MinimapRenderer::prepareShader() {
minimapShader.start();
MapBounds bounds = MapGenerator::getMapBounds();
float mapWidth = bounds.maxX - bounds.minX;
float mapHeight = bounds.maxZ - bounds.minZ;
glm::vec3 mapCenter(
bounds.minX + mapWidth * 0.5f,
50.0f,
bounds.minZ + mapHeight * 0.5f
);
glm::mat4 view = glm::lookAt(mapCenter + glm::vec3(0,50,0), mapCenter, glm::vec3(0,0,1));
glm::mat4 proj = glm::ortho(-mapWidth * 0.5f, mapWidth * 0.5f, -mapHeight * 0.5f, mapHeight * 0.5f, -100.f, 100.0f);
minimapShader.loadViewProjectionMatrix(proj * view);
}
void MinimapRenderer::finalizeShader() {
minimapShader.stop();
}
void MinimapRenderer::prepareInstance(const MinimapRenderData &data, const std::unordered_map<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);
auto color = glm::vec3(0.5f);
if (data.owner) {
color = colorMapping.at(data.owner->playerID);
}
minimapShader.loadColor(color);
}

View File

@ -0,0 +1,37 @@
//
// Created by sebastian on 14.02.26.
//
#ifndef DICEWARS_SIEDLER_MINIMAPRENDERER_H
#define DICEWARS_SIEDLER_MINIMAPRENDERER_H
#include <memory>
#include <vector>
#include "../../game/GameMode.h"
#include "components/MinimapRenderData.h"
#include "model/FramebufferObject.h"
#include "shaders/MinimapShader.h"
class MinimapRenderer {
public:
MinimapRenderer(int width, int height): width(width), height(height) {
minimapFBO = std::make_unique<FramebufferObject>(width, height);
}
void render(const std::vector<MinimapRenderData> &renderData, std::unordered_map<PlayerID, glm::vec3> colorMapping);
GLuint getMinimapTexture();
private:
std::unique_ptr<FramebufferObject> minimapFBO;
MinimapShader minimapShader;
int width, height;
void prepareShader();
void finalizeShader();
void prepareInstance(const MinimapRenderData &data, const std::unordered_map<PlayerID, glm::vec3>& colorMapping);
};
#endif //DICEWARS_SIEDLER_MINIMAPRENDERER_H

View File

@ -0,0 +1,17 @@
//
// Created by sebastian on 14.02.26.
//
#ifndef DICEWARS_SIEDLER_MINIMAPRENDERDATA_H
#define DICEWARS_SIEDLER_MINIMAPRENDERDATA_H
#include <memory>
#include "../../../game/hexWorld/ecs/components/TileGameplayComponent.h"
struct MinimapRenderData {
std::shared_ptr<ModelComponent> modelComponent;
std::shared_ptr<TransformComponent> transform;
std::shared_ptr<OwnerComponent> owner;
};
#endif //DICEWARS_SIEDLER_MINIMAPRENDERDATA_H

View File

@ -0,0 +1,9 @@
//
// Created by sebastian on 14.02.26.
//
#include "FramebufferObject.h"
GLuint FramebufferObject::getColorTexture() const {
return colorTextureID;
}

View File

@ -0,0 +1,60 @@
//
// Created by sebastian on 14.02.26.
//
#ifndef DICEWARS_SIEDLER_FRAMEBUFFEROBJECT_H
#define DICEWARS_SIEDLER_FRAMEBUFFEROBJECT_H
#include <stdexcept>
#include "glad/glad.h"
class FramebufferObject {
public:
FramebufferObject(int width, int height, bool withDepth = true) : width(width), height(height) {
// Fbo erzeugen
glGenFramebuffers(1, &fboID);
glBindFramebuffer(GL_FRAMEBUFFER, fboID);
// Color Texture
glGenTextures(1, &colorTextureID);
glBindTexture(GL_TEXTURE_2D, colorTextureID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorTextureID, 0);
if (withDepth) {
glGenRenderbuffers(1, &rboDepthID);
glBindRenderbuffer(GL_RENDERBUFFER, rboDepthID);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rboDepthID);
}
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
throw std::runtime_error("Framebuffer is incomplete!");
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
~FramebufferObject() {
glDeleteFramebuffers(1, &fboID);
glDeleteTextures(1, &colorTextureID);
if (rboDepthID) glDeleteRenderbuffers(1, &rboDepthID);
}
void bind() const { glBindFramebuffer(GL_FRAMEBUFFER, fboID); }
void unbind() const { glBindFramebuffer(GL_FRAMEBUFFER, 0); }
GLuint getColorTexture() const;
private:
GLuint fboID = 0;
GLuint colorTextureID = 0;
GLuint rboDepthID = 0;
int width, height;
};
#endif //DICEWARS_SIEDLER_FRAMEBUFFEROBJECT_H

View File

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

View File

@ -0,0 +1,25 @@
//
// Created by sebastian on 14.02.26.
//
#ifndef DICEWARS_SIEDLER_RENDERTARGETS_H
#define DICEWARS_SIEDLER_RENDERTARGETS_H
#include "glad/glad.h"
class RenderTargets {
public:
static RenderTargets& instance() {
static RenderTargets instance;
return instance;
}
[[nodiscard]] GLuint getMinimapTexture() const {return minimapTexture;}
void setMinimapTexture(const GLuint textureID) {minimapTexture = textureID;}
private:
GLuint minimapTexture = 0;
};
#endif //DICEWARS_SIEDLER_RENDERTARGETS_H

View File

@ -0,0 +1,27 @@
//
// Created by sebastian on 14.02.26.
//
#include "MinimapShader.h"
void MinimapShader::loadTransformationMatrix(const glm::mat4 &matrix) {
ShaderProgram::loadMatrix(location_transformationMatrix, matrix);
}
void MinimapShader::loadViewProjectionMatrix(const glm::mat4 &matrix) {
ShaderProgram::loadMatrix(location_viewProjectionMatrix, matrix);
}
void MinimapShader::loadColor(glm::vec3 color) {
ShaderProgram::loadVector(location_color, color);
}
void MinimapShader::getAllUniformLocations() {
location_color = getUniformLocation("color");
location_transformationMatrix = getUniformLocation("transformationMatrix");
location_viewProjectionMatrix = getUniformLocation("viewProjectionMatrix");
}
void MinimapShader::bindAttributes() const {
bindAttribute(0, "position");
}

View File

@ -0,0 +1,34 @@
//
// Created by sebastian on 14.02.26.
//
#ifndef DICEWARS_SIEDLER_MINIMAPSHADER_H
#define DICEWARS_SIEDLER_MINIMAPSHADER_H
#include "ShaderProgram.h"
class MinimapShader: public ShaderProgram {
public:
MinimapShader() : ShaderProgram(VERTEX_FILE, FRAGMENT_FILE) {
MinimapShader::bindAttributes();
MinimapShader::getAllUniformLocations();
}
void loadTransformationMatrix(const glm::mat4 &matrix);
void loadViewProjectionMatrix(const glm::mat4 &matrix);
void loadColor(glm::vec3 color);
private:
int location_transformationMatrix;
int location_viewProjectionMatrix;
int location_color;
protected:
inline static const std::string VERTEX_FILE = "assets/shaders/minimapVertexShader.glsl";
inline static const std::string FRAGMENT_FILE = "assets/shaders/minimapFragmentShader.glsl";
void getAllUniformLocations() override;
void bindAttributes() const override;
};
#endif //DICEWARS_SIEDLER_MINIMAPSHADER_H

View File

@ -79,4 +79,8 @@ void GameMode::addResource(PlayerID playerID, RessourceType ressource, int amoun
players[playerID].getInventory()->add(ressource, amount); players[playerID].getInventory()->add(ressource, amount);
} }
glm::vec3 GameMode::getColorOfPlayer(PlayerID playerID) {
return players[playerID].getColor();
}

View File

@ -38,6 +38,7 @@ public:
bool getCurrentTurnPlayer(int turn) const; bool getCurrentTurnPlayer(int turn) const;
void addResource(PlayerID uint32, RessourceType ressource, int get_storage); void addResource(PlayerID uint32, RessourceType ressource, int get_storage);
glm::vec3 getColorOfPlayer(PlayerID playerID);
private: private:
std::unordered_map<PlayerID, Player> players; std::unordered_map<PlayerID, Player> players;

View File

@ -14,6 +14,7 @@
#include "../engine/core/gui/uiComponent/UiText.h" #include "../engine/core/gui/uiComponent/UiText.h"
#include "../engine/renderer/loader/Loader.h" #include "../engine/renderer/loader/Loader.h"
#include "../engine/renderer/model/GUITexture.h" #include "../engine/renderer/model/GUITexture.h"
#include "../engine/renderer/model/RenderTargets.h"
#include "hexWorld/events/TurnChangedEvent.h" #include "hexWorld/events/TurnChangedEvent.h"
#include "ui/components/UiInventoryContainer.h" #include "ui/components/UiInventoryContainer.h"
#include "ui/components/UiRessourceWidget.h" #include "ui/components/UiRessourceWidget.h"
@ -92,6 +93,15 @@ void UILayer::onAttach() {
turnTextLabel->setText("Runde: " + std::to_string(event.newTurn)); turnTextLabel->setText("Runde: " + std::to_string(event.newTurn));
}; };
}); });
auto minimapStyle = LayoutStyle();
minimapStyle.width = SizeValue(600, SizeUnit::Pixels);
minimapStyle.height = SizeValue(400.f, SizeUnit::Pixels);
minimapStyle.margin.top = {10.f, SizeUnit::Pixels};
GLuint minimapTextureID = RenderTargets::instance().getMinimapTexture();
auto minimap = std::make_unique<UiImage>(minimapTextureID, minimapStyle);
rootContainer->addChild(std::move(minimap));
} }
void UILayer::onUpdate() { void UILayer::onUpdate() {

View File

@ -12,6 +12,7 @@ struct TileInfo {
}; };
float MapGenerator::hexRadius = 10.0f; float MapGenerator::hexRadius = 10.0f;
MapBounds MapGenerator::mapBounds;
void MapGenerator::init(Loader &loader, float hexRadius) { void MapGenerator::init(Loader &loader, float hexRadius) {
MapGenerator::hexRadius = hexRadius; MapGenerator::hexRadius = hexRadius;
@ -72,6 +73,7 @@ void MapGenerator::generateHexMap(Map &map, int width, int height, EntityManager
} }
assignOwners(entityManager, 2); assignOwners(entityManager, 2);
computeMapBounds(entityManager);
} }
void MapGenerator::assignOwners(EntityManager &entityManager, int numPlayers) { void MapGenerator::assignOwners(EntityManager &entityManager, int numPlayers) {
@ -170,3 +172,18 @@ bool MapGenerator::areHexNeighbors(int q1, int r1, int q2, int r2) {
} }
return false; return false;
} }
MapBounds MapGenerator::getMapBounds() {
return mapBounds;
}
void MapGenerator::computeMapBounds(EntityManager em) {
for (EntityID e : em.getAllEntities()) {
if (auto t = em.getComponent<TransformComponent>(e)) {
mapBounds.minX = std::min(mapBounds.minX, t->position.x);
mapBounds.maxX = std::max(mapBounds.maxX, t->position.x);
mapBounds.minZ = std::min(mapBounds.minZ, t->position.z);
mapBounds.maxZ = std::max(mapBounds.maxZ, t->position.z);
}
}
}

View File

@ -4,6 +4,7 @@
#ifndef MAPGENERATOR_H #ifndef MAPGENERATOR_H
#define MAPGENERATOR_H #define MAPGENERATOR_H
#include <cfloat>
#include <cmath> #include <cmath>
#include <random> #include <random>
@ -18,6 +19,13 @@
#include "ecs/components/TileGameplayComponent.h" #include "ecs/components/TileGameplayComponent.h"
#include "tileGenerator/ForestTileGenerator.h" #include "tileGenerator/ForestTileGenerator.h"
struct MapBounds {
float minX = FLT_MAX;
float maxX = -FLT_MAX;
float minZ = FLT_MAX;
float maxZ = -FLT_MAX;
};
struct MapArea { struct MapArea {
int id; int id;
std::vector<std::pair<int, int>> tiles; std::vector<std::pair<int, int>> tiles;
@ -26,6 +34,8 @@ struct MapArea {
class MapGenerator { class MapGenerator {
private: private:
static float hexRadius; static float hexRadius;
static MapBounds mapBounds;
static void computeMapBounds(EntityManager em);
public: public:
static void init(Loader& loader, float hexRadius); static void init(Loader& loader, float hexRadius);
static void generateHexMap(Map& map, int width, int height, EntityManager& entityManager); static void generateHexMap(Map& map, int width, int height, EntityManager& entityManager);
@ -33,6 +43,8 @@ public:
static void assignOwners(EntityManager &entityManager, int numPlayers); static void assignOwners(EntityManager &entityManager, int numPlayers);
static bool areHexNeighbors(int tile_q, int tile_r, int neighbor_q, int neighbor_r); static bool areHexNeighbors(int tile_q, int tile_r, int neighbor_q, int neighbor_r);
static MapBounds getMapBounds();
private: private:

View File

@ -7,3 +7,7 @@
const std::unique_ptr<PlayerInventory> & Player::getInventory() const { const std::unique_ptr<PlayerInventory> & Player::getInventory() const {
return inventory; return inventory;
} }
glm::vec3 Player::getColor() const {
return color;
}

View File

@ -10,6 +10,7 @@
#include <utility> #include <utility>
#include "PlayerInventory.h" #include "PlayerInventory.h"
#include "glm/vec3.hpp"
using PlayerID = std::uint32_t; using PlayerID = std::uint32_t;
@ -19,6 +20,7 @@ private:
std::string name; std::string name;
std::unique_ptr<PlayerInventory> inventory = std::make_unique<PlayerInventory>(); std::unique_ptr<PlayerInventory> inventory = std::make_unique<PlayerInventory>();
bool isAI = false; bool isAI = false;
glm::vec3 color = glm::vec3(1.0f);
public: public:
Player() = default; Player() = default;
@ -28,6 +30,7 @@ public:
}; };
const std::unique_ptr<PlayerInventory> &getInventory() const; const std::unique_ptr<PlayerInventory> &getInventory() const;
glm::vec3 getColor() const;
}; };