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

Author Topic: How to effectively break up large Tile Map made with sf::VertexArray  (Read 3298 times)

0 Members and 1 Guest are viewing this topic.

hypnotix

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Email
So I successfully made this tile map sort of thing with an sf::VertexArray, it has around 1.5 million points in it and is of type sf::PrimitiveTypes::Triangles. The problem is, frame rates aren't particularly high (low 80s) at the moment because of its size. Now, there will definitely never be a time in which all of it will be in the screen space to be drawn, so I suspect dividing it into groups and drawing only the ones that are visible would be better right now. So the question is, at what point does the increase in draw() calls offset the performance gain of me having divided it and thus not drawing everything?

Rhimlock

  • Jr. Member
  • **
  • Posts: 73
    • View Profile
Re: How to effectively break up large Tile Map made with sf::VertexArray
« Reply #1 on: July 01, 2015, 12:13:49 pm »
That would depend on the hardware you are using.

A few draw call wont be a problem so my suggesting woul be to split your tilemap into chuncks which are about the size auf your screen. At worst you would have 9 draw calls, which is as good as nothing.

You should just test for yourself to find a size fitting your needs.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10846
    • View Profile
    • development blog
    • Email
Re: How to effectively break up large Tile Map made with sf::VertexArray
« Reply #2 on: July 01, 2015, 12:42:14 pm »
A few hundred draw calls should not be a big issue, in the end however you can only know for sure by benchmarking all the hardware. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

hypnotix

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Email
Re: How to effectively break up large Tile Map made with sf::VertexArray
« Reply #3 on: July 01, 2015, 02:14:59 pm »
All right then, thanks for the replies.

Hapax

  • Hero Member
  • *****
  • Posts: 3360
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: How to effectively break up large Tile Map made with sf::VertexArray
« Reply #4 on: July 01, 2015, 08:33:11 pm »
It might be worth consider creating the tile map vertex array with a size that fits the screen and then update the tiles from your tile data when different tiles are displayed. That way, you're only ever using the amount of primitives that fits on the screen (you may need a little extra to allow for smooth scrolling).
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Resethel

  • Newbie
  • *
  • Posts: 22
    • View Profile
    • Email
Re: How to effectively break up large Tile Map made with sf::VertexArray
« Reply #5 on: July 05, 2015, 04:07:49 pm »
Another possible solution is to render a zone 2/3 tiles wider than your screen
You can for example:
  • Get the view center and the view size
  • Transform them in your tile coordinate system
  • Choose a starting tile ( like startingTile = your center - your mapSize - Vector2<T>(2,2)
  • Render your map from (StartingTile.x) to (StartingTile.x + mapSize.x + 4) same for y axis

It's really non-optimized but I used this kind of system when I learned SFML, but it's pretty effective 8)

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Re: How to effectively break up large Tile Map made with sf::VertexArray
« Reply #6 on: July 05, 2015, 07:09:00 pm »
Another possible solution is to render a zone 2/3 tiles wider than your screen
You can for example:
  • Get the view center and the view size
  • Transform them in your tile coordinate system
  • Choose a starting tile ( like startingTile = your center - your mapSize - Vector2<T>(2,2)
  • Render your map from (StartingTile.x) to (StartingTile.x + mapSize.x + 4) same for y axis

It's really non-optimized but I used this kind of system when I learned SFML, but it's pretty effective 8)
+1, it is robust way to do it. The amount of draw calls depends on screen size Y / primitive size Y. All in all 10/10 IGN
« Last Edit: July 05, 2015, 11:48:02 pm by BaneTrapper »
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

hypnotix

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Email
Re: How to effectively break up large Tile Map made with sf::VertexArray
« Reply #7 on: July 06, 2015, 04:46:42 pm »
Would that not entail creating a New VertexArray to be drawn every time the user scrolls or zooms?

Hapax

  • Hero Member
  • *****
  • Posts: 3360
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: How to effectively break up large Tile Map made with sf::VertexArray
« Reply #8 on: July 06, 2015, 06:00:40 pm »
It's not that big a deal to re-create the vertex array. Most of the time, it could be just changing where on the texture the vertices point to and possibly moving them.
You may want to resize the vertex array if it changes and, as it turns out, that isn't actually much of a problem.

Note that it's not creating a new one; it's just updating the current one from recent data.

It's obviously dependent on what you need it for but this can be done every frame with hundreds of primitives without any significantly noticable delays.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything