migrate blocks interaction (scripting) to global chunks storage (WIP)

This commit is contained in:
MihailRis
2024-12-13 05:54:41 +03:00
parent 53cc8d3c7b
commit e0b3425eff
16 changed files with 227 additions and 144 deletions
-43
View File
@@ -1,43 +0,0 @@
#include <mutex>
#include <memory>
#include <unordered_map>
namespace util {
template <typename K, typename V>
class WeakPtrsMap {
std::unordered_map<K, std::weak_ptr<V>> map;
std::mutex mutex;
public:
std::weak_ptr<V>& operator[](const K& k) {
return map[k];
}
std::shared_ptr<V> fetch(const K& k) {
auto found = map.find(k);
if (found == map.end()) {
return nullptr;
}
auto ptr = found->second.lock();
if (ptr == nullptr) {
map.erase(found);
}
return ptr;
}
void erase(const K& k) {
map.erase(k);
}
size_t size() const {
return map.size();
}
void lock() {
mutex.lock();
}
void unlock() {
mutex.unlock();
}
};
}