Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions Core/GameEngine/Include/Common/GameDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@
#endif
#endif

#if (!defined(DEEP_CRC_TO_MEMORY) && !defined(DEBUG_CRC))
#define DEEP_CRC_TO_MEMORY 1
#endif

#define MIN_DISPLAY_BIT_DEPTH 16
#define DEFAULT_DISPLAY_BIT_DEPTH 32
#define DEFAULT_DISPLAY_WIDTH 800 // The standard resolution this game was designed for
Expand Down
4 changes: 4 additions & 0 deletions Core/GameEngine/Include/Common/RandomValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ extern void InitRandom( UnsignedInt seed );
extern UnsignedInt GetGameLogicRandomSeed(); ///< Get the seed (used for replays)
extern UnsignedInt GetGameLogicRandomSeedCRC();///< Get the seed (used for CRCs)

#if DEEP_CRC_TO_MEMORY
AsciiString GetGameLogicalRandomSeeds();
#endif

//--------------------------------------------------------------------------------------------------------------
4 changes: 4 additions & 0 deletions Core/GameEngine/Include/Common/Xfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ class Xfer
virtual void xferMatrix3D( Matrix3D* mtx );
virtual void xferMapName( AsciiString *mapNameData );

#if DEEP_CRC_TO_MEMORY
virtual void xferLogString(const AsciiString& str) {}
#endif

protected:

// this is the actual xfer implementation that each derived class should implement
Expand Down
13 changes: 13 additions & 0 deletions Core/GameEngine/Include/Common/XferDeepCRC.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
// USER INCLUDES //////////////////////////////////////////////////////////////////////////////////
#include "Common/Xfer.h"
#include "Common/XferCRC.h"
#if DEEP_CRC_TO_MEMORY
#include <vector>
#endif

// FORWARD REFERENCES /////////////////////////////////////////////////////////////////////////////
class Snapshot;
Expand All @@ -55,9 +58,19 @@ class XferDeepCRC : public XferCRC
virtual void xferAsciiString( AsciiString *asciiStringData ) override; ///< xfer ascii string (need our own)
virtual void xferUnicodeString( UnicodeString *unicodeStringData ) override; ///< xfer unicode string (need our own);

#if DEEP_CRC_TO_MEMORY
virtual void xferLogString(const AsciiString& str) override;
void changeXferMode(XferMode xferMode);
#endif

protected:

virtual void xferImplementation( void *data, Int dataSize ) override;

#if DEEP_CRC_TO_MEMORY
std::vector<UnsignedByte>* m_buffer; ///< pointer to buffer
size_t m_bufferIndex; ///< current index in buffer
#else
FILE * m_fileFP; ///< pointer to file
#endif
};
16 changes: 16 additions & 0 deletions Core/GameEngine/Source/Common/RandomValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@ UnsignedInt GetGameLogicRandomSeedCRC()
return c.get();
}

#if DEEP_CRC_TO_MEMORY
AsciiString GetGameLogicalRandomSeeds()
{
AsciiString str;
str.format("%8.8X, %8.8X, %8.8X, %8.8X, %8.8X, %8.8X",
theGameLogicSeed[0],
theGameLogicSeed[1],
theGameLogicSeed[2],
theGameLogicSeed[3],
theGameLogicSeed[4],
theGameLogicSeed[5]);

return str;
}
#endif

static void seedRandom(UnsignedInt SEED, UnsignedInt (&seed)[6])
{
UnsignedInt ax;
Expand Down
99 changes: 99 additions & 0 deletions Core/GameEngine/Source/Common/System/XferCRC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
#include "Common/Snapshot.h"
#include "Utility/endian_compat.h"

#if DEEP_CRC_TO_MEMORY
#include "GameLogic/GameLogic.h"
#endif

//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
XferCRC::XferCRC()
Expand Down Expand Up @@ -175,8 +179,14 @@
XferDeepCRC::XferDeepCRC()
{

#if DEEP_CRC_TO_MEMORY
m_xferMode = XFER_CRC;
m_buffer = nullptr;
m_bufferIndex = 0;
#else
m_xferMode = XFER_SAVE;
m_fileFP = nullptr;
#endif

}

Expand All @@ -185,6 +195,7 @@
XferDeepCRC::~XferDeepCRC()
{

#if !DEEP_CRC_TO_MEMORY
// warn the user if a file was left open
if( m_fileFP != nullptr )
{
Expand All @@ -193,6 +204,7 @@
close();

}
#endif

}

Expand All @@ -202,8 +214,13 @@
void XferDeepCRC::open( AsciiString identifier )
{

#if DEEP_CRC_TO_MEMORY
m_xferMode = XFER_CRC;
#else
m_xferMode = XFER_SAVE;
#endif

#if !DEEP_CRC_TO_MEMORY
// sanity, check to see if we're already open
if( m_fileFP != nullptr )
{
Expand All @@ -213,10 +230,26 @@
throw XFER_FILE_ALREADY_OPEN;

}
#endif

// call base class
Xfer::open( identifier );

#if DEEP_CRC_TO_MEMORY
m_buffer = &TheGameLogic->getCRCBuffer();

Check failure on line 239 in Core/GameEngine/Source/Common/System/XferCRC.cpp

View workflow job for this annotation

GitHub Actions / Build Generals / vc6-debug+t+e

'getCRCBuffer' : is not a member of 'GameLogic'

Check failure on line 239 in Core/GameEngine/Source/Common/System/XferCRC.cpp

View workflow job for this annotation

GitHub Actions / Build Generals / vc6+t+e

'getCRCBuffer' : is not a member of 'GameLogic'

Check failure on line 239 in Core/GameEngine/Source/Common/System/XferCRC.cpp

View workflow job for this annotation

GitHub Actions / Build Generals / vc6-profile+t+e

'getCRCBuffer' : is not a member of 'GameLogic'

Check failure on line 239 in Core/GameEngine/Source/Common/System/XferCRC.cpp

View workflow job for this annotation

GitHub Actions / Build Generals / win32-debug+t+e

'getCRCBuffer': is not a member of 'GameLogic'

Check failure on line 239 in Core/GameEngine/Source/Common/System/XferCRC.cpp

View workflow job for this annotation

GitHub Actions / Build Generals / win32-profile+t+e

'getCRCBuffer': is not a member of 'GameLogic'

Check failure on line 239 in Core/GameEngine/Source/Common/System/XferCRC.cpp

View workflow job for this annotation

GitHub Actions / Build Generals / win32+t+e

'getCRCBuffer': is not a member of 'GameLogic'

AsciiString str;
str.format("[ START OF DEEP CRC FRAME %d ]", TheGameLogic->getFrame());
const UnsignedInt length = str.getLength();

while (m_bufferIndex + length >= m_buffer->size())
{
m_buffer->resize(m_buffer->size() * 2);
}

memcpy(&(*m_buffer)[m_bufferIndex], str.str(), length);
m_bufferIndex += length;
#else
// open the file
m_fileFP = fopen( identifier.str(), "w+b" );
if( m_fileFP == nullptr )
Expand All @@ -226,6 +259,7 @@
throw XFER_FILE_NOT_FOUND;

}
#endif

// initialize CRC to brand new one at zero
m_crc = 0;
Expand All @@ -238,6 +272,21 @@
void XferDeepCRC::close()
{

#if DEEP_CRC_TO_MEMORY
AsciiString str;
str.format("[ END OF DEEP CRC FRAME %d ]", TheGameLogic->getFrame());
const UnsignedInt length = str.getLength();

while (m_bufferIndex + length >= m_buffer->size())
{
m_buffer->resize(m_buffer->size() * 2);
}

memcpy(&(*m_buffer)[m_bufferIndex], str.str(), length);
m_bufferIndex += length;

TheGameLogic->storeCRCBuffer(m_bufferIndex);

Check failure on line 288 in Core/GameEngine/Source/Common/System/XferCRC.cpp

View workflow job for this annotation

GitHub Actions / Build Generals / vc6-debug+t+e

'storeCRCBuffer' : is not a member of 'GameLogic'

Check failure on line 288 in Core/GameEngine/Source/Common/System/XferCRC.cpp

View workflow job for this annotation

GitHub Actions / Build Generals / vc6+t+e

'storeCRCBuffer' : is not a member of 'GameLogic'

Check failure on line 288 in Core/GameEngine/Source/Common/System/XferCRC.cpp

View workflow job for this annotation

GitHub Actions / Build Generals / vc6-profile+t+e

'storeCRCBuffer' : is not a member of 'GameLogic'

Check failure on line 288 in Core/GameEngine/Source/Common/System/XferCRC.cpp

View workflow job for this annotation

GitHub Actions / Build Generals / win32-debug+t+e

'storeCRCBuffer': is not a member of 'GameLogic'

Check failure on line 288 in Core/GameEngine/Source/Common/System/XferCRC.cpp

View workflow job for this annotation

GitHub Actions / Build Generals / win32-profile+t+e

'storeCRCBuffer': is not a member of 'GameLogic'

Check failure on line 288 in Core/GameEngine/Source/Common/System/XferCRC.cpp

View workflow job for this annotation

GitHub Actions / Build Generals / win32+t+e

'storeCRCBuffer': is not a member of 'GameLogic'
#else
// sanity, if we don't have an open file we can do nothing
if( m_fileFP == nullptr )
{
Expand All @@ -246,10 +295,15 @@
throw XFER_FILE_NOT_OPEN;

}
#endif

#if DEEP_CRC_TO_MEMORY
m_buffer = nullptr;
#else
// close the file
fclose( m_fileFP );
m_fileFP = nullptr;
#endif

// erase the filename
m_identifier.clear();
Expand All @@ -267,6 +321,15 @@
return;
}

#if DEEP_CRC_TO_MEMORY
while (m_bufferIndex + dataSize >= m_buffer->size())
{
m_buffer->resize(m_buffer->size() * 2);
}

memcpy(&(*m_buffer)[m_bufferIndex], data, dataSize);
m_bufferIndex += dataSize;
#else
// sanity
DEBUG_ASSERTCRASH( m_fileFP != nullptr, ("XferSave - file pointer for '%s' is null",
m_identifier.str()) );
Expand All @@ -279,6 +342,7 @@
throw XFER_WRITE_ERROR;

}
#endif

XferCRC::xferImplementation( data, dataSize );

Expand All @@ -290,6 +354,11 @@
void XferDeepCRC::xferMarkerLabel( AsciiString asciiStringData )
{

#if DEEP_CRC_TO_MEMORY
XferCRC::xferMarkerLabel(asciiStringData);
return;
#endif

}

// ------------------------------------------------------------------------------------------------
Expand All @@ -298,6 +367,11 @@
void XferDeepCRC::xferAsciiString( AsciiString *asciiStringData )
{

#if DEEP_CRC_TO_MEMORY
XferCRC::xferAsciiString(asciiStringData);
return;
#endif

// sanity
if( asciiStringData->getLength() > 16385 )
{
Expand All @@ -323,6 +397,11 @@
void XferDeepCRC::xferUnicodeString( UnicodeString *unicodeStringData )
{

#if DEEP_CRC_TO_MEMORY
XferCRC::xferUnicodeString(unicodeStringData);
return;
#endif

// sanity
if( unicodeStringData->getLength() > 255 )
{
Expand All @@ -341,3 +420,23 @@
xferUser( (void *)unicodeStringData->str(), sizeof( WideChar ) * len );

}

#if DEEP_CRC_TO_MEMORY
void XferDeepCRC::xferLogString(const AsciiString& str)
{
const UnsignedInt length = str.getLength();

while (m_bufferIndex + length >= m_buffer->size())
{
m_buffer->resize(m_buffer->size() * 2);
}

memcpy(&(*m_buffer)[m_bufferIndex], str.str(), length);
m_bufferIndex += length;
}

void XferDeepCRC::changeXferMode(XferMode xferMode)
{
m_xferMode = xferMode;
}
#endif
2 changes: 2 additions & 0 deletions Core/GameEngine/Source/GameClient/ClientInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ UnsignedInt ClientInstance::s_instanceIndex = 0;

#if defined(RTS_MULTI_INSTANCE)
Bool ClientInstance::s_isMultiInstance = true;
#elif DEEP_CRC_TO_MEMORY
Bool ClientInstance::s_isMultiInstance = true;
#else
Bool ClientInstance::s_isMultiInstance = false;
#endif
Expand Down
2 changes: 2 additions & 0 deletions Core/GameEngine/Source/GameNetwork/Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@

#if defined(DEBUG_CRC)
Int NET_CRC_INTERVAL = 1;
#elif DEEP_CRC_TO_MEMORY
Int NET_CRC_INTERVAL = 1;
#else
Int NET_CRC_INTERVAL = 100;
#endif
Expand Down
10 changes: 10 additions & 0 deletions GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,16 @@ class GameLogic : public SubsystemInterface, public Snapshot
void xferObjectTOC( Xfer *xfer ); ///< save/load object TOC for current state of map
void prepareLogicForObjectLoad(); ///< prepare engine for object data from game file

#if DEEP_CRC_TO_MEMORY
UnsignedInt m_crcBufferIndex;
std::vector<UnsignedByte> m_crcWriteBuffer;
std::vector<UnsignedByte> m_crcBuffers[64];

public:
std::vector<UnsignedByte>& getCRCBuffer();
void storeCRCBuffer(size_t size);
void writeCRCBuffersToDisk(UnsignedInt frame) const;
#endif
};

// INLINE /////////////////////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 4 additions & 0 deletions GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,10 @@ class Object : public Thing, public Snapshot
Bool m_singleUseCommandUsed;
Bool m_isReceivingDifficultyBonus;

#if DEEP_CRC_TO_MEMORY
public:
const UpgradeMaskType& getUpgrades() const { return m_objectUpgradesCompleted; }
#endif
};

// deleteInstance is not meant to be used with Object in order to require the use of TheGameLogic->destroyObject()
Expand Down
4 changes: 4 additions & 0 deletions GeneralsMD/Code/GameEngine/Source/Common/Recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,10 @@ void RecorderClass::handleCRCMessage(UnsignedInt newCRC, Int playerIndex, Bool f
// playbackCRC, newCRC, TheGameLogic->getFrame()-m_crcInfo->GetQueueSize()-1, playerIndex));
if (TheGameLogic->getFrame() > 0 && newCRC != playbackCRC && !m_crcInfo->sawCRCMismatch())
{
#if DEEP_CRC_TO_MEMORY
TheGameLogic->writeCRCBuffersToDisk(TheGameLogic->getFrame() - m_crcInfo->GetQueueSize() - 1);
#endif

//Kris: Patch 1.01 November 10, 2003 (integrated changes from Matt Campbell)
// Since we don't seem to have any *visible* desyncs when replaying games, but get this warning
// virtually every replay, the assumption is our CRC checking is faulty. Since we're at the
Expand Down
Loading
Loading