From eb9d45e9065a94c93dc2f1624c22f026b9be3d5f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 11 Aug 2013 19:18:06 +0200 Subject: Moved MaxPlayers and Description from cWorld to cServer. Also started creating a new cWorld::cTickThread class, but not used yet. --- source/World.h | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'source/World.h') diff --git a/source/World.h b/source/World.h index b9182e300..1ae56a410 100644 --- a/source/World.h +++ b/source/World.h @@ -204,13 +204,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 +216,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); @@ -484,8 +475,6 @@ 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); /// Stops threads that belong to this world (part of deinit) @@ -540,7 +529,25 @@ 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; + /// The dimension of the world, used by the client to provide correct lighting scheme eDimension m_Dimension; @@ -583,8 +590,6 @@ private: cWorldStorage m_Storage; - AString m_Description; - unsigned int m_MaxPlayers; cChunkMap * m_ChunkMap; @@ -616,13 +621,14 @@ private: cChunkSender m_ChunkSender; cLightingThread m_Lighting; + cTickThread m_TickThread; + - AString m_WorldName; - AString m_IniFileName; - cWorld(const AString & a_WorldName); ~cWorld(); + void Tick(float a_Dt); + void TickWeather(float a_Dt); // Handles weather each tick void TickSpawnMobs(float a_Dt); // Handles mob spawning each tick -- cgit v1.2.3 From 4c5590636cf4a311f03e735878557b1e7b3362dd Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 11 Aug 2013 20:16:41 +0200 Subject: Each world now ticks in a separate thread. --- source/World.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'source/World.h') diff --git a/source/World.h b/source/World.h index 1ae56a410..a12a9e40e 100644 --- a/source/World.h +++ b/source/World.h @@ -477,8 +477,12 @@ public: 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 @@ -548,6 +552,9 @@ private: 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; -- cgit v1.2.3 From 829cc866cd63c50ebff4dac2f942a0df93d269fc Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 11 Aug 2013 21:05:44 +0200 Subject: Added cWorld:QueueSaveAllChunks() function for saving chunks asynchronously. The cWorld:SaveAllChunks() is therefore deprecated in the API and will be removed soon, use QueueSaveAllChunks() instead. --- source/World.h | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'source/World.h') diff --git a/source/World.h b/source/World.h index a12a9e40e..d84920470 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 cTasks; + + class cTaskSaveAllChunks : + public cTask + { + protected: + // cTask overrides: + virtual void Run(cWorld & a_World) override; + } ; + // tolua_begin @@ -461,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); @@ -629,6 +654,12 @@ private: cChunkSender m_ChunkSender; cLightingThread m_Lighting; 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; cWorld(const AString & a_WorldName); @@ -639,6 +670,9 @@ private: void TickWeather(float a_Dt); // Handles weather each tick void TickSpawnMobs(float a_Dt); // Handles mob spawning each tick + /// Executes all tasks queued onto the tick thread + void TickQueuedTasks(void); + /// 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); }; // tolua_export -- cgit v1.2.3 From 9020dc993241a4a90e8e98b3435d9b2576f313ea Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 13 Aug 2013 22:45:29 +0200 Subject: Clients are now ticked in cServer first, then in cWorld once they get assigned a world. --- source/World.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'source/World.h') diff --git a/source/World.h b/source/World.h index d84920470..da59b12f6 100644 --- a/source/World.h +++ b/source/World.h @@ -660,6 +660,12 @@ private: /// 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); @@ -667,12 +673,18 @@ private: void Tick(float a_Dt); - void TickWeather(float a_Dt); // Handles weather each tick - void TickSpawnMobs(float a_Dt); // Handles mob spawning each tick + /// 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); }; // tolua_export -- cgit v1.2.3 From b65a91dde33bc8c7c3e802e94d1862206a1b6a32 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 13 Aug 2013 23:10:59 +0200 Subject: Exported cWorld:BroadcastChat() to the Lua API; used in the Core. --- source/World.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source/World.h') diff --git a/source/World.h b/source/World.h index da59b12f6..2c04c4cc6 100644 --- a/source/World.h +++ b/source/World.h @@ -154,8 +154,8 @@ public: void BroadcastAttachEntity (const cEntity & a_Entity, const cEntity * a_Vehicle); void BroadcastBlockAction (int a_BlockX, int a_BlockY, int a_BlockZ, char a_Byte1, char a_Byte2, BLOCKTYPE a_BlockType, const cClientHandle * a_Exclude = NULL); void BroadcastBlockBreakAnimation(int a_EntityID, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Stage, const cClientHandle * a_Exclude = NULL); - void BroadcastBlockEntity (int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = NULL); ///< If there is a block entity at the specified coods, sends it to all clients except a_Exclude - void BroadcastChat (const AString & a_Message, const cClientHandle * a_Exclude = NULL); + void BroadcastBlockEntity (int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = NULL); ///< If there is a block entity at the specified coods, sends it to all clients except a_Exclude + void BroadcastChat (const AString & a_Message, const cClientHandle * a_Exclude = NULL); // tolua_export void BroadcastChunkData (int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer, const cClientHandle * a_Exclude = NULL); void BroadcastCollectPickup (const cPickup & a_Pickup, const cPlayer & a_Player, const cClientHandle * a_Exclude = NULL); void BroadcastDestroyEntity (const cEntity & a_Entity, const cClientHandle * a_Exclude = NULL); -- cgit v1.2.3 From f8757d3606a9cf14a353e5b7a61b8e660a4cce6d Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 14 Aug 2013 13:43:55 +0200 Subject: Fixed crashes in world's clientlist manipulators --- source/World.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source/World.h') diff --git a/source/World.h b/source/World.h index 2c04c4cc6..4f1e942e4 100644 --- a/source/World.h +++ b/source/World.h @@ -666,6 +666,12 @@ private: /// List of clients in this world, these will be ticked by this world cClientHandleList m_Clients; + + /// Clients that are scheduled for removal (ticked in another world), waiting for TickClients() to remove them + cClientHandleList m_ClientsToRemove; + + /// Clients that are scheduled for adding, waiting for TickClients to add them + cClientHandleList m_ClientsToAdd; cWorld(const AString & a_WorldName); -- cgit v1.2.3 From 7acb665f25a073bf9eb3ca0f8cced0f1caea1dfd Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 15 Aug 2013 22:12:57 +0200 Subject: Exported cWorld:DoExplosionAt() to Lua API. --- source/World.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/World.h') diff --git a/source/World.h b/source/World.h index 4f1e942e4..8525eebe5 100644 --- a/source/World.h +++ b/source/World.h @@ -403,7 +403,7 @@ public: | esWitherBirth | TBD | | esPlugin | void * | */ - void DoExplosiontAt(double a_ExplosionSize, double a_BlockX, double a_BlockY, double a_BlockZ, bool a_CanCauseFire, eExplosionSource a_Source, void * a_SourceData); + void DoExplosiontAt(double a_ExplosionSize, double a_BlockX, double a_BlockY, double a_BlockZ, bool a_CanCauseFire, eExplosionSource a_Source, void * a_SourceData); // tolua_export /// Calls the callback for the chest at the specified coords; returns false if there's no chest at those coords, true if found bool DoWithChestAt (int a_BlockX, int a_BlockY, int a_BlockZ, cChestCallback & a_Callback); // Exported in ManualBindings.cpp -- cgit v1.2.3 From 0cb00996de574095fac49e181a11e6a766248743 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 16 Aug 2013 10:48:19 +0200 Subject: Replaced E_ENTITY_TYPE_XXX with cMonster::mtXXX. Also slightly improved the spawning algorithm. --- source/World.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source/World.h') diff --git a/source/World.h b/source/World.h index 8525eebe5..5d3de06d0 100644 --- a/source/World.h +++ b/source/World.h @@ -20,6 +20,7 @@ #include "Defines.h" #include "LightingThread.h" #include "Item.h" +#include "Mobs/Monster.h" @@ -546,8 +547,8 @@ public: bool IsBlockDirectlyWatered(int a_BlockX, int a_BlockY, int a_BlockZ); // tolua_export - /// Spawns a mob of the specified entity type. Returns the mob's EntityID if recognized and spawned, <0 otherwise - int SpawnMob(double a_PosX, double a_PosY, double a_PosZ, int a_EntityType); // tolua_export + /// Spawns a mob of the specified type. Returns the mob's EntityID if recognized and spawned, <0 otherwise + int SpawnMob(double a_PosX, double a_PosY, double a_PosZ, cMonster::eType a_MonsterType); // tolua_export /// Returns a random number from the m_TickRand in range [0 .. a_Range]. To be used only in the tick thread! int GetTickRandomNumber(unsigned a_Range) { return (int)(m_TickRand.randInt(a_Range)); } -- cgit v1.2.3