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

Author Topic: Problem with tiles and performance  (Read 4420 times)

0 Members and 1 Guest are viewing this topic.

Glenn

  • Newbie
  • *
  • Posts: 12
    • View Profile
Problem with tiles and performance
« on: December 03, 2008, 10:16:27 am »
Ok so I use this function to draw tiles to my screen:

Code: [Select]
for(i = 0; i < 40; i++)
{
for(j = 0; j < 20; j++)
{
int tileId = 0;
currentTile.SetImage(tilesImage);
tileId = gameMap[i][j].tileId;

currentRect.Left =  32 * tileId;
currentRect.Right = 32 + 32 * tileId;
currentRect.Top = 0;
currentRect.Bottom = 32;
currentTile.SetSubRect(currentRect);


currentTile.SetPosition(32 * i, 32 * j);

App.Draw(currentTile);
}
}


On my laptop when I run the game it runs fine, but on my desktop, which is considerably better than my laptop, I get about 1/3 of the fps.

I've narrowed it down to this bit of code right here.
Why does it run so slow on my desktop? and is there a better way of drawing tiles to the screen?

Edit: Upon further inspection the App.Draw(currentTile); is whats slowing everything down, is there any way to fix it?

bullno1

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
Problem with tiles and performance
« Reply #1 on: December 03, 2008, 01:56:43 pm »
40*20=800 tiles which is 1600 tris. This is not a huge number. It even runs fine on your laptop so I think maybe your desktop has a poor OpenGL driver.

Quote
is there a better way of drawing tiles to the screen?

Your implementation is quite OK. There's a faster way though: You can use hardware vertex buffer and hardware index. But that's an overkill in this case.

efeXor

  • Newbie
  • *
  • Posts: 10
    • MSN Messenger - Steam:BrokenGlassX
    • View Profile
Problem with tiles and performance
« Reply #2 on: December 04, 2008, 06:44:33 am »
Try updating your opengl driver  :wink:

Glenn

  • Newbie
  • *
  • Posts: 12
    • View Profile
Problem with tiles and performance
« Reply #3 on: December 04, 2008, 07:16:23 am »
I just updated it and its still the same. I found a fix that's working for me though.

 
Code: [Select]
 for(i = 0; i < 40; i++)
      {
         for(j = 0; j < 20; j++)
         {
            if(!gameMap.tileId == 0)
           {
            int tileId = 0;
            currentTile.SetImage(tilesImage);
            tileId = gameMap[i][j].tileId;

            currentRect.Left =  32 * tileId;
            currentRect.Right = 32 + 32 * tileId;
            currentRect.Top = 0;
            currentRect.Bottom = 32;
            currentTile.SetSubRect(currentRect);
           
           
            currentTile.SetPosition(32 * i, 32 * j);
           
            App.Draw(currentTile);  
           }
         }
      }


That if statement prevents invisible tiles from being drawn[/code]

Wizzard

  • Full Member
  • ***
  • Posts: 213
    • View Profile
Problem with tiles and performance
« Reply #4 on: December 04, 2008, 09:40:11 am »
You can try using multiple sprites to draw each tile, rather than using one sprite to draw each tile, in order to further increase execution speed, at the cost of memory.

This can be accomplished by either using separate sprites for each tile, or, optimally, by using separate sprites for each frame in the sprite sheet.

prchakal

  • Full Member
  • ***
  • Posts: 142
    • View Profile
Problem with tiles and performance
« Reply #5 on: December 14, 2008, 02:48:36 pm »
I have the same performance problem here:

http://www.sfml-dev.org/forum/viewtopic.php?t=816&highlight=performance

In my game in SDL i do it easy , with the same logic and with floors, and this problem dont exists.

The problem is on DRAW method, too many DRAW call cause it.

Where is the problem? SFML ? Me and the author of this post? The creator?

I try the same with on a new pc, on SVN release, and the problem is the same.

 

anything