aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gamedef.h29
-rw-r--r--src/mapgen.h2
-rw-r--r--src/mg_biome.cpp13
-rw-r--r--src/mg_biome.h3
-rw-r--r--src/script/lua_api/l_mapgen.cpp1
-rw-r--r--src/server.h5
6 files changed, 36 insertions, 17 deletions
diff --git a/src/gamedef.h b/src/gamedef.h
index 793d85b39..a5f6b5968 100644
--- a/src/gamedef.h
+++ b/src/gamedef.h
@@ -31,6 +31,7 @@ class ISoundManager;
class IShaderSource;
class MtEventManager;
class IRollbackManager;
+class EmergeManager;
namespace irr { namespace scene {
class IAnimatedMesh;
class ISceneManager;
@@ -55,10 +56,10 @@ public:
virtual ITextureSource* getTextureSource()=0;
virtual IShaderSource* getShaderSource()=0;
-
+
// Used for keeping track of names/ids of unknown nodes
virtual u16 allocateUnknownNodeId(const std::string &name)=0;
-
+
// Only usable on the client
virtual ISoundManager* getSoundManager()=0;
virtual MtEventManager* getEventManager()=0;
@@ -69,20 +70,24 @@ public:
// Only usable on the server, and NOT thread-safe. It is usable from the
// environment thread.
virtual IRollbackManager* getRollbackManager(){return NULL;}
-
+
+ // Only usable on the server. Thread safe if not written while running threads.
+ virtual EmergeManager *getEmergeManager() { return NULL; }
+
// Used on the client
virtual bool checkLocalPrivilege(const std::string &priv)
{ return false; }
-
+
// Shorthands
- IItemDefManager* idef(){return getItemDefManager();}
- INodeDefManager* ndef(){return getNodeDefManager();}
- ICraftDefManager* cdef(){return getCraftDefManager();}
- ITextureSource* tsrc(){return getTextureSource();}
- ISoundManager* sound(){return getSoundManager();}
- IShaderSource* shsrc(){return getShaderSource();}
- MtEventManager* event(){return getEventManager();}
- IRollbackManager* rollback(){return getRollbackManager();}
+ IItemDefManager *idef() { return getItemDefManager(); }
+ INodeDefManager *ndef() { return getNodeDefManager(); }
+ ICraftDefManager *cdef() { return getCraftDefManager(); }
+ ITextureSource *tsrc() { return getTextureSource(); }
+ ISoundManager *sound() { return getSoundManager(); }
+ IShaderSource *shsrc() { return getShaderSource(); }
+ MtEventManager *event() { return getEventManager(); }
+ IRollbackManager *rollback() { return getRollbackManager();}
+ EmergeManager *emerge() { return getEmergeManager(); }
};
#endif
diff --git a/src/mapgen.h b/src/mapgen.h
index 5ae99c3cd..ee7e8227e 100644
--- a/src/mapgen.h
+++ b/src/mapgen.h
@@ -229,6 +229,8 @@ public:
virtual ObjDef *getRaw(u32 index) const;
virtual ObjDef *setRaw(u32 index, ObjDef *obj);
+ size_t getNumObjects() const { return m_objects.size(); }
+ ObjDefType getType() const { return m_objtype; }
INodeDefManager *getNodeDef() const { return m_ndef; }
u32 validateHandle(ObjDefHandle handle) const;
diff --git a/src/mg_biome.cpp b/src/mg_biome.cpp
index c2040f542..854876545 100644
--- a/src/mg_biome.cpp
+++ b/src/mg_biome.cpp
@@ -18,6 +18,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/
#include "mg_biome.h"
+#include "mg_decoration.h"
+#include "emerge.h"
#include "gamedef.h"
#include "nodedef.h"
#include "map.h" //for MMVManip
@@ -33,6 +35,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
BiomeManager::BiomeManager(IGameDef *gamedef) :
ObjDefManager(gamedef, OBJDEF_BIOME)
{
+ m_gamedef = gamedef;
+
// Create default biome to be used in case none exist
Biome *b = new Biome;
@@ -103,7 +107,16 @@ Biome *BiomeManager::getBiome(float heat, float humidity, s16 y)
void BiomeManager::clear()
{
+ EmergeManager *emerge = m_gamedef->getEmergeManager();
+
+ // Remove all dangling references in Decorations
+ DecorationManager *decomgr = emerge->decomgr;
+ for (size_t i = 0; i != decomgr->getNumObjects(); i++) {
+ Decoration *deco = (Decoration *)decomgr->getRaw(i);
+ deco->biomes.clear();
+ }
+ // Don't delete the first biome
for (size_t i = 1; i < m_objects.size(); i++) {
Biome *b = (Biome *)m_objects[i];
delete b;
diff --git a/src/mg_biome.h b/src/mg_biome.h
index a0ed30d6e..46ae21959 100644
--- a/src/mg_biome.h
+++ b/src/mg_biome.h
@@ -78,6 +78,9 @@ public:
void calcBiomes(s16 sx, s16 sy, float *heat_map, float *humidity_map,
s16 *height_map, u8 *biomeid_map);
Biome *getBiome(float heat, float humidity, s16 y);
+
+private:
+ IGameDef *m_gamedef;
};
#endif
diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp
index 953d80538..c2b461b43 100644
--- a/src/script/lua_api/l_mapgen.cpp
+++ b/src/script/lua_api/l_mapgen.cpp
@@ -1039,7 +1039,6 @@ int ModApiMapgen::l_create_schematic(lua_State *L)
Schematic schem;
Map *map = &(getEnv(L)->getMap());
- INodeDefManager *ndef = getServer(L)->getNodeDefManager();
v3s16 p1 = read_v3s16(L, 1);
v3s16 p2 = read_v3s16(L, 2);
diff --git a/src/server.h b/src/server.h
index da506acf1..ba993523b 100644
--- a/src/server.h
+++ b/src/server.h
@@ -297,9 +297,6 @@ public:
// Envlock and conlock should be locked when using scriptapi
GameScripting *getScriptIface(){ return m_script; }
- //TODO: determine what (if anything) should be locked to access EmergeManager
- EmergeManager *getEmergeManager(){ return m_emerge; }
-
// actions: time-reversed list
// Return value: success/failure
bool rollbackRevertActions(const std::list<RollbackAction> &actions,
@@ -317,7 +314,7 @@ public:
virtual MtEventManager* getEventManager();
virtual scene::ISceneManager* getSceneManager();
virtual IRollbackManager *getRollbackManager() { return m_rollback; }
-
+ virtual EmergeManager *getEmergeManager() { return m_emerge; }
IWritableItemDefManager* getWritableItemDefManager();
IWritableNodeDefManager* getWritableNodeDefManager();