diff options
Diffstat (limited to 'src/core/common.h')
-rw-r--r-- | src/core/common.h | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/src/core/common.h b/src/core/common.h index 48b20884..0e6bd60f 100644 --- a/src/core/common.h +++ b/src/core/common.h @@ -217,12 +217,13 @@ public: #if (defined(_MSC_VER)) extern int strcasecmp(const char *str1, const char *str2); +extern int strncasecmp(const char *str1, const char *str2, size_t len); #endif -extern wchar *AllocUnicode(const char*src); - #define clamp(v, low, high) ((v)<(low) ? (low) : (v)>(high) ? (high) : (v)) +#define clamp2(v, center, radius) ((v) < (center) ? Max(v, center - radius) : Min(v, center + radius)) + inline float sq(float x) { return x*x; } #define SQR(x) ((x) * (x)) @@ -411,6 +412,15 @@ inline void SkipSaveBuf(uint8 *&buf, int32 skip) #endif } +inline void SkipSaveBuf(uint8*& buf, uint32 &length, int32 skip) +{ + buf += skip; + length += skip; +#ifdef VALIDATE_SAVE_SIZE + _saveBufCount += skip; +#endif +} + template<typename T> inline const T ReadSaveBuf(uint8 *&buf) { @@ -420,6 +430,14 @@ inline const T ReadSaveBuf(uint8 *&buf) } template<typename T> +inline const T ReadSaveBuf(uint8 *&buf, uint32 &length) +{ + T &value = *(T*)buf; + SkipSaveBuf(buf, length, sizeof(T)); + return value; +} + +template<typename T> inline T *WriteSaveBuf(uint8 *&buf, const T &value) { T *p = (T*)buf; @@ -428,6 +446,15 @@ inline T *WriteSaveBuf(uint8 *&buf, const T &value) return p; } +template<typename T> +inline T *WriteSaveBuf(uint8 *&buf, uint32 &length, const T &value) +{ + T *p = (T*)buf; + *p = value; + SkipSaveBuf(buf, length, sizeof(T)); + return p; +} + #define SAVE_HEADER_SIZE (4*sizeof(char)+sizeof(uint32)) @@ -438,6 +465,13 @@ inline T *WriteSaveBuf(uint8 *&buf, const T &value) WriteSaveBuf(buf, d);\ WriteSaveBuf<uint32>(buf, size); +#define WriteSaveHeaderWithLength(buf,len,a,b,c,d,size) \ + WriteSaveBuf(buf, len, a);\ + WriteSaveBuf(buf, len, b);\ + WriteSaveBuf(buf, len, c);\ + WriteSaveBuf(buf, len, d);\ + WriteSaveBuf<uint32>(buf, len, size); + #define CheckSaveHeader(buf,a,b,c,d,size)\ assert(ReadSaveBuf<char>(buf) == a);\ assert(ReadSaveBuf<char>(buf) == b);\ @@ -445,5 +479,12 @@ inline T *WriteSaveBuf(uint8 *&buf, const T &value) assert(ReadSaveBuf<char>(buf) == d);\ assert(ReadSaveBuf<uint32>(buf) == size); +#define CheckSaveHeaderWithLength(buf,len,a,b,c,d,size)\ + assert(ReadSaveBuf<char>(buf,len) == a);\ + assert(ReadSaveBuf<char>(buf,len) == b);\ + assert(ReadSaveBuf<char>(buf,len) == c);\ + assert(ReadSaveBuf<char>(buf,len) == d);\ + assert(ReadSaveBuf<uint32>(buf,len) == size); + -void cprintf(char*, ...); +void cprintf(char*, ...);
\ No newline at end of file |