UPD: Refactor Building System
This commit is contained in:
parent
42a1e89bee
commit
fffc799447
@ -79,6 +79,8 @@ add_executable(Dicewars_Siedler src/main.cpp
|
|||||||
src/game/hexWorld/tileGenerator/ForestTileGenerator.h
|
src/game/hexWorld/tileGenerator/ForestTileGenerator.h
|
||||||
src/engine/toolbox/Random.cpp
|
src/engine/toolbox/Random.cpp
|
||||||
src/engine/toolbox/Random.h
|
src/engine/toolbox/Random.h
|
||||||
|
src/game/TileInteractionSystem.cpp
|
||||||
|
src/game/TileInteractionSystem.h
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(Dicewars_Siedler PRIVATE
|
target_include_directories(Dicewars_Siedler PRIVATE
|
||||||
|
|||||||
@ -67,38 +67,22 @@ void GameLayer::onUpdate()
|
|||||||
renderer->submitEntity(entity.get());
|
renderer->submitEntity(entity.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (HexTile& tile : map->tiles) {
|
tileInteractionSystem->update(*map, *camera, *mousePicker);
|
||||||
glm::vec3 intersectionPoint;
|
tileInteractionSystem->handleBuildAction(*map);
|
||||||
bool highlight = tile.intersect(camera->getPosition(), mousePicker->getCurrentRay(), intersectionPoint);
|
|
||||||
tile.isHighlighted = highlight;
|
|
||||||
|
|
||||||
if (tile.isHighlighted) {
|
|
||||||
if (InputManager::isMouseButtonPressed(GLFW_MOUSE_BUTTON_1)) {
|
|
||||||
//On this tile you should build something
|
|
||||||
if (!tile.building && tile.resourceType == RessourceType::WOOD) {
|
|
||||||
tile.entitiesOnTile.clear();
|
|
||||||
tile.building = std::make_shared<Entity>(AssetManager::getModel("cabin"), tile.worldPos, 0,0,0,1.f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto& entity: tile.entitiesOnTile) {
|
|
||||||
renderer->submitEntity(entity.get());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tile.building) {
|
|
||||||
renderer->submitEntity(tile.building.get());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
std::vector<HexRenderData> terrainRenderData = map->getTerrainRenderData(hexModelDefault, hexModelWood, hexModelStone);
|
std::vector<HexRenderData> terrainRenderData = map->getTerrainRenderData(hexModelDefault, hexModelWood, hexModelStone);
|
||||||
|
|
||||||
|
|
||||||
for (auto& renderData : terrainRenderData) {
|
for (auto& renderData : terrainRenderData) {
|
||||||
renderer->submitTerrainTile(&renderData);
|
renderer->submitTerrainTile(&renderData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (HexTile& tile : map->tiles) {
|
||||||
|
for (const auto& entity : tile.entitiesOnTile) {
|
||||||
|
renderer->submitEntity(entity.get());
|
||||||
|
}
|
||||||
|
if (tile.building) renderer->submitEntity(tile.building.get());
|
||||||
|
}
|
||||||
|
|
||||||
renderer->render(*light, *camera);
|
renderer->render(*light, *camera);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#ifndef DICEWARS_SIEDLER_GAMELAYER_H
|
#ifndef DICEWARS_SIEDLER_GAMELAYER_H
|
||||||
#define DICEWARS_SIEDLER_GAMELAYER_H
|
#define DICEWARS_SIEDLER_GAMELAYER_H
|
||||||
|
#include "TileInteractionSystem.h"
|
||||||
#include "../engine/layer/Layer.h"
|
#include "../engine/layer/Layer.h"
|
||||||
#include "../engine/platform/glfw/MousePicker.h"
|
#include "../engine/platform/glfw/MousePicker.h"
|
||||||
#include "../engine/renderer/Renderer.h"
|
#include "../engine/renderer/Renderer.h"
|
||||||
@ -37,6 +38,7 @@ private:
|
|||||||
|
|
||||||
std::vector<std::shared_ptr<Entity>> mapEntities;
|
std::vector<std::shared_ptr<Entity>> mapEntities;
|
||||||
std::vector<std::shared_ptr<Entity>> entities;
|
std::vector<std::shared_ptr<Entity>> entities;
|
||||||
|
std::unique_ptr<TileInteractionSystem> tileInteractionSystem = std::make_unique<TileInteractionSystem>();
|
||||||
std::unique_ptr<Map> map;
|
std::unique_ptr<Map> map;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
30
src/game/TileInteractionSystem.cpp
Normal file
30
src/game/TileInteractionSystem.cpp
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
//
|
||||||
|
// Created by sebastian on 08.02.26.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "TileInteractionSystem.h"
|
||||||
|
|
||||||
|
#include "../engine/layer/entities/Camera.h"
|
||||||
|
#include "../engine/platform/glfw/InputManager.h"
|
||||||
|
#include "../engine/renderer/model/AssetManager.h"
|
||||||
|
#include "GLFW/glfw3.h"
|
||||||
|
|
||||||
|
void TileInteractionSystem::update(Map &map, const Camera &camera, const MousePicker &mousePicker) {
|
||||||
|
for (HexTile& tile : map.tiles) {
|
||||||
|
glm::vec3 intersectionPoint;
|
||||||
|
tile.isHighlighted = tile.intersect(camera.getPosition(), mousePicker.getCurrentRay(), intersectionPoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void TileInteractionSystem::handleBuildAction(Map &map) {
|
||||||
|
for (HexTile& tile : map.tiles) {
|
||||||
|
if (tile.isHighlighted && InputManager::isMouseButtonPressed(GLFW_MOUSE_BUTTON_1)) {
|
||||||
|
if (!tile.building && tile.resourceType == RessourceType::WOOD) {
|
||||||
|
tile.entitiesOnTile.clear();
|
||||||
|
tile.building = std::make_shared<Entity>(AssetManager::getModel("cabin"), tile.worldPos, 0,0,0,1.f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
19
src/game/TileInteractionSystem.h
Normal file
19
src/game/TileInteractionSystem.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
//
|
||||||
|
// Created by sebastian on 08.02.26.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef TILEINTERACTIONSYSTEM_H
|
||||||
|
#define TILEINTERACTIONSYSTEM_H
|
||||||
|
#include "../engine/platform/glfw/MousePicker.h"
|
||||||
|
#include "hexWorld/Map.h"
|
||||||
|
|
||||||
|
|
||||||
|
class TileInteractionSystem {
|
||||||
|
public:
|
||||||
|
void update(Map& map, const Camera& camera, const MousePicker& mousePicker);
|
||||||
|
void handleBuildAction(Map& map);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif //TILEINTERACTIONSYSTEM_H
|
||||||
Loading…
Reference in New Issue
Block a user