]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - common.h
physics: fix and refactor unsticking
[xonotic/darkplaces.git] / common.h
index e85f43eb9ebd9dca8fc5631adacbe15d41d9f753..5b73aa6f6c4d9a5e0fd0bff5a21eac16c87ad24a 100644 (file)
--- a/common.h
+++ b/common.h
@@ -182,10 +182,12 @@ float MSG_ReadBigFloat (sizebuf_t *sb);
 char *MSG_ReadString (sizebuf_t *sb, char *string, size_t maxstring);
 /// Same as MSG_ReadString except it returns the number of bytes written to *string excluding the \0 terminator.
 size_t MSG_ReadString_len (sizebuf_t *sb, char *string, size_t maxstring);
-int MSG_ReadBytes (sizebuf_t *sb, int numbytes, unsigned char *out);
+size_t MSG_ReadBytes (sizebuf_t *sb, size_t numbytes, unsigned char *out);
 
 #define MSG_ReadChar(sb) ((sb)->readcount >= (sb)->cursize ? ((sb)->badread = true, -1) : (signed char)(sb)->data[(sb)->readcount++])
 #define MSG_ReadByte(sb) ((sb)->readcount >= (sb)->cursize ? ((sb)->badread = true, -1) : (unsigned char)(sb)->data[(sb)->readcount++])
+/// Same as MSG_ReadByte but with no need to copy twice (first to `int` to check for -1) so each byte can be copied directly to a string[]
+#define MSG_ReadByte_opt(sb) ((sb)->readcount >= (sb)->cursize ? ((sb)->badread = true, '\0') : (unsigned char)(sb)->data[(sb)->readcount++])
 #define MSG_ReadShort MSG_ReadLittleShort
 #define MSG_ReadLong MSG_ReadLittleLong
 #define MSG_ReadFloat MSG_ReadLittleFloat
@@ -208,10 +210,10 @@ int COM_Wordwrap(const char *string, size_t length, float continuationSize, floa
 
 extern char com_token[MAX_INPUTLINE];
 extern unsigned com_token_len;
-int COM_ParseToken_Simple(const char **datapointer, qbool returnnewline, qbool parsebackslash, qbool parsecomments);
-int COM_ParseToken_QuakeC(const char **datapointer, qbool returnnewline);
-int COM_ParseToken_VM_Tokenize(const char **datapointer, qbool returnnewline);
-int COM_ParseToken_Console(const char **datapointer);
+qbool COM_ParseToken_Simple(const char **datapointer, qbool returnnewline, qbool parsebackslash, qbool parsecomments);
+qbool COM_ParseToken_QuakeC(const char **datapointer, qbool returnnewline);
+qbool COM_ParseToken_VM_Tokenize(const char **datapointer, qbool returnnewline);
+qbool COM_ParseToken_Console(const char **datapointer);
 
 void COM_Init (void);
 void COM_Shutdown (void);
@@ -232,11 +234,14 @@ char *va(char *buf, size_t buflen, const char *format, ...) DP_FUNC_PRINTF(3);
 #undef vsnprintf
 #define vsnprintf DP_STATIC_ASSERT(0, "vsnprintf is forbidden for portability reasons. Use dpvsnprintf instead.")
 
-// dpsnprintf and dpvsnprintf
-// return the number of printed characters, excluding the final '\0'
-// or return -1 if the buffer isn't big enough to contain the entire string.
-// buffer is ALWAYS null-terminated
+// documentation duplicated deliberately for the benefit of IDEs that support https://www.doxygen.nl/manual/docblocks.html
+/// Returns the number of printed characters, excluding the final '\0'
+/// or returns -1 if the buffer isn't big enough to contain the entire string.
+/// Buffer is ALWAYS null-terminated.
 extern int dpsnprintf (char *buffer, size_t buffersize, const char *format, ...) DP_FUNC_PRINTF(3);
+/// Returns the number of printed characters, excluding the final '\0'
+/// or returns -1 if the buffer isn't big enough to contain the entire string.
+/// Buffer is ALWAYS null-terminated.
 extern int dpvsnprintf (char *buffer, size_t buffersize, const char *format, va_list args);
 
 // A bunch of functions are forbidden for security reasons (and also to please MSVS 2005, for some of them)
@@ -295,7 +300,7 @@ size_t COM_StringDecolorize(const char *in, size_t size_in, char *out, size_t si
 size_t dp__strlcpy(char *dst, const char *src, size_t dsize, const char *func, unsigned line);
 size_t dp__strlcat(char *dst, const char *src, size_t dsize, const char *func, unsigned line);
 char *dp_stpecpy(char *dst, char *end, const char *src);
-char *dp_ustr2stp(char *dst, size_t dsize, const char *src, size_t ssize);
+char *dp_ustr2stp(char *dst, size_t dsize, const char *src, size_t slen);
 
 
 void FindFraction(double val, int *num, int *denom, int denomMax);