summaryrefslogtreecommitdiff
path: root/src/environment.h
diff options
context:
space:
mode:
authorest31 <MTest31@outlook.com>2016-02-09 07:08:31 +0100
committerest31 <MTest31@outlook.com>2016-03-07 19:54:26 +0100
commitd494733839e9cf6cb557462326ed21e7a58816c7 (patch)
tree07ead00672b0096aa2a60938b769bf030bba2951 /src/environment.h
parent88fbe7ca1e5451851ee0c7ab5524c39a7bb703c2 (diff)
downloadminetest-d494733839e9cf6cb557462326ed21e7a58816c7.tar.gz
minetest-d494733839e9cf6cb557462326ed21e7a58816c7.tar.bz2
minetest-d494733839e9cf6cb557462326ed21e7a58816c7.zip
Add minetest.register_lbm() to run code on block load only
Diffstat (limited to 'src/environment.h')
-rw-r--r--src/environment.h80
1 files changed, 78 insertions, 2 deletions
diff --git a/src/environment.h b/src/environment.h
index e7b818dc9..448ed70e6 100644
--- a/src/environment.h
+++ b/src/environment.h
@@ -139,7 +139,7 @@ private:
};
/*
- Active block modifier interface.
+ {Active, Loading} block modifier interface.
These are fed into ServerEnvironment at initialization time;
ServerEnvironment handles deleting them.
@@ -177,6 +177,77 @@ struct ABMWithState
ABMWithState(ActiveBlockModifier *abm_);
};
+struct LoadingBlockModifierDef
+{
+ // Set of contents to trigger on
+ std::set<std::string> trigger_contents;
+ std::string name;
+ bool run_at_every_load;
+
+ virtual ~LoadingBlockModifierDef() {}
+ virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n){};
+};
+
+struct LBMContentMapping
+{
+ typedef std::map<content_t, std::vector<LoadingBlockModifierDef *> > container_map;
+ container_map 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();
+ void addLBM(LoadingBlockModifierDef *lbm_def, IGameDef *gamedef);
+ const std::vector<LoadingBlockModifierDef *> *lookup(content_t c) const;
+};
+
+class LBMManager
+{
+public:
+ LBMManager():
+ m_query_mode(false)
+ {}
+
+ ~LBMManager();
+
+ // Don't call this after loadIntroductionTimes() ran.
+ void addLBMDef(LoadingBlockModifierDef *lbm_def);
+
+ void loadIntroductionTimes(const std::string &times,
+ IGameDef *gamedef, u32 now);
+
+ // Don't call this before loadIntroductionTimes() ran.
+ std::string createIntroductionTimesString();
+
+ // Don't call this before loadIntroductionTimes() ran.
+ void applyLBMs(ServerEnvironment *env, MapBlock *block, u32 stamp);
+
+ // Warning: do not make this std::unordered_map, order is relevant here
+ typedef std::map<u32, LBMContentMapping> lbm_lookup_map;
+
+private:
+ // Once we set this to true, we can only query,
+ // not modify
+ bool m_query_mode;
+
+ // For m_query_mode == false:
+ // The key of the map is the LBM def's name.
+ // TODO make this std::unordered_map
+ std::map<std::string, LoadingBlockModifierDef *> m_lbm_defs;
+
+ // For m_query_mode == true:
+ // The key of the map is the LBM def's first introduction time.
+ lbm_lookup_map m_lbm_lookup;
+
+ // Returns an iterator to the LBMs that were introduced
+ // after the given time. This is guaranteed to return
+ // valid values for everything
+ lbm_lookup_map::const_iterator getLBMsIntroducedAfter(u32 time)
+ { return m_lbm_lookup.lower_bound(time); }
+};
+
/*
List of active blocks, used by ServerEnvironment
*/
@@ -254,6 +325,9 @@ public:
*/
void saveMeta();
void loadMeta();
+ // to be called instead of loadMeta if
+ // env_meta.txt doesn't exist (e.g. new world)
+ void loadDefaultMeta();
/*
External ActiveObject interface
@@ -312,11 +386,12 @@ public:
void activateBlock(MapBlock *block, u32 additional_dtime=0);
/*
- ActiveBlockModifiers
+ {Active,Loading}BlockModifiers
-------------------------------------------
*/
void addActiveBlockModifier(ActiveBlockModifier *abm);
+ void addLoadingBlockModifierDef(LoadingBlockModifierDef *lbm);
/*
Other stuff
@@ -427,6 +502,7 @@ private:
u32 m_last_clear_objects_time;
// Active block modifiers
std::vector<ABMWithState> m_abms;
+ LBMManager m_lbm_mgr;
// An interval for generally sending object positions and stuff
float m_recommended_send_interval;
// Estimate for general maximum lag as determined by server.