55 lines
1.1 KiB
C++
55 lines
1.1 KiB
C++
#pragma once
|
|
|
|
#include "Craft/Common.h"
|
|
#include "Craft/ComponentManager.h"
|
|
#include <vector>
|
|
|
|
namespace craft {
|
|
|
|
class EEntity;
|
|
|
|
class WWorld {
|
|
public:
|
|
WWorld();
|
|
virtual ~WWorld();
|
|
virtual void Begin();
|
|
virtual void Tick(float deltaTime);
|
|
virtual void FixedTick();
|
|
|
|
inline bool HasBegun() const { return mHasBegun; }
|
|
|
|
////////// ENTITIES
|
|
entId GetNextEntityId();
|
|
void Reset();
|
|
EEntity &GetEntity(entId id);
|
|
|
|
template <typename T>
|
|
entId SpawnEntity();
|
|
void DestroyEntity(entId id);
|
|
size_t GetTotalEntities();
|
|
|
|
template <typename T>
|
|
ComponentManager<T> &GetComponentManager() {
|
|
static ComponentManager<T> manager;
|
|
return manager;
|
|
}
|
|
|
|
private:
|
|
bool mHasBegun;
|
|
Dict<entId, unique<EEntity>> mEntities;
|
|
std::vector<unique<EEntity>> mPendingEntities;
|
|
|
|
////////// Static
|
|
entId sNextEntityId;
|
|
};
|
|
|
|
////////// IMPLEMENTATIONS
|
|
|
|
template <typename T>
|
|
unsigned int WWorld::SpawnEntity() {
|
|
auto &entity = mPendingEntities.emplace_back(std::make_unique<T>());
|
|
return entity->Id;
|
|
}
|
|
|
|
} // namespace craft
|