[Debugging] Slightly optimize zb writing
This commit is contained in:
parent
403974b9cc
commit
336a891d26
@ -7,7 +7,8 @@ namespace Assets
|
||||
AssertSize(Game::FxWorld, 116);
|
||||
|
||||
Utils::Stream* buffer = builder->getBuffer();
|
||||
SAVE_LOG_ENTER("FxWorld");
|
||||
SaveLogEnter("FxWorld");
|
||||
|
||||
Game::FxWorld* asset = header.fxWorld;
|
||||
Game::FxWorld* dest = buffer->dest<Game::FxWorld>();
|
||||
buffer->save(asset);
|
||||
@ -152,6 +153,8 @@ namespace Assets
|
||||
Utils::Stream::ClearPointer(&dest->glassSys.initGeoData);
|
||||
}
|
||||
}
|
||||
|
||||
SaveLogExit();
|
||||
}
|
||||
void IFxWorld::mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
|
||||
{
|
||||
|
@ -113,7 +113,7 @@ namespace Assets
|
||||
AssertSize(Game::GfxWorldDpvsPlanes, 16);
|
||||
|
||||
Utils::Stream* buffer = builder->getBuffer();
|
||||
SAVE_LOG_ENTER("GfxWorldDpvsPlanes");
|
||||
SaveLogEnter("GfxWorldDpvsPlanes");
|
||||
|
||||
if (asset->planes)
|
||||
{
|
||||
@ -150,13 +150,13 @@ namespace Assets
|
||||
}
|
||||
|
||||
buffer->popBlock();
|
||||
SAVE_LOG_EXIT();
|
||||
SaveLogExit();
|
||||
}
|
||||
|
||||
void IGfxWorld::saveGfxWorldDraw(Game::GfxWorldDraw* asset, Game::GfxWorldDraw* dest, Components::ZoneBuilder::Zone* builder)
|
||||
{
|
||||
AssertSize(Game::GfxWorldDraw, 72);
|
||||
SAVE_LOG_ENTER("GfxWorldDraw");
|
||||
SaveLogEnter("GfxWorldDraw");
|
||||
|
||||
Utils::Stream* buffer = builder->getBuffer();
|
||||
|
||||
@ -282,7 +282,7 @@ namespace Assets
|
||||
Utils::Stream::ClearPointer(&dest->indices);
|
||||
}
|
||||
|
||||
SAVE_LOG_EXIT();
|
||||
SaveLogExit();
|
||||
}
|
||||
|
||||
void IGfxWorld::saveGfxLightGrid(Game::GfxLightGrid* asset, Game::GfxLightGrid* dest, Components::ZoneBuilder::Zone* builder)
|
||||
@ -290,7 +290,7 @@ namespace Assets
|
||||
AssertSize(Game::GfxLightGrid, 56);
|
||||
|
||||
Utils::Stream* buffer = builder->getBuffer();
|
||||
SAVE_LOG_ENTER("GfxLightGrid");
|
||||
SaveLogEnter("GfxLightGrid");
|
||||
|
||||
if (asset->rowDataStart)
|
||||
{
|
||||
@ -323,14 +323,14 @@ namespace Assets
|
||||
buffer->saveArray(asset->colors, asset->colorCount);
|
||||
Utils::Stream::ClearPointer(&dest->colors);
|
||||
}
|
||||
SAVE_LOG_EXIT();
|
||||
|
||||
SaveLogExit();
|
||||
}
|
||||
|
||||
void IGfxWorld::savesunflare_t(Game::sunflare_t* asset, Game::sunflare_t* dest, Components::ZoneBuilder::Zone* builder)
|
||||
{
|
||||
AssertSize(Game::sunflare_t, 96);
|
||||
|
||||
SAVE_LOG_ENTER("sunflare_t");
|
||||
SaveLogEnter("sunflare_t");
|
||||
|
||||
if (asset->spriteMaterial)
|
||||
{
|
||||
@ -342,7 +342,7 @@ namespace Assets
|
||||
dest->flareMaterial = builder->requireAsset(Game::XAssetType::ASSET_TYPE_MATERIAL, asset->flareMaterial->name).material;
|
||||
}
|
||||
|
||||
SAVE_LOG_EXIT();
|
||||
SaveLogExit();
|
||||
}
|
||||
|
||||
void IGfxWorld::saveGfxWorldDpvsStatic(Game::GfxWorld* world, Game::GfxWorldDpvsStatic* asset, Game::GfxWorldDpvsStatic* dest, int /*planeCount*/, Components::ZoneBuilder::Zone* builder)
|
||||
@ -350,7 +350,7 @@ namespace Assets
|
||||
AssertSize(Game::GfxWorldDpvsStatic, 108);
|
||||
|
||||
Utils::Stream* buffer = builder->getBuffer();
|
||||
SAVE_LOG_ENTER("GfxWorldDpvsStatic");
|
||||
SaveLogEnter("GfxWorldDpvsStatic");
|
||||
|
||||
buffer->pushBlock(Game::XFILE_BLOCK_RUNTIME);
|
||||
|
||||
@ -464,7 +464,7 @@ namespace Assets
|
||||
}
|
||||
|
||||
buffer->popBlock();
|
||||
SAVE_LOG_EXIT();
|
||||
SaveLogExit();
|
||||
}
|
||||
|
||||
void IGfxWorld::saveGfxWorldDpvsDynamic(Game::GfxWorldDpvsDynamic* asset, Game::GfxWorldDpvsDynamic* dest, Components::ZoneBuilder::Zone* builder)
|
||||
@ -472,7 +472,7 @@ namespace Assets
|
||||
AssertSize(Game::GfxWorldDpvsDynamic, 48);
|
||||
|
||||
Utils::Stream* buffer = builder->getBuffer();
|
||||
SAVE_LOG_ENTER("GfxWorldDpvsDynamic");
|
||||
SaveLogEnter("GfxWorldDpvsDynamic");
|
||||
|
||||
buffer->pushBlock(Game::XFILE_BLOCK_RUNTIME);
|
||||
|
||||
@ -505,7 +505,7 @@ namespace Assets
|
||||
}
|
||||
|
||||
buffer->popBlock();
|
||||
SAVE_LOG_EXIT();
|
||||
SaveLogExit();
|
||||
}
|
||||
|
||||
void IGfxWorld::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
|
||||
@ -513,7 +513,8 @@ namespace Assets
|
||||
AssertSize(Game::GfxWorld, 628);
|
||||
|
||||
Utils::Stream* buffer = builder->getBuffer();
|
||||
SAVE_LOG_ENTER("GfxWorld");
|
||||
SaveLogEnter("GfxWorld");
|
||||
|
||||
Game::GfxWorld* asset = header.gfxWorld;
|
||||
Game::GfxWorld* dest = buffer->dest<Game::GfxWorld>();
|
||||
buffer->save(asset);
|
||||
@ -869,6 +870,6 @@ namespace Assets
|
||||
}
|
||||
|
||||
buffer->popBlock();
|
||||
SAVE_LOG_EXIT();
|
||||
SaveLogExit();
|
||||
}
|
||||
}
|
||||
|
@ -148,17 +148,6 @@ using namespace std::literals;
|
||||
#define AssertSize(x, size) static_assert(sizeof(x) == size, STRINGIZE(x) " structure has an invalid size.")
|
||||
#define AssertOffset(x, y, offset) static_assert(offsetof(x, y) == offset, STRINGIZE(x) "::" STRINGIZE(y) " is not at the right offset.")
|
||||
|
||||
// write logs for ZoneBuilder
|
||||
#ifndef DEBUG
|
||||
#define SAVE_LOG_ENTER(x)
|
||||
#define SAVE_LOG_EXIT()
|
||||
#define SAVE_LOG_WRITE(size)
|
||||
#else
|
||||
#define SAVE_LOG_ENTER(x) builder->getBuffer()->enterStruct(x)
|
||||
#define SAVE_LOG_EXIT() builder->getBuffer()->leaveStruct()
|
||||
#define SAVE_LOG_WRITE(size) this->logWrite(size)
|
||||
#endif
|
||||
|
||||
// Resource stuff
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
|
@ -62,13 +62,10 @@ namespace Utils
|
||||
Stream::Stream() : criticalSectionState(0)
|
||||
{
|
||||
memset(this->blockSize, 0, sizeof(this->blockSize));
|
||||
#ifdef DEBUG
|
||||
|
||||
if (this->writeLog) return;
|
||||
if (fopen_s(&this->writeLog, "userraw/logs/zb_writes.log", "w"))
|
||||
{
|
||||
Components::Logger::Print("WARNING: Couldn't open write log. Writes from ZoneBuilder will not be logged.\n");
|
||||
}
|
||||
#ifdef DEBUG
|
||||
this->structLevel = 0;
|
||||
Utils::IO::WriteFile("userraw/logs/zb_writes.log", "", false);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -85,13 +82,6 @@ namespace Utils
|
||||
{
|
||||
MessageBoxA(0, Utils::String::VA("Invalid critical section state '%i' for stream destruction!", this->criticalSectionState), "WARNING", MB_ICONEXCLAMATION);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
if (this->writeLog)
|
||||
{
|
||||
fclose(this->writeLog);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
size_t Stream::length()
|
||||
@ -130,9 +120,6 @@ namespace Utils
|
||||
|
||||
this->buffer.append(static_cast<const char*>(_str), size * count);
|
||||
|
||||
// log the write for zonebuilder debugging
|
||||
SAVE_LOG_WRITE(size * count);
|
||||
|
||||
if (this->data() != data && this->isCriticalSection())
|
||||
{
|
||||
MessageBoxA(0, "Stream reallocation during critical operations not permitted!\nPlease increase the initial memory size or reallocate memory during non-critical sections!", "ERROR", MB_ICONERROR);
|
||||
@ -247,6 +234,12 @@ namespace Utils
|
||||
{
|
||||
this->blockSize[stream] += size;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
std::string data = fmt::sprintf("%*s%d\n", this->structLevel, "", size);
|
||||
if(stream == Game::XFILE_BLOCK_RUNTIME) data = fmt::sprintf("%*s(%d)\n", this->structLevel, "", size);
|
||||
Utils::IO::WriteFile("userraw/logs/zb_writes.log", data, true);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Stream::increaseBlockSize(unsigned int size)
|
||||
@ -329,36 +322,23 @@ namespace Utils
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
FILE* Stream::writeLog = nullptr;
|
||||
int Stream::structLevel = 0;
|
||||
|
||||
void Stream::enterStruct(const char* structName)
|
||||
{
|
||||
if (!this->writeLog) return;
|
||||
fprintf(this->writeLog, "%*s%s\n", this->structLevel++, "", structName);
|
||||
if (this->structLevel >= 0)
|
||||
{
|
||||
Utils::IO::WriteFile("userraw/logs/zb_writes.log", fmt::sprintf("%*s%s\n", this->structLevel++, "", structName), true);
|
||||
}
|
||||
}
|
||||
|
||||
void Stream::leaveStruct()
|
||||
{
|
||||
if (!this->writeLog) return;
|
||||
this->structLevel--;
|
||||
|
||||
if (this->structLevel < 0) {
|
||||
Components::Logger::Print("Stream::exitStruct underflow! All following writes will not be logged!\n");
|
||||
fclose(this->writeLog);
|
||||
this->writeLog = nullptr;
|
||||
if (--this->structLevel < 0)
|
||||
{
|
||||
Components::Logger::Print("Stream::leaveStruct underflow! All following writes will not be logged!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf(this->writeLog, "%*s-----\n", this->structLevel, "");
|
||||
Utils::IO::WriteFile("userraw/logs/zb_writes.log", fmt::sprintf("%*s-----\n", this->structLevel, ""), true);
|
||||
}
|
||||
|
||||
void Stream::logWrite(int writeLen)
|
||||
{
|
||||
if (!this->writeLog) return;
|
||||
fprintf(this->writeLog, "%*s%d\n", this->structLevel, "", writeLen);
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
@ -1,3 +1,12 @@
|
||||
// write logs for ZoneBuilder
|
||||
#ifndef DEBUG
|
||||
#define SaveLogEnter(x)
|
||||
#define SaveLogExit()
|
||||
#else
|
||||
#define SaveLogEnter(x) builder->getBuffer()->enterStruct(x)
|
||||
#define SaveLogExit() builder->getBuffer()->leaveStruct()
|
||||
#endif
|
||||
|
||||
namespace Utils
|
||||
{
|
||||
class Stream
|
||||
@ -123,11 +132,9 @@ namespace Utils
|
||||
|
||||
// for recording zb writes
|
||||
#ifdef DEBUG
|
||||
static FILE* writeLog;
|
||||
static int structLevel;
|
||||
int structLevel;
|
||||
void enterStruct(const char* structName);
|
||||
void leaveStruct();
|
||||
void logWrite(int writeLen);
|
||||
#endif
|
||||
|
||||
// This represents packed offset in streams:
|
||||
|
Loading…
Reference in New Issue
Block a user