From 32bc9693390c7a2b662ec55a17b338fe68a720eb Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 30 Aug 2013 19:38:21 +0200 Subject: AnvilStats: Added the callback for region begin and end. --- Tools/AnvilStats/Callback.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'Tools/AnvilStats/Callback.h') diff --git a/Tools/AnvilStats/Callback.h b/Tools/AnvilStats/Callback.h index 83b330651..eed51a41c 100644 --- a/Tools/AnvilStats/Callback.h +++ b/Tools/AnvilStats/Callback.h @@ -22,17 +22,20 @@ class cParsedNBT; /** The base class for all chunk-processor callbacks, declares the interface. The processor calls each virtual function in the order they are declared here with the specified args. -If the function returns true, the processor moves on to next chunk and starts calling the callbacks again from start with -the new chunk data. +If the function returns true, the processor doesn't process the data item, moves on to the next chunk +and starts calling the callbacks again from start with the new chunk data. So if a statistics collector doesn't need data decompression at all, it can stop the processor from doing so early-enough and still get meaningful data. -A callback is guaranteed to run in a single thread and always the same thread. +A callback is guaranteed to run in a single thread and always the same thread for the same chunk. A callback is guaranteed to run on all chunks in a region and one region is guaranteed to be handled by only callback. */ class cCallback abstract { public: virtual ~cCallback() {} // Force a virtual destructor in each descendant + + /// Called when a new region file is about to be opened; by default allow the region + virtual bool OnNewRegion(int a_RegionX, int a_RegionZ) { return false; } /// Called to inform the stats module of the chunk coords for newly processing chunk virtual bool OnNewChunk(int a_ChunkX, int a_ChunkZ) = 0; @@ -118,6 +121,9 @@ public: int a_TicksLeft, int a_PosX, int a_PosY, int a_PosZ ) { return true; } + + /// Called after the entire region file has been processed. No more callbacks for this region will be called. No processing by default + virtual void OnRegionFinished(int a_RegionX, int a_RegionZ) {} } ; typedef std::vector cCallbacks; -- cgit v1.2.3 From b1f8b6e4c47556799f7fe753c87960f60d003153 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 30 Aug 2013 20:45:29 +0200 Subject: AnvilStats: Callbacks can now use CALLBACK_CONTINUE and CALLBACK_ABORT instead of bool return values. This makes the code slightly easier to understand. --- Tools/AnvilStats/Callback.h | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'Tools/AnvilStats/Callback.h') diff --git a/Tools/AnvilStats/Callback.h b/Tools/AnvilStats/Callback.h index eed51a41c..eda4a8478 100644 --- a/Tools/AnvilStats/Callback.h +++ b/Tools/AnvilStats/Callback.h @@ -32,37 +32,43 @@ A callback is guaranteed to run on all chunks in a region and one region is guar class cCallback abstract { public: + enum + { + CALLBACK_CONTINUE = false, + CALLBACK_ABORT = true, + } ; + virtual ~cCallback() {} // Force a virtual destructor in each descendant /// Called when a new region file is about to be opened; by default allow the region - virtual bool OnNewRegion(int a_RegionX, int a_RegionZ) { return false; } + virtual bool OnNewRegion(int a_RegionX, int a_RegionZ) { return CALLBACK_CONTINUE; } /// Called to inform the stats module of the chunk coords for newly processing chunk virtual bool OnNewChunk(int a_ChunkX, int a_ChunkZ) = 0; /// Called to inform about the chunk's data offset in the file (chunk mini-header), the number of sectors it uses and the timestamp field value - virtual bool OnHeader(int a_FileOffset, unsigned char a_NumSectors, int a_Timestamp) { return true; } + virtual bool OnHeader(int a_FileOffset, unsigned char a_NumSectors, int a_Timestamp) { return CALLBACK_ABORT; } /// Called to inform of the compressed chunk data size and position in the file (offset from file start to the actual data) - virtual bool OnCompressedDataSizePos(int a_CompressedDataSize, int a_DataOffset, char a_CompressionMethod) { return true; } + virtual bool OnCompressedDataSizePos(int a_CompressedDataSize, int a_DataOffset, char a_CompressionMethod) { return CALLBACK_ABORT; } /// Just in case you wanted to process the NBT yourself ;) - virtual bool OnDecompressedData(const char * a_DecompressedNBT, int a_DataSize) { return true; } + virtual bool OnDecompressedData(const char * a_DecompressedNBT, int a_DataSize) { return CALLBACK_ABORT; } /// The chunk's NBT should specify chunk coords, these are sent here: - virtual bool OnRealCoords(int a_ChunkX, int a_ChunkZ) { return true; } + virtual bool OnRealCoords(int a_ChunkX, int a_ChunkZ) { return CALLBACK_ABORT; } /// The chunk contains a LastUpdate value specifying the last tick in which it was saved. - virtual bool OnLastUpdate(Int64 a_LastUpdate) { return true; } + virtual bool OnLastUpdate(Int64 a_LastUpdate) { return CALLBACK_ABORT; } - virtual bool OnTerrainPopulated(bool a_Populated) { return true; } + virtual bool OnTerrainPopulated(bool a_Populated) { return CALLBACK_ABORT; } - virtual bool OnBiomes(const unsigned char * a_BiomeData) { return true; } + virtual bool OnBiomes(const unsigned char * a_BiomeData) { return CALLBACK_ABORT; } /** Called when a heightmap for the chunk is read from the file. Note that the heightmap is given in big-endian ints, so if you want it, you need to ntohl() it first! */ - virtual bool OnHeightMap(const int * a_HeightMapBE) { return true; } + virtual bool OnHeightMap(const int * a_HeightMapBE) { return CALLBACK_ABORT; } /** If there is data for the section, this callback is called; otherwise OnEmptySection() is called instead. All OnSection() callbacks are called first, and only then all the remaining sections are reported in OnEmptySection(). @@ -74,16 +80,16 @@ public: const NIBBLETYPE * a_BlockMeta, const NIBBLETYPE * a_BlockLight, const NIBBLETYPE * a_BlockSkyLight - ) { return true; } + ) { return CALLBACK_ABORT; } /** If there is no data for a section, this callback is called; otherwise OnSection() is called instead. OnEmptySection() callbacks are called after all OnSection() callbacks. */ - virtual bool OnEmptySection(unsigned char a_Y) { return false; } + virtual bool OnEmptySection(unsigned char a_Y) { return CALLBACK_CONTINUE; } /** Called after all sections have been processed via either OnSection() or OnEmptySection(). */ - virtual bool OnSectionsFinished(void) { return true; } + virtual bool OnSectionsFinished(void) { return CALLBACK_ABORT; } /** Called for each entity in the chunk. Common parameters are parsed from the NBT. @@ -101,7 +107,7 @@ public: char a_IsOnGround, cParsedNBT & a_NBT, int a_NBTTag - ) { return true; } + ) { return CALLBACK_ABORT; } /** Called for each tile entity in the chunk. Common parameters are parsed from the NBT. @@ -113,14 +119,14 @@ public: int a_PosX, int a_PosY, int a_PosZ, cParsedNBT & a_NBT, int a_NBTTag - ) { return true; } + ) { return CALLBACK_ABORT; } /// Called for each tile tick in the chunk virtual bool OnTileTick( int a_BlockType, int a_TicksLeft, int a_PosX, int a_PosY, int a_PosZ - ) { return true; } + ) { return CALLBACK_ABORT; } /// Called after the entire region file has been processed. No more callbacks for this region will be called. No processing by default virtual void OnRegionFinished(int a_RegionX, int a_RegionZ) {} -- cgit v1.2.3