Skip to content

[GEN] Backport several GameEngine additions from Zero Hour #752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 9, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Generals/Code/GameEngine/Include/Common/ArchiveFileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,10 @@ class ArchiveFileSystem : public SubsystemInterface

// Unprotected this for copy-protection routines
AsciiString getArchiveFilenameForFile(const AsciiString& filename) const;

void loadMods( void );

protected:
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.
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.

ArchiveFileMap m_archiveFileMap;
ArchivedDirectoryInfo m_rootDirectory;
Expand Down
12 changes: 12 additions & 0 deletions Generals/Code/GameEngine/Include/Common/BitFlagsIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,18 @@ template <size_t NUMBITS>
((BitFlags*)store)->parse(ini, NULL);
}

//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
template <size_t NUMBITS>
/*static*/ void BitFlags<NUMBITS>::parseSingleBitFromINI(INI* ini, void* /*instance*/, void *store, const void* /*userData*/)
{
const char *token = ini->getNextToken();
Int bitIndex = INI::scanIndexList(token, s_bitNameList); // this throws if the token is not found

Int *storeAsInt = (Int*)store;
*storeAsInt = bitIndex;
}

//-------------------------------------------------------------------------------------------------
/** Xfer method
* Version Info:
Expand Down
3 changes: 3 additions & 0 deletions Generals/Code/GameEngine/Include/Common/DataChunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class DataChunkOutput
void writeUnicodeString(UnicodeString string);
void writeArrayOfBytes(char *ptr, Int len);
void writeDict(const Dict& d);
void writeNameKey(const NameKeyType key);
};

//----------------------------------------------------------------------
Expand Down Expand Up @@ -228,6 +229,8 @@ class DataChunkInput
UnicodeString readUnicodeString(void);
Dict readDict(void);
void readArrayOfBytes(char *ptr, Int len);

NameKeyType readNameKey(void);
};


Expand Down
4 changes: 2 additions & 2 deletions Generals/Code/GameEngine/Include/Common/Energy.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Energy : public Snapshot

public:

inline Energy() : m_energyProduction(0), m_energyConsumption(0), m_owner(NULL) { }
Energy();

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

/// return current energy production in kilowatts
Int getProduction() const { return m_energyProduction; }
Int getProduction() const;

/// return current energy consumption in kilowatts
Int getConsumption() const { return m_energyConsumption; }
Expand Down
1 change: 0 additions & 1 deletion Generals/Code/GameEngine/Include/Common/GameAudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ class AudioManager : public SubsystemInterface

// For tracking purposes
virtual AudioHandle allocateNewHandle( void );

// Remove all AudioEventInfo's with the m_isLevelSpecific flag
virtual void removeLevelSpecificAudioEventInfos( void );

Expand Down
1 change: 1 addition & 0 deletions Generals/Code/GameEngine/Include/Common/Geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ class GeometryInfo : public Snapshot

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

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

Expand Down
9 changes: 8 additions & 1 deletion Generals/Code/GameEngine/Include/Common/Money.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,15 @@ class Money : public Snapshot

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

protected:
static void parseMoneyAmount( INI *ini, void *instance, void *store, const void* userData );

// Does the amount of this == the amount of that (compare everything except m_playerIndex)
Bool amountEqual( const Money & that ) const
{
return m_money == that.m_money;
}

protected:
// snapshot methods
virtual void crc( Xfer *xfer );
virtual void xfer( Xfer *xfer );
Expand Down
6 changes: 3 additions & 3 deletions Generals/Code/GameEngine/Include/Common/MultiplayerSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ class MultiplayerSettings : public SubsystemInterface

MultiplayerSettings( void );

void init() { }
void update() { }
void reset() { }
virtual void init() { }
virtual void update() { }
virtual void reset() { }

//-----------------------------------------------------------------------------------------------
static const FieldParse m_multiplayerSettingsFieldParseTable[]; ///< the parse table for INI definition
Expand Down
5 changes: 5 additions & 0 deletions Generals/Code/GameEngine/Include/Common/NameKeyGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ class NameKeyGenerator : public SubsystemInterface

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

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

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

// Get a string out of the INI. Store it into a NameKeyType
static void parseStringAsNameKeyType( INI *ini, void *instance, void *store, const void* userData );

private:

enum
Expand Down
1 change: 1 addition & 0 deletions Generals/Code/GameEngine/Include/Common/Radar.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ class Radar : public Snapshot,
Bool isRadarWindow( GameWindow *window ) { return (m_radarWindow == window) && (m_radarWindow != NULL); }

Bool radarToWorld( const ICoord2D *radar, Coord3D *world ); ///< radar point to world point on terrain
Bool radarToWorld2D( const ICoord2D *radar, Coord3D *world ); ///< radar point to world point (x,y only!)
Bool worldToRadar( const Coord3D *world, ICoord2D *radar ); ///< translate world point to radar (x,y)
Bool localPixelToRadar( const ICoord2D *pixel, ICoord2D *radar ); ///< translate pixel (with UL of radar being (0,0)) to logical radar coords
Bool screenPixelToWorld( const ICoord2D *pixel, Coord3D *world ); ///< translate pixel (with UL of the screen being (0,0)) to world position in the world
Expand Down
5 changes: 4 additions & 1 deletion Generals/Code/GameEngine/Include/Common/ScopedMutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ class ScopedMutex
public:
ScopedMutex(HANDLE mutex) : m_mutex(mutex)
{
WaitForSingleObject(m_mutex, INFINITE);
DWORD status = WaitForSingleObject(m_mutex, 500);
if (status != WAIT_OBJECT_0) {
DEBUG_LOG(("ScopedMutex WaitForSingleObject timed out - status %d\n", status));
}
}

~ScopedMutex()
Expand Down
20 changes: 20 additions & 0 deletions Generals/Code/GameEngine/Include/Common/SparseMatchFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,26 @@ class SparseMatchFinder
}
};

struct MapHelper
{
bool operator()(const BITSET& a, const BITSET& b) const
{
int i;
if (a.size() < b.size()) {
return true;
}
for (i = 0; i < a.size(); ++i) {
bool aVal = a.test(i);
bool bVal = b.test(i);
if (aVal && bVal) continue;
if (!aVal && !bVal) continue;
if (!aVal) return true;
return false;
}
return false; // all bits match.
}
};

//-------------------------------------------------------------------------------------------------
typedef std::hash_map< BITSET, const MATCHABLE*, HashMapHelper, HashMapHelper > MatchMap;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#define __SPECIALPOWERMASKTYPE_H__

#include "Common/BitFlags.h"
#include "Common/BitFlagsIO.h"
#include "Common/SpecialPowerType.h"

typedef BitFlags<SPECIALPOWER_COUNT> SpecialPowerMaskType;
Expand Down
3 changes: 2 additions & 1 deletion Generals/Code/GameEngine/Include/Common/StateMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class State;
class StateMachine;
class Object;

#undef STATE_MACHINE_DEBUG
//#undef STATE_MACHINE_DEBUG
#if defined(RTS_DEBUG)
#define STATE_MACHINE_DEBUG
#endif
Expand Down Expand Up @@ -169,6 +169,7 @@ class State : public MemoryPoolObject, public Snapshot

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

// for internal use by the StateMachine class ---------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion Generals/Code/GameEngine/Include/Common/Xfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
#define __XFER_H_

// INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
#include "Common/ModelState.h"
#include "Common/Science.h"
#include "Common/Upgrade.h"

Expand Down Expand Up @@ -171,6 +170,7 @@ class Xfer
virtual void xferRGBAColorInt( RGBAColorInt *rgbaColorInt );
virtual void xferObjectID( ObjectID *objectID );
virtual void xferDrawableID( DrawableID *drawableID );
virtual void xferSTLObjectIDVector( std::vector<ObjectID> *objectIDVectorData );
virtual void xferSTLObjectIDList( std::list< ObjectID > *objectIDListData );
virtual void xferSTLIntList( std::list< Int > *intListData );
virtual void xferScienceType( ScienceType *science );
Expand Down
76 changes: 76 additions & 0 deletions Generals/Code/GameEngine/Include/Common/crc.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
#define _CRC_H_

#include "Lib/BaseType.h"

#ifdef RTS_DEBUG

//#include "winsock2.h" // for htonl

class CRC
Expand All @@ -50,4 +53,77 @@ class CRC
UnsignedInt crc;
};

#else

// optimized inline only version
class CRC
{
public:
CRC(void) { crc=0; }

/// Compute the CRC for a buffer, added into current CRC
__forceinline void computeCRC( const void *buf, Int len )
{
if (!buf||len<1)
return;

#if !(defined(_MSC_VER) && _MSC_VER < 1300)
// C++ version left in for reference purposes
for (UnsignedByte *uintPtr=(UnsignedByte *)buf;len>0;len--,uintPtr++)
{
int hibit;
if (crc & 0x80000000)
{
hibit = 1;
}
else
{
hibit = 0;
}

crc <<= 1;
crc += *uintPtr;
crc += hibit;
}
#else
// ASM version, verified by comparing resulting data with C++ version data
unsigned *crcPtr=&crc;
_asm
{
mov esi,[buf]
mov ecx,[len]
dec ecx
mov edi,[crcPtr]
mov ebx,dword ptr [edi]
xor eax,eax
lp:
mov al,byte ptr [esi]
shl ebx,1
inc esi
adc ebx,eax
dec ecx
jns lp
mov dword ptr [edi],ebx
};
#endif
}

/// Clears the CRC to 0
void clear( void )
{
crc = 0;
}

///< Get the combined CRC
UnsignedInt get( void ) const
{
return crc;
}

private:
UnsignedInt crc;
};

#endif

#endif // _CRC_H_
9 changes: 9 additions & 0 deletions Generals/Code/GameEngine/Include/GameClient/Color.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ extern void GameGetColorComponents( Color color,
UnsignedByte *green,
UnsignedByte *blue,
UnsignedByte *alpha );

// Put on ice until later - M Lorenzen
//extern void GameGetColorComponentsWithCheatSpy( Color color,
// UnsignedByte *red,
// UnsignedByte *green,
// UnsignedByte *blue,
// UnsignedByte *alpha );


extern void GameGetColorComponentsReal( Color color, Real *red, Real *green, Real *blue, Real *alpha );

extern Color GameDarkenColor( Color color, Int percent = 10 );
Expand Down
18 changes: 15 additions & 3 deletions Generals/Code/GameEngine/Include/GameClient/ControlBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@ class CommandButton : public Overridable

// bleah. shouldn't be const, but is. sue me. (srj)
void copyImagesFrom( const CommandButton *button, Bool markUIDirtyIfChanged ) const;

// bleah. shouldn't be const, but is. sue me. (Kris) -snork!
void copyButtonTextFrom( const CommandButton *button, Bool shortcutButton, Bool markUIDirtyIfChanged ) const;

// bleah. shouldn't be const, but is. sue me. (srj)
void setFlashCount(Int c) const { m_flashCount = c; }

Expand All @@ -359,8 +363,11 @@ class CommandButton : public Overridable
RadiusCursorType m_radiusCursor; ///< radius cursor, if any
AsciiString m_cursorName; ///< cursor name for placement (NEED_TARGET_POS) or valid version (CONTEXTMODE_COMMAND)
AsciiString m_invalidCursorName; ///< cursor name for invalid version
AsciiString m_textLabel; ///< string manager text label
AsciiString m_descriptionLabel; ///< The description of the current command, read in from the ini

// bleah. shouldn't be mutable, but is. sue me. (Kris) -snork!
mutable AsciiString m_textLabel; ///< string manager text label
mutable AsciiString m_descriptionLabel; ///< The description of the current command, read in from the ini

AsciiString m_purchasedLabel; ///< Description for the current command if it has already been purchased.
AsciiString m_conflictingLabel; ///< Description for the current command if it can't be selected due to multually-exclusive choice.
WeaponSlotType m_weaponSlot; ///< for commands that refer to a weapon slot
Expand Down Expand Up @@ -640,7 +647,7 @@ class ControlBar : public SubsystemInterface
virtual void update( void ); ///< from subsystem interface

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

/// a drawable has just become selected
void onDrawableSelected( Drawable *draw );
Expand Down Expand Up @@ -999,6 +1006,11 @@ class ControlBar : public SubsystemInterface
Bool m_radarAttackGlowOn;
Int m_remainingRadarAttackGlowFrames;
GameWindow *m_radarAttackGlowWindow;

#if defined( RTS_INTERNAL ) || defined( RTS_DEBUG )
UnsignedInt m_lastFrameMarkedDirty;
UnsignedInt m_consecutiveDirtyFrames;
#endif
// ControlBarResizer *m_controlBarResizer;

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
extern void GadgetCheckBoxSetText( GameWindow *g, UnicodeString text );
extern Bool GadgetCheckBoxIsChecked( GameWindow *g );
extern void GadgetCheckBoxSetChecked( GameWindow *g, Bool isChecked);
extern void GadgetCheckBoxToggle( GameWindow *g);

inline void GadgetCheckBoxSetEnabledImage( GameWindow *g, const Image *image ) { g->winSetEnabledImage( 0, image ); }
inline void GadgetCheckBoxSetEnabledColor( GameWindow *g, Color color ) { g->winSetEnabledColor( 0, color ); }
Expand Down
1 change: 1 addition & 0 deletions Generals/Code/GameEngine/Include/GameClient/GameWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ friend class GameWindowManager;
Int winBringToTop( void ); ///< bring this window to the top of the win list
Int winEnable( Bool enable ); /**< enable/disable a window, a disbled
window can be seen but accepts no input */
Bool winGetEnabled( void ); ///< Is window enabled?
Int winHide( Bool hide ); ///< hide/unhide a window
Bool winIsHidden( void ); ///< is this window hidden/
UnsignedInt winSetStatus( UnsignedInt status ); ///< set status bits
Expand Down
2 changes: 1 addition & 1 deletion Generals/Code/GameEngine/Include/GameClient/Mouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ class Mouse : public SubsystemInterface
void mouseNotifyResolutionChange(void);

Bool isClick(const ICoord2D *anchor, const ICoord2D *dest, UnsignedInt previousMouseClick, UnsignedInt currentMouseClick);

AsciiString m_tooltipFontName; ///< tooltip font
Int m_tooltipFontSize; ///< tooltip font
Bool m_tooltipFontIsBold; ///< tooltip font
Expand Down
Loading
Loading