Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion YRpp
Submodule YRpp updated 1 files
+1 −1 AbstractClass.h
89 changes: 89 additions & 0 deletions src/Misc/SyncLogging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
int SyncLogger::AnimCreations_HighestX = 0;
int SyncLogger::AnimCreations_HighestY = 0;
int SyncLogger::AnimCreations_HighestZ = 0;
int SyncLogger::TeamTypeClass_MaxIDLength = 0;
int SyncLogger::ScriptTypeClass_MaxIDLength = 0;
int SyncLogger::HouseTypeClass_MaxIDLength = 0;
int SyncLogger::HouseName_MaxIDLength = 0;

SyncLogEventBuffer<RNGCallSyncLogEvent, RNGCalls_Size> SyncLogger::RNGCalls;
SyncLogEventBuffer<FacingChangeSyncLogEvent, FacingChanges_Size> SyncLogger::FacingChanges;
Expand Down Expand Up @@ -128,6 +132,7 @@ void SyncLogger::WriteSyncLog(const char* logFilename)
WriteTargetChanges(pLogFile, frameDigits);
WriteDestinationChanges(pLogFile, frameDigits);
WriteAnimCreations(pLogFile, frameDigits);
WriteTeams(pLogFile);

fclose(pLogFile);
}
Expand Down Expand Up @@ -258,6 +263,90 @@ void SyncLogger::WriteAnimCreations(FILE* const pLogFile, int frameDigits)
fprintf(pLogFile, "\n");
}

void SyncLogger::WriteTeams(FILE* const pLogFile)
{
if (TeamClass::Array.Count < 1)
return;

fprintf(pLogFile, "AI Teams:\n");
char buffer[0x20];
size_t count = 0;

// Set padding for values.
for (auto const& pTeam : TeamClass::Array)
{
SyncLogger::SetTeamLoggingPadding(pTeam);
count++;
}

for (size_t i = 0; i < count; i++)
{
auto const pTeam = TeamClass::Array[i];

fprintf(pLogFile, "#%05d: Type: %*s",
i, SyncLogger::TeamTypeClass_MaxIDLength, pTeam->Type->get_ID());

if (pTeam->CurrentScript && pTeam->CurrentScript->Type)
{
sprintf_s(buffer, sizeof(buffer), "%d", pTeam->CurrentScript->CurrentMission);
fprintf(pLogFile, " | Script: %*s | Line: %2s", SyncLogger::ScriptTypeClass_MaxIDLength, pTeam->CurrentScript->Type->get_ID(), buffer);
}

if (pTeam->Owner)
{
sprintf_s(buffer, sizeof(buffer), "(%s)", pTeam->Owner->PlainName);
fprintf(pLogFile, " | Owner: %d %*s | OwnerHouse: %*s", pTeam->Owner->ArrayIndex,
SyncLogger::HouseName_MaxIDLength, buffer,SyncLogger::HouseTypeClass_MaxIDLength, pTeam->Owner->Type->get_ID());
}

if (pTeam->Focus)
{
auto const rtti = pTeam->Focus->WhatAmI();
fprintf(pLogFile, " | TargetRTTI: %d (%s) | TargetID: %08d", rtti, AbstractClass::GetRTTIName(rtti), pTeam->Focus->UniqueID);
}

if (pTeam->QueuedFocus)
{
auto const rtti = pTeam->QueuedFocus->WhatAmI();
fprintf(pLogFile, " | MissionTargetRTTI: %d (%s) | MissionTargetID: %08d", rtti,AbstractClass::GetRTTIName(rtti),
pTeam->QueuedFocus->UniqueID);
}

fprintf(pLogFile, "\n");
}

fprintf(pLogFile, "\n");
}

void SyncLogger::SetTeamLoggingPadding(TeamClass* pTeam)
{
int length = strlen(pTeam->Type->get_ID());

if (length <= 24 && SyncLogger::TeamTypeClass_MaxIDLength < length)
SyncLogger::TeamTypeClass_MaxIDLength = length;

if (pTeam->Type->ScriptType)
{
length = strlen(pTeam->Type->ScriptType->get_ID());

if (length <= 24 && SyncLogger::ScriptTypeClass_MaxIDLength < length)
SyncLogger::ScriptTypeClass_MaxIDLength = length;
}

if (pTeam->Owner)
{
length = strlen(pTeam->Owner->Type->get_ID());

if (length <= 24 && SyncLogger::HouseTypeClass_MaxIDLength < length)
SyncLogger::HouseTypeClass_MaxIDLength = length;

length = strlen(pTeam->Owner->PlainName);

if (length <= 21 && SyncLogger::HouseName_MaxIDLength < length)
SyncLogger::HouseName_MaxIDLength = length;
}
}

// Hooks. Anim contructor logging is in Ext/Anim/Body.cpp to reduce duplicate hooks

// Sync file writing
Expand Down
8 changes: 8 additions & 0 deletions src/Misc/SyncLogging.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <AbstractClass.h>
#include <GeneralDefinitions.h>
#include <Randomizer.h>
#include <TeamClass.h>

#include <vector>

// These determine how many of each type of sync log event are stored in the buffers.
Expand Down Expand Up @@ -157,10 +159,15 @@ class SyncLogger
static void WriteDestinationChanges(FILE* const pLogFile, int frameDigits);
static void WriteMissionOverrides(FILE* const pLogFile, int frameDigits);
static void WriteAnimCreations(FILE* const pLogFile, int frameDigits);
static void WriteTeams(FILE* const pLogFile);
public:
static int AnimCreations_HighestX;
static int AnimCreations_HighestY;
static int AnimCreations_HighestZ;
static int TeamTypeClass_MaxIDLength;
static int ScriptTypeClass_MaxIDLength;
static int HouseTypeClass_MaxIDLength;
static int HouseName_MaxIDLength;

static void AddRNGCallSyncLogEvent(Randomizer* pRandomizer, int type, unsigned int callerAddress, int min = 0, int max = 0);
static void AddFacingChangeSyncLogEvent(unsigned short facing, unsigned int callerAddress);
Expand All @@ -169,4 +176,5 @@ class SyncLogger
static void AddMissionOverrideSyncLogEvent(AbstractClass* pObject, int mission, unsigned int callerAddress);
static void AddAnimCreationSyncLogEvent(const CoordStruct& coords, unsigned int callerAddress);
static void WriteSyncLog(const char* logFilename);
static void SetTeamLoggingPadding(TeamClass* pTeam);
};
Loading