19 #include "shared/shared.h"
20 #include "common/msg.h"
21 #include "common/protocol.h"
22 #include "common/sizebuf.h"
23 #include "common/math.h"
94 if (c < -128 || c > 127)
95 Com_Error(ERR_FATAL,
"MSG_WriteChar: range error");
112 if (c < 0 || c > 255)
113 Com_Error(ERR_FATAL,
"MSG_WriteByte: range error");
130 if (
c < ((
short)0x8000) ||
c > (
short)0x7fff)
131 Com_Error(ERR_FATAL,
"MSG_WriteShort: range error");
150 buf[1] = (
c >> 8) & 0xff;
151 buf[2] = (
c >> 16) & 0xff;
169 length = strlen(
string);
170 if (length >= MAX_NET_STRING) {
171 Com_WPrintf(
"%s: overflow: %"PRIz
" chars", __func__, length);
176 MSG_WriteData(
string, length + 1);
185 #define COORD2SHORT(x) ((int)((x)*8.0f))
186 #define SHORT2COORD(x) ((x)*(1.0f/8))
211 #define ANGLE2BYTE(x) ((int)((x)*256.0f/360)&255)
212 #define BYTE2ANGLE(x) ((x)*(360.0f/256))
226 int MSG_WriteDeltaUsercmd(
const usercmd_t *from,
const usercmd_t *cmd,
int version)
228 int bits, buttons = cmd->buttons & BUTTON_MASK;
238 if (cmd->angles[0] != from->angles[0])
240 if (cmd->angles[1] != from->angles[1])
242 if (cmd->angles[2] != from->angles[2])
244 if (cmd->forwardmove != from->forwardmove)
246 if (cmd->sidemove != from->sidemove)
248 if (cmd->upmove != from->upmove)
250 if (cmd->buttons != from->buttons)
252 if (cmd->impulse != from->impulse)
257 if (version >= PROTOCOL_VERSION_R1Q2_UCMD) {
258 if (bits & CM_BUTTONS) {
259 if ((bits & CM_FORWARD) && !(cmd->forwardmove % 5)) {
260 buttons |= BUTTON_FORWARD;
262 if ((bits & CM_SIDE) && !(cmd->sidemove % 5)) {
263 buttons |= BUTTON_SIDE;
265 if ((bits & CM_UP) && !(cmd->upmove % 5)) {
266 buttons |= BUTTON_UP;
272 if (bits & CM_ANGLE1)
274 if (bits & CM_ANGLE2)
276 if (bits & CM_ANGLE3)
279 if (bits & CM_FORWARD) {
280 if (buttons & BUTTON_FORWARD) {
286 if (bits & CM_SIDE) {
287 if (buttons & BUTTON_SIDE) {
294 if (buttons & BUTTON_UP) {
301 if (version < PROTOCOL_VERSION_R1Q2_UCMD) {
302 if (bits & CM_BUTTONS)
305 if (bits & CM_IMPULSE)
318 void MSG_WriteBits(
int value,
int bits)
323 if (bits == 0 || bits < -31 || bits > 32) {
324 Com_Error(ERR_FATAL,
"MSG_WriteBits: bad bits: %d", bits);
328 Com_Error(ERR_FATAL,
"MSG_WriteBits: overflow");
336 if ((bitpos & 7) == 0) {
352 for (i = 0; i < bits; i++, bitpos++) {
353 if ((bitpos & 7) == 0) {
356 msg_write.data[bitpos >> 3] |= (value & 1) << (bitpos & 7);
368 int MSG_WriteDeltaUsercmd_Enhanced(
const usercmd_t *from,
369 const usercmd_t *cmd,
372 int bits, delta, count;
382 if (cmd->angles[0] != from->angles[0])
384 if (cmd->angles[1] != from->angles[1])
386 if (cmd->angles[2] != from->angles[2])
388 if (cmd->forwardmove != from->forwardmove)
390 if (cmd->sidemove != from->sidemove)
392 if (cmd->upmove != from->upmove)
394 if (cmd->buttons != from->buttons)
396 if (cmd->msec != from->msec)
405 MSG_WriteBits(bits, 8);
407 if (bits & CM_ANGLE1) {
408 delta = cmd->angles[0] - from->angles[0];
409 if (delta >= -128 && delta <= 127) {
411 MSG_WriteBits(delta, -8);
414 MSG_WriteBits(cmd->angles[0], -16);
417 if (bits & CM_ANGLE2) {
418 delta = cmd->angles[1] - from->angles[1];
419 if (delta >= -128 && delta <= 127) {
421 MSG_WriteBits(delta, -8);
424 MSG_WriteBits(cmd->angles[1], -16);
427 if (bits & CM_ANGLE3) {
428 MSG_WriteBits(cmd->angles[2], -16);
431 if (version >= PROTOCOL_VERSION_Q2PRO_UCMD) {
437 if (bits & CM_FORWARD) {
438 MSG_WriteBits(cmd->forwardmove, count);
440 if (bits & CM_SIDE) {
441 MSG_WriteBits(cmd->sidemove, count);
444 MSG_WriteBits(cmd->upmove, count);
447 if (bits & CM_BUTTONS) {
448 int buttons = (cmd->buttons & 3) | (cmd->buttons >> 5);
449 MSG_WriteBits(buttons, 3);
451 if (bits & CM_IMPULSE) {
452 MSG_WriteBits(cmd->msec, 8);
468 void MSG_PackEntity(entity_packed_t *out,
const entity_state_t *in, qboolean short_angles)
471 if (in->number < 0 || in->number >= MAX_EDICTS)
472 Com_Error(ERR_DROP,
"%s: bad number: %d", __func__, in->number);
474 out->number = in->number;
479 out->angles[0] = ANGLE2SHORT(in->angles[0]);
480 out->angles[1] = ANGLE2SHORT(in->angles[1]);
481 out->angles[2] = ANGLE2SHORT(in->angles[2]);
485 out->angles[0] =
ANGLE2BYTE(in->angles[0]) << 8;
486 out->angles[1] =
ANGLE2BYTE(in->angles[1]) << 8;
487 out->angles[2] =
ANGLE2BYTE(in->angles[2]) << 8;
489 out->old_origin[0] =
COORD2SHORT(in->old_origin[0]);
490 out->old_origin[1] =
COORD2SHORT(in->old_origin[1]);
491 out->old_origin[2] =
COORD2SHORT(in->old_origin[2]);
492 out->modelindex = in->modelindex;
493 out->modelindex2 = in->modelindex2;
494 out->modelindex3 = in->modelindex3;
495 out->modelindex4 = in->modelindex4;
496 out->skinnum = in->skinnum;
497 out->effects = in->effects;
498 out->renderfx = in->renderfx;
499 out->solid = in->solid;
500 out->frame = in->frame;
501 out->sound = in->sound;
502 out->event = in->event;
506 const entity_packed_t *to,
513 Com_Error(ERR_DROP,
"%s: NULL", __func__);
515 if (from->number < 1 || from->number >= MAX_EDICTS)
516 Com_Error(ERR_DROP,
"%s: bad number: %d", __func__, from->number);
519 if (from->number & 0xff00)
520 bits |= U_NUMBER16 | U_MOREBITS1;
523 if (bits & 0x0000ff00)
526 if (bits & U_NUMBER16)
534 if (to->number < 1 || to->number >= MAX_EDICTS)
535 Com_Error(ERR_DROP,
"%s: bad number: %d", __func__, to->number);
543 if (!(flags & MSG_ES_FIRSTPERSON)) {
544 if (to->origin[0] != from->origin[0])
546 if (to->origin[1] != from->origin[1])
548 if (to->origin[2] != from->origin[2])
551 if (flags & MSG_ES_SHORTANGLES) {
552 if (to->angles[0] != from->angles[0])
553 bits |= U_ANGLE1 | U_ANGLE16;
554 if (to->angles[1] != from->angles[1])
555 bits |= U_ANGLE2 | U_ANGLE16;
556 if (to->angles[2] != from->angles[2])
557 bits |= U_ANGLE3 | U_ANGLE16;
559 if (to->angles[0] != from->angles[0])
561 if (to->angles[1] != from->angles[1])
563 if (to->angles[2] != from->angles[2])
567 if (flags & MSG_ES_NEWENTITY) {
568 if (to->old_origin[0] != from->origin[0] ||
569 to->old_origin[1] != from->origin[1] ||
570 to->old_origin[2] != from->origin[2])
575 if (flags & MSG_ES_UMASK)
580 if (to->skinnum != from->skinnum) {
581 if (to->skinnum & mask)
582 bits |= U_SKIN8 | U_SKIN16;
583 else if (to->skinnum & 0x0000ff00)
589 if (to->frame != from->frame) {
590 if (to->frame & 0xff00)
596 if (to->effects != from->effects) {
597 if (to->effects & mask)
598 bits |= U_EFFECTS8 | U_EFFECTS16;
599 else if (to->effects & 0x0000ff00)
605 if (to->renderfx != from->renderfx) {
606 if (to->renderfx & mask)
607 bits |= U_RENDERFX8 | U_RENDERFX16;
608 else if (to->renderfx & 0x0000ff00)
609 bits |= U_RENDERFX16;
614 if (to->solid != from->solid)
621 if (to->modelindex != from->modelindex)
623 if (to->modelindex2 != from->modelindex2)
625 if (to->modelindex3 != from->modelindex3)
627 if (to->modelindex4 != from->modelindex4)
630 if (to->sound != from->sound)
633 if (to->renderfx & RF_FRAMELERP) {
635 }
else if (to->renderfx & RF_BEAM) {
636 if (flags & MSG_ES_BEAMORIGIN) {
637 if (to->old_origin[0] != from->old_origin[0] ||
638 to->old_origin[1] != from->old_origin[1] ||
639 to->old_origin[2] != from->old_origin[2])
649 if (!bits && !(flags & MSG_ES_FORCE))
652 if (flags & MSG_ES_REMOVE)
657 if (to->number & 0xff00)
660 if (bits & 0xff000000)
661 bits |= U_MOREBITS3 | U_MOREBITS2 | U_MOREBITS1;
662 else if (bits & 0x00ff0000)
663 bits |= U_MOREBITS2 | U_MOREBITS1;
664 else if (bits & 0x0000ff00)
669 if (bits & 0xff000000) {
673 }
else if (bits & 0x00ff0000) {
676 }
else if (bits & 0x0000ff00) {
682 if (bits & U_NUMBER16)
698 else if (bits & U_FRAME16)
701 if ((bits & (U_SKIN8 | U_SKIN16)) == (U_SKIN8 | U_SKIN16))
703 else if (bits & U_SKIN8)
705 else if (bits & U_SKIN16)
708 if ((bits & (U_EFFECTS8 | U_EFFECTS16)) == (U_EFFECTS8 | U_EFFECTS16))
710 else if (bits & U_EFFECTS8)
712 else if (bits & U_EFFECTS16)
715 if ((bits & (U_RENDERFX8 | U_RENDERFX16)) == (U_RENDERFX8 | U_RENDERFX16))
717 else if (bits & U_RENDERFX8)
719 else if (bits & U_RENDERFX16)
722 if (bits & U_ORIGIN1)
724 if (bits & U_ORIGIN2)
726 if (bits & U_ORIGIN3)
729 if ((flags & MSG_ES_SHORTANGLES) && (bits & U_ANGLE16)) {
745 if (bits & U_OLDORIGIN) {
755 if (bits & U_SOLID) {
756 if (flags & MSG_ES_LONGSOLID)
767 out->pmove = in->pmove;
768 out->viewangles[0] = ANGLE2SHORT(in->viewangles[0]);
769 out->viewangles[1] = ANGLE2SHORT(in->viewangles[1]);
770 out->viewangles[2] = ANGLE2SHORT(in->viewangles[2]);
771 out->viewoffset[0] = in->viewoffset[0] * 4;
772 out->viewoffset[1] = in->viewoffset[1] * 4;
773 out->viewoffset[2] = in->viewoffset[2] * 4;
774 out->kick_angles[0] = in->kick_angles[0] * 4;
775 out->kick_angles[1] = in->kick_angles[1] * 4;
776 out->kick_angles[2] = in->kick_angles[2] * 4;
777 out->gunoffset[0] = in->gunoffset[0] * 4;
778 out->gunoffset[1] = in->gunoffset[1] * 4;
779 out->gunoffset[2] = in->gunoffset[2] * 4;
780 out->gunangles[0] = in->gunangles[0] * 4;
781 out->gunangles[1] = in->gunangles[1] * 4;
782 out->gunangles[2] = in->gunangles[2] * 4;
783 out->gunindex = in->gunindex;
784 out->gunframe = in->gunframe;
785 out->blend[0] = in->blend[0] * 255;
786 out->blend[1] = in->blend[1] * 255;
787 out->blend[2] = in->blend[2] * 255;
788 out->blend[3] = in->blend[3] * 255;
790 out->rdflags = in->rdflags;
791 for (i = 0; i < MAX_STATS; i++)
792 out->stats[i] = in->stats[i];
802 Com_Error(ERR_DROP,
"%s: NULL", __func__);
812 if (to->pmove.pm_type != from->pmove.pm_type)
815 if (to->pmove.origin[0] != from->pmove.origin[0] ||
816 to->pmove.origin[1] != from->pmove.origin[1] ||
817 to->pmove.origin[2] != from->pmove.origin[2])
818 pflags |= PS_M_ORIGIN;
820 if (to->pmove.velocity[0] != from->pmove.velocity[0] ||
821 to->pmove.velocity[1] != from->pmove.velocity[1] ||
822 to->pmove.velocity[2] != from->pmove.velocity[2])
823 pflags |= PS_M_VELOCITY;
825 if (to->pmove.pm_time != from->pmove.pm_time)
828 if (to->pmove.pm_flags != from->pmove.pm_flags)
829 pflags |= PS_M_FLAGS;
831 if (to->pmove.gravity != from->pmove.gravity)
832 pflags |= PS_M_GRAVITY;
834 if (to->pmove.delta_angles[0] != from->pmove.delta_angles[0] ||
835 to->pmove.delta_angles[1] != from->pmove.delta_angles[1] ||
836 to->pmove.delta_angles[2] != from->pmove.delta_angles[2])
837 pflags |= PS_M_DELTA_ANGLES;
839 if (to->viewoffset[0] != from->viewoffset[0] ||
840 to->viewoffset[1] != from->viewoffset[1] ||
841 to->viewoffset[2] != from->viewoffset[2])
842 pflags |= PS_VIEWOFFSET;
844 if (to->viewangles[0] != from->viewangles[0] ||
845 to->viewangles[1] != from->viewangles[1] ||
846 to->viewangles[2] != from->viewangles[2])
847 pflags |= PS_VIEWANGLES;
849 if (to->kick_angles[0] != from->kick_angles[0] ||
850 to->kick_angles[1] != from->kick_angles[1] ||
851 to->kick_angles[2] != from->kick_angles[2])
852 pflags |= PS_KICKANGLES;
854 if (to->blend[0] != from->blend[0] ||
855 to->blend[1] != from->blend[1] ||
856 to->blend[2] != from->blend[2] ||
857 to->blend[3] != from->blend[3])
860 if (to->fov != from->fov)
863 if (to->rdflags != from->rdflags)
864 pflags |= PS_RDFLAGS;
866 if (to->gunframe != from->gunframe ||
867 to->gunoffset[0] != from->gunoffset[0] ||
868 to->gunoffset[1] != from->gunoffset[1] ||
869 to->gunoffset[2] != from->gunoffset[2] ||
870 to->gunangles[0] != from->gunangles[0] ||
871 to->gunangles[1] != from->gunangles[1] ||
872 to->gunangles[2] != from->gunangles[2])
873 pflags |= PS_WEAPONFRAME;
875 if (to->gunindex != from->gunindex)
876 pflags |= PS_WEAPONINDEX;
886 if (pflags & PS_M_TYPE)
889 if (pflags & PS_M_ORIGIN) {
895 if (pflags & PS_M_VELOCITY) {
901 if (pflags & PS_M_TIME)
904 if (pflags & PS_M_FLAGS)
907 if (pflags & PS_M_GRAVITY)
910 if (pflags & PS_M_DELTA_ANGLES) {
919 if (pflags & PS_VIEWOFFSET) {
925 if (pflags & PS_VIEWANGLES) {
931 if (pflags & PS_KICKANGLES) {
937 if (pflags & PS_WEAPONINDEX)
940 if (pflags & PS_WEAPONFRAME) {
950 if (pflags & PS_BLEND) {
960 if (pflags & PS_RDFLAGS)
965 for (i = 0; i < MAX_STATS; i++)
966 if (to->stats[i] != from->stats[i])
970 for (i = 0; i < MAX_STATS; i++)
971 if (statbits & (1 << i))
984 Com_Error(ERR_DROP,
"%s: NULL", __func__);
995 if (to->pmove.pm_type != from->pmove.pm_type)
998 if (to->pmove.origin[0] != from->pmove.origin[0] ||
999 to->pmove.origin[1] != from->pmove.origin[1])
1000 pflags |= PS_M_ORIGIN;
1002 if (to->pmove.origin[2] != from->pmove.origin[2])
1003 eflags |= EPS_M_ORIGIN2;
1005 if (!(flags & MSG_PS_IGNORE_PREDICTION)) {
1006 if (to->pmove.velocity[0] != from->pmove.velocity[0] ||
1007 to->pmove.velocity[1] != from->pmove.velocity[1])
1008 pflags |= PS_M_VELOCITY;
1010 if (to->pmove.velocity[2] != from->pmove.velocity[2])
1011 eflags |= EPS_M_VELOCITY2;
1013 if (to->pmove.pm_time != from->pmove.pm_time)
1014 pflags |= PS_M_TIME;
1016 if (to->pmove.pm_flags != from->pmove.pm_flags)
1017 pflags |= PS_M_FLAGS;
1019 if (to->pmove.gravity != from->pmove.gravity)
1020 pflags |= PS_M_GRAVITY;
1023 VectorCopy(from->pmove.velocity, to->pmove.velocity);
1024 to->pmove.pm_time = from->pmove.pm_time;
1025 to->pmove.pm_flags = from->pmove.pm_flags;
1026 to->pmove.gravity = from->pmove.gravity;
1029 if (!(flags & MSG_PS_IGNORE_DELTAANGLES)) {
1030 if (to->pmove.delta_angles[0] != from->pmove.delta_angles[0] ||
1031 to->pmove.delta_angles[1] != from->pmove.delta_angles[1] ||
1032 to->pmove.delta_angles[2] != from->pmove.delta_angles[2])
1033 pflags |= PS_M_DELTA_ANGLES;
1036 VectorCopy(from->pmove.delta_angles, to->pmove.delta_angles);
1039 if (from->viewoffset[0] != to->viewoffset[0] ||
1040 from->viewoffset[1] != to->viewoffset[1] ||
1041 from->viewoffset[2] != to->viewoffset[2])
1042 pflags |= PS_VIEWOFFSET;
1044 if (!(flags & MSG_PS_IGNORE_VIEWANGLES)) {
1045 if (from->viewangles[0] != to->viewangles[0] ||
1046 from->viewangles[1] != to->viewangles[1])
1047 pflags |= PS_VIEWANGLES;
1049 if (from->viewangles[2] != to->viewangles[2])
1050 eflags |= EPS_VIEWANGLE2;
1053 to->viewangles[0] = from->viewangles[0];
1054 to->viewangles[1] = from->viewangles[1];
1055 to->viewangles[2] = from->viewangles[2];
1058 if (from->kick_angles[0] != to->kick_angles[0] ||
1059 from->kick_angles[1] != to->kick_angles[1] ||
1060 from->kick_angles[2] != to->kick_angles[2])
1061 pflags |= PS_KICKANGLES;
1063 if (!(flags & MSG_PS_IGNORE_BLEND)) {
1064 if (from->blend[0] != to->blend[0] ||
1065 from->blend[1] != to->blend[1] ||
1066 from->blend[2] != to->blend[2] ||
1067 from->blend[3] != to->blend[3])
1071 to->blend[0] = from->blend[0];
1072 to->blend[1] = from->blend[1];
1073 to->blend[2] = from->blend[2];
1074 to->blend[3] = from->blend[3];
1077 if (from->fov != to->fov)
1080 if (to->rdflags != from->rdflags)
1081 pflags |= PS_RDFLAGS;
1083 if (!(flags & MSG_PS_IGNORE_GUNINDEX)) {
1084 if (to->gunindex != from->gunindex)
1085 pflags |= PS_WEAPONINDEX;
1088 to->gunindex = from->gunindex;
1091 if (!(flags & MSG_PS_IGNORE_GUNFRAMES)) {
1092 if (to->gunframe != from->gunframe)
1093 pflags |= PS_WEAPONFRAME;
1095 if (from->gunoffset[0] != to->gunoffset[0] ||
1096 from->gunoffset[1] != to->gunoffset[1] ||
1097 from->gunoffset[2] != to->gunoffset[2])
1098 eflags |= EPS_GUNOFFSET;
1100 if (from->gunangles[0] != to->gunangles[0] ||
1101 from->gunangles[1] != to->gunangles[1] ||
1102 from->gunangles[2] != to->gunangles[2])
1103 eflags |= EPS_GUNANGLES;
1106 to->gunframe = from->gunframe;
1108 to->gunoffset[0] = from->gunoffset[0];
1109 to->gunoffset[1] = from->gunoffset[1];
1110 to->gunoffset[2] = from->gunoffset[2];
1112 to->gunangles[0] = from->gunangles[0];
1113 to->gunangles[1] = from->gunangles[1];
1114 to->gunangles[2] = from->gunangles[2];
1118 for (i = 0; i < MAX_STATS; i++)
1119 if (to->stats[i] != from->stats[i])
1123 eflags |= EPS_STATS;
1133 if (pflags & PS_M_TYPE)
1136 if (pflags & PS_M_ORIGIN) {
1141 if (eflags & EPS_M_ORIGIN2)
1144 if (pflags & PS_M_VELOCITY) {
1149 if (eflags & EPS_M_VELOCITY2)
1152 if (pflags & PS_M_TIME)
1155 if (pflags & PS_M_FLAGS)
1158 if (pflags & PS_M_GRAVITY)
1161 if (pflags & PS_M_DELTA_ANGLES) {
1170 if (pflags & PS_VIEWOFFSET) {
1176 if (pflags & PS_VIEWANGLES) {
1181 if (eflags & EPS_VIEWANGLE2)
1184 if (pflags & PS_KICKANGLES) {
1190 if (pflags & PS_WEAPONINDEX)
1193 if (pflags & PS_WEAPONFRAME)
1196 if (eflags & EPS_GUNOFFSET) {
1202 if (eflags & EPS_GUNANGLES) {
1208 if (pflags & PS_BLEND) {
1215 if (pflags & PS_FOV)
1218 if (pflags & PS_RDFLAGS)
1222 if (eflags & EPS_STATS) {
1224 for (i = 0; i < MAX_STATS; i++)
1225 if (statbits & (1 << i))
1232 #if USE_MVD_SERVER || USE_MVD_CLIENT
1242 void MSG_WriteDeltaPlayerstate_Packet(
const player_packed_t *from,
1243 const player_packed_t *to,
1251 if (number < 0 || number >= MAX_CLIENTS)
1252 Com_Error(ERR_DROP,
"%s: bad number: %d", __func__, number);
1268 if (to->pmove.pm_type != from->pmove.pm_type)
1269 pflags |= PPS_M_TYPE;
1271 if (to->pmove.origin[0] != from->pmove.origin[0] ||
1272 to->pmove.origin[1] != from->pmove.origin[1])
1273 pflags |= PPS_M_ORIGIN;
1275 if (to->pmove.origin[2] != from->pmove.origin[2])
1276 pflags |= PPS_M_ORIGIN2;
1278 if (from->viewoffset[0] != to->viewoffset[0] ||
1279 from->viewoffset[1] != to->viewoffset[1] ||
1280 from->viewoffset[2] != to->viewoffset[2])
1281 pflags |= PPS_VIEWOFFSET;
1283 if (from->viewangles[0] != to->viewangles[0] ||
1284 from->viewangles[1] != to->viewangles[1])
1285 pflags |= PPS_VIEWANGLES;
1287 if (from->viewangles[2] != to->viewangles[2])
1288 pflags |= PPS_VIEWANGLE2;
1290 if (from->kick_angles[0] != to->kick_angles[0] ||
1291 from->kick_angles[1] != to->kick_angles[1] ||
1292 from->kick_angles[2] != to->kick_angles[2])
1293 pflags |= PPS_KICKANGLES;
1295 if (!(flags & MSG_PS_IGNORE_BLEND)) {
1296 if (from->blend[0] != to->blend[0] ||
1297 from->blend[1] != to->blend[1] ||
1298 from->blend[2] != to->blend[2] ||
1299 from->blend[3] != to->blend[3])
1300 pflags |= PPS_BLEND;
1303 if (from->fov != to->fov)
1306 if (to->rdflags != from->rdflags)
1307 pflags |= PPS_RDFLAGS;
1309 if (!(flags & MSG_PS_IGNORE_GUNINDEX)) {
1310 if (to->gunindex != from->gunindex)
1311 pflags |= PPS_WEAPONINDEX;
1314 if (!(flags & MSG_PS_IGNORE_GUNFRAMES)) {
1315 if (to->gunframe != from->gunframe)
1316 pflags |= PPS_WEAPONFRAME;
1318 if (from->gunoffset[0] != to->gunoffset[0] ||
1319 from->gunoffset[1] != to->gunoffset[1] ||
1320 from->gunoffset[2] != to->gunoffset[2])
1321 pflags |= PPS_GUNOFFSET;
1323 if (from->gunangles[0] != to->gunangles[0] ||
1324 from->gunangles[1] != to->gunangles[1] ||
1325 from->gunangles[2] != to->gunangles[2])
1326 pflags |= PPS_GUNANGLES;
1330 for (i = 0; i < MAX_STATS; i++)
1331 if (to->stats[i] != from->stats[i])
1335 pflags |= PPS_STATS;
1337 if (!pflags && !(flags & MSG_PS_FORCE))
1340 if (flags & MSG_PS_REMOVE)
1341 pflags |= PPS_REMOVE;
1352 if (pflags & PPS_M_TYPE)
1355 if (pflags & PPS_M_ORIGIN) {
1360 if (pflags & PPS_M_ORIGIN2)
1366 if (pflags & PPS_VIEWOFFSET) {
1372 if (pflags & PPS_VIEWANGLES) {
1377 if (pflags & PPS_VIEWANGLE2)
1380 if (pflags & PPS_KICKANGLES) {
1386 if (pflags & PPS_WEAPONINDEX)
1389 if (pflags & PPS_WEAPONFRAME)
1392 if (pflags & PPS_GUNOFFSET) {
1398 if (pflags & PPS_GUNANGLES) {
1404 if (pflags & PPS_BLEND) {
1411 if (pflags & PPS_FOV)
1414 if (pflags & PPS_RDFLAGS)
1418 if (pflags & PPS_STATS) {
1420 for (i = 0; i < MAX_STATS; i++)
1421 if (statbits & (1 << i))
1426 #endif // USE_MVD_SERVER || USE_MVD_CLIENT
1452 Com_Error(ERR_DROP,
"%s: read past end of message", __func__);
1469 c = (
signed char)buf[0];
1483 c = (
unsigned char)buf[0];
1497 c = (
signed short)LittleShortMem(buf);
1511 c = (
unsigned short)LittleShortMem(buf);
1525 c = LittleLongMem(buf);
1538 if (
c == -1 ||
c == 0) {
1541 if (len + 1 < size) {
1560 if (
c == -1 ||
c == 0 ||
c ==
'\n') {
1563 if (len + 1 < size) {
1602 if (b < 0 || b >= NUMVERTEXNORMALS)
1603 Com_Error(ERR_DROP,
"MSG_ReadDir: out of range");
1612 memcpy(to, from,
sizeof(*to));
1614 memset(to, 0,
sizeof(*to));
1620 if (bits & CM_ANGLE1)
1622 if (bits & CM_ANGLE2)
1624 if (bits & CM_ANGLE3)
1628 if (bits & CM_FORWARD)
1636 if (bits & CM_BUTTONS)
1639 if (bits & CM_IMPULSE)
1651 int bits, buttons = 0;
1654 memcpy(to, from,
sizeof(*to));
1656 memset(to, 0,
sizeof(*to));
1662 if (bits & CM_BUTTONS) {
1664 to->buttons = buttons & BUTTON_MASK;
1668 if (bits & CM_ANGLE1) {
1669 if (buttons & BUTTON_ANGLE1) {
1675 if (bits & CM_ANGLE2) {
1676 if (buttons & BUTTON_ANGLE2) {
1682 if (bits & CM_ANGLE3)
1686 if (bits & CM_FORWARD) {
1687 if (buttons & BUTTON_FORWARD) {
1693 if (bits & CM_SIDE) {
1694 if (buttons & BUTTON_SIDE) {
1701 if (buttons & BUTTON_UP) {
1708 if (bits & CM_IMPULSE)
1725 if (bits == 0 || bits < -31 || bits > 32) {
1726 Com_Error(ERR_FATAL,
"MSG_ReadBits: bad bits: %d", bits);
1730 if ((bitpos & 7) == 0) {
1757 for (i = 0; i < bits; i++, bitpos++) {
1758 get = (
msg_read.data[bitpos >> 3] >> (bitpos & 7)) & 1;
1762 msg_read.readcount = (bitpos + 7) >> 3;
1765 if (value & (1 << (bits - 1))) {
1766 value |= -1 ^((1 << bits) - 1);
1780 memcpy(to, from,
sizeof(*to));
1782 memset(to, 0,
sizeof(*to));
1792 if (bits & CM_ANGLE1) {
1799 if (bits & CM_ANGLE2) {
1806 if (bits & CM_ANGLE3) {
1811 if (version >= PROTOCOL_VERSION_Q2PRO_UCMD) {
1817 if (bits & CM_FORWARD) {
1820 if (bits & CM_SIDE) {
1828 if (bits & CM_BUTTONS) {
1830 to->buttons = (buttons & 3) | ((buttons & 4) << 5);
1834 if (bits & CM_IMPULSE) {
1839 #if USE_CLIENT || USE_MVD_CLIENT
1848 int MSG_ParseEntityBits(
int *bits)
1854 if (total & U_MOREBITS1) {
1858 if (total & U_MOREBITS2) {
1862 if (total & U_MOREBITS3) {
1867 if (total & U_NUMBER16)
1884 void MSG_ParseDeltaEntity(
const entity_state_t *from,
1891 Com_Error(ERR_DROP,
"%s: NULL", __func__);
1894 if (number < 1 || number >= MAX_EDICTS) {
1895 Com_Error(ERR_DROP,
"%s: bad entity number: %d", __func__, number);
1900 memset(to, 0,
sizeof(*to));
1901 }
else if (to != from) {
1902 memcpy(to, from,
sizeof(*to));
1905 to->number = number;
1912 if (bits & U_MODEL) {
1915 if (bits & U_MODEL2) {
1918 if (bits & U_MODEL3) {
1921 if (bits & U_MODEL4) {
1925 if (bits & U_FRAME8)
1927 if (bits & U_FRAME16)
1930 if ((bits & (U_SKIN8 | U_SKIN16)) == (U_SKIN8 | U_SKIN16))
1932 else if (bits & U_SKIN8)
1934 else if (bits & U_SKIN16)
1937 if ((bits & (U_EFFECTS8 | U_EFFECTS16)) == (U_EFFECTS8 | U_EFFECTS16))
1939 else if (bits & U_EFFECTS8)
1941 else if (bits & U_EFFECTS16)
1944 if ((bits & (U_RENDERFX8 | U_RENDERFX16)) == (U_RENDERFX8 | U_RENDERFX16))
1946 else if (bits & U_RENDERFX8)
1948 else if (bits & U_RENDERFX16)
1951 if (bits & U_ORIGIN1) {
1954 if (bits & U_ORIGIN2) {
1957 if (bits & U_ORIGIN3) {
1961 if ((flags & MSG_ES_SHORTANGLES) && (bits & U_ANGLE16)) {
1962 if (bits & U_ANGLE1)
1964 if (bits & U_ANGLE2)
1966 if (bits & U_ANGLE3)
1969 if (bits & U_ANGLE1)
1971 if (bits & U_ANGLE2)
1973 if (bits & U_ANGLE3)
1977 if (bits & U_OLDORIGIN) {
1981 if (bits & U_SOUND) {
1985 if (bits & U_EVENT) {
1989 if (bits & U_SOLID) {
1990 if (flags & MSG_ES_LONGSOLID) {
1998 #endif // USE_CLIENT || USE_MVD_CLIENT
2007 void MSG_ParseDeltaPlayerstate_Default(
const player_state_t *from,
2015 Com_Error(ERR_DROP,
"%s: NULL", __func__);
2020 memset(to, 0,
sizeof(*to));
2021 }
else if (to != from) {
2022 memcpy(to, from,
sizeof(*to));
2028 if (flags & PS_M_TYPE)
2031 if (flags & PS_M_ORIGIN) {
2037 if (flags & PS_M_VELOCITY) {
2043 if (flags & PS_M_TIME)
2046 if (flags & PS_M_FLAGS)
2049 if (flags & PS_M_GRAVITY)
2052 if (flags & PS_M_DELTA_ANGLES) {
2061 if (flags & PS_VIEWOFFSET) {
2067 if (flags & PS_VIEWANGLES) {
2073 if (flags & PS_KICKANGLES) {
2079 if (flags & PS_WEAPONINDEX) {
2083 if (flags & PS_WEAPONFRAME) {
2093 if (flags & PS_BLEND) {
2103 if (flags & PS_RDFLAGS)
2108 for (i = 0; i < MAX_STATS; i++)
2109 if (statbits & (1 << i))
2119 void MSG_ParseDeltaPlayerstate_Enhanced(
const player_state_t *from,
2128 Com_Error(ERR_DROP,
"%s: NULL", __func__);
2133 memset(to, 0,
sizeof(*to));
2134 }
else if (to != from) {
2135 memcpy(to, from,
sizeof(*to));
2141 if (flags & PS_M_TYPE)
2144 if (flags & PS_M_ORIGIN) {
2149 if (extraflags & EPS_M_ORIGIN2) {
2153 if (flags & PS_M_VELOCITY) {
2158 if (extraflags & EPS_M_VELOCITY2) {
2162 if (flags & PS_M_TIME)
2165 if (flags & PS_M_FLAGS)
2168 if (flags & PS_M_GRAVITY)
2171 if (flags & PS_M_DELTA_ANGLES) {
2180 if (flags & PS_VIEWOFFSET) {
2186 if (flags & PS_VIEWANGLES) {
2191 if (extraflags & EPS_VIEWANGLE2) {
2195 if (flags & PS_KICKANGLES) {
2201 if (flags & PS_WEAPONINDEX) {
2205 if (flags & PS_WEAPONFRAME) {
2209 if (extraflags & EPS_GUNOFFSET) {
2215 if (extraflags & EPS_GUNANGLES) {
2221 if (flags & PS_BLEND) {
2231 if (flags & PS_RDFLAGS)
2235 if (extraflags & EPS_STATS) {
2237 for (i = 0; i < MAX_STATS; i++) {
2238 if (statbits & (1 << i)) {
2246 #endif // USE_CLIENT
2255 void MSG_ParseDeltaPlayerstate_Packet(
const player_state_t *from,
2263 Com_Error(ERR_DROP,
"%s: NULL", __func__);
2268 memset(to, 0,
sizeof(*to));
2269 }
else if (to != from) {
2270 memcpy(to, from,
sizeof(*to));
2276 if (flags & PPS_M_TYPE)
2279 if (flags & PPS_M_ORIGIN) {
2284 if (flags & PPS_M_ORIGIN2) {
2291 if (flags & PPS_VIEWOFFSET) {
2297 if (flags & PPS_VIEWANGLES) {
2302 if (flags & PPS_VIEWANGLE2) {
2306 if (flags & PPS_KICKANGLES) {
2312 if (flags & PPS_WEAPONINDEX) {
2316 if (flags & PPS_WEAPONFRAME) {
2320 if (flags & PPS_GUNOFFSET) {
2326 if (flags & PPS_GUNANGLES) {
2332 if (flags & PPS_BLEND) {
2339 if (flags & PPS_FOV)
2342 if (flags & PPS_RDFLAGS)
2346 if (flags & PPS_STATS) {
2348 for (i = 0; i < MAX_STATS; i++) {
2349 if (statbits & (1 << i)) {
2356 #endif // USE_MVD_CLIENT
2369 #define SHOWBITS(x) Com_LPrintf(PRINT_DEVELOPER, x " ")
2373 void MSG_ShowDeltaPlayerstateBits_Default(
int flags)
2375 #define S(b,s) if(flags&PS_##b) SHOWBITS(s)
2376 S(M_TYPE,
"pmove.pm_type");
2377 S(M_ORIGIN,
"pmove.origin");
2378 S(M_VELOCITY,
"pmove.velocity");
2379 S(M_TIME,
"pmove.pm_time");
2380 S(M_FLAGS,
"pmove.pm_flags");
2381 S(M_GRAVITY,
"pmove.gravity");
2382 S(M_DELTA_ANGLES,
"pmove.delta_angles");
2383 S(VIEWOFFSET,
"viewoffset");
2384 S(VIEWANGLES,
"viewangles");
2385 S(KICKANGLES,
"kick_angles");
2386 S(WEAPONINDEX,
"gunindex");
2387 S(WEAPONFRAME,
"gunframe");
2390 S(RDFLAGS,
"rdflags");
2394 void MSG_ShowDeltaPlayerstateBits_Enhanced(
int flags,
int extraflags)
2396 #define SP(b,s) if(flags&PS_##b) SHOWBITS(s)
2397 #define SE(b,s) if(extraflags&EPS_##b) SHOWBITS(s)
2398 SP(M_TYPE,
"pmove.pm_type");
2399 SP(M_ORIGIN,
"pmove.origin[0,1]");
2400 SE(M_ORIGIN2,
"pmove.origin[2]");
2401 SP(M_VELOCITY,
"pmove.velocity[0,1]");
2402 SE(M_VELOCITY2,
"pmove.velocity[2]");
2403 SP(M_TIME,
"pmove.pm_time");
2404 SP(M_FLAGS,
"pmove.pm_flags");
2405 SP(M_GRAVITY,
"pmove.gravity");
2406 SP(M_DELTA_ANGLES,
"pmove.delta_angles");
2407 SP(VIEWOFFSET,
"viewoffset");
2408 SP(VIEWANGLES,
"viewangles[0,1]");
2409 SE(VIEWANGLE2,
"viewangles[2]");
2410 SP(KICKANGLES,
"kick_angles");
2411 SP(WEAPONINDEX,
"gunindex");
2412 SP(WEAPONFRAME,
"gunframe");
2413 SE(GUNOFFSET,
"gunoffset");
2414 SE(GUNANGLES,
"gunangles");
2417 SP(RDFLAGS,
"rdflags");
2423 void MSG_ShowDeltaUsercmdBits_Enhanced(
int bits)
2430 #define S(b,s) if(bits&CM_##b) SHOWBITS(s)
2431 S(ANGLE1,
"angle1");
2432 S(ANGLE2,
"angle2");
2433 S(ANGLE3,
"angle3");
2434 S(FORWARD,
"forward");
2437 S(BUTTONS,
"buttons");
2442 #endif // USE_CLIENT
2444 #if USE_CLIENT || USE_MVD_CLIENT
2446 void MSG_ShowDeltaEntityBits(
int bits)
2448 #define S(b,s) if(bits&U_##b) SHOWBITS(s)
2449 S(MODEL,
"modelindex");
2450 S(MODEL2,
"modelindex2");
2451 S(MODEL3,
"modelindex3");
2452 S(MODEL4,
"modelindex4");
2454 if (bits & U_FRAME8)
2456 if (bits & U_FRAME16)
2457 SHOWBITS(
"frame16");
2459 if ((bits & (U_SKIN8 | U_SKIN16)) == (U_SKIN8 | U_SKIN16))
2460 SHOWBITS(
"skinnum32");
2461 else if (bits & U_SKIN8)
2462 SHOWBITS(
"skinnum8");
2463 else if (bits & U_SKIN16)
2464 SHOWBITS(
"skinnum16");
2466 if ((bits & (U_EFFECTS8 | U_EFFECTS16)) == (U_EFFECTS8 | U_EFFECTS16))
2467 SHOWBITS(
"effects32");
2468 else if (bits & U_EFFECTS8)
2469 SHOWBITS(
"effects8");
2470 else if (bits & U_EFFECTS16)
2471 SHOWBITS(
"effects16");
2473 if ((bits & (U_RENDERFX8 | U_RENDERFX16)) == (U_RENDERFX8 | U_RENDERFX16))
2474 SHOWBITS(
"renderfx32");
2475 else if (bits & U_RENDERFX8)
2476 SHOWBITS(
"renderfx8");
2477 else if (bits & U_RENDERFX16)
2478 SHOWBITS(
"renderfx16");
2480 S(ORIGIN1,
"origin[0]");
2481 S(ORIGIN2,
"origin[1]");
2482 S(ORIGIN3,
"origin[2]");
2483 S(ANGLE1,
"angles[0]");
2484 S(ANGLE2,
"angles[1]");
2485 S(ANGLE3,
"angles[2]");
2486 S(OLDORIGIN,
"old_origin");
2493 void MSG_ShowDeltaPlayerstateBits_Packet(
int flags)
2495 #define S(b,s) if(flags&PPS_##b) SHOWBITS(s)
2496 S(M_TYPE,
"pmove.pm_type");
2497 S(M_ORIGIN,
"pmove.origin[0,1]");
2498 S(M_ORIGIN2,
"pmove.origin[2]");
2499 S(VIEWOFFSET,
"viewoffset");
2500 S(VIEWANGLES,
"viewangles[0,1]");
2501 S(VIEWANGLE2,
"viewangles[2]");
2502 S(KICKANGLES,
"kick_angles");
2503 S(WEAPONINDEX,
"gunindex");
2504 S(WEAPONFRAME,
"gunframe");
2505 S(GUNOFFSET,
"gunoffset");
2506 S(GUNANGLES,
"gunangles");
2509 S(RDFLAGS,
"rdflags");
2514 const char *MSG_ServerCommandString(
int cmd)
2517 case -1:
return "END OF MESSAGE";
2518 default:
return "UNKNOWN COMMAND";
2519 #define S(x) case svc_##x: return "svc_" #x;
2539 S(deltapacketentities)
2548 #endif // USE_CLIENT || USE_MVD_CLIENT