Added basics of the ECS world's life cycle
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
#define GUARD_TOURMALINE_ECS_H
|
#define GUARD_TOURMALINE_ECS_H
|
||||||
#include <any>
|
#include <any>
|
||||||
#include <format>
|
#include <format>
|
||||||
|
#include <stack>
|
||||||
#include <typeindex>
|
#include <typeindex>
|
||||||
|
|
||||||
#include "../Containers/DualkeyMap.hpp"
|
#include "../Containers/DualkeyMap.hpp"
|
||||||
@@ -24,6 +25,9 @@ class World;
|
|||||||
|
|
||||||
class World {
|
class World {
|
||||||
public:
|
public:
|
||||||
|
// ====== World controls ======
|
||||||
|
void Step();
|
||||||
|
|
||||||
// ======== Entities ========
|
// ======== Entities ========
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Entity CreateEntity();
|
Entity CreateEntity();
|
||||||
@@ -75,9 +79,13 @@ private:
|
|||||||
|
|
||||||
// All of this is done so entities are not disabled during the
|
// All of this is done so entities are not disabled during the
|
||||||
// run of the systems
|
// run of the systems
|
||||||
std::vector<std::pair<Components::Enabled *, bool>> entitiesToDisable;
|
std::stack<std::pair<Components::Enabled *, bool>> entitiesToDisable;
|
||||||
// Oh here comes the jank
|
// Oh here comes the jank
|
||||||
friend void Components::Enabled::setEnabled(bool);
|
friend void Components::Enabled::setEnabled(bool);
|
||||||
|
|
||||||
|
// ======== Life-cycle ========
|
||||||
|
void preSystems();
|
||||||
|
void postSystems();
|
||||||
};
|
};
|
||||||
} // namespace Tourmaline::Systems::ECS
|
} // namespace Tourmaline::Systems::ECS
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -15,6 +15,26 @@
|
|||||||
using namespace Tourmaline::Systems;
|
using namespace Tourmaline::Systems;
|
||||||
using namespace ECS;
|
using namespace ECS;
|
||||||
|
|
||||||
|
void World::Step() {
|
||||||
|
preSystems();
|
||||||
|
// Actual systems will happen here
|
||||||
|
postSystems();
|
||||||
|
}
|
||||||
|
|
||||||
|
void World::preSystems() {
|
||||||
|
// Defined for future use
|
||||||
|
}
|
||||||
|
|
||||||
|
void World::postSystems() {
|
||||||
|
// Can't do a foreach with a std::stack
|
||||||
|
while (!entitiesToDisable.empty()) {
|
||||||
|
std::pair<Components::Enabled *, bool> &request = entitiesToDisable.top();
|
||||||
|
request.first->enabled = request.second;
|
||||||
|
entitiesToDisable.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Entities
|
||||||
Entity World::CreateEntity() {
|
Entity World::CreateEntity() {
|
||||||
auto newEntity = Random::GenerateUUID();
|
auto newEntity = Random::GenerateUUID();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user