diff options
author | LaG1924 <lag1924@gmail.com> | 2021-12-27 18:49:09 +0100 |
---|---|---|
committer | LaG1924 <lag1924@gmail.com> | 2021-12-27 18:49:09 +0100 |
commit | bb25dc91d9a83a9f9031ad364f1cbbc1b39a4c7c (patch) | |
tree | a98514dcbd52cabbe28344ea3e9dc5636cfe9af0 /src | |
parent | Removed previous liquids implementation (diff) | |
download | AltCraft-bb25dc91d9a83a9f9031ad364f1cbbc1b39a4c7c.tar AltCraft-bb25dc91d9a83a9f9031ad364f1cbbc1b39a4c7c.tar.gz AltCraft-bb25dc91d9a83a9f9031ad364f1cbbc1b39a4c7c.tar.bz2 AltCraft-bb25dc91d9a83a9f9031ad364f1cbbc1b39a4c7c.tar.lz AltCraft-bb25dc91d9a83a9f9031ad364f1cbbc1b39a4c7c.tar.xz AltCraft-bb25dc91d9a83a9f9031ad364f1cbbc1b39a4c7c.tar.zst AltCraft-bb25dc91d9a83a9f9031ad364f1cbbc1b39a4c7c.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Block.cpp | 32 | ||||
-rw-r--r-- | src/Block.hpp | 9 | ||||
-rw-r--r-- | src/Plugin.cpp | 8 |
3 files changed, 35 insertions, 14 deletions
diff --git a/src/Block.cpp b/src/Block.cpp index 85870f6..8af5a4b 100644 --- a/src/Block.cpp +++ b/src/Block.cpp @@ -1,25 +1,29 @@ #include "Block.hpp" #include <map> -#include <vector> -#include "Plugin.hpp" +static std::map<BlockId, BlockInfo> blocks; +static std::map<BlockId, LiquidInfo> liquids; -static std::vector<BlockInfo> blocks; -static std::map<BlockId, size_t> staticBlockInfo; - -BlockInfo WTFBlock{ true, "", "" }; +static BlockInfo UnknownBlock{ true, "", "" }; +static LiquidInfo UnknownLiquid{ "", "" }; void RegisterStaticBlockInfo(BlockId blockId, BlockInfo blockInfo) { - //NOTE: It can be made thread-safe by using atomic incrementer - staticBlockInfo[blockId] = blocks.size(); - blocks.push_back(blockInfo); + blocks.emplace(blockId, blockInfo); +} + +void RegisterStaticLiquidInfo(BlockId blockId, LiquidInfo liquidInfo) { + liquids[blockId] = liquidInfo; + for (uint8_t i = 0; i < 16; i++) + blocks.emplace(BlockId{ blockId.id, i }, BlockInfo{ true, "@liquid", liquidInfo.stillTexture }); } BlockInfo* GetBlockInfo(BlockId blockId) { - auto it = staticBlockInfo.find(blockId); - if (it != staticBlockInfo.end()) - return &blocks.data()[it->second]; - else - return &WTFBlock; + auto it = blocks.find(blockId); + return it != blocks.end() ? &it->second : &UnknownBlock; +} + +const LiquidInfo& GetBlockLiquidInfo(BlockId blockId) { + auto it = liquids.find(blockId); + return it != liquids.end() ? it->second : UnknownLiquid; } diff --git a/src/Block.hpp b/src/Block.hpp index 0fd0e89..535ae68 100644 --- a/src/Block.hpp +++ b/src/Block.hpp @@ -47,6 +47,15 @@ struct BlockInfo { std::string variant; }; +struct LiquidInfo { + std::string flowTexture; + std::string stillTexture; +}; + void RegisterStaticBlockInfo(BlockId blockId, BlockInfo blockInfo); +void RegisterStaticLiquidInfo(BlockId blockId, LiquidInfo liquidInfo); + BlockInfo* GetBlockInfo(BlockId blockId); + +const LiquidInfo& GetBlockLiquidInfo(BlockId blockId); diff --git a/src/Plugin.cpp b/src/Plugin.cpp index 3e06b0c..7a3b716 100644 --- a/src/Plugin.cpp +++ b/src/Plugin.cpp @@ -78,6 +78,13 @@ namespace PluginApi { }); } + void RegisterLiquid(BlockId blockId, std::string flowTexture, std::string stillTexture) { + RegisterStaticLiquidInfo(blockId, LiquidInfo{ + flowTexture, + stillTexture + }); + } + void RegisterDimension(int dimId, Dimension dim) { RegisterNewDimension(dimId, dim); } @@ -286,6 +293,7 @@ void PluginSystem::Init() { apiTable["LogError"] = PluginApi::LogError; apiTable["GetGameState"] = PluginApi::GetGameState; apiTable["RegisterBlock"] = PluginApi::RegisterBlock; + apiTable["RegisterLiquid"] = PluginApi::RegisterLiquid; apiTable["RegisterDimension"] = PluginApi::RegisterDimension; apiTable["ConnectToServer"] = PluginApi::ConnectToServer; apiTable["Exit"] = PluginApi::Exit; |