1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Add generic IPC mechanism between Lua envs

This commit is contained in:
sfan5 2024-05-14 22:24:05 +02:00
parent 06907aa99b
commit f1a436619f
12 changed files with 191 additions and 19 deletions

View file

@ -47,6 +47,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <unordered_set>
#include <optional>
#include <string_view>
#include <shared_mutex>
class ChatEvent;
struct ChatEventChat;
@ -142,6 +143,20 @@ struct ClientInfo {
std::string vers_string, lang_code;
};
struct ModIPCStore {
ModIPCStore() = default;
~ModIPCStore();
/// RW lock for this entire structure
std::shared_mutex mutex;
/**
* Map storing the data
*
* @note Do not store `nil` data in this map, instead remove the whole key.
*/
std::unordered_map<std::string, std::unique_ptr<PackedValue>> map;
};
class Server : public con::PeerHandler, public MapEventReceiver,
public IGameDef
{
@ -301,12 +316,14 @@ public:
NodeDefManager* getWritableNodeDefManager();
IWritableCraftDefManager* getWritableCraftDefManager();
// Not under envlock
virtual const std::vector<ModSpec> &getMods() const;
virtual const ModSpec* getModSpec(const std::string &modname) const;
virtual const SubgameSpec* getGameSpec() const { return &m_gamespec; }
static std::string getBuiltinLuaPath();
virtual std::string getWorldPath() const { return m_path_world; }
virtual std::string getModDataPath() const { return m_path_mod_data; }
virtual ModIPCStore *getModIPCStore() { return &m_ipcstore; }
inline bool isSingleplayer() const
{ return m_simple_singleplayer_mode; }
@ -666,6 +683,8 @@ private:
std::unordered_map<std::string, Translations> server_translations;
ModIPCStore m_ipcstore;
/*
Threads
*/