Re: Storing Tilemaps/Drawing Tilemaps
- From: nathan@xxxxxxxx (Nathan Mates)
- Date: Mon, 25 Jul 2005 03:27:17 -0000
In article <iPidnT7u3O63j3nfRVnytA@xxxxxxxxx>, GaRRy <spam@xxxxxxxx> wrote:
> Up until quite recently I was storing my tiles in a huge array and
> was happy with it, good speed etc. Then I realised that more than
> half of my tiles were empty - so this was a huge waste of memory.
If you're programming for a PC, this is less of a problem than
you think.
>So I made it a map point based map..
>std::map< QPOINT, unsigned int, QPOINT >
Worst. Solution. Ever. Really, this is a bad idea. std::map is not
designed for a large sparse 2D grid. There's a ton of overhead
involved, and a ton of pointer-chasing, which isn't terribly fast even
on PCs.
How about a better solution: have your large map out on disk. Read
in chunks (say 16x16 tiles) when you need them. Keep say 4x the number
of screen tiles in memory, and when you need another chunk, evict the
oldest chunk from memory and read it off disk. That will give you the
speed of arrays, and a much reduced memory hit. For bonus points, RLE
the chunks to reduce the empty ones to nearly nothing.
Nathan Mates
--
<*> Nathan Mates - personal webpage http://www.visi.com/~nathan/
# Programmer at Pandemic Studios -- http://www.pandemicstudios.com/
# NOT speaking for Pandemic Studios. "Care not what the neighbors
# think. What are the facts, and to how many decimal places?" -R.A. Heinlein
.
- References:
- Storing Tilemaps/Drawing Tilemaps
- From: GaRRy
- Storing Tilemaps/Drawing Tilemaps
- Prev by Date: Storing Tilemaps/Drawing Tilemaps
- Next by Date: Re: Storing Tilemaps/Drawing Tilemaps
- Previous by thread: Storing Tilemaps/Drawing Tilemaps
- Next by thread: Re: Storing Tilemaps/Drawing Tilemaps
- Index(es):
Relevant Pages
|