summaryrefslogtreecommitdiffstats
path: root/source/World.h
diff options
context:
space:
mode:
Diffstat (limited to 'source/World.h')
-rw-r--r--source/World.h101
1 files changed, 80 insertions, 21 deletions
diff --git a/source/World.h b/source/World.h
index b9182e300..da59b12f6 100644
--- a/source/World.h
+++ b/source/World.h
@@ -69,6 +69,24 @@ public:
public:
cLock(cWorld & a_World);
} ;
+
+ /// A common ancestor for all tasks queued onto the tick thread
+ class cTask
+ {
+ public:
+ virtual void Run(cWorld & a_World) = 0;
+ } ;
+
+ typedef std::vector<cTask *> cTasks;
+
+ class cTaskSaveAllChunks :
+ public cTask
+ {
+ protected:
+ // cTask overrides:
+ virtual void Run(cWorld & a_World) override;
+ } ;
+
// tolua_begin
@@ -204,13 +222,6 @@ public:
void CollectPickupsByPlayer(cPlayer * a_Player);
- // MOTD
- const AString & GetDescription(void) const {return m_Description; } // FIXME: This should not be in cWorld
-
- // Max Players
- unsigned int GetMaxPlayers(void) const {return m_MaxPlayers; } // tolua_export
- void SetMaxPlayers(int iMax); // tolua_export
-
void AddPlayer( cPlayer* a_Player );
void RemovePlayer( cPlayer* a_Player );
@@ -223,8 +234,6 @@ public:
/// Finds a player from a partial or complete player name and calls the callback - case-insensitive
bool FindAndDoWithPlayer(const AString & a_PlayerNameHint, cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS <<
- unsigned int GetNumPlayers(); // tolua_export
-
// TODO: This interface is dangerous - rewrite to DoWithClosestPlayer(pos, sight, action)
cPlayer * FindClosestPlayer(const Vector3f & a_Pos, float a_SightLimit);
@@ -470,10 +479,17 @@ public:
if(a_Z < 0 && a_Z % cChunkDef::Width != 0) a_ChunkZ--;
}
- void SaveAllChunks(void); // tolua_export
+ /// Saves all chunks immediately. Dangerous interface, may deadlock, use QueueSaveAllChunks() instead
+ void SaveAllChunks(void); // tolua_export
+
+ /// Queues a task to save all chunks onto the tick thread. The prefferred way of saving chunks from external sources
+ void QueueSaveAllChunks(void); // tolua_export
+
+ /// Queues a task onto the tick thread. The task object will be deleted once the task is finished
+ void QueueTask(cTask * a_Task);
/// Returns the number of chunks loaded
- int GetNumChunks() const; // tolua_export
+ int GetNumChunks() const; // tolua_export
/// Returns the number of chunks loaded and dirty, and in the lighting queue
void GetChunkStats(int & a_NumValid, int & a_NumDirty, int & a_NumInLightingQueue);
@@ -484,12 +500,14 @@ public:
inline int GetStorageLoadQueueLength(void) { return m_Storage.GetLoadQueueLength(); } // tolua_export
inline int GetStorageSaveQueueLength(void) { return m_Storage.GetSaveQueueLength(); } // tolua_export
- void Tick(float a_Dt);
-
void InitializeSpawn(void);
+ /// Starts threads that belong to this world
+ void Start(void);
+
/// Stops threads that belong to this world (part of deinit)
- void StopThreads(void);
+ void Stop(void);
+
void TickQueuedBlocks(float a_Dt);
struct BlockTickQueueItem
@@ -540,7 +558,28 @@ public:
private:
friend class cRoot;
+
+ class cTickThread :
+ public cIsThread
+ {
+ typedef cIsThread super;
+ public:
+ cTickThread(cWorld & a_World);
+
+ protected:
+ cWorld & m_World;
+
+ // cIsThread overrides:
+ virtual void Execute(void) override;
+ } ;
+
+ AString m_WorldName;
+ AString m_IniFileName;
+
+ /// Name of the storage schema used to load and save chunks
+ AString m_StorageSchema;
+
/// The dimension of the world, used by the client to provide correct lighting scheme
eDimension m_Dimension;
@@ -583,8 +622,6 @@ private:
cWorldStorage m_Storage;
- AString m_Description;
-
unsigned int m_MaxPlayers;
cChunkMap * m_ChunkMap;
@@ -616,15 +653,37 @@ private:
cChunkSender m_ChunkSender;
cLightingThread m_Lighting;
-
- AString m_WorldName;
- AString m_IniFileName;
+ cTickThread m_TickThread;
+ /// Guards the m_Tasks
+ cCriticalSection m_CSTasks;
+
+ /// Tasks that have been queued onto the tick thread; guarded by m_CSTasks
+ cTasks m_Tasks;
+
+ /// Guards m_Clients
+ cCriticalSection m_CSClients;
+
+ /// List of clients in this world, these will be ticked by this world
+ cClientHandleList m_Clients;
+
+
cWorld(const AString & a_WorldName);
~cWorld();
- void TickWeather(float a_Dt); // Handles weather each tick
- void TickSpawnMobs(float a_Dt); // Handles mob spawning each tick
+ void Tick(float a_Dt);
+
+ /// Handles the weather in each tick
+ void TickWeather(float a_Dt);
+
+ /// Handles the mob spawning each tick
+ void TickSpawnMobs(float a_Dt);
+
+ /// Executes all tasks queued onto the tick thread
+ void TickQueuedTasks(void);
+
+ /// Ticks all clients that are in this world
+ void TickClients(float a_Dt);
/// Creates a new fluid simulator, loads its settings from the inifile (a_FluidName section)
cFluidSimulator * InitializeFluidSimulator(cIniFile & a_IniFile, const char * a_FluidName, BLOCKTYPE a_SimulateBlock, BLOCKTYPE a_StationaryBlock);