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

Author Topic: Optimize this City Map application?  (Read 4095 times)

0 Members and 2 Guests are viewing this topic.

Tukimitzu

  • Full Member
  • ***
  • Posts: 117
  • Anti-Hero Member
    • View Profile
Optimize this City Map application?
« on: May 18, 2018, 12:55:59 am »
EDIT: just realized this should be in General Discussion board, I think.

I'm doing this application where it shows a city, which is divided in neighborhoods, and then when the user clicks on one of them, it shows the urban blocks and streets in another view. I'm hoping I can improve the rendering performance because right now it is pretty bad.



On the top left you can see the time it takes to render going up until it stabilizes at 14-15 milliseconds. I only create the polygons once (which are not sf::ConvexShape, rather they are sf::VertexArray triangles for the filling part and sf::VertexArray line strips for the outline), and redraw them every frame. I was hoping sf::VertexBuffer would improve the performance, which it did, but only for 5-10%. Do you have any tips? How would YOU use SFML to do something like this?
« Last Edit: May 18, 2018, 12:57:59 am by Tukimitzu »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Optimize this City Map application?
« Reply #1 on: May 18, 2018, 09:08:49 am »
Why does your average slowly count up? And what exactly does the value mean?

Help section is the right place, as you're asking for help and not discuss something in general. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Optimize this City Map application?
« Reply #2 on: May 18, 2018, 09:38:18 am »
How many triangles do you have in total? It looks like you need a lot, to define areas with so many details. What about pre-rendering all that stuff and drawing it with textured quads? It's just an idea though, I don't know if it will give better results. If you want to know for sure what should be improved, use an OpenGL profiler and check what the bottleneck is.
Laurent Gomila - SFML developer

Geheim

  • Full Member
  • ***
  • Posts: 201
    • View Profile
    • Email
Re: Optimize this City Map application?
« Reply #3 on: May 18, 2018, 01:40:24 pm »
I would also pre render your city, as it does not seem to change?
Failing to succeed does not mean failing to progress!

Tukimitzu

  • Full Member
  • ***
  • Posts: 117
  • Anti-Hero Member
    • View Profile
Re: Optimize this City Map application?
« Reply #4 on: May 18, 2018, 10:41:32 pm »
Why does your average slowly count up? And what exactly does the value mean?

Help section is the right place, as you're asking for help and not discuss something in general. ;)

It's because I calculate the average based on the last 500 records, so it takes a while for it to stabilize the average when I suddenly add more polygons to the screen. Everytime my draw everything function is called, it records the time it took and updates the average.

Anyway. I should probably mention I was doing something really stupid: rather than putting every triangle in one sf::VertexArray, had one sf::VertexArray for every polygon. When I changed this, so I only have to do one draw(...) call, I had a huge performance gain.

How many triangles do you have in total? It looks like you need a lot, to define areas with so many details. What about pre-rendering all that stuff and drawing it with textured quads? It's just an idea though, I don't know if it will give better results. If you want to know for sure what should be improved, use an OpenGL profiler and check what the bottleneck is.

The dream is to display every block, which in total is close to 1.000.000 triangles. But even with the optimization cited above, it's too much for my machine, which takes 80ms in average to do so.

Now I'm trying to do something smarter, which is the way you usually see being done with interactive maps: I'll break it into layers and tiles and only draw a tile if the camera is zoomed in enough and it is within the view boundaries.

I would also pre render your city, as it does not seem to change?

I don't want to prerender if I can avoid it because I want it to experiment doing some cool stuff with the polygons.

Wish me luck!