Skip to content

Commit 0aaa74f

Browse files
committed
Simplified implementation by relying on the size of the template hash map.
1 parent 67f96ad commit 0aaa74f

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

GeneralsMD/Code/GameEngine/Include/Common/ThingFactory.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ class ThingFactory : public SubsystemInterface
124124

125125
ThingTemplate *m_firstTemplate; ///< head of linked list
126126
UnsignedShort m_nextTemplateID; ///< next available ID for templates
127-
UnsignedShort m_templateCount; ///< the value of m_nextTemplateID before loading the first map (even shellmap)
128127

129128
ThingTemplateHashMap m_templateHashMap; ///< all thing templates, for fast lookup.
130129

GeneralsMD/Code/GameEngine/Source/Common/Thing/ThingFactory.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ void ThingFactory::addTemplate( ThingTemplate *tmplate )
104104
ThingFactory::ThingFactory()
105105
{
106106
m_firstTemplate = NULL;
107-
m_nextTemplateID = 1; // not zero!
108-
m_templateCount = 0;
107+
m_nextTemplateID = 0;
109108

110109
#ifdef USING_STLPORT
111110
m_templateHashMap.resize( TEMPLATE_HASH_SIZE );
@@ -146,7 +145,7 @@ ThingTemplate *ThingFactory::newTemplate( const AsciiString& name )
146145
}
147146

148147
// give template a unique identifier
149-
newTemplate->friend_setTemplateID( m_nextTemplateID++ );
148+
newTemplate->friend_setTemplateID( ++m_nextTemplateID ); // pre-increment to use non-zero ID value
150149
DEBUG_ASSERTCRASH( m_nextTemplateID != 0, ("m_nextTemplateID wrapped to zero") );
151150

152151
// assign name
@@ -237,12 +236,14 @@ void ThingFactory::reset( void )
237236
m_templateHashMap.erase(templateName);
238237
}
239238

239+
DEBUG_ASSERTCRASH(!nextT || t->getTemplateID() == nextT->getTemplateID() + 1);
240+
240241
t = nextT;
241242
}
242243

243244
// TheSuperHackers @bugfix Caball009 25/12/2025 Avoid mismatches by making m_nextTemplateID unique for a single match instead of unique since game launch.
244-
DEBUG_ASSERTCRASH(m_templateHashMap.size() + 1 == m_templateCount, ("The ThingTemplate count is invalid after deleting overrides"));
245-
m_nextTemplateID = m_templateCount;
245+
DEBUG_ASSERTCRASH(m_firstTemplate && m_firstTemplate->getTemplateID() == m_templateHashMap.size(), ("Template ID is unexpected after deleting overrides"));
246+
m_nextTemplateID = static_cast<UnsignedShort>(m_templateHashMap.size());
246247
}
247248

248249
//-------------------------------------------------------------------------------------------------
@@ -547,8 +548,6 @@ void ThingFactory::postProcessLoad()
547548

548549
}
549550

550-
m_templateCount = m_nextTemplateID;
551-
552551
#ifdef CHECK_THING_NAMES
553552
dumpMissingStringNames();
554553
exit(0);

0 commit comments

Comments
 (0)