Skip to content
Permalink
Browse files

Biomes: Remove referenced biomes from Decorations on clear

  • Loading branch information
kwolekr committed Apr 17, 2015
1 parent 4abb96f commit 821d0025da3d7dec662e75c6ce2ea32e86aec508
Showing with 36 additions and 17 deletions.
  1. +17 −12 src/gamedef.h
  2. +2 −0 src/mapgen.h
  3. +13 −0 src/mg_biome.cpp
  4. +3 −0 src/mg_biome.h
  5. +0 −1 src/script/lua_api/l_mapgen.cpp
  6. +1 −4 src/server.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 @@ class IGameDef
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 @@ class IGameDef
// 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
@@ -229,6 +229,8 @@ class ObjDefManager {
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;
@@ -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;
@@ -78,6 +78,9 @@ class BiomeManager : public ObjDefManager {
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
@@ -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);
@@ -297,9 +297,6 @@ class Server : public con::PeerHandler, public MapEventReceiver,
// 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 @@ class Server : public con::PeerHandler, public MapEventReceiver,
virtual MtEventManager* getEventManager();
virtual scene::ISceneManager* getSceneManager();
virtual IRollbackManager *getRollbackManager() { return m_rollback; }

virtual EmergeManager *getEmergeManager() { return m_emerge; }

IWritableItemDefManager* getWritableItemDefManager();
IWritableNodeDefManager* getWritableNodeDefManager();

0 comments on commit 821d002

Please sign in to comment.