The Partridge Family were neither partridges nor a family. Discuss.
-
MrGodin
- Posts: 721
- Joined: November 30th, 2013, 7:40 pm
- Location: Merville, British Columbia Canada
Post
by MrGodin » December 7th, 2017, 1:45 am
I think i know the relationship between smart pointers and scope. If a container (vector) holds a smart pointer then it is responsible for freeing it ? .. correct ? as in this example.
Code: Select all
void EntityManager::Refresh()
{
for (auto i(0u); i < maxGroups; i++)
{
auto& v(groups[i]);
v.erase(std::remove_if(std::begin(v),std::end(v),
[i](Entity* ent)
{
return !ent->Active() || !ent->HasGroup(i);
}
), std::end(v));
}
entities.erase(std::remove_if(std::begin(entities), std::end(entities),
[](const std::unique_ptr<Entity>& inEnt)
{
return !inEnt->Active();
}), std::end(entities));
}
Curiosity killed the cat, satisfaction brought him back
-
MrGodin
- Posts: 721
- Joined: November 30th, 2013, 7:40 pm
- Location: Merville, British Columbia Canada
Post
by MrGodin » December 7th, 2017, 2:04 am
I love my managers lol
groups hold entities with a particular component
ent->Add<Collider>();// add a collider component to the entity
ent->AddGroup(groupCollider);// add the entity to the group that holds colliders
i made the entity class have a static reference to EntityManager ie:: Entity::SetManager(m_EntityMgr.get()); now all entities have a reference err, pointer to the entity manager so ent->AddGroup(groupCollider) adds the entity to the group which the manager holds
Curiosity killed the cat, satisfaction brought him back
-
albinopapa
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Post
by albinopapa » December 8th, 2017, 12:23 am
Yes, if you have a vector<unique_ptr<Entity>> and you erease an element from the vector, the unique_ptr at that index will have it's destructor called and the memory is freed for you, you do not need to call release or reset() for each removed element. Basically, what you have is fine.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com