Skip to content

Commit

Permalink
Server: Fixed handling of NULL mobj states in deltas
Browse files Browse the repository at this point in the history
The server was trying to generate deltas out of mobjs with a NULL
pointer for state, causing the delta to be invalid.

Next big question: why aren't the mobjs visible on clientside?
  • Loading branch information
skyjake committed Mar 20, 2011
1 parent 910922f commit 0beadda
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 36 deletions.
1 change: 0 additions & 1 deletion doomsday/engine/portable/include/sv_pool.h
Expand Up @@ -87,7 +87,6 @@ typedef enum {
#define MDFC_TRANSLUCENCY 0x40000 // Mobj has translucency.
#define MDFC_FADETARGET 0x80000 // Mobj is fading to/from visible/invisible


// Extra flags for the Extra Flags byte.
#define MDFE_FAST_MOM 0x01 // Momentum has 10.6 bits (+/- 512)
#define MDFE_TRANSLUCENCY 0x02
Expand Down
21 changes: 10 additions & 11 deletions doomsday/engine/portable/src/cl_mobj.c
Expand Up @@ -597,8 +597,7 @@ void Cl_PredictMovement(void)
if(cmo->mo.state == states)
{
#ifdef _DEBUG
if(!cmo->mo.thinker.id)
Con_Error("No clmobj id!!!!\n");
if(!cmo->mo.thinker.id) Con_Error("No clmobj id!!!!\n");
#endif
Cl_DestroyMobj(cmo);
continue;
Expand All @@ -609,16 +608,16 @@ if(!cmo->mo.thinker.id)
}
}
#ifdef _DEBUG
if(verbose >= 2)
{
static int timer = 0;

if(++timer > 5 * 35)
if(verbose >= 2)
{
timer = 0;
Con_Printf("moCount=%i\n", moCount);
static int timer = 0;

if(++timer > 5 * 35)
{
timer = 0;
Con_Printf("moCount=%i\n", moCount);
}
}
}
#endif
}

Expand Down Expand Up @@ -844,7 +843,7 @@ void Cl_ReadMobjDelta2(boolean skip)

if(df & MDF_STATE)
{
ushort stateIdx = Msg_ReadPackedShort();
int stateIdx = Msg_ReadPackedShort();
if(!skip)
{
Cl_SetMobjState(d, stateIdx);
Expand Down
46 changes: 22 additions & 24 deletions doomsday/engine/portable/src/sv_frame.c
Expand Up @@ -248,15 +248,14 @@ void Sv_WriteMobjDelta(const void* deltaPtr)
}

#ifdef _DEBUG
if(df & MDFC_NULL)
{
Con_Error("Sv_WriteMobjDelta: We don't write Null deltas.\n");
}
if((df & 0xffff) == 0)
{
Con_Printf("Sv_WriteMobjDelta: This delta id%i [%x] is empty.\n",
delta->delta.id, df);
}
if(df & MDFC_NULL)
{
Con_Error("Sv_WriteMobjDelta: We don't write Null deltas.\n");
}
if((df & 0xffff) == 0)
{
Con_Printf("Sv_WriteMobjDelta: This delta id%i [%x] is empty.\n", delta->delta.id, df);
}
#endif

// First the mobj ID number and flags.
Expand All @@ -272,46 +271,43 @@ if((df & 0xffff) == 0)
// Coordinates with three bytes.
if(df & MDF_POS_X)
{
fixed_t vx = FLT2FIX(d->pos[VX]);
fixed_t vx = FLT2FIX(d->pos[VX]);

Msg_WriteShort(vx >> FRACBITS);
Msg_WriteByte(vx >> 8);
}
if(df & MDF_POS_Y)
{
fixed_t vy = FLT2FIX(d->pos[VY]);
fixed_t vy = FLT2FIX(d->pos[VY]);

Msg_WriteShort(vy >> FRACBITS);
Msg_WriteByte(vy >> 8);
}

if(df & MDF_POS_Z)
{
fixed_t vz = FLT2FIX(d->pos[VZ]);
fixed_t vz = FLT2FIX(d->pos[VZ]);
Msg_WriteShort(vz >> FRACBITS);
Msg_WriteByte(vz >> 8);
}

// Momentum using 8.8 fixed point.
if(df & MDF_MOM_X)
{
fixed_t mx = FLT2FIX(d->mom[MX]);
Msg_WriteShort(moreFlags & MDFE_FAST_MOM ? FIXED10_6(mx) :
FIXED8_8(mx));
fixed_t mx = FLT2FIX(d->mom[MX]);
Msg_WriteShort(moreFlags & MDFE_FAST_MOM ? FIXED10_6(mx) : FIXED8_8(mx));
}

if(df & MDF_MOM_Y)
{
fixed_t my = FLT2FIX(d->mom[MY]);
Msg_WriteShort(moreFlags & MDFE_FAST_MOM ? FIXED10_6(my) :
FIXED8_8(my));
fixed_t my = FLT2FIX(d->mom[MY]);
Msg_WriteShort(moreFlags & MDFE_FAST_MOM ? FIXED10_6(my) : FIXED8_8(my));
}

if(df & MDF_MOM_Z)
{
fixed_t mz = FLT2FIX(d->mom[MZ]);
Msg_WriteShort(moreFlags & MDFE_FAST_MOM ? FIXED10_6(mz) :
FIXED8_8(mz));
fixed_t mz = FLT2FIX(d->mom[MZ]);
Msg_WriteShort(moreFlags & MDFE_FAST_MOM ? FIXED10_6(mz) : FIXED8_8(mz));
}

// Angles with 16-bit accuracy.
Expand All @@ -323,13 +319,15 @@ if((df & 0xffff) == 0)
if(df & MDF_SELSPEC)
Msg_WriteByte(d->selector >> 24);

if(df & MDF_STATE)
if((df & MDF_STATE) && d->state)
{
Msg_WritePackedShort(d->state - states);
}

// Pack flags into a word (3 bytes?).
// \fixme Do the packing!
if(df & MDF_FLAGS)
{
Msg_WriteLong(d->ddFlags & DDMF_PACK_MASK);
}

// Radius, height and floorclip are all bytes.
if(df & MDF_RADIUS)
Expand Down
9 changes: 9 additions & 0 deletions doomsday/engine/portable/src/sv_pool.c
Expand Up @@ -594,6 +594,15 @@ boolean Sv_RegisterCompareMobj(cregister_t* reg, const mobj_t* s,
{
df |= MDF_STATE;

if(s->state == NULL)
{
#ifdef _DEBUG
Con_Message("Sv_RegisterCompareMobj: Mobj state is NULL, ignoring.\n");
#endif
// No valid comparison can be generated because the mobj is gone.
return false;
}

#ifdef _DEBUG
VERBOSE2( if(regMo && Sys_GetTime() - regMo->lastTimeStateSent > (60 + s->thinker.id%35))
Con_Message("Sv_RegisterCompareMobj: (%i) Sending state due to time.\n",
Expand Down

0 comments on commit 0beadda

Please sign in to comment.