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
166 changes: 92 additions & 74 deletions src/LawnApp.cpp

Large diffs are not rendered by default.

49 changes: 24 additions & 25 deletions src/LawnApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ class LawnApp : public SexyApp
TrialType mTrialType;
bool mDebugTrialLocked;
bool mMuteSoundsForCutscene;
bool mRunInCompileMode{};

static Version gResoddedVersion;


public:
LawnApp();
virtual ~LawnApp();
Expand Down Expand Up @@ -355,11 +355,11 @@ class LawnApp : public SexyApp
/// @param theButtonMode Button creation flags
/// @return The created dialog
virtual Dialog *DoDialog(int theDialogId,
bool isModal,
const SexyString &theDialogHeader,
const SexyString &theDialogLines,
const SexyString &theDialogFooter,
int theButtonMode);
bool isModal,
const SexyString &theDialogHeader,
const SexyString &theDialogLines,
const SexyString &theDialogFooter,
int theButtonMode);

/// @brief After 30 ticks create a new dialog and focus on it
/// @param theDialogId The ID of the dialog (determines the behavior on closing and opening)
Expand All @@ -370,11 +370,11 @@ class LawnApp : public SexyApp
/// @param theButtonMode Button creation flags
/// @return The created dialog
virtual Dialog *DoDialogDelay(int theDialogId,
bool isModal,
const SexyString &theDialogHeader,
const SexyString &theDialogLines,
const SexyString &theDialogFooter,
int theButtonMode);
bool isModal,
const SexyString &theDialogHeader,
const SexyString &theDialogLines,
const SexyString &theDialogFooter,
int theButtonMode);

/// @brief Shutdown the game
virtual void Shutdown();
Expand All @@ -394,11 +394,11 @@ class LawnApp : public SexyApp
/// @param theButtonMode Button creation flags
/// @return The created dialog
virtual Dialog *NewDialog(int theDialogId,
bool isModal,
const SexyString &theDialogHeader,
const SexyString &theDialogLines,
const SexyString &theDialogFooter,
int theButtonMode);
bool isModal,
const SexyString &theDialogHeader,
const SexyString &theDialogLines,
const SexyString &theDialogFooter,
int theButtonMode);

/// @brief Destroy the dialog
/// @param theDialogId The ID of the dialog (determines the behavior on closing and opening)
Expand Down Expand Up @@ -636,7 +636,7 @@ class LawnApp : public SexyApp
/// @brief Is the current level a BungeeBlitz level
/// @return True if the GameMode is a BungeeBlitz level, false otherwise
bool IsBungeeBlitzLevel();

/// @brief Get the SeedType awarded in a level
/// @param theLevel The level to check
/// @return Awarded SeedType
Expand Down Expand Up @@ -727,15 +727,15 @@ class LawnApp : public SexyApp
void PreloadForUser();

/// @brief
/// @return
/// @return
int GetNumPreloadingTasks();

int LawnMessageBox(int theDialogId,
const SexyString &theHeaderName,
const SexyString &theLinesName,
const SexyString &theButton1Name,
const SexyString &theButton2Name,
int theButtonMode);
const SexyString &theHeaderName,
const SexyString &theLinesName,
const SexyString &theButton1Name,
const SexyString &theButton2Name,
int theButtonMode);

/// @brief Open Credits screen
void ShowCreditScreen();
Expand Down Expand Up @@ -909,7 +909,6 @@ class LawnApp : public SexyApp
/// @param theWidth The width to center it in
/// @param theHeight The height to center it in
static void CenterDialog(Dialog *theDialog, int theWidth, int theHeight);

};

/// @brief Get the current level name, used for logging
Expand Down Expand Up @@ -937,4 +936,4 @@ extern bool gSlowMo;
extern LawnApp *gLawnApp;
extern int gSlowMoCounter;

#endif // __LAWNAPP_H__
#endif // __LAWNAPP_H__
89 changes: 51 additions & 38 deletions src/Sexy.TodLib/Definition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

DefSymbol gTrailFlagDefSymbols[] = {
{ 0, "Loops" },
{ -1, nullptr }
{ -1, nullptr }
};
DefField gTrailDefFields[] = {
{ "Image", offsetof(TrailDefinition, mImage), DefFieldType::DT_IMAGE, nullptr },
Expand Down Expand Up @@ -44,25 +44,25 @@ DefSymbol gParticleFlagSymbols[] = {
};
DefSymbol gEmitterTypeSymbols[] = {
{ 0, "Circle" },
{ 1, "Box" },
{ 2, "BoxPath" },
{ 3, "CirclePath" },
{ 4, "CircleEvenSpacing" },
{ -1, nullptr }
{ 1, "Box" },
{ 2, "BoxPath" },
{ 3, "CirclePath" },
{ 4, "CircleEvenSpacing" },
{ -1, nullptr }
};
DefSymbol gParticleTypeSymbols[] = {
{ 1, "Friction" },
{ 2, "Acceleration" },
{ 3, "Attractor" },
{ 4, "MaxVelocity" },
{ 5, "Velocity" },
{ 6, "Position" },
{ 7, "SystemPosition" },
{ 8, "GroundConstraint" },
{ 9, "Shake" },
{ 10, "Circle" },
{ 11, "Away" },
{ -1, nullptr }
{ 2, "Acceleration" },
{ 3, "Attractor" },
{ 4, "MaxVelocity" },
{ 5, "Velocity" },
{ 6, "Position" },
{ 7, "SystemPosition" },
{ 8, "GroundConstraint" },
{ 9, "Shake" },
{ 10, "Circle" },
{ 11, "Away" },
{ -1, nullptr }
};

DefField gParticleFieldDefFields[] = {
Expand Down Expand Up @@ -166,9 +166,9 @@ DefMap gReanimatorDefMap = { gReanimatorDefFields, sizeof(ReanimatorDefinition),

static DefLoadResPath gDefLoadResPaths[4] = {
{ "IMAGE_", "" },
{ "IMAGE_", "particles/" },
{ "IMAGE_REANIM_", "reanim/" },
{ "IMAGE_REANIM_", "images/" }
{ "IMAGE_", "particles/" },
{ "IMAGE_REANIM_", "reanim/" },
{ "IMAGE_REANIM_", "images/" }
};

void *ParticleFieldConstructor(void *thePointer)
Expand Down Expand Up @@ -325,9 +325,9 @@ bool DefinitionLoadFont(Font **theFont, const SexyString &theName)
return aFont != nullptr;
}

bool DefinitionLoadXML(const SexyString &theFileName, DefMap *theDefMap, void *theDefinition)
bool DefinitionLoadXML(const SexyString &theFileName, DefMap *theDefMap, void *theDefinition, bool recompile)
{
return DefinitionCompileAndLoad(theFileName, theDefMap, theDefinition);
return DefinitionCompileAndLoad(theFileName, theDefMap, theDefinition, recompile);
}

bool DefReadFromCacheArray(void *&theReadPtr, DefinitionArrayDef *theArray, DefMap *theDefMap)
Expand Down Expand Up @@ -555,15 +555,15 @@ bool DefinitionReadCompiledFile(const SexyString &theCompiledFilePath, DefMap *t

PerfTimer aTimer;
aTimer.Start();
FILE *pFile = fopen(theCompiledFilePath.c_str(), "rb");
PFILE *pFile = p_fopen(theCompiledFilePath.c_str(), "rb");
if (pFile)
{
fseek(pFile, 0, 2);
size_t aFileSize = ftell(pFile);
fseek(pFile, 0, 0);
p_fseek(pFile, 0, 2);
size_t aFileSize = p_ftell(pFile);
p_fseek(pFile, 0, 0);
aCompiledFile.mData.resize(aFileSize);
bool aReadCompressedFailed = fread(aCompiledFile.mData.data(), sizeof(uint8_t), aFileSize, pFile) != aFileSize;
fclose(pFile);
bool aReadCompressedFailed = p_fread(aCompiledFile.mData.data(), sizeof(uint8_t), aFileSize, pFile) != aFileSize;
p_fclose(pFile);
if (aReadCompressedFailed)
{
TodTraceAndLog("[TodLib] - Failed to read compiled file: %s\n", theCompiledFilePath.c_str());
Expand Down Expand Up @@ -591,6 +591,10 @@ bool DefinitionReadCompiledFile(const SexyString &theCompiledFilePath, DefMap *t
}

bool aResult = DefMapReadFromCache(anUncompressedData, theDefMap, theDefinition);
if (!aResult)
{
TodTraceAndLog("[TodLib] - Failed to read from cache: %s\n", theCompiledFilePath.c_str());
}

return aResult;
}
Expand All @@ -606,6 +610,7 @@ bool DefinitionReadCompiledFile(const SexyString &theCompiledFilePath, DefMap *t
}
return aResult;
#else
TodTraceAndLog("[TodLib] - Cache is not valid: %s\n", theCompiledFilePath.c_str());
return false;
#endif
}
Expand Down Expand Up @@ -1349,28 +1354,36 @@ bool DefinitionCompileFile(const SexyString theXMLFilePath, const SexyString &th
return true;
}

bool DefinitionCompileAndLoad(const SexyString &theXMLFilePath, DefMap *theDefMap, void *theDefinition)
bool DefinitionCompileAndLoad(const SexyString &theXMLFilePath, DefMap *theDefMap, void *theDefinition, bool recompile)
{
SexyString aCompiledFilePath = DefinitionGetCompiledFilePathFromXMLFilePath(theXMLFilePath);
TodHesitationTrace("predef");

try
if (!recompile)
{
if (DefinitionReadCompiledFile(aCompiledFilePath, theDefMap, theDefinition))
try
{
if (DefinitionReadCompiledFile(aCompiledFilePath, theDefMap, theDefinition))
{
TodHesitationTrace("loaded %s", aCompiledFilePath.c_str());
return true;
}
}
catch (int anErrorCode)
{
TodHesitationTrace("loaded %s", aCompiledFilePath.c_str());
return true;
}
}
catch (int anErrorCode)
{
}

PerfTimer aTimer;
aTimer.Start();
if (!recompile)
{
//write to fresh_compiled to not overwrite on game re-compile by accident
aCompiledFilePath = "fresh_" + aCompiledFilePath;
}
bool aResult =
DefinitionCompileFile(theXMLFilePath, "fresh_" + aCompiledFilePath, theDefMap,
theDefinition); //write to fresh_compiled to not overwrite on game re-compile by accident
DefinitionCompileFile(theXMLFilePath, aCompiledFilePath, theDefMap,
theDefinition);
TodTraceAndLog("[TodLib] - compile %d ms:'%s'", (int)aTimer.GetDuration(), aCompiledFilePath.c_str());
TodHesitationTrace("compiled %s", aCompiledFilePath.c_str());
if (aResult)
Expand Down
4 changes: 2 additions & 2 deletions src/Sexy.TodLib/Definition.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,11 @@ void DefWriteToCacheFont(DefinitionCompiler *theReadPtr, Font **theFont);
void DefWriteToCacheFloatTrack(DefinitionCompiler *theReadPtr, FloatParameterTrack *theTrack);
void DefMapWriteToCache(DefinitionCompiler *theReadPtr, DefMap *theDefMap, void *theDefinition);

bool DefinitionCompileAndLoad(const SexyString &theXMLFilePath, DefMap *theDefMap, void *theDefinition);
bool DefinitionCompileAndLoad(const SexyString &theXMLFilePath, DefMap *theDefMap, void *theDefinition, bool recompile);
bool DefinitionLoadMap(XMLParser *theXmlParser, DefMap *theDefMap, void *theDefinition);
bool DefinitionLoadImage(Image **theImage, const SexyString &theName);
bool DefinitionLoadFont(Font **theFont, const SexyString &theName);
bool DefinitionLoadXML(const SexyString &theFilename, DefMap *theDefMap, void *theDefinition);
bool DefinitionLoadXML(const SexyString &theFilename, DefMap *theDefMap, void *theDefinition, bool recompile);
void DefinitionFreeArrayField(DefinitionArrayDef *theArray, DefMap *theDefMap);
void DefinitionFreeMap(DefMap *theDefMap, void *theDefinition);

Expand Down
Loading
Loading