Rev 3976 | Rev 4127 | 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 | void G_InitMultiPsky(int32_t CLOUDYOCEAN__DYN, int32_t MOONSKY1__DYN, int32_t BIGORBIT1__DYN, int32_t LA__DYN) |
3220 | hendricks2 | 161 | { |
162 | int32_t i; |
||
163 | |||
3976 | helixhorne | 164 | psky_t *defaultsky = &multipsky[0]; |
165 | psky_t *oceansky = &multipsky[1]; |
||
166 | psky_t *moonsky = &multipsky[2]; |
||
167 | psky_t *spacesky = &multipsky[3]; |
||
168 | psky_t *citysky = &multipsky[4]; |
||
3220 | hendricks2 | 169 | |
3975 | helixhorne | 170 | static int32_t inited; |
171 | if (inited) |
||
172 | return; |
||
173 | inited = 1; |
||
3220 | hendricks2 | 174 | |
3976 | helixhorne | 175 | multipskytile[0] = -1; |
176 | multipskytile[1] = CLOUDYOCEAN__DYN; |
||
177 | multipskytile[2] = MOONSKY1__DYN; |
||
178 | multipskytile[3] = BIGORBIT1__DYN; |
||
179 | multipskytile[4] = LA__DYN; |
||
3220 | hendricks2 | 180 | |
3976 | helixhorne | 181 | pskynummultis = NUMPSKYMULTIS; |
3220 | hendricks2 | 182 | |
3975 | helixhorne | 183 | // When adding other multi-skies, take care that the tileofs[] values are |
184 | // <= PSKYOFF_MAX. (It can be increased up to MAXPSKYTILES, but should be |
||
185 | // set as tight as possible.) |
||
186 | |||
3976 | helixhorne | 187 | // The default sky properties (all others are implicitly zero): |
188 | defaultsky->lognumtiles = 3; |
||
189 | defaultsky->horizfrac = 32768; |
||
190 | |||
191 | // CLOUDYOCEAN |
||
192 | // Aligns with the drawn scene horizon because it has one itself. |
||
193 | oceansky->lognumtiles = 3; |
||
194 | oceansky->horizfrac = 65536; |
||
195 | |||
3220 | hendricks2 | 196 | // MOONSKY1 |
197 | // earth mountain mountain sun |
||
3975 | helixhorne | 198 | moonsky->lognumtiles = 3; |
199 | moonsky->horizfrac = 32768; |
||
200 | moonsky->tileofs[6] = 1; |
||
201 | moonsky->tileofs[1] = 2; |
||
202 | moonsky->tileofs[4] = 2; |
||
203 | moonsky->tileofs[2] = 3; |
||
3220 | hendricks2 | 204 | |
205 | // BIGORBIT1 // orbit |
||
206 | // earth1 2 3 moon/sun |
||
3975 | helixhorne | 207 | spacesky->lognumtiles = 3; |
208 | spacesky->horizfrac = 32768; |
||
209 | spacesky->tileofs[5] = 1; |
||
210 | spacesky->tileofs[6] = 2; |
||
211 | spacesky->tileofs[7] = 3; |
||
212 | spacesky->tileofs[2] = 4; |
||
3220 | hendricks2 | 213 | |
214 | // LA // la city |
||
215 | // earth1 2 3 moon/sun |
||
3975 | helixhorne | 216 | citysky->lognumtiles = 3; |
217 | citysky->horizfrac = 16384+1024; |
||
218 | citysky->tileofs[0] = 1; |
||
219 | citysky->tileofs[1] = 2; |
||
220 | citysky->tileofs[2] = 1; |
||
221 | citysky->tileofs[3] = 3; |
||
222 | citysky->tileofs[4] = 4; |
||
223 | citysky->tileofs[5] = 0; |
||
224 | citysky->tileofs[6] = 2; |
||
225 | citysky->tileofs[7] = 3; |
||
3220 | hendricks2 | 226 | |
3975 | helixhorne | 227 | for (i=0; i<pskynummultis; ++i) |
228 | { |
||
229 | int32_t j; |
||
230 | for (j=0; j<(1<<multipsky[i].lognumtiles); ++j) |
||
231 | Bassert(multipsky[i].tileofs[j] <= PSKYOFF_MAX); |
||
232 | } |
||
3976 | helixhorne | 233 | } |
3220 | hendricks2 | 234 | |
3976 | helixhorne | 235 | void G_SetupGlobalPsky(void) |
236 | { |
||
237 | int32_t i, mskyidx=0; |
||
238 | |||
239 | // NOTE: Loop must be running backwards for the same behavior as the game |
||
240 | // (greatest sector index with matching parallaxed sky takes precedence). |
||
241 | for (i=numsectors-1; i>=0; i--) |
||
242 | { |
||
243 | if (sector[i].ceilingstat & 1) |
||
244 | { |
||
4006 | helixhorne | 245 | mskyidx = getpskyidx(sector[i].ceilingpicnum); |
3976 | helixhorne | 246 | if (mskyidx > 0) |
247 | break; |
||
248 | } |
||
249 | } |
||
250 | |||
251 | g_pskyidx = mskyidx; |
||
3220 | hendricks2 | 252 | } |
253 | |||
254 | ////////// |
||
255 | |||
3582 | hendricks2 | 256 | #ifdef GEKKO |
257 | #include "gctypes.h" // for bool |
||
258 | void L2Enhance(); |
||
259 | void CON_EnableGecko(int channel,int safe); |
||
260 | bool fatInit (uint32_t cacheSize, bool setAsDefaultDevice); |
||
261 | #endif |
||
262 | |||
263 | void G_ExtPreInit(void) |
||
264 | { |
||
265 | #ifdef GEKKO |
||
266 | L2Enhance(); |
||
267 | CON_EnableGecko(1, 1); |
||
268 | Bprintf("Console started\n"); |
||
269 | fatInit(28, true); |
||
270 | #endif |
||
271 | } |
||
272 | |||
3622 | terminx | 273 | #ifdef _WIN32 |
3637 | terminx | 274 | const char * G_GetInstallPath(int32_t insttype) |
3622 | terminx | 275 | { |
3637 | terminx | 276 | static char spath[NUMINSTPATHS][BMAX_PATH]; |
277 | static int32_t success[NUMINSTPATHS] = { -1, -1 }; |
||
3622 | terminx | 278 | int32_t siz = BMAX_PATH; |
279 | |||
3637 | terminx | 280 | if (success[insttype] == -1) |
281 | { |
||
3671 | hendricks2 | 282 | HKEY HKLM32; |
283 | LONG keygood = RegOpenKeyEx(HKEY_LOCAL_MACHINE, NULL, 0, KEY_READ | KEY_WOW64_32KEY, &HKLM32); |
||
284 | // KEY_WOW64_32KEY gets us around Wow6432Node on 64-bit builds |
||
285 | |||
286 | if (keygood == ERROR_SUCCESS) |
||
287 | switch (insttype) |
||
288 | { |
||
289 | case INSTPATH_STEAM: |
||
290 | success[insttype] = SHGetValueA(HKLM32, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Steam App 225140", "InstallLocation", NULL, spath[insttype], (LPDWORD)&siz); |
||
291 | break; |
||
292 | case INSTPATH_GOG: |
||
293 | success[insttype] = SHGetValueA(HKLM32, "SOFTWARE\\GOG.com\\GOGDUKE3D", "PATH", NULL, spath[insttype], (LPDWORD)&siz); |
||
294 | break; |
||
295 | } |
||
3637 | terminx | 296 | } |
3622 | terminx | 297 | |
3637 | terminx | 298 | if (success[insttype] == ERROR_SUCCESS) |
299 | return spath[insttype]; |
||
3622 | terminx | 300 | |
301 | return NULL; |
||
302 | } |
||
303 | #endif |
||
304 | |||
3581 | hendricks2 | 305 | void G_AddSearchPaths(void) |
306 | { |
||
307 | #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) |
||
308 | addsearchpath("/usr/share/games/jfduke3d"); |
||
309 | addsearchpath("/usr/local/share/games/jfduke3d"); |
||
310 | addsearchpath("/usr/share/games/eduke32"); |
||
311 | addsearchpath("/usr/local/share/games/eduke32"); |
||
312 | #elif defined(__APPLE__) |
||
313 | addsearchpath("/Library/Application Support/JFDuke3D"); |
||
314 | addsearchpath("/Library/Application Support/EDuke32"); |
||
315 | #elif defined (_WIN32) |
||
3615 | terminx | 316 | // detect Steam and GOG versions of Duke3D |
317 | char buf[BMAX_PATH]; |
||
3671 | hendricks2 | 318 | const char* instpath; |
3615 | terminx | 319 | |
3671 | hendricks2 | 320 | if ((instpath = G_GetInstallPath(INSTPATH_STEAM))) |
3622 | terminx | 321 | { |
3671 | hendricks2 | 322 | Bsprintf(buf, "%s/gameroot", instpath); |
3622 | terminx | 323 | addsearchpath(buf); |
3615 | terminx | 324 | |
3671 | hendricks2 | 325 | Bsprintf(buf, "%s/gameroot/addons", instpath); |
3622 | terminx | 326 | addsearchpath(buf); |
3615 | terminx | 327 | } |
328 | |||
3671 | hendricks2 | 329 | if ((instpath = G_GetInstallPath(INSTPATH_GOG))) |
330 | addsearchpath(instpath); |
||
3581 | hendricks2 | 331 | #endif |
332 | } |
||
333 | |||
3654 | terminx | 334 | void G_CleanupSearchPaths(void) |
335 | { |
||
336 | #ifdef _WIN32 |
||
337 | char buf[BMAX_PATH]; |
||
3671 | hendricks2 | 338 | const char* instpath; |
3654 | terminx | 339 | |
3671 | hendricks2 | 340 | if ((instpath = G_GetInstallPath(INSTPATH_STEAM))) |
3654 | terminx | 341 | { |
3671 | hendricks2 | 342 | Bsprintf(buf, "%s/gameroot", instpath); |
3654 | terminx | 343 | removesearchpath(buf); |
344 | |||
3671 | hendricks2 | 345 | Bsprintf(buf, "%s/gameroot/addons", instpath); |
3654 | terminx | 346 | removesearchpath(buf); |
347 | } |
||
348 | |||
3671 | hendricks2 | 349 | if ((instpath = G_GetInstallPath(INSTPATH_GOG))) |
350 | removesearchpath(instpath); |
||
3654 | terminx | 351 | #endif |
352 | } |
||
353 | |||
3581 | hendricks2 | 354 | ////////// |
355 | |||
2542 | helixhorne | 356 | struct strllist *CommandPaths, *CommandGrps; |
357 | |||
358 | void G_AddGroup(const char *buffer) |
||
359 | { |
||
360 | char buf[BMAX_PATH]; |
||
361 | |||
3176 | helixhorne | 362 | struct strllist *s = (struct strllist *)Bcalloc(1,sizeof(struct strllist)); |
2542 | helixhorne | 363 | |
364 | Bstrcpy(buf, buffer); |
||
365 | |||
366 | if (Bstrchr(buf,'.') == 0) |
||
367 | Bstrcat(buf,".grp"); |
||
368 | |||
369 | s->str = Bstrdup(buf); |
||
370 | |||
371 | if (CommandGrps) |
||
372 | { |
||
373 | struct strllist *t; |
||
374 | for (t = CommandGrps; t->next; t=t->next) ; |
||
375 | t->next = s; |
||
376 | return; |
||
377 | } |
||
378 | CommandGrps = s; |
||
379 | } |
||
380 | |||
381 | void G_AddPath(const char *buffer) |
||
382 | { |
||
3176 | helixhorne | 383 | struct strllist *s = (struct strllist *)Bcalloc(1,sizeof(struct strllist)); |
2542 | helixhorne | 384 | s->str = Bstrdup(buffer); |
385 | |||
386 | if (CommandPaths) |
||
387 | { |
||
388 | struct strllist *t; |
||
389 | for (t = CommandPaths; t->next; t=t->next) ; |
||
390 | t->next = s; |
||
391 | return; |
||
392 | } |
||
393 | CommandPaths = s; |
||
394 | } |
||
2549 | helixhorne | 395 | |
396 | ////////// |
||
397 | |||
398 | int32_t getatoken(scriptfile *sf, const tokenlist *tl, int32_t ntokens) |
||
399 | { |
||
400 | char *tok; |
||
401 | int32_t i; |
||
402 | |||
403 | if (!sf) return T_ERROR; |
||
404 | tok = scriptfile_gettoken(sf); |
||
405 | if (!tok) return T_EOF; |
||
406 | |||
407 | for (i=ntokens-1; i>=0; i--) |
||
408 | { |
||
409 | if (!Bstrcasecmp(tok, tl[i].text)) |
||
410 | return tl[i].tokenid; |
||
411 | } |
||
412 | return T_ERROR; |
||
413 | } |
||
2554 | helixhorne | 414 | |
415 | ////////// |
||
416 | |||
2752 | helixhorne | 417 | // returns: 1 if file could be opened, 0 else |
418 | int32_t testkopen(const char *filename, char searchfirst) |
||
419 | { |
||
420 | int32_t fd = kopen4load(filename, searchfirst); |
||
421 | if (fd >= 0) |
||
422 | kclose(fd); |
||
423 | return (fd >= 0); |
||
424 | } |
||
425 | |||
2554 | helixhorne | 426 | // checks from path and in ZIPs, returns 1 if NOT found |
427 | int32_t check_file_exist(const char *fn) |
||
428 | { |
||
429 | int32_t opsm = pathsearchmode; |
||
430 | char *tfn; |
||
431 | |||
432 | pathsearchmode = 1; |
||
433 | if (findfrompath(fn,&tfn) < 0) |
||
434 | { |
||
435 | char buf[BMAX_PATH]; |
||
436 | |||
437 | Bstrcpy(buf,fn); |
||
438 | kzfindfilestart(buf); |
||
439 | if (!kzfindfile(buf)) |
||
440 | { |
||
441 | initprintf("Error: file \"%s\" does not exist\n",fn); |
||
442 | pathsearchmode = opsm; |
||
443 | return 1; |
||
444 | } |
||
445 | } |
||
446 | else Bfree(tfn); |
||
447 | pathsearchmode = opsm; |
||
448 | |||
449 | return 0; |
||
450 | } |
||
2555 | helixhorne | 451 | |
452 | |||
453 | //// FILE NAME / DIRECTORY LISTS //// |
||
454 | void fnlist_clearnames(fnlist_t *fnl) |
||
455 | { |
||
456 | klistfree(fnl->finddirs); |
||
457 | klistfree(fnl->findfiles); |
||
458 | |||
459 | fnl->finddirs = fnl->findfiles = NULL; |
||
460 | fnl->numfiles = fnl->numdirs = 0; |
||
461 | } |
||
462 | |||
463 | // dirflags, fileflags: |
||
464 | // -1 means "don't get dirs/files", |
||
465 | // otherwise ORed to flags for respective klistpath |
||
466 | int32_t fnlist_getnames(fnlist_t *fnl, const char *dirname, const char *pattern, |
||
467 | int32_t dirflags, int32_t fileflags) |
||
468 | { |
||
469 | CACHE1D_FIND_REC *r; |
||
470 | |||
471 | fnlist_clearnames(fnl); |
||
472 | |||
473 | if (dirflags != -1) |
||
474 | fnl->finddirs = klistpath(dirname, "*", CACHE1D_FIND_DIR|dirflags); |
||
475 | if (fileflags != -1) |
||
476 | fnl->findfiles = klistpath(dirname, pattern, CACHE1D_FIND_FILE|fileflags); |
||
477 | |||
478 | for (r=fnl->finddirs; r; r=r->next) |
||
479 | fnl->numdirs++; |
||
480 | for (r=fnl->findfiles; r; r=r->next) |
||
481 | fnl->numfiles++; |
||
482 | |||
483 | return(0); |
||
484 | } |
||
485 | |||
486 | |||
3269 | terminx | 487 | // loads all group (grp, zip, pk3/4) files in the given directory |
2555 | helixhorne | 488 | void G_LoadGroupsInDir(const char *dirname) |
489 | { |
||
3269 | terminx | 490 | static const char *extensions[4] = { "*.grp", "*.zip", "*.pk3", "*.pk4" }; |
2555 | helixhorne | 491 | |
492 | char buf[BMAX_PATH]; |
||
493 | int32_t i; |
||
494 | |||
495 | fnlist_t fnlist = FNLIST_INITIALIZER; |
||
496 | |||
3269 | terminx | 497 | for (i=0; i<4; i++) |
2555 | helixhorne | 498 | { |
499 | CACHE1D_FIND_REC *rec; |
||
500 | |||
501 | fnlist_getnames(&fnlist, dirname, extensions[i], -1, 0); |
||
502 | |||
503 | for (rec=fnlist.findfiles; rec; rec=rec->next) |
||
504 | { |
||
505 | Bsnprintf(buf, sizeof(buf), "%s/%s", dirname, rec->name); |
||
506 | initprintf("Using group file \"%s\".\n", buf); |
||
507 | initgroupfile(buf); |
||
508 | } |
||
509 | |||
510 | fnlist_clearnames(&fnlist); |
||
511 | } |
||
512 | } |
||
513 | |||
514 | void G_DoAutoload(const char *dirname) |
||
515 | { |
||
516 | char buf[BMAX_PATH]; |
||
517 | |||
518 | Bsnprintf(buf, sizeof(buf), "autoload/%s", dirname); |
||
519 | G_LoadGroupsInDir(buf); |
||
520 | } |
||
2560 | helixhorne | 521 | |
522 | //// |
||
523 | |||
524 | // returns a buffer of size BMAX_PATH |
||
525 | char *dup_filename(const char *fn) |
||
526 | { |
||
3176 | helixhorne | 527 | char *buf = (char *)Bmalloc(BMAX_PATH); |
2560 | helixhorne | 528 | |
529 | return Bstrncpyz(buf, fn, BMAX_PATH); |
||
530 | } |
||
3004 | helixhorne | 531 | |
532 | |||
533 | // Copy FN to WBUF and append an extension if it's not there, which is checked |
||
534 | // case-insensitively. |
||
535 | // Returns: 1 if not all characters could be written to WBUF, 0 else. |
||
536 | int32_t maybe_append_ext(char *wbuf, int32_t wbufsiz, const char *fn, const char *ext) |
||
537 | { |
||
538 | const int32_t slen=Bstrlen(fn), extslen=Bstrlen(ext); |
||
539 | const int32_t haveext = (slen>=extslen && Bstrcasecmp(&fn[slen-extslen], ext)==0); |
||
540 | |||
541 | Bassert((intptr_t)wbuf != (intptr_t)fn); // no aliasing |
||
542 | |||
543 | // If 'fn' has no extension suffixed, append one. |
||
544 | return (Bsnprintf(wbuf, wbufsiz, "%s%s", fn, haveext ? "" : ext) >= wbufsiz); |
||
545 | } |
||
3243 | helixhorne | 546 | |
547 | |||
3489 | helixhorne | 548 | // Approximations to 2D and 3D Euclidean distances. Initial EDuke32 SVN import says |
3243 | helixhorne | 549 | // in jmact/mathutil.c: "Ken's reverse-engineering job". |
550 | // Note that jmact/mathutil.c contains practically the same code, but where the |
||
551 | // individual x/y(/z) distances are passed instead. |
||
552 | int32_t ldist(const spritetype *s1, const spritetype *s2) |
||
553 | { |
||
554 | int32_t x = klabs(s1->x-s2->x); |
||
555 | int32_t y = klabs(s1->y-s2->y); |
||
556 | |||
557 | if (x<y) swaplong(&x,&y); |
||
558 | |||
559 | { |
||
560 | int32_t t = y + (y>>1); |
||
561 | return (x - (x>>5) - (x>>7) + (t>>2) + (t>>6)); |
||
562 | } |
||
563 | } |
||
564 | |||
565 | int32_t dist(const spritetype *s1, const spritetype *s2) |
||
566 | { |
||
567 | int32_t x = klabs(s1->x-s2->x); |
||
568 | int32_t y = klabs(s1->y-s2->y); |
||
569 | int32_t z = klabs((s1->z-s2->z)>>4); |
||
570 | |||
571 | if (x<y) swaplong(&x,&y); |
||
572 | if (x<z) swaplong(&x,&z); |
||
573 | |||
574 | { |
||
575 | int32_t t = y + z; |
||
576 | return (x - (x>>4) + (t>>2) + (t>>3)); |
||
577 | } |
||
578 | } |
||
3321 | helixhorne | 579 | |
580 | |||
581 | // Clear OSD background |
||
582 | void COMMON_clearbackground(int32_t numcols, int32_t numrows) |
||
583 | { |
||
584 | UNREFERENCED_PARAMETER(numcols); |
||
585 | |||
586 | # ifdef USE_OPENGL |
||
3784 | terminx | 587 | if (getrendermode() >= REND_POLYMOST && qsetmode==200) |
3321 | helixhorne | 588 | { |
589 | setpolymost2dview(); |
||
590 | bglColor4f(0,0,0,0.67f); |
||
591 | bglEnable(GL_BLEND); |
||
592 | bglRectd(0,0, xdim,8*numrows+8); |
||
593 | bglColor4f(0,0,0,1); |
||
594 | bglRectd(0,8*numrows+4, xdim,8*numrows+8); |
||
595 | return; |
||
596 | } |
||
597 | # endif |
||
598 | |||
599 | CLEARLINES2D(0, min(ydim, numrows*8+8), editorcolors[16]); |
||
600 | } |