AnvilStats: Added the callback for region begin and end.
This commit is contained in:
parent
1c5b571633
commit
32bc969339
|
@ -15,6 +15,7 @@ Possible usage:
|
||||||
- count the per-chunk density of specific blocks
|
- count the per-chunk density of specific blocks
|
||||||
- count the per-chunk density of dungeons, by measuring the number of zombie/skeleton/regularspider spawners
|
- count the per-chunk density of dungeons, by measuring the number of zombie/skeleton/regularspider spawners
|
||||||
- count the per-chunk-per-biome density of trees, by measuring the number of dirt-log vertical transitions, correlating to biome data
|
- count the per-chunk-per-biome density of trees, by measuring the number of dirt-log vertical transitions, correlating to biome data
|
||||||
|
- draw a vertical map of the world based on a specific measured value (biome, elevation, ...)
|
||||||
|
|
||||||
This project is Windows-only, although it shouldn't be too difficult to make it portable.
|
This project is Windows-only, although it shouldn't be too difficult to make it portable.
|
||||||
|
|
||||||
|
|
|
@ -22,17 +22,20 @@ class cParsedNBT;
|
||||||
|
|
||||||
/** The base class for all chunk-processor callbacks, declares the interface.
|
/** 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.
|
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
|
If the function returns true, the processor doesn't process the data item, moves on to the next chunk
|
||||||
the new chunk data.
|
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
|
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.
|
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.
|
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
|
class cCallback abstract
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~cCallback() {} // Force a virtual destructor in each descendant
|
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
|
/// Called to inform the stats module of the chunk coords for newly processing chunk
|
||||||
virtual bool OnNewChunk(int a_ChunkX, int a_ChunkZ) = 0;
|
virtual bool OnNewChunk(int a_ChunkX, int a_ChunkZ) = 0;
|
||||||
|
@ -118,6 +121,9 @@ public:
|
||||||
int a_TicksLeft,
|
int a_TicksLeft,
|
||||||
int a_PosX, int a_PosY, int a_PosZ
|
int a_PosX, int a_PosY, int a_PosZ
|
||||||
) { return true; }
|
) { 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<cCallback *> cCallbacks;
|
typedef std::vector<cCallback *> cCallbacks;
|
||||||
|
|
|
@ -76,6 +76,12 @@ void cProcessor::cThread::ProcessFile(const AString & a_FileName)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_Callback.OnNewRegion(RegionX, RegionZ))
|
||||||
|
{
|
||||||
|
// Callback doesn't want the region file processed
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
cFile f;
|
cFile f;
|
||||||
if (!f.Open(a_FileName, cFile::fmRead))
|
if (!f.Open(a_FileName, cFile::fmRead))
|
||||||
{
|
{
|
||||||
|
@ -92,6 +98,8 @@ void cProcessor::cThread::ProcessFile(const AString & a_FileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
ProcessFileData(FileContents.data(), FileContents.size(), RegionX * 32, RegionZ * 32);
|
ProcessFileData(FileContents.data(), FileContents.size(), RegionX * 32, RegionZ * 32);
|
||||||
|
|
||||||
|
m_Callback.OnRegionFinished(RegionX, RegionZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue