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

Author Topic: Improving performance on Netbook  (Read 7312 times)

0 Members and 2 Guests are viewing this topic.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Improving performance on Netbook
« Reply #15 on: January 27, 2010, 08:49:10 am »
You still didn't understand my solution ;)

I suggested that you precompute and store one sf::Sprite instance per tile, not a single instance for all of them.

Then, instead of storing the color in colorLookup[mapArray[n][m].screenTile.color], you can directly change the sprite's color when it changes.
Laurent Gomila - SFML developer

mongrol

  • Newbie
  • *
  • Posts: 29
    • View Profile
Improving performance on Netbook
« Reply #16 on: January 27, 2010, 09:52:00 am »
Ah I have it. Then when the tile changes, I simply change the sprite's image pointer.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Improving performance on Netbook
« Reply #17 on: January 27, 2010, 10:36:06 am »
Yeah, same for any of the sprite's attribute (color, position, ...). So that in your drawing function you just have to... draw ;)

If it's still too slow we can talk about other improvements.
Laurent Gomila - SFML developer

mongrol

  • Newbie
  • *
  • Posts: 29
    • View Profile
Improving performance on Netbook
« Reply #18 on: January 27, 2010, 12:46:07 pm »
Righty. I now have a nested vector of sprites created once. THen every frame I iterate and draw them. GetFrameTime() shows an average of 0.35 per frame so around 2-3fps.

Code: [Select]

void GfxEngine::createMap(std::vector<std::vector<Terrain> >& mapArray)
{
// this is called once
    mapSprites.resize(MAPHEIGHT);
    for (int i=0; i<MAPHEIGHT; i++){
        mapSprites[i].resize(MAPWIDTH);
    };
for (int n=0; n < MAPHEIGHT; n++){
for (int m=0; m < MAPWIDTH; m++){
   sf::Sprite tileSprite;
            tileSprite.SetImage(tileImage);
tileSprite.SetPosition(m*TILEWIDTH,n*TILEHEIGHT);
tileSprite.SetColor(colorLookup[mapArray[n][m].screenTile.color]);
   mapSprites[n][m]=tileSprite;
        }
    }
}

void GfxEngine::renderMap()
{
// this is called every frame
for (int n=0; n < MAPHEIGHT; n++){
for (int m=0; m < MAPWIDTH; m++){
m_mainWindow.Draw(mapSprites[n][m]);
}
}
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Improving performance on Netbook
« Reply #19 on: January 27, 2010, 12:53:38 pm »
How many FPS do you get if you don't call the renderMap() function (just to know how much we can optimize)?

I currently see two solutions for optimizing further:
- if not all the sprites are visible on screen, you can try to avoid drawing those that are hidden
- try SFML 2
Laurent Gomila - SFML developer

mongrol

  • Newbie
  • *
  • Posts: 29
    • View Profile
Improving performance on Netbook
« Reply #20 on: January 27, 2010, 09:25:11 pm »
If I turn off renderMap then the only thing that is drawing is the overlay. This is drawing 3 players (squad based game) which are drawn using last weeks sf::String method. It now shows 0.04 with GetFrameTime so over 20fps. I'll change this routine to sprites as well.

SFML2 isn't an option until a Mac version shows up. I'll implement delta's on the map, get rid of any legacy sf::String stuff, further optimise my own bit of the pipe and it'll probably be acceptable. My main aim at this point is to have the netbook good enough to develop on, rather than actually have users play the game on it.

It would be interesting to see how see how it runs on Windows7 which this machine dual boots with. I'd not be surprised to find some Intel/XOrg driver issues here as well.

Thanks very much for your patience and help Laurent.

 

anything