-
Notifications
You must be signed in to change notification settings - Fork 23
Description
The intention of this issue is only to remove a few instances of unnecessary data copying which should not change how the game functions.
The purpose of function MSG_ReadDeltaPlayerstate is to take an old playerState_s struct, copy it and apply a delta update (from serialized data) to it and store the result in a new playerState_s struct.
The first thing the function does is making a copy here; it makes a complete copy of old to new:
KisakCOD/src/qcommon/msg_mp.cpp
Line 1595 in ad50220
| memcpy((unsigned __int8 *)to, (unsigned __int8 *)from, sizeof(playerState_s)); |
That means that the following partial copies are unnecessary (from top to bottom):
KisakCOD/src/qcommon/msg_mp.cpp
Lines 1624 to 1632 in ad50220
j = LastChangedField; fielda = (NetField *)&playerStateFields[LastChangedField]; while (j < numPlayerStateFields) { v19 = (int *)((char *)&from->commandTime + fielda->offset); *(int *)((char *)&to->commandTime + fielda->offset) = *v19; ++j; ++fielda; }
--KisakCOD/src/qcommon/msg_mp.cpp
Lines 1649 to 1659 in ad50220
to->origin[0] = from->origin[0]; to->origin[1] = from->origin[1]; to->origin[2] = from->origin[2]; to->velocity[0] = from->velocity[0]; to->velocity[1] = from->velocity[1]; to->velocity[2] = from->velocity[2]; to->bobCycle = from->bobCycle; to->movementDir = from->movementDir; to->viewangles[0] = from->viewangles[0]; to->viewangles[1] = from->viewangles[1]; to->viewangles[2] = from->viewangles[2];
--KisakCOD/src/qcommon/msg_mp.cpp
Lines 1721 to 1727 in ad50220
MSG_ReadDeltaFields( msg, time, (char *)&from->objective[j], (char *)&to->objective[j], numObjectiveFields, objectiveFields);
KisakCOD/src/qcommon/msg_mp.cpp
Lines 1763 to 1764 in ad50220
for (ia = 0; ia < numFields; ++ia) *(unsigned int *)&to[stateFields[ia].offset] = *(unsigned int *)&from[stateFields[ia].offset];
--KisakCOD/src/qcommon/msg_mp.cpp
Lines 1732 to 1733 in ad50220
MSG_ReadDeltaHudElems(msg, time, from->hud.archival, to->hud.archival, 31); MSG_ReadDeltaHudElems(msg, time, from->hud.current, to->hud.current, 31);
KisakCOD/src/qcommon/msg_mp.cpp
Lines 1788 to 1792 in ad50220
while (j < numHudElemFields) { *(&to[i].type + hudElemFields[j].offset) = *(&from[i].type + hudElemFields[j].offset); ++j; }
--
The second one is debatable and may depend on how the corresponding server side code works. It's possible that those fields were updated here below, but then it doesn't make sense that the server would expect the client to also use its own values for these fields.
KisakCOD/src/qcommon/msg_mp.cpp
Lines 1614 to 1617 in ad50220
if (predictedFieldsIgnoreXor && lc && field->changeHints == 3) MSG_ReadDeltaField(msg, time, (char *)from, (char *)to, field, print, 1); else MSG_ReadDeltaField(msg, time, (char *)from, (char *)to, field, print, 0);