rvandoosselaer / Blocks

A block (voxel) engine for jMonkeyEngine
BSD 3-Clause "New" or "Revised" License
42 stars 14 forks source link

What's the best way to store block states? #50

Closed Igrium closed 4 years ago

Igrium commented 4 years ago

This isn't an issue per se, but I don't really know where else to put this as there isn't a community forum for this project.

I'm trying to integrate this library into a pre-existing block data structure which has a feature where it can store arbitrary block data that may change the block's model. I've already written a basic adapter and I am not trying to store this data in the render blocks themselves, but I need a way of conforming this multi-model system into your single-model system at runtime.

How would you recommend doing this in a way that makes sense?

rvandoosselaer commented 4 years ago

There is a dedicated thread for Blocks at the jMonkeyEngine forum. You can ask all your questions there.

I don't quite understand the question, but I'll try to answer it generally.

It's not a good idea to mix render data and business data together. In JME terms, it would be the same as storing game data on Spatials. If you want to add data to blocks, don't put this data in the Block class. Store the data and link it with the block id.

The Block class is pure data. It has an id, type, shape, ... It contains the bare minimum info so Blocks know how to render this specific block. A block will always render in exactly the same way. Some blocks however have only differences in shapes, or models as you call it.

A wedge block for example, actually has 4 different shapes. One shape facing north, east, south and west. Each shape is represented by a different block object (eg. oak_log-wedge_north, oak_log-wedge_east, ...). You could for example create an object (WedgeBlock), that holds a collection of blocks (Collection<Block> models) containing all the different shapes of a specific type. This way you have sort of a multi-model system.

For handling blocks, there is the Chunk class. A chunk is a way of organising and structuring block data. Internally it has optimizations for block data lookup etc. A ChunkRepository is used to serialize and deserialize (save and load) block data using protocol buffers.

Igrium commented 4 years ago

That makes sense. Thanks!