ADD: Introduce ModelStages to ModelComponent and refactor EntityManager

This commit is contained in:
sebastian 2026-02-14 08:06:19 +01:00
parent 8e5036d402
commit 2d453d05c1
34 changed files with 25943 additions and 174 deletions

View File

@ -74,8 +74,8 @@ add_executable(Dicewars_Siedler src/main.cpp
src/engine/renderer/TerrainRenderer.h src/engine/renderer/TerrainRenderer.h
src/engine/renderer/shaders/TerrainShader.cpp src/engine/renderer/shaders/TerrainShader.cpp
src/engine/renderer/shaders/TerrainShader.h src/engine/renderer/shaders/TerrainShader.h
src/engine/renderer/model/AssetManager.cpp src/engine/renderer/loader/AssetManager.cpp
src/engine/renderer/model/AssetManager.h src/engine/renderer/loader/AssetManager.h
src/game/hexWorld/tileGenerator/HexTileGeneratorStrategy.cpp src/game/hexWorld/tileGenerator/HexTileGeneratorStrategy.cpp
src/game/hexWorld/tileGenerator/HexTileGeneratorStrategy.h src/game/hexWorld/tileGenerator/HexTileGeneratorStrategy.h
src/game/hexWorld/tileGenerator/ForestTileGenerator.cpp src/game/hexWorld/tileGenerator/ForestTileGenerator.cpp
@ -171,11 +171,16 @@ add_executable(Dicewars_Siedler src/main.cpp
src/game/hexWorld/gameplay/TurnSystem.cpp src/game/hexWorld/gameplay/TurnSystem.cpp
src/game/hexWorld/gameplay/TurnSystem.h src/game/hexWorld/gameplay/TurnSystem.h
src/game/hexWorld/gameplay/TurnState.h src/game/hexWorld/gameplay/TurnState.h
src/engine/layer/entities/ModelState.cpp
src/engine/layer/entities/ModelState.h
src/engine/layer/entities/ModelStage.cpp
src/engine/layer/entities/ModelStage.h
src/engine/renderer/model/SubModel.h src/engine/renderer/model/SubModel.h
src/engine/renderer/model/ModelStageConfiguration.cpp
src/engine/renderer/model/ModelStageConfiguration.h
src/engine/renderer/model/ModelStageCondition.h
src/engine/renderer/model/ModelStages.cpp
src/engine/renderer/model/ModelStages.h
src/engine/toolbox/IndexedMap.cpp
src/engine/toolbox/IndexedMap.h
src/engine/core/ECS/ModelStateComponent.cpp
src/engine/core/ECS/ModelStateComponent.h
) )
target_compile_options(Dicewars_Siedler PRIVATE target_compile_options(Dicewars_Siedler PRIVATE
@ -191,6 +196,7 @@ target_include_directories(Dicewars_Siedler PRIVATE
lib/glm lib/glm
lib/stb_image lib/stb_image
lib/tinyobjloader lib/tinyobjloader
lib/nlohmann
) )
target_link_libraries(Dicewars_Siedler target_link_libraries(Dicewars_Siedler

View File

@ -0,0 +1,21 @@
{
"name": "stoneMason",
"allowedTileResources" : ["stone"],
"cost" : {"wood": 15, "stone": 10},
"modelStages": [
{
"name": "stone_mason_empty",
"filename": "stone_mason.obj",
"conditionKey": "fillRatio",
"minValue": 0.0,
"maxValue": 0.5
},
{
"name": "stone_mason_full",
"filename": "stone_mason_full.obj",
"conditionKey": "fillRatio",
"minValue": 0.5,
"maxValue": 1.0
}
]
}

View File

@ -1,6 +1,6 @@
# Blender 5.0.1 # Blender 5.0.1
# www.blender.org # www.blender.org
mtllib stone_masonobj.mtl mtllib stone_mason.mtl
o geometry_0 o geometry_0
v -1.816149 2.851243 0.385599 v -1.816149 2.851243 0.385599
v -1.802683 2.812722 0.365557 v -1.802683 2.812722 0.365557

View File

@ -1,6 +1,6 @@
# Blender 5.0.1 # Blender 5.0.1
# www.blender.org # www.blender.org
mtllib stone_masonobj_full.mtl mtllib stone_mason_full.mtl
o geometry_0 o geometry_0
v -1.816149 2.851243 0.385599 v -1.816149 2.851243 0.385599
v -1.802683 2.812722 0.365557 v -1.802683 2.812722 0.365557

25526
lib/nlohmann/json.hpp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -4,17 +4,17 @@
#include "EntityManager.h" #include "EntityManager.h"
#include <algorithm> #include <algorithm>
#include <ranges>
EntityID EntityManager::createEntity() { EntityID EntityManager::createEntity() {
const EntityID id = nextID++; const EntityID id = nextID++;
entities.push_back(id); entities.push_back(id);
return id; return id;
} }
void EntityManager::destroyEntity(EntityID entity) { void EntityManager::destroyEntity(const EntityID entity) {
entities.erase(std::remove(entities.begin(), entities.end(), entity), entities.end()); std::erase(entities, entity);
transforms.erase(entity); for (auto &compMap: components | std::views::values) {
models.erase(entity); compMap.erase(entity);
tileRenderComponents.erase(entity); }
tileGameplayComponents.erase(entity);
buildings.erase(entity);
} }

View File

@ -6,6 +6,7 @@
#define ENTITYMANAGER_H #define ENTITYMANAGER_H
#include <cstdint> #include <cstdint>
#include <memory> #include <memory>
#include <typeindex>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
@ -26,13 +27,7 @@ private:
EntityID nextID = 1; EntityID nextID = 1;
std::vector<EntityID> entities; std::vector<EntityID> entities;
std::unordered_map<EntityID, std::shared_ptr<TransformComponent>> transforms; std::unordered_map<std::type_index, std::unordered_map<EntityID, std::shared_ptr<Component>>> components;
std::unordered_map<EntityID, std::shared_ptr<ModelComponent>> models;
std::unordered_map<EntityID, std::shared_ptr<TileRenderComponent>> tileRenderComponents;
std::unordered_map<EntityID, std::shared_ptr<TileGameplayComponent>> tileGameplayComponents;
std::unordered_map<EntityID, std::shared_ptr<MapEntityComponent>> mapEntityComponents;
std::unordered_map<EntityID, std::shared_ptr<BuildingComponent>> buildings;
std::unordered_map<EntityID, std::shared_ptr<OwnerComponent>> owners;
public: public:
EntityID createEntity(); EntityID createEntity();
@ -40,51 +35,21 @@ public:
template<typename T> template<typename T>
void addComponent(EntityID entity, std::shared_ptr<T> component) { void addComponent(EntityID entity, std::shared_ptr<T> component) {
if constexpr (std::is_same_v<T, TransformComponent>) { auto& compMap = components[typeid(T)];
transforms[entity] = component; compMap[entity] = component;
} else if constexpr (std::is_same_v<T, ModelComponent>) {
models[entity] = component;
} else if constexpr (std::is_same_v<T, TileRenderComponent>) {
tileRenderComponents[entity] = component;
} else if constexpr (std::is_same_v<T, TileGameplayComponent>) {
tileGameplayComponents[entity] = component;
} else if constexpr (std::is_same_v<T, MapEntityComponent>) {
mapEntityComponents[entity] = component;
} else if constexpr (std::is_same_v<T, BuildingComponent>) {
buildings[entity] = component;
} else if constexpr (std::is_same_v<T, OwnerComponent>) {
owners[entity] = component;
} else {
static_assert(sizeof(T) == 0, "Component-Typ nicht unterstützt");
}
} }
template<typename T> template<typename T>
std::shared_ptr<T> getComponent(EntityID entity) { std::shared_ptr<T> getComponent(EntityID entity) {
if constexpr (std::is_same_v<T, TransformComponent>) { auto it = components.find(typeid(T));
auto it = transforms.find(entity); if (it != components.end()) {
return (it != transforms.end()) ? it->second : nullptr; auto& compMap = it->second;
} else if constexpr (std::is_same_v<T, ModelComponent>) { auto compIt = compMap.find(entity);
auto it = models.find(entity); if (compIt != compMap.end()) {
return (it != models.end()) ? it->second : nullptr; return std::static_pointer_cast<T>(compIt->second);
} else if constexpr (std::is_same_v<T, TileRenderComponent>) { }
auto it = tileRenderComponents.find(entity);
return (it != tileRenderComponents.end()) ? it->second : nullptr;
} else if constexpr (std::is_same_v<T, TileGameplayComponent>) {
auto it = tileGameplayComponents.find(entity);
return (it != tileGameplayComponents.end()) ? it->second : nullptr;
} else if constexpr (std::is_same_v<T, MapEntityComponent>) {
auto it = mapEntityComponents.find(entity);
return (it != mapEntityComponents.end()) ? it->second : nullptr;
} else if constexpr (std::is_same_v<T, BuildingComponent>) {
auto it = buildings.find(entity);
return (it != buildings.end()) ? it->second : nullptr;
} else if constexpr (std::is_same_v<T, OwnerComponent>) {
auto it = owners.find(entity);
return (it != owners.end()) ? it->second : nullptr;
} else {
static_assert(sizeof(T) == 0, "Component-Typ nicht unterstützt");
} }
return nullptr;
} }
const std::vector<EntityID>& getAllEntities() const { return entities; } const std::vector<EntityID>& getAllEntities() const { return entities; }

View File

@ -4,36 +4,43 @@
#ifndef MODELCOMPONENT_H #ifndef MODELCOMPONENT_H
#define MODELCOMPONENT_H #define MODELCOMPONENT_H
#include <iostream>
#include <memory> #include <memory>
#include <utility> #include <utility>
#include "Component.h" #include "Component.h"
#include "../../layer/entities/ModelStage.h" #include "../../renderer/model/ModelStages.h"
#include "../../renderer/model/TexturedModel.h" #include "../../renderer/model/TexturedModel.h"
#include "../../toolbox/IndexedMap.h"
class ModelComponent: public Component { class ModelComponent: public Component {
public: public:
ModelComponent(const std::vector<ModelStage>& stages) : stages(stages) {}; explicit ModelComponent(const ModelStages& modelStages): currentStage(0) {
ModelComponent(std::shared_ptr<TexturedModel> model) { for (const auto& stage : modelStages.getModelStages()) {
activeModel = std::move(model); stages.insert(stage.getStageName(), stage.getModelOfModelStage());
}
};
explicit ModelComponent(std::shared_ptr<TexturedModel> model): currentStage(0) {
stages["default"] = std::move(model);
} }
void updateStage() { void updateStage(const std::string& updatedStage) {
for (const auto& stage : stages) { if (stages.containsKey(updatedStage)) {
if (stage.isActive()) { size_t updatedStageIndex = stages.indexOfKey(updatedStage);
activeModel = stage.model; currentStage = updatedStageIndex;
return; } else {
} std::cerr << "Stage " << updatedStage << " not found!" << std::endl;
} }
} }
[[nodiscard]] std::shared_ptr<TexturedModel> getActiveModel() const { [[nodiscard]] std::shared_ptr<TexturedModel> getActiveModel() const{
return activeModel; return stages.atIndex(currentStage);
} }
private: private:
std::vector<ModelStage> stages; IndexedMap<std::string, std::shared_ptr<TexturedModel>> stages;
std::shared_ptr<TexturedModel> activeModel; size_t currentStage;
}; };

View File

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

View File

@ -0,0 +1,18 @@
//
// Created by sebastian on 14.02.26.
//
#ifndef DICEWARS_SIEDLER_MODELSTATECOMPONENT_H
#define DICEWARS_SIEDLER_MODELSTATECOMPONENT_H
#include <string>
#include "Component.h"
class ModelStateComponent : public Component {
public:
std::unordered_map<std::string, float> params;
};
#endif //DICEWARS_SIEDLER_MODELSTATECOMPONENT_H

View File

@ -9,7 +9,6 @@ void RenderSystem::render(EntityManager &entityManager, MasterRenderer &renderer
auto transform = entityManager.getComponent<TransformComponent>(id); auto transform = entityManager.getComponent<TransformComponent>(id);
auto model = entityManager.getComponent<ModelComponent>(id); auto model = entityManager.getComponent<ModelComponent>(id);
model->updateStage();
auto tileRenderingComponent = entityManager.getComponent<TileRenderComponent>(id); auto tileRenderingComponent = entityManager.getComponent<TileRenderComponent>(id);
if (!transform || !model) continue; if (!transform || !model) continue;

View File

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

View File

@ -1,22 +0,0 @@
//
// Created by sebastian on 13.02.26.
//
#ifndef DICEWARS_SIEDLER_MODELSTAGE_H
#define DICEWARS_SIEDLER_MODELSTAGE_H
#include <functional>
#include <string>
#include "../../renderer/model/TexturedModel.h"
class ModelStage {
public:
std::string name;
std::shared_ptr<TexturedModel> model;
// Trigger-Funktion: Gibt true zurück, wenn dieser State aktiv sein sollte
std::function<bool()> isActive;
};
#endif //DICEWARS_SIEDLER_MODELSTAGE_H

View File

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

View File

@ -1,22 +0,0 @@
//
// Created by sebastian on 13.02.26.
//
#ifndef DICEWARS_SIEDLER_MODELSTATE_H
#define DICEWARS_SIEDLER_MODELSTATE_H
#include <functional>
#include <string>
class ModelState {
public:
std::string name;
std::string modelPath;
std::string texturePath;
// Trigger-Function: Returns true when this state should be active
std::function<bool()> isActive;
};
#endif //DICEWARS_SIEDLER_MODELSTATE_H

View File

@ -0,0 +1,80 @@
//
// Created by sebastian on 08.02.26.
//
#include "AssetManager.h"
#include <cassert>
#include <filesystem>
#include <fstream>
#include <utility>
#include "json.hpp"
#include "OBJLoader.h"
namespace fs = std::filesystem;
using namespace nlohmann;
std::shared_ptr<TexturedModel> AssetManager::loadModel(const std::string &name, const std::string &objPath, const std::string &texturePath, Loader &loader) {
if (models.contains(name)) {
return models[name];
}
auto model = OBJLoader::loadModel(objPath, texturePath, loader);
models[name] = model;
return model;
}
std::shared_ptr<TexturedModel> AssetManager::getModel(const std::string &name) {
assert(models.contains(name) && "Model not found!");
return models.at(name);
}
void AssetManager::insertGeneratedModel(const std::string &name, std::shared_ptr<TexturedModel> model) {
assert(!models.contains(name) && "Model already exists!");
models[name] = std::move(model);
}
void AssetManager::loadAsset(const std::string &assetPath, Loader &loader) {
json assetConfiguration = readJsonFile(assetPath);
ModelStages modelStages;
std::string baseDir = std::filesystem::path(assetPath).parent_path().string();
for (const auto& modelStage : assetConfiguration["modelStages"]) {
auto name = modelStage["name"].get<std::string>();
auto objPath = modelStage["filename"].get<std::string>();
const auto conditionKey = modelStage["conditionKey"].get<std::string>();
const float min = modelStage["minValue"].get<float>();
const float max = modelStage["maxValue"].get<float>();
std::filesystem::path fullObjPath = std::filesystem::path(baseDir) / std::filesystem::path(objPath);
const std::shared_ptr<TexturedModel> model = loadModel(name, fullObjPath, "", loader);
const auto condition = ModelStageCondition(conditionKey, min, max);
modelStages.addModelStage(ModelStageConfiguration(model, name, condition));
}
modelsWithStages[assetConfiguration["name"].get<std::string>()] = std::make_shared<ModelStages>(modelStages);
}
std::shared_ptr<ModelStages> AssetManager::getModelStages(const std::string &modelName) {
if (modelsWithStages.contains(modelName)) {
return modelsWithStages[modelName];
}
return nullptr;
}
std::shared_ptr<ModelStageConfiguration> AssetManager::getModelStageConfiguration(const std::string &modelName, const std::string &stageName) {
if (const auto modelStages = getModelStages(modelName)) {
return std::make_shared<ModelStageConfiguration>(modelStages->getModelStageConfiguration(stageName));
}
return nullptr;
}
json AssetManager::readJsonFile(const std::string &path) {
if (fs::exists(path)) {
std::ifstream filestream(path);
json j;
filestream >> j;
return j;
}
return json::object();
}

View File

@ -7,8 +7,10 @@
#include <memory> #include <memory>
#include <unordered_map> #include <unordered_map>
#include "TexturedModel.h" #include "json.hpp"
#include "../loader/Loader.h" #include "../model/TexturedModel.h"
#include "Loader.h"
#include "../model/ModelStages.h"
class AssetManager { class AssetManager {
@ -16,8 +18,14 @@ public:
static std::shared_ptr<TexturedModel> loadModel(const std::string& name, const std::string& objPath, const std::string& texturePath, Loader& loader); static std::shared_ptr<TexturedModel> loadModel(const std::string& name, const std::string& objPath, const std::string& texturePath, Loader& loader);
static std::shared_ptr<TexturedModel> getModel(const std::string& name); static std::shared_ptr<TexturedModel> getModel(const std::string& name);
static void insertGeneratedModel(const std::string& name, std::shared_ptr<TexturedModel> model); static void insertGeneratedModel(const std::string& name, std::shared_ptr<TexturedModel> model);
static void loadAsset(const std::string& assetPath, Loader& loader);
static std::shared_ptr<ModelStages> getModelStages(const std::string& modelName);
static std::shared_ptr<ModelStageConfiguration> getModelStageConfiguration(const std::string& modelName, const std::string& stageName);
private: private:
static inline std::unordered_map<std::string, std::shared_ptr<TexturedModel>> models; static inline std::unordered_map<std::string, std::shared_ptr<TexturedModel>> models;
static inline std::unordered_map<std::string, std::shared_ptr<ModelStages>> modelsWithStages;
static nlohmann::json readJsonFile(const std::string &path);
}; };

View File

@ -1,31 +0,0 @@
//
// Created by sebastian on 08.02.26.
//
#include "AssetManager.h"
#include <cassert>
#include <utility>
#include "../loader/OBJLoader.h"
std::shared_ptr<TexturedModel> AssetManager::loadModel(const std::string &name, const std::string &objPath, const std::string &texturePath, Loader &loader) {
if (models.contains(name)) {
return models[name];
}
auto model = OBJLoader::loadModel(objPath, texturePath, loader);
models[name] = model;
return model;
}
std::shared_ptr<TexturedModel> AssetManager::getModel(const std::string &name) {
assert(models.contains(name) && "Model not found!");
return models.at(name);
}
void AssetManager::insertGeneratedModel(const std::string &name, std::shared_ptr<TexturedModel> model) {
assert(!models.contains(name) && "Model already exists!");
models[name] = std::move(model);
}

View File

@ -0,0 +1,15 @@
//
// Created by sebastian on 14.02.26.
//
#ifndef DICEWARS_SIEDLER_MODELSTAGECONDITION_H
#define DICEWARS_SIEDLER_MODELSTAGECONDITION_H
#include <string>
struct ModelStageCondition {
std::string key;
float min;
float max;
};
#endif //DICEWARS_SIEDLER_MODELSTAGECONDITION_H

View File

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

View File

@ -0,0 +1,28 @@
//
// Created by sebastian on 14.02.26.
//
#ifndef DICEWARS_SIEDLER_MODELSTAGECONFIGURATION_H
#define DICEWARS_SIEDLER_MODELSTAGECONFIGURATION_H
#include <memory>
#include <vector>
#include "ModelStageCondition.h"
#include "TexturedModel.h"
class ModelStageConfiguration {
public:
ModelStageConfiguration() = default;
ModelStageConfiguration(std::shared_ptr<TexturedModel> modelOfModelStage, std::string stageName, ModelStageCondition condition) : modelOfModelStage(std::move(modelOfModelStage)), stageName(std::move(stageName)), condition(std::move(condition)) {};
[[nodiscard]] std::shared_ptr<TexturedModel> getModelOfModelStage() const {return modelOfModelStage;}
[[nodiscard]] const std::string& getStageName() const {return stageName;}
[[nodiscard]] const ModelStageCondition& getCondition() const {return condition;}
private:
std::shared_ptr<TexturedModel> modelOfModelStage;
std::string stageName;
ModelStageCondition condition;
};
#endif //DICEWARS_SIEDLER_MODELSTAGECONFIGURATION_H

View File

@ -0,0 +1,26 @@
//
// Created by sebastian on 14.02.26.
//
#include "ModelStages.h"
#include <ranges>
void ModelStages::addModelStage(const ModelStageConfiguration &modelStage) {
modelStages[modelStage.getStageName()] = modelStage;
}
std::vector<ModelStageConfiguration> ModelStages::getModelStages() const {
std::vector<ModelStageConfiguration> result;
for (const auto &modelStage: this->modelStages | std::views::values) {
result.push_back(modelStage);
}
return result;
}
ModelStageConfiguration &ModelStages::getModelStageConfiguration(const std::string &name) {
if (modelStages.contains(name)) {
return modelStages.at(name);
}
throw std::runtime_error("ModelStage not found!");
}

View File

@ -0,0 +1,29 @@
//
// Created by sebastian on 14.02.26.
//
#ifndef DICEWARS_SIEDLER_MODELSTAGES_H
#define DICEWARS_SIEDLER_MODELSTAGES_H
#include <unordered_map>
#include <vector>
#include "ModelStageConfiguration.h"
class ModelStages {
public:
explicit ModelStages(std::vector<ModelStageConfiguration> modelStages);
ModelStages() = default;
void addModelStage(const ModelStageConfiguration &modelStage);
[[nodiscard]] std::vector<ModelStageConfiguration> getModelStages() const;
ModelStageConfiguration &getModelStageConfiguration(const std::string &name);
private:
std::unordered_map<std::string, ModelStageConfiguration> modelStages;
};
#endif //DICEWARS_SIEDLER_MODELSTAGES_H

View File

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

View File

@ -0,0 +1,99 @@
//
// Created by sebastian on 14.02.26.
//
#ifndef DICEWARS_SIEDLER_INDEXEDMAP_H
#define DICEWARS_SIEDLER_INDEXEDMAP_H
#include <vector>
#include <utility>
#include <stdexcept>
#include <algorithm>
template<typename Key, typename Value>
class IndexedMap {
public:
[[nodiscard]] size_t size() const {return data.size();}
Value& atIndex(size_t index) {
if (index >= data.size()) throw std::out_of_range("Index out of range");
return data[index].second;
}
const Value& atIndex(const size_t index) const {
if (index >= data.size()) throw std::out_of_range("Index out of range");
return data[index].second;
}
// Zugriff über Key
Value& atKey(const Key& key) {
auto it = findKey(key);
if (it == data.end()) throw std::out_of_range("Key not found");
return it->second;
}
const Value& atKey(const Key& key) const {
auto it = findKey(key);
if (it == data.end()) throw std::out_of_range("Key not found");
return it->second;
}
// Optional: wie Map operator[]
Value& operator[](const Key& key) {
auto it = findKey(key);
if (it != data.end()) return it->second;
// Key noch nicht vorhanden -> hinzufügen
data.emplace_back(key, Value{});
return data.back().second;
}
// Einfügen oder Überschreiben
void insert(const Key& key, const Value& value) {
auto it = findKey(key);
if (it != data.end()) {
it->second = value; // überschreiben
} else {
data.emplace_back(key, value);
}
}
void insert(Key&& key, Value&& value) {
auto it = findKey(key);
if (it != data.end()) {
it->second = std::move(value);
} else {
data.emplace_back(std::move(key), std::move(value));
}
}
// Zugriff auf Keys (optional)
const Key& keyAt(size_t index) const {
if (index >= data.size()) throw std::out_of_range("Index out of range");
return data[index].first;
}
bool containsKey(const Key& key) const {
return findKey(key) != data.end();
}
size_t indexOfKey(const Key& key) const {
auto it = findKey(key);
if (it == data.end()) throw std::out_of_range("Key not found");
return std::distance(data.begin(), it);
}
private:
std::vector<std::pair<Key, Value>> data;
auto findKey(const Key& key) {
return std::find_if(data.begin(), data.end(),
[&key](const auto& p) {return p.first == key;});
}
auto findKey(const Key& key) const {
return std::find_if(data.begin(), data.end(),
[&key](const auto& p) {return p.first == key;});
}
};
#endif //DICEWARS_SIEDLER_INDEXEDMAP_H

View File

@ -11,7 +11,7 @@
#include "../engine/renderer/textures/ModelTexture.h" #include "../engine/renderer/textures/ModelTexture.h"
#include "../engine/toolbox/MathUtils.h" #include "../engine/toolbox/MathUtils.h"
#include "../engine/layer/entities/Light.h" #include "../engine/layer/entities/Light.h"
#include "../engine/renderer/model/AssetManager.h" #include "../engine/renderer/loader/AssetManager.h"
#include "hexWorld/HexModelFactory.h" #include "hexWorld/HexModelFactory.h"
#include "hexWorld/MapGenerator.h" #include "hexWorld/MapGenerator.h"
@ -65,12 +65,18 @@ void GameLayer::onAttach()
entityManager->addComponent(entityID, transformComponent); entityManager->addComponent(entityID, transformComponent);
entityManager->addComponent(entityID, modelComponent);*/ entityManager->addComponent(entityID, modelComponent);*/
auto test = AssetManager::loadModel("test", "assets/buildings/stone_mason/stone_masonobj_full.obj", "assets/buildings/stone_mason/textures/stone_mason.png", loader);
AssetManager::loadAsset("assets/buildings/stone_mason/stone_mason.json", loader);
auto modelStages = AssetManager::getModelStages("stoneMason");
auto transformComponent = std::make_shared<TransformComponent>(glm::vec3(0,0,0), glm::vec3(0), 1.f); auto transformComponent = std::make_shared<TransformComponent>(glm::vec3(0,0,0), glm::vec3(0), 1.f);
auto modelComponent = std::make_shared<ModelComponent>(test); auto modelComponent = std::make_shared<ModelComponent>(*modelStages);
modelComponent->updateStage("stone_mason_empty");
EntityID entityID = entityManager->createEntity(); EntityID entityID = entityManager->createEntity();
entityManager->addComponent(entityID, transformComponent); entityManager->addComponent(entityID, transformComponent);
entityManager->addComponent(entityID, modelComponent); entityManager->addComponent(entityID, modelComponent);
testEntity = entityID;
} }
void GameLayer::onDetach() void GameLayer::onDetach()
@ -98,6 +104,11 @@ void GameLayer::onUpdate()
turnSystem->nextTurn(*turnState, Application::getInstance().getEventBus()); turnSystem->nextTurn(*turnState, Application::getInstance().getEventBus());
} }
if (InputManager::isKeyPressed(GLFW_KEY_U)) {
auto model_component = entityManager->getComponent<ModelComponent>(testEntity);
model_component->updateStage("stone_mason_full");
}
camera->move(moveDir, 0.5f); camera->move(moveDir, 0.5f);
tileHighlightSystem->update(*entityManager, *mousePicker, *camera); tileHighlightSystem->update(*entityManager, *mousePicker, *camera);

View File

@ -48,6 +48,8 @@ private:
std::unique_ptr<Map> map; std::unique_ptr<Map> map;
std::unique_ptr<TurnSystem> turnSystem = std::make_unique<TurnSystem>(); std::unique_ptr<TurnSystem> turnSystem = std::make_unique<TurnSystem>();
std::unique_ptr<TurnState> turnState = std::make_unique<TurnState>(); std::unique_ptr<TurnState> turnState = std::make_unique<TurnState>();
EntityID testEntity;
}; };

View File

@ -12,7 +12,7 @@
#include "../../engine/core/ECS/ModelComponent.h" #include "../../engine/core/ECS/ModelComponent.h"
#include "../../engine/core/ECS/TileRenderComponent.h" #include "../../engine/core/ECS/TileRenderComponent.h"
#include "../../engine/core/ECS/TransformComponent.h" #include "../../engine/core/ECS/TransformComponent.h"
#include "../../engine/renderer/model/AssetManager.h" #include "../../engine/renderer/loader/AssetManager.h"
#include "../../engine/toolbox/Random.h" #include "../../engine/toolbox/Random.h"
#include "ecs/components/MapEntityComponent.h" #include "ecs/components/MapEntityComponent.h"
#include "ecs/components/TileGameplayComponent.h" #include "ecs/components/TileGameplayComponent.h"

View File

@ -6,7 +6,7 @@
#include "../../../engine/core/ECS/ModelComponent.h" #include "../../../engine/core/ECS/ModelComponent.h"
#include "../../../engine/core/ECS/TransformComponent.h" #include "../../../engine/core/ECS/TransformComponent.h"
#include "../../../engine/renderer/model/AssetManager.h" #include "../../../engine/renderer/loader/AssetManager.h"
EntityID BuildingFactory::create(EntityManager &em, const BuildingDefinition &def, EntityID BuildingFactory::create(EntityManager &em, const BuildingDefinition &def,
const TransformComponent &tileTransform, EntityID tileEntity, PlayerID owner) { const TransformComponent &tileTransform, EntityID tileEntity, PlayerID owner) {

View File

@ -12,7 +12,7 @@ enum class BuildingType {
}; };
class BuildingComponent { class BuildingComponent : public Component {
public: public:
BuildingType type; BuildingType type;

View File

@ -6,8 +6,7 @@
#define MAPENTITYCOMPONENT_H #define MAPENTITYCOMPONENT_H
class MapEntityComponent: public Component {};
struct MapEntityComponent {};

View File

@ -10,7 +10,7 @@
#include "../../../../engine/core/ECS/TileRenderComponent.h" #include "../../../../engine/core/ECS/TileRenderComponent.h"
#include "../../../../engine/core/ECS/TransformComponent.h" #include "../../../../engine/core/ECS/TransformComponent.h"
#include "../../../../engine/platform/glfw/InputManager.h" #include "../../../../engine/platform/glfw/InputManager.h"
#include "../../../../engine/renderer/model/AssetManager.h" #include "../../../../engine/renderer/loader/AssetManager.h"
#include "../../building/BuildingConfig.h" #include "../../building/BuildingConfig.h"
#include "../../building/BuildingFactory.h" #include "../../building/BuildingFactory.h"
#include "../../building/BuildingRules.h" #include "../../building/BuildingRules.h"

View File

@ -6,7 +6,7 @@
#include "../../../engine/core/ECS/ModelComponent.h" #include "../../../engine/core/ECS/ModelComponent.h"
#include "../../../engine/core/ECS/TransformComponent.h" #include "../../../engine/core/ECS/TransformComponent.h"
#include "../../../engine/renderer/model/AssetManager.h" #include "../../../engine/renderer/loader/AssetManager.h"
#include "glm/detail/func_geometric.inl" #include "glm/detail/func_geometric.inl"