yquake2remaster/src/common/movemsg.c

1045 lines
18 KiB
C
Raw Normal View History

2010-08-31 08:48:11 +00:00
/*
* Copyright (C) 1997-2001 Id Software, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* =======================================================================
*
* Movement message (forward, backward, left, right, etc) handling.
2010-08-31 08:48:11 +00:00
*
* =======================================================================
2012-04-29 13:57:33 +00:00
*/
2010-08-31 08:48:11 +00:00
#include "header/common.h"
2010-08-31 08:48:11 +00:00
vec3_t bytedirs[NUMVERTEXNORMALS] = {
2010-08-31 08:48:11 +00:00
{-0.525731, 0.000000, 0.850651},
{-0.442863, 0.238856, 0.864188},
{-0.295242, 0.000000, 0.955423},
{-0.309017, 0.500000, 0.809017},
{-0.162460, 0.262866, 0.951056},
{0.000000, 0.000000, 1.000000},
{0.000000, 0.850651, 0.525731},
{-0.147621, 0.716567, 0.681718},
{0.147621, 0.716567, 0.681718},
{0.000000, 0.525731, 0.850651},
{0.309017, 0.500000, 0.809017},
{0.525731, 0.000000, 0.850651},
{0.295242, 0.000000, 0.955423},
{0.442863, 0.238856, 0.864188},
{0.162460, 0.262866, 0.951056},
{-0.681718, 0.147621, 0.716567},
{-0.809017, 0.309017, 0.500000},
{-0.587785, 0.425325, 0.688191},
{-0.850651, 0.525731, 0.000000},
{-0.864188, 0.442863, 0.238856},
{-0.716567, 0.681718, 0.147621},
{-0.688191, 0.587785, 0.425325},
{-0.500000, 0.809017, 0.309017},
{-0.238856, 0.864188, 0.442863},
{-0.425325, 0.688191, 0.587785},
{-0.716567, 0.681718, -0.147621},
{-0.500000, 0.809017, -0.309017},
{-0.525731, 0.850651, 0.000000},
{0.000000, 0.850651, -0.525731},
{-0.238856, 0.864188, -0.442863},
{0.000000, 0.955423, -0.295242},
{-0.262866, 0.951056, -0.162460},
{0.000000, 1.000000, 0.000000},
{0.000000, 0.955423, 0.295242},
{-0.262866, 0.951056, 0.162460},
{0.238856, 0.864188, 0.442863},
{0.262866, 0.951056, 0.162460},
{0.500000, 0.809017, 0.309017},
{0.238856, 0.864188, -0.442863},
{0.262866, 0.951056, -0.162460},
{0.500000, 0.809017, -0.309017},
{0.850651, 0.525731, 0.000000},
{0.716567, 0.681718, 0.147621},
{0.716567, 0.681718, -0.147621},
{0.525731, 0.850651, 0.000000},
{0.425325, 0.688191, 0.587785},
{0.864188, 0.442863, 0.238856},
{0.688191, 0.587785, 0.425325},
{0.809017, 0.309017, 0.500000},
{0.681718, 0.147621, 0.716567},
{0.587785, 0.425325, 0.688191},
{0.955423, 0.295242, 0.000000},
{1.000000, 0.000000, 0.000000},
{0.951056, 0.162460, 0.262866},
{0.850651, -0.525731, 0.000000},
{0.955423, -0.295242, 0.000000},
{0.864188, -0.442863, 0.238856},
{0.951056, -0.162460, 0.262866},
{0.809017, -0.309017, 0.500000},
{0.681718, -0.147621, 0.716567},
{0.850651, 0.000000, 0.525731},
{0.864188, 0.442863, -0.238856},
{0.809017, 0.309017, -0.500000},
{0.951056, 0.162460, -0.262866},
{0.525731, 0.000000, -0.850651},
{0.681718, 0.147621, -0.716567},
{0.681718, -0.147621, -0.716567},
{0.850651, 0.000000, -0.525731},
{0.809017, -0.309017, -0.500000},
{0.864188, -0.442863, -0.238856},
{0.951056, -0.162460, -0.262866},
{0.147621, 0.716567, -0.681718},
{0.309017, 0.500000, -0.809017},
{0.425325, 0.688191, -0.587785},
{0.442863, 0.238856, -0.864188},
{0.587785, 0.425325, -0.688191},
{0.688191, 0.587785, -0.425325},
{-0.147621, 0.716567, -0.681718},
{-0.309017, 0.500000, -0.809017},
{0.000000, 0.525731, -0.850651},
{-0.525731, 0.000000, -0.850651},
{-0.442863, 0.238856, -0.864188},
{-0.295242, 0.000000, -0.955423},
{-0.162460, 0.262866, -0.951056},
{0.000000, 0.000000, -1.000000},
{0.295242, 0.000000, -0.955423},
{0.162460, 0.262866, -0.951056},
{-0.442863, -0.238856, -0.864188},
{-0.309017, -0.500000, -0.809017},
{-0.162460, -0.262866, -0.951056},
{0.000000, -0.850651, -0.525731},
{-0.147621, -0.716567, -0.681718},
{0.147621, -0.716567, -0.681718},
{0.000000, -0.525731, -0.850651},
{0.309017, -0.500000, -0.809017},
{0.442863, -0.238856, -0.864188},
{0.162460, -0.262866, -0.951056},
{0.238856, -0.864188, -0.442863},
{0.500000, -0.809017, -0.309017},
{0.425325, -0.688191, -0.587785},
{0.716567, -0.681718, -0.147621},
{0.688191, -0.587785, -0.425325},
{0.587785, -0.425325, -0.688191},
{0.000000, -0.955423, -0.295242},
{0.000000, -1.000000, 0.000000},
{0.262866, -0.951056, -0.162460},
{0.000000, -0.850651, 0.525731},
{0.000000, -0.955423, 0.295242},
{0.238856, -0.864188, 0.442863},
{0.262866, -0.951056, 0.162460},
{0.500000, -0.809017, 0.309017},
{0.716567, -0.681718, 0.147621},
{0.525731, -0.850651, 0.000000},
{-0.238856, -0.864188, -0.442863},
{-0.500000, -0.809017, -0.309017},
{-0.262866, -0.951056, -0.162460},
{-0.850651, -0.525731, 0.000000},
{-0.716567, -0.681718, -0.147621},
{-0.716567, -0.681718, 0.147621},
{-0.525731, -0.850651, 0.000000},
{-0.500000, -0.809017, 0.309017},
{-0.238856, -0.864188, 0.442863},
{-0.262866, -0.951056, 0.162460},
{-0.864188, -0.442863, 0.238856},
{-0.809017, -0.309017, 0.500000},
{-0.688191, -0.587785, 0.425325},
{-0.681718, -0.147621, 0.716567},
{-0.442863, -0.238856, 0.864188},
{-0.587785, -0.425325, 0.688191},
{-0.309017, -0.500000, 0.809017},
{-0.147621, -0.716567, 0.681718},
{-0.425325, -0.688191, 0.587785},
{-0.162460, -0.262866, 0.951056},
{0.442863, -0.238856, 0.864188},
{0.162460, -0.262866, 0.951056},
{0.309017, -0.500000, 0.809017},
{0.147621, -0.716567, 0.681718},
{0.000000, -0.525731, 0.850651},
{0.425325, -0.688191, 0.587785},
{0.587785, -0.425325, 0.688191},
{0.688191, -0.587785, 0.425325},
{-0.955423, 0.295242, 0.000000},
{-0.951056, 0.162460, 0.262866},
{-1.000000, 0.000000, 0.000000},
{-0.850651, 0.000000, 0.525731},
{-0.955423, -0.295242, 0.000000},
{-0.951056, -0.162460, 0.262866},
{-0.864188, 0.442863, -0.238856},
{-0.951056, 0.162460, -0.262866},
{-0.809017, 0.309017, -0.500000},
{-0.864188, -0.442863, -0.238856},
{-0.951056, -0.162460, -0.262866},
{-0.809017, -0.309017, -0.500000},
{-0.681718, 0.147621, -0.716567},
{-0.681718, -0.147621, -0.716567},
{-0.850651, 0.000000, -0.525731},
{-0.688191, 0.587785, -0.425325},
{-0.587785, 0.425325, -0.688191},
{-0.425325, 0.688191, -0.587785},
{-0.425325, -0.688191, -0.587785},
{-0.587785, -0.425325, -0.688191},
{-0.688191, -0.587785, -0.425325}
};
void
MSG_WriteChar(sizebuf_t *sb, int c)
2010-08-31 08:48:11 +00:00
{
byte *buf;
2010-08-31 08:48:11 +00:00
buf = SZ_GetSpace(sb, 1);
2010-08-31 08:48:11 +00:00
buf[0] = c;
}
void
MSG_WriteByte(sizebuf_t *sb, int c)
2010-08-31 08:48:11 +00:00
{
byte *buf;
2010-08-31 08:48:11 +00:00
buf = SZ_GetSpace(sb, 1);
2010-08-31 08:48:11 +00:00
buf[0] = c;
}
void
MSG_WriteShort(sizebuf_t *sb, int c)
2010-08-31 08:48:11 +00:00
{
byte *buf;
2010-08-31 08:48:11 +00:00
buf = SZ_GetSpace(sb, 2);
buf[0] = c & 0xff;
buf[1] = c >> 8;
2010-08-31 08:48:11 +00:00
}
void
MSG_WriteLong(sizebuf_t *sb, int c)
2010-08-31 08:48:11 +00:00
{
byte *buf;
2010-08-31 08:48:11 +00:00
buf = SZ_GetSpace(sb, 4);
buf[0] = c & 0xff;
buf[1] = (c >> 8) & 0xff;
buf[2] = (c >> 16) & 0xff;
buf[3] = c >> 24;
2010-08-31 08:48:11 +00:00
}
void
MSG_WriteFloat(sizebuf_t *sb, float f)
2010-08-31 08:48:11 +00:00
{
union
{
float f;
int l;
2010-08-31 08:48:11 +00:00
} dat;
dat.f = f;
dat.l = LittleLong(dat.l);
2010-08-31 08:48:11 +00:00
SZ_Write(sb, &dat.l, 4);
2010-08-31 08:48:11 +00:00
}
void
MSG_WriteString(sizebuf_t *sb, char *s)
2010-08-31 08:48:11 +00:00
{
if (!s)
{
SZ_Write(sb, "", 1);
}
2010-08-31 08:48:11 +00:00
else
{
SZ_Write(sb, s, (int)strlen(s) + 1);
}
2010-08-31 08:48:11 +00:00
}
void
MSG_WriteCoord(sizebuf_t *sb, float f)
2010-08-31 08:48:11 +00:00
{
MSG_WriteShort(sb, (int)(f * 8));
2010-08-31 08:48:11 +00:00
}
void
MSG_WritePos(sizebuf_t *sb, vec3_t pos)
2010-08-31 08:48:11 +00:00
{
MSG_WriteShort(sb, (int)(pos[0] * 8));
MSG_WriteShort(sb, (int)(pos[1] * 8));
MSG_WriteShort(sb, (int)(pos[2] * 8));
2010-08-31 08:48:11 +00:00
}
void
MSG_WriteAngle(sizebuf_t *sb, float f)
2010-08-31 08:48:11 +00:00
{
MSG_WriteByte(sb, (int)(f * 256 / 360) & 255);
2010-08-31 08:48:11 +00:00
}
void
MSG_WriteAngle16(sizebuf_t *sb, float f)
2010-08-31 08:48:11 +00:00
{
MSG_WriteShort(sb, ANGLE2SHORT(f));
2010-08-31 08:48:11 +00:00
}
void
MSG_WriteDeltaUsercmd(sizebuf_t *buf, usercmd_t *from, usercmd_t *cmd)
2010-08-31 08:48:11 +00:00
{
int bits;
2010-08-31 08:48:11 +00:00
/* Movement messages */
bits = 0;
if (cmd->angles[0] != from->angles[0])
{
2010-08-31 08:48:11 +00:00
bits |= CM_ANGLE1;
}
2010-08-31 08:48:11 +00:00
if (cmd->angles[1] != from->angles[1])
{
2010-08-31 08:48:11 +00:00
bits |= CM_ANGLE2;
}
2010-08-31 08:48:11 +00:00
if (cmd->angles[2] != from->angles[2])
{
2010-08-31 08:48:11 +00:00
bits |= CM_ANGLE3;
}
2010-08-31 08:48:11 +00:00
if (cmd->forwardmove != from->forwardmove)
{
2010-08-31 08:48:11 +00:00
bits |= CM_FORWARD;
}
2010-08-31 08:48:11 +00:00
if (cmd->sidemove != from->sidemove)
{
2010-08-31 08:48:11 +00:00
bits |= CM_SIDE;
}
2010-08-31 08:48:11 +00:00
if (cmd->upmove != from->upmove)
{
2010-08-31 08:48:11 +00:00
bits |= CM_UP;
}
2010-08-31 08:48:11 +00:00
if (cmd->buttons != from->buttons)
{
2010-08-31 08:48:11 +00:00
bits |= CM_BUTTONS;
}
2010-08-31 08:48:11 +00:00
if (cmd->impulse != from->impulse)
{
2010-08-31 08:48:11 +00:00
bits |= CM_IMPULSE;
}
2010-08-31 08:48:11 +00:00
MSG_WriteByte(buf, bits);
2010-08-31 08:48:11 +00:00
if (bits & CM_ANGLE1)
{
MSG_WriteShort(buf, cmd->angles[0]);
}
2010-08-31 08:48:11 +00:00
if (bits & CM_ANGLE2)
{
MSG_WriteShort(buf, cmd->angles[1]);
}
2010-08-31 08:48:11 +00:00
if (bits & CM_ANGLE3)
{
MSG_WriteShort(buf, cmd->angles[2]);
}
2010-08-31 08:48:11 +00:00
if (bits & CM_FORWARD)
{
MSG_WriteShort(buf, cmd->forwardmove);
}
2010-08-31 08:48:11 +00:00
if (bits & CM_SIDE)
{
MSG_WriteShort(buf, cmd->sidemove);
}
2010-08-31 08:48:11 +00:00
if (bits & CM_UP)
{
MSG_WriteShort(buf, cmd->upmove);
}
2010-08-31 08:48:11 +00:00
if (bits & CM_BUTTONS)
{
MSG_WriteByte(buf, cmd->buttons);
}
2010-08-31 08:48:11 +00:00
if (bits & CM_IMPULSE)
{
MSG_WriteByte(buf, cmd->impulse);
}
2010-08-31 08:48:11 +00:00
MSG_WriteByte(buf, cmd->msec);
MSG_WriteByte(buf, cmd->lightlevel);
2010-08-31 08:48:11 +00:00
}
void
MSG_WriteDir(sizebuf_t *sb, vec3_t dir)
2010-08-31 08:48:11 +00:00
{
int i, best;
float d, bestd;
2010-08-31 08:48:11 +00:00
if (!dir)
{
MSG_WriteByte(sb, 0);
2010-08-31 08:48:11 +00:00
return;
}
bestd = 0;
best = 0;
for (i = 0; i < NUMVERTEXNORMALS; i++)
2010-08-31 08:48:11 +00:00
{
d = DotProduct(dir, bytedirs[i]);
2010-08-31 08:48:11 +00:00
if (d > bestd)
{
bestd = d;
best = i;
}
}
MSG_WriteByte(sb, best);
2010-08-31 08:48:11 +00:00
}
void
MSG_ReadDir(sizebuf_t *sb, vec3_t dir)
2010-08-31 08:48:11 +00:00
{
int b;
2010-08-31 08:48:11 +00:00
b = MSG_ReadByte(sb);
2010-08-31 08:48:11 +00:00
if (b >= NUMVERTEXNORMALS)
{
Com_Error(ERR_DROP, "MSF_ReadDir: out of range");
}
2010-08-31 08:48:11 +00:00
VectorCopy(bytedirs[b], dir);
2010-08-31 08:48:11 +00:00
}
/*
* Writes part of a packetentities message.
* Can delta from either a baseline or a previous packet_entity
*/
void
MSG_WriteDeltaEntity(entity_state_t *from,
entity_state_t *to,
sizebuf_t *msg,
qboolean force,
qboolean newentity)
2010-08-31 08:48:11 +00:00
{
int bits;
2010-08-31 08:48:11 +00:00
if (!to->number)
{
Com_Error(ERR_FATAL, "Unset entity number");
}
2010-08-31 08:48:11 +00:00
if (to->number >= MAX_EDICTS)
{
Com_Error(ERR_FATAL, "Entity number >= MAX_EDICTS");
}
2010-08-31 08:48:11 +00:00
/* send an update */
bits = 0;
if (to->number >= 256)
{
2010-08-31 08:48:11 +00:00
bits |= U_NUMBER16; /* number8 is implicit otherwise */
}
2010-08-31 08:48:11 +00:00
if (to->origin[0] != from->origin[0])
{
2010-08-31 08:48:11 +00:00
bits |= U_ORIGIN1;
}
2010-08-31 08:48:11 +00:00
if (to->origin[1] != from->origin[1])
{
2010-08-31 08:48:11 +00:00
bits |= U_ORIGIN2;
}
2010-08-31 08:48:11 +00:00
if (to->origin[2] != from->origin[2])
{
2010-08-31 08:48:11 +00:00
bits |= U_ORIGIN3;
}
2010-08-31 08:48:11 +00:00
if (to->angles[0] != from->angles[0])
{
2010-08-31 08:48:11 +00:00
bits |= U_ANGLE1;
}
2010-08-31 08:48:11 +00:00
if (to->angles[1] != from->angles[1])
{
2010-08-31 08:48:11 +00:00
bits |= U_ANGLE2;
}
2010-08-31 08:48:11 +00:00
if (to->angles[2] != from->angles[2])
{
2010-08-31 08:48:11 +00:00
bits |= U_ANGLE3;
}
2010-08-31 08:48:11 +00:00
if (to->skinnum != from->skinnum)
2010-08-31 08:48:11 +00:00
{
if ((unsigned)to->skinnum < 256)
{
2010-08-31 08:48:11 +00:00
bits |= U_SKIN8;
}
2010-08-31 08:48:11 +00:00
else if ((unsigned)to->skinnum < 0x10000)
{
2010-08-31 08:48:11 +00:00
bits |= U_SKIN16;
}
2010-08-31 08:48:11 +00:00
else
{
bits |= (U_SKIN8 | U_SKIN16);
}
2010-08-31 08:48:11 +00:00
}
if (to->frame != from->frame)
2010-08-31 08:48:11 +00:00
{
if (to->frame < 256)
{
2010-08-31 08:48:11 +00:00
bits |= U_FRAME8;
}
2010-08-31 08:48:11 +00:00
else
{
2010-08-31 08:48:11 +00:00
bits |= U_FRAME16;
}
2010-08-31 08:48:11 +00:00
}
if (to->effects != from->effects)
2010-08-31 08:48:11 +00:00
{
if (to->effects < 256)
{
2010-08-31 08:48:11 +00:00
bits |= U_EFFECTS8;
}
2010-08-31 08:48:11 +00:00
else if (to->effects < 0x8000)
{
2010-08-31 08:48:11 +00:00
bits |= U_EFFECTS16;
}
2010-08-31 08:48:11 +00:00
else
{
bits |= U_EFFECTS8 | U_EFFECTS16;
}
2010-08-31 08:48:11 +00:00
}
if (to->renderfx != from->renderfx)
2010-08-31 08:48:11 +00:00
{
if (to->renderfx < 256)
{
2010-08-31 08:48:11 +00:00
bits |= U_RENDERFX8;
}
2010-08-31 08:48:11 +00:00
else if (to->renderfx < 0x8000)
{
2010-08-31 08:48:11 +00:00
bits |= U_RENDERFX16;
}
2010-08-31 08:48:11 +00:00
else
{
bits |= U_RENDERFX8 | U_RENDERFX16;
}
2010-08-31 08:48:11 +00:00
}
if (to->solid != from->solid)
{
2010-08-31 08:48:11 +00:00
bits |= U_SOLID;
}
2010-08-31 08:48:11 +00:00
/* event is not delta compressed, just 0 compressed */
if (to->event)
{
2010-08-31 08:48:11 +00:00
bits |= U_EVENT;
}
2010-08-31 08:48:11 +00:00
if (to->modelindex != from->modelindex)
{
2010-08-31 08:48:11 +00:00
bits |= U_MODEL;
}
2010-08-31 08:48:11 +00:00
if (to->modelindex2 != from->modelindex2)
{
2010-08-31 08:48:11 +00:00
bits |= U_MODEL2;
}
2010-08-31 08:48:11 +00:00
if (to->modelindex3 != from->modelindex3)
{
2010-08-31 08:48:11 +00:00
bits |= U_MODEL3;
}
2010-08-31 08:48:11 +00:00
if (to->modelindex4 != from->modelindex4)
{
2010-08-31 08:48:11 +00:00
bits |= U_MODEL4;
}
2010-08-31 08:48:11 +00:00
if (to->sound != from->sound)
{
2010-08-31 08:48:11 +00:00
bits |= U_SOUND;
}
2010-08-31 08:48:11 +00:00
if (newentity || (to->renderfx & RF_BEAM))
{
2010-08-31 08:48:11 +00:00
bits |= U_OLDORIGIN;
}
2010-08-31 08:48:11 +00:00
/* write the message */
if (!bits && !force)
{
2010-08-31 08:48:11 +00:00
return; /* nothing to send! */
}
2010-08-31 08:48:11 +00:00
if (bits & 0xff000000)
{
2010-08-31 08:48:11 +00:00
bits |= U_MOREBITS3 | U_MOREBITS2 | U_MOREBITS1;
}
2010-08-31 08:48:11 +00:00
else if (bits & 0x00ff0000)
{
2010-08-31 08:48:11 +00:00
bits |= U_MOREBITS2 | U_MOREBITS1;
}
2010-08-31 08:48:11 +00:00
else if (bits & 0x0000ff00)
{
2010-08-31 08:48:11 +00:00
bits |= U_MOREBITS1;
}
2010-08-31 08:48:11 +00:00
MSG_WriteByte(msg, bits & 255);
2010-08-31 08:48:11 +00:00
if (bits & 0xff000000)
{
MSG_WriteByte(msg, (bits >> 8) & 255);
MSG_WriteByte(msg, (bits >> 16) & 255);
MSG_WriteByte(msg, (bits >> 24) & 255);
2010-08-31 08:48:11 +00:00
}
else if (bits & 0x00ff0000)
{
MSG_WriteByte(msg, (bits >> 8) & 255);
MSG_WriteByte(msg, (bits >> 16) & 255);
2010-08-31 08:48:11 +00:00
}
else if (bits & 0x0000ff00)
{
MSG_WriteByte(msg, (bits >> 8) & 255);
2010-08-31 08:48:11 +00:00
}
if (bits & U_NUMBER16)
{
MSG_WriteShort(msg, to->number);
}
2010-08-31 08:48:11 +00:00
else
{
MSG_WriteByte(msg, to->number);
}
2010-08-31 08:48:11 +00:00
if (bits & U_MODEL)
{
MSG_WriteByte(msg, to->modelindex);
}
2010-08-31 08:48:11 +00:00
if (bits & U_MODEL2)
{
MSG_WriteByte(msg, to->modelindex2);
}
2010-08-31 08:48:11 +00:00
if (bits & U_MODEL3)
{
MSG_WriteByte(msg, to->modelindex3);
}
2010-08-31 08:48:11 +00:00
if (bits & U_MODEL4)
{
MSG_WriteByte(msg, to->modelindex4);
}
2010-08-31 08:48:11 +00:00
if (bits & U_FRAME8)
{
MSG_WriteByte(msg, to->frame);
}
2010-08-31 08:48:11 +00:00
if (bits & U_FRAME16)
{
MSG_WriteShort(msg, to->frame);
}
2010-08-31 08:48:11 +00:00
if ((bits & U_SKIN8) && (bits & U_SKIN16)) /*used for laser colors */
{
MSG_WriteLong(msg, to->skinnum);
}
2010-08-31 08:48:11 +00:00
else if (bits & U_SKIN8)
{
MSG_WriteByte(msg, to->skinnum);
}
2010-08-31 08:48:11 +00:00
else if (bits & U_SKIN16)
{
MSG_WriteShort(msg, to->skinnum);
}
2010-08-31 08:48:11 +00:00
if ((bits & (U_EFFECTS8 | U_EFFECTS16)) == (U_EFFECTS8 | U_EFFECTS16))
{
MSG_WriteLong(msg, to->effects);
}
2010-08-31 08:48:11 +00:00
else if (bits & U_EFFECTS8)
{
MSG_WriteByte(msg, to->effects);
}
2010-08-31 08:48:11 +00:00
else if (bits & U_EFFECTS16)
{
MSG_WriteShort(msg, to->effects);
}
2010-08-31 08:48:11 +00:00
if ((bits & (U_RENDERFX8 | U_RENDERFX16)) == (U_RENDERFX8 | U_RENDERFX16))
{
MSG_WriteLong(msg, to->renderfx);
}
2010-08-31 08:48:11 +00:00
else if (bits & U_RENDERFX8)
{
MSG_WriteByte(msg, to->renderfx);
}
2010-08-31 08:48:11 +00:00
else if (bits & U_RENDERFX16)
{
MSG_WriteShort(msg, to->renderfx);
}
2010-08-31 08:48:11 +00:00
if (bits & U_ORIGIN1)
{
MSG_WriteCoord(msg, to->origin[0]);
}
2010-08-31 08:48:11 +00:00
if (bits & U_ORIGIN2)
{
MSG_WriteCoord(msg, to->origin[1]);
}
2010-08-31 08:48:11 +00:00
if (bits & U_ORIGIN3)
{
MSG_WriteCoord(msg, to->origin[2]);
}
2010-08-31 08:48:11 +00:00
if (bits & U_ANGLE1)
{
2010-08-31 08:48:11 +00:00
MSG_WriteAngle(msg, to->angles[0]);
}
2010-08-31 08:48:11 +00:00
if (bits & U_ANGLE2)
{
2010-08-31 08:48:11 +00:00
MSG_WriteAngle(msg, to->angles[1]);
}
2010-08-31 08:48:11 +00:00
if (bits & U_ANGLE3)
{
2010-08-31 08:48:11 +00:00
MSG_WriteAngle(msg, to->angles[2]);
}
2010-08-31 08:48:11 +00:00
if (bits & U_OLDORIGIN)
{
MSG_WriteCoord(msg, to->old_origin[0]);
MSG_WriteCoord(msg, to->old_origin[1]);
MSG_WriteCoord(msg, to->old_origin[2]);
2010-08-31 08:48:11 +00:00
}
if (bits & U_SOUND)
{
MSG_WriteByte(msg, to->sound);
}
2010-08-31 08:48:11 +00:00
if (bits & U_EVENT)
{
MSG_WriteByte(msg, to->event);
}
2010-08-31 08:48:11 +00:00
if (bits & U_SOLID)
{
MSG_WriteShort(msg, to->solid);
}
}
void
MSG_BeginReading(sizebuf_t *msg)
{
msg->readcount = 0;
}
int
MSG_ReadChar(sizebuf_t *msg_read)
{
int c;
if (msg_read->readcount + 1 > msg_read->cursize)
{
c = -1;
}
else
{
c = (signed char)msg_read->data[msg_read->readcount];
}
msg_read->readcount++;
return c;
2010-08-31 08:48:11 +00:00
}
int
MSG_ReadByte(sizebuf_t *msg_read)
{
int c;
if (msg_read->readcount + 1 > msg_read->cursize)
{
c = -1;
}
else
{
c = (unsigned char)msg_read->data[msg_read->readcount];
}
msg_read->readcount++;
return c;
}
int
MSG_ReadShort(sizebuf_t *msg_read)
{
int c;
if (msg_read->readcount + 2 > msg_read->cursize)
{
c = -1;
}
else
{
c = (short)(msg_read->data[msg_read->readcount]
+ (msg_read->data[msg_read->readcount + 1] << 8));
}
msg_read->readcount += 2;
return c;
}
int
MSG_ReadLong(sizebuf_t *msg_read)
{
int c;
if (msg_read->readcount + 4 > msg_read->cursize)
{
c = -1;
}
else
{
c = msg_read->data[msg_read->readcount]
+ (msg_read->data[msg_read->readcount + 1] << 8)
+ (msg_read->data[msg_read->readcount + 2] << 16)
+ (msg_read->data[msg_read->readcount + 3] << 24);
}
msg_read->readcount += 4;
return c;
}
float
MSG_ReadFloat(sizebuf_t *msg_read)
{
union
{
byte b[4];
float f;
int l;
} dat;
if (msg_read->readcount + 4 > msg_read->cursize)
{
dat.f = -1;
}
else
{
dat.b[0] = msg_read->data[msg_read->readcount];
dat.b[1] = msg_read->data[msg_read->readcount + 1];
dat.b[2] = msg_read->data[msg_read->readcount + 2];
dat.b[3] = msg_read->data[msg_read->readcount + 3];
}
msg_read->readcount += 4;
dat.l = LittleLong(dat.l);
return dat.f;
}
char *
MSG_ReadString(sizebuf_t *msg_read)
{
static char string[2048];
int l, c;
l = 0;
do
{
c = MSG_ReadChar(msg_read);
if ((c == -1) || (c == 0))
{
break;
}
string[l] = c;
l++;
}
while (l < sizeof(string) - 1);
string[l] = 0;
return string;
}
char *
MSG_ReadStringLine(sizebuf_t *msg_read)
{
static char string[2048];
int l, c;
l = 0;
do
{
c = MSG_ReadChar(msg_read);
if ((c == -1) || (c == 0) || (c == '\n'))
{
break;
}
string[l] = c;
l++;
}
while (l < sizeof(string) - 1);
string[l] = 0;
return string;
}
float
MSG_ReadCoord(sizebuf_t *msg_read)
{
return MSG_ReadShort(msg_read) * (0.125f);
}
void
MSG_ReadPos(sizebuf_t *msg_read, vec3_t pos)
{
pos[0] = MSG_ReadShort(msg_read) * (0.125f);
pos[1] = MSG_ReadShort(msg_read) * (0.125f);
pos[2] = MSG_ReadShort(msg_read) * (0.125f);
}
float
MSG_ReadAngle(sizebuf_t *msg_read)
{
return MSG_ReadChar(msg_read) * 1.40625f;
}
float
MSG_ReadAngle16(sizebuf_t *msg_read)
{
return SHORT2ANGLE(MSG_ReadShort(msg_read));
}
void
MSG_ReadDeltaUsercmd(sizebuf_t *msg_read, usercmd_t *from, usercmd_t *move)
{
int bits;
memcpy(move, from, sizeof(*move));
bits = MSG_ReadByte(msg_read);
/* read current angles */
if (bits & CM_ANGLE1)
{
move->angles[0] = MSG_ReadShort(msg_read);
}
if (bits & CM_ANGLE2)
{
move->angles[1] = MSG_ReadShort(msg_read);
}
if (bits & CM_ANGLE3)
{
move->angles[2] = MSG_ReadShort(msg_read);
}
/* read movement */
if (bits & CM_FORWARD)
{
move->forwardmove = MSG_ReadShort(msg_read);
}
if (bits & CM_SIDE)
{
move->sidemove = MSG_ReadShort(msg_read);
}
if (bits & CM_UP)
{
move->upmove = MSG_ReadShort(msg_read);
}
/* read buttons */
if (bits & CM_BUTTONS)
{
move->buttons = MSG_ReadByte(msg_read);
}
if (bits & CM_IMPULSE)
{
move->impulse = MSG_ReadByte(msg_read);
}
/* read time to run command */
move->msec = MSG_ReadByte(msg_read);
/* read the light level */
move->lightlevel = MSG_ReadByte(msg_read);
}
void
MSG_ReadData(sizebuf_t *msg_read, void *data, int len)
{
int i;
for (i = 0; i < len; i++)
{
((byte *)data)[i] = MSG_ReadByte(msg_read);
}
}