summaryrefslogtreecommitdiffstats
path: root/src/Block.cpp
diff options
context:
space:
mode:
authorLaG1924 <12997935+LaG1924@users.noreply.github.com>2021-06-27 05:46:22 +0200
committerGitHub <noreply@github.com>2021-06-27 05:46:22 +0200
commitdd1323d398733f0f4a3b285b396ed3a47fb8eb96 (patch)
tree3064b292efd41a36b5655fd4d07ec42053463ffb /src/Block.cpp
parentMerge pull request #60 from LaG1924/fix/memleak (diff)
parentFixed entity bug found by @uis246 (diff)
downloadAltCraft-dd1323d398733f0f4a3b285b396ed3a47fb8eb96.tar
AltCraft-dd1323d398733f0f4a3b285b396ed3a47fb8eb96.tar.gz
AltCraft-dd1323d398733f0f4a3b285b396ed3a47fb8eb96.tar.bz2
AltCraft-dd1323d398733f0f4a3b285b396ed3a47fb8eb96.tar.lz
AltCraft-dd1323d398733f0f4a3b285b396ed3a47fb8eb96.tar.xz
AltCraft-dd1323d398733f0f4a3b285b396ed3a47fb8eb96.tar.zst
AltCraft-dd1323d398733f0f4a3b285b396ed3a47fb8eb96.zip
Diffstat (limited to 'src/Block.cpp')
-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..85870f6 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 by using atomic incrementer
+ staticBlockInfo[blockId] = blocks.size();
+ blocks.push_back(blockInfo);
}
-BlockInfo GetBlockInfo(BlockId blockId, Vector blockPos) {
+BlockInfo* GetBlockInfo(BlockId blockId) {
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;
}