Towards 1.13
#19
Late to the party here but I had some ideas that I thought might be worth sharing.

The idea of a global palette is mentioned as just an optimisation but I think it might be a key part of the initial 1.13 implementation.  IMO the easiest path to 1.13 support is to keep supporting the current block id + meta data pattern used throughout the game logic. This could allow the chunk representation to be changed for 1.13 support without needing to rewrite half of the game logic first.

My idea for a global block palette/registry is that when you register a new block you also specify how many unique block states are required. The palette then assigns two things:
  • A BlockId that is just a unique number for that block name
  • A contiguous range of BlockStateId values on the global palette which uniquely represent block name + block state
This is how I envisage it working:
  • The chunk local palette only stores a single index into the global palette, not name + index as your example shows.
  • The "meta value" is still just dumb data like BlockMeta is currently and won't require any new data structures.
  • The "meta value" can be calculated directly from the BlockStateId
             BlockStateMeta = BlockStateId - (Lowest BlockStateId for this block type)
    So it's really just a State index that's specific to that block type.
  • When you need to access individual values from the block state it could be handled by the respective block handler. I pass in the meta value and it returns a struct with the components or alternatively just have query functions like many block handlers have currently.
In code:

enum class BlockId : UInt16 {};        // The new BlockType
enum class BlockStateId : UInt32 {};   // Global Id specifies both Type & Meta 
enum class BlockStateMeta : UInt16 {}; // State index for a known block type

class BlockPalette
{
public:

    struct BlockData
    {
        BlockId m_Id;
        BlockStateMeta m_State;
    };

    BlockId GetBlockId(const AString & a_BlockName) const;
    BlockId GetBlockId(BlockStateId a_StateId) const;

    BlockData GetBlockData(BlockStateId a_StateId) const;

    BlockId RegisterBlock(const AString & a_BlockName, UInt16 a_NumStates);

private:
    std::vector<BlockStateId> m_BlockIdToStateId;
    std::vector<AString> m_BlockIdToName;
    std::unordered_map<AString, BlockId> m_NameToBlockId;

};

BlockPalette gBlockStatePalette;

using ChunkPalette = std::map<UInt32, BlockStateId> mBlockStateMap;

class BlockArea
{
    UInt32 mBlocks[];  // To be replaced by smaller numbers when possible
    ChunkPalette mPalette;

    BlockData block(const Vector3i & aPos)
    {
        const UInt32 paletteIndex = mBlocks[...];
        const BlockStateId StateId = mPalette.mBlockStateMap[paletteIndex];
        return gPalette.GetBlockData(StateId);
    }
};

I don't know if I've explained it well but in my mind this seems far more than just an optimisation.
Reply
Thanks given by:


Messages In This Thread
Towards 1.13 - by xoft - 01-08-2019, 01:04 AM
RE: Towards 1.13 - by xoft - 01-09-2019, 03:06 AM
RE: Towards 1.13 - by NiLSPACE - 01-09-2019, 06:45 AM
RE: Towards 1.13 - by xoft - 01-09-2019, 09:55 PM
RE: Towards 1.13 - by xoft - 01-09-2019, 09:58 PM
RE: Towards 1.13 - by NiLSPACE - 01-09-2019, 10:28 PM
RE: Towards 1.13 - by xoft - 01-11-2019, 05:57 AM
RE: Towards 1.13 - by ShadowCone - 01-11-2019, 03:52 AM
RE: Towards 1.13 - by NiLSPACE - 01-11-2019, 06:03 AM
RE: Towards 1.13 - by ShadowCone - 01-12-2019, 12:28 AM
RE: Towards 1.13 - by xoft - 01-16-2019, 01:10 AM
RE: Towards 1.13 - by xoft - 01-22-2019, 09:14 AM
RE: Towards 1.13 - by NiLSPACE - 01-22-2019, 06:56 PM
RE: Towards 1.13 - by xoft - 01-22-2019, 07:34 PM
RE: Towards 1.13 - by NiLSPACE - 01-22-2019, 08:57 PM
RE: Towards 1.13 - by NiLSPACE - 01-23-2019, 04:58 AM
RE: Towards 1.13 - by xoft - 01-23-2019, 05:32 AM
RE: Towards 1.13 - by xoft - 01-23-2019, 06:04 AM
RE: Towards 1.13 - by peterbell10 - 01-23-2019, 09:49 AM
RE: Towards 1.13 - by xoft - 01-24-2019, 12:00 AM
RE: Towards 1.13 - by xoft - 01-24-2019, 12:07 AM
RE: Towards 1.13 - by peterbell10 - 01-24-2019, 02:35 AM
RE: Towards 1.13 - by peterbell10 - 01-24-2019, 02:59 AM
RE: Towards 1.13 - by xoft - 01-24-2019, 08:02 AM
RE: Towards 1.13 - by xoft - 01-24-2019, 07:41 PM
RE: Towards 1.13 - by tigerw - 01-25-2019, 02:25 AM
RE: Towards 1.13 - by NiLSPACE - 01-25-2019, 04:41 AM
RE: Towards 1.13 - by xoft - 01-25-2019, 05:08 AM
RE: Towards 1.13 - by NiLSPACE - 01-25-2019, 04:31 PM
RE: Towards 1.13 - by xoft - 01-25-2019, 05:19 AM
RE: Towards 1.13 - by tigerw - 01-25-2019, 06:16 AM
RE: Towards 1.13 - by xoft - 01-25-2019, 07:49 PM
RE: Towards 1.13 - by tigerw - 01-25-2019, 09:44 PM
RE: Towards 1.13 - by tigerw - 01-25-2019, 10:40 PM
RE: Towards 1.13 - by xoft - 01-26-2019, 12:58 AM
RE: Towards 1.13 - by tigerw - 01-26-2019, 09:11 PM
RE: Towards 1.13 - by xoft - 01-27-2019, 03:40 AM
RE: Towards 1.13 - by Aberts10 - 05-28-2019, 09:31 AM
RE: Towards 1.13 - by xoft - 05-30-2019, 12:11 AM
RE: Towards 1.13 - by xoft - 08-04-2019, 07:56 AM
RE: Towards 1.13 - by Seadragon91 - 08-04-2019, 07:22 PM
RE: Towards 1.13 - by xoft - 08-04-2019, 11:34 PM
RE: Towards 1.13 - by xoft - 08-05-2019, 07:20 PM
RE: Towards 1.13 - by xoft - 08-06-2019, 07:50 PM
RE: Towards 1.13 - by xoft - 08-29-2019, 12:02 AM
RE: Towards 1.13 - by xoft - 08-30-2019, 10:21 PM
RE: Towards 1.13 - by xoft - 08-31-2019, 02:35 AM
RE: Towards 1.13 - by NiLSPACE - 09-01-2019, 03:04 AM
RE: Towards 1.13 - by xoft - 09-01-2019, 07:13 AM
RE: Towards 1.13 - by NiLSPACE - 09-02-2019, 03:51 AM
RE: Towards 1.13 - by NiLSPACE - 09-05-2019, 12:25 AM
RE: Towards 1.13 - by xoft - 09-05-2019, 06:04 AM
RE: Towards 1.13 - by xoft - 09-05-2019, 06:05 AM
RE: Towards 1.13 - by xoft - 09-10-2019, 05:57 AM
RE: Towards 1.13 - by xoft - 09-27-2019, 07:50 PM
RE: Towards 1.13 - by xoft - 10-17-2019, 06:23 AM
RE: Towards 1.13 - by xoft - 12-28-2019, 08:45 AM



Users browsing this thread: 1 Guest(s)