switch to ECS architecture
This commit is contained in:
@@ -1,28 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
#include <QVector2D>
|
||||
|
||||
#include "EntityId.h"
|
||||
#include "Scrap.h"
|
||||
#include "EcsComponents.h"
|
||||
#include "Tick.h"
|
||||
|
||||
#include "entt/entity/entity.hpp"
|
||||
|
||||
class EntityAdmin;
|
||||
|
||||
struct ScrapInfo
|
||||
{
|
||||
entt::entity entity;
|
||||
QVector2D position;
|
||||
};
|
||||
|
||||
class ScrapSystem
|
||||
{
|
||||
public:
|
||||
explicit ScrapSystem(std::function<EntityId()> allocateId);
|
||||
explicit ScrapSystem(EntityAdmin& admin);
|
||||
|
||||
EntityId spawn(QVector2D position, int amount, Tick despawnAt);
|
||||
void tickDespawn(Tick currentTick);
|
||||
std::optional<Scrap> consume(EntityId id); // removes and returns scrap, or nullopt
|
||||
entt::entity spawn(QVector2D position, int amount, Tick despawnAt);
|
||||
void tickDespawn(Tick currentTick);
|
||||
|
||||
const Scrap* findScrap(EntityId id) const;
|
||||
std::vector<Scrap> allScraps() const;
|
||||
// Removes the scrap and returns its amount, or nullopt if not found.
|
||||
std::optional<int> consume(entt::entity entity);
|
||||
|
||||
// Lightweight snapshot for callers that need to iterate all scrap.
|
||||
std::vector<ScrapInfo> allScrapInfo() const;
|
||||
|
||||
private:
|
||||
std::function<EntityId()> m_allocateId;
|
||||
std::vector<Scrap> m_scraps;
|
||||
EntityAdmin& m_admin;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user