0

My scenario: A Minecraft like game with a theroretical unlimited orld. The chunks need to be stored and retrieved from filesystem in realtime as the game runs.

The size of one chunk is from a couple of bytes up to theoretical maximum of 65kb.

How can I efficiently manage such data on harddisk, given the fact that chunks may change their size when the player modifies it, so I cannot simply overwrite its old position in my level file.

Is it maybe better to use a database for this, something like SqLite?

codymanix
  • 28,510
  • 21
  • 92
  • 151

1 Answers1

2

In v1 of your game you can cheat... in an NTFS folder you can have up to 2^32 - 1 files. One block == one file. The advantage is that it is very very easy to implement, fast enough and you won't have to debug unknown libraries. FileStream API is a known quantity.

Then in v2 of your game you can use SqLite or things like http://nfilestorage.codeplex.com or http://filedb.codeplex.com or http://litedb.org or any other nosql dbs . In v2 you can look at "bettering" your game.

Community
  • 1
  • 1
xanatos
  • 109,618
  • 12
  • 197
  • 280
  • 1
    Of course, Minecraft used v1 for a long time. No point in doing all the work when there's an existing implementation that's easy to use and usually good enough. I wouldn't use a *single* folder, though - most applications aren't very happy about folders with millions of files :D A simple folder structure can also automatically work as simple partitioning / indexing. Oh, and "free" compression, that's nice too. Of course, file systems tend to have rather large overheads for that application, that's why you want to move away from those eventually. No hurry, though :) – Luaan Apr 20 '15 at 12:18
  • @Luaan I didn't know of how Minecraft worked, but it seemed to be a sensible solution :-) Not a long-term-plan, but surely good enough for a first release. – xanatos Apr 20 '15 at 12:19
  • Yeah, it actually lasted for a while. No point in implementing the harder solution when there's bigger fish to fry. The improved format then joined chunks into regions - still using the file system for region look ups etc., just on a bigger scale. – Luaan Apr 20 '15 at 12:27