## Tile "buffering" (?)

Pliskin09
Citizen
Posts: 89
Joined: Fri Jul 24, 2009 8:30 am

### Tile "buffering" (?)

when you have a tile based game and you draw only those that are required, and one or two extra rows of tiles that get draw outside of the view as the buffer. ( now im not too sure on the name. i have the right idea of what a buffer is, yea?)

i get around

i did this as a challenge to myself, but might turn it into a game later on huh.

i get around 310 FPS at 40 x 40 tiles. my max FPS is 915 FPS at 3 x 3 tiles. these all include the buffers ofcourse, so 3x3 isnt even playable (its 1 playable tile, 8 buffer ones surrounding it).

use the arrow keys to move around. i created a mockup map - 12 x 12 tiles. pretty tiny i know.. the other tiles will display an error tile. these are all tiles too though. the grey box shows what would be inside the viewable area, and outside it is the buffer.

ctrl + wheel up/down to make the area to be drawn wider/thinner.
shift + wheel up/down to make it higher/shorter
ctrl + shift + wheel up/down to make it bigger

what i really want to know
the point of this is to save the computer all the work of drawing the entire map. have i done a good job? or is the FPS impact far too much? (i guess what i mean is how efficient is this, as i dont have much to compare to in my experiances?)

bit of a lua question; how could i load the contents of a table from a file. for example, file X.file has the contents:

Code: Select all

{1,2,3,4}
and in the main.lua, i do something like

resulting in

Code: Select all

a_table = {1,2,3,4}
im going to need this to allow my system to take in maps.
Attachments
buffer.love

TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

### Re: Tile "buffering" (?)

The purpose of a buffer is to smooth out any sort of lag between i/o devices. So, if the program is slow at loading a certain tile off screen the program gets extra time to sort it out before the user can see it. You are correct.
The other technique you are doing is culling. When you only spend time drawing what the user can see to increase performance. No point in using a cpu cycle on something the user will not see.

zugamifk
Prole
Posts: 28
Joined: Sun Jul 26, 2009 4:01 pm

### Re: Tile "buffering" (?)

This probably isn't the best way to do it, but my map files are essentially a long list of assignments for each tile of the map. I made a makeshift map designer and then saved the state of each tile into a data file. When the map is loaded, it open the file and reads it. For example:

Code: Select all

map[1][1][1]=0
map[1][2][1]=2
map[1][3][1]=0
map[1][4][1]=3
map[1][5][1]=2
map[1][6][1]=1
map[1][7][1]=1
map[1][8][1]=3
map[1][9][1]=3
map[1][10][1]=2
map[1][11][1]=0
map[1][12][1]=3
map[1][13][1]=2
Where the table "map" is the table storing all of the tile information, "map[1]" is the first row of tiles, "map[1][1]" is the top left-most tile and "map[1][1][1]" is the index for the sort of dirt tile to draw. This way I can store layers of tiles, for example I can assign each tile's "map[x][y][2]" a value for what decoration to draw on that tile.

Then all I have to do is go into the map editing thing I made and place the tiles I want and save the current state of the map into a file to be opened later.

What you've got going now is what I've got in my game. As it currently stands I've got 10 layers of tiles in a 24x32 grid being drawn at once and it runs very smoothly although I haven't checked the actual FPS. The map file itself is 100x100, and I've tried increasing the load to see how much memory it uses. At 100x100 it's only using about 20mb of ram, but at 1000x1000 it uses 700mb. At 10000x10000 it freezes, so I'm assuming it increases exponentially although I'm not sure why.

Jasoco
Inner party member
Posts: 3650
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

### Re: Tile "buffering" (?)

You should probably take a look at my thread.

### Who is online

Users browsing this forum: No registered users and 8 guests