Skip to content
This repository has been archived by the owner on Sep 28, 2023. It is now read-only.

Commit

Permalink
CrcStore: Reduce periodic remote compare message to an single compare…
Browse files Browse the repository at this point in the history
… frame check sum.

On a check sum error, send the individual object check sums to track down the problem.
  • Loading branch information
the3dfxdude committed Aug 24, 2020
1 parent b35ae3a commit 61c1a96
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 8 deletions.
16 changes: 12 additions & 4 deletions include/OCRC_STO.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <OVQUEUE.h>
#include <OSTR.h>
#include <CRC.h>

class CrcStore
{
Expand All @@ -39,16 +40,26 @@ class CrcStore
VLenQueue rebels;
VLenQueue spies;
VLenQueue talk_msgs;
VLenQueue all_crc;

// #### patch begin Gilbert 23/1 #####//
String crc_error_string;
// #### patch end Gilbert 23/1 #####//

CRC_TYPE frame_check_num;

public:
CrcStore();
void init();
void deinit();

void record_all();
void send_all();
void send_frame();
int compare_remote(uint32_t remoteMsgId, char *);
int compare_frame(char *dataPtr);

private:
void record_nations();
void record_units();
void record_firms();
Expand All @@ -58,11 +69,8 @@ class CrcStore
void record_spies();
void record_talk_msgs();

void record_all();
void send_all();
int compare_remote(uint32_t remoteMsgId, char *);
};

extern CrcStore crc_store;

#endif
#endif
3 changes: 3 additions & 0 deletions include/OREMOTE.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ enum { MSG_QUEUE_HEADER=FIRST_REMOTE_MSG_ID,

MSG_U_CARA_COPY_ROUTE,

MSG_COMPARE_CRC,

LAST_REMOTE_MSG_ID // keep this item last
};

Expand Down Expand Up @@ -305,6 +307,7 @@ struct RemoteMsg
//##### trevor 30/9 #######//

void compare_remote_object();
void compare_remote_crc();

void caravan_copy_route();
};
Expand Down
3 changes: 3 additions & 0 deletions include/OVQUEUE.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
// Filename : OVQUEUE.H
// Description : header file of variable length queue

#include <stdint.h>

#ifndef __OVQUEUE_H
#define __OVQUEUE_H
Expand Down Expand Up @@ -52,6 +53,8 @@ class VLenQueue
void swap(VLenQueue &);
int length();

uint8_t crc8();

private:

// actually, this can be called 'reserve' in terms of stl containers, except
Expand Down
34 changes: 34 additions & 0 deletions src/OCRC_STO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ void CrcStore::deinit()
rebels.clear();
spies.clear();
talk_msgs.clear();
all_crc.clear();
frame_check_num = 0;
}

void CrcStore::record_nations()
Expand All @@ -66,6 +68,7 @@ void CrcStore::record_nations()
if( !nation_array.is_deleted(nationRecno) )
checkNum = nation_array[nationRecno]->crc8();
*(CRC_TYPE *)nations.reserve(sizeof(CRC_TYPE)) = checkNum;
*(CRC_TYPE *)all_crc.reserve(sizeof(CRC_TYPE)) = checkNum;
}
}

Expand All @@ -80,6 +83,7 @@ void CrcStore::record_units()
if( !unit_array.is_deleted(unitRecno) )
checkNum = unit_array[unitRecno]->crc8();
*(CRC_TYPE *)units.reserve(sizeof(CRC_TYPE)) = checkNum;
*(CRC_TYPE *)all_crc.reserve(sizeof(CRC_TYPE)) = checkNum;
}
}

Expand All @@ -94,6 +98,7 @@ void CrcStore::record_firms()
if( !firm_array.is_deleted(firmRecno) )
checkNum = firm_array[firmRecno]->crc8();
*(CRC_TYPE *)firms.reserve(sizeof(CRC_TYPE)) = checkNum;
*(CRC_TYPE *)all_crc.reserve(sizeof(CRC_TYPE)) = checkNum;
}
}

Expand All @@ -108,6 +113,7 @@ void CrcStore::record_towns()
if( !town_array.is_deleted(townRecno) )
checkNum = town_array[townRecno]->crc8();
*(CRC_TYPE *)towns.reserve(sizeof(CRC_TYPE)) = checkNum;
*(CRC_TYPE *)all_crc.reserve(sizeof(CRC_TYPE)) = checkNum;
}
}

Expand All @@ -122,6 +128,7 @@ void CrcStore::record_bullets()
if( !bullet_array.is_deleted(bulletRecno) )
checkNum = bullet_array[bulletRecno]->crc8();
*(CRC_TYPE *)bullets.reserve(sizeof(CRC_TYPE)) = checkNum;
*(CRC_TYPE *)all_crc.reserve(sizeof(CRC_TYPE)) = checkNum;
}
}

Expand All @@ -139,6 +146,7 @@ void CrcStore::record_rebels()
checkNum = rebel_array[rebelRecno]->crc8();
}
*(CRC_TYPE *)rebels.reserve(sizeof(CRC_TYPE)) = checkNum;
*(CRC_TYPE *)all_crc.reserve(sizeof(CRC_TYPE)) = checkNum;
}
}

Expand All @@ -156,6 +164,7 @@ void CrcStore::record_spies()
checkNum = spy_array[spyRecno]->crc8();
}
*(CRC_TYPE *)spies.reserve(sizeof(CRC_TYPE)) = checkNum;
*(CRC_TYPE *)all_crc.reserve(sizeof(CRC_TYPE)) = checkNum;
}
}

Expand All @@ -173,11 +182,13 @@ void CrcStore::record_talk_msgs()
checkNum = talk_res.get_talk_msg(talkRecno)->crc8();
}
*(CRC_TYPE *)talk_msgs.reserve(sizeof(CRC_TYPE)) = checkNum;
*(CRC_TYPE *)all_crc.reserve(sizeof(CRC_TYPE)) = checkNum;
}
}

void CrcStore::record_all()
{
all_crc.clear();
record_nations();
record_units();
record_firms();
Expand All @@ -186,6 +197,7 @@ void CrcStore::record_all()
record_rebels();
record_spies();
record_talk_msgs();
frame_check_num = all_crc.crc8();
}


Expand Down Expand Up @@ -217,6 +229,15 @@ void CrcStore::send_all()
memcpy(charPtr, talk_msgs.queue_buf, talk_msgs.length() );
}


void CrcStore::send_frame()
{
CRC_TYPE *dataPtr;
dataPtr = (CRC_TYPE *)remote.new_send_queue_msg(MSG_COMPARE_CRC, sizeof(CRC_TYPE) );
*dataPtr = frame_check_num;
}


// return 0 if equal
// otherwise not equal
int CrcStore::compare_remote(uint32_t remoteMsgId, char *dataPtr)
Expand Down Expand Up @@ -286,3 +307,16 @@ int CrcStore::compare_remote(uint32_t remoteMsgId, char *dataPtr)
}
return rc;
}


// return 0 if equal
// otherwise not equal
int CrcStore::compare_frame(char *dataPtr)
{
if( *(CRC_TYPE*)dataPtr != frame_check_num )
{
send_all();
return 1;
}
return 0;
}
9 changes: 9 additions & 0 deletions src/OMP_CRC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include <OSPY.h>
// ###### patch end Gilbert 20/1 #######//
#include <OTALKRES.h>
#include <OVQUEUE.h>


// ###### patch begin Gilbert 21/1 #####//
Expand Down Expand Up @@ -1481,3 +1482,11 @@ void TalkMsg::clear_ptr()
{
}
//----------- End of function TalkMsg::clear_ptr -----------//


//----------- Begin of function VLenQueue::crc8 -----------//
uint8_t VLenQueue::crc8()
{
return ::crc8((uint8_t*)queue_buf, queued_size);
}
//----------- End of function VLenQueue::crc8 -----------//
20 changes: 17 additions & 3 deletions src/OREMOTEM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ static MsgProcessFP msg_process_function_array[] =
&RemoteMsg::compare_remote_object,

&RemoteMsg::caravan_copy_route,

&RemoteMsg::compare_remote_crc,
};

//---------- Declare static functions ----------//
Expand Down Expand Up @@ -2866,10 +2868,8 @@ void RemoteMsg::compare_remote_object()
err_when( id < MSG_COMPARE_NATION || id > MSG_COMPARE_TALK );

// ###### patch begin Gilbert 20/1 #######//
if( (remote.sync_test_level & 2) && (remote.sync_test_level >= 0)
&& crc_store.compare_remote(id, data_buf) )
if( crc_store.compare_remote(id, data_buf) )
{
remote.sync_test_level = ~2; // signal error encountered
if( sys.debug_session )
err.run( _("Multiplayer Object Sync Error") );
}
Expand All @@ -2878,6 +2878,20 @@ void RemoteMsg::compare_remote_object()
//------- End of function RemoteMsg::compare_remote_object -------//


//------- Begin of function RemoteMsg::compare_remote_crc -------//
void RemoteMsg::compare_remote_crc()
{
err_when( id != MSG_COMPARE_CRC );

if( (remote.sync_test_level & 2) && (remote.sync_test_level >= 0)
&& crc_store.compare_frame(data_buf) )
{
remote.sync_test_level = ~2; // signal error encountered
}
}
//------- End of function RemoteMsg::compare_remote_crc -------//


//------- Begin of function RemoteMsg::unit_add_way_point -------//
void RemoteMsg::unit_add_way_point()
{
Expand Down
2 changes: 1 addition & 1 deletion src/OSYS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ void Sys::main_loop(int isLoadedGame)
// cannot compare every frame, as PROCESS_FRAME_DELAY >= 1
crc_store.record_all();
if( !remote.is_replay() )
crc_store.send_all();
crc_store.send_frame();
}
// ###### patch end Gilbert 20/1 ######//

Expand Down
6 changes: 6 additions & 0 deletions tools/rpldump
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ my @msg_ids = (

['MSG_U_CARA_COPY_ROUTE', 'ss', [qw(sprite_recno copy_unit_recno)]],

['MSG_COMPARE_CRC', 'sC', [qw(crc)]],

['LAST_REMOTE_MSG_ID'],
);

Expand Down Expand Up @@ -265,6 +267,10 @@ my (
$MSG_COMPARE_SPY,
$MSG_COMPARE_TALK,

$MSG_U_CARA_COPY_ROUTE,

$MSG_COMPARE_CRC,

$LAST_REMOTE_MSG_ID,
) = (FIRST_REMOTE_MSG_ID)..(FIRST_REMOTE_MSG_ID+scalar(@msg_ids));

Expand Down

0 comments on commit 61c1a96

Please sign in to comment.