From e561e652ccae7d7fd214930000892cc24281f96c Mon Sep 17 00:00:00 2001 From: UIS Date: Fri, 14 Aug 2020 01:38:23 +0300 Subject: Use 12+4 bits for BlockId, GetBlockInfo return pointer instead value --- src/Block.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/Block.cpp') diff --git a/src/Block.cpp b/src/Block.cpp index 48c099d..b81a762 100644 --- a/src/Block.cpp +++ b/src/Block.cpp @@ -1,20 +1,25 @@ #include "Block.hpp" #include +#include #include "Plugin.hpp" -std::map staticBlockInfo; +static std::vector blocks; +static std::map staticBlockInfo; + +BlockInfo WTFBlock{ true, "", "" }; void RegisterStaticBlockInfo(BlockId blockId, BlockInfo blockInfo) { - staticBlockInfo[blockId] = blockInfo; + //NOTE: It can be made thread-safe using incrementer + staticBlockInfo[blockId] = blocks.size(); + blocks.push_back(blockInfo); } -BlockInfo GetBlockInfo(BlockId blockId, Vector blockPos) { +BlockInfo* GetBlockInfo(BlockId blockId, Vector blockPos) { auto it = staticBlockInfo.find(blockId); if (it != staticBlockInfo.end()) - return it->second; - if (blockPos == Vector()) - return BlockInfo{ true, "", "" }; - return PluginSystem::RequestBlockInfo(blockPos); + return &blocks.data()[it->second]; + else + return &WTFBlock; } -- cgit v1.2.3