*/
ServerEnvironment::ServerEnvironment(ServerMap *map, lua_State *L,
- IGameDef *gamedef):
+ IGameDef *gamedef, IBackgroundBlockEmerger *emerger):
m_map(map),
m_lua(L),
m_gamedef(gamedef),
+ m_emerger(emerger),
m_random_spawn_timer(3),
m_send_recommended_timer(0),
m_game_time(0),
<<") became active"<<std::endl;*/
MapBlock *block = m_map->getBlockNoCreateNoEx(p);
- if(block==NULL)
+ if(block==NULL){
+ // Block needs to be fetched first
+ m_emerger->queueBlockEmerge(p, false);
+ m_active_blocks.m_list.remove(p);
continue;
+ }
activateBlock(block);
}
private:
};
+class IBackgroundBlockEmerger
+{
+public:
+ virtual void queueBlockEmerge(v3s16 blockpos, bool allow_generate)=0;
+};
+
/*
The server-side environment.
class ServerEnvironment : public Environment
{
public:
- ServerEnvironment(ServerMap *map, lua_State *L, IGameDef *gamedef);
+ ServerEnvironment(ServerMap *map, lua_State *L, IGameDef *gamedef,
+ IBackgroundBlockEmerger *emerger);
~ServerEnvironment();
Map & getMap()
lua_State *m_lua;
// Game definition
IGameDef *m_gamedef;
+ // Background block emerger (the server, in practice)
+ IBackgroundBlockEmerger *m_emerger;
// Active object list
core::map<u16, ServerActiveObject*> m_active_objects;
// Outgoing network message buffer for active objects
// Initialize Environment
- m_env = new ServerEnvironment(new ServerMap(mapsavedir, this), m_lua, this);
+ m_env = new ServerEnvironment(new ServerMap(mapsavedir, this), m_lua,
+ this, this);
// Give environment reference to scripting api
scriptapi_add_environment(m_lua, m_env);
BroadcastChatMessage(msg);
}
+void Server::queueBlockEmerge(v3s16 blockpos, bool allow_generate)
+{
+ u8 flags = 0;
+ if(!allow_generate)
+ flags |= BLOCK_EMERGE_FLAG_FROMDISK;
+ m_emerge_queue.addBlock(PEER_ID_INEXISTENT, blockpos, flags);
+}
+
// IGameDef interface
// Under envlock
IToolDefManager* Server::getToolDefManager()
};
class Server : public con::PeerHandler, public MapEventReceiver,
- public InventoryManager, public IGameDef
+ public InventoryManager, public IGameDef,
+ public IBackgroundBlockEmerger
{
public:
/*
// Envlock and conlock should be locked when calling this
void notifyPlayer(const char *name, const std::wstring msg);
void notifyPlayers(const std::wstring msg);
+
+ void queueBlockEmerge(v3s16 blockpos, bool allow_generate);
// Envlock and conlock should be locked when using Lua
lua_State *getLua(){ return m_lua; }