Author Topic: linked list-tilemap  (Read 2611 times)

Offline Corax

  • Mr. Drawsprite
  • **
  • Posts: 57
    • View Profile
linked list-tilemap
« on: 2009-Jul-01 »
The problem with a tilemap consisting of multiple layers is the large amount of unused memory. For example, if you have a DIM like this: TileMap[1000][1000][10] and only a few indexes use 10 tiles, the waste of memory isn?t acceptable.

I thought about tilemaps that function like linked lists. Is this possible with GLB ?
If yes, can someone post an example ?

Offline 9940

  • Mr. Drawsprite
  • **
  • Posts: 53
    • View Profile
Re: linked list-tilemap
« Reply #1 on: 2009-Jul-01 »
hint: with REDIM you can resize an array and free the space is unused

Offline Corax

  • Mr. Drawsprite
  • **
  • Posts: 57
    • View Profile
Re: linked list-tilemap
« Reply #2 on: 2009-Jul-01 »
One index could have 10 tiles, the other but 1.

Offline Corax

  • Mr. Drawsprite
  • **
  • Posts: 57
    • View Profile
Re: linked list-tilemap
« Reply #3 on: 2009-Jul-01 »
Is this ?sparse matrix?possible on GLB ?

Offline Corax

  • Mr. Drawsprite
  • **
  • Posts: 57
    • View Profile
Re: linked list-tilemap
« Reply #4 on: 2009-Jul-01 »
Could you explain the concept of ?sparse matrix? and post a GLB example ?
(I read the wiki-article about it, but didn?t understand it)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10752
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: linked list-tilemap
« Reply #5 on: 2009-Jul-01 »
use a TYPE with an array, that has a dynamic size. Then make an array from that TYPE.
No big deal.

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1789
    • View Profile
    • Homepage
Re: linked list-tilemap
« Reply #6 on: 2009-Jul-01 »
There is a short text about it in the documentation, search on Types. I haven't tried it though since I never felt the need for it.

Offline Nobiag

  • Mr. Drawsprite
  • **
  • Posts: 58
    • View Profile
Re: linked list-tilemap
« Reply #7 on: 2009-Jul-01 »
I hope thats right:

Code: (glbasic) [Select]
TYPE tmaptiles
 tiles[]
ENDTYPE
GLOBAL tilemap[] AS tmaptiles

DIM tilemap[100][100]

DIM tilemap[0][0].tiles[10]
DIM tilemap[1][0].tiles[2]
...

Offline Corax

  • Mr. Drawsprite
  • **
  • Posts: 57
    • View Profile
Re: linked list-tilemap
« Reply #8 on: 2009-Jul-01 »
Thanks.

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1640
  • Particle Hawk
    • View Profile
Re: linked list-tilemap
« Reply #9 on: 2009-Jul-01 »
The problem with a tilemap consisting of multiple layers is the large amount of unused memory. For example, if you have a DIM like this: TileMap[1000][1000][10] and only a few indexes use 10 tiles, the waste of memory isn?t acceptable.

I thought about tilemaps that function like linked lists. Is this possible with GLB ?
If yes, can someone post an example ?

Its not a waste of memory, it is a waste of FPS to loop through those dimensions...just dont loop through everything...just what you need.

I am using that method, to map out particle special effects, in (25*1)dimensions and (11*2)dimensions...and growing...with more options available, and yet, still low resources required.

Im, working on, and almost done with a particle engine.
And it runs fast on everyones computer!

If you can live without Dimensional arrays, TYPEs are right up your alley.

BTW, a 3 dimensioinal array will definetely cause CPU lag.
And is probably too large to mess with strings containing data groups, or long sets of data type numbers bundled into each xyz position in a 3d array. Thats going to also make it harder to program.
Too hard to play with the data are regroup it for more useful optimizations:

Use 3 separate 1* dimensions x[] y[] z[], this is because each dimension vertice contains individual values.
BounceSizeX[] BounceSizeY[] will be easier to read and understand, and manipulate, without the need to rummage through an entire 3d array.

This is exactly what a TYPE does if im not mistaking, it groups arrays and variables throughout a program.

The advantage to a DIM is auto-quick-dirty-byref resource....if it is single dimensional.


« Last Edit: 2009-Jul-01 by Hemlos »
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)