summaryrefslogtreecommitdiffstats
path: root/src/Block.cpp
diff options
context:
space:
mode:
authorUIS <uis9936@gmail.com>2020-08-14 00:38:23 +0200
committerLaG1924 <lag1924@gmail.com>2021-06-24 10:48:13 +0200
commite561e652ccae7d7fd214930000892cc24281f96c (patch)
tree4c06e3df8643fbbefe9c6d2a46b820dd8edaccf8 /src/Block.cpp
parentMinor network fixes (diff)
downloadAltCraft-e561e652ccae7d7fd214930000892cc24281f96c.tar
AltCraft-e561e652ccae7d7fd214930000892cc24281f96c.tar.gz
AltCraft-e561e652ccae7d7fd214930000892cc24281f96c.tar.bz2
AltCraft-e561e652ccae7d7fd214930000892cc24281f96c.tar.lz
AltCraft-e561e652ccae7d7fd214930000892cc24281f96c.tar.xz
AltCraft-e561e652ccae7d7fd214930000892cc24281f96c.tar.zst
AltCraft-e561e652ccae7d7fd214930000892cc24281f96c.zip
Diffstat (limited to '')
-rw-r--r--src/Block.cpp19
1 files changed, 12 insertions, 7 deletions
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 <map>
+#include <vector>
#include "Plugin.hpp"
-std::map<BlockId, BlockInfo> staticBlockInfo;
+static std::vector<BlockInfo> blocks;
+static std::map<BlockId, size_t> 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;
}