On 2014-02-03 Brandon Fergerson wrote:
> I realize the new XZ Block would be bigger which is why I'm looking
> to insert the data instead of overwrite it. I imagined something
> like: find block, insert new compressed data over block (while
> pushing down the blocks below), and then update indices to reflect
> changes. Or would this not be efficient?

Unfortunately most file systems don't support inserting new data in the
middle of a file (not even as multiples of the file system block size)
so "pushing down" means rewriting everything after that file offset. If
the file is big, it gets slow. If the file is small, the question
doesn't matter much since you could rewrite the whole file anyway.

> I suppose my problem is that I don't really understand what it is I'm 
> looking for. I knew I wanted the maps to be compressed and I knew I 
> wanted them to support random access. What else should I be looking
> for?

I fully agree with Alexander's advice. First write something simple that
works even if it wastes a few hundred megabytes of disk space per map.
Make the map available with getTile(int x, int y) or something like
that. When it and other major parts of the game work, you can replace
the map implementation without affecting the rest of the game code.

From your first post I guess you are using Java, and with my
limited Java experience I cannot say if there's good enough mmap()
equivalent, but it should be very easy for you to write a class that
writes the whole map into a single uncompressed file, each tile taking
a fixed amount of space.

Once you have that working, you could try a multi-file approach and
write for example 16x16 tiles per file, again each tile taking a fixed
amount of space. Naturally you need to name each file so that you know
which file contains which tiles. A new empty map can consist of no
files: any missing file is considered to be full of empty tiles. That
way small maps don't take much space. Later you can add compression
easily by compressing each file separately.

Don't worry about a single-file compressed map format for now.

Feel free to ask if you got more questions, but I hope you can at least
get started now.

-- 
Lasse Collin  |  IRC: Larhzu @ IRCnet & Freenode

Reply via email to