1 //
2 // Definitions of common non-engine data structures/functions
3 // (and declarations of data appearing in both)
4 // for EDuke32 and Mapster32
5 //
6
7 #ifndef EDUKE32_COMMON_H_
8 #define EDUKE32_COMMON_H_
9
10 #include "cache1d.h"
11 #include "compat.h"
12 #include "pragmas.h" // klabs
13 #include "scriptfile.h"
14 #include "vfs.h"
15
16
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20
21 //// TYPES
22 struct strllist
23 {
24 struct strllist *next;
25 char *str;
26 };
27
28 typedef struct
29 {
30 const char *text;
31 int32_t tokenid;
32 }
33 tokenlist;
34
35 typedef struct
36 {
37 BUILDVFS_FIND_REC *finddirs, *findfiles;
38 int32_t numdirs, numfiles;
39 }
40 fnlist_t;
41
42 #define FNLIST_INITIALIZER { NULL, NULL, 0, 0 }
43
44 enum
45 {
46 T_EOF = -2,
47 T_ERROR = -1,
48 };
49
50
51 //// EXTERN DECLS
52
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 extern const char *s_buildRev;
57 extern const char *s_buildTimestamp;
58 #ifdef __cplusplus
59 }
60 #endif
61
62 //// FUNCTIONS
63 extern void PrintBuildInfo(void);
64
65 extern void clearDefNamePtr(void);
66
67 void G_AddGroup(const char *buffer);
68 void G_AddPath(const char *buffer);
69 void G_AddDef(const char *buffer);
70 void G_AddDefModule(const char *buffer);
71 #ifdef HAVE_CLIPSHAPE_FEATURE
72 void G_AddClipMap(const char *buffer);
73 #endif
74
75 // returns a buffer of size BMAX_PATH
dup_filename(const char * fn)76 static inline char *dup_filename(const char *fn)
77 {
78 char * const buf = (char *) Xmalloc(BMAX_PATH);
79 return Bstrncpyz(buf, fn, BMAX_PATH);
80 }
81
realloc_copy(char ** fn,const char * buf)82 static inline void realloc_copy(char **fn, const char *buf)
83 {
84 uint8_t len = Bstrlen(buf) + 1;
85 *fn = (char *)Xrealloc(*fn, len);
86 Bstrncpy(*fn, buf, len);
87 }
88
89 int32_t getatoken(scriptfile *sf, const tokenlist *tl, int32_t ntokens);
90
91 int32_t G_CheckCmdSwitch(int32_t argc, char const * const * argv, const char *str);
92
93 int32_t testkopen(const char *filename, char searchfirst); // full-blown kopen4load
94 int32_t check_file_exist(const char *fn); // findfrompath with pathsearchmode=1 / search in zips
95
96 void fnlist_clearnames(fnlist_t *fnl);
97 int32_t fnlist_getnames(fnlist_t *fnl, const char *dirname, const char *pattern,
98 int32_t dirflags, int32_t fileflags);
99
100
101 int32_t maybe_append_ext(char *wbuf, int32_t wbufsiz, const char *fn, const char *ext);
102
103 // Approximations to 2D and 3D Euclidean distances. Initial EDuke32 SVN import says
104 // in mact/src/mathutil.c: "Ken's reverse-engineering job".
105 // Note that mathutil.c contains practically the same code, but where the
106 // individual x/y(/z) distances are passed instead.
107 extern int32_t duke64;
sepldist(const int32_t dx,const int32_t dy)108 static inline int32_t sepldist(const int32_t dx, const int32_t dy)
109 {
110 vec2_t d = { klabs(dx), klabs(dy) };
111
112 if (duke64)
113 return Blrintf(Bsqrtf(float(d.x)*float(d.x)+float(d.y)*float(d.y)));
114
115 if (!d.y) return d.x;
116 if (!d.x) return d.y;
117
118 if (d.x < d.y)
119 swaplong(&d.x, &d.y);
120
121 d.y += (d.y>>1);
122
123 return d.x - (d.x>>5) - (d.x>>7) + (d.y>>2) + (d.y>>6);
124 }
125
126 // dz: in Build coordinates
sepdist(const int32_t dx,const int32_t dy,const int32_t dz)127 static inline int32_t sepdist(const int32_t dx, const int32_t dy, const int32_t dz)
128 {
129 vec3_t d = { klabs(dx), klabs(dy), klabs(dz>>4) };
130
131 if (duke64)
132 return Blrintf(Bsqrtf(float(d.x)*float(d.x)+float(d.y)*float(d.y)+float(d.z)*float(d.z)));
133
134 if (d.x < d.y)
135 swaplong(&d.x, &d.y);
136
137 if (d.x < d.z)
138 swaplong(&d.x, &d.z);
139
140 d.y += d.z;
141
142 return d.x - (d.x>>4) + (d.y>>2) + (d.y>>3);
143 }
144
145 int32_t FindDistance2D(int32_t dx, int32_t dy);
146 int32_t FindDistance3D(int32_t dx, int32_t dy, int32_t dz);
147 int32_t ldist(const void *s1, const void *s2);
148 int32_t dist(const void *s1, const void *s2);
149
150 void COMMON_clearbackground(int32_t numcols, int32_t numrows);
151
152 // timer defs for profiling function chunks the simple way
153 #define EDUKE32_TMRDEF int32_t t[20], ti=0; const char *tmrstr=__func__; fprintf(stderr,"%s\n",tmrstr); t[ti++]=timerGetTicks();
154 #define EDUKE32_TMRTIC t[ti++]=timerGetTicks()
155 #define EDUKE32_TMRPRN do { int ii=0; fprintf(stderr,"%s: ",tmrstr); for (ii=1; ii<ti; ii++) fprintf(stderr,"%d ", t[ii]-t[ii-1]); fprintf(stderr,"\n"); } while (0)
156
157 #if defined _WIN32 && !defined EDUKE32_STANDALONE
158 int Paths_ReadRegistryValue(char const * const SubKey, char const * const Value, char * const Output, DWORD * OutputSize);
159 #endif
160
161 using PathsParseFunc = void(*)(const char *);
162 void Paths_ParseSteamLibraryVDF(const char * fn, PathsParseFunc func);
163 void Paths_ParseXDGDesktopFile(const char * fn, PathsParseFunc func);
164 void Paths_ParseXDGDesktopFilesFromGOG(const char * homepath, const char * game, PathsParseFunc func);
165
166 #ifdef __cplusplus
167 }
168 #endif
169
170 #endif
171