Permalink
Comparing changes
Open a pull request
- 2 commits
- 4 files changed
- 0 commit comments
- 1 contributor
Unified
Split
Showing
with
71 additions
and 14 deletions.
- +16 −8 Tools/AnvilStats/Processor.cpp
- +8 −2 Tools/AnvilStats/Processor.h
- +44 −4 Tools/AnvilStats/Statistics.cpp
- +3 −0 Tools/AnvilStats/Statistics.h
| @@ -28,18 +28,28 @@ cProcessor::cThread::cThread(cCallback & a_Callback, cProcessor & a_ParentProces | ||
| m_Callback(a_Callback), | ||
| m_ParentProcessor(a_ParentProcessor) | ||
| { | ||
| LOG("Created a new thread: %p", this); | ||
| super::Start(); | ||
| } | ||
| void cProcessor::cThread::WaitForStart(void) | ||
| { | ||
| m_HasStarted.Wait(); | ||
| } | ||
| void cProcessor::cThread::Execute(void) | ||
| { | ||
| LOG("Started a new thread: %d", cIsThread::GetCurrentID()); | ||
| LOG("Started a new thread: %p, ID %d", this, cIsThread::GetCurrentID()); | ||
| m_ParentProcessor.m_ThreadsHaveStarted.Set(); | ||
| m_HasStarted.Set(); | ||
| for (;;) | ||
| { | ||
| @@ -52,7 +62,7 @@ void cProcessor::cThread::Execute(void) | ||
| ProcessFile(FileName); | ||
| } // for-ever | ||
| LOG("Thread %d terminated", cIsThread::GetCurrentID()); | ||
| LOG("Thread %p (ID %d) terminated", this, cIsThread::GetCurrentID()); | ||
| } | ||
| @@ -522,20 +532,18 @@ void cProcessor::ProcessWorld(const AString & a_WorldFolder, cCallbackFactory & | ||
| #endif // _DEBUG | ||
| //*/ | ||
| // Start all the threads: | ||
| for (int i = 0; i < NumThreads; i++) | ||
| { | ||
| cCallback * Callback = a_CallbackFactory.GetNewCallback(); | ||
| m_Threads.push_back(new cThread(*Callback, *this)); | ||
| } | ||
| // Wait for the first thread to start processing: | ||
| m_ThreadsHaveStarted.Wait(); | ||
| // Wait for all threads to finish | ||
| // simply by calling each thread's destructor sequentially | ||
| // Wait for all threads to finish: | ||
| LOG("Waiting for threads to finish"); | ||
| for (cThreads::iterator itr = m_Threads.begin(), end = m_Threads.end(); itr != end; ++itr) | ||
| { | ||
| (*itr)->WaitForStart(); | ||
| delete *itr; | ||
| } // for itr - m_Threads[] | ||
| LOG("Processor finished"); | ||
| @@ -30,6 +30,7 @@ class cProcessor | ||
| cCallback & m_Callback; | ||
| cProcessor & m_ParentProcessor; | ||
| cEvent m_HasStarted; | ||
| // cIsThread override: | ||
| virtual void Execute(void) override; | ||
| @@ -48,6 +49,9 @@ class cProcessor | ||
| public: | ||
| cThread(cCallback & a_Callback, cProcessor & a_ParentProcessor); | ||
| /** Waits until the thread starts processing the callback code. */ | ||
| void WaitForStart(void); | ||
| } ; | ||
| typedef std::vector<cThread *> cThreads; | ||
| @@ -65,10 +69,12 @@ class cProcessor | ||
| AStringList m_FileQueue; | ||
| cThreads m_Threads; | ||
| cEvent m_ThreadsHaveStarted; // This is signalled by each thread to notify the parent thread that it can start waiting for those threads | ||
| /** Populates m_FileQueue with Anvil files from the specified folder. */ | ||
| void PopulateFileQueue(const AString & a_WorldFolder); | ||
| /** Returns one filename from m_FileQueue, and removes the name from the queue. */ | ||
| AString GetOneFileName(void); | ||
| } ; | ||
| @@ -342,6 +342,8 @@ cStatisticsFactory::~cStatisticsFactory() | ||
| SaveBiomeBlockTypes(); | ||
| LOG(" Spawners.xls"); | ||
| SaveSpawners(); | ||
| LOG(" PerHeightSpawners.xls"); | ||
| SavePerHeightSpawners(); | ||
| } | ||
| @@ -429,7 +431,7 @@ void cStatisticsFactory::SavePerHeightBlockTypes(void) | ||
| } | ||
| // Write header: | ||
| f.Printf("Blocks 0 - 127:\nHeight\t"); | ||
| f.Printf("Blocks 0 - 127:\nHeight"); | ||
| for (int i = 0; i < 128; i++) | ||
| { | ||
| f.Printf("\t%s(%d)", GetBlockTypeString(i), i); | ||
| @@ -442,14 +444,14 @@ void cStatisticsFactory::SavePerHeightBlockTypes(void) | ||
| f.Printf("%d", y); | ||
| for (int BlockType = 0; BlockType < 128; BlockType++) | ||
| { | ||
| f.Printf("\t%d", m_CombinedStats.m_PerHeightBlockCounts[y][BlockType]); | ||
| f.Printf("\t%llu", m_CombinedStats.m_PerHeightBlockCounts[y][BlockType]); | ||
| } // for BlockType | ||
| f.Printf("\n"); | ||
| } // for y - height (0 - 127) | ||
| f.Printf("\n"); | ||
| // Write second header: | ||
| f.Printf("Blocks 128 - 255:\nHeight\t"); | ||
| f.Printf("Blocks 128 - 255:\nHeight"); | ||
| for (int i = 128; i < 256; i++) | ||
| { | ||
| f.Printf("\t%s(%d)", GetBlockTypeString(i), i); | ||
| @@ -462,7 +464,7 @@ void cStatisticsFactory::SavePerHeightBlockTypes(void) | ||
| f.Printf("%d", y); | ||
| for (int BlockType = 128; BlockType < 256; BlockType++) | ||
| { | ||
| f.Printf("\t%d", m_CombinedStats.m_PerHeightBlockCounts[y][BlockType]); | ||
| f.Printf("\t%llu", m_CombinedStats.m_PerHeightBlockCounts[y][BlockType]); | ||
| } // for BlockType | ||
| f.Printf("\n"); | ||
| } // for y - height (0 - 127) | ||
| @@ -598,3 +600,41 @@ void cStatisticsFactory::SaveSpawners(void) | ||
| void cStatisticsFactory::SavePerHeightSpawners(void) | ||
| { | ||
| cFile f; | ||
| if (!f.Open("PerHeightSpawners.xls", cFile::fmWrite)) | ||
| { | ||
| LOG("Cannot write to file PerHeightSpawners.xls. Statistics not written."); | ||
| return; | ||
| } | ||
| // Write header: | ||
| f.Printf("Height\tTotal"); | ||
| for (int i = 0; i < entMax; i++) | ||
| { | ||
| f.Printf("\t%s", GetEntityTypeString((eEntityType)i)); | ||
| } | ||
| f.Printf("\n"); | ||
| // Write individual lines: | ||
| for (int y = 0; y < 256; y++) | ||
| { | ||
| UInt64 Total = 0; | ||
| for (int i = 0; i < entMax; i++) | ||
| { | ||
| Total += m_CombinedStats.m_PerHeightSpawners[y][i]; | ||
| } | ||
| f.Printf("%d\t%llu", y, Total); | ||
| for (int i = 0; i < entMax; i++) | ||
| { | ||
| f.Printf("\t%llu", m_CombinedStats.m_PerHeightSpawners[y][i]); | ||
| } | ||
| f.Printf("\n"); | ||
| } | ||
| } | ||
| @@ -76,6 +76,8 @@ class cStatistics : | ||
| virtual bool OnEmptySection(unsigned char a_Y) override; | ||
| virtual bool OnSectionsFinished(void) override { return false; } // continue processing | ||
| virtual bool OnEntity( | ||
| const AString & a_EntityType, | ||
| double a_PosX, double a_PosY, double a_PosZ, | ||
| @@ -134,6 +136,7 @@ class cStatisticsFactory : | ||
| void SaveBiomeBlockTypes(void); | ||
| void SaveStatistics(void); | ||
| void SaveSpawners(void); | ||
| void SavePerHeightSpawners(void); | ||
| } ; | ||