Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

SFML Framerate Problems


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 Silgen   Members   -  Reputation: 178

Like
0Likes
Like

Posted 30 October 2012 - 02:58 AM

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<std::string> deletionList; std::list<std::string>::iterator it; std::map<std::string, cEntity*>::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<std::string, cEntity*>::iterator itr; itr = entityList.find(s); delete itr->second; entityList.erase(s);}[/source]

Does anyone have any idea why this is misbehaving?

Edited by Silgen, 30 October 2012 - 03:01 AM.


Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS