Skip to content

Commit c9dfe90

Browse files
committed
Refactored Hash_Maps to use Vectors due to Large Overhead(1) + Optimized & ordered Weapon codes
1 parent a18ef9e commit c9dfe90

31 files changed

+1337
-947
lines changed

GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ friend class Drawable; // for selection/deselection transactions
717717
void clearWorldAnimations( void ); ///< delete all world animations
718718
void updateAndDrawWorldAnimations( void ); ///< update and draw visible world animations
719719

720-
Bool findCrateCollideCommandHint( const Object *obj, const Object *other, const GameMessage *msg, Bool *isParasite );
720+
Bool findCrateCollideCommandHint( const Object *obj, const Object *other, const GameMessage *msg, Bool &isParasite );
721721

722722
SuperweaponInfo* findSWInfo(Int playerIndex, const AsciiString& powerName, ObjectID id, const SpecialPowerTemplate *powerTemplate);
723723

GeneralsMD/Code/GameEngine/Include/GameLogic/Armor.h

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,12 @@
3838

3939
// FORWARD REFERENCES /////////////////////////////////////////////////////////////////////////////
4040
class ArmorStore;
41-
typedef std::hash_map<AsciiString, Real, rts::hash<AsciiString>, rts::equal_to<AsciiString> > CustomDamageTypeMap;
42-
typedef std::hash_map< AsciiString, Int, rts::hash<AsciiString>, rts::equal_to<AsciiString> > StringListCheckMap;
41+
typedef std::pair<NameKeyType, Real> NameKeyTypeReal;
42+
typedef std::vector<NameKeyTypeReal> CustomDamageTypeVec;
43+
typedef std::pair<AsciiString, Real> AsciiStringReal;
44+
typedef std::vector<AsciiStringReal> CustomDamageStrTypeVec;
45+
//typedef std::hash_map<AsciiString, Real, rts::hash<AsciiString>, rts::equal_to<AsciiString> > CustomDamageTypeMap;
46+
//typedef std::hash_map< AsciiString, Int, rts::hash<AsciiString>, rts::equal_to<AsciiString> > StringListCheckMap;
4347

4448
//-------------------------------------------------------------------------------------------------
4549
/**
@@ -62,7 +66,7 @@ class ArmorTemplate
6266
and return the amount that should be dealt.
6367
*/
6468
Real adjustDamage(DamageType t, Real damage, const AsciiString& ct) const;
65-
Real scaleArmorBonus(ObjectStatusMaskType statusType, WeaponBonusConditionFlags weaponBonusType, ObjectCustomStatusType customStatusType, ObjectCustomStatusType customBonusType) const;
69+
Real scaleArmorBonus(ObjectStatusMaskType statusType, WeaponBonusConditionFlags weaponBonusType, const std::vector<AsciiString>& customStatusType, const std::vector<AsciiString>& customBonusType) const;
6670

6771
static void parseArmorCoefficients( INI* ini, void *instance, void* /* store */, const void* userData );
6872
static void parseArmorMultiplier( INI* ini, void *instance, void* /* store */, const void* userData );
@@ -80,9 +84,9 @@ class ArmorTemplate
8084
Real m_weaponBonusCoefficient[WEAPONBONUSCONDITION_COUNT]; ///< modifiers to damage
8185
std::vector<ObjectStatusTypes> m_statusFlags;
8286
WeaponBonusConditionTypeVec m_weaponBonusFlags;
83-
CustomDamageTypeMap m_customCoefficients;
84-
CustomDamageTypeMap m_customStatusArmorBonus;
85-
CustomDamageTypeMap m_customMultCoefficients;
87+
CustomDamageTypeVec m_customCoefficients;
88+
CustomDamageStrTypeVec m_customStatusArmorBonus;
89+
CustomDamageTypeVec m_customMultCoefficients;
8690
};
8791

8892
//-------------------------------------------------------------------------------------------------
@@ -94,7 +98,7 @@ class Armor
9498
{
9599
}
96100

97-
inline Real scaleArmorBonus(ObjectStatusMaskType statusType, WeaponBonusConditionFlags weaponBonusType, ObjectCustomStatusType customStatusType, ObjectCustomStatusType customBonusType) const
101+
inline Real scaleArmorBonus(ObjectStatusMaskType statusType, WeaponBonusConditionFlags weaponBonusType, const std::vector<AsciiString>& customStatusType, const std::vector<AsciiString>& customBonusType) const
98102
{
99103
return m_template ? m_template->scaleArmorBonus(statusType, weaponBonusType, customStatusType, customBonusType) : 1.0f;
100104
}
@@ -148,7 +152,7 @@ class ArmorStore : public SubsystemInterface
148152
DamageType m_linkDamageType;
149153
Bool m_declaredLinkDamageType;
150154
Bool m_declaredCoefficient;
151-
std::vector<AsciiString> m_customDamageTypeLink;
155+
std::vector<NameKeyType> m_customDamageTypeLink;
152156

153157
CustomDamageType() : m_coefficient(1.0f), m_declaredLinkDamageType(FALSE), m_declaredCoefficient(FALSE)
154158
{
@@ -157,26 +161,18 @@ class ArmorStore : public SubsystemInterface
157161
}
158162
};
159163

160-
typedef std::hash_map< AsciiString, CustomDamageType, rts::hash<AsciiString>, rts::equal_to<AsciiString> > CustomDamageTypesMap;
164+
//typedef std::hash_map< AsciiString, CustomDamageType, rts::hash<AsciiString>, rts::equal_to<AsciiString> > CustomDamageTypesMap;
165+
typedef std::hash_map< NameKeyType, CustomDamageType, rts::hash<NameKeyType>, rts::equal_to<NameKeyType> > CustomDamageTypesMap;
161166
CustomDamageTypesMap m_customDamageTypes;
162167

163168
CustomDamageType m_customDamageTypeParse;
164169
AsciiString m_customDamageTypeParseNext;
165170

166-
const CustomDamageTypesMap& getCustomDamageTypes() const
167-
{
168-
return m_customDamageTypes;
169-
}
170-
171-
Int getCustomDamageTypesSize() const
172-
{
173-
return m_customDamageTypes.size();
174-
}
175-
176-
Bool isNameInTypesList(const AsciiString& ct) const;
177-
std::vector<AsciiString> GetLinkInTypesList(const AsciiString& ct);
178-
DamageType GetDeclaredLinkDamageType(const AsciiString& ct);
179-
Real GetDeclaredCoefficient(const AsciiString& ct);
171+
Bool findNameInTypesList(NameKeyType nameKey, Real damage, const CustomDamageTypeVec& coefficients, DamageType &linkDamageType);
172+
Bool isNameInTypesList(NameKeyType nameKey) const;
173+
std::vector<NameKeyType> GetLinkInTypesList(NameKeyType nameKey);
174+
DamageType GetDeclaredLinkDamageType(NameKeyType nameKey);
175+
Real GetDeclaredCoefficient(NameKeyType nameKey);
180176

181177
static void parseArmorDefinition(INI* ini);
182178
static void parseArmorExtendDefinition(INI* ini);

GeneralsMD/Code/GameEngine/Include/GameLogic/FiringTracker.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ class FiringTracker : public UpdateModule
6262

6363
virtual UpdateSleepTime update(); ///< See if spin down is needed because we haven't shot in a while
6464

65+
void computeFiringTrackerBonus(const Weapon *weaponToFire, const Object *victim);
66+
void computeFiringTrackerBonusClear(const Weapon *weaponToFire);
67+
6568
protected:
6669

6770
/*
@@ -90,5 +93,9 @@ class FiringTracker : public UpdateModule
9093
AudioHandle m_audioHandle;
9194

9295
WeaponBonusConditionFlags m_prevTargetWeaponBonus; ///< weaponBonus against previous target
93-
ObjectCustomStatusType m_prevTargetCustomWeaponBonus; ///< custom weaponBonus against previous target
96+
std::vector<AsciiString> m_prevTargetCustomWeaponBonus; ///< custom weaponBonus against previous target
97+
98+
Bool m_firingTrackerBonusCleared; ///< have I cleared my Tracker Bonus
99+
ObjectStatusMaskType m_prevTargetStatus; ///< previous Target's Status
100+
std::vector<AsciiString> m_prevTargetCustomStatus; ///< previous Target's Custom Status
94101
};

GeneralsMD/Code/GameEngine/Include/GameLogic/Module/ContainModule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class ContainModuleInterface
197197

198198
virtual Bool isWeaponBonusPassedToPassengers() const = 0;
199199
virtual WeaponBonusConditionFlags getWeaponBonusPassedToPassengers() const = 0;
200-
virtual ObjectCustomStatusType getCustomWeaponBonusPassedToPassengers() const = 0;
200+
virtual const std::vector<AsciiString>& getCustomWeaponBonusPassedToPassengers() const = 0;
201201

202202
virtual void doUpgradeChecks( void ) = 0;
203203
virtual void doStatusChecks( void ) = 0;

GeneralsMD/Code/GameEngine/Include/GameLogic/Module/DumbProjectileBehavior.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class DumbProjectileBehavior : public UpdateModule, public ProjectileUpdateInter
122122
Int m_flightPathSegments; ///< number of segments in the flightpath (in case we must regen it)
123123
Int m_currentFlightPathStep; ///< Our current index in the flight path vector. Quicker than popping off.
124124
WeaponBonusConditionFlags m_extraBonusFlags;
125-
ObjectCustomStatusType m_extraBonusCustomFlags;
125+
std::vector<AsciiString> m_extraBonusCustomFlags;
126126
Bool m_noDamage;
127127
UnsignedInt m_framesTillDecoyed;
128128
UnsignedInt m_detonateDistance;

GeneralsMD/Code/GameEngine/Include/GameLogic/Module/FreeFallProjectileBehavior.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class FreeFallProjectileBehavior : public UpdateModule, public ProjectileUpdateI
120120
const WeaponTemplate* m_detonationWeaponTmpl; ///< weapon to fire at end (or null)
121121
UnsignedInt m_lifespanFrame; ///< if we haven't collided by this frame, blow up anyway
122122
WeaponBonusConditionFlags m_extraBonusFlags;
123-
ObjectCustomStatusType m_extraBonusCustomFlags;
123+
std::vector<AsciiString> m_extraBonusCustomFlags;
124124
Bool m_noDamage;
125125
UnsignedInt m_framesTillDecoyed;
126126
UnsignedInt m_detonateDistance;

GeneralsMD/Code/GameEngine/Include/GameLogic/Module/MissileAIUpdate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class MissileAIUpdate : public AIUpdateInterface, public ProjectileUpdateInterfa
144144
Coord3D m_originalTargetPos; ///< When firing uphill, we aim high to clear the brow of the hill. jba.
145145
Coord3D m_prevPos;
146146
WeaponBonusConditionFlags m_extraBonusFlags;
147-
ObjectCustomStatusType m_extraBonusCustomFlags;
147+
std::vector<AsciiString> m_extraBonusCustomFlags;
148148
const WeaponTemplate* m_detonationWeaponTmpl; ///< weapon to fire at end (or null)
149149
const ParticleSystemTemplate* m_exhaustSysTmpl;
150150
ParticleSystemID m_exhaustID; ///< our exhaust particle system (if any)

GeneralsMD/Code/GameEngine/Include/GameLogic/Module/OpenContain.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ class OpenContain : public UpdateModule,
243243

244244
virtual Bool isWeaponBonusPassedToPassengers() const;
245245
virtual WeaponBonusConditionFlags getWeaponBonusPassedToPassengers() const;
246-
virtual ObjectCustomStatusType getCustomWeaponBonusPassedToPassengers() const;
246+
virtual const std::vector<AsciiString>& getCustomWeaponBonusPassedToPassengers() const;
247247

248248
virtual void enableLoadSounds( Bool enable ) { m_loadSoundsEnabled = enable; }
249249

GeneralsMD/Code/GameEngine/Include/GameLogic/Module/RiderChangeContain.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class RiderChangeContain : public TransportContain
184184
Bool m_registeredUpgradeNames; // me three
185185

186186
ObjectStatusMaskType m_prevStatus;
187-
ObjectCustomStatusType m_prevCustomStatusTypes;
187+
std::vector<AsciiString> m_prevCustomStatusTypes;
188188

189189
ObjectStatusType m_riderDataStatusRegister;
190190
AsciiString m_riderDataCustomStatusRegister;

GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,9 @@ class Object : public Thing, public Snapshot
586586

587587
void notifyFiringTrackerShotFired( const Weapon* weaponFired, ObjectID victimID ) ;
588588

589+
void computeFiringTrackerBonus(const Weapon *weaponToFire, const Object *victim);
590+
void computeFiringTrackerBonusClear(const Weapon *weaponToFire);
591+
589592
/**
590593
Determines if the unit has any weapon that could conceivably
591594
harm the victim. this does not take range, ammo, etc. into
@@ -637,8 +640,9 @@ class Object : public Thing, public Snapshot
637640
Bool isCurWeaponLocked() const { return m_weaponSet.isCurWeaponLocked(); }
638641
Bool isCurWeaponLockedPriority() const { return m_weaponSet.isCurWeaponLockedPriority(); }
639642

640-
ObjectCustomStatusType getCustomStatus() const { return m_customStatus; }
641-
void setCustomStatusFlags(ObjectCustomStatusType customStatusMap) { m_customStatus = customStatusMap; }
643+
//const ObjectCustomStatusType *getCustomStatus() const { return &m_customStatus; }
644+
std::vector<AsciiString> getCustomStatus() const { return m_customStatusSet; }
645+
void setCustomStatusFlags( const std::vector<AsciiString>& customStatusSetVec ) { m_customStatusSet = customStatusSetVec; }
642646
Bool testCustomStatus(const AsciiString& cst) const;
643647
Bool testCustomStatusForAll(const std::vector<AsciiString>& cst) const;
644648

@@ -679,29 +683,31 @@ class Object : public Thing, public Snapshot
679683
inline WeaponBonusConditionFlags getWeaponBonusConditionAgainst() const { return m_weaponBonusConditionAgainst; }
680684
inline void setWeaponBonusConditionFlagsAgainst(WeaponBonusConditionFlags flags) { m_weaponBonusConditionAgainst = flags; }
681685

682-
void applyCustomWeaponBonusConditionFlags(ObjectCustomStatusType flags);
683-
void removeCustomWeaponBonusConditionFlags(ObjectCustomStatusType flags);
686+
void applyCustomWeaponBonusConditionFlags(const std::vector<AsciiString>& flags);
687+
void removeCustomWeaponBonusConditionFlags(const std::vector<AsciiString>& flags);
684688

685689
void setCustomWeaponBonusConditionAgainst(const AsciiString& cst);
686690
void clearCustomWeaponBonusConditionAgainst(const AsciiString& cst);
687691
Bool testCustomWeaponBonusConditionAgainst(const AsciiString& cst) const;
688-
const ObjectCustomStatusType getCustomWeaponBonusConditionAgainst() const { return m_customWeaponBonusConditionAgainst; }
689-
void setCustomWeaponBonusConditionFlagsAgainst(ObjectCustomStatusType flags) { m_customWeaponBonusConditionAgainst = flags; }
692+
//const ObjectCustomStatusType *getCustomWeaponBonusConditionAgainst() const { return &m_customWeaponBonusConditionAgainst; }
693+
std::vector<AsciiString> getCustomWeaponBonusConditionAgainst() const { return m_customWeaponBonusConditionAgainst; }
694+
void setCustomWeaponBonusConditionFlagsAgainst(const std::vector<AsciiString>& flags) { m_customWeaponBonusConditionAgainst = flags; }
690695

691696

692-
ObjectCustomStatusType getCustomWeaponBonusCondition() const { return m_customWeaponBonusCondition; }
697+
//const ObjectCustomStatusType *getCustomWeaponBonusCondition() const { return &m_customWeaponBonusCondition; }
698+
std::vector<AsciiString> getCustomWeaponBonusCondition() const { return m_customWeaponBonusCondition; }
693699
// TO-DO: Change to Hash_Map. DONE.
694-
void setCustomWeaponBonusConditionFlags(ObjectCustomStatusType customFlags) {
695-
m_customWeaponBonusCondition.clear();
696-
m_customWeaponBonusCondition = customFlags;
697-
}
700+
/// Reverted to use Vector.
701+
void setCustomWeaponBonusConditionFlags(const std::vector<AsciiString>& customFlags) { m_customWeaponBonusCondition = customFlags; }
698702
Bool testCustomWeaponBonusCondition(const AsciiString& cst) const;
699703

700704
WeaponBonusConditionFlags getWeaponBonusConditionIgnoreClear() const { return m_weaponBonusConditionIC; }
701-
ObjectCustomStatusType getCustomWeaponBonusConditionIgnoreClear() const { return m_customWeaponBonusConditionIC; }
705+
//const ObjectCustomStatusType *getCustomWeaponBonusConditionIgnoreClear() const { return &m_customWeaponBonusConditionIC; }
706+
std::vector<AsciiString> getCustomWeaponBonusConditionIgnoreClear() const { return m_customWeaponBonusConditionIC; }
702707

703708
inline void setWeaponBonusConditionIgnoreClear(WeaponBonusConditionFlags flags) { m_weaponBonusConditionIC = flags; }
704-
void setCustomWeaponBonusConditionIgnoreClear(ObjectCustomStatusType map) { m_customWeaponBonusConditionIC = map; }
709+
//void setCustomWeaponBonusConditionIgnoreClear(ObjectCustomStatusType map) { m_customWeaponBonusConditionIC = map; }
710+
void setCustomWeaponBonusConditionIgnoreClear(const std::vector<AsciiString>& vec) { m_customWeaponBonusConditionIC = vec; }
705711

706712
void doWeaponBonusChange() { m_weaponSet.weaponSetOnWeaponBonusChange(this); }
707713

@@ -983,7 +989,8 @@ class Object : public Thing, public Snapshot
983989
Object * m_next;
984990
Object * m_prev;
985991
ObjectStatusMaskType m_status; ///< status bits (see ObjectStatusMaskType)
986-
ObjectCustomStatusType m_customStatus;
992+
//ObjectCustomStatusType m_customStatus;
993+
std::vector<AsciiString> m_customStatusSet;
987994

988995
ObjectID m_shielderID;
989996
ObjectID m_shieldingID;
@@ -1079,11 +1086,12 @@ class Object : public Thing, public Snapshot
10791086
WeaponSet m_weaponSet;
10801087
WeaponSetFlags m_curWeaponSetFlags;
10811088
WeaponBonusConditionFlags m_weaponBonusCondition;
1082-
ObjectCustomStatusType m_customWeaponBonusCondition;
1089+
//ObjectCustomStatusType m_customWeaponBonusCondition;
1090+
std::vector<AsciiString> m_customWeaponBonusCondition;
10831091

10841092
//Ignore Bonus Types to clear if it is bonus granted outside of new Firing Tracker system.
10851093
WeaponBonusConditionFlags m_weaponBonusConditionIC;
1086-
ObjectCustomStatusType m_customWeaponBonusConditionIC;
1094+
std::vector<AsciiString> m_customWeaponBonusConditionIC;
10871095

10881096
Real m_invsqrt_mass;
10891097
//Real m_magnetLevitateHeight;
@@ -1096,7 +1104,8 @@ class Object : public Thing, public Snapshot
10961104
Byte m_lastWeaponCondition[WEAPONSLOT_COUNT];
10971105

10981106
WeaponBonusConditionFlags m_weaponBonusConditionAgainst; ///< Weapon bonus granted when attacking this target;
1099-
ObjectCustomStatusType m_customWeaponBonusConditionAgainst; ///< Weapon bonus granted when attacking this target;
1107+
//ObjectCustomStatusType m_customWeaponBonusConditionAgainst; ///< Weapon bonus granted when attacking this target;
1108+
std::vector<AsciiString> m_customWeaponBonusConditionAgainst; ///< Weapon bonus granted when attacking this target;
11001109

11011110
SpecialPowerMaskType m_specialPowerBits; ///< bits determining what kind of special abilities this object has access to.
11021111

0 commit comments

Comments
 (0)