quakeforge/qw/source/msg_ucmd.c

133 lines
3.1 KiB
C
Raw Normal View History

/*
msg.c
(description)
Copyright (C) 1996-1997 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:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
static __attribute__ ((unused)) const char rcsid[] =
"$Id$";
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include "QF/msg.h"
#include "QF/qendian.h"
#include "QF/sys.h"
#include "msg_ucmd.h"
2001-08-29 02:12:57 +00:00
#include "net.h"
#include "protocol.h"
struct usercmd_s nullcmd;
2001-08-29 02:12:57 +00:00
void
MSG_WriteDeltaUsercmd (sizebuf_t *buf, usercmd_t *from, usercmd_t *cmd)
{
int bits;
2001-08-29 02:12:57 +00:00
// send the movement message
bits = 0;
if (cmd->angles[0] != from->angles[0])
bits |= CM_ANGLE1;
if (cmd->angles[1] != from->angles[1])
bits |= CM_ANGLE2;
if (cmd->angles[2] != from->angles[2])
bits |= CM_ANGLE3;
if (cmd->forwardmove != from->forwardmove)
bits |= CM_FORWARD;
if (cmd->sidemove != from->sidemove)
bits |= CM_SIDE;
if (cmd->upmove != from->upmove)
bits |= CM_UP;
if (cmd->buttons != from->buttons)
bits |= CM_BUTTONS;
if (cmd->impulse != from->impulse)
bits |= CM_IMPULSE;
MSG_WriteByte (buf, bits);
if (bits & CM_ANGLE1)
MSG_WriteAngle16 (buf, cmd->angles[0]);
if (bits & CM_ANGLE2)
MSG_WriteAngle16 (buf, cmd->angles[1]);
if (bits & CM_ANGLE3)
MSG_WriteAngle16 (buf, cmd->angles[2]);
if (bits & CM_FORWARD)
MSG_WriteShort (buf, cmd->forwardmove);
if (bits & CM_SIDE)
MSG_WriteShort (buf, cmd->sidemove);
if (bits & CM_UP)
MSG_WriteShort (buf, cmd->upmove);
if (bits & CM_BUTTONS)
MSG_WriteByte (buf, cmd->buttons);
if (bits & CM_IMPULSE)
MSG_WriteByte (buf, cmd->impulse);
MSG_WriteByte (buf, cmd->msec);
}
void
MSG_ReadDeltaUsercmd (usercmd_t *from, usercmd_t *move)
{
int bits;
memcpy (move, from, sizeof (*move));
bits = MSG_ReadByte (net_message);
2001-08-29 02:12:57 +00:00
// read current angles
if (bits & CM_ANGLE1)
move->angles[0] = MSG_ReadAngle16 (net_message);
if (bits & CM_ANGLE2)
move->angles[1] = MSG_ReadAngle16 (net_message);
if (bits & CM_ANGLE3)
move->angles[2] = MSG_ReadAngle16 (net_message);
2001-08-29 02:12:57 +00:00
// read movement
if (bits & CM_FORWARD)
move->forwardmove = MSG_ReadShort (net_message);
if (bits & CM_SIDE)
move->sidemove = MSG_ReadShort (net_message);
if (bits & CM_UP)
move->upmove = MSG_ReadShort (net_message);
2001-08-29 02:12:57 +00:00
// read buttons
if (bits & CM_BUTTONS)
move->buttons = MSG_ReadByte (net_message);
if (bits & CM_IMPULSE)
move->impulse = MSG_ReadByte (net_message);
2001-08-29 02:12:57 +00:00
// read time to run command
move->msec = MSG_ReadByte (net_message);
}