X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;ds=sidebyside;f=protocol.c;h=4a66bfc6e806bbb268b0d31beeeadb18658bb06a;hb=0896ffc41ce8fdf985d5659b2b572763c527fdf9;hp=95ded37bd19c5de23220003208cc3e9bcf71ad56;hpb=142ec9e43c5bd046ce3a33e822167373bf244d21;p=xonotic%2Fdarkplaces.git diff --git a/protocol.c b/protocol.c index 95ded37b..4a66bfc6 100644 --- a/protocol.c +++ b/protocol.c @@ -44,8 +44,17 @@ void EntityFrame_AckFrame(entity_database_t *d, int frame) // (server) clears frame, to prepare for adding entities void EntityFrame_Clear(entity_frame_t *f, vec3_t eye) { - memset(f, 0, sizeof(*f)); - VectorCopy(eye, f->eye); + f->time = 0; + f->framenum = 0; + f->numentities = 0; + if (eye == NULL) + { + VectorClear(f->eye); + } + else + { + VectorCopy(eye, f->eye); + } } // (server) allocates an entity slot in frame, returns NULL if full @@ -64,7 +73,7 @@ entity_state_t *EntityFrame_NewEntity(entity_frame_t *f, int number) void EntityFrame_FetchFrame(entity_database_t *d, int framenum, entity_frame_t *f) { int i, n; - memset(f, 0, sizeof(*f)); + EntityFrame_Clear(f, NULL); for (i = 0;i < d->numframes && d->frames[i].framenum < framenum;i++); if (i < d->numframes && framenum == d->frames[i].framenum) { @@ -275,17 +284,17 @@ void EntityFrame_Write(entity_database_t *d, entity_frame_t *f, sizebuf_t *msg) if (bits & E_ANGLE3) MSG_WriteAngle(msg, ent->angles[2]); if (bits & E_MODEL1) - MSG_WriteByte(msg, ent->modelindex & 0x00FF); + MSG_WriteByte(msg, ent->modelindex & 0xFF); if (bits & E_MODEL2) - MSG_WriteByte(msg, ent->modelindex & 0xFF00); + MSG_WriteByte(msg, (ent->modelindex >> 8) & 0xFF); if (bits & E_FRAME1) - MSG_WriteByte(msg, ent->frame & 0x00FF); + MSG_WriteByte(msg, ent->frame & 0xFF); if (bits & E_FRAME2) - MSG_WriteByte(msg, ent->frame & 0xFF00); + MSG_WriteByte(msg, (ent->frame >> 8) & 0xFF); if (bits & E_EFFECTS1) - MSG_WriteByte(msg, ent->effects & 0x00FF); + MSG_WriteByte(msg, ent->effects & 0xFF); if (bits & E_EFFECTS2) - MSG_WriteByte(msg, ent->effects & 0xFF00); + MSG_WriteByte(msg, (ent->effects >> 8) & 0xFF); if (bits & E_COLORMAP) MSG_WriteByte(msg, ent->colormap); if (bits & E_SKIN) @@ -316,7 +325,9 @@ void EntityFrame_Read(entity_database_t *d) entity_state_t *e, baseline, *old, *oldend; ClearStateToDefault(&baseline); - memset(f, 0, sizeof(*f)); + + EntityFrame_Clear(f, NULL); + // read the frame header info f->time = cl.mtime[0]; number = MSG_ReadLong(); @@ -429,17 +440,17 @@ void EntityFrame_Read(entity_database_t *d) if (bits & E_ANGLE3) e->angles[2] = MSG_ReadAngle(); if (bits & E_MODEL1) - e->modelindex = (e->modelindex & 0xFF00) | MSG_ReadByte(); + e->modelindex = (e->modelindex & 0xFF00) | (unsigned int) MSG_ReadByte(); if (bits & E_MODEL2) - e->modelindex = (e->modelindex & 0x00FF) | (MSG_ReadByte() << 8); + e->modelindex = (e->modelindex & 0x00FF) | ((unsigned int) MSG_ReadByte() << 8); if (bits & E_FRAME1) - e->frame = (e->frame & 0xFF00) | MSG_ReadByte(); + e->frame = (e->frame & 0xFF00) | (unsigned int) MSG_ReadByte(); if (bits & E_FRAME2) - e->frame = (e->frame & 0x00FF) | (MSG_ReadByte() << 8); + e->frame = (e->frame & 0x00FF) | ((unsigned int) MSG_ReadByte() << 8); if (bits & E_EFFECTS1) - e->effects = (e->effects & 0xFF00) | MSG_ReadByte(); + e->effects = (e->effects & 0xFF00) | (unsigned int) MSG_ReadByte(); if (bits & E_EFFECTS2) - e->effects = (e->effects & 0x00FF) | (MSG_ReadByte() << 8); + e->effects = (e->effects & 0x00FF) | ((unsigned int) MSG_ReadByte() << 8); if (bits & E_COLORMAP) e->colormap = MSG_ReadByte(); if (bits & E_SKIN) @@ -469,51 +480,6 @@ void EntityFrame_Read(entity_database_t *d) EntityFrame_AddFrame(d, f); } -/* -// (client) reads (and interpolates) the eye location from the database, -// given a current time -int EntityFrame_FetchEye(entity_database_t *d, vec3_t eye, double time) -{ - float frac; - if (d->numframes == 0) - return false; -// Host_Error("EntityFrame_FetchEye: no frames\n"); - if (d->numframes > 1 && d->frames[d->numframes - 2].time != d->frames[d->numframes - 1].time) - { - frac = (time - d->frames[d->numframes - 2].time) / (d->frames[d->numframes - 1].time - d->frames[d->numframes - 2].time); - frac = bound(0, frac, 1); - VectorSubtract(d->frames[d->numframes - 2].eye, d->frames[d->numframes - 1].eye, eye); - VectorMA(d->frames[d->numframes - 2].eye, frac, eye, eye); - } - else - VectorCopy(d->frames[0].eye, eye); - return true; -} - -// (client) fetchs an entity from a frame, index is the index into the frame's entity list, returns false if index is out of bounds -int EntityFrame_FetchEntityByIndex(entity_frame_t *f, entity_state_t *e, int index) -{ - if (index < 0 || index >= f->numentities) - return false; - memcpy(e, f->entitydata + index, sizeof(*e)); - return true; -} - -int EntityFrame_FetchEntityByNumber(entity_frame_t *f, entity_state_t *e, int number) -{ - int i; - for (i = 0;i < f->numentities;i++) - { - if (f->entitydata[i].number == number) - { - memcpy(e, f->entitydata + i, sizeof(*e)); - return true; - } - } - ClearStateToDefault(e); - return false; -} -*/ // (client) returns the frame number of the most recent frame recieved int EntityFrame_MostRecentlyRecievedFrameNum(entity_database_t *d) @@ -523,3 +489,4 @@ int EntityFrame_MostRecentlyRecievedFrameNum(entity_database_t *d) else return -1; } +