Files
MinecraftConsoles/Minecraft.World/ChunkStorageProfileDecorator.cpp
ModMaker101 a9be52c41a Project modernization (#630)
* Fixed boats falling and a TP glitch #266

* Replaced every C-style cast with C++ ones

* Replaced every C-style cast with C++ ones

* Fixed boats falling and a TP glitch #266

* Updated NULL to nullptr and fixing some type issues

* Modernized and fixed a few bugs

- Replaced most instances of `NULL` with `nullptr`.
- Replaced most `shared_ptr(new ...)` with `make_shared`.
- Removed the `nullptr` macro as it was interfering with the actual nullptr keyword in some instances.

* Fixing more conflicts

* Replace int loops with size_t and start work on overrides
2026-03-08 09:56:03 +07:00

71 lines
1.9 KiB
C++

#include "stdafx.h"
#include "System.h"
#include "ChunkStorageProfileDecorator.h"
ChunkStorageProfilerDecorator::ChunkStorageProfilerDecorator(ChunkStorage *capsulated) :
timeSpentLoading(0), loadCount(0), timeSpentSaving(0), saveCount(0), counter(0)
{
this->capsulated = capsulated;
}
LevelChunk *ChunkStorageProfilerDecorator::load(Level *level, int x, int z)
{
int64_t nanoTime = System::nanoTime();
LevelChunk *chunk = capsulated->load(level, x, z);
timeSpentLoading += System::nanoTime() - nanoTime;
loadCount++;
return chunk;
}
void ChunkStorageProfilerDecorator::save(Level *level, LevelChunk *levelChunk)
{
int64_t nanoTime = System::nanoTime();
capsulated->save(level, levelChunk);
timeSpentSaving += System::nanoTime() - nanoTime;
saveCount++;
}
void ChunkStorageProfilerDecorator::saveEntities(Level *level, LevelChunk *levelChunk)
{
capsulated->saveEntities(level, levelChunk);
}
void ChunkStorageProfilerDecorator::tick()
{
char buf[256];
capsulated->tick();
counter++;
if (counter > 500)
{
if (loadCount > 0)
{
#ifndef _CONTENT_PACKAGE
#ifdef __PSVITA__
sprintf(buf,"Average load time: %f (%lld)",0.000001 * (double) timeSpentLoading / (double) loadCount, loadCount);
#else
sprintf(buf,"Average load time: %f (%I64d)",0.000001 * static_cast<double>(timeSpentLoading) / static_cast<double>(loadCount), loadCount);
#endif
app.DebugPrintf(buf);
#endif
}
if (saveCount > 0)
{
#ifndef _CONTENT_PACKAGE
#ifdef __PSVITA__
sprintf(buf,"Average save time: %f (%lld)",0.000001 * (double) timeSpentSaving / (double) loadCount, loadCount);
#else
sprintf(buf,"Average save time: %f (%I64d)",0.000001 * static_cast<double>(timeSpentSaving) / static_cast<double>(loadCount), loadCount);
#endif
app.DebugPrintf(buf);
#endif
}
counter = 0;
}
}
void ChunkStorageProfilerDecorator::flush()
{
capsulated->flush();
}