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

Author Topic: [Solved] Tilemap improvements  (Read 2764 times)

0 Members and 1 Guest are viewing this topic.

Geheim

  • Full Member
  • ***
  • Posts: 201
    • View Profile
    • Email
[Solved] Tilemap improvements
« on: October 03, 2012, 07:24:11 pm »
Good evening guys,
I have an isometric tilemap (100x100 tiles) and I already split the map into 16 super-chunks, which have 25 chunks, which again have 25 tiles. The problem is, that the frametime is not as high as I expected it to be.

So my questions are:
Is there any way to improve the frametime? Is the way I handle the map a good one?
I think I read something about rendering directly with OpenGl, but I forgot where... Is this a solution?
Should I handle the map different? If yes, how?
Or is this already the most efficient way and it can't get optimized?

Greetings, Geheim!
« Last Edit: October 04, 2012, 05:08:35 pm by Geheim »
Failing to succeed does not mean failing to progress!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: Tilemap improvements
« Reply #1 on: October 03, 2012, 07:29:26 pm »
  • Profile it, to see where the problem is.
  • If you don't use sf::VertexArray then use it.
  • If you want more help you need to provide more information on what you're doing at the moment. ;)

Shall I cross post this too? ;D
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Geheim

  • Full Member
  • ***
  • Posts: 201
    • View Profile
    • Email
Re: Tilemap improvements
« Reply #2 on: October 03, 2012, 07:40:20 pm »
I don't know exactly where the problem is, but I have a guess. I have to check if the chunk is seen by the camera or not and this takes some time I think, because I have to check with the position of each chunk and the position of the camera... For example:
for(std::list<Chunk>::iterator iChunk=chunkList.begin(); iChunk!=chunkList.end(); ++iChunk)
{
        //If the chunks are seen by the camera, they render
        if((*iChunk).getPosition().x - (*iChunk).getchunkWidth() < camera.getCenter().x + camera.getSize().x &&
                (*iChunk).getPosition().x + (*iChunk).getchunkWidth() > camera.getCenter().x - camera.getSize().x &&
                (*iChunk).getPosition().y  - (*iChunk).getchunkWidth() < camera.getCenter().y + camera.getSize().y &&
                (*iChunk).getPosition().y + (*iChunk).getchunkHeight() > camera.getCenter().y - camera.getSize().y)
        (*iChunk).render();
}

And then there are quite a bit tiles to be rendered, which takes the most time obviously.
Failing to succeed does not mean failing to progress!

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: Tilemap improvements
« Reply #3 on: October 03, 2012, 08:19:49 pm »
Guessing around is not what one calls 'profiling'... ::)

Google for a profiler matching your OS & IDE and run your code through it. With that you'll exactly know what function is called most and where the most time is spend. Additionally you'll also see if your 'clipping-function' is efficient or not.

As far as I can see the 8 additions/subtractions and the 4 checks aren't really that time consumption. A time wasting part could be the iteration of a std::list, but if it's really the thing that slows down the application can't really be said...
Also you could optimize things a bit by calculating the camera Center -+ Size once and then check against a temporary variable. The camera should move in the meantime shouldn't it? So you'd get 4*n additions less and 8*(2)*n function calls less. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Geheim

  • Full Member
  • ***
  • Posts: 201
    • View Profile
    • Email
Re: Tilemap improvements
« Reply #4 on: October 04, 2012, 05:08:14 pm »
The thing with the VertexArray works surprisingly better!
Thanks a lot for this, it really helped a lot! Amazing how different it is now, with only a few changes  :o
Failing to succeed does not mean failing to progress!