UPD: Make Gamesystems static and move their orchestration to GameWorldSystems
This commit is contained in:
parent
373fb34ea0
commit
1b4cc8ef89
@ -260,6 +260,8 @@ add_executable(Dicewars_Siedler src/main.cpp
|
||||
src/game/hexWorld/ecs/systems/BuildPreviewSystem.h
|
||||
src/game/hexWorld/ecs/components/BuildingPreviewComponent.cpp
|
||||
src/game/hexWorld/ecs/components/BuildingPreviewComponent.h
|
||||
src/game/GameWorldSystems.cpp
|
||||
src/game/GameWorldSystems.h
|
||||
)
|
||||
|
||||
target_compile_options(Dicewars_Siedler PRIVATE
|
||||
|
||||
@ -17,13 +17,11 @@ struct KeyboardIntent {
|
||||
|
||||
class GameInputUser : public InputUser {
|
||||
public:
|
||||
GameInputUser(TileHighlightSystem& highlightSystem,
|
||||
EntityManager& em,
|
||||
GameInputUser(EntityManager& em,
|
||||
MousePicker& picker,
|
||||
Camera& camera,
|
||||
GameMode& gameMode)
|
||||
: highlightSystem(highlightSystem),
|
||||
em(em),
|
||||
:em(em),
|
||||
picker(picker),
|
||||
camera(camera),
|
||||
gameMode(gameMode) {}
|
||||
@ -32,13 +30,10 @@ public:
|
||||
if (!isMouseEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
highlightSystem.update(em, picker, camera, gameMode);
|
||||
}
|
||||
|
||||
KeyboardIntent processKeyboard();
|
||||
private:
|
||||
TileHighlightSystem& highlightSystem;
|
||||
EntityManager& em;
|
||||
MousePicker& picker;
|
||||
Camera& camera;
|
||||
|
||||
@ -74,7 +74,7 @@ void GameLayer::onAttach()
|
||||
ProducingSystem::onTurnEnded(*entityManager);
|
||||
});
|
||||
|
||||
gameInputUser = std::make_unique<GameInputUser>(*tileHighlightSystem, *entityManager, *mousePicker, *camera, *gameMode);
|
||||
gameInputUser = std::make_unique<GameInputUser>(*entityManager, *mousePicker, *camera, *gameMode);
|
||||
Application::getInstance().stateManager->registerMouseUser(gameInputUser.get(), {StateRegistry::get().game});
|
||||
|
||||
events.subscribe<BuildingTypeSelectEvent>([this](const BuildingTypeSelectEvent& event) {
|
||||
@ -100,7 +100,7 @@ void GameLayer::onUpdate()
|
||||
}
|
||||
|
||||
if (intent.nextTurn) {
|
||||
turnSystem->nextTurn(*turnState, Application::getInstance().getEventBus());
|
||||
worldSystems->onTurnEnd(*entityManager, *gameMode, *turnState);
|
||||
}
|
||||
|
||||
if (intent.toggleUpgrade) {
|
||||
@ -120,18 +120,7 @@ void GameLayer::onUpdate()
|
||||
}
|
||||
|
||||
AnimationSystem::update(*entityManager, EngineTime::totalTime);
|
||||
if (gameInputUser->isMouseEnabled()) {
|
||||
tileHighlightSystem->update(*entityManager, *mousePicker, *camera, *gameMode);
|
||||
BuildPreviewSystem::updateBuildPreview(*entityManager, *gameMode, gameMode->getCurrentPlayer(), *turnState);
|
||||
SelectionSystem::update(*entityManager, *gameInputUser, *mousePicker);
|
||||
if (gameMode->isUpgradeMode()) {
|
||||
UpgradeSystem::tryUpdate(*entityManager, *gameMode, gameMode->getCurrentPlayer(), *turnState);
|
||||
}
|
||||
} else {
|
||||
tileHighlightSystem->reset(*entityManager);
|
||||
}
|
||||
buildingPlacementSystem->update(*entityManager, *gameMode, 0, *turnState);
|
||||
CollectResourceSystem::update(*entityManager, *gameMode);
|
||||
worldSystems->update(*entityManager, *gameMode, *mousePicker, *camera, *gameInputUser, *turnState);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
|
||||
#ifndef DICEWARS_SIEDLER_GAMELAYER_H
|
||||
#define DICEWARS_SIEDLER_GAMELAYER_H
|
||||
#include "GameWorldSystems.h"
|
||||
#include "../engine/core/ECS/RenderSystem.h"
|
||||
#include "../engine/core/inputsOutputs/stateControl/inputUser/GameInputUser.h"
|
||||
#include "../engine/layer/Layer.h"
|
||||
@ -42,17 +43,15 @@ private:
|
||||
std::vector<std::shared_ptr<Entity>> mapEntities;
|
||||
std::vector<std::shared_ptr<Entity>> entities;
|
||||
|
||||
std::unique_ptr<TileHighlightSystem> tileHighlightSystem = std::make_unique<TileHighlightSystem>();
|
||||
std::unique_ptr<BuildingPlacementSystem> buildingPlacementSystem = std::make_unique<BuildingPlacementSystem>();
|
||||
std::unique_ptr<EntityManager> entityManager = std::make_unique<EntityManager>();
|
||||
|
||||
std::unique_ptr<Map> map;
|
||||
std::unique_ptr<TurnSystem> turnSystem = std::make_unique<TurnSystem>();
|
||||
std::unique_ptr<TurnState> turnState = std::make_unique<TurnState>();
|
||||
|
||||
std::unique_ptr<GameInputUser> gameInputUser;
|
||||
|
||||
EntityID testEntity;
|
||||
|
||||
std::unique_ptr<GameWorldSystems> worldSystems;
|
||||
};
|
||||
|
||||
|
||||
|
||||
33
src/game/GameWorldSystems.cpp
Normal file
33
src/game/GameWorldSystems.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
//
|
||||
// Created by sebastian on 17.04.26.
|
||||
//
|
||||
|
||||
#include "GameWorldSystems.h"
|
||||
|
||||
#include "hexWorld/ecs/systems/BuildingPlacementSystem.h"
|
||||
#include "hexWorld/ecs/systems/BuildPreviewSystem.h"
|
||||
#include "hexWorld/ecs/systems/CollectResourceSystem.h"
|
||||
#include "hexWorld/ecs/systems/ProducingSystem.h"
|
||||
#include "hexWorld/ecs/systems/SelectionSystem.h"
|
||||
#include "hexWorld/ecs/systems/UpgradeSystem.h"
|
||||
#include "hexWorld/gameplay/TurnSystem.h"
|
||||
|
||||
void GameWorldSystems::update(EntityManager &em, GameMode &gm, MousePicker &mp, const Camera &cam, GameInputUser &gameInputUser, const TurnState &turnState) {
|
||||
if (gameInputUser.isMouseEnabled()) {
|
||||
TileHighlightSystem::update(em, mp, cam, gm);
|
||||
BuildPreviewSystem::updateBuildPreview(em, gm, gm.getCurrentPlayer(), turnState);
|
||||
SelectionSystem::update(em, gameInputUser, mp);
|
||||
if (gm.isUpgradeMode()) {
|
||||
UpgradeSystem::tryUpdate(em, gm, gm.getCurrentPlayer(), turnState);
|
||||
}
|
||||
BuildingPlacementSystem::update(em, gm, gm.getCurrentPlayer(), turnState);
|
||||
CollectResourceSystem::update(em, gm);
|
||||
} else {
|
||||
TileHighlightSystem::reset(em);
|
||||
}
|
||||
}
|
||||
|
||||
void GameWorldSystems::onTurnEnd(EntityManager& em, GameMode& gm, TurnState& turnState) {
|
||||
ProducingSystem::onTurnEnded(em);
|
||||
TurnSystem::nextTurn(turnState, Application::getInstance().getEventBus());
|
||||
}
|
||||
26
src/game/GameWorldSystems.h
Normal file
26
src/game/GameWorldSystems.h
Normal file
@ -0,0 +1,26 @@
|
||||
//
|
||||
// Created by sebastian on 17.04.26.
|
||||
//
|
||||
|
||||
#ifndef DICEWARS_SIEDLER_GAMEWORLDSYSTEMS_H
|
||||
#define DICEWARS_SIEDLER_GAMEWORLDSYSTEMS_H
|
||||
#include "../engine/core/inputsOutputs/stateControl/inputUser/GameInputUser.h"
|
||||
#include "../engine/platform/glfw/MousePicker.h"
|
||||
|
||||
class EntityManager;
|
||||
class GameMode;
|
||||
class MousePicker;
|
||||
class Camera;
|
||||
class GameInputUser;
|
||||
struct TurnState;
|
||||
|
||||
|
||||
class GameWorldSystems {
|
||||
public:
|
||||
void update(EntityManager& em, GameMode& gm, MousePicker& mp, const Camera& cam, GameInputUser& gameInputUser, const TurnState& turnState);
|
||||
void onTurnEnd(EntityManager& em, GameMode& gm, TurnState& turnState);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //DICEWARS_SIEDLER_GAMEWORLDSYSTEMS_H
|
||||
@ -11,7 +11,7 @@
|
||||
|
||||
class BuildingPlacementSystem {
|
||||
public:
|
||||
void update(EntityManager &entityManager, GameMode &gameMode, EntityID player, const TurnState &turnState);
|
||||
static void update(EntityManager &entityManager, GameMode &gameMode, EntityID player, const TurnState &turnState);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -12,10 +12,10 @@ class Camera;
|
||||
|
||||
class TileHighlightSystem {
|
||||
public:
|
||||
void update(EntityManager &entityManager, const MousePicker &picker, const Camera &camera, GameMode& gameMode);
|
||||
void reset(EntityManager& entityManager);
|
||||
static void update(EntityManager &entityManager, const MousePicker &picker, const Camera &camera, GameMode& gameMode);
|
||||
static void reset(EntityManager& entityManager);
|
||||
private:
|
||||
bool intersectTile(const glm::vec3 & rayOrigin, const glm::vec3 & rayDirection, glm::vec3 worldPos, float hexRadius, glm::vec3 &interectionPoint);
|
||||
static bool intersectTile(const glm::vec3 & rayOrigin, const glm::vec3 & rayDirection, glm::vec3 worldPos, float hexRadius, glm::vec3 &interectionPoint);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
|
||||
class TurnSystem {
|
||||
public:
|
||||
void nextTurn(TurnState& turn, EventBus& events);
|
||||
static void nextTurn(TurnState& turn, EventBus& events);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user