Skip to content

Remove superfluous data copying in MSG_ReadDeltaPlayerstate #36

@Caball009

Description

@Caball009

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:

memcpy((unsigned __int8 *)to, (unsigned __int8 *)from, sizeof(playerState_s));

That means that the following partial copies are unnecessary (from top to bottom):

  1. 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;
    }

    --
  2. 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];

    --
  3. MSG_ReadDeltaFields(
    msg,
    time,
    (char *)&from->objective[j],
    (char *)&to->objective[j],
    numObjectiveFields,
    objectiveFields);

    for (ia = 0; ia < numFields; ++ia)
    *(unsigned int *)&to[stateFields[ia].offset] = *(unsigned int *)&from[stateFields[ia].offset];

    --
  4. MSG_ReadDeltaHudElems(msg, time, from->hud.archival, to->hud.archival, 31);
    MSG_ReadDeltaHudElems(msg, time, from->hud.current, to->hud.current, 31);

    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.
    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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions