2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
msg.h
|
|
|
|
|
|
|
|
(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
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifndef _MSG_H
|
|
|
|
#define _MSG_H
|
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
/** \defgroup msg Message reading and writing
|
2006-12-05 11:40:00 +00:00
|
|
|
\ingroup utils
|
2004-11-08 23:27:00 +00:00
|
|
|
*/
|
|
|
|
//@{
|
|
|
|
|
2001-03-27 23:36:02 +00:00
|
|
|
#include "QF/sizebuf.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-08-19 01:58:01 +00:00
|
|
|
void MSG_WriteByte (sizebuf_t *sb, int c);
|
|
|
|
void MSG_WriteShort (sizebuf_t *sb, int c);
|
|
|
|
void MSG_WriteLong (sizebuf_t *sb, int c);
|
2001-02-19 21:15:25 +00:00
|
|
|
void MSG_WriteFloat (sizebuf_t *sb, float f);
|
2001-07-15 07:04:17 +00:00
|
|
|
void MSG_WriteString (sizebuf_t *sb, const char *s);
|
2012-02-06 06:04:01 +00:00
|
|
|
void MSG_WriteBytes (sizebuf_t *sb, const void *buf, int len);
|
2001-12-12 21:56:09 +00:00
|
|
|
void MSG_WriteCoord (sizebuf_t *sb, float coord);
|
2002-01-03 05:29:38 +00:00
|
|
|
void MSG_WriteCoordV (sizebuf_t *sb, const vec3_t coord);
|
|
|
|
void MSG_WriteCoordAngleV (sizebuf_t *sb, const vec3_t coord,
|
|
|
|
const vec3_t angles);
|
2001-12-12 21:56:09 +00:00
|
|
|
void MSG_WriteAngle (sizebuf_t *sb, float angle);
|
2002-01-03 05:29:38 +00:00
|
|
|
void MSG_WriteAngleV (sizebuf_t *sb, const vec3_t angles);
|
2010-08-24 00:53:54 +00:00
|
|
|
void MSG_WriteAngle16 (sizebuf_t *sb, float angle);
|
|
|
|
void MSG_WriteAngle16V (sizebuf_t *sb, const vec3_t angle);
|
2005-05-05 00:27:04 +00:00
|
|
|
void MSG_WriteUTF8 (sizebuf_t *sb, unsigned utf8);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-23 23:16:13 +00:00
|
|
|
typedef struct msg_s {
|
|
|
|
int readcount;
|
|
|
|
qboolean badread; // set if a read goes beyond end of message
|
|
|
|
sizebuf_t *message;
|
2001-10-18 06:23:26 +00:00
|
|
|
size_t badread_string_size;
|
|
|
|
char *badread_string;
|
2004-01-20 06:11:00 +00:00
|
|
|
} qmsg_t;
|
2001-02-23 23:16:13 +00:00
|
|
|
|
2011-08-28 09:33:29 +00:00
|
|
|
/** Reset the message read status.
|
|
|
|
|
|
|
|
Clears the error flag and resets the read index to 0.
|
|
|
|
|
|
|
|
\param msg The message to be reset.
|
|
|
|
*/
|
2004-01-20 06:11:00 +00:00
|
|
|
void MSG_BeginReading (qmsg_t *msg);
|
2011-08-28 09:33:29 +00:00
|
|
|
|
|
|
|
/** Get the number of bytes that have been read from the message.
|
|
|
|
|
|
|
|
The result can also be used as the index to the next byte to be read.
|
|
|
|
|
|
|
|
\param msg The message to check.
|
|
|
|
\return The number of bytes that have been read.
|
|
|
|
*/
|
2004-01-20 06:11:00 +00:00
|
|
|
int MSG_GetReadCount(qmsg_t *msg);
|
2011-08-28 09:33:29 +00:00
|
|
|
|
|
|
|
/** Read a single byte from the message.
|
|
|
|
|
|
|
|
Advances the read index.
|
|
|
|
|
|
|
|
\param msg The message from which the byte will be read.
|
|
|
|
\return The byte value (0 - 255), or -1 if already at the end of
|
|
|
|
the message.
|
|
|
|
*/
|
2004-01-20 06:11:00 +00:00
|
|
|
int MSG_ReadByte (qmsg_t *msg);
|
2011-08-28 09:33:29 +00:00
|
|
|
|
2011-09-03 04:10:03 +00:00
|
|
|
/** Read a single little-endian unsigned short from the message.
|
2011-08-28 09:33:29 +00:00
|
|
|
|
|
|
|
Advances the read index.
|
|
|
|
|
|
|
|
\param msg The message from which the short will be read.
|
|
|
|
\return The short value (0 - 65535), or -1 if already at
|
|
|
|
the end of the message.
|
|
|
|
*/
|
2004-01-20 06:11:00 +00:00
|
|
|
int MSG_ReadShort (qmsg_t *msg);
|
2011-08-28 09:33:29 +00:00
|
|
|
|
2011-09-03 04:10:03 +00:00
|
|
|
/** Read a single little-endian long from the message.
|
2011-08-28 09:33:29 +00:00
|
|
|
|
|
|
|
Advances the read index.
|
|
|
|
|
|
|
|
\param msg The message from which the long will be read.
|
|
|
|
\return The signed long value or -1 if already at the end of
|
|
|
|
the message.
|
|
|
|
\note -1 may be either an error or a value. Check qmsg_t::badread to
|
|
|
|
differentiate the two cases (false for a value).
|
|
|
|
\todo Fix?
|
|
|
|
*/
|
2004-01-20 06:11:00 +00:00
|
|
|
int MSG_ReadLong (qmsg_t *msg);
|
2011-08-28 09:33:29 +00:00
|
|
|
|
2011-09-03 04:10:03 +00:00
|
|
|
/** Read a single little-endian float from the message.
|
2011-08-28 09:33:29 +00:00
|
|
|
|
|
|
|
Advances the read index.
|
|
|
|
|
|
|
|
\param msg The message from which the float will be read.
|
|
|
|
\return The float value or -1 if already at the end of the
|
|
|
|
message.
|
|
|
|
\note -1 may be either an error or a value. Check qmsg_t::badread to
|
|
|
|
differentiate the two cases (false for a value).
|
|
|
|
\todo Fix?
|
|
|
|
*/
|
2004-01-20 06:11:00 +00:00
|
|
|
float MSG_ReadFloat (qmsg_t *msg);
|
2011-08-28 09:33:29 +00:00
|
|
|
|
|
|
|
/** Read a nul terminated string from the message.
|
|
|
|
|
|
|
|
Advances the read index to the first byte after the string.
|
|
|
|
|
|
|
|
The returned string is guaranteed to be valid. If the string in the
|
|
|
|
message is not nul terminated, the string will be safely extracted,
|
|
|
|
qmst_t::badread set to true, and the extracted string will be returned.
|
|
|
|
|
|
|
|
\param msg The message from which the string will be read.
|
|
|
|
\return The string within the message, or "" if alread at the
|
|
|
|
end of the message.
|
|
|
|
\note "" may be either an error or a value. Check qmsg_t::badread to
|
|
|
|
differentiate the two cases (false for a value).
|
|
|
|
\todo Fix?
|
|
|
|
*/
|
2004-01-20 06:11:00 +00:00
|
|
|
const char *MSG_ReadString (qmsg_t *msg);
|
2011-08-28 09:33:29 +00:00
|
|
|
|
|
|
|
/** Read a block of bytes from the message.
|
|
|
|
|
|
|
|
Advances the read index to the first byte after the block.
|
|
|
|
|
|
|
|
If not all bytes could be read, qmsg_t::badread will be set to true.
|
|
|
|
|
|
|
|
\param msg The message from which the string will be read.
|
|
|
|
\param buf Pointer to the buffer into which the bytes will be
|
|
|
|
placed.
|
|
|
|
\param len The number of bytes to read.
|
|
|
|
\return The number of bytes read from the message.
|
|
|
|
*/
|
2005-05-02 09:00:17 +00:00
|
|
|
int MSG_ReadBytes (qmsg_t *msg, void *buf, int len);
|
2001-02-23 23:16:13 +00:00
|
|
|
|
2011-09-03 04:10:03 +00:00
|
|
|
/** Read a little-endian 16-bit fixed point (13.3) coordinate value from the
|
|
|
|
message.
|
2011-08-28 09:33:29 +00:00
|
|
|
|
|
|
|
Advances the read index to the first byte after the block.
|
|
|
|
|
|
|
|
\param msg The message from which the coordinate will be read.
|
|
|
|
\return The coordinate value converted to floating point.
|
|
|
|
|
|
|
|
\note -0.125 may be either an error or a value. Check qmsg_t::badread
|
|
|
|
to differentiate the two cases (false for a value).
|
|
|
|
\todo Fix?
|
|
|
|
*/
|
2004-01-20 06:11:00 +00:00
|
|
|
float MSG_ReadCoord (qmsg_t *msg);
|
2011-08-28 09:33:29 +00:00
|
|
|
|
2011-09-03 04:10:03 +00:00
|
|
|
/** Read three little-endian 16-bit fixed point (s12.3) coordinate values
|
|
|
|
from the message.
|
2011-08-28 09:33:29 +00:00
|
|
|
|
|
|
|
Advances the read index.
|
|
|
|
|
|
|
|
\param msg The message from which the coordinates will be read.
|
|
|
|
\param coord The vector into which the three coordinates will be
|
|
|
|
placed.
|
|
|
|
|
|
|
|
\note -0.125 may be either an error or a value. Check qmsg_t::badread
|
|
|
|
to differentiate the two cases (false for a value).
|
|
|
|
\todo Fix?
|
|
|
|
*/
|
2004-01-20 06:11:00 +00:00
|
|
|
void MSG_ReadCoordV (qmsg_t *msg, vec3_t coord);
|
2011-08-28 09:33:29 +00:00
|
|
|
|
|
|
|
/** Read an 8-bit encoded angle from the message.
|
|
|
|
|
|
|
|
Advances the read index.
|
|
|
|
|
|
|
|
\param msg The message from which the angle will be read.
|
|
|
|
\return The angle converted to the range -180 - 180.
|
|
|
|
*/
|
2004-01-20 06:11:00 +00:00
|
|
|
float MSG_ReadAngle (qmsg_t *msg);
|
2011-08-28 09:33:29 +00:00
|
|
|
|
2011-09-03 04:10:03 +00:00
|
|
|
/** Read interleaved little-endian 16-bit coordinate/8-bit angle vectors
|
|
|
|
from the message.
|
2011-08-28 09:33:29 +00:00
|
|
|
|
|
|
|
Advances the read index.
|
|
|
|
|
|
|
|
\param msg The message from which the angle will be read.
|
|
|
|
\param coord The vector into which the converted coordinate vector
|
|
|
|
will be placed.
|
|
|
|
\param angles The vector into which the converted coordinate angles
|
|
|
|
will be placed.
|
|
|
|
\see MSG_ReadCoord
|
|
|
|
\see MSG_ReadAngle
|
|
|
|
*/
|
2004-01-20 06:11:00 +00:00
|
|
|
void MSG_ReadCoordAngleV (qmsg_t *msg, vec3_t coord, vec3_t angles);
|
2011-08-28 09:33:29 +00:00
|
|
|
|
|
|
|
/** Read three 8-bit encoded angle values from the message.
|
|
|
|
|
|
|
|
Advances the read index.
|
|
|
|
|
|
|
|
\param msg The message from which the angles will be read.
|
|
|
|
\param angles The vector into which the three angles will be placed.
|
|
|
|
|
|
|
|
\note The angles will be converted to the range -180 - 180.
|
|
|
|
*/
|
2004-01-20 06:11:00 +00:00
|
|
|
void MSG_ReadAngleV (qmsg_t *msg, vec3_t angles);
|
2011-08-28 09:33:29 +00:00
|
|
|
|
2011-09-03 04:10:03 +00:00
|
|
|
/** Read a little-endian 16-bit encoded angle from the message.
|
2011-08-28 09:33:29 +00:00
|
|
|
|
|
|
|
Advances the read index.
|
|
|
|
|
|
|
|
\param msg The message from which the angle will be read.
|
|
|
|
\return The angle converted to the range -180 - 180.
|
|
|
|
*/
|
2004-01-20 06:11:00 +00:00
|
|
|
float MSG_ReadAngle16 (qmsg_t *msg);
|
2011-08-28 09:33:29 +00:00
|
|
|
|
2011-09-03 04:10:03 +00:00
|
|
|
/** Read three little-endian 16-bit encoded angle values from the message.
|
2011-08-28 09:33:29 +00:00
|
|
|
|
|
|
|
Advances the read index.
|
|
|
|
|
|
|
|
\param msg The message from which the angles will be read.
|
|
|
|
\param angles The vector into which the three angles will be placed.
|
|
|
|
|
|
|
|
\note The angles will be converted to the range -180 - 180.
|
|
|
|
*/
|
2010-08-24 00:53:54 +00:00
|
|
|
void MSG_ReadAngle16V (qmsg_t *msg, vec3_t angles);
|
2011-08-28 09:33:29 +00:00
|
|
|
|
|
|
|
/** Read a single UTF-8 encoded value.
|
|
|
|
|
|
|
|
Advances the read index the the first byte after the value. However,
|
|
|
|
the read index will not be advanced if any error is detected.
|
|
|
|
|
|
|
|
A successfull read will read between 1 and 6 bytes from the message.
|
|
|
|
|
|
|
|
\param msg The message from which the UTF-8 encoded value will be
|
|
|
|
read.
|
|
|
|
\return The 31-bit value, or -1 on error.
|
|
|
|
*/
|
2005-05-05 00:27:04 +00:00
|
|
|
int MSG_ReadUTF8 (qmsg_t *msg);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-11-08 23:27:00 +00:00
|
|
|
//@}
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
#endif
|