1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-06 17:41:04 +00:00

Lua on each mapgen thread (#13092)

This commit is contained in:
sfan5 2024-02-13 22:47:30 +01:00 committed by GitHub
parent d4b107e2e8
commit 3cac17d23e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
32 changed files with 1329 additions and 193 deletions

View file

@ -76,29 +76,41 @@ enum GenNotifyType {
GENNOTIFY_LARGECAVE_BEGIN,
GENNOTIFY_LARGECAVE_END,
GENNOTIFY_DECORATION,
GENNOTIFY_CUSTOM, // user-defined data
NUM_GENNOTIFY_TYPES
};
struct GenNotifyEvent {
GenNotifyType type;
v3s16 pos;
u32 id;
};
class GenerateNotifier {
public:
struct GenNotifyEvent {
GenNotifyType type;
v3s16 pos;
u32 id; // for GENNOTIFY_DECORATION
};
// Use only for temporary Mapgen objects with no map generation!
GenerateNotifier() = default;
GenerateNotifier(u32 notify_on, const std::set<u32> *notify_on_deco_ids);
// normal constructor
GenerateNotifier(u32 notify_on, const std::set<u32> *notify_on_deco_ids,
const std::set<std::string> *notify_on_custom);
bool addEvent(GenNotifyType type, v3s16 pos, u32 id=0);
void getEvents(std::map<std::string, std::vector<v3s16> > &event_map);
bool addEvent(GenNotifyType type, v3s16 pos);
bool addDecorationEvent(v3s16 pos, u32 deco_id);
bool setCustom(const std::string &key, const std::string &value);
void getEvents(std::map<std::string, std::vector<v3s16>> &map) const;
const StringMap &getCustomData() const { return m_notify_custom; }
void clearEvents();
private:
u32 m_notify_on = 0;
const std::set<u32> *m_notify_on_deco_ids = nullptr;
const std::set<std::string> *m_notify_on_custom = nullptr;
std::list<GenNotifyEvent> m_notify_events;
StringMap m_notify_custom;
inline bool shouldNotifyOn(GenNotifyType type) const {
return m_notify_on & (1 << type);
}
};
// Order must match the order of 'static MapgenDesc g_reg_mapgens[]' in mapgen.cpp