improvements to EntityManagers and Filament APIs (#7302)
* prevent public classes from being created on the stack
- we used to to this by deleting operator delete, but this prevented
the internal "F" classes from being virtual; which can be useful
when using EntityManger::Listener.
now we just make the destructor protected in each class.
- EntityManger::Listener now has a virtual destructor so that
objects could be correctly destroyed from Listener*
* improve EntityManger and Component managers
- all component managers now have the same "base" API
- getComponentCount()
- empty()
- getEntity()
- getEntities()
- Scene now has getEntityCount()
- EntityManager now has getEntityCount()
- all component manager implement gc() the same way, by calling destroy()
- SingleInstanceComponentManager::gc() that calls removeComponent() has
been removed because it's dangerous. removeComponent() is often
not enough, some additional cleanup might be needed.
This commit is contained in:
@@ -22,6 +22,8 @@
|
||||
|
||||
namespace utils {
|
||||
|
||||
EntityManager::Listener::~Listener() noexcept = default;
|
||||
|
||||
EntityManager::EntityManager()
|
||||
: mGens(new uint8_t[RAW_INDEX_COUNT]) {
|
||||
// initialize all the generations to 0
|
||||
@@ -32,8 +34,6 @@ EntityManager::~EntityManager() {
|
||||
delete [] mGens;
|
||||
}
|
||||
|
||||
EntityManager::Listener::~Listener() noexcept = default;
|
||||
|
||||
EntityManager& EntityManager::get() noexcept {
|
||||
// note: we leak the EntityManager because it's more important that it survives everything else
|
||||
// the leak is really not a problem because the process is terminating anyway.
|
||||
@@ -57,6 +57,10 @@ void EntityManager::unregisterListener(EntityManager::Listener* l) noexcept {
|
||||
static_cast<EntityManagerImpl *>(this)->unregisterListener(l);
|
||||
}
|
||||
|
||||
size_t EntityManager::getEntityCount() const noexcept {
|
||||
return static_cast<EntityManagerImpl const *>(this)->getEntityCount();
|
||||
}
|
||||
|
||||
#if FILAMENT_UTILS_TRACK_ENTITIES
|
||||
std::vector<Entity> EntityManager::getActiveEntities() const {
|
||||
return static_cast<EntityManagerImpl const *>(this)->getActiveEntities();
|
||||
|
||||
Reference in New Issue
Block a user