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

Author Topic: TileMap Problem with 30,000,000 tiles!!  (Read 1565 times)

0 Members and 1 Guest are viewing this topic.

jimmyrickson

  • Guest
TileMap Problem with 30,000,000 tiles!!
« on: June 27, 2019, 08:50:04 am »
I am making a maze game.

I got a problem showing 30,000,000 tiles at the same time, it slow a lot the rendering process, it take 0.6 seconds for each frames.

My maze is composed of 2 sprite, one yellow and one blue. What decide the position of everything is a std::vector<std::vector<sf::Color>>. I draw everything by reference to the 2 existing sprite without copy of any kind. Even more, i only draw what can be seen by the view. But i have to test every sprite to know if they can be seen.

I would like to know if there are way to keep up 60 fps while been able to differentiate each tile programmatically.

Here is my maze with each tile taking up 1 pixel. This is only what can be seen by the view.

Elias Daler

  • Hero Member
  • *****
  • Posts: 599
    • View Profile
    • Blog
    • Email
Re: TileMap Problem with 30,000,000 tiles!!
« Reply #1 on: June 27, 2019, 10:52:31 am »
Can you show the result? Why is it 1 pixel? Isn't it too small?
One way you can deal with it is to draw pixels on sf::RenderTexture's and draw them instead of doing 30,000,000 draw calls.
Tomb Painter, Re:creation dev (abandoned, doing other things) | edw.is | @EliasDaler

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: TileMap Problem with 30,000,000 tiles!!
« Reply #2 on: June 27, 2019, 02:37:58 pm »
well, 30.000.000 tiles is a pretty high number, eh?
of course we would need a piece of code to help you finding the problem, but beforehand I could already say:
1- you don't need to check if every tile is inside the screen. just do something like
for (int y = view.position.y - view.size.y/2; y < view.position.y + view.size.y/2; y++){
    for (int x = view.position.x - view.size.x/2; x < view.position.x + view.size.x/2; x++){
        window.draw(tile[x][y]);
    }
}
(you probably will have to increase this size a bit to avoid blank spaces around the screen)

2- if each tile takes only 1 pixel, dont use tiles. use points, or even better, vertexArrays, so you can draw everything in one draw call.
Visit my game site (and hopefully help funding it? )
Website | IndieDB

 

anything