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

Author Topic: Problems rendering TileMaps  (Read 1879 times)

0 Members and 1 Guest are viewing this topic.

Digot

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Problems rendering TileMaps
« on: August 01, 2014, 08:23:12 pm »
Hello!

I have a Tilemap that is 5 by 5 big and has 64 by 64 big Tiles!

I'm using .tmx maps with tmxparser lib and i have only 2 FPS.

Also at when the map ends there are still buggy grass tiles. What's the problem there? . Btw that's the only thing I'm rendering right now.

Image: http://imgur.com/NoIUBbi (2 is the FPS counted by Fraps)

void DrawMap(){
        IntRect cropRect;
        for (int i = 0; i < testmap->map.layerCollection.size(); ++i)
        {
                tmxparser::TmxLayer layer = testmap->map.layerCollection[i];
                int currTile = 0;
                for (int y = 0; y < layer.width; y++)
                {
                        for (int x = 0; x < layer.height; x++)
                        {
                                if (layer.tiles[currTile].gid > 0){
                                        tmxparser::TmxTileset currTileset = testmap->map.tilesetCollection[layer.tiles[currTile].tilesetIndex];

                                       
                                        int tileIndex = layer.tiles[currTile].gid - currTileset.firstgid;
                                        cropRect.left = (tileIndex % (currTileset.image.width / 64)) * 64;
                                        cropRect.top = (tileIndex / (currTileset.image.width / 64)) * 64;
                                        cropRect.width = currTileset.tileWidth;
                                        cropRect.height = currTileset.tileHeight;

               
                                        VertexArray v(sf::Quads,4);
                                        v[0].position = Vector2f(x * 64, y * 64);
                                        v[1].position = Vector2f((x + 64) * 64, y * 64);
                                        v[2].position = Vector2f((x + 64) * 64, (y + 64) * 64);
                                        v[3].position = Vector2f(x * 64, (y + 64) * 64);

                                        v[0].texCoords = Vector2f(cropRect.left * 64, cropRect.top * 64);
                                        v[1].texCoords = Vector2f((64 + cropRect.left) * 64, cropRect.top * 64);
                                        v[2].texCoords = Vector2f((64 + cropRect.left) * 64, (64 + cropRect.top) * 64);
                                        v[3].texCoords = Vector2f(cropRect.left * 64, (64 + cropRect.top) * 64);

                                        window->draw(v, &currTileset.image.texture);
                                       
                                }
                                currTile++;
                                printf("Tile %i \n", currTile);
                        }

                }
                currTile = 0;
        }
}

Please help :)


Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Problems rendering TileMaps
« Reply #1 on: August 02, 2014, 12:12:19 am »
I can't see anything in this code that could particularly slow down your tiny map.
The only thing I can see it being is the TMX thingy you have. Can you try this without using TMX (e.g. make a static version) and see if the FPS are still low?

Also, imgur is down so I can't see your image :(
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Digot

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Problems rendering TileMaps
« Reply #2 on: August 02, 2014, 12:16:25 am »
Hi!

Thanks for your answer.

I think it's because I'm doing those loops on each Draw call instead of just doing it once and saving it to a costum class so i only have to call it through one loop.

But instead of that i'll do it like the tutorial (http://www.sfml-dev.org/tutorials/2.0/graphics-vertex-array.php) showed.

I think it will perform much better.

Thanks!

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Problems rendering TileMaps
« Reply #3 on: August 02, 2014, 01:26:45 am »
Calling draw 25 times (5 x 5 tiles, right?) would not cause massive delays, especially with such small tiles.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Digot

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Problems rendering TileMaps
« Reply #4 on: August 02, 2014, 10:19:31 am »
Yeah that was only a small test map.

Also each map has layers. And the tiles are 64 x 64 not 5x5.

5x5 was the Map Size (*64) i took to test the framerates.

Codespear

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Problems rendering TileMaps
« Reply #5 on: August 03, 2014, 09:19:47 am »
Digot,

Using the vertex array is good idea, but it is unlikely to solve the 2 fps you measure.

There are two possible causes I can think of:
a. Your game loop is not working well
b. Fraps is not measuring what you think its measuring. 

If the problem is (a) we need to see the main loop code in order to help you.

To see if the problem is (b) measure the fps yourself (counting in your game loop).  Then compare with fraps.  I do not know fraps at all, but this investigation might guide you in some other direction.
 

Digot

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: Problems rendering TileMaps
« Reply #6 on: August 03, 2014, 11:28:29 am »
Heyyy

I'm using a lib now that parses my map format and renders it with Vertices to the screen.

Thanks for your help tho :)