File tree Expand file tree Collapse file tree 8 files changed +66
-16
lines changed
GeneralsMD/Code/GameEngine/Include
Generals/Code/GameEngine/Include Expand file tree Collapse file tree 8 files changed +66
-16
lines changed Original file line number Diff line number Diff line change 42
42
#undef SPARSEMATCH_DEBUG
43
43
#endif
44
44
45
+ typedef UnsignedInt SparseMatchFinderFlags;
46
+ enum SparseMatchFinderFlags_ CPP_11 (: SparseMatchFinderFlags)
47
+ {
48
+ SparseMatchFinderFlags_NoCopy = 1 <<0 ,
49
+ };
50
+
45
51
// -------------------------------------------------------------------------------------------------
46
- template <class MATCHABLE , class BITSET >
52
+ template <class MATCHABLE , class BITSET , SparseMatchFinderFlags FLAGS = 0 >
47
53
class SparseMatchFinder
48
54
{
49
55
private:
@@ -183,9 +189,29 @@ class SparseMatchFinder
183
189
return result;
184
190
}
185
191
186
- // -------------------------------------------------------------------------------------------------
187
192
public:
188
193
194
+
195
+ // -------------------------------------------------------------------------------------------------
196
+ SparseMatchFinder () {}
197
+ SparseMatchFinder (const SparseMatchFinder& other)
198
+ {
199
+ *this = other;
200
+ }
201
+
202
+ // -------------------------------------------------------------------------------------------------
203
+ SparseMatchFinder& operator =(const SparseMatchFinder& other)
204
+ {
205
+ if CONSTEXPR ((FLAGS & SparseMatchFinderFlags_NoCopy) == 0 )
206
+ {
207
+ if (this != &other)
208
+ {
209
+ m_bestMatches = other.m_bestMatches ;
210
+ }
211
+ }
212
+ return *this ;
213
+ }
214
+
189
215
// -------------------------------------------------------------------------------------------------
190
216
void clear ()
191
217
{
Original file line number Diff line number Diff line change @@ -681,6 +681,11 @@ class ThingTemplate : public Overridable
681
681
// Code renderer handles these states now.
682
682
// AsciiString m_inventoryImage[ INV_IMAGE_NUM_IMAGES ]; ///< portrait inventory pictures
683
683
684
+ // TheSuperHackers @bugfix Caball009/xezon 06/07/2025 No longer copy SparseMatchFinder to prevent copied instances linking to unrelated data.
685
+ // This avoids mismatching in certain maps, for example those that spawn units with veterancy.
686
+ typedef SparseMatchFinder<WeaponTemplateSet, WeaponSetFlags, SparseMatchFinderFlags_NoCopy> WeaponTemplateSetFinder;
687
+ typedef SparseMatchFinder<ArmorTemplateSet, ArmorSetFlags, SparseMatchFinderFlags_NoCopy> ArmorTemplateSetFinder;
688
+
684
689
// ---- STL-sized things
685
690
std::vector<ProductionPrerequisite> m_prereqInfo; // /< the unit Prereqs for this tech
686
691
std::vector<AsciiString> m_buildVariations; /* *< if we build a unit of this type via script or ui, randomly choose one
Original file line number Diff line number Diff line change @@ -94,7 +94,4 @@ class ArmorTemplateSet
94
94
// -------------------------------------------------------------------------------------------------
95
95
typedef std::vector<ArmorTemplateSet> ArmorTemplateSetVector;
96
96
97
- // -------------------------------------------------------------------------------------------------
98
- typedef SparseMatchFinder<ArmorTemplateSet, ArmorSetFlags> ArmorTemplateSetFinder;
99
-
100
97
#endif // _ArmorSet_H_
Original file line number Diff line number Diff line change @@ -146,9 +146,6 @@ class WeaponTemplateSet
146
146
// -------------------------------------------------------------------------------------------------
147
147
typedef std::vector<WeaponTemplateSet> WeaponTemplateSetVector;
148
148
149
- // -------------------------------------------------------------------------------------------------
150
- typedef SparseMatchFinder<WeaponTemplateSet, WeaponSetFlags> WeaponTemplateSetFinder;
151
-
152
149
// -------------------------------------------------------------------------------------------------
153
150
enum WeaponChoiceCriteria CPP_11 (: Int)
154
151
{
Original file line number Diff line number Diff line change 42
42
#undef SPARSEMATCH_DEBUG
43
43
#endif
44
44
45
+ typedef UnsignedInt SparseMatchFinderFlags;
46
+ enum SparseMatchFinderFlags_ CPP_11 (: SparseMatchFinderFlags)
47
+ {
48
+ SparseMatchFinderFlags_NoCopy = 1 <<0 ,
49
+ };
50
+
45
51
// -------------------------------------------------------------------------------------------------
46
- template <class MATCHABLE , class BITSET >
52
+ template <class MATCHABLE , class BITSET , SparseMatchFinderFlags FLAGS = 0 >
47
53
class SparseMatchFinder
48
54
{
49
55
private:
@@ -185,9 +191,29 @@ class SparseMatchFinder
185
191
return result;
186
192
}
187
193
188
- // -------------------------------------------------------------------------------------------------
189
194
public:
190
195
196
+
197
+ // -------------------------------------------------------------------------------------------------
198
+ SparseMatchFinder () {}
199
+ SparseMatchFinder (const SparseMatchFinder& other)
200
+ {
201
+ *this = other;
202
+ }
203
+
204
+ // -------------------------------------------------------------------------------------------------
205
+ SparseMatchFinder& operator =(const SparseMatchFinder& other)
206
+ {
207
+ if CONSTEXPR ((FLAGS & SparseMatchFinderFlags_NoCopy) == 0 )
208
+ {
209
+ if (this != &other)
210
+ {
211
+ m_bestMatches = other.m_bestMatches ;
212
+ }
213
+ }
214
+ return *this ;
215
+ }
216
+
191
217
// -------------------------------------------------------------------------------------------------
192
218
void clear ()
193
219
{
Original file line number Diff line number Diff line change @@ -698,6 +698,11 @@ class ThingTemplate : public Overridable
698
698
// Code renderer handles these states now.
699
699
// AsciiString m_inventoryImage[ INV_IMAGE_NUM_IMAGES ]; ///< portrait inventory pictures
700
700
701
+ // TheSuperHackers @bugfix Caball009/xezon 06/07/2025 No longer copy SparseMatchFinder to prevent copied instances linking to unrelated data.
702
+ // This avoids mismatching in certain maps, for example those that spawn units with veterancy.
703
+ typedef SparseMatchFinder<WeaponTemplateSet, WeaponSetFlags, SparseMatchFinderFlags_NoCopy> WeaponTemplateSetFinder;
704
+ typedef SparseMatchFinder<ArmorTemplateSet, ArmorSetFlags, SparseMatchFinderFlags_NoCopy> ArmorTemplateSetFinder;
705
+
701
706
// ---- STL-sized things
702
707
std::vector<ProductionPrerequisite> m_prereqInfo; // /< the unit Prereqs for this tech
703
708
std::vector<AsciiString> m_buildVariations; /* *< if we build a unit of this type via script or ui, randomly choose one
Original file line number Diff line number Diff line change @@ -97,7 +97,4 @@ class ArmorTemplateSet
97
97
// -------------------------------------------------------------------------------------------------
98
98
typedef std::vector<ArmorTemplateSet> ArmorTemplateSetVector;
99
99
100
- // -------------------------------------------------------------------------------------------------
101
- typedef SparseMatchFinder<ArmorTemplateSet, ArmorSetFlags> ArmorTemplateSetFinder;
102
-
103
100
#endif // _ArmorSet_H_
Original file line number Diff line number Diff line change @@ -166,9 +166,6 @@ class WeaponTemplateSet
166
166
// -------------------------------------------------------------------------------------------------
167
167
typedef std::vector<WeaponTemplateSet> WeaponTemplateSetVector;
168
168
169
- // -------------------------------------------------------------------------------------------------
170
- typedef SparseMatchFinder<WeaponTemplateSet, WeaponSetFlags> WeaponTemplateSetFinder;
171
-
172
169
// -------------------------------------------------------------------------------------------------
173
170
enum WeaponChoiceCriteria CPP_11 (: Int)
174
171
{
You can’t perform that action at this time.
0 commit comments