1 /*
2 	msg.c
3 
4 	(description)
5 
6 	Copyright (C) 1996-1997  Id Software, Inc.
7 
8 	This program is free software; you can redistribute it and/or
9 	modify it under the terms of the GNU General Public License
10 	as published by the Free Software Foundation; either version 2
11 	of the License, or (at your option) any later version.
12 
13 	This program is distributed in the hope that it will be useful,
14 	but WITHOUT ANY WARRANTY; without even the implied warranty of
15 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 
17 	See the GNU General Public License for more details.
18 
19 	You should have received a copy of the GNU General Public License
20 	along with this program; if not, write to:
21 
22 		Free Software Foundation, Inc.
23 		59 Temple Place - Suite 330
24 		Boston, MA  02111-1307, USA
25 
26 */
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30 
31 #ifdef HAVE_STRING_H
32 # include <string.h>
33 #endif
34 #ifdef HAVE_STRINGS_H
35 # include <strings.h>
36 #endif
37 
38 #include "QF/msg.h"
39 #include "QF/qendian.h"
40 #include "QF/sys.h"
41 
42 #include "qw/msg_ucmd.h"
43 #include "qw/protocol.h"
44 
45 struct usercmd_s nullcmd;
46 
47 void
MSG_WriteDeltaUsercmd(sizebuf_t * buf,usercmd_t * from,usercmd_t * cmd)48 MSG_WriteDeltaUsercmd (sizebuf_t *buf, usercmd_t *from, usercmd_t *cmd)
49 {
50 	int         bits;
51 
52 	// send the movement message
53 	bits = 0;
54 	if (cmd->angles[0] != from->angles[0])
55 		bits |= CM_ANGLE1;
56 	if (cmd->angles[1] != from->angles[1])
57 		bits |= CM_ANGLE2;
58 	if (cmd->angles[2] != from->angles[2])
59 		bits |= CM_ANGLE3;
60 	if (cmd->forwardmove != from->forwardmove)
61 		bits |= CM_FORWARD;
62 	if (cmd->sidemove != from->sidemove)
63 		bits |= CM_SIDE;
64 	if (cmd->upmove != from->upmove)
65 		bits |= CM_UP;
66 	if (cmd->buttons != from->buttons)
67 		bits |= CM_BUTTONS;
68 	if (cmd->impulse != from->impulse)
69 		bits |= CM_IMPULSE;
70 	MSG_WriteByte (buf, bits);
71 
72 	if (bits & CM_ANGLE1)
73 		MSG_WriteAngle16 (buf, cmd->angles[0]);
74 	if (bits & CM_ANGLE2)
75 		MSG_WriteAngle16 (buf, cmd->angles[1]);
76 	if (bits & CM_ANGLE3)
77 		MSG_WriteAngle16 (buf, cmd->angles[2]);
78 
79 	if (bits & CM_FORWARD)
80 		MSG_WriteShort (buf, cmd->forwardmove);
81 	if (bits & CM_SIDE)
82 		MSG_WriteShort (buf, cmd->sidemove);
83 	if (bits & CM_UP)
84 		MSG_WriteShort (buf, cmd->upmove);
85 
86 	if (bits & CM_BUTTONS)
87 		MSG_WriteByte (buf, cmd->buttons);
88 	if (bits & CM_IMPULSE)
89 		MSG_WriteByte (buf, cmd->impulse);
90 	MSG_WriteByte (buf, cmd->msec);
91 }
92 
93 void
MSG_ReadDeltaUsercmd(qmsg_t * msg,usercmd_t * from,usercmd_t * move)94 MSG_ReadDeltaUsercmd (qmsg_t *msg, usercmd_t *from, usercmd_t *move)
95 {
96 	int         bits;
97 
98 	memcpy (move, from, sizeof (*move));
99 
100 	bits = MSG_ReadByte (msg);
101 
102 	// read current angles
103 	if (bits & CM_ANGLE1)
104 		move->angles[0] = MSG_ReadAngle16 (msg);
105 	if (bits & CM_ANGLE2)
106 		move->angles[1] = MSG_ReadAngle16 (msg);
107 	if (bits & CM_ANGLE3)
108 		move->angles[2] = MSG_ReadAngle16 (msg);
109 
110 	// read movement
111 	if (bits & CM_FORWARD)
112 		move->forwardmove = MSG_ReadShort (msg);
113 	if (bits & CM_SIDE)
114 		move->sidemove = MSG_ReadShort (msg);
115 	if (bits & CM_UP)
116 		move->upmove = MSG_ReadShort (msg);
117 
118 	// read buttons
119 	if (bits & CM_BUTTONS)
120 		move->buttons = MSG_ReadByte (msg);
121 
122 	if (bits & CM_IMPULSE)
123 		move->impulse = MSG_ReadByte (msg);
124 
125 	// read time to run command
126 	move->msec = MSG_ReadByte (msg);
127 }
128