Rev 3975 | Rev 4006 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2542 | helixhorne | 1 | // |
2 | // Common non-engine code/data for EDuke32 and Mapster32 |
||
3 | // |
||
4 | |||
5 | #include "compat.h" |
||
2726 | hendricks2 | 6 | #include "build.h" |
2549 | helixhorne | 7 | #include "scriptfile.h" |
2554 | helixhorne | 8 | #include "cache1d.h" |
9 | #include "kplib.h" |
||
10 | #include "baselayer.h" |
||
3220 | hendricks2 | 11 | #include "names.h" |
2542 | helixhorne | 12 | |
3581 | hendricks2 | 13 | #ifdef _WIN32 |
14 | # include "winbits.h" |
||
3671 | hendricks2 | 15 | # include <shlwapi.h> |
16 | # include <winnt.h> |
||
17 | # ifndef KEY_WOW64_32KEY |
||
18 | # define KEY_WOW64_32KEY 0x0200 |
||
19 | # endif |
||
3581 | hendricks2 | 20 | #endif |
21 | |||
2542 | helixhorne | 22 | #include "common.h" |
2726 | hendricks2 | 23 | #include "common_game.h" |
2542 | helixhorne | 24 | |
2789 | hendricks2 | 25 | int32_t g_gameType = GAMEFLAG_DUKE; |
2542 | helixhorne | 26 | |
2726 | hendricks2 | 27 | // grp/con/def handling |
28 | |||
2796 | helixhorne | 29 | const char *defaultgamegrp[GAMECOUNT] = { "DUKE3D.GRP", "NAM.GRP", "NAPALM.GRP", "WW2GI.GRP" }; |
30 | const char *defaultdeffilename[GAMECOUNT] = { "duke3d.def", "nam.def", "napalm.def", "ww2gi.def" }; |
||
31 | const char *defaultconfilename = "GAME.CON"; |
||
32 | const char *defaultgameconfilename[GAMECOUNT] = { "EDUKE.CON", "NAM.CON", "NAPALM.CON", "WW2GI.CON" }; |
||
2726 | hendricks2 | 33 | |
34 | // g_grpNamePtr can ONLY point to a malloc'd block (length BMAX_PATH) |
||
35 | char *g_grpNamePtr = NULL; |
||
36 | // g_defNamePtr can ONLY point to a malloc'd block (length BMAX_PATH) |
||
37 | char *g_defNamePtr = NULL; |
||
38 | // g_scriptNamePtr can ONLY point to a malloc'd block (length BMAX_PATH) |
||
39 | char *g_scriptNamePtr = NULL; |
||
40 | |||
41 | void clearGrpNamePtr(void) |
||
42 | { |
||
43 | if (g_grpNamePtr != NULL) |
||
44 | Bfree(g_grpNamePtr); |
||
45 | // g_grpNamePtr assumed to be assigned to right after |
||
46 | } |
||
47 | |||
48 | void clearDefNamePtr(void) |
||
49 | { |
||
50 | if (g_defNamePtr != NULL) |
||
51 | Bfree(g_defNamePtr); |
||
52 | // g_defNamePtr assumed to be assigned to right after |
||
53 | } |
||
54 | |||
55 | void clearScriptNamePtr(void) |
||
56 | { |
||
57 | if (g_scriptNamePtr != NULL) |
||
58 | Bfree(g_scriptNamePtr); |
||
59 | // g_scriptNamePtr assumed to be assigned to right after |
||
60 | } |
||
61 | |||
2796 | helixhorne | 62 | const char *G_DefaultGrpFile(void) |
2726 | hendricks2 | 63 | { |
64 | if (DUKE) |
||
65 | return defaultgamegrp[GAME_DUKE]; |
||
66 | // order is important for the following three because GAMEFLAG_NAM overlaps all |
||
67 | else if (NAPALM) |
||
68 | return defaultgamegrp[GAME_NAPALM]; |
||
69 | else if (WW2GI) |
||
70 | return defaultgamegrp[GAME_WW2GI]; |
||
71 | else if (NAM) |
||
72 | return defaultgamegrp[GAME_NAM]; |
||
73 | |||
74 | return defaultgamegrp[0]; |
||
75 | } |
||
2796 | helixhorne | 76 | const char *G_DefaultDefFile(void) |
2726 | hendricks2 | 77 | { |
78 | if (DUKE) |
||
79 | return defaultdeffilename[GAME_DUKE]; |
||
80 | else if (WW2GI) |
||
81 | return defaultdeffilename[GAME_WW2GI]; |
||
82 | else if (NAPALM) |
||
83 | { |
||
2752 | helixhorne | 84 | if (!testkopen(defaultdeffilename[GAME_NAPALM],0) && testkopen(defaultdeffilename[GAME_NAM],0)) |
3618 | hendricks2 | 85 | return defaultdeffilename[GAME_NAM]; // NAM/NAPALM Sharing |
2726 | hendricks2 | 86 | else |
87 | return defaultdeffilename[GAME_NAPALM]; |
||
88 | } |
||
89 | else if (NAM) |
||
90 | { |
||
2752 | helixhorne | 91 | if (!testkopen(defaultdeffilename[GAME_NAM],0) && testkopen(defaultdeffilename[GAME_NAPALM],0)) |
3618 | hendricks2 | 92 | return defaultdeffilename[GAME_NAPALM]; // NAM/NAPALM Sharing |
2726 | hendricks2 | 93 | else |
94 | return defaultdeffilename[GAME_NAM]; |
||
95 | } |
||
96 | |||
97 | return defaultdeffilename[0]; |
||
98 | } |
||
2796 | helixhorne | 99 | const char *G_DefaultConFile(void) |
2726 | hendricks2 | 100 | { |
2752 | helixhorne | 101 | if (DUKE && testkopen(defaultgameconfilename[GAME_DUKE],0)) |
2726 | hendricks2 | 102 | return defaultgameconfilename[GAME_DUKE]; |
2752 | helixhorne | 103 | else if (WW2GI && testkopen(defaultgameconfilename[GAME_WW2GI],0)) |
2726 | hendricks2 | 104 | return defaultgameconfilename[GAME_WW2GI]; |
105 | else if (NAPALM) |
||
106 | { |
||
2752 | helixhorne | 107 | if (!testkopen(defaultgameconfilename[GAME_NAPALM],0)) |
2726 | hendricks2 | 108 | { |
2752 | helixhorne | 109 | if (testkopen(defaultgameconfilename[GAME_NAM],0)) |
3618 | hendricks2 | 110 | return defaultgameconfilename[GAME_NAM]; // NAM/NAPALM Sharing |
2726 | hendricks2 | 111 | } |
112 | else |
||
113 | return defaultgameconfilename[GAME_NAPALM]; |
||
114 | } |
||
115 | else if (NAM) |
||
116 | { |
||
2752 | helixhorne | 117 | if (!testkopen(defaultgameconfilename[GAME_NAM],0)) |
2726 | hendricks2 | 118 | { |
2752 | helixhorne | 119 | if (testkopen(defaultgameconfilename[GAME_NAPALM],0)) |
3618 | hendricks2 | 120 | return defaultgameconfilename[GAME_NAPALM]; // NAM/NAPALM Sharing |
2726 | hendricks2 | 121 | } |
122 | else |
||
123 | return defaultgameconfilename[GAME_NAM]; |
||
124 | } |
||
125 | |||
126 | return defaultconfilename; |
||
127 | } |
||
128 | |||
2796 | helixhorne | 129 | const char *G_GrpFile(void) |
2726 | hendricks2 | 130 | { |
131 | if (g_grpNamePtr == NULL) |
||
132 | return G_DefaultGrpFile(); |
||
133 | else |
||
134 | return g_grpNamePtr; |
||
135 | } |
||
3654 | terminx | 136 | |
2796 | helixhorne | 137 | const char *G_DefFile(void) |
2726 | hendricks2 | 138 | { |
139 | if (g_defNamePtr == NULL) |
||
140 | return G_DefaultDefFile(); |
||
141 | else |
||
142 | return g_defNamePtr; |
||
143 | } |
||
3654 | terminx | 144 | |
2796 | helixhorne | 145 | const char *G_ConFile(void) |
2726 | hendricks2 | 146 | { |
147 | if (g_scriptNamePtr == NULL) |
||
148 | return G_DefaultConFile(); |
||
149 | else |
||
150 | return g_scriptNamePtr; |
||
151 | } |
||
152 | |||
153 | ////////// |
||
154 | |||
3976 | helixhorne | 155 | #define NUMPSKYMULTIS 5 |
156 | EDUKE32_STATIC_ASSERT(NUMPSKYMULTIS <= MAXPSKYMULTIS); |
||
157 | EDUKE32_STATIC_ASSERT(PSKYOFF_MAX <= MAXPSKYTILES); |
||
158 | |||
3975 | helixhorne | 159 | // Set up new-style multi-psky handling. |
3976 | helixhorne | 160 | // KEEPINSYNC MultiPsky_TileToIdx(). |
161 | void G_InitMultiPsky(int32_t CLOUDYOCEAN__DYN, int32_t MOONSKY1__DYN, int32_t BIGORBIT1__DYN, int32_t LA__DYN) |
||
3220 | hendricks2 | 162 | { |
163 | int32_t i; |
||
164 | |||
3976 | helixhorne | 165 | psky_t *defaultsky = &multipsky[0]; |
166 | psky_t *oceansky = &multipsky[1]; |
||
167 | psky_t *moonsky = &multipsky[2]; |
||
168 | psky_t *spacesky = &multipsky[3]; |
||
169 | psky_t *citysky = &multipsky[4]; |
||
3220 | hendricks2 | 170 | |
3975 | helixhorne | 171 | static int32_t inited; |
172 | if (inited) |
||
173 | return; |
||
174 | inited = 1; |
||
3220 | hendricks2 | 175 | |
3976 | helixhorne | 176 | multipskytile[0] = -1; |
177 | multipskytile[1] = CLOUDYOCEAN__DYN; |
||
178 | multipskytile[2] = MOONSKY1__DYN; |
||
179 | multipskytile[3] = BIGORBIT1__DYN; |
||
180 | multipskytile[4] = LA__DYN; |
||
3220 | hendricks2 | 181 | |
3976 | helixhorne | 182 | pskynummultis = NUMPSKYMULTIS; |
3220 | hendricks2 | 183 | |
3975 | helixhorne | 184 | // When adding other multi-skies, take care that the tileofs[] values are |
185 | // <= PSKYOFF_MAX. (It can be increased up to MAXPSKYTILES, but should be |
||
186 | // set as tight as possible.) |
||
187 | |||
3976 | helixhorne | 188 | // The default sky properties (all others are implicitly zero): |
189 | defaultsky->lognumtiles = 3; |
||
190 | defaultsky->horizfrac = 32768; |
||
191 | |||
192 | // CLOUDYOCEAN |
||
193 | // Aligns with the drawn scene horizon because it has one itself. |
||
194 | oceansky->lognumtiles = 3; |
||
195 | oceansky->horizfrac = 65536; |
||
196 | |||
3220 | hendricks2 | 197 | // MOONSKY1 |
198 | // earth mountain mountain sun |
||
3975 | helixhorne | 199 | moonsky->lognumtiles = 3; |
200 | moonsky->horizfrac = 32768; |
||
201 | moonsky->tileofs[6] = 1; |
||
202 | moonsky->tileofs[1] = 2; |
||
203 | moonsky->tileofs[4] = 2; |
||
204 | moonsky->tileofs[2] = 3; |
||
3220 | hendricks2 | 205 | |
206 | // BIGORBIT1 // orbit |
||
207 | // earth1 2 3 moon/sun |
||
3975 | helixhorne | 208 | spacesky->lognumtiles = 3; |
209 | spacesky->horizfrac = 32768; |
||
210 | spacesky->tileofs[5] = 1; |
||
211 | spacesky->tileofs[6] = 2; |
||
212 | spacesky->tileofs[7] = 3; |
||
213 | spacesky->tileofs[2] = 4; |
||
3220 | hendricks2 | 214 | |
215 | // LA // la city |
||
216 | // earth1 2 3 moon/sun |
||
3975 | helixhorne | 217 | citysky->lognumtiles = 3; |
218 | citysky->horizfrac = 16384+1024; |
||
219 | citysky->tileofs[0] = 1; |
||
220 | citysky->tileofs[1] = 2; |
||
221 | citysky->tileofs[2] = 1; |
||
222 | citysky->tileofs[3] = 3; |
||
223 | citysky->tileofs[4] = 4; |
||
224 | citysky->tileofs[5] = 0; |
||
225 | citysky->tileofs[6] = 2; |
||
226 | citysky->tileofs[7] = 3; |
||
3220 | hendricks2 | 227 | |
3975 | helixhorne | 228 | for (i=0; i<pskynummultis; ++i) |
229 | { |
||
230 | int32_t j; |
||
231 | for (j=0; j<(1<<multipsky[i].lognumtiles); ++j) |
||
232 | Bassert(multipsky[i].tileofs[j] <= PSKYOFF_MAX); |
||
233 | } |
||
3976 | helixhorne | 234 | } |
3220 | hendricks2 | 235 | |
3976 | helixhorne | 236 | void G_SetupGlobalPsky(void) |
237 | { |
||
238 | int32_t i, mskyidx=0; |
||
239 | |||
240 | // NOTE: Loop must be running backwards for the same behavior as the game |
||
241 | // (greatest sector index with matching parallaxed sky takes precedence). |
||
242 | for (i=numsectors-1; i>=0; i--) |
||
243 | { |
||
244 | if (sector[i].ceilingstat & 1) |
||
245 | { |
||
246 | mskyidx = MultiPsky_TileToIdx(sector[i].ceilingpicnum); |
||
247 | if (mskyidx > 0) |
||
248 | break; |
||
249 | } |
||
250 | } |
||
251 | |||
252 | g_pskyidx = mskyidx; |
||
3220 | hendricks2 | 253 | } |
254 | |||
255 | ////////// |
||
256 | |||
3582 | hendricks2 | 257 | #ifdef GEKKO |
258 | #include "gctypes.h" // for bool |
||
259 | void L2Enhance(); |
||
260 | void CON_EnableGecko(int channel,int safe); |
||
261 | bool fatInit (uint32_t cacheSize, bool setAsDefaultDevice); |
||
262 | #endif |
||
263 | |||
264 | void G_ExtPreInit(void) |
||
265 | { |
||
266 | #ifdef GEKKO |
||
267 | L2Enhance(); |
||
268 | CON_EnableGecko(1, 1); |
||
269 | Bprintf("Console started\n"); |
||
270 | fatInit(28, true); |
||
271 | #endif |
||
272 | } |
||
273 | |||
3622 | terminx | 274 | #ifdef _WIN32 |
3637 | terminx | 275 | const char * G_GetInstallPath(int32_t insttype) |
3622 | terminx | 276 | { |
3637 | terminx | 277 | static char spath[NUMINSTPATHS][BMAX_PATH]; |
278 | static int32_t success[NUMINSTPATHS] = { -1, -1 }; |
||
3622 | terminx | 279 | int32_t siz = BMAX_PATH; |
280 | |||
3637 | terminx | 281 | if (success[insttype] == -1) |
282 | { |
||
3671 | hendricks2 | 283 | HKEY HKLM32; |
284 | LONG keygood = RegOpenKeyEx(HKEY_LOCAL_MACHINE, NULL, 0, KEY_READ | KEY_WOW64_32KEY, &HKLM32); |
||
285 | // KEY_WOW64_32KEY gets us around Wow6432Node on 64-bit builds |
||
286 | |||
287 | if (keygood == ERROR_SUCCESS) |
||
288 | switch (insttype) |
||
289 | { |
||
290 | case INSTPATH_STEAM: |
||
291 | success[insttype] = SHGetValueA(HKLM32, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Steam App 225140", "InstallLocation", NULL, spath[insttype], (LPDWORD)&siz); |
||
292 | break; |
||
293 | case INSTPATH_GOG: |
||
294 | success[insttype] = SHGetValueA(HKLM32, "SOFTWARE\\GOG.com\\GOGDUKE3D", "PATH", NULL, spath[insttype], (LPDWORD)&siz); |
||
295 | break; |
||
296 | } |
||
3637 | terminx | 297 | } |
3622 | terminx | 298 | |
3637 | terminx | 299 | if (success[insttype] == ERROR_SUCCESS) |
300 | return spath[insttype]; |
||
3622 | terminx | 301 | |
302 | return NULL; |
||
303 | } |
||
304 | #endif |
||
305 | |||
3581 | hendricks2 | 306 | void G_AddSearchPaths(void) |
307 | { |
||
308 | #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) |
||
309 | addsearchpath("/usr/share/games/jfduke3d"); |
||
310 | addsearchpath("/usr/local/share/games/jfduke3d"); |
||
311 | addsearchpath("/usr/share/games/eduke32"); |
||
312 | addsearchpath("/usr/local/share/games/eduke32"); |
||
313 | #elif defined(__APPLE__) |
||
314 | addsearchpath("/Library/Application Support/JFDuke3D"); |
||
315 | addsearchpath("/Library/Application Support/EDuke32"); |
||
316 | #elif defined (_WIN32) |
||
3615 | terminx | 317 | // detect Steam and GOG versions of Duke3D |
318 | char buf[BMAX_PATH]; |
||
3671 | hendricks2 | 319 | const char* instpath; |
3615 | terminx | 320 | |
3671 | hendricks2 | 321 | if ((instpath = G_GetInstallPath(INSTPATH_STEAM))) |
3622 | terminx | 322 | { |
3671 | hendricks2 | 323 | Bsprintf(buf, "%s/gameroot", instpath); |
3622 | terminx | 324 | addsearchpath(buf); |
3615 | terminx | 325 | |
3671 | hendricks2 | 326 | Bsprintf(buf, "%s/gameroot/addons", instpath); |
3622 | terminx | 327 | addsearchpath(buf); |
3615 | terminx | 328 | } |
329 | |||
3671 | hendricks2 | 330 | if ((instpath = G_GetInstallPath(INSTPATH_GOG))) |
331 | addsearchpath(instpath); |
||
3581 | hendricks2 | 332 | #endif |
333 | } |
||
334 | |||
3654 | terminx | 335 | void G_CleanupSearchPaths(void) |
336 | { |
||
337 | #ifdef _WIN32 |
||
338 | char buf[BMAX_PATH]; |
||
3671 | hendricks2 | 339 | const char* instpath; |
3654 | terminx | 340 | |
3671 | hendricks2 | 341 | if ((instpath = G_GetInstallPath(INSTPATH_STEAM))) |
3654 | terminx | 342 | { |
3671 | hendricks2 | 343 | Bsprintf(buf, "%s/gameroot", instpath); |
3654 | terminx | 344 | removesearchpath(buf); |
345 | |||
3671 | hendricks2 | 346 | Bsprintf(buf, "%s/gameroot/addons", instpath); |
3654 | terminx | 347 | removesearchpath(buf); |
348 | } |
||
349 | |||
3671 | hendricks2 | 350 | if ((instpath = G_GetInstallPath(INSTPATH_GOG))) |
351 | removesearchpath(instpath); |
||
3654 | terminx | 352 | #endif |
353 | } |
||
354 | |||
3581 | hendricks2 | 355 | ////////// |
356 | |||
2542 | helixhorne | 357 | struct strllist *CommandPaths, *CommandGrps; |
358 | |||
359 | void G_AddGroup(const char *buffer) |
||
360 | { |
||
361 | char buf[BMAX_PATH]; |
||
362 | |||
3176 | helixhorne | 363 | struct strllist *s = (struct strllist *)Bcalloc(1,sizeof(struct strllist)); |
2542 | helixhorne | 364 | |
365 | Bstrcpy(buf, buffer); |
||
366 | |||
367 | if (Bstrchr(buf,'.') == 0) |
||
368 | Bstrcat(buf,".grp"); |
||
369 | |||
370 | s->str = Bstrdup(buf); |
||
371 | |||
372 | if (CommandGrps) |
||
373 | { |
||
374 | struct strllist *t; |
||
375 | for (t = CommandGrps; t->next; t=t->next) ; |
||
376 | t->next = s; |
||
377 | return; |
||
378 | } |
||
379 | CommandGrps = s; |
||
380 | } |
||
381 | |||
382 | void G_AddPath(const char *buffer) |
||
383 | { |
||
3176 | helixhorne | 384 | struct strllist *s = (struct strllist *)Bcalloc(1,sizeof(struct strllist)); |
2542 | helixhorne | 385 | s->str = Bstrdup(buffer); |
386 | |||
387 | if (CommandPaths) |
||
388 | { |
||
389 | struct strllist *t; |
||
390 | for (t = CommandPaths; t->next; t=t->next) ; |
||
391 | t->next = s; |
||
392 | return; |
||
393 | } |
||
394 | CommandPaths = s; |
||
395 | } |
||
2549 | helixhorne | 396 | |
397 | ////////// |
||
398 | |||
399 | int32_t getatoken(scriptfile *sf, const tokenlist *tl, int32_t ntokens) |
||
400 | { |
||
401 | char *tok; |
||
402 | int32_t i; |
||
403 | |||
404 | if (!sf) return T_ERROR; |
||
405 | tok = scriptfile_gettoken(sf); |
||
406 | if (!tok) return T_EOF; |
||
407 | |||
408 | for (i=ntokens-1; i>=0; i--) |
||
409 | { |
||
410 | if (!Bstrcasecmp(tok, tl[i].text)) |
||
411 | return tl[i].tokenid; |
||
412 | } |
||
413 | return T_ERROR; |
||
414 | } |
||
2554 | helixhorne | 415 | |
416 | ////////// |
||
417 | |||
2752 | helixhorne | 418 | // returns: 1 if file could be opened, 0 else |
419 | int32_t testkopen(const char *filename, char searchfirst) |
||
420 | { |
||
421 | int32_t fd = kopen4load(filename, searchfirst); |
||
422 | if (fd >= 0) |
||
423 | kclose(fd); |
||
424 | return (fd >= 0); |
||
425 | } |
||
426 | |||
2554 | helixhorne | 427 | // checks from path and in ZIPs, returns 1 if NOT found |
428 | int32_t check_file_exist(const char *fn) |
||
429 | { |
||
430 | int32_t opsm = pathsearchmode; |
||
431 | char *tfn; |
||
432 | |||
433 | pathsearchmode = 1; |
||
434 | if (findfrompath(fn,&tfn) < 0) |
||
435 | { |
||
436 | char buf[BMAX_PATH]; |
||
437 | |||
438 | Bstrcpy(buf,fn); |
||
439 | kzfindfilestart(buf); |
||
440 | if (!kzfindfile(buf)) |
||
441 | { |
||
442 | initprintf("Error: file \"%s\" does not exist\n",fn); |
||
443 | pathsearchmode = opsm; |
||
444 | return 1; |
||
445 | } |
||
446 | } |
||
447 | else Bfree(tfn); |
||
448 | pathsearchmode = opsm; |
||
449 | |||
450 | return 0; |
||
451 | } |
||
2555 | helixhorne | 452 | |
453 | |||
454 | //// FILE NAME / DIRECTORY LISTS //// |
||
455 | void fnlist_clearnames(fnlist_t *fnl) |
||
456 | { |
||
457 | klistfree(fnl->finddirs); |
||
458 | klistfree(fnl->findfiles); |
||
459 | |||
460 | fnl->finddirs = fnl->findfiles = NULL; |
||
461 | fnl->numfiles = fnl->numdirs = 0; |
||
462 | } |
||
463 | |||
464 | // dirflags, fileflags: |
||
465 | // -1 means "don't get dirs/files", |
||
466 | // otherwise ORed to flags for respective klistpath |
||
467 | int32_t fnlist_getnames(fnlist_t *fnl, const char *dirname, const char *pattern, |
||
468 | int32_t dirflags, int32_t fileflags) |
||
469 | { |
||
470 | CACHE1D_FIND_REC *r; |
||
471 | |||
472 | fnlist_clearnames(fnl); |
||
473 | |||
474 | if (dirflags != -1) |
||
475 | fnl->finddirs = klistpath(dirname, "*", CACHE1D_FIND_DIR|dirflags); |
||
476 | if (fileflags != -1) |
||
477 | fnl->findfiles = klistpath(dirname, pattern, CACHE1D_FIND_FILE|fileflags); |
||
478 | |||
479 | for (r=fnl->finddirs; r; r=r->next) |
||
480 | fnl->numdirs++; |
||
481 | for (r=fnl->findfiles; r; r=r->next) |
||
482 | fnl->numfiles++; |
||
483 | |||
484 | return(0); |
||
485 | } |
||
486 | |||
487 | |||
3269 | terminx | 488 | // loads all group (grp, zip, pk3/4) files in the given directory |
2555 | helixhorne | 489 | void G_LoadGroupsInDir(const char *dirname) |
490 | { |
||
3269 | terminx | 491 | static const char *extensions[4] = { "*.grp", "*.zip", "*.pk3", "*.pk4" }; |
2555 | helixhorne | 492 | |
493 | char buf[BMAX_PATH]; |
||
494 | int32_t i; |
||
495 | |||
496 | fnlist_t fnlist = FNLIST_INITIALIZER; |
||
497 | |||
3269 | terminx | 498 | for (i=0; i<4; i++) |
2555 | helixhorne | 499 | { |
500 | CACHE1D_FIND_REC *rec; |
||
501 | |||
502 | fnlist_getnames(&fnlist, dirname, extensions[i], -1, 0); |
||
503 | |||
504 | for (rec=fnlist.findfiles; rec; rec=rec->next) |
||
505 | { |
||
506 | Bsnprintf(buf, sizeof(buf), "%s/%s", dirname, rec->name); |
||
507 | initprintf("Using group file \"%s\".\n", buf); |
||
508 | initgroupfile(buf); |
||
509 | } |
||
510 | |||
511 | fnlist_clearnames(&fnlist); |
||
512 | } |
||
513 | } |
||
514 | |||
515 | void G_DoAutoload(const char *dirname) |
||
516 | { |
||
517 | char buf[BMAX_PATH]; |
||
518 | |||
519 | Bsnprintf(buf, sizeof(buf), "autoload/%s", dirname); |
||
520 | G_LoadGroupsInDir(buf); |
||
521 | } |
||
2560 | helixhorne | 522 | |
523 | //// |
||
524 | |||
525 | // returns a buffer of size BMAX_PATH |
||
526 | char *dup_filename(const char *fn) |
||
527 | { |
||
3176 | helixhorne | 528 | char *buf = (char *)Bmalloc(BMAX_PATH); |
2560 | helixhorne | 529 | |
530 | return Bstrncpyz(buf, fn, BMAX_PATH); |
||
531 | } |
||
3004 | helixhorne | 532 | |
533 | |||
534 | // Copy FN to WBUF and append an extension if it's not there, which is checked |
||
535 | // case-insensitively. |
||
536 | // Returns: 1 if not all characters could be written to WBUF, 0 else. |
||
537 | int32_t maybe_append_ext(char *wbuf, int32_t wbufsiz, const char *fn, const char *ext) |
||
538 | { |
||
539 | const int32_t slen=Bstrlen(fn), extslen=Bstrlen(ext); |
||
540 | const int32_t haveext = (slen>=extslen && Bstrcasecmp(&fn[slen-extslen], ext)==0); |
||
541 | |||
542 | Bassert((intptr_t)wbuf != (intptr_t)fn); // no aliasing |
||
543 | |||
544 | // If 'fn' has no extension suffixed, append one. |
||
545 | return (Bsnprintf(wbuf, wbufsiz, "%s%s", fn, haveext ? "" : ext) >= wbufsiz); |
||
546 | } |
||
3243 | helixhorne | 547 | |
548 | |||
3489 | helixhorne | 549 | // Approximations to 2D and 3D Euclidean distances. Initial EDuke32 SVN import says |
3243 | helixhorne | 550 | // in jmact/mathutil.c: "Ken's reverse-engineering job". |
551 | // Note that jmact/mathutil.c contains practically the same code, but where the |
||
552 | // individual x/y(/z) distances are passed instead. |
||
553 | int32_t ldist(const spritetype *s1, const spritetype *s2) |
||
554 | { |
||
555 | int32_t x = klabs(s1->x-s2->x); |
||
556 | int32_t y = klabs(s1->y-s2->y); |
||
557 | |||
558 | if (x<y) swaplong(&x,&y); |
||
559 | |||
560 | { |
||
561 | int32_t t = y + (y>>1); |
||
562 | return (x - (x>>5) - (x>>7) + (t>>2) + (t>>6)); |
||
563 | } |
||
564 | } |
||
565 | |||
566 | int32_t dist(const spritetype *s1, const spritetype *s2) |
||
567 | { |
||
568 | int32_t x = klabs(s1->x-s2->x); |
||
569 | int32_t y = klabs(s1->y-s2->y); |
||
570 | int32_t z = klabs((s1->z-s2->z)>>4); |
||
571 | |||
572 | if (x<y) swaplong(&x,&y); |
||
573 | if (x<z) swaplong(&x,&z); |
||
574 | |||
575 | { |
||
576 | int32_t t = y + z; |
||
577 | return (x - (x>>4) + (t>>2) + (t>>3)); |
||
578 | } |
||
579 | } |
||
3321 | helixhorne | 580 | |
581 | |||
582 | // Clear OSD background |
||
583 | void COMMON_clearbackground(int32_t numcols, int32_t numrows) |
||
584 | { |
||
585 | UNREFERENCED_PARAMETER(numcols); |
||
586 | |||
587 | # ifdef USE_OPENGL |
||
3784 | terminx | 588 | if (getrendermode() >= REND_POLYMOST && qsetmode==200) |
3321 | helixhorne | 589 | { |
590 | setpolymost2dview(); |
||
591 | bglColor4f(0,0,0,0.67f); |
||
592 | bglEnable(GL_BLEND); |
||
593 | bglRectd(0,0, xdim,8*numrows+8); |
||
594 | bglColor4f(0,0,0,1); |
||
595 | bglRectd(0,8*numrows+4, xdim,8*numrows+8); |
||
596 | return; |
||
597 | } |
||
598 | # endif |
||
599 | |||
600 | CLEARLINES2D(0, min(ydim, numrows*8+8), editorcolors[16]); |
||
601 | } |