Quake II RTX doxygen  1.0 dev
msg.c File Reference
#include "shared/shared.h"
#include "common/msg.h"
#include "common/protocol.h"
#include "common/sizebuf.h"
#include "common/math.h"

Go to the source code of this file.

Macros

#define COORD2SHORT(x)   ((int)((x)*8.0f))
 
#define SHORT2COORD(x)   ((x)*(1.0f/8))
 
#define ANGLE2BYTE(x)   ((int)((x)*256.0f/360)&255)
 
#define BYTE2ANGLE(x)   ((x)*(360.0f/256))
 

Functions

void MSG_Init (void)
 
void MSG_BeginWriting (void)
 
void MSG_WriteChar (int c)
 
void MSG_WriteByte (int c)
 
void MSG_WriteShort (int c)
 
void MSG_WriteLong (int c)
 
void MSG_WriteString (const char *string)
 
static void MSG_WriteCoord (float f)
 
void MSG_WritePos (const vec3_t pos)
 
void MSG_WriteAngle (float f)
 
void MSG_WriteDir (const vec3_t dir)
 
void MSG_PackEntity (entity_packed_t *out, const entity_state_t *in, qboolean short_angles)
 
void MSG_WriteDeltaEntity (const entity_packed_t *from, const entity_packed_t *to, msgEsFlags_t flags)
 
void MSG_PackPlayer (player_packed_t *out, const player_state_t *in)
 
void MSG_WriteDeltaPlayerstate_Default (const player_packed_t *from, const player_packed_t *to)
 
int MSG_WriteDeltaPlayerstate_Enhanced (const player_packed_t *from, player_packed_t *to, msgPsFlags_t flags)
 
void MSG_BeginReading (void)
 
byte * MSG_ReadData (size_t len)
 
int MSG_ReadChar (void)
 
int MSG_ReadByte (void)
 
int MSG_ReadShort (void)
 
int MSG_ReadWord (void)
 
int MSG_ReadLong (void)
 
size_t MSG_ReadString (char *dest, size_t size)
 
size_t MSG_ReadStringLine (char *dest, size_t size)
 
static float MSG_ReadCoord (void)
 
void MSG_ReadPos (vec3_t pos)
 
static float MSG_ReadAngle (void)
 
static float MSG_ReadAngle16 (void)
 
void MSG_ReadDir (vec3_t dir)
 
void MSG_ReadDeltaUsercmd (const usercmd_t *from, usercmd_t *to)
 
void MSG_ReadDeltaUsercmd_Hacked (const usercmd_t *from, usercmd_t *to)
 
int MSG_ReadBits (int bits)
 
void MSG_ReadDeltaUsercmd_Enhanced (const usercmd_t *from, usercmd_t *to, int version)
 

Variables

sizebuf_t msg_write
 
byte msg_write_buffer [MAX_MSGLEN]
 
sizebuf_t msg_read
 
byte msg_read_buffer [MAX_MSGLEN]
 
const entity_packed_t nullEntityState
 
const player_packed_t nullPlayerState
 
const usercmd_t nullUserCmd
 

Macro Definition Documentation

◆ ANGLE2BYTE

#define ANGLE2BYTE (   x)    ((int)((x)*256.0f/360)&255)

Definition at line 211 of file msg.c.

◆ BYTE2ANGLE

#define BYTE2ANGLE (   x)    ((x)*(360.0f/256))

Definition at line 212 of file msg.c.

◆ COORD2SHORT

#define COORD2SHORT (   x)    ((int)((x)*8.0f))

Definition at line 185 of file msg.c.

◆ SHORT2COORD

#define SHORT2COORD (   x)    ((x)*(1.0f/8))

Definition at line 186 of file msg.c.

Function Documentation

◆ MSG_BeginReading()

void MSG_BeginReading ( void  )

Definition at line 1437 of file msg.c.

1438 {
1439  msg_read.readcount = 0;
1440  msg_read.bitpos = 0;
1441 }

Referenced by CL_ConnectionlessPacket(), NetchanNew_Process(), NetchanOld_Process(), and SV_ConnectionlessPacket().

◆ MSG_BeginWriting()

void MSG_BeginWriting ( void  )

Definition at line 77 of file msg.c.

78 {
79  msg_write.cursize = 0;
80  msg_write.bitpos = 0;
81  msg_write.overflowed = qfalse;
82 }

◆ MSG_Init()

void MSG_Init ( void  )

Definition at line 57 of file msg.c.

58 {
59  SZ_TagInit(&msg_read, msg_read_buffer, MAX_MSGLEN, SZ_MSG_READ);
60  SZ_TagInit(&msg_write, msg_write_buffer, MAX_MSGLEN, SZ_MSG_WRITE);
61 }

Referenced by Com_Error(), and Qcommon_Init().

◆ MSG_PackEntity()

void MSG_PackEntity ( entity_packed_t *  out,
const entity_state_t *  in,
qboolean  short_angles 
)

Definition at line 468 of file msg.c.

469 {
470  // allow 0 to accomodate empty baselines
471  if (in->number < 0 || in->number >= MAX_EDICTS)
472  Com_Error(ERR_DROP, "%s: bad number: %d", __func__, in->number);
473 
474  out->number = in->number;
475  out->origin[0] = COORD2SHORT(in->origin[0]);
476  out->origin[1] = COORD2SHORT(in->origin[1]);
477  out->origin[2] = COORD2SHORT(in->origin[2]);
478  if (short_angles) {
479  out->angles[0] = ANGLE2SHORT(in->angles[0]);
480  out->angles[1] = ANGLE2SHORT(in->angles[1]);
481  out->angles[2] = ANGLE2SHORT(in->angles[2]);
482  } else {
483  // pack angles8 akin to angles16 to make delta compression happy when
484  // precision suddenly changes between entity updates
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;
488  }
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;
503 }

Referenced by build_gamestate(), CL_GTV_EmitFrame(), CL_Record_f(), create_baselines(), emit_base_frame(), emit_frame(), emit_packet_entities(), and SV_BuildClientFrame().

◆ MSG_PackPlayer()

void MSG_PackPlayer ( player_packed_t *  out,
const player_state_t *  in 
)

Definition at line 763 of file msg.c.

764 {
765  int i;
766 
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;
789  out->fov = in->fov;
790  out->rdflags = in->rdflags;
791  for (i = 0; i < MAX_STATS; i++)
792  out->stats[i] = in->stats[i];
793 }

Referenced by build_gamestate(), CL_GTV_EmitFrame(), emit_base_frame(), emit_delta_frame(), emit_frame(), and SV_BuildClientFrame().

◆ MSG_ReadAngle()

static float MSG_ReadAngle ( void  )
inlinestatic

Definition at line 1587 of file msg.c.

1588 {
1589  return BYTE2ANGLE(MSG_ReadChar());
1590 }

◆ MSG_ReadAngle16()

static float MSG_ReadAngle16 ( void  )
inlinestatic

Definition at line 1592 of file msg.c.

1593 {
1594  return SHORT2ANGLE(MSG_ReadShort());
1595 }

◆ MSG_ReadBits()

int MSG_ReadBits ( int  bits)

Definition at line 1718 of file msg.c.

1719 {
1720  int i, get;
1721  size_t bitpos;
1722  qboolean sgn;
1723  int value;
1724 
1725  if (bits == 0 || bits < -31 || bits > 32) {
1726  Com_Error(ERR_FATAL, "MSG_ReadBits: bad bits: %d", bits);
1727  }
1728 
1729  bitpos = msg_read.bitpos;
1730  if ((bitpos & 7) == 0) {
1731  // optimized case
1732  switch (bits) {
1733  case -8:
1734  value = MSG_ReadChar();
1735  return value;
1736  case 8:
1737  value = MSG_ReadByte();
1738  return value;
1739  case -16:
1740  value = MSG_ReadShort();
1741  return value;
1742  case 32:
1743  value = MSG_ReadLong();
1744  return value;
1745  default:
1746  break;
1747  }
1748  }
1749 
1750  sgn = qfalse;
1751  if (bits < 0) {
1752  bits = -bits;
1753  sgn = qtrue;
1754  }
1755 
1756  value = 0;
1757  for (i = 0; i < bits; i++, bitpos++) {
1758  get = (msg_read.data[bitpos >> 3] >> (bitpos & 7)) & 1;
1759  value |= get << i;
1760  }
1761  msg_read.bitpos = bitpos;
1762  msg_read.readcount = (bitpos + 7) >> 3;
1763 
1764  if (sgn) {
1765  if (value & (1 << (bits - 1))) {
1766  value |= -1 ^((1 << bits) - 1);
1767  }
1768  }
1769 
1770  return value;
1771 }

Referenced by MSG_ReadDeltaUsercmd_Enhanced(), and SV_NewClientExecuteMove().

◆ MSG_ReadByte()

◆ MSG_ReadChar()

int MSG_ReadChar ( void  )

Definition at line 1461 of file msg.c.

1462 {
1463  byte *buf = MSG_ReadData(1);
1464  int c;
1465 
1466  if (!buf) {
1467  c = -1;
1468  } else {
1469  c = (signed char)buf[0];
1470  }
1471 
1472  return c;
1473 }

Referenced by MSG_ReadAngle(), MSG_ReadBits(), and MSG_ReadDeltaUsercmd_Hacked().

◆ MSG_ReadCoord()

static float MSG_ReadCoord ( void  )
inlinestatic

Definition at line 1575 of file msg.c.

1576 {
1577  return SHORT2COORD(MSG_ReadShort());
1578 }

Referenced by MSG_ReadPos().

◆ MSG_ReadData()

byte* MSG_ReadData ( size_t  len)

Definition at line 1443 of file msg.c.

1444 {
1445  byte *buf = msg_read.data + msg_read.readcount;
1446 
1447  msg_read.readcount += len;
1448  msg_read.bitpos = msg_read.readcount << 3;
1449 
1450  if (msg_read.readcount > msg_read.cursize) {
1451  if (!msg_read.allowunderflow) {
1452  Com_Error(ERR_DROP, "%s: read past end of message", __func__);
1453  }
1454  return NULL;
1455  }
1456 
1457  return buf;
1458 }

Referenced by MSG_ReadByte(), MSG_ReadChar(), MSG_ReadLong(), MSG_ReadShort(), MSG_ReadWord(), and read_level_file().

◆ MSG_ReadDeltaUsercmd()

void MSG_ReadDeltaUsercmd ( const usercmd_t *  from,
usercmd_t *  to 
)

Definition at line 1607 of file msg.c.

1608 {
1609  int bits;
1610 
1611  if (from) {
1612  memcpy(to, from, sizeof(*to));
1613  } else {
1614  memset(to, 0, sizeof(*to));
1615  }
1616 
1617  bits = MSG_ReadByte();
1618 
1619 // read current angles
1620  if (bits & CM_ANGLE1)
1621  to->angles[0] = MSG_ReadShort();
1622  if (bits & CM_ANGLE2)
1623  to->angles[1] = MSG_ReadShort();
1624  if (bits & CM_ANGLE3)
1625  to->angles[2] = MSG_ReadShort();
1626 
1627 // read movement
1628  if (bits & CM_FORWARD)
1629  to->forwardmove = MSG_ReadShort();
1630  if (bits & CM_SIDE)
1631  to->sidemove = MSG_ReadShort();
1632  if (bits & CM_UP)
1633  to->upmove = MSG_ReadShort();
1634 
1635 // read buttons
1636  if (bits & CM_BUTTONS)
1637  to->buttons = MSG_ReadByte();
1638 
1639  if (bits & CM_IMPULSE)
1640  to->impulse = MSG_ReadByte();
1641 
1642 // read time to run command
1643  to->msec = MSG_ReadByte();
1644 
1645 // read the light level
1646  to->lightlevel = MSG_ReadByte();
1647 }

Referenced by SV_OldClientExecuteMove().

◆ MSG_ReadDeltaUsercmd_Enhanced()

void MSG_ReadDeltaUsercmd_Enhanced ( const usercmd_t *  from,
usercmd_t *  to,
int  version 
)

Definition at line 1773 of file msg.c.

1776 {
1777  int bits, count;
1778 
1779  if (from) {
1780  memcpy(to, from, sizeof(*to));
1781  } else {
1782  memset(to, 0, sizeof(*to));
1783  }
1784 
1785  if (!MSG_ReadBits(1)) {
1786  return;
1787  }
1788 
1789  bits = MSG_ReadBits(8);
1790 
1791 // read current angles
1792  if (bits & CM_ANGLE1) {
1793  if (MSG_ReadBits(1)) {
1794  to->angles[0] += MSG_ReadBits(-8);
1795  } else {
1796  to->angles[0] = MSG_ReadBits(-16);
1797  }
1798  }
1799  if (bits & CM_ANGLE2) {
1800  if (MSG_ReadBits(1)) {
1801  to->angles[1] += MSG_ReadBits(-8);
1802  } else {
1803  to->angles[1] = MSG_ReadBits(-16);
1804  }
1805  }
1806  if (bits & CM_ANGLE3) {
1807  to->angles[2] = MSG_ReadBits(-16);
1808  }
1809 
1810 // read movement
1811  if (version >= PROTOCOL_VERSION_Q2PRO_UCMD) {
1812  count = -10;
1813  } else {
1814  count = -16;
1815  }
1816 
1817  if (bits & CM_FORWARD) {
1818  to->forwardmove = MSG_ReadBits(count);
1819  }
1820  if (bits & CM_SIDE) {
1821  to->sidemove = MSG_ReadBits(count);
1822  }
1823  if (bits & CM_UP) {
1824  to->upmove = MSG_ReadBits(count);
1825  }
1826 
1827 // read buttons
1828  if (bits & CM_BUTTONS) {
1829  int buttons = MSG_ReadBits(3);
1830  to->buttons = (buttons & 3) | ((buttons & 4) << 5);
1831  }
1832 
1833 // read time to run command
1834  if (bits & CM_IMPULSE) {
1835  to->msec = MSG_ReadBits(8);
1836  }
1837 }

Referenced by SV_NewClientExecuteMove().

◆ MSG_ReadDeltaUsercmd_Hacked()

void MSG_ReadDeltaUsercmd_Hacked ( const usercmd_t *  from,
usercmd_t *  to 
)

Definition at line 1649 of file msg.c.

1650 {
1651  int bits, buttons = 0;
1652 
1653  if (from) {
1654  memcpy(to, from, sizeof(*to));
1655  } else {
1656  memset(to, 0, sizeof(*to));
1657  }
1658 
1659  bits = MSG_ReadByte();
1660 
1661 // read buttons
1662  if (bits & CM_BUTTONS) {
1663  buttons = MSG_ReadByte();
1664  to->buttons = buttons & BUTTON_MASK;
1665  }
1666 
1667 // read current angles
1668  if (bits & CM_ANGLE1) {
1669  if (buttons & BUTTON_ANGLE1) {
1670  to->angles[0] = MSG_ReadChar() * 64;
1671  } else {
1672  to->angles[0] = MSG_ReadShort();
1673  }
1674  }
1675  if (bits & CM_ANGLE2) {
1676  if (buttons & BUTTON_ANGLE2) {
1677  to->angles[1] = MSG_ReadChar() * 256;
1678  } else {
1679  to->angles[1] = MSG_ReadShort();
1680  }
1681  }
1682  if (bits & CM_ANGLE3)
1683  to->angles[2] = MSG_ReadShort();
1684 
1685 // read movement
1686  if (bits & CM_FORWARD) {
1687  if (buttons & BUTTON_FORWARD) {
1688  to->forwardmove = MSG_ReadChar() * 5;
1689  } else {
1690  to->forwardmove = MSG_ReadShort();
1691  }
1692  }
1693  if (bits & CM_SIDE) {
1694  if (buttons & BUTTON_SIDE) {
1695  to->sidemove = MSG_ReadChar() * 5;
1696  } else {
1697  to->sidemove = MSG_ReadShort();
1698  }
1699  }
1700  if (bits & CM_UP) {
1701  if (buttons & BUTTON_UP) {
1702  to->upmove = MSG_ReadChar() * 5;
1703  } else {
1704  to->upmove = MSG_ReadShort();
1705  }
1706  }
1707 
1708  if (bits & CM_IMPULSE)
1709  to->impulse = MSG_ReadByte();
1710 
1711 // read time to run command
1712  to->msec = MSG_ReadByte();
1713 
1714 // read the light level
1715  to->lightlevel = MSG_ReadByte();
1716 }

Referenced by SV_OldClientExecuteMove().

◆ MSG_ReadDir()

void MSG_ReadDir ( vec3_t  dir)

Definition at line 1597 of file msg.c.

1598 {
1599  int b;
1600 
1601  b = MSG_ReadByte();
1602  if (b < 0 || b >= NUMVERTEXNORMALS)
1603  Com_Error(ERR_DROP, "MSG_ReadDir: out of range");
1604  VectorCopy(bytedirs[b], dir);
1605 }

Referenced by CL_ParseTEntPacket().

◆ MSG_ReadLong()

int MSG_ReadLong ( void  )

Definition at line 1517 of file msg.c.

1518 {
1519  byte *buf = MSG_ReadData(4);
1520  int c;
1521 
1522  if (!buf) {
1523  c = -1;
1524  } else {
1525  c = LittleLongMem(buf);
1526  }
1527 
1528  return c;
1529 }

Referenced by AC_ParseClient(), CL_ConnectionlessPacket(), CL_GetDemoInfo(), CL_ParseFrame(), CL_ParseServerData(), CL_ParseSetting(), CL_ParseTEntPacket(), MSG_ReadBits(), MVD_ParseServerData(), NetchanNew_Process(), NetchanOld_Process(), parse_hello(), read_level_file(), read_server_file(), SV_ConnectionlessPacket(), SV_GetSaveInfo(), SV_NewClientExecuteMove(), and SV_OldClientExecuteMove().

◆ MSG_ReadPos()

void MSG_ReadPos ( vec3_t  pos)

Definition at line 1580 of file msg.c.

1581 {
1582  pos[0] = MSG_ReadCoord();
1583  pos[1] = MSG_ReadCoord();
1584  pos[2] = MSG_ReadCoord();
1585 }

Referenced by CL_ParseStartSoundPacket(), and CL_ParseTEntPacket().

◆ MSG_ReadShort()

◆ MSG_ReadString()

size_t MSG_ReadString ( char *  dest,
size_t  size 
)

Definition at line 1531 of file msg.c.

1532 {
1533  int c;
1534  size_t len = 0;
1535 
1536  while (1) {
1537  c = MSG_ReadByte();
1538  if (c == -1 || c == 0) {
1539  break;
1540  }
1541  if (len + 1 < size) {
1542  *dest++ = c;
1543  }
1544  len++;
1545  }
1546  if (size) {
1547  *dest = 0;
1548  }
1549 
1550  return len;
1551 }

Referenced by AC_ParseError(), AC_ParseFileViolation(), AC_ParseViolation(), CL_GetDemoInfo(), CL_ParseCenterPrint(), CL_ParseConfigstring(), CL_ParseInfoMessage(), CL_ParseLayout(), CL_ParsePrint(), CL_ParsePrintMessage(), CL_ParseServerData(), CL_ParseStuffText(), CL_SeekDemoMessage(), MVD_ParseConfigstring(), MVD_ParsePrint(), MVD_ParseServerData(), MVD_UnicastLayout(), MVD_UnicastPrint(), MVD_UnicastString(), MVD_UnicastStuff(), parse_hello(), parse_stringcmd(), read_level_file(), read_server_file(), SV_GetSaveInfo(), SV_ParseClientCommand(), SV_ParseDeltaUserinfo(), and SV_ParseFullUserinfo().

◆ MSG_ReadStringLine()

size_t MSG_ReadStringLine ( char *  dest,
size_t  size 
)

Definition at line 1553 of file msg.c.

1554 {
1555  int c;
1556  size_t len = 0;
1557 
1558  while (1) {
1559  c = MSG_ReadByte();
1560  if (c == -1 || c == 0 || c == '\n') {
1561  break;
1562  }
1563  if (len + 1 < size) {
1564  *dest++ = c;
1565  }
1566  len++;
1567  }
1568  if (size) {
1569  *dest = 0;
1570  }
1571 
1572  return len;
1573 }

Referenced by CL_ConnectionlessPacket(), and SV_ConnectionlessPacket().

◆ MSG_ReadWord()

int MSG_ReadWord ( void  )

Definition at line 1503 of file msg.c.

1504 {
1505  byte *buf = MSG_ReadData(2);
1506  int c;
1507 
1508  if (!buf) {
1509  c = -1;
1510  } else {
1511  c = (unsigned short)LittleShortMem(buf);
1512  }
1513 
1514  return c;
1515 }

Referenced by AC_ParseClient(), CL_ParseZPacket(), MVD_ParseMulticast(), and parse_hello().

◆ MSG_WriteAngle()

void MSG_WriteAngle ( float  f)

Definition at line 214 of file msg.c.

215 {
217 }

Referenced by SV_InitGameProgs().

◆ MSG_WriteByte()

void MSG_WriteByte ( int  c)

Definition at line 107 of file msg.c.

108 {
109  byte *buf;
110 
111 #ifdef PARANOID
112  if (c < 0 || c > 255)
113  Com_Error(ERR_FATAL, "MSG_WriteByte: range error");
114 #endif
115 
116  buf = SZ_GetSpace(&msg_write, 1);
117  buf[0] = c;
118 }

Referenced by AC_Announce(), AC_ClientConnect(), AC_ClientDisconnect(), AC_ClientQuery(), AC_SendChecks(), AC_SendHello(), AC_SendPing(), AC_SendPrefs(), AC_WriteString(), CL_ClientCommand(), CL_ConnectionlessPacket(), CL_Disconnect(), CL_EmitDemoSnapshot(), CL_GTV_EmitFrame(), CL_Record_f(), CL_SendBatchedCmd(), CL_SendDefaultCmd(), CL_SendUserinfo(), CL_UpdateBlendSetting(), CL_UpdateFootstepsSetting(), CL_UpdateGibSetting(), CL_UpdateGunSetting(), CL_UpdatePredictSetting(), CL_UpdateRecordingSetting(), demo_emit_snapshot(), emit_base_frame(), emit_delta_frame(), emit_frame(), emit_gamestate(), emit_snd(), gtv_forward_cmd(), handle_filtercmd(), MSG_WriteAngle(), MSG_WriteDeltaEntity(), MSG_WriteDeltaPlayerstate_Default(), MSG_WriteDeltaPlayerstate_Enhanced(), MSG_WriteDir(), MSG_WriteString(), MVD_BroadcastPrintf(), MVD_ChangeLevel(), MVD_LayoutChannels(), MVD_LayoutClients(), MVD_LayoutFollow(), MVD_LayoutMenu(), MVD_LayoutScores(), MVD_ParseSound(), MVD_SwitchChannel(), MVD_UpdateConfigstring(), PF_bprintf(), PF_centerprintf(), PF_configstring(), PF_cprintf(), PF_PositionedSound(), PF_StartSound(), redirect(), stuff_cmds(), SV_BeginDownload_f(), SV_BroadcastCommand(), SV_BroadcastPrintf(), SV_ClientCommand(), SV_ClientPrintf(), SV_DropClient(), SV_FinalMessage(), SV_FlushRedirect(), SV_InitGameProgs(), SV_New_f(), SV_StopDownload_f(), SV_Stuff_f(), SV_StuffAll_f(), SV_WriteFrameToClient_Default(), SV_WriteFrameToClient_Enhanced(), write_cs_list(), write_datagram_new(), write_level_file(), write_plain_baselines(), write_plain_configstrings(), and write_server_file().

◆ MSG_WriteChar()

void MSG_WriteChar ( int  c)

Definition at line 89 of file msg.c.

90 {
91  byte *buf;
92 
93 #ifdef PARANOID
94  if (c < -128 || c > 127)
95  Com_Error(ERR_FATAL, "MSG_WriteChar: range error");
96 #endif
97 
98  buf = SZ_GetSpace(&msg_write, 1);
99  buf[0] = c;
100 }

Referenced by MSG_WriteDeltaPlayerstate_Default(), MSG_WriteDeltaPlayerstate_Enhanced(), and SV_InitGameProgs().

◆ MSG_WriteCoord()

static void MSG_WriteCoord ( float  f)
inlinestatic

Definition at line 188 of file msg.c.

189 {
191 }

Referenced by MSG_WritePos().

◆ MSG_WriteDeltaEntity()

void MSG_WriteDeltaEntity ( const entity_packed_t *  from,
const entity_packed_t *  to,
msgEsFlags_t  flags 
)

Definition at line 505 of file msg.c.

508 {
509  uint32_t bits, mask;
510 
511  if (!to) {
512  if (!from)
513  Com_Error(ERR_DROP, "%s: NULL", __func__);
514 
515  if (from->number < 1 || from->number >= MAX_EDICTS)
516  Com_Error(ERR_DROP, "%s: bad number: %d", __func__, from->number);
517 
518  bits = U_REMOVE;
519  if (from->number & 0xff00)
520  bits |= U_NUMBER16 | U_MOREBITS1;
521 
522  MSG_WriteByte(bits & 255);
523  if (bits & 0x0000ff00)
524  MSG_WriteByte((bits >> 8) & 255);
525 
526  if (bits & U_NUMBER16)
527  MSG_WriteShort(from->number);
528  else
529  MSG_WriteByte(from->number);
530 
531  return; // remove entity
532  }
533 
534  if (to->number < 1 || to->number >= MAX_EDICTS)
535  Com_Error(ERR_DROP, "%s: bad number: %d", __func__, to->number);
536 
537  if (!from)
538  from = &nullEntityState;
539 
540 // send an update
541  bits = 0;
542 
543  if (!(flags & MSG_ES_FIRSTPERSON)) {
544  if (to->origin[0] != from->origin[0])
545  bits |= U_ORIGIN1;
546  if (to->origin[1] != from->origin[1])
547  bits |= U_ORIGIN2;
548  if (to->origin[2] != from->origin[2])
549  bits |= U_ORIGIN3;
550 
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;
558  } else {
559  if (to->angles[0] != from->angles[0])
560  bits |= U_ANGLE1;
561  if (to->angles[1] != from->angles[1])
562  bits |= U_ANGLE2;
563  if (to->angles[2] != from->angles[2])
564  bits |= U_ANGLE3;
565  }
566 
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])
571  bits |= U_OLDORIGIN;
572  }
573  }
574 
575  if (flags & MSG_ES_UMASK)
576  mask = 0xffff0000;
577  else
578  mask = 0xffff8000; // don't confuse old clients
579 
580  if (to->skinnum != from->skinnum) {
581  if (to->skinnum & mask)
582  bits |= U_SKIN8 | U_SKIN16;
583  else if (to->skinnum & 0x0000ff00)
584  bits |= U_SKIN16;
585  else
586  bits |= U_SKIN8;
587  }
588 
589  if (to->frame != from->frame) {
590  if (to->frame & 0xff00)
591  bits |= U_FRAME16;
592  else
593  bits |= U_FRAME8;
594  }
595 
596  if (to->effects != from->effects) {
597  if (to->effects & mask)
598  bits |= U_EFFECTS8 | U_EFFECTS16;
599  else if (to->effects & 0x0000ff00)
600  bits |= U_EFFECTS16;
601  else
602  bits |= U_EFFECTS8;
603  }
604 
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;
610  else
611  bits |= U_RENDERFX8;
612  }
613 
614  if (to->solid != from->solid)
615  bits |= U_SOLID;
616 
617  // event is not delta compressed, just 0 compressed
618  if (to->event)
619  bits |= U_EVENT;
620 
621  if (to->modelindex != from->modelindex)
622  bits |= U_MODEL;
623  if (to->modelindex2 != from->modelindex2)
624  bits |= U_MODEL2;
625  if (to->modelindex3 != from->modelindex3)
626  bits |= U_MODEL3;
627  if (to->modelindex4 != from->modelindex4)
628  bits |= U_MODEL4;
629 
630  if (to->sound != from->sound)
631  bits |= U_SOUND;
632 
633  if (to->renderfx & RF_FRAMELERP) {
634  bits |= U_OLDORIGIN;
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])
640  bits |= U_OLDORIGIN;
641  } else {
642  bits |= U_OLDORIGIN;
643  }
644  }
645 
646  //
647  // write the message
648  //
649  if (!bits && !(flags & MSG_ES_FORCE))
650  return; // nothing to send!
651 
652  if (flags & MSG_ES_REMOVE)
653  bits |= U_REMOVE; // used for MVD stream only
654 
655  //----------
656 
657  if (to->number & 0xff00)
658  bits |= U_NUMBER16; // number8 is implicit otherwise
659 
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)
665  bits |= U_MOREBITS1;
666 
667  MSG_WriteByte(bits & 255);
668 
669  if (bits & 0xff000000) {
670  MSG_WriteByte((bits >> 8) & 255);
671  MSG_WriteByte((bits >> 16) & 255);
672  MSG_WriteByte((bits >> 24) & 255);
673  } else if (bits & 0x00ff0000) {
674  MSG_WriteByte((bits >> 8) & 255);
675  MSG_WriteByte((bits >> 16) & 255);
676  } else if (bits & 0x0000ff00) {
677  MSG_WriteByte((bits >> 8) & 255);
678  }
679 
680  //----------
681 
682  if (bits & U_NUMBER16)
683  MSG_WriteShort(to->number);
684  else
685  MSG_WriteByte(to->number);
686 
687  if (bits & U_MODEL)
688  MSG_WriteByte(to->modelindex);
689  if (bits & U_MODEL2)
690  MSG_WriteByte(to->modelindex2);
691  if (bits & U_MODEL3)
692  MSG_WriteByte(to->modelindex3);
693  if (bits & U_MODEL4)
694  MSG_WriteByte(to->modelindex4);
695 
696  if (bits & U_FRAME8)
697  MSG_WriteByte(to->frame);
698  else if (bits & U_FRAME16)
699  MSG_WriteShort(to->frame);
700 
701  if ((bits & (U_SKIN8 | U_SKIN16)) == (U_SKIN8 | U_SKIN16)) //used for laser colors
702  MSG_WriteLong(to->skinnum);
703  else if (bits & U_SKIN8)
704  MSG_WriteByte(to->skinnum);
705  else if (bits & U_SKIN16)
706  MSG_WriteShort(to->skinnum);
707 
708  if ((bits & (U_EFFECTS8 | U_EFFECTS16)) == (U_EFFECTS8 | U_EFFECTS16))
709  MSG_WriteLong(to->effects);
710  else if (bits & U_EFFECTS8)
711  MSG_WriteByte(to->effects);
712  else if (bits & U_EFFECTS16)
713  MSG_WriteShort(to->effects);
714 
715  if ((bits & (U_RENDERFX8 | U_RENDERFX16)) == (U_RENDERFX8 | U_RENDERFX16))
716  MSG_WriteLong(to->renderfx);
717  else if (bits & U_RENDERFX8)
718  MSG_WriteByte(to->renderfx);
719  else if (bits & U_RENDERFX16)
720  MSG_WriteShort(to->renderfx);
721 
722  if (bits & U_ORIGIN1)
723  MSG_WriteShort(to->origin[0]);
724  if (bits & U_ORIGIN2)
725  MSG_WriteShort(to->origin[1]);
726  if (bits & U_ORIGIN3)
727  MSG_WriteShort(to->origin[2]);
728 
729  if ((flags & MSG_ES_SHORTANGLES) && (bits & U_ANGLE16)) {
730  if (bits & U_ANGLE1)
731  MSG_WriteShort(to->angles[0]);
732  if (bits & U_ANGLE2)
733  MSG_WriteShort(to->angles[1]);
734  if (bits & U_ANGLE3)
735  MSG_WriteShort(to->angles[2]);
736  } else {
737  if (bits & U_ANGLE1)
738  MSG_WriteByte(to->angles[0] >> 8);
739  if (bits & U_ANGLE2)
740  MSG_WriteByte(to->angles[1] >> 8);
741  if (bits & U_ANGLE3)
742  MSG_WriteByte(to->angles[2] >> 8);
743  }
744 
745  if (bits & U_OLDORIGIN) {
746  MSG_WriteShort(to->old_origin[0]);
747  MSG_WriteShort(to->old_origin[1]);
748  MSG_WriteShort(to->old_origin[2]);
749  }
750 
751  if (bits & U_SOUND)
752  MSG_WriteByte(to->sound);
753  if (bits & U_EVENT)
754  MSG_WriteByte(to->event);
755  if (bits & U_SOLID) {
756  if (flags & MSG_ES_LONGSOLID)
757  MSG_WriteLong(to->solid);
758  else
759  MSG_WriteShort(to->solid);
760  }
761 }

Referenced by CL_GTV_EmitFrame(), CL_Record_f(), emit_base_frame(), emit_frame(), emit_gamestate(), emit_packet_entities(), SV_EmitPacketEntities(), and write_baseline().

◆ MSG_WriteDeltaPlayerstate_Default()

void MSG_WriteDeltaPlayerstate_Default ( const player_packed_t *  from,
const player_packed_t *  to 
)

Definition at line 795 of file msg.c.

796 {
797  int i;
798  int pflags;
799  int statbits;
800 
801  if (!to)
802  Com_Error(ERR_DROP, "%s: NULL", __func__);
803 
804  if (!from)
805  from = &nullPlayerState;
806 
807  //
808  // determine what needs to be sent
809  //
810  pflags = 0;
811 
812  if (to->pmove.pm_type != from->pmove.pm_type)
813  pflags |= PS_M_TYPE;
814 
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;
819 
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;
824 
825  if (to->pmove.pm_time != from->pmove.pm_time)
826  pflags |= PS_M_TIME;
827 
828  if (to->pmove.pm_flags != from->pmove.pm_flags)
829  pflags |= PS_M_FLAGS;
830 
831  if (to->pmove.gravity != from->pmove.gravity)
832  pflags |= PS_M_GRAVITY;
833 
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;
838 
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;
843 
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;
848 
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;
853 
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])
858  pflags |= PS_BLEND;
859 
860  if (to->fov != from->fov)
861  pflags |= PS_FOV;
862 
863  if (to->rdflags != from->rdflags)
864  pflags |= PS_RDFLAGS;
865 
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;
874 
875  if (to->gunindex != from->gunindex)
876  pflags |= PS_WEAPONINDEX;
877 
878  //
879  // write it
880  //
881  MSG_WriteShort(pflags);
882 
883  //
884  // write the pmove_state_t
885  //
886  if (pflags & PS_M_TYPE)
887  MSG_WriteByte(to->pmove.pm_type);
888 
889  if (pflags & PS_M_ORIGIN) {
890  MSG_WriteShort(to->pmove.origin[0]);
891  MSG_WriteShort(to->pmove.origin[1]);
892  MSG_WriteShort(to->pmove.origin[2]);
893  }
894 
895  if (pflags & PS_M_VELOCITY) {
896  MSG_WriteShort(to->pmove.velocity[0]);
897  MSG_WriteShort(to->pmove.velocity[1]);
898  MSG_WriteShort(to->pmove.velocity[2]);
899  }
900 
901  if (pflags & PS_M_TIME)
902  MSG_WriteByte(to->pmove.pm_time);
903 
904  if (pflags & PS_M_FLAGS)
905  MSG_WriteByte(to->pmove.pm_flags);
906 
907  if (pflags & PS_M_GRAVITY)
908  MSG_WriteShort(to->pmove.gravity);
909 
910  if (pflags & PS_M_DELTA_ANGLES) {
911  MSG_WriteShort(to->pmove.delta_angles[0]);
912  MSG_WriteShort(to->pmove.delta_angles[1]);
913  MSG_WriteShort(to->pmove.delta_angles[2]);
914  }
915 
916  //
917  // write the rest of the player_state_t
918  //
919  if (pflags & PS_VIEWOFFSET) {
920  MSG_WriteChar(to->viewoffset[0]);
921  MSG_WriteChar(to->viewoffset[1]);
922  MSG_WriteChar(to->viewoffset[2]);
923  }
924 
925  if (pflags & PS_VIEWANGLES) {
926  MSG_WriteShort(to->viewangles[0]);
927  MSG_WriteShort(to->viewangles[1]);
928  MSG_WriteShort(to->viewangles[2]);
929  }
930 
931  if (pflags & PS_KICKANGLES) {
932  MSG_WriteChar(to->kick_angles[0]);
933  MSG_WriteChar(to->kick_angles[1]);
934  MSG_WriteChar(to->kick_angles[2]);
935  }
936 
937  if (pflags & PS_WEAPONINDEX)
938  MSG_WriteByte(to->gunindex);
939 
940  if (pflags & PS_WEAPONFRAME) {
941  MSG_WriteByte(to->gunframe);
942  MSG_WriteChar(to->gunoffset[0]);
943  MSG_WriteChar(to->gunoffset[1]);
944  MSG_WriteChar(to->gunoffset[2]);
945  MSG_WriteChar(to->gunangles[0]);
946  MSG_WriteChar(to->gunangles[1]);
947  MSG_WriteChar(to->gunangles[2]);
948  }
949 
950  if (pflags & PS_BLEND) {
951  MSG_WriteByte(to->blend[0]);
952  MSG_WriteByte(to->blend[1]);
953  MSG_WriteByte(to->blend[2]);
954  MSG_WriteByte(to->blend[3]);
955  }
956 
957  if (pflags & PS_FOV)
958  MSG_WriteByte(to->fov);
959 
960  if (pflags & PS_RDFLAGS)
961  MSG_WriteByte(to->rdflags);
962 
963  // send stats
964  statbits = 0;
965  for (i = 0; i < MAX_STATS; i++)
966  if (to->stats[i] != from->stats[i])
967  statbits |= 1 << i;
968 
969  MSG_WriteLong(statbits);
970  for (i = 0; i < MAX_STATS; i++)
971  if (statbits & (1 << i))
972  MSG_WriteShort(to->stats[i]);
973 }

Referenced by emit_delta_frame(), and SV_WriteFrameToClient_Default().

◆ MSG_WriteDeltaPlayerstate_Enhanced()

int MSG_WriteDeltaPlayerstate_Enhanced ( const player_packed_t *  from,
player_packed_t *  to,
msgPsFlags_t  flags 
)

Definition at line 975 of file msg.c.

978 {
979  int i;
980  int pflags, eflags;
981  int statbits;
982 
983  if (!to)
984  Com_Error(ERR_DROP, "%s: NULL", __func__);
985 
986  if (!from)
987  from = &nullPlayerState;
988 
989  //
990  // determine what needs to be sent
991  //
992  pflags = 0;
993  eflags = 0;
994 
995  if (to->pmove.pm_type != from->pmove.pm_type)
996  pflags |= PS_M_TYPE;
997 
998  if (to->pmove.origin[0] != from->pmove.origin[0] ||
999  to->pmove.origin[1] != from->pmove.origin[1])
1000  pflags |= PS_M_ORIGIN;
1001 
1002  if (to->pmove.origin[2] != from->pmove.origin[2])
1003  eflags |= EPS_M_ORIGIN2;
1004 
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;
1009 
1010  if (to->pmove.velocity[2] != from->pmove.velocity[2])
1011  eflags |= EPS_M_VELOCITY2;
1012 
1013  if (to->pmove.pm_time != from->pmove.pm_time)
1014  pflags |= PS_M_TIME;
1015 
1016  if (to->pmove.pm_flags != from->pmove.pm_flags)
1017  pflags |= PS_M_FLAGS;
1018 
1019  if (to->pmove.gravity != from->pmove.gravity)
1020  pflags |= PS_M_GRAVITY;
1021  } else {
1022  // save previous state
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;
1027  }
1028 
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;
1034  } else {
1035  // save previous state
1036  VectorCopy(from->pmove.delta_angles, to->pmove.delta_angles);
1037  }
1038 
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;
1043 
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;
1048 
1049  if (from->viewangles[2] != to->viewangles[2])
1050  eflags |= EPS_VIEWANGLE2;
1051  } else {
1052  // save previous state
1053  to->viewangles[0] = from->viewangles[0];
1054  to->viewangles[1] = from->viewangles[1];
1055  to->viewangles[2] = from->viewangles[2];
1056  }
1057 
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;
1062 
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])
1068  pflags |= PS_BLEND;
1069  } else {
1070  // save previous state
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];
1075  }
1076 
1077  if (from->fov != to->fov)
1078  pflags |= PS_FOV;
1079 
1080  if (to->rdflags != from->rdflags)
1081  pflags |= PS_RDFLAGS;
1082 
1083  if (!(flags & MSG_PS_IGNORE_GUNINDEX)) {
1084  if (to->gunindex != from->gunindex)
1085  pflags |= PS_WEAPONINDEX;
1086  } else {
1087  // save previous state
1088  to->gunindex = from->gunindex;
1089  }
1090 
1091  if (!(flags & MSG_PS_IGNORE_GUNFRAMES)) {
1092  if (to->gunframe != from->gunframe)
1093  pflags |= PS_WEAPONFRAME;
1094 
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;
1099 
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;
1104  } else {
1105  // save previous state
1106  to->gunframe = from->gunframe;
1107 
1108  to->gunoffset[0] = from->gunoffset[0];
1109  to->gunoffset[1] = from->gunoffset[1];
1110  to->gunoffset[2] = from->gunoffset[2];
1111 
1112  to->gunangles[0] = from->gunangles[0];
1113  to->gunangles[1] = from->gunangles[1];
1114  to->gunangles[2] = from->gunangles[2];
1115  }
1116 
1117  statbits = 0;
1118  for (i = 0; i < MAX_STATS; i++)
1119  if (to->stats[i] != from->stats[i])
1120  statbits |= 1 << i;
1121 
1122  if (statbits)
1123  eflags |= EPS_STATS;
1124 
1125  //
1126  // write it
1127  //
1128  MSG_WriteShort(pflags);
1129 
1130  //
1131  // write the pmove_state_t
1132  //
1133  if (pflags & PS_M_TYPE)
1134  MSG_WriteByte(to->pmove.pm_type);
1135 
1136  if (pflags & PS_M_ORIGIN) {
1137  MSG_WriteShort(to->pmove.origin[0]);
1138  MSG_WriteShort(to->pmove.origin[1]);
1139  }
1140 
1141  if (eflags & EPS_M_ORIGIN2)
1142  MSG_WriteShort(to->pmove.origin[2]);
1143 
1144  if (pflags & PS_M_VELOCITY) {
1145  MSG_WriteShort(to->pmove.velocity[0]);
1146  MSG_WriteShort(to->pmove.velocity[1]);
1147  }
1148 
1149  if (eflags & EPS_M_VELOCITY2)
1150  MSG_WriteShort(to->pmove.velocity[2]);
1151 
1152  if (pflags & PS_M_TIME)
1153  MSG_WriteByte(to->pmove.pm_time);
1154 
1155  if (pflags & PS_M_FLAGS)
1156  MSG_WriteByte(to->pmove.pm_flags);
1157 
1158  if (pflags & PS_M_GRAVITY)
1159  MSG_WriteShort(to->pmove.gravity);
1160 
1161  if (pflags & PS_M_DELTA_ANGLES) {
1162  MSG_WriteShort(to->pmove.delta_angles[0]);
1163  MSG_WriteShort(to->pmove.delta_angles[1]);
1164  MSG_WriteShort(to->pmove.delta_angles[2]);
1165  }
1166 
1167  //
1168  // write the rest of the player_state_t
1169  //
1170  if (pflags & PS_VIEWOFFSET) {
1171  MSG_WriteChar(to->viewoffset[0]);
1172  MSG_WriteChar(to->viewoffset[1]);
1173  MSG_WriteChar(to->viewoffset[2]);
1174  }
1175 
1176  if (pflags & PS_VIEWANGLES) {
1177  MSG_WriteShort(to->viewangles[0]);
1178  MSG_WriteShort(to->viewangles[1]);
1179  }
1180 
1181  if (eflags & EPS_VIEWANGLE2)
1182  MSG_WriteShort(to->viewangles[2]);
1183 
1184  if (pflags & PS_KICKANGLES) {
1185  MSG_WriteChar(to->kick_angles[0]);
1186  MSG_WriteChar(to->kick_angles[1]);
1187  MSG_WriteChar(to->kick_angles[2]);
1188  }
1189 
1190  if (pflags & PS_WEAPONINDEX)
1191  MSG_WriteByte(to->gunindex);
1192 
1193  if (pflags & PS_WEAPONFRAME)
1194  MSG_WriteByte(to->gunframe);
1195 
1196  if (eflags & EPS_GUNOFFSET) {
1197  MSG_WriteChar(to->gunoffset[0]);
1198  MSG_WriteChar(to->gunoffset[1]);
1199  MSG_WriteChar(to->gunoffset[2]);
1200  }
1201 
1202  if (eflags & EPS_GUNANGLES) {
1203  MSG_WriteChar(to->gunangles[0]);
1204  MSG_WriteChar(to->gunangles[1]);
1205  MSG_WriteChar(to->gunangles[2]);
1206  }
1207 
1208  if (pflags & PS_BLEND) {
1209  MSG_WriteByte(to->blend[0]);
1210  MSG_WriteByte(to->blend[1]);
1211  MSG_WriteByte(to->blend[2]);
1212  MSG_WriteByte(to->blend[3]);
1213  }
1214 
1215  if (pflags & PS_FOV)
1216  MSG_WriteByte(to->fov);
1217 
1218  if (pflags & PS_RDFLAGS)
1219  MSG_WriteByte(to->rdflags);
1220 
1221  // send stats
1222  if (eflags & EPS_STATS) {
1223  MSG_WriteLong(statbits);
1224  for (i = 0; i < MAX_STATS; i++)
1225  if (statbits & (1 << i))
1226  MSG_WriteShort(to->stats[i]);
1227  }
1228 
1229  return eflags;
1230 }

Referenced by SV_WriteFrameToClient_Enhanced().

◆ MSG_WriteDir()

void MSG_WriteDir ( const vec3_t  dir)

Definition at line 460 of file msg.c.

461 {
462  int best;
463 
464  best = DirToByte(dir);
465  MSG_WriteByte(best);
466 }

Referenced by SV_InitGameProgs().

◆ MSG_WriteLong()

◆ MSG_WritePos()

void MSG_WritePos ( const vec3_t  pos)

Definition at line 198 of file msg.c.

199 {
200  MSG_WriteCoord(pos[0]);
201  MSG_WriteCoord(pos[1]);
202  MSG_WriteCoord(pos[2]);
203 }

Referenced by MVD_ParseSound(), PF_PositionedSound(), PF_StartSound(), and SV_InitGameProgs().

◆ MSG_WriteShort()

◆ MSG_WriteString()

void MSG_WriteString ( const char *  string)

Definition at line 160 of file msg.c.

161 {
162  size_t length;
163 
164  if (!string) {
165  MSG_WriteByte(0);
166  return;
167  }
168 
169  length = strlen(string);
170  if (length >= MAX_NET_STRING) {
171  Com_WPrintf("%s: overflow: %"PRIz" chars", __func__, length);
172  MSG_WriteByte(0);
173  return;
174  }
175 
176  MSG_WriteData(string, length + 1);
177 }

Referenced by CL_ClientCommand(), CL_EmitDemoSnapshot(), CL_Record_f(), CL_SendUserinfo(), emit_gamestate(), MVD_ChangeLevel(), MVD_LayoutScores(), MVD_SwitchChannel(), MVD_UpdateConfigstring(), redirect(), send_hello(), SV_FinalMessage(), SV_InitGameProgs(), SV_New_f(), SV_Stuff_f(), SV_StuffAll_f(), write_cs_list(), and write_server_file().

Variable Documentation

◆ msg_read

◆ msg_read_buffer

◆ msg_write

◆ msg_write_buffer

byte msg_write_buffer[MAX_MSGLEN]

Definition at line 35 of file msg.c.

Referenced by MSG_Init().

◆ nullEntityState

const entity_packed_t nullEntityState

Definition at line 40 of file msg.c.

Referenced by MSG_WriteDeltaEntity(), and SV_EmitPacketEntities().

◆ nullPlayerState

const player_packed_t nullPlayerState

Definition at line 41 of file msg.c.

Referenced by MSG_WriteDeltaPlayerstate_Default(), and MSG_WriteDeltaPlayerstate_Enhanced().

◆ nullUserCmd

const usercmd_t nullUserCmd

Definition at line 42 of file msg.c.

nullEntityState
const entity_packed_t nullEntityState
Definition: msg.c:40
MSG_WriteCoord
static void MSG_WriteCoord(float f)
Definition: msg.c:188
msg_read
sizebuf_t msg_read
Definition: msg.c:37
msg_read_buffer
byte msg_read_buffer[MAX_MSGLEN]
Definition: msg.c:38
BYTE2ANGLE
#define BYTE2ANGLE(x)
Definition: msg.c:212
nullPlayerState
const player_packed_t nullPlayerState
Definition: msg.c:41
ANGLE2BYTE
#define ANGLE2BYTE(x)
Definition: msg.c:211
SHORT2COORD
#define SHORT2COORD(x)
Definition: msg.c:186
MSG_WriteByte
void MSG_WriteByte(int c)
Definition: msg.c:107
MSG_ReadChar
int MSG_ReadChar(void)
Definition: msg.c:1461
msg_write_buffer
byte msg_write_buffer[MAX_MSGLEN]
Definition: msg.c:35
MSG_ReadBits
int MSG_ReadBits(int bits)
Definition: msg.c:1718
SZ_GetSpace
void * SZ_GetSpace(sizebuf_t *buf, size_t len)
Definition: sizebuf.c:48
Com_Error
void Com_Error(error_type_t type, const char *fmt,...)
Definition: g_main.c:258
MSG_ReadData
byte * MSG_ReadData(size_t len)
Definition: msg.c:1443
msg_write
sizebuf_t msg_write
Definition: msg.c:34
DirToByte
int DirToByte(const vec3_t dir)
Definition: math.c:245
MSG_ReadLong
int MSG_ReadLong(void)
Definition: msg.c:1517
MSG_WriteShort
void MSG_WriteShort(int c)
Definition: msg.c:125
COORD2SHORT
#define COORD2SHORT(x)
Definition: msg.c:185
SZ_TagInit
void SZ_TagInit(sizebuf_t *buf, void *data, size_t size, uint32_t tag)
Definition: sizebuf.c:23
MSG_ReadCoord
static float MSG_ReadCoord(void)
Definition: msg.c:1575
c
statCounters_t c
Definition: main.c:30
MSG_WriteLong
void MSG_WriteLong(int c)
Definition: msg.c:144
MSG_WriteChar
void MSG_WriteChar(int c)
Definition: msg.c:89
MSG_ReadByte
int MSG_ReadByte(void)
Definition: msg.c:1475
bytedirs
const vec3_t bytedirs[NUMVERTEXNORMALS]
Definition: math.c:80
MSG_ReadShort
int MSG_ReadShort(void)
Definition: msg.c:1489