Represent 3D map

Hi all!

I’m implementing a simple multiplayer game engine for learning purposes, as I want to understand better EC systems, physics and generally “backend game development”. In what follows, completely ignore the rendering part - I’m not interested in the clients for now.

This is the basic idea:

  • 3 coordinates world (XY for the horizontal planes, Z for height), composed of particles (small moving spheres but not masseless) only colliding with the Ground or with AABBs (walls, ceilings and floors), but not among themselves (ie, they can be at the same point in space)
  • three “materials”: ground, impenetrable; water, realistic with drag & buoyancy; air, realistic with drag & buoyancy
  • the “normal” plane, where particles initially move on, is the plane Z=0. Below that is either ground or water (but most often ground), above that is air (but it might be ground, if there is a natural “zigurrat” or floating islands)

Now, the world can change: ground can be dug and made Air (ie, a hole), or “rise” and become a zigurrat-like structure. For now, I only need to save what of these 3 types a “cell” is, but in future the cell can be more complex (saving inside properties for example, be of more materials etc)

My basic/prototype idea would be to make the map a binary file, then memory map it so the modifications are persisted. However this can lead to the map corruption, and is not scalable (sure, RAM is cheap these days… but it’s an annoying limit/waste nonetheless).

Another possibility would be a sparse format for the map, and/or dividing and loading the world in fixed chunks. This would allow to save space in disk (first option), and to cache the chunks actually in use without loading the others, saving loads of RAM.

I’m sure though I’m re-inventing the wheel, possibly in bad ways - so I turn to you for advice :slight_smile: what do you think? do you know of any stable java libraries that do this, maybe even save in some known format, so I’ll be able to couple it with a world generator (given the constraints above)?

Thanks for any advice you can give.

Nobody having worked with a game using a 3D “block” map? Searching around I can only find dodgy-looking libraries for Minecraft NBF, but nothing a bit more general/standard, nor good advice either :confused:

I guess the use case is not common, but still. Probably I’ve just worded the post very badly…

This is beyond my level to help directly, however you might want to consider asking on the ompf2 forums… it is a forum for advanced real time ray tracers but they also have fantastic insight on how to structure data for 3d worlds.

Perhaps they can help you.

Thanks - will do some crossposting then :slight_smile:

For learning and well for not learning, KISS (Keep It Simple Stupid). You will learn more finishing something that works than something you don’t. So a 3d array is a good start. Yea memory will be an issue for a large map. Don’t worry about that at the start. small maps can be turned into a “chunk” type maps easy enough. The interaction to the map is always just a “what is at location x,y,z” or the slightly more advanced method of “height of ground at x,y”. Then later, if you want to try more advanced quad tress or something, you don’t need to change the rest of the code.

But just start with a 3d array. 100x100x100 bytes is not that much ram and more than big enough to get started with all the challenges you will face just getting that much to work.