1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-27 17:28:41 +00:00

Refactor ABM/LBM related code

This commit is contained in:
sfan5 2024-08-11 13:34:03 +02:00
parent 387856a1c3
commit 7ae51382c8
7 changed files with 295 additions and 269 deletions

View file

@ -90,7 +90,7 @@ struct ABMWithState
struct LoadingBlockModifierDef
{
// Set of contents to trigger on
std::set<std::string> trigger_contents;
std::vector<std::string> trigger_contents;
std::string name;
bool run_at_every_load = false;
@ -100,19 +100,25 @@ struct LoadingBlockModifierDef
MapNode n, float dtime_s) {};
};
struct LBMContentMapping
class LBMContentMapping
{
typedef std::unordered_map<content_t, std::vector<LoadingBlockModifierDef *>> lbm_map;
lbm_map map;
public:
typedef std::vector<LoadingBlockModifierDef*> lbm_vector;
typedef std::unordered_map<content_t, lbm_vector> lbm_map;
std::vector<LoadingBlockModifierDef *> lbm_list;
// Needs to be separate method (not inside destructor),
// because the LBMContentMapping may be copied and destructed
// many times during operation in the lbm_lookup_map.
void deleteContents();
LBMContentMapping() = default;
void addLBM(LoadingBlockModifierDef *lbm_def, IGameDef *gamedef);
const lbm_map::mapped_type *lookup(content_t c) const;
const lbm_vector &getList() const { return lbm_list; }
// This struct owns the LBM pointers.
~LBMContentMapping();
DISABLE_CLASS_COPY(LBMContentMapping);
ALLOW_CLASS_MOVE(LBMContentMapping);
private:
lbm_vector lbm_list;
lbm_map map;
};
class LBMManager