MCPcopy Create free account
hub / github.com/JACoders/OpenJK / MSG_WriteDeltaPlayerstate

Function MSG_WriteDeltaPlayerstate

code/qcommon/msg.cpp:1038–1167  ·  view source on GitHub ↗

============= MSG_WriteDeltaPlayerstate ============= */

Source from the content-addressed store, hash-verified

1036=============
1037*/
1038void MSG_WriteDeltaPlayerstate( msg_t *msg, playerState_t *from, playerState_t *to ) {
1039 int i;
1040 playerState_t dummy;
1041 int statsbits;
1042 int persistantbits;
1043 int ammobits;
1044 int powerupbits;
1045 int numFields;
1046 int c;
1047 const netField_t *field;
1048 int *fromF, *toF;
1049
1050 if (!from) {
1051 from = &dummy;
1052 memset (&dummy, 0, sizeof(dummy));
1053 }
1054
1055 c = msg->cursize;
1056
1057 numFields = sizeof( playerStateFields ) / sizeof( playerStateFields[0] );
1058 for ( i = 0, field = playerStateFields ; i < numFields ; i++, field++ ) {
1059 fromF = (int *)( (byte *)from + field->offset );
1060 toF = (int *)( (byte *)to + field->offset );
1061
1062 if ( *fromF == *toF ) {
1063 MSG_WriteBits( msg, 0, 1 ); // no change
1064 continue;
1065 }
1066
1067 MSG_WriteBits( msg, 1, 1 ); // changed
1068 MSG_WriteField (msg, toF, field);
1069 }
1070 c = msg->cursize - c;
1071
1072
1073 //
1074 // send the arrays
1075 //
1076 statsbits = 0;
1077 for (i=0 ; i<MAX_STATS ; i++) {
1078 if (to->stats[i] != from->stats[i]) {
1079 statsbits |= 1<<i;
1080 }
1081 }
1082 if ( statsbits ) {
1083 MSG_WriteBits( msg, 1, 1 ); // changed
1084 MSG_WriteShort( msg, statsbits );
1085 for (i=0 ; i<MAX_STATS ; i++)
1086 if (statsbits & (1<<i) )
1087 MSG_WriteBits(msg, to->stats[i], 32);
1088 } else {
1089 MSG_WriteBits( msg, 0, 1 ); // no change
1090 }
1091
1092
1093 persistantbits = 0;
1094 for (i=0 ; i<MAX_PERSISTANT ; i++) {
1095 if (to->persistant[i] != from->persistant[i]) {

Callers 1

SV_WriteSnapshotToClientFunction · 0.50

Calls 5

MSG_WriteFieldFunction · 0.85
MSG_WriteSShortFunction · 0.85
MSG_WriteBitsFunction · 0.70
MSG_WriteShortFunction · 0.70
MSG_WriteLongFunction · 0.70

Tested by

no test coverage detected