From ee929793f09c431693e1bef7edd77213ba412f60 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 25 May 2014 13:46:34 +0100 Subject: Hopefully fixed piston duplication issues * Fixes #879 * Fixes #714 --- src/World.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/World.h') diff --git a/src/World.h b/src/World.h index 86cbb3e7e..5ef63a540 100644 --- a/src/World.h +++ b/src/World.h @@ -117,6 +117,22 @@ public: }; + class cTaskSendBlockToAllPlayers : + public cTask + { + public: + cTaskSendBlockToAllPlayers(int a_BlockX, int a_BlockY, int a_BlockZ); + + protected: + // cTask overrides: + virtual void Run(cWorld & a_World) override; + + int m_BlockX; + int m_BlockY; + int m_BlockZ; + }; + + static const char * GetClassStatic(void) // Needed for ManualBindings's ForEach templates { return "cWorld"; @@ -373,7 +389,7 @@ public: /** Sets the block at the specified coords to the specified value. Full processing, incl. updating neighbors, is performed. */ - void SetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); + void SetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, bool a_SendToClients = true); /** Sets the block at the specified coords to the specified value. The replacement doesn't trigger block updates. -- cgit v1.2.3 From 365c6f50bd057eb62c66b9b222a07ca6efcb2c47 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 29 May 2014 11:57:06 +0100 Subject: Changed block send queue to use vectors As suggested by @worktycho. --- src/World.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/World.h') diff --git a/src/World.h b/src/World.h index 5ef63a540..98b241a2b 100644 --- a/src/World.h +++ b/src/World.h @@ -121,15 +121,13 @@ public: public cTask { public: - cTaskSendBlockToAllPlayers(int a_BlockX, int a_BlockY, int a_BlockZ); + cTaskSendBlockToAllPlayers(std::vector & a_SendQueue); protected: // cTask overrides: virtual void Run(cWorld & a_World) override; - int m_BlockX; - int m_BlockY; - int m_BlockZ; + std::vector m_SendQueue; }; -- cgit v1.2.3 From b904223b9dbbe7b696dbd30e748bc131742e11ea Mon Sep 17 00:00:00 2001 From: Mattes D Date: Fri, 6 Jun 2014 22:31:16 +0200 Subject: Added queue for adding entities to cWorld. This alone doesn't work properly yet, further changes to cPlayer are needed. --- src/World.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/World.h') diff --git a/src/World.h b/src/World.h index 98b241a2b..4c014a976 100644 --- a/src/World.h +++ b/src/World.h @@ -301,7 +301,8 @@ public: void SendPlayerList(cPlayer * a_DestPlayer); // Sends playerlist to the player - /** Adds the entity into its appropriate chunk; takes ownership of the entity ptr */ + /** Adds the entity into its appropriate chunk; takes ownership of the entity ptr. + The entity is added lazily - this function only puts it in a queue that is then processed by the Tick thread. */ void AddEntity(cEntity * a_Entity); bool HasEntity(int a_UniqueID); @@ -926,6 +927,12 @@ private: /** Clients that are scheduled for adding, waiting for TickClients to add them */ cClientHandleList m_ClientsToAdd; + /** Guards m_EntitiesToAdd */ + cCriticalSection m_CSEntitiesToAdd; + + /** List of entities that are scheduled for adding, waiting for the Tick thread to add them. */ + cEntityList m_EntitiesToAdd; + cWorld(const AString & a_WorldName); virtual ~cWorld(); -- cgit v1.2.3 From af4a21ea0689107b377818574cb07dc4a2e8b755 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 8 Jun 2014 21:58:08 +0200 Subject: Fixed deadlock when moving players to other worlds. Fixes #1039, fixes #851 --- src/World.h | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/World.h') diff --git a/src/World.h b/src/World.h index 4c014a976..abdc3120c 100644 --- a/src/World.h +++ b/src/World.h @@ -284,8 +284,15 @@ public: void CollectPickupsByPlayer(cPlayer * a_Player); - void AddPlayer( cPlayer* a_Player ); - void RemovePlayer( cPlayer* a_Player ); + /** Adds the player to the world. + Uses a queue to store the player object until the Tick thread processes the addition event. + Also adds the player as an entity in the chunkmap, and the player's ClientHandle, if any, for ticking. */ + void AddPlayer(cPlayer * a_Player); + + /** Removes the player from the world. + Removes the player from the addition queue, too, if appropriate. + If the player has a ClientHandle, the ClientHandle is removed from all chunks in the world and will not be ticked by this world anymore. */ + void RemovePlayer(cPlayer * a_Player); /** Calls the callback for each player in the list; returns true if all players processed, false if the callback aborted by returning true */ virtual bool ForEachPlayer(cPlayerListCallback & a_Callback) override; // >> EXPORTED IN MANUALBINDINGS << @@ -933,6 +940,12 @@ private: /** List of entities that are scheduled for adding, waiting for the Tick thread to add them. */ cEntityList m_EntitiesToAdd; + /** Guards m_PlayersToAdd */ + cCriticalSection m_CSPlayersToAdd; + + /** List of players that are scheduled for adding, waiting for the Tick thread to add them. */ + cPlayerList m_PlayersToAdd; + cWorld(const AString & a_WorldName); virtual ~cWorld(); @@ -970,6 +983,10 @@ private: /** Creates a new redstone simulator.*/ cRedstoneSimulator * InitializeRedstoneSimulator(cIniFile & a_IniFile); + + /** Adds the players queued in the m_PlayersToAdd queue into the m_Players list. + Assumes it is called from the Tick thread. */ + void AddQueuedPlayers(void); }; // tolua_export -- cgit v1.2.3 From c3c3782c67265f2844dc66667d3e6bc79a6b25ff Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Wed, 11 Jun 2014 10:33:16 +0100 Subject: Add new IsWeatherWet hook for cauldrons. @madmaxoft can you comment? --- src/World.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/World.h') diff --git a/src/World.h b/src/World.h index abdc3120c..b0fed84ba 100644 --- a/src/World.h +++ b/src/World.h @@ -708,12 +708,23 @@ public: eWeather GetWeather (void) const { return m_Weather; }; bool IsWeatherSunny(void) const { return (m_Weather == wSunny); } + bool IsWeatherSunny(int a_BlockX, int a_BlockZ) const { + return (m_Weather == wSunny) + } bool IsWeatherRain (void) const { return (m_Weather == wRain); } + bool IsWeatherRain (int a_BlockX, int a_BlockZ) const { + return (m_Weather == wRain) && (!IsBiomeNoDownfall(GetBiomeAt(a_BlockX, a_BlockZ))) + } bool IsWeatherStorm(void) const { return (m_Weather == wStorm); } + bool IsWeatherStorm(int a_BlockX, int a_BlockZ) const { + return (m_Weather == wStorm) && (!IsBiomeNoDownfall(GetBiomeAt(a_BlockX, a_BlockZ))) + } /** Returns true if the current weather has any precipitation - rain or storm */ bool IsWeatherWet (void) const { return (m_Weather != wSunny); } - + bool IsWeatherWet (int a_BlockX, int a_BlockZ) const { + return (m_Weather != wSunny) && (!IsBiomeNoDownfall(GetBiomeAt(a_BlockX, a_BlockZ))) + } // tolua_end cChunkGenerator & GetGenerator(void) { return m_Generator; } -- cgit v1.2.3 From c5010ebcc13c29a567755d938dabfa5250de73fc Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Wed, 11 Jun 2014 13:01:52 +0100 Subject: Add DoxyComments to he weather things. Also changed the function names. --- src/World.h | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'src/World.h') diff --git a/src/World.h b/src/World.h index b0fed84ba..ac275b991 100644 --- a/src/World.h +++ b/src/World.h @@ -707,22 +707,39 @@ public: /** Returns the current weather. Instead of comparing values directly to the weather constants, use IsWeatherXXX() functions, if possible */ eWeather GetWeather (void) const { return m_Weather; }; + /** Returns true if the current weather is sun */ bool IsWeatherSunny(void) const { return (m_Weather == wSunny); } - bool IsWeatherSunny(int a_BlockX, int a_BlockZ) const { + + /** Returns true if it is sunny at the specified location. This takes into accunt biomes. */ + bool IsWeatherSunnyAt(int a_BlockX, int a_BlockZ) const + { return (m_Weather == wSunny) } - bool IsWeatherRain (void) const { return (m_Weather == wRain); } - bool IsWeatherRain (int a_BlockX, int a_BlockZ) const { + + /** Returns true if the current weather is rain */ + bool IsWeatherRain(void) const { return (m_Weather == wRain); } + + /** Returns true if it is raining at the specified location. This takes into accunt biomes. */ + bool IsWeatherRainAt (int a_BlockX, int a_BlockZ) const + { return (m_Weather == wRain) && (!IsBiomeNoDownfall(GetBiomeAt(a_BlockX, a_BlockZ))) } + + /** Returns true if the current weather is stormy */ bool IsWeatherStorm(void) const { return (m_Weather == wStorm); } - bool IsWeatherStorm(int a_BlockX, int a_BlockZ) const { + + /** Returns true if the weather is stormy at the specified location. This takes into accunt biomes. */ + bool IsWeatherStormAt(int a_BlockX, int a_BlockZ) const + { return (m_Weather == wStorm) && (!IsBiomeNoDownfall(GetBiomeAt(a_BlockX, a_BlockZ))) } - /** Returns true if the current weather has any precipitation - rain or storm */ - bool IsWeatherWet (void) const { return (m_Weather != wSunny); } - bool IsWeatherWet (int a_BlockX, int a_BlockZ) const { + /** Returns true if the current weather has any precipitation - rain, storm or snow */ + bool IsWeatherWet(void) const { return (m_Weather != wSunny); } + + /** Returns true if it is raining, stormy or snowing at the specified location. This takes into accunt biomes. */ + bool IsWeatherWetAt(int a_BlockX, int a_BlockZ) const + { return (m_Weather != wSunny) && (!IsBiomeNoDownfall(GetBiomeAt(a_BlockX, a_BlockZ))) } // tolua_end -- cgit v1.2.3 From 711113cd2b9deaa2f556c446885e976a79fadcbf Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 11 Jun 2014 13:10:10 +0100 Subject: Updated unnecessary function :/ --- src/World.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/World.h') diff --git a/src/World.h b/src/World.h index ac275b991..11c262e3a 100644 --- a/src/World.h +++ b/src/World.h @@ -710,9 +710,13 @@ public: /** Returns true if the current weather is sun */ bool IsWeatherSunny(void) const { return (m_Weather == wSunny); } - /** Returns true if it is sunny at the specified location. This takes into accunt biomes. */ + /** Returns true if it is sunny at the specified location. This takes into accunt biomes. + This function is identical to IsWeatherSunny except for two extra parameters that aren't used, but bearbin insists :/ + */ bool IsWeatherSunnyAt(int a_BlockX, int a_BlockZ) const { + UNUSED(a_BlockX); + UNUSED(a_BlockZ); return (m_Weather == wSunny) } -- cgit v1.2.3 From c09207cabcecb94b134f92e2dbfdad69da930b43 Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Wed, 11 Jun 2014 13:20:31 +0100 Subject: SMICOLOSL Meant to be semicolons up there. --- src/World.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/World.h') diff --git a/src/World.h b/src/World.h index 11c262e3a..a72904f6a 100644 --- a/src/World.h +++ b/src/World.h @@ -717,7 +717,7 @@ public: { UNUSED(a_BlockX); UNUSED(a_BlockZ); - return (m_Weather == wSunny) + return (m_Weather == wSunny); } /** Returns true if the current weather is rain */ @@ -726,7 +726,7 @@ public: /** Returns true if it is raining at the specified location. This takes into accunt biomes. */ bool IsWeatherRainAt (int a_BlockX, int a_BlockZ) const { - return (m_Weather == wRain) && (!IsBiomeNoDownfall(GetBiomeAt(a_BlockX, a_BlockZ))) + return (m_Weather == wRain) && (!IsBiomeNoDownfall(GetBiomeAt(a_BlockX, a_BlockZ))); } /** Returns true if the current weather is stormy */ @@ -735,7 +735,7 @@ public: /** Returns true if the weather is stormy at the specified location. This takes into accunt biomes. */ bool IsWeatherStormAt(int a_BlockX, int a_BlockZ) const { - return (m_Weather == wStorm) && (!IsBiomeNoDownfall(GetBiomeAt(a_BlockX, a_BlockZ))) + return (m_Weather == wStorm) && (!IsBiomeNoDownfall(GetBiomeAt(a_BlockX, a_BlockZ))); } /** Returns true if the current weather has any precipitation - rain, storm or snow */ @@ -744,7 +744,7 @@ public: /** Returns true if it is raining, stormy or snowing at the specified location. This takes into accunt biomes. */ bool IsWeatherWetAt(int a_BlockX, int a_BlockZ) const { - return (m_Weather != wSunny) && (!IsBiomeNoDownfall(GetBiomeAt(a_BlockX, a_BlockZ))) + return (m_Weather != wSunny) && (!IsBiomeNoDownfall(GetBiomeAt(a_BlockX, a_BlockZ))); } // tolua_end -- cgit v1.2.3 From f7913d3b742e13595e3ded99820a13ade8a3b674 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 11 Jun 2014 13:37:04 +0100 Subject: IsWeatherSunnyAt does something useful :D --- src/World.h | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'src/World.h') diff --git a/src/World.h b/src/World.h index a72904f6a..f9471e881 100644 --- a/src/World.h +++ b/src/World.h @@ -710,20 +710,16 @@ public: /** Returns true if the current weather is sun */ bool IsWeatherSunny(void) const { return (m_Weather == wSunny); } - /** Returns true if it is sunny at the specified location. This takes into accunt biomes. - This function is identical to IsWeatherSunny except for two extra parameters that aren't used, but bearbin insists :/ - */ + /** Returns true if it is sunny at the specified location. This takes into account biomes. */ bool IsWeatherSunnyAt(int a_BlockX, int a_BlockZ) const { - UNUSED(a_BlockX); - UNUSED(a_BlockZ); - return (m_Weather == wSunny); + return (IsWeatherSunny() || IsBiomeNoDownfall(GetBiomeAt(a_BlockX, a_BlockZ))); } /** Returns true if the current weather is rain */ bool IsWeatherRain(void) const { return (m_Weather == wRain); } - /** Returns true if it is raining at the specified location. This takes into accunt biomes. */ + /** Returns true if it is raining at the specified location. This takes into account biomes. */ bool IsWeatherRainAt (int a_BlockX, int a_BlockZ) const { return (m_Weather == wRain) && (!IsBiomeNoDownfall(GetBiomeAt(a_BlockX, a_BlockZ))); @@ -732,7 +728,7 @@ public: /** Returns true if the current weather is stormy */ bool IsWeatherStorm(void) const { return (m_Weather == wStorm); } - /** Returns true if the weather is stormy at the specified location. This takes into accunt biomes. */ + /** Returns true if the weather is stormy at the specified location. This takes into account biomes. */ bool IsWeatherStormAt(int a_BlockX, int a_BlockZ) const { return (m_Weather == wStorm) && (!IsBiomeNoDownfall(GetBiomeAt(a_BlockX, a_BlockZ))); @@ -741,7 +737,7 @@ public: /** Returns true if the current weather has any precipitation - rain, storm or snow */ bool IsWeatherWet(void) const { return (m_Weather != wSunny); } - /** Returns true if it is raining, stormy or snowing at the specified location. This takes into accunt biomes. */ + /** Returns true if it is raining, stormy or snowing at the specified location. This takes into account biomes. */ bool IsWeatherWetAt(int a_BlockX, int a_BlockZ) const { return (m_Weather != wSunny) && (!IsBiomeNoDownfall(GetBiomeAt(a_BlockX, a_BlockZ))); -- cgit v1.2.3 From 1a9467574e462f467dc9e1a9cc45b68c87276968 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 11 Jun 2014 13:40:34 +0100 Subject: Reduced code duplication call @maxmaxoft! calling... call connected (0:20) call ended --- src/World.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/World.h') diff --git a/src/World.h b/src/World.h index f9471e881..7469c1054 100644 --- a/src/World.h +++ b/src/World.h @@ -722,7 +722,7 @@ public: /** Returns true if it is raining at the specified location. This takes into account biomes. */ bool IsWeatherRainAt (int a_BlockX, int a_BlockZ) const { - return (m_Weather == wRain) && (!IsBiomeNoDownfall(GetBiomeAt(a_BlockX, a_BlockZ))); + return (IsWeatherRain() && !IsBiomeNoDownfall(GetBiomeAt(a_BlockX, a_BlockZ))); } /** Returns true if the current weather is stormy */ @@ -731,16 +731,16 @@ public: /** Returns true if the weather is stormy at the specified location. This takes into account biomes. */ bool IsWeatherStormAt(int a_BlockX, int a_BlockZ) const { - return (m_Weather == wStorm) && (!IsBiomeNoDownfall(GetBiomeAt(a_BlockX, a_BlockZ))); + return (IsWeatherStorm() && !IsBiomeNoDownfall(GetBiomeAt(a_BlockX, a_BlockZ))); } /** Returns true if the current weather has any precipitation - rain, storm or snow */ - bool IsWeatherWet(void) const { return (m_Weather != wSunny); } + bool IsWeatherWet(void) const { return !IsWeatherSunny(); } /** Returns true if it is raining, stormy or snowing at the specified location. This takes into account biomes. */ bool IsWeatherWetAt(int a_BlockX, int a_BlockZ) const { - return (m_Weather != wSunny) && (!IsBiomeNoDownfall(GetBiomeAt(a_BlockX, a_BlockZ))); + return (IsWeatherWet() && !IsBiomeNoDownfall(GetBiomeAt(a_BlockX, a_BlockZ))); } // tolua_end -- cgit v1.2.3 From e24830f0b12597896d895855298e8dde5f448b5b Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 11 Jun 2014 13:49:57 +0100 Subject: Compile fix --- src/World.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/World.h') diff --git a/src/World.h b/src/World.h index 7469c1054..45b42b280 100644 --- a/src/World.h +++ b/src/World.h @@ -597,7 +597,7 @@ public: void GrowSugarcane(int a_BlockX, int a_BlockY, int a_BlockZ, int a_NumBlocksToGrow); /** Returns the biome at the specified coords. Reads the biome from the chunk, if loaded, otherwise uses the world generator to provide the biome value */ - EMCSBiome GetBiomeAt(int a_BlockX, int a_BlockZ); + EMCSBiome GetBiomeAt(int a_BlockX, int a_BlockZ) const; /** Sets the biome at the specified coords. Returns true if successful, false if not (chunk not loaded). Doesn't resend the chunk to clients, use ForceSendChunkTo() for that. */ -- cgit v1.2.3 From 70c20d77721f69e9f04a27630a4e4b65c5be601f Mon Sep 17 00:00:00 2001 From: worktycho Date: Wed, 11 Jun 2014 16:23:53 +0100 Subject: Fixed constness --- src/World.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/World.h') diff --git a/src/World.h b/src/World.h index 45b42b280..0a8dcffc4 100644 --- a/src/World.h +++ b/src/World.h @@ -597,7 +597,7 @@ public: void GrowSugarcane(int a_BlockX, int a_BlockY, int a_BlockZ, int a_NumBlocksToGrow); /** Returns the biome at the specified coords. Reads the biome from the chunk, if loaded, otherwise uses the world generator to provide the biome value */ - EMCSBiome GetBiomeAt(int a_BlockX, int a_BlockZ) const; + EMCSBiome GetBiomeAt(int a_BlockX, int a_BlockZ); /** Sets the biome at the specified coords. Returns true if successful, false if not (chunk not loaded). Doesn't resend the chunk to clients, use ForceSendChunkTo() for that. */ @@ -711,7 +711,7 @@ public: bool IsWeatherSunny(void) const { return (m_Weather == wSunny); } /** Returns true if it is sunny at the specified location. This takes into account biomes. */ - bool IsWeatherSunnyAt(int a_BlockX, int a_BlockZ) const + bool IsWeatherSunnyAt(int a_BlockX, int a_BlockZ) { return (IsWeatherSunny() || IsBiomeNoDownfall(GetBiomeAt(a_BlockX, a_BlockZ))); } @@ -720,7 +720,7 @@ public: bool IsWeatherRain(void) const { return (m_Weather == wRain); } /** Returns true if it is raining at the specified location. This takes into account biomes. */ - bool IsWeatherRainAt (int a_BlockX, int a_BlockZ) const + bool IsWeatherRainAt (int a_BlockX, int a_BlockZ) { return (IsWeatherRain() && !IsBiomeNoDownfall(GetBiomeAt(a_BlockX, a_BlockZ))); } @@ -729,7 +729,7 @@ public: bool IsWeatherStorm(void) const { return (m_Weather == wStorm); } /** Returns true if the weather is stormy at the specified location. This takes into account biomes. */ - bool IsWeatherStormAt(int a_BlockX, int a_BlockZ) const + bool IsWeatherStormAt(int a_BlockX, int a_BlockZ) { return (IsWeatherStorm() && !IsBiomeNoDownfall(GetBiomeAt(a_BlockX, a_BlockZ))); } @@ -738,7 +738,7 @@ public: bool IsWeatherWet(void) const { return !IsWeatherSunny(); } /** Returns true if it is raining, stormy or snowing at the specified location. This takes into account biomes. */ - bool IsWeatherWetAt(int a_BlockX, int a_BlockZ) const + bool IsWeatherWetAt(int a_BlockX, int a_BlockZ) { return (IsWeatherWet() && !IsBiomeNoDownfall(GetBiomeAt(a_BlockX, a_BlockZ))); } -- cgit v1.2.3 From f76420ac55edd82e06042a93927e275e5799d59f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 13 Jun 2014 09:38:25 +0200 Subject: Removed an unused fwd declaration. --- src/World.h | 1 - 1 file changed, 1 deletion(-) (limited to 'src/World.h') diff --git a/src/World.h b/src/World.h index 0a8dcffc4..3e63e2b8c 100644 --- a/src/World.h +++ b/src/World.h @@ -47,7 +47,6 @@ class cFlowerPotEntity; class cFurnaceEntity; class cNoteEntity; class cMobHeadEntity; -class cMobCensus; class cCompositeChat; class cCuboid; -- cgit v1.2.3