From bdc7c5161af59c08930c02b8ebb6b2fe76a6c33c Mon Sep 17 00:00:00 2001 From: Caball009 <82909616+Caball009@users.noreply.github.com> Date: Wed, 25 Jun 2025 10:06:10 +0200 Subject: [PATCH] Added 'clearOnNewOverride' function. --- Generals/Code/GameEngine/Include/Common/ThingTemplate.h | 3 +++ .../Code/GameEngine/Source/Common/Thing/ThingFactory.cpp | 3 +++ .../Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp | 8 ++++++++ GeneralsMD/Code/GameEngine/Include/Common/ThingTemplate.h | 3 +++ .../Code/GameEngine/Source/Common/Thing/ThingFactory.cpp | 3 +++ .../Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp | 8 ++++++++ 6 files changed, 28 insertions(+) diff --git a/Generals/Code/GameEngine/Include/Common/ThingTemplate.h b/Generals/Code/GameEngine/Include/Common/ThingTemplate.h index 38c88874d7..6d01e26de5 100644 --- a/Generals/Code/GameEngine/Include/Common/ThingTemplate.h +++ b/Generals/Code/GameEngine/Include/Common/ThingTemplate.h @@ -369,6 +369,9 @@ class ThingTemplate : public Overridable // copy the guts of that into this, but preserve this' name, id, and list-links. void copyFrom(const ThingTemplate* that); + // clear data that's only valid for the 'parent' template but not the override. + void clearOnNewOverride(); + /// called by ThingFactory after all templates have been loaded. void resolveNames(); diff --git a/Generals/Code/GameEngine/Source/Common/Thing/ThingFactory.cpp b/Generals/Code/GameEngine/Source/Common/Thing/ThingFactory.cpp index e95b59b285..a1cd4b08ee 100644 --- a/Generals/Code/GameEngine/Source/Common/Thing/ThingFactory.cpp +++ b/Generals/Code/GameEngine/Source/Common/Thing/ThingFactory.cpp @@ -194,6 +194,9 @@ ThingTemplate* ThingFactory::newOverride( ThingTemplate *thingTemplate ) newTemplate->markAsOverride(); child->setNextOverride(newTemplate); + // TheSuperHackers @bugfix Caball009 25/06/2025 Clear data that was valid for the 'parent' template but not for the override. + newTemplate->clearOnNewOverride(); + // return the newly created override for us to set values with etc return newTemplate; diff --git a/Generals/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp b/Generals/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp index cedcb61716..fcfbf0e259 100644 --- a/Generals/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp +++ b/Generals/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp @@ -1093,6 +1093,14 @@ void ThingTemplate::copyFrom(const ThingTemplate* that) this->m_nameString = name; } +//------------------------------------------------------------------------------------------------- +void ThingTemplate::clearOnNewOverride() +{ + // TheSuperHackers @info Clear containers that may contain pointers to data in the 'parent' template for memoization purposes. + m_weaponTemplateSetFinder.clear(); + m_armorTemplateSetFinder.clear(); +} + //------------------------------------------------------------------------------------------------- void ThingTemplate::setCopiedFromDefault() { diff --git a/GeneralsMD/Code/GameEngine/Include/Common/ThingTemplate.h b/GeneralsMD/Code/GameEngine/Include/Common/ThingTemplate.h index 2764437135..ee69cf8343 100644 --- a/GeneralsMD/Code/GameEngine/Include/Common/ThingTemplate.h +++ b/GeneralsMD/Code/GameEngine/Include/Common/ThingTemplate.h @@ -369,6 +369,9 @@ class ThingTemplate : public Overridable // copy the guts of that into this, but preserve this' name, id, and list-links. void copyFrom(const ThingTemplate* that); + // clear data that's only valid for the 'parent' template but not the override. + void clearOnNewOverride(); + /// called by ThingFactory after all templates have been loaded. void resolveNames(); diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingFactory.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingFactory.cpp index a92d80b548..1c73f4e95d 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingFactory.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingFactory.cpp @@ -194,6 +194,9 @@ ThingTemplate* ThingFactory::newOverride( ThingTemplate *thingTemplate ) newTemplate->markAsOverride(); child->setNextOverride(newTemplate); + // TheSuperHackers @bugfix Caball009 25/06/2025 Clear data that was valid for the 'parent' template but not for the override. + newTemplate->clearOnNewOverride(); + // return the newly created override for us to set values with etc return newTemplate; diff --git a/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp b/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp index 81105d61a0..a0cbc2bf06 100644 --- a/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingTemplate.cpp @@ -1232,6 +1232,14 @@ void ThingTemplate::copyFrom(const ThingTemplate* that) this->m_nameString = name; } +//------------------------------------------------------------------------------------------------- +void ThingTemplate::clearOnNewOverride() +{ + // TheSuperHackers @info Clear containers that may contain pointers to data in the 'parent' template for memoization purposes. + m_weaponTemplateSetFinder.clear(); + m_armorTemplateSetFinder.clear(); +} + //------------------------------------------------------------------------------------------------- void ThingTemplate::setCopiedFromDefault() {