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

Author Topic: Better FPS drawing 10.000 sprite  (Read 10534 times)

0 Members and 1 Guest are viewing this topic.

Ptlomej

  • Newbie
  • *
  • Posts: 48
    • ICQ Messenger - 353167418
    • View Profile
    • Local
Better FPS drawing 10.000 sprite
« Reply #15 on: March 11, 2012, 07:47:06 pm »
i draw about 100*random(100,500) Sprites with a little trick and high performance :)

TheEnigmist

  • Full Member
  • ***
  • Posts: 119
    • View Profile
Better FPS drawing 10.000 sprite
« Reply #16 on: March 11, 2012, 08:50:31 pm »
Quote from: "Ptlomej"
i draw about 100*random(100,500) Sprites with a little trick and high performance :)

Can you explain how or it's a secret? :)

Ptlomej

  • Newbie
  • *
  • Posts: 48
    • ICQ Messenger - 353167418
    • View Profile
    • Local
Better FPS drawing 10.000 sprite
« Reply #17 on: March 11, 2012, 10:00:39 pm »
Here and example :)

i have an Area 1000x1000.
I create now 100 sf::Images

Code: [Select]

for(int x = 0; x != 100; x++){
    sf::Image *Chunk = new sf::Image;
    Chunk->Create(1000,1000);
}


Then i add all the Objects that are on this area schould be with
Code: [Select]

Chunk->Copy(Exampleimage,X,Y,IntRect(0,0,Exampleimage.GetWidth(),Exampleimage.GetHeight()),true);


then convert to the sprites and add too sprite list
Code: [Select]
Texture *tChunk = new Texture;
tChunk->LoadFromImage(Chunk,IntRect(0,0,1000,1000));
Sprite *sChunk = new sf::Sprite(*tChunk);
sChunk->SetOrigin(0,0);
sChunk->SetPosition(sf::Vector2f((float)xCount,(float)yCount));
BackgroundChunks.push_back(sChunk);


generate new position for the next "chunk"
Code: [Select]
xCount += 1000;
xCounter++;
if(xCount == 5000){
xCount = -5000;
yCount += 1000;
xCounter = 0;
yCounter++;
}


and then Draw the 100 Sprites
Code: [Select]
for(list<sf::Sprite*>::iterator IT = BackgroundChunks.begin(); IT != BackgroundChunks.end(); IT++){
_RenderWindow->Draw(**IT);
}


its very simple ;)

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Better FPS drawing 10.000 sprite
« Reply #18 on: March 12, 2012, 11:56:42 am »
Ptolemaj, why are you using pointers and new? There's no reason, just use std::vector<sf::Sprite> or std::vector<sf::Texture>. It's even faster, since not every sprite/texture is allocated on its own. Same applies for the usage of vector instead of list. And avoiding manual memory management is simpler and less error-prone.

And why don't you directly have a sf::Texture with the needed sub-rects?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Mjonir

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Better FPS drawing 10.000 sprite
« Reply #19 on: March 12, 2012, 09:21:15 pm »
Just a word on SFML performance in drawing a lot of sprites:

I have a benchmark for my engines that creates 500 animated objects, each with an independent and quite complex (voluntarily unoptimized! It could easily be!) move sequence that is computed in Lua. I get about 35 FPS.  A simpler move sequence gives me around 110 FPS.

I was curious so I programmed a little profiling lib today and checked where the horsepower was going:

- 95% of the time is spent calculating the next frame.
- Which means only 5% of the frame is spent drawing.
- Out of the 95%, about 1 or 2% is checking keyboard/mouse/window events
- I'd say 2% for the engine itself (collision detection, etc.)
- 90% spent computing the move sequences (it's sequential, unoptimized, very complex and goes through a Lua interpreter, but still that's the kind of complexity you could easily get for a "whole city" above :)).

Even better, I have an option on my engine that separates the update from display, and thus on a dual core display doesn't even matter at all.

That's to say: Don't worry too much about drawing lots of sprites, that's maybe not your bottleneck thanks to SFML.

mateandmetal

  • Full Member
  • ***
  • Posts: 171
  • The bird is the word
    • View Profile
    • my blog
Better FPS drawing 10.000 sprite
« Reply #20 on: March 13, 2012, 12:10:08 am »
Quote from: "Ptlomej"

Code: [Select]

for(int x = 0; x != 100; x++){
    sf::Image *Chunk = new sf::Image;
    Chunk->Create(1000,1000);
}


I see memory leaks  :lol:

Btw..What about using tilemaps for the city? Drawing a tilemap using VertexArray is very fast
- Mate (beverage) addict
- Heavy metal addict _lml
- SFML 2 addict
- My first (and free) game: BichingISH!

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Better FPS drawing 10.000 sprite
« Reply #21 on: March 13, 2012, 06:45:21 pm »
I agree with Mjonir. You also have to make sure you are compiling with the right features, e.g. release mode. Also start without debugger (even in release mode), it can make a huge difference, especially for dynamic allocations. Also, some STL implementations use error checks that need to be disabled manually.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

TheEnigmist

  • Full Member
  • ***
  • Posts: 119
    • View Profile
Better FPS drawing 10.000 sprite
« Reply #22 on: March 13, 2012, 08:07:52 pm »
Quote from: "Nexus"
I agree with Mjonir. You also have to make sure you are compiling with the right features, e.g. release mode. Also start without debugger (even in release mode), it can make a huge difference, especially for dynamic allocations. Also, some STL implementations use error checks that need to be disabled manually.


Is it a good idea to disable STL error checks? Do they take much memory to check errors?

drifton

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Re: Better FPS drawing 10.000 sprite
« Reply #23 on: March 29, 2012, 01:41:32 pm »
two things that will greatly improve tiles on today's hardware,  vba/vbo and texture atlas/ ie compiling all your sprites and tiles into one texture/image,

steps process map to determine number of quads needed for background, fringes , transitions, buildings, ect...

apply uv that reference the tile image in the atlas/tilesheet what ever you really want to call it

draw base tile/fringe vbos
draw objects (characters, chests, npc's , enemies)  vbo
draw cover tile vbo
done

even with alpha blendening you are looking at very few triangles being drawn for today'a hardware
point in case 1920x1080 screen filled with 16x16 tiles with 4 layers = 32,400 tiles per frame or ~ 3.89 million triangles per-second and even the old geforce 2 could draw ~25 million triangles per second



and that really is all brute force with out you dropping the tiles in the 3 top layers that are not drawn out of the vertex buffer and in most cases are just empty space in my game and i actually have several smaller buffer so that it's easier on me to just update tiles like water animation every few frames / characters

 

anything