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

Author Topic: VertexArray for tilemap  (Read 9005 times)

0 Members and 1 Guest are viewing this topic.

TheEnigmist

  • Full Member
  • ***
  • Posts: 119
    • View Profile
VertexArray for tilemap
« on: May 31, 2012, 12:13:12 am »
Ok, now i made a functional tilemap, but i foud a limit... cus VertexArray is a std::vector<Vertex> i can't make a 3900x3900 tile map (60 milion of vertex)
Due to private member i can't know m_vertices.max_size()
For the moment i can generate and build a 32x32*256px tilemap in some microseconds and draw it in 10 microseconds :)
My question, how can i know the max size of m_vertices?

For the moment i get crash at this line:
myMap.resize(nrows*ncols*4);
 

EDIT:
Ok i see that i will get some FPS crash with 350x350 map. So i suppose to set max map size to 300x300 which is the last stable FPS map size!
« Last Edit: May 31, 2012, 12:41:48 am by TheEnigmist »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11037
    • View Profile
    • development blog
    • Email
Re: VertexArray for tilemap
« Reply #1 on: May 31, 2012, 01:39:55 am »
You'll need to know the memory footprint of a tile and the limit will probably be your available amout of RAM.

Also I'd say the question is just wrong to ask (except if you're doing a benchmark or something) but if you need 60 million vertecies then you're design is kind of flawed. (Okay maybe you're doing some uber cool game but for a 'normal' tilemap you won't need that many...
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: VertexArray for tilemap
« Reply #2 on: May 31, 2012, 08:10:12 am »
Dude, your map has 1 million x 1 million pixels ???

I think this is crazy. Even if this is really necessary, you should at least split that in chunks and do visibility tests, so that you don't draw the whole thing all the time.
Laurent Gomila - SFML developer

TheEnigmist

  • Full Member
  • ***
  • Posts: 119
    • View Profile
Re: VertexArray for tilemap
« Reply #3 on: May 31, 2012, 10:38:57 am »
Yes, it is crazy to make 3900x3900 xD
300x300 is alredy too big and take too much to "walk" all around. So probably i will limit the map size to 300x300
1000x1000 (and 3900x3900) are just tests, if i could draw 1000x1000 map without FPS crash it will be very usefull, so i can draw all size below 1000x1000 with an high framerate :)

So now, my question is: to manage chunks, will i need to split vertexarray map in n small vertexarray? Or there is a better and coolest way to do it?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: VertexArray for tilemap
« Reply #4 on: May 31, 2012, 10:48:10 am »
There's no "automatic" way, you have to split your world into vertex arrays of an optimal size. The cool thing is that with some simple visibility tests, you can draw only 4 chunks (vertex arrays) at any time.
Laurent Gomila - SFML developer

TheEnigmist

  • Full Member
  • ***
  • Posts: 119
    • View Profile
Re: VertexArray for tilemap
« Reply #5 on: May 31, 2012, 11:03:40 am »
Ok, i will make some tests to reach this goal :P

Vovosunt

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: VertexArray for tilemap
« Reply #6 on: May 31, 2012, 04:49:06 pm »
I think using wrapping is more logical.
You only have enough vertices to cover the screen. As the player moves and tiles go out of view, you move them to the opposite side (obviously changing the texture to the appropriate one) and record the offset.
Making 3900x3900x4 verteces for the whole tilemap is just idiotic. Holding them all in memory and manipulating them is very unefficient (I'm not even talking about rendering). Use some sort of dynamic map/chunk loading.

TheEnigmist

  • Full Member
  • ***
  • Posts: 119
    • View Profile
Re: VertexArray for tilemap
« Reply #7 on: June 01, 2012, 12:05:45 am »
Ok i'm testing for chunks, but i get some errors.
I put in my TileMap class a
std::vector<sf::VertexArray> mapChunks
For my test i want to draw only a 2x2 section of my map that start from (0, 0) coordinates.
So i build a function that store in a vertexarray the right vertex and then store the vertexarray inside the vector.
Then i call draw
window.draw(mapChunks[0],&tilesTexture);

It draws nothing :(
I used the same algorith to build and draw the normal huge map (it draws well), but this tme it wil lbe limited only to a 2x2 matrix.
I checked memory with debugging and vertexarray inside the vector has the same vertexs of normal big map vertexarray.
Why it doesn't draw my small tilemap? What is my mistake?

EDIT: Error found, i forgot to set primitive type xD Now it draws well 2x2 map :)
« Last Edit: June 01, 2012, 12:29:09 am by TheEnigmist »

TheEnigmist

  • Full Member
  • ***
  • Posts: 119
    • View Profile
Re: VertexArray for tilemap
« Reply #8 on: June 01, 2012, 07:32:39 am »
There is a way to rotate 90° a texture that normally is not rotated in tileset? Or have i to draw the same texture  rotated and put it in tile set?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: VertexArray for tilemap
« Reply #9 on: June 01, 2012, 07:55:27 am »
Quote
There is a way to rotate 90° a texture that normally is not rotated in tileset?
Rotate the texture coordinates of the quad.
Laurent Gomila - SFML developer

TheEnigmist

  • Full Member
  • ***
  • Posts: 119
    • View Profile
Re: VertexArray for tilemap
« Reply #10 on: June 01, 2012, 09:46:33 pm »
Quote
There is a way to rotate 90° a texture that normally is not rotated in tileset?
Rotate the texture coordinates of the quad.
Nice!  :D
Now i want to see how much memory (in bytes) each item uses. I read aroud about _msize for VS10, but i get a debug error wich say that the poiter i use is invalid or something like that:
std::cout << "The Matrix size allocated is " << _msize(mapMatrix) << " bytes!"<<std::endl;
std::cout << "The MyMap size allocated is " << _msize(&myMap) << " bytes!"<<std::endl;
std::cout << "The MyMapChunk size allocated is " << _msize(&myMapChunk) << " bytes!"<<std::endl;
 
mapMatrix is a sf:Uint16 pointer
myMap is sf::VertexArray
myMapChunk is a std::vector<sf::VertexArray>
The error appear at _msize(&myMap).
There is a better way to know how much bytes each item uses?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: VertexArray for tilemap
« Reply #11 on: June 01, 2012, 09:57:52 pm »
_msize() doesn't work like that. You should read the documentation of unknown functions before using them:
Quote from: MSDN
The _msize function returns the size, in bytes, of the memory block allocated by a call to calloc, malloc, or realloc.

There is no portable way to find out how much bytes are totally allocated by an arbitrary object.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

TheEnigmist

  • Full Member
  • ***
  • Posts: 119
    • View Profile
Re: VertexArray for tilemap
« Reply #12 on: June 01, 2012, 10:01:46 pm »
_msize() doesn't work like that. You should read the documentation of unknown functions before using them:
Quote from: MSDN
The _msize function returns the size, in bytes, of the memory block allocated by a call to calloc, malloc, or realloc.

There is no portable way to find out how much bytes are totally allocated by an arbitrary object.
Oh yes xD Sorry! I read only some forum posts taht said it used to know bytes and i used it :P
Ok, thx for fast reply :)

TheEnigmist

  • Full Member
  • ***
  • Posts: 119
    • View Profile
Re: VertexArray for tilemap
« Reply #13 on: June 02, 2012, 12:45:47 pm »
I'm getting crazy with update and draw chunks :( I don't know how to code it.
I've a matrix wich represent my tilemap and where i can build tiles.
Chunk size is 8x8 tile
Chunks are std::vector<sf::VertexArray> (maybe i've to code a Chunk class, so i can manage something more than the tilemap)
How can i code a fast and good chunks system? :S
I was thinking about using a IntRect > windowView and calculate tiles coordinates in tile (x*256,y*256) and tehn build and draw chunks taht cover all points inside IntRect... its a good way or there is a more flexible way to manage them?