landscape data in files

hello

i work on an adventure game and i am now on an
complicate point. i got my map in clusters int (20x20x3(height,ground,special )
5x5 clusters are in memory (100x100)

my first (very bad idea) was to save each cluster as seperate file
(i produce 40000 files, very bad idea)

my idea was, when the char/camera leaves the inner space the next 5 clusters
are reloaded (north,south,east,west), the files are working…but 40000 files is tooo much.

did anybody got an idea how i can fix this problem?

i think about one large file and adress direct the data (read/save) that i need

open the file…
for (int z=0;z<100;z++)
{
for (int x=0;x<100;x++)
{
file_position=((cluster_z+z)*20000)+cluster_x+x
read/write
}
}

is it possible, is it good or bad idea
and what is todo, i am not very experienced with file io stuff?

thanks for any answer :slight_smile:

What is very bad? is there a performance issue? Sure there are better ways to do what you want, but if you are not experiencing any slow downs is there a problem?

You could have a background thread pre-loading the clusters surrounding inner space clusters. This means when the char leaves the inner space clusters, the appropriate clusters are already loaded. This is slightly inefficent as you are loading extra clusters which may not be needed.

hello moogie :slight_smile:

i got no performance problem at moment,
i only reload 5 cluster files when camera is leaving inner part…
the rest is moved in memory.

but the question is, is it good to use so much files
(40000 files with each 4-8k size)
or are there better ways

If you care about storage size, then yes having that many small files may waste a lot of disk space (depending on the file format & cluster size the disc is using…)

It depends on the filesystem. Both in performance and in actual space usage. (round up to 4k, on most systems)

Furter, you’re putting (some) strain on your directory file listing, but I guess the OS will cache that into RAM. Still, if there is no reason to split your data over a few thousand files, why would you? Using a RandomAccessFile is probably a much better approach. You can manipulate the filepointer with seek(…)

RandomAccessFile sounds like for what i search for.

is there any online tutorial for that?

javadocs

much thanks :slight_smile: