1 // Misc stuff to transition from ZDoom to Wolf
2 
3 #ifndef __ZDOOM_SUPPORT__
4 #define __ZDOOM_SUPPORT__
5 
6 #include "m_crc32.h"
7 #include "templates.h"
8 
9 #include <cstring>
10 
11 #ifdef __ANDROID__
12 #include <android/log.h>
13 #define printf LOGI
14 #endif
15 
16 int ParseHex(const char* hex);
17 
18 // Ensures that a double is a whole number or a half
CheckTicsValid(double tics)19 static inline bool CheckTicsValid(double tics)
20 {
21 	double ipart;
22 	double fpart = modf(tics, &ipart);
23 	if(MIN(fabs(fpart), fabs(0.5 - fpart)) > 0.0001)
24 		return false;
25 	return true;
26 }
27 
copystring(const char * src)28 static inline char* copystring(const char* src)
29 {
30 	char *dest = new char[strlen(src)+1];
31 	strcpy(dest, src);
32 	dest[strlen(src)] = 0;
33 	return dest;
34 }
35 
ReplaceString(char * & ptr,const char * str)36 static inline void ReplaceString(char* &ptr, const char* str)
37 {
38 	if(ptr)
39 	{
40 		if(ptr == str)
41 			return;
42 		delete[] ptr;
43 	}
44 	ptr = copystring(str);
45 }
46 
MakeKey(const char * s,size_t len)47 static inline unsigned int MakeKey(const char *s, size_t len)
48 {
49 	BYTE* hashString = new BYTE[len];
50 	memcpy(hashString, s, len);
51 	for(size_t i = 0;i < len;++i)
52 		hashString[i] = tolower(*s++);
53 	const DWORD ret = CalcCRC32(hashString, static_cast<unsigned int>(len));
54 	delete[] hashString;
55 	return ret;
56 }
MakeKey(const char * s)57 static inline unsigned int MakeKey(const char *s) { return MakeKey(s, strlen(s)); }
58 
59 // Technically T should always be FString, but we use a template to avoid a
60 // circular dependency issue.
FixPathSeperator(T & path)61 template<class T> void FixPathSeperator (T &path) { path.ReplaceChars('\\', '/'); }
62 
DPrintf(const char * fmt,...)63 static void DPrintf(const char* fmt, ...) {}
64 
65 #define countof(x) (sizeof(x)/sizeof(x[0]))
66 #ifndef __BIG_ENDIAN__
67 #define MAKE_ID(a,b,c,d)	((DWORD)((a)|((b)<<8)|((c)<<16)|((d)<<24)))
68 #else
69 #define MAKE_ID(a,b,c,d)	((DWORD)((d)|((c)<<8)|((b)<<16)|((a)<<24)))
70 #endif
71 
72 #define MAXWIDTH 5120
73 #define Printf printf
74 #define I_FatalError Quit
75 void I_Error(const char* format, ...);
76 
77 #define MulScale16(x,y) (SDWORD((SQWORD(x)*SQWORD(y))>>16))
78 
79 #if defined(_MSC_VER) || defined(__WATCOMC__)
80 #define STACK_ARGS __cdecl
81 #else
82 #define STACK_ARGS
83 #endif
84 
85 #endif /* __ZDOOM_SUPPORT__ */
86