Skip to content

Commit

Permalink
Fix custom logics serialisation (#476)
Browse files Browse the repository at this point in the history
* Add new animTable to s_animTables

* Fix - new settings should allow for mod override

* Serialise generator.logicName
  • Loading branch information
jerethk authored Dec 4, 2024
1 parent f46a884 commit e31c7d0
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 15 deletions.
1 change: 1 addition & 0 deletions TheForceEngine/TFE_DarkForces/Actor/animTables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ namespace TFE_DarkForces
s_officerAnimTable,
s_troopAnimTable,
s_commandoAnimTable,
s_customAnimTable,
};
static const s32 s_animTableCount = TFE_ARRAYSIZE(s_animTables);

Expand Down
17 changes: 12 additions & 5 deletions TheForceEngine/TFE_DarkForces/generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace TFE_DarkForces
Wax* wax;
JBool active;

char logicName[256]; // JK: added to store a custom logic name
char logicName[64]; // JK: added to store a custom logic name
};

void generatorTaskFunc(MessageType msg)
Expand Down Expand Up @@ -108,8 +108,6 @@ namespace TFE_DarkForces

assert(gen->entities && allocator_validate(gen->entities));

TFE_Settings_Game* gameSettings = TFE_Settings::getGameSettings();

fixed16_16 dy = TFE_Jedi::abs(s_playerObject->posWS.y - spawn->posWS.y);
fixed16_16 dist = dy + distApprox(spawn->posWS.x, spawn->posWS.z, s_playerObject->posWS.x, s_playerObject->posWS.z);
if (dist >= gen->minDist && dist <= gen->maxDist && !actor_canSeeObject(spawn, s_playerObject))
Expand All @@ -119,7 +117,7 @@ namespace TFE_DarkForces
// Search the externally defined logics for a match
TFE_ExternalData::CustomActorLogic* customLogic;
customLogic = tryFindCustomActorLogic(gen->logicName);
if (customLogic && gameSettings->df_jsonAiLogics)
if (customLogic && TFE_Settings::jsonAiLogics())
{
obj_setCustomActorLogic(spawn, customLogic);
}
Expand Down Expand Up @@ -236,7 +234,7 @@ namespace TFE_DarkForces
memset(generator, 0, sizeof(Generator));

generator->type = genType;
strncpy(generator->logicName, logicName, 255);
strncpy(generator->logicName, logicName, 63);
generator->active = 1;
generator->delay = 0;

Expand Down Expand Up @@ -363,5 +361,14 @@ namespace TFE_DarkForces
SERIALIZE(ObjState_InitVersion, gen->wanderTime, 0);
serialization_serializeWaxPtr(stream, ObjState_InitVersion, gen->wax);
SERIALIZE(ObjState_InitVersion, gen->active, 0);

u32 len = 0;
if (serialization_getMode() == SMODE_WRITE)
{
len = (u32)strlen(gen->logicName);
}
SERIALIZE(ObjState_CustomLogics, len, 0);
SERIALIZE_BUF(ObjState_CustomLogics, gen->logicName, len);
gen->logicName[len] = 0;
}
} // TFE_DarkForces
7 changes: 2 additions & 5 deletions TheForceEngine/TFE_DarkForces/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ namespace TFE_DarkForces

JBool object_parseSeq(SecObject* obj, TFE_Parser* parser, size_t* bufferPos)
{
TFE_Settings_Game* gameSettings = TFE_Settings::getGameSettings();

LogicSetupFunc setupFunc = nullptr;

const char* line = parser->readLine(*bufferPos);
Expand All @@ -133,12 +131,11 @@ namespace TFE_DarkForces
KEYWORD logicId = getKeywordIndex(s_objSeqArg1);

// First, search the externally defined logics for a match (if the setting is enabled)
TFE_Settings_Game* gameSettings = TFE_Settings::getGameSettings();
TFE_ExternalData::CustomActorLogic* customLogic = (logicId != KW_PLAYER)
? tryFindCustomActorLogic(s_objSeqArg1)
: nullptr; // do not allow "LOGIC: PLAYER" to be overridden !!

if (gameSettings->df_jsonAiLogics && customLogic)
if (TFE_Settings::jsonAiLogics() && customLogic)
{
newLogic = obj_setCustomActorLogic(obj, customLogic);
setupFunc = nullptr;
Expand Down Expand Up @@ -186,7 +183,7 @@ namespace TFE_DarkForces
obj_createPickup(obj, itemId);
setupFunc = nullptr;
}
else if (gameSettings->df_enableUnusedItem && strcasecmp(s_objSeqArg1, "ITEM10") == 0)
else if (TFE_Settings::enableUnusedItem() && strcasecmp(s_objSeqArg1, "ITEM10") == 0)
{
obj_createPickup(obj, ITEM_UNUSED);
setupFunc = nullptr;
Expand Down
3 changes: 2 additions & 1 deletion TheForceEngine/TFE_Jedi/Level/robjData.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ enum ObjStateVersion : u32
ObjState_VueSmoothing = 3,
ObjState_OneHitCheats = 4,
ObjState_CrouchToggle = 5,
ObjState_CurVersion = ObjState_CrouchToggle,
ObjState_CustomLogics = 6,
ObjState_CurVersion = ObjState_CustomLogics,
};

#define SPRITE_SCALE_FIXED FIXED(10)
Expand Down
3 changes: 1 addition & 2 deletions TheForceEngine/TFE_Jedi/Level/rsector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1130,8 +1130,7 @@ namespace TFE_Jedi
RSector* next = wall->nextSector;
if (next)
{
TFE_Settings_Game* gameSettings = TFE_Settings::getGameSettings();
if (!TFE_Settings::soidWallFlagFix() || !(wall->flags3 & WF3_SOLID_WALL || wall->mirrorWall->flags3 & WF3_SOLID_WALL))
if (!TFE_Settings::solidWallFlagFix() || !(wall->flags3 & WF3_SOLID_WALL || wall->mirrorWall->flags3 & WF3_SOLID_WALL))
{
RSector* sector = wall->sector;
if (sector->floorHeight >= obj->posWS.y)
Expand Down
2 changes: 1 addition & 1 deletion TheForceEngine/TFE_Settings/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,7 @@ namespace TFE_Settings
return s_gameSettings.df_stepSecondAlt;
}

bool soidWallFlagFix()
bool solidWallFlagFix()
{
if (s_modSettings.solidWallFlagFix != MSO_NOT_SET)
{
Expand Down
4 changes: 3 additions & 1 deletion TheForceEngine/TFE_Settings/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,12 @@ namespace TFE_Settings
// Settings factoring in mod overrides.
bool ignoreInfLimits();
bool stepSecondAlt();
bool soidWallFlagFix();
bool solidWallFlagFix();
bool extendAdjoinLimits();
bool ignore3doLimits();
bool normalFix3do();
bool enableUnusedItem();
bool jsonAiLogics();

// Settings for level mod overrides.
ModSettingLevelOverride getLevelOverrides(string levelName);
Expand Down

0 comments on commit e31c7d0

Please sign in to comment.