Files
source/TileEngine/XML_ExplosionData.cpp
T
00fb898600 Delete builddefines.h
Nothing was left in it but the include of profiler.h, and 132 translation units
were including it for that alone. Fifteen files were leaning on profiler.h to
drag in <set>, <vector> and <ostream> for them; those now include what they use.

This is the commit that moves line numbers. Removing an include line shifts
__LINE__ by one for everything below it, and __LINE__ is an immediate operand in
every Assert() and DebugMsg() call, so the four game executables differ from
their predecessors by roughly a thousand 32-bit constants each. Every one of
those is accounted for: each is a single immediate that moved by -1 where the
builddefines.h include went away, or +1 where a <set>/<vector> include was
added. Nothing else in .text, .rdata or .data moves, no object file's section
sizes change, and symbolize_crash and Ja2Export stay bit-identical.

The one non-immediate difference is that the 24 Editor translation units of the
non-editor apps stop emitting __Avx2WmemEnabledWeakValue, a 4-byte weak COMDAT
they only ever instantiated through profiler.h's <vector>. It is a UCRT weak
default that other translation units still provide.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-22 01:07:26 -03:00

241 lines
6.6 KiB
C++

// Lesh:
#include <stdio.h>
#include <string.h>
#include "Explosion Control.h"
#include "DEBUG.H"
#include "FileMan.h"
#include "Debug Control.h"
#include "expat.h"
#include "XML.h"
struct
{
PARSE_STAGE curElement;
CHAR8 szCharData[MAX_CHAR_DATA_LENGTH+1];
EXPLOSION_DATA expData;
INT32 maxArraySize;
INT32 curIndex;
INT32 currentDepth;
INT32 maxReadDepth;
}
typedef explosionDataParseData;
static void XMLCALL
explosionDataStartElementHandle(void *userData, const XML_Char *name, const XML_Char **atts)
{
explosionDataParseData * pData = (explosionDataParseData *)userData;
if(pData->currentDepth <= pData->maxReadDepth) //are we reading this element?
{
if(strcmp(name, "EXPDATALIST") == 0 && pData->curElement == ELEMENT_NONE)
{
pData->curElement = ELEMENT_LIST;
pData->maxReadDepth++; //we are not skipping this element
}
else if(strcmp(name, "EXPDATA") == 0 && pData->curElement == ELEMENT_LIST)
{
pData->curElement = ELEMENT;
//DebugMsg(TOPIC_JA2, DBG_LEVEL_3,"MergeStartElementHandle: setting memory for curMerge");
memset(&(pData->expData),0,sizeof(EXPLOSION_DATA));
pData->maxReadDepth++; //we are not skipping this element
pData->curIndex++;
}
else if(pData->curElement == ELEMENT &&
(strcmp(name, "TransKeyFrame") == 0 ||
strcmp(name, "DamageKeyFrame") == 0 ||
strcmp(name, "ExplosionSoundID") == 0 ||
strcmp(name, "AltExplosionSoundID") == 0 ||
strcmp(name, "BlastFilename") == 0 ||
strcmp(name, "BlastSpeed") == 0 ))
{
pData->curElement = ELEMENT_PROPERTY;
pData->maxReadDepth++; //we are not skipping this element
}
pData->szCharData[0] = '\0';
}
pData->currentDepth++;
}
static void XMLCALL
explosionDataCharacterDataHandle(void *userData, const XML_Char *str, int len)
{
explosionDataParseData * pData = (explosionDataParseData *)userData;
if( (pData->currentDepth <= pData->maxReadDepth) &&
(strlen(pData->szCharData) < MAX_CHAR_DATA_LENGTH)
){
strncat(pData->szCharData,str,__min((unsigned int)len,MAX_CHAR_DATA_LENGTH-strlen(pData->szCharData)));
}
}
static void XMLCALL
explosionDataEndElementHandle(void *userData, const XML_Char *name)
{
explosionDataParseData * pData = (explosionDataParseData *)userData;
if(pData->currentDepth <= pData->maxReadDepth) //we're at the end of an element that we've been reading
{
if(strcmp(name, "EXPDATALIST") == 0)
{
pData->curElement = ELEMENT_NONE;
}
else if(strcmp(name, "EXPDATA") == 0)
{
pData->curElement = ELEMENT_LIST;
if(pData->curIndex < pData->maxArraySize)
{
memcpy( &(gExpAniData[pData->curIndex]), &(pData->expData), sizeof(EXPLOSION_DATA) );
}
}
else if(strcmp(name, "TransKeyFrame") == 0)
{
pData->curElement = ELEMENT;
pData->expData.ubTransKeyFrame = (UINT8) atol(pData->szCharData);
}
else if(strcmp(name, "DamageKeyFrame") == 0)
{
pData->curElement = ELEMENT;
pData->expData.ubDamageKeyFrame = (UINT8) atol(pData->szCharData);
}
else if(strcmp(name, "ExplosionSoundID") == 0)
{
pData->curElement = ELEMENT;
pData->expData.sExplosionSoundID = (INT32) strtoul(pData->szCharData, NULL, 0);
}
else if(strcmp(name, "AltExplosionSoundID") == 0)
{
pData->curElement = ELEMENT;
pData->expData.sAltExplosionSoundID = (INT32)strtoul( pData->szCharData, NULL, 0 );
}
else if(strcmp(name, "BlastFilename") == 0)
{
pData->curElement = ELEMENT;
// Lesh: maybe it is needed to check lenght of the pData->szCharData string
// and warn user, otherwise game behavior is unexpected when trying to
// play animation from clipped filename (runtime error, crash ???)
strncpy(pData->expData.zBlastFilename, pData->szCharData, MAX_BLAST_FILENAME_LEN);
}
else if(strcmp(name, "BlastSpeed") == 0)
{
pData->curElement = ELEMENT;
pData->expData.sBlastSpeed = (UINT8) atol(pData->szCharData);
}
pData->maxReadDepth--;
}
pData->currentDepth--;
}
BOOLEAN ReadInExplosionDataStats(STR fileName)
{
HWFILE hFile;
UINT32 uiBytesRead;
UINT32 uiFSize;
CHAR8 * lpcBuffer;
XML_Parser parser = XML_ParserCreate(NULL);
explosionDataParseData pData;
DebugMsg(TOPIC_JA2, DBG_LEVEL_3, "Loading ExplosionData.xml" );
// Open merges file
hFile = FileOpen( fileName, FILE_ACCESS_READ, FALSE );
if ( !hFile )
return( FALSE );
uiFSize = FileGetSize(hFile);
lpcBuffer = (CHAR8 *) MemAlloc(uiFSize+1);
//Read in block
if ( !FileRead( hFile, lpcBuffer, uiFSize, &uiBytesRead ) )
{
MemFree(lpcBuffer);
return( FALSE );
}
lpcBuffer[uiFSize] = 0; //add a null terminator
FileClose( hFile );
XML_SetElementHandler(parser, explosionDataStartElementHandle, explosionDataEndElementHandle);
XML_SetCharacterDataHandler(parser, explosionDataCharacterDataHandle);
memset(&pData,0,sizeof(pData));
pData.maxArraySize = NUM_EXP_TYPES;
pData.curIndex = -1;
XML_SetUserData(parser, &pData);
if(!XML_Parse(parser, lpcBuffer, uiFSize, TRUE))
{
CHAR8 errorBuf[511];
sprintf(errorBuf, "XML Parser Error in ExplosionData.xml: %s at line %d", XML_ErrorString(XML_GetErrorCode(parser)), XML_GetCurrentLineNumber(parser));
LiveMessage(errorBuf);
MemFree(lpcBuffer);
return FALSE;
}
MemFree(lpcBuffer);
XML_ParserFree(parser);
return( TRUE );
}
BOOLEAN WriteExplosionDataStats()
{
HWFILE hFile;
//Debug code; make sure that what we got from the file is the same as what's there
// Open a new file
hFile = FileOpen( "TABLEDATA\\ExplosionData out.xml", FILE_ACCESS_WRITE | FILE_CREATE_ALWAYS, FALSE );
if ( !hFile )
return( FALSE );
{
UINT32 cnt;
FilePrintf(hFile,"<EXPDATALIST>\r\n");
for(cnt = 0;cnt < NUM_EXP_TYPES;cnt++)
{
FilePrintf(hFile,"\t<EXPDATA>\r\n");
FilePrintf(hFile,"\t\t<TransKeyFrame>%d</TransKeyFrame>\r\n", gExpAniData[cnt].ubTransKeyFrame);
FilePrintf(hFile,"\t\t<DamageKeyFrame>%d</DamageKeyFrame>\r\n", gExpAniData[cnt].ubDamageKeyFrame);
FilePrintf(hFile,"\t\t<ExplosionSoundID>%d</ExplosionSoundID>\r\n", gExpAniData[cnt].sExplosionSoundID );
FilePrintf(hFile,"\t\t<AltExplosionSoundID>%d</AltExplosionSoundID>\r\n", gExpAniData[cnt].sAltExplosionSoundID );
FilePrintf(hFile,"\t\t<BlastFilename>%s</BlastFilename>\r\n", gExpAniData[cnt].zBlastFilename);
FilePrintf(hFile,"\t\t<BlastSpeed>%d</BlastSpeed>\r\n", gExpAniData[cnt].sBlastSpeed);
FilePrintf(hFile,"\t</EXPDATA>\r\n");
}
FilePrintf(hFile,"</EXPDATALIST>\r\n");
}
FileClose( hFile );
return( TRUE );
}