-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
kult::entities() always returns 0 entities #2
Comments
Are you sure about this?
|
Ah because for your test the entities are always in scope. In my use case I'll create the entity in one method, and then try to access all of them in a different method. This causes no live instances to actually exist, just reference to |
Since everything |
Or you could have something like this instead: class EntityManager {
std::vector<kult::entity*> entities;
kult::entity &add();
void del( const kult::entity &);
}
kult::entity &EntityManager::add() {
entities.push_back( new kult::entity );
return *entities.back();
}
void EntityManager::del( const kult::entity &k ) {
entities.erase( std::find(k, entities.begin(), entities.end() );
} |
You dont need N factories to create N type of entites. Example to create different kind of entities with a single factory: EntityManager em;
kult::entity &ent1 = em.add();
kult::entity &ent2 = em.add();
ent1[ position ] = vec2f();
ent2[ shape ] = circle();
assert( kult::entities() == 2 );
em.del( ent1 );
em.del( ent2 );
assert( kult::entities() == 0 ); |
This method of manually adding and removing entities takes away a lot of magic that made your library great! Take a look at my project to see how I'm using the https://github.com/tVoss/AnotherGame Sorry for being the only one create issues in this repo! |
Under the current implementation of
kult::entities()
, nothing is ever returned. My current method for getting all entities (and deleting them) now is looping through all the component types and purging them that way. Hopefully a solution to this can be found.The text was updated successfully, but these errors were encountered: