[Debugging] Slightly optimize zb writing
This commit is contained in:
parent
403974b9cc
commit
336a891d26
@ -7,7 +7,8 @@ namespace Assets
|
|||||||
AssertSize(Game::FxWorld, 116);
|
AssertSize(Game::FxWorld, 116);
|
||||||
|
|
||||||
Utils::Stream* buffer = builder->getBuffer();
|
Utils::Stream* buffer = builder->getBuffer();
|
||||||
SAVE_LOG_ENTER("FxWorld");
|
SaveLogEnter("FxWorld");
|
||||||
|
|
||||||
Game::FxWorld* asset = header.fxWorld;
|
Game::FxWorld* asset = header.fxWorld;
|
||||||
Game::FxWorld* dest = buffer->dest<Game::FxWorld>();
|
Game::FxWorld* dest = buffer->dest<Game::FxWorld>();
|
||||||
buffer->save(asset);
|
buffer->save(asset);
|
||||||
@ -152,6 +153,8 @@ namespace Assets
|
|||||||
Utils::Stream::ClearPointer(&dest->glassSys.initGeoData);
|
Utils::Stream::ClearPointer(&dest->glassSys.initGeoData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SaveLogExit();
|
||||||
}
|
}
|
||||||
void IFxWorld::mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
|
void IFxWorld::mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
|
||||||
{
|
{
|
||||||
|
@ -113,7 +113,7 @@ namespace Assets
|
|||||||
AssertSize(Game::GfxWorldDpvsPlanes, 16);
|
AssertSize(Game::GfxWorldDpvsPlanes, 16);
|
||||||
|
|
||||||
Utils::Stream* buffer = builder->getBuffer();
|
Utils::Stream* buffer = builder->getBuffer();
|
||||||
SAVE_LOG_ENTER("GfxWorldDpvsPlanes");
|
SaveLogEnter("GfxWorldDpvsPlanes");
|
||||||
|
|
||||||
if (asset->planes)
|
if (asset->planes)
|
||||||
{
|
{
|
||||||
@ -150,13 +150,13 @@ namespace Assets
|
|||||||
}
|
}
|
||||||
|
|
||||||
buffer->popBlock();
|
buffer->popBlock();
|
||||||
SAVE_LOG_EXIT();
|
SaveLogExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IGfxWorld::saveGfxWorldDraw(Game::GfxWorldDraw* asset, Game::GfxWorldDraw* dest, Components::ZoneBuilder::Zone* builder)
|
void IGfxWorld::saveGfxWorldDraw(Game::GfxWorldDraw* asset, Game::GfxWorldDraw* dest, Components::ZoneBuilder::Zone* builder)
|
||||||
{
|
{
|
||||||
AssertSize(Game::GfxWorldDraw, 72);
|
AssertSize(Game::GfxWorldDraw, 72);
|
||||||
SAVE_LOG_ENTER("GfxWorldDraw");
|
SaveLogEnter("GfxWorldDraw");
|
||||||
|
|
||||||
Utils::Stream* buffer = builder->getBuffer();
|
Utils::Stream* buffer = builder->getBuffer();
|
||||||
|
|
||||||
@ -282,7 +282,7 @@ namespace Assets
|
|||||||
Utils::Stream::ClearPointer(&dest->indices);
|
Utils::Stream::ClearPointer(&dest->indices);
|
||||||
}
|
}
|
||||||
|
|
||||||
SAVE_LOG_EXIT();
|
SaveLogExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IGfxWorld::saveGfxLightGrid(Game::GfxLightGrid* asset, Game::GfxLightGrid* dest, Components::ZoneBuilder::Zone* builder)
|
void IGfxWorld::saveGfxLightGrid(Game::GfxLightGrid* asset, Game::GfxLightGrid* dest, Components::ZoneBuilder::Zone* builder)
|
||||||
@ -290,7 +290,7 @@ namespace Assets
|
|||||||
AssertSize(Game::GfxLightGrid, 56);
|
AssertSize(Game::GfxLightGrid, 56);
|
||||||
|
|
||||||
Utils::Stream* buffer = builder->getBuffer();
|
Utils::Stream* buffer = builder->getBuffer();
|
||||||
SAVE_LOG_ENTER("GfxLightGrid");
|
SaveLogEnter("GfxLightGrid");
|
||||||
|
|
||||||
if (asset->rowDataStart)
|
if (asset->rowDataStart)
|
||||||
{
|
{
|
||||||
@ -323,14 +323,14 @@ namespace Assets
|
|||||||
buffer->saveArray(asset->colors, asset->colorCount);
|
buffer->saveArray(asset->colors, asset->colorCount);
|
||||||
Utils::Stream::ClearPointer(&dest->colors);
|
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)
|
void IGfxWorld::savesunflare_t(Game::sunflare_t* asset, Game::sunflare_t* dest, Components::ZoneBuilder::Zone* builder)
|
||||||
{
|
{
|
||||||
AssertSize(Game::sunflare_t, 96);
|
AssertSize(Game::sunflare_t, 96);
|
||||||
|
SaveLogEnter("sunflare_t");
|
||||||
SAVE_LOG_ENTER("sunflare_t");
|
|
||||||
|
|
||||||
if (asset->spriteMaterial)
|
if (asset->spriteMaterial)
|
||||||
{
|
{
|
||||||
@ -342,7 +342,7 @@ namespace Assets
|
|||||||
dest->flareMaterial = builder->requireAsset(Game::XAssetType::ASSET_TYPE_MATERIAL, asset->flareMaterial->name).material;
|
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)
|
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);
|
AssertSize(Game::GfxWorldDpvsStatic, 108);
|
||||||
|
|
||||||
Utils::Stream* buffer = builder->getBuffer();
|
Utils::Stream* buffer = builder->getBuffer();
|
||||||
SAVE_LOG_ENTER("GfxWorldDpvsStatic");
|
SaveLogEnter("GfxWorldDpvsStatic");
|
||||||
|
|
||||||
buffer->pushBlock(Game::XFILE_BLOCK_RUNTIME);
|
buffer->pushBlock(Game::XFILE_BLOCK_RUNTIME);
|
||||||
|
|
||||||
@ -464,7 +464,7 @@ namespace Assets
|
|||||||
}
|
}
|
||||||
|
|
||||||
buffer->popBlock();
|
buffer->popBlock();
|
||||||
SAVE_LOG_EXIT();
|
SaveLogExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IGfxWorld::saveGfxWorldDpvsDynamic(Game::GfxWorldDpvsDynamic* asset, Game::GfxWorldDpvsDynamic* dest, Components::ZoneBuilder::Zone* builder)
|
void IGfxWorld::saveGfxWorldDpvsDynamic(Game::GfxWorldDpvsDynamic* asset, Game::GfxWorldDpvsDynamic* dest, Components::ZoneBuilder::Zone* builder)
|
||||||
@ -472,7 +472,7 @@ namespace Assets
|
|||||||
AssertSize(Game::GfxWorldDpvsDynamic, 48);
|
AssertSize(Game::GfxWorldDpvsDynamic, 48);
|
||||||
|
|
||||||
Utils::Stream* buffer = builder->getBuffer();
|
Utils::Stream* buffer = builder->getBuffer();
|
||||||
SAVE_LOG_ENTER("GfxWorldDpvsDynamic");
|
SaveLogEnter("GfxWorldDpvsDynamic");
|
||||||
|
|
||||||
buffer->pushBlock(Game::XFILE_BLOCK_RUNTIME);
|
buffer->pushBlock(Game::XFILE_BLOCK_RUNTIME);
|
||||||
|
|
||||||
@ -505,7 +505,7 @@ namespace Assets
|
|||||||
}
|
}
|
||||||
|
|
||||||
buffer->popBlock();
|
buffer->popBlock();
|
||||||
SAVE_LOG_EXIT();
|
SaveLogExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IGfxWorld::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
|
void IGfxWorld::save(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
|
||||||
@ -513,7 +513,8 @@ namespace Assets
|
|||||||
AssertSize(Game::GfxWorld, 628);
|
AssertSize(Game::GfxWorld, 628);
|
||||||
|
|
||||||
Utils::Stream* buffer = builder->getBuffer();
|
Utils::Stream* buffer = builder->getBuffer();
|
||||||
SAVE_LOG_ENTER("GfxWorld");
|
SaveLogEnter("GfxWorld");
|
||||||
|
|
||||||
Game::GfxWorld* asset = header.gfxWorld;
|
Game::GfxWorld* asset = header.gfxWorld;
|
||||||
Game::GfxWorld* dest = buffer->dest<Game::GfxWorld>();
|
Game::GfxWorld* dest = buffer->dest<Game::GfxWorld>();
|
||||||
buffer->save(asset);
|
buffer->save(asset);
|
||||||
@ -869,6 +870,6 @@ namespace Assets
|
|||||||
}
|
}
|
||||||
|
|
||||||
buffer->popBlock();
|
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 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.")
|
#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
|
// Resource stuff
|
||||||
#ifdef APSTUDIO_INVOKED
|
#ifdef APSTUDIO_INVOKED
|
||||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||||
|
@ -62,13 +62,10 @@ namespace Utils
|
|||||||
Stream::Stream() : criticalSectionState(0)
|
Stream::Stream() : criticalSectionState(0)
|
||||||
{
|
{
|
||||||
memset(this->blockSize, 0, sizeof(this->blockSize));
|
memset(this->blockSize, 0, sizeof(this->blockSize));
|
||||||
#ifdef DEBUG
|
|
||||||
|
|
||||||
if (this->writeLog) return;
|
#ifdef DEBUG
|
||||||
if (fopen_s(&this->writeLog, "userraw/logs/zb_writes.log", "w"))
|
this->structLevel = 0;
|
||||||
{
|
Utils::IO::WriteFile("userraw/logs/zb_writes.log", "", false);
|
||||||
Components::Logger::Print("WARNING: Couldn't open write log. Writes from ZoneBuilder will not be logged.\n");
|
|
||||||
}
|
|
||||||
#endif
|
#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);
|
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()
|
size_t Stream::length()
|
||||||
@ -130,9 +120,6 @@ namespace Utils
|
|||||||
|
|
||||||
this->buffer.append(static_cast<const char*>(_str), size * count);
|
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())
|
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);
|
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;
|
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)
|
void Stream::increaseBlockSize(unsigned int size)
|
||||||
@ -329,36 +322,23 @@ namespace Utils
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
||||||
FILE* Stream::writeLog = nullptr;
|
|
||||||
int Stream::structLevel = 0;
|
|
||||||
|
|
||||||
void Stream::enterStruct(const char* structName)
|
void Stream::enterStruct(const char* structName)
|
||||||
{
|
{
|
||||||
if (!this->writeLog) return;
|
if (this->structLevel >= 0)
|
||||||
fprintf(this->writeLog, "%*s%s\n", this->structLevel++, "", structName);
|
{
|
||||||
|
Utils::IO::WriteFile("userraw/logs/zb_writes.log", fmt::sprintf("%*s%s\n", this->structLevel++, "", structName), true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stream::leaveStruct()
|
void Stream::leaveStruct()
|
||||||
{
|
{
|
||||||
if (!this->writeLog) return;
|
if (--this->structLevel < 0)
|
||||||
this->structLevel--;
|
{
|
||||||
|
Components::Logger::Print("Stream::leaveStruct underflow! All following writes will not be logged!\n");
|
||||||
if (this->structLevel < 0) {
|
|
||||||
Components::Logger::Print("Stream::exitStruct underflow! All following writes will not be logged!\n");
|
|
||||||
fclose(this->writeLog);
|
|
||||||
this->writeLog = nullptr;
|
|
||||||
return;
|
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
|
#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
|
namespace Utils
|
||||||
{
|
{
|
||||||
class Stream
|
class Stream
|
||||||
@ -123,11 +132,9 @@ namespace Utils
|
|||||||
|
|
||||||
// for recording zb writes
|
// for recording zb writes
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
static FILE* writeLog;
|
int structLevel;
|
||||||
static int structLevel;
|
|
||||||
void enterStruct(const char* structName);
|
void enterStruct(const char* structName);
|
||||||
void leaveStruct();
|
void leaveStruct();
|
||||||
void logWrite(int writeLen);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// This represents packed offset in streams:
|
// This represents packed offset in streams:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user