Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Run into major slowdown when trying to draw 10+ sprites  (Read 2529 times)

0 Members and 2 Guests are viewing this topic.

The_Mezentine

  • Newbie
  • *
  • Posts: 16
    • View Profile
Run into major slowdown when trying to draw 10+ sprites
« on: January 26, 2012, 12:09:23 am »
So I have a class of ImmobileObjects, each of which has an SFML sprite as a member. They're populated into a vector using something like this:
Code: [Select]
ImmobileVector.push_back(std::shared_ptr<ImmobileObject>(new ImmobileObject(&World, 40, 60, 80, 10, 1)));

And then every loop I iterate like so:
Code: [Select]

for(std::vector<std::shared_ptr<ImmobileObject>>::iterator it = ImmobileVector.begin(); it !=ImmobileVector.end(); it++){

App.Draw((*it)->Sprite);
}


When I have even ten objects to draw I run into major slowdown. It runs fine with just three or four though. Is my general approach just messed up?[/code]

BlueMagic

  • Newbie
  • *
  • Posts: 49
    • View Profile
Run into major slowdown when trying to draw 10+ sprites
« Reply #1 on: January 26, 2012, 01:33:44 am »
I guess it's a pretty standard approach, I don't see why it wouldn't work well. I do the same with normal pointers and a list instead of a vector and it works fine with many sprites (althought I didn't test it well).

Are you sure that's the problem? Maybe you have some other issue. Try running a profiler.

The_Mezentine

  • Newbie
  • *
  • Posts: 16
    • View Profile
Run into major slowdown when trying to draw 10+ sprites
« Reply #2 on: January 26, 2012, 03:29:08 am »
Quote from: "BlueMagic"
I guess it's a pretty standard approach, I don't see why it wouldn't work well. I do the same with normal pointers and a list instead of a vector and it works fine with many sprites (althought I didn't test it well).

Are you sure that's the problem? Maybe you have some other issue. Try running a profiler.

I'm fairly certain that this is the issue since the slowdown scales with the number of objects populating the scene and this is the only iterative process that would vary with object count, but I'll try a profiler

The_Mezentine

  • Newbie
  • *
  • Posts: 16
    • View Profile
Run into major slowdown when trying to draw 10+ sprites
« Reply #3 on: January 28, 2012, 05:49:01 am »
Looks like the version of Visual Studio I'm working in doesn't have a profiler. But my performance jumps right back up to full speed if I cut the contents of the draw loop. For full disclosure, this is what things look like:

Code: [Select]

while (App.IsOpened()){
//stuff

System::Draw(position, App, Player, Mobile, Immobile);

//stuff

}

Code: [Select]

void System::Draw(b2Vec2 position, sf::RenderWindow &App, PlayerObject &Player, std::vector<std::shared_ptr<MobileObject>> &Mobile, std::vector<std::shared_ptr<ImmobileObject>> &Immobile){
position = Player.Body->GetPosition();
Player.Sprite.SetPosition(10*position.x, -(10*position.y));
if(Player.isVisible) App.Draw(Player.Sprite);
for(std::vector<std::shared_ptr<ImmobileObject>>::iterator it = Immobile.begin(); it !=Immobile.end(); it++){
App.Draw((*it)->Sprite);
}
for(std::vector<std::shared_ptr<MobileObject>>::iterator it = Mobile.begin(); it !=Mobile.end(); it++){
position = (*it)->Body->GetPosition();
(*it)->Sprite.SetPosition(10*position.x, -(10*position.y));
App.Draw((*it)->Sprite);
}

}


TheEnigmist

  • Full Member
  • ***
  • Posts: 119
    • View Profile
Run into major slowdown when trying to draw 10+ sprites
« Reply #4 on: January 28, 2012, 03:04:15 pm »
Remember that your game can take long to manage all for (if you have for example 1 milion element)

The_Mezentine

  • Newbie
  • *
  • Posts: 16
    • View Profile
Run into major slowdown when trying to draw 10+ sprites
« Reply #5 on: January 28, 2012, 06:14:29 pm »
Quote from: "TheEnigmist"
Remember that your game can take long to manage all for (if you have for example 1 milion element)

Right, but the problem is I'm running into this with only ten or fifteen elements.

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Run into major slowdown when trying to draw 10+ sprites
« Reply #6 on: January 28, 2012, 06:29:53 pm »
Are you using SFML 1.6 or SGML 2? SFML 1.6 had horrible sprite drawing performance for me.

 

anything