Original Post
For some reason, the framerate in my game is behaving strangely. I'm just testing things at the moment - so all that is on the screen are the tiles and some collectible items. Sometimes the game will start with a laggy framerate, and then return to normal after collecting the items. Sometimes it will be normal until I move, and collecting the items will resolve it again. Sometimes it will be normal until I collect the items.
I don't really understand why it isn't at least behaving consistently.
This is the function called every frame to check for collisions between an entity 'e' and other non-tile entities. At the moment I'm not doing a broadphase check, as there aren't any off screen items.
[source lang="cpp"]void cEntityManager::calculateCollisions(cEntity* e) {
std::list deletionList;
std::list::iterator it;
std::map::iterator itr;
for(itr=entityList.begin(); itr != entityList.end(); ++itr){
if(e != itr->second && ( getIntersectionX(getPathRectX(*e), itr->second->getBoundingBox()) ||
getIntersectionY(getPathRectY(*e), itr->second->getBoundingBox() ))) {
if(e->handleCollision(itr->second) == 1) {
deletionList.insert(deletionList.end(), itr->first);
}
}
}
if(deletionList.size() != 0) {
for(it = deletionList.begin(); it != deletionList.end(); ++it) {
itr = entityList.find(it->data());
removeItem(itr->first);
}
}
}[/source]
Then the removal function, which will remove the items from the std::map
[source lang="cpp"]void cEntityManager::removeItem(std::string s) {
std::map::iterator itr;
itr = entityList.find(s);
delete itr->second;
entityList.erase(s);
}[/source]
Does anyone have any idea why this is misbehaving?
I don't really understand why it isn't at least behaving consistently.
This is the function called every frame to check for collisions between an entity 'e' and other non-tile entities. At the moment I'm not doing a broadphase check, as there aren't any off screen items.
[source lang="cpp"]void cEntityManager::calculateCollisions(cEntity* e) {
std::list
std::list
std::map
for(itr=entityList.begin(); itr != entityList.end(); ++itr){
if(e != itr->second && ( getIntersectionX(getPathRectX(*e), itr->second->getBoundingBox()) ||
getIntersectionY(getPathRectY(*e), itr->second->getBoundingBox() ))) {
if(e->handleCollision(itr->second) == 1) {
deletionList.insert(deletionList.end(), itr->first);
}
}
}
if(deletionList.size() != 0) {
for(it = deletionList.begin(); it != deletionList.end(); ++it) {
itr = entityList.find(it->data());
removeItem(itr->first);
}
}
}[/source]
Then the removal function, which will remove the items from the std::map
[source lang="cpp"]void cEntityManager::removeItem(std::string s) {
std::map
itr = entityList.find(s);
delete itr->second;
entityList.erase(s);
}[/source]
Does anyone have any idea why this is misbehaving?