mirror of
https://github.com/neoStudiosLCE/neoLegacy.git
synced 2026-06-11 14:02:53 +00:00
36 lines
737 B
C++
36 lines
737 B
C++
#include "BlockStateDecoderRegistry.h"
|
|
#include <unordered_map>
|
|
#include <mutex>
|
|
|
|
namespace BlockStateDecoderRegistry {
|
|
|
|
static std::unordered_map<int, DecoderFn> *g_map = nullptr;
|
|
static std::mutex g_mapMutex;
|
|
|
|
static void ensureMap()
|
|
{
|
|
if (!g_map) g_map = new std::unordered_map<int, DecoderFn>();
|
|
}
|
|
|
|
void registerDecoder(int tileId, DecoderFn fn)
|
|
{
|
|
std::lock_guard<std::mutex> l(g_mapMutex);
|
|
ensureMap();
|
|
(*g_map)[tileId] = fn;
|
|
}
|
|
|
|
std::wstring decode(int tileId, int composite)
|
|
{
|
|
std::lock_guard<std::mutex> l(g_mapMutex);
|
|
ensureMap();
|
|
auto it = g_map->find(tileId);
|
|
if (it == g_map->end()) return L"";
|
|
try {
|
|
return it->second(composite);
|
|
} catch (...) {
|
|
return L"";
|
|
}
|
|
}
|
|
|
|
}
|