From c0b62ef139a65ca648135fb6999e6623438fdd71 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 24 Jul 2014 18:32:05 +0200 Subject: Added a queue for setting chunk data. Fixes #1196. --- src/World.h | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'src/World.h') diff --git a/src/World.h b/src/World.h index 2346ac523..6613b495a 100644 --- a/src/World.h +++ b/src/World.h @@ -49,9 +49,14 @@ class cNoteEntity; class cMobHeadEntity; class cCompositeChat; class cCuboid; +class cSetChunkData; + typedef std::list< cPlayer * > cPlayerList; +typedef SharedPtr cSetChunkDataPtr; // TODO: Change to unique_ptr once we go C++11 +typedef std::vector cSetChunkDataPtrs; + typedef cItemCallback cPlayerListCallback; typedef cItemCallback cEntityCallback; typedef cItemCallback cChestCallback; @@ -246,24 +251,9 @@ public: void MarkChunkSaving(int a_ChunkX, int a_ChunkZ); void MarkChunkSaved (int a_ChunkX, int a_ChunkZ); - /** Sets the chunk data as either loaded from the storage or generated. - a_BlockLight and a_BlockSkyLight are optional, if not present, chunk will be marked as unlighted. - a_BiomeMap is optional, if not present, biomes will be calculated by the generator - a_HeightMap is optional, if not present, will be calculated. - If a_MarkDirty is set, the chunk is set as dirty (used after generating) - */ - void SetChunkData( - int a_ChunkX, int a_ChunkZ, - const BLOCKTYPE * a_BlockTypes, - const NIBBLETYPE * a_BlockMeta, - const NIBBLETYPE * a_BlockLight, - const NIBBLETYPE * a_BlockSkyLight, - const cChunkDef::HeightMap * a_HeightMap, - const cChunkDef::BiomeMap * a_BiomeMap, - cEntityList & a_Entities, - cBlockEntityList & a_BlockEntities, - bool a_MarkDirty - ); + /** Puts the chunk data into a queue to be set into the chunkmap in the tick thread. + If the chunk data doesn't contain valid biomes, the biomes are calculated before adding the data into the queue. */ + void QueueSetChunkData(const cSetChunkDataPtr & a_SetChunkData); void ChunkLighted( int a_ChunkX, int a_ChunkZ, @@ -969,6 +959,12 @@ private: /** List of players that are scheduled for adding, waiting for the Tick thread to add them. */ cPlayerList m_PlayersToAdd; + + /** CS protecting m_SetChunkDataQueue. */ + cCriticalSection m_CSSetChunkDataQueue; + + /** Queue for the chunk data to be set into m_ChunkMap by the tick thread. Protected by m_CSSetChunkDataQueue */ + cSetChunkDataPtrs m_SetChunkDataQueue; cWorld(const AString & a_WorldName); @@ -1011,6 +1007,10 @@ private: /** 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); + + /** Sets the specified chunk data into the chunkmap. Called in the tick thread. + Modifies the a_SetChunkData - moves the entities contained in it into the chunk. */ + void SetChunkData(cSetChunkData & a_SetChunkData); }; // tolua_export -- cgit v1.2.3