Skip to content

Commit 035624e

Browse files
authored
[GEN] Backport several GameEngine additions from Zero Hour (#752)
1 parent 7d884ad commit 035624e

File tree

74 files changed

+1418
-95
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1418
-95
lines changed

Generals/Code/GameEngine/Include/Common/ArchiveFileSystem.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,10 @@ class ArchiveFileSystem : public SubsystemInterface
172172

173173
// Unprotected this for copy-protection routines
174174
AsciiString getArchiveFilenameForFile(const AsciiString& filename) const;
175-
176175
void loadMods( void );
177176

178177
protected:
179-
virtual void loadIntoDirectoryTree(const ArchiveFile *archiveFile, const AsciiString& archiveFilename, Bool overwrite = FALSE); ///< load the archive file's header information and apply it to the global archive directory tree.
178+
virtual void loadIntoDirectoryTree(const ArchiveFile *archiveFile, const AsciiString& archiveFilename, Bool overwrite = FALSE ); ///< load the archive file's header information and apply it to the global archive directory tree.
180179

181180
ArchiveFileMap m_archiveFileMap;
182181
ArchivedDirectoryInfo m_rootDirectory;

Generals/Code/GameEngine/Include/Common/BitFlagsIO.h

+12
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,18 @@ template <size_t NUMBITS>
138138
((BitFlags*)store)->parse(ini, NULL);
139139
}
140140

141+
//-------------------------------------------------------------------------------------------------
142+
//-------------------------------------------------------------------------------------------------
143+
template <size_t NUMBITS>
144+
/*static*/ void BitFlags<NUMBITS>::parseSingleBitFromINI(INI* ini, void* /*instance*/, void *store, const void* /*userData*/)
145+
{
146+
const char *token = ini->getNextToken();
147+
Int bitIndex = INI::scanIndexList(token, s_bitNameList); // this throws if the token is not found
148+
149+
Int *storeAsInt = (Int*)store;
150+
*storeAsInt = bitIndex;
151+
}
152+
141153
//-------------------------------------------------------------------------------------------------
142154
/** Xfer method
143155
* Version Info:

Generals/Code/GameEngine/Include/Common/DataChunk.h

+3
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ class DataChunkOutput
136136
void writeUnicodeString(UnicodeString string);
137137
void writeArrayOfBytes(char *ptr, Int len);
138138
void writeDict(const Dict& d);
139+
void writeNameKey(const NameKeyType key);
139140
};
140141

141142
//----------------------------------------------------------------------
@@ -228,6 +229,8 @@ class DataChunkInput
228229
UnicodeString readUnicodeString(void);
229230
Dict readDict(void);
230231
void readArrayOfBytes(char *ptr, Int len);
232+
233+
NameKeyType readNameKey(void);
231234
};
232235

233236

Generals/Code/GameEngine/Include/Common/Energy.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class Energy : public Snapshot
6666

6767
public:
6868

69-
inline Energy() : m_energyProduction(0), m_energyConsumption(0), m_owner(NULL) { }
69+
Energy();
7070

7171
// reset energy information to base values.
7272
void init( Player *owner)
@@ -77,7 +77,7 @@ class Energy : public Snapshot
7777
}
7878

7979
/// return current energy production in kilowatts
80-
Int getProduction() const { return m_energyProduction; }
80+
Int getProduction() const;
8181

8282
/// return current energy consumption in kilowatts
8383
Int getConsumption() const { return m_energyConsumption; }

Generals/Code/GameEngine/Include/Common/GameAudio.h

-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,6 @@ class AudioManager : public SubsystemInterface
316316

317317
// For tracking purposes
318318
virtual AudioHandle allocateNewHandle( void );
319-
320319
// Remove all AudioEventInfo's with the m_isLevelSpecific flag
321320
virtual void removeLevelSpecificAudioEventInfos( void );
322321

Generals/Code/GameEngine/Include/Common/Geometry.h

+1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ class GeometryInfo : public Snapshot
179179

180180
/// note that the pt is generated using game logic random, not game client random!
181181
void makeRandomOffsetWithinFootprint(Coord3D& pt) const;
182+
void makeRandomOffsetOnPerimeter(Coord3D& pt) const; //Chooses a random point on the extent border.
182183

183184
void clipPointToFootprint(const Coord3D& geomCenter, Coord3D& ptToClip) const;
184185

Generals/Code/GameEngine/Include/Common/Money.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,15 @@ class Money : public Snapshot
8282

8383
void setPlayerIndex(Int ndx) { m_playerIndex = ndx; }
8484

85-
protected:
85+
static void parseMoneyAmount( INI *ini, void *instance, void *store, const void* userData );
86+
87+
// Does the amount of this == the amount of that (compare everything except m_playerIndex)
88+
Bool amountEqual( const Money & that ) const
89+
{
90+
return m_money == that.m_money;
91+
}
8692

93+
protected:
8794
// snapshot methods
8895
virtual void crc( Xfer *xfer );
8996
virtual void xfer( Xfer *xfer );

Generals/Code/GameEngine/Include/Common/MultiplayerSettings.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ class MultiplayerSettings : public SubsystemInterface
7979

8080
MultiplayerSettings( void );
8181

82-
void init() { }
83-
void update() { }
84-
void reset() { }
82+
virtual void init() { }
83+
virtual void update() { }
84+
virtual void reset() { }
8585

8686
//-----------------------------------------------------------------------------------------------
8787
static const FieldParse m_multiplayerSettingsFieldParseTable[]; ///< the parse table for INI definition

Generals/Code/GameEngine/Include/Common/NameKeyGenerator.h

+5
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,11 @@ class NameKeyGenerator : public SubsystemInterface
9696

9797
/// Given a string, convert into a unique integer key.
9898
NameKeyType nameToKey(const AsciiString& name) { return nameToKey(name.str()); }
99+
NameKeyType nameToLowercaseKey(const AsciiString& name) { return nameToLowercaseKey(name.str()); }
99100

100101
/// Given a string, convert into a unique integer key.
101102
NameKeyType nameToKey(const char* name);
103+
NameKeyType nameToLowercaseKey(const char *name);
102104

103105
/**
104106
given a key, return the name. this is almost never needed,
@@ -108,6 +110,9 @@ class NameKeyGenerator : public SubsystemInterface
108110
*/
109111
AsciiString keyToName(NameKeyType key);
110112

113+
// Get a string out of the INI. Store it into a NameKeyType
114+
static void parseStringAsNameKeyType( INI *ini, void *instance, void *store, const void* userData );
115+
111116
private:
112117

113118
enum

Generals/Code/GameEngine/Include/Common/Radar.h

+1
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ class Radar : public Snapshot,
169169
Bool isRadarWindow( GameWindow *window ) { return (m_radarWindow == window) && (m_radarWindow != NULL); }
170170

171171
Bool radarToWorld( const ICoord2D *radar, Coord3D *world ); ///< radar point to world point on terrain
172+
Bool radarToWorld2D( const ICoord2D *radar, Coord3D *world ); ///< radar point to world point (x,y only!)
172173
Bool worldToRadar( const Coord3D *world, ICoord2D *radar ); ///< translate world point to radar (x,y)
173174
Bool localPixelToRadar( const ICoord2D *pixel, ICoord2D *radar ); ///< translate pixel (with UL of radar being (0,0)) to logical radar coords
174175
Bool screenPixelToWorld( const ICoord2D *pixel, Coord3D *world ); ///< translate pixel (with UL of the screen being (0,0)) to world position in the world

Generals/Code/GameEngine/Include/Common/SparseMatchFinder.h

+20
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,26 @@ class SparseMatchFinder
7272
}
7373
};
7474

75+
struct MapHelper
76+
{
77+
bool operator()(const BITSET& a, const BITSET& b) const
78+
{
79+
int i;
80+
if (a.size() < b.size()) {
81+
return true;
82+
}
83+
for (i = 0; i < a.size(); ++i) {
84+
bool aVal = a.test(i);
85+
bool bVal = b.test(i);
86+
if (aVal && bVal) continue;
87+
if (!aVal && !bVal) continue;
88+
if (!aVal) return true;
89+
return false;
90+
}
91+
return false; // all bits match.
92+
}
93+
};
94+
7595
//-------------------------------------------------------------------------------------------------
7696
typedef std::hash_map< BITSET, const MATCHABLE*, HashMapHelper, HashMapHelper > MatchMap;
7797

Generals/Code/GameEngine/Include/Common/SpecialPowerMaskType.h

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#define __SPECIALPOWERMASKTYPE_H__
3232

3333
#include "Common/BitFlags.h"
34+
#include "Common/BitFlagsIO.h"
3435
#include "Common/SpecialPowerType.h"
3536

3637
typedef BitFlags<SPECIALPOWER_COUNT> SpecialPowerMaskType;

Generals/Code/GameEngine/Include/Common/StateMachine.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class State;
4545
class StateMachine;
4646
class Object;
4747

48-
#undef STATE_MACHINE_DEBUG
48+
//#undef STATE_MACHINE_DEBUG
4949
#if defined(RTS_DEBUG)
5050
#define STATE_MACHINE_DEBUG
5151
#endif
@@ -169,6 +169,7 @@ class State : public MemoryPoolObject, public Snapshot
169169

170170
#ifdef STATE_MACHINE_DEBUG
171171
virtual AsciiString getName() const {return m_name;}
172+
std::vector<StateID> *getTransitions(void);
172173
#endif
173174

174175
// for internal use by the StateMachine class ---------------------------------------------------------

Generals/Code/GameEngine/Include/Common/crc.h

+76
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
#define _CRC_H_
3333

3434
#include "Lib/BaseType.h"
35+
36+
#ifdef RTS_DEBUG
37+
3538
//#include "winsock2.h" // for htonl
3639

3740
class CRC
@@ -50,4 +53,77 @@ class CRC
5053
UnsignedInt crc;
5154
};
5255

56+
#else
57+
58+
// optimized inline only version
59+
class CRC
60+
{
61+
public:
62+
CRC(void) { crc=0; }
63+
64+
/// Compute the CRC for a buffer, added into current CRC
65+
__forceinline void computeCRC( const void *buf, Int len )
66+
{
67+
if (!buf||len<1)
68+
return;
69+
70+
#if !(defined(_MSC_VER) && _MSC_VER < 1300)
71+
// C++ version left in for reference purposes
72+
for (UnsignedByte *uintPtr=(UnsignedByte *)buf;len>0;len--,uintPtr++)
73+
{
74+
int hibit;
75+
if (crc & 0x80000000)
76+
{
77+
hibit = 1;
78+
}
79+
else
80+
{
81+
hibit = 0;
82+
}
83+
84+
crc <<= 1;
85+
crc += *uintPtr;
86+
crc += hibit;
87+
}
88+
#else
89+
// ASM version, verified by comparing resulting data with C++ version data
90+
unsigned *crcPtr=&crc;
91+
_asm
92+
{
93+
mov esi,[buf]
94+
mov ecx,[len]
95+
dec ecx
96+
mov edi,[crcPtr]
97+
mov ebx,dword ptr [edi]
98+
xor eax,eax
99+
lp:
100+
mov al,byte ptr [esi]
101+
shl ebx,1
102+
inc esi
103+
adc ebx,eax
104+
dec ecx
105+
jns lp
106+
mov dword ptr [edi],ebx
107+
};
108+
#endif
109+
}
110+
111+
/// Clears the CRC to 0
112+
void clear( void )
113+
{
114+
crc = 0;
115+
}
116+
117+
///< Get the combined CRC
118+
UnsignedInt get( void ) const
119+
{
120+
return crc;
121+
}
122+
123+
private:
124+
UnsignedInt crc;
125+
};
126+
127+
#endif
128+
53129
#endif // _CRC_H_

Generals/Code/GameEngine/Include/GameClient/Color.h

+9
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ extern void GameGetColorComponents( Color color,
7676
UnsignedByte *green,
7777
UnsignedByte *blue,
7878
UnsignedByte *alpha );
79+
80+
// Put on ice until later - M Lorenzen
81+
//extern void GameGetColorComponentsWithCheatSpy( Color color,
82+
// UnsignedByte *red,
83+
// UnsignedByte *green,
84+
// UnsignedByte *blue,
85+
// UnsignedByte *alpha );
86+
87+
7988
extern void GameGetColorComponentsReal( Color color, Real *red, Real *green, Real *blue, Real *alpha );
8089

8190
extern Color GameDarkenColor( Color color, Int percent = 10 );

Generals/Code/GameEngine/Include/GameClient/ControlBar.h

+15-3
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,10 @@ class CommandButton : public Overridable
341341

342342
// bleah. shouldn't be const, but is. sue me. (srj)
343343
void copyImagesFrom( const CommandButton *button, Bool markUIDirtyIfChanged ) const;
344+
345+
// bleah. shouldn't be const, but is. sue me. (Kris) -snork!
346+
void copyButtonTextFrom( const CommandButton *button, Bool shortcutButton, Bool markUIDirtyIfChanged ) const;
347+
344348
// bleah. shouldn't be const, but is. sue me. (srj)
345349
void setFlashCount(Int c) const { m_flashCount = c; }
346350

@@ -359,8 +363,11 @@ class CommandButton : public Overridable
359363
RadiusCursorType m_radiusCursor; ///< radius cursor, if any
360364
AsciiString m_cursorName; ///< cursor name for placement (NEED_TARGET_POS) or valid version (CONTEXTMODE_COMMAND)
361365
AsciiString m_invalidCursorName; ///< cursor name for invalid version
362-
AsciiString m_textLabel; ///< string manager text label
363-
AsciiString m_descriptionLabel; ///< The description of the current command, read in from the ini
366+
367+
// bleah. shouldn't be mutable, but is. sue me. (Kris) -snork!
368+
mutable AsciiString m_textLabel; ///< string manager text label
369+
mutable AsciiString m_descriptionLabel; ///< The description of the current command, read in from the ini
370+
364371
AsciiString m_purchasedLabel; ///< Description for the current command if it has already been purchased.
365372
AsciiString m_conflictingLabel; ///< Description for the current command if it can't be selected due to multually-exclusive choice.
366373
WeaponSlotType m_weaponSlot; ///< for commands that refer to a weapon slot
@@ -640,7 +647,7 @@ class ControlBar : public SubsystemInterface
640647
virtual void update( void ); ///< from subsystem interface
641648

642649
/// mark the UI as dirty so the context of everything is re-evaluated
643-
void markUIDirty( void ) { m_UIDirty = TRUE; }
650+
void markUIDirty( void );
644651

645652
/// a drawable has just become selected
646653
void onDrawableSelected( Drawable *draw );
@@ -999,6 +1006,11 @@ class ControlBar : public SubsystemInterface
9991006
Bool m_radarAttackGlowOn;
10001007
Int m_remainingRadarAttackGlowFrames;
10011008
GameWindow *m_radarAttackGlowWindow;
1009+
1010+
#if defined( RTS_INTERNAL ) || defined( RTS_DEBUG )
1011+
UnsignedInt m_lastFrameMarkedDirty;
1012+
UnsignedInt m_consecutiveDirtyFrames;
1013+
#endif
10021014
// ControlBarResizer *m_controlBarResizer;
10031015

10041016
};

Generals/Code/GameEngine/Include/GameClient/GadgetCheckBox.h

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
extern void GadgetCheckBoxSetText( GameWindow *g, UnicodeString text );
8181
extern Bool GadgetCheckBoxIsChecked( GameWindow *g );
8282
extern void GadgetCheckBoxSetChecked( GameWindow *g, Bool isChecked);
83+
extern void GadgetCheckBoxToggle( GameWindow *g);
8384

8485
inline void GadgetCheckBoxSetEnabledImage( GameWindow *g, const Image *image ) { g->winSetEnabledImage( 0, image ); }
8586
inline void GadgetCheckBoxSetEnabledColor( GameWindow *g, Color color ) { g->winSetEnabledColor( 0, color ); }

Generals/Code/GameEngine/Include/GameClient/GameWindow.h

+1
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ friend class GameWindowManager;
248248
Int winBringToTop( void ); ///< bring this window to the top of the win list
249249
Int winEnable( Bool enable ); /**< enable/disable a window, a disbled
250250
window can be seen but accepts no input */
251+
Bool winGetEnabled( void ); ///< Is window enabled?
251252
Int winHide( Bool hide ); ///< hide/unhide a window
252253
Bool winIsHidden( void ); ///< is this window hidden/
253254
UnsignedInt winSetStatus( UnsignedInt status ); ///< set status bits

Generals/Code/GameEngine/Include/GameClient/Mouse.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ class Mouse : public SubsystemInterface
281281
void mouseNotifyResolutionChange(void);
282282

283283
Bool isClick(const ICoord2D *anchor, const ICoord2D *dest, UnsignedInt previousMouseClick, UnsignedInt currentMouseClick);
284-
284+
285285
AsciiString m_tooltipFontName; ///< tooltip font
286286
Int m_tooltipFontSize; ///< tooltip font
287287
Bool m_tooltipFontIsBold; ///< tooltip font

Generals/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h

+3
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,8 @@ class AIUpdateInterface : public UpdateModule, public AICommandInterface
412412
Real getLocomotorDistanceToGoal();
413413
const Locomotor *getCurLocomotor() const {return m_curLocomotor;}
414414
Locomotor *getCurLocomotor() { return m_curLocomotor; }
415+
LocomotorSetType getCurLocomotorSetType() const { return m_curLocomotorSet; }
416+
Bool hasLocomotorForSurface(LocomotorSurfaceType surfaceType);
415417

416418
// turret stuff.
417419
WhichTurretType getWhichTurretForWeaponSlot(WeaponSlotType wslot, Real* turretAngle, Real* turretPitch = NULL) const;
@@ -476,6 +478,7 @@ class AIUpdateInterface : public UpdateModule, public AICommandInterface
476478
void friend_endingMove(void);
477479

478480
void friend_setPath(Path *newPath);
481+
Path* friend_getPath() { return m_path; }
479482

480483
void friend_setGoalObject(Object *obj);
481484

0 commit comments

Comments
 (0)