DEADSOFTWARE

cleanup: remove g_main.pas
[d2df-sdl.git] / src / game / Doom2DF.lpr
1 (* Copyright (C) Doom 2D: Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *)
15 {$INCLUDE ../shared/a_modes.inc}
16 {$IFDEF ANDROID}library{$ELSE}program{$ENDIF} Doom2DF;
18 {$IFNDEF HEADLESS}
19 {$IFDEF WINDOWS}
20 {$APPTYPE GUI}
21 {$ENDIF}
22 {$ENDIF}
23 {$HINTS OFF}
25 uses
26 {$IFDEF ANDROID}
27 ctypes,
28 {$ENDIF}
29 {$IFDEF UNIX}
30 cthreads, BaseUnix,
31 {$ENDIF}
32 {$IFDEF DARWIN}
33 MacOSAll, CocoaAll,
34 {$ENDIF}
35 mempool in '../shared/mempool.pas',
36 conbuf in '../shared/conbuf.pas',
37 geom in '../shared/geom.pas',
38 math,
40 {$IFDEF USE_MINIUPNPC}
41 miniupnpc in '../lib/miniupnpc/miniupnpc.pas',
42 {$ENDIF}
44 {$IFDEF USE_SDL}
45 SDL,
46 {$IFDEF USE_SDLMIXER}
47 SDL_mixer,
48 {$ENDIF}
49 {$ENDIF}
50 {$IFDEF USE_SDL2}
51 SDL2 in '../lib/sdl2/sdl2.pas',
52 {$IFDEF USE_SDLMIXER}
53 SDL2_mixer in '../lib/sdl2/SDL2_mixer.pas',
54 {$ENDIF}
55 {$ENDIF}
56 {$IFDEF USE_SYSSTUB}
57 {$IFDEF USE_SDLMIXER}
58 SDL2 in '../lib/sdl2/sdl2.pas',
59 SDL2_mixer in '../lib/sdl2/SDL2_mixer.pas',
60 {$ENDIF}
61 {$ENDIF}
63 {$IFDEF USE_OPENAL}
64 AL in '../lib/openal/al.pas',
65 e_soundfile in '../engine/e_soundfile.pas',
66 {$IF DEFINED(USE_SDL) OR DEFINED(USE_SDL2)}
67 e_soundfile_wav in '../engine/e_soundfile_wav.pas',
68 {$ENDIF}
69 {$IFDEF USE_VORBIS}
70 vorbis in '../lib/vorbis/vorbis.pas',
71 e_soundfile_vorbis in '../engine/e_soundfile_vorbis.pas',
72 {$ENDIF}
73 {$IFDEF USE_FLUIDSYNTH}
74 fluidsynth in '../lib/fluidsynth/fluidsynth.pas',
75 e_soundfile_fluid in '../engine/e_soundfile_fluid.pas',
76 {$ENDIF}
77 {$IFDEF USE_MODPLUG}
78 modplug in '../lib/modplug/modplug.pas',
79 e_soundfile_modplug in '../engine/e_soundfile_modplug.pas',
80 {$ENDIF}
81 {$IFDEF USE_XMP}
82 xmp in '../lib/xmp/xmp.pas',
83 e_soundfile_xmp in '../engine/e_soundfile_xmp.pas',
84 {$ENDIF}
85 {$IFDEF USE_GME}
86 gme in '../lib/gme/gme.pas',
87 e_soundfile_gme in '../engine/e_soundfile_gme.pas',
88 {$ENDIF}
89 {$IFDEF USE_MPG123}
90 mpg123 in '../lib/mpg123/mpg123.pas',
91 e_soundfile_mp3 in '../engine/e_soundfile_mp3.pas',
92 {$ENDIF}
93 {$IFDEF USE_OPUS}
94 opus in '../lib/opus/opus.pas',
95 e_soundfile_opus in '../engine/e_soundfile_opus.pas',
96 {$ENDIF}
97 {$IF DEFINED(USE_VORBIS) OR DEFINED(USE_OPUS)}
98 ogg in '../lib/vorbis/ogg.pas', // this has to come last because link order
99 {$ENDIF}
100 {$ENDIF}
102 ENet in '../lib/enet/enet.pp',
103 e_input in '../engine/e_input.pas',
104 e_log in '../engine/e_log.pas',
105 e_sound in '../engine/e_sound.pas',
106 e_msg in '../engine/e_msg.pas',
107 e_res in '../engine/e_res.pas',
108 utils in '../shared/utils.pas',
109 xstreams in '../shared/xstreams.pas',
110 sfs in '../sfs/sfs.pas',
111 sfsPlainFS in '../sfs/sfsPlainFS.pas',
112 sfsZipFS in '../sfs/sfsZipFS.pas',
113 wadreader in '../shared/wadreader.pas',
114 MAPDEF in '../shared/MAPDEF.pas',
115 CONFIG in '../shared/CONFIG.pas',
116 g_base in 'g_base.pas',
117 g_basic in 'g_basic.pas',
118 g_console in 'g_console.pas',
119 g_net in 'g_net.pas',
120 g_netmsg in 'g_netmsg.pas',
121 g_nethandler in 'g_nethandler.pas',
122 g_netmaster in 'g_netmaster.pas',
123 g_res_downloader in 'g_res_downloader.pas',
124 g_grid in 'g_grid.pas',
125 g_game in 'g_game.pas',
126 g_gfx in 'g_gfx.pas',
127 g_gui in 'g_gui.pas',
128 g_items in 'g_items.pas',
129 g_map in 'g_map.pas',
130 g_menu in 'g_menu.pas',
131 g_monsters in 'g_monsters.pas',
132 g_options in 'g_options.pas',
133 g_phys in 'g_phys.pas',
134 g_player in 'g_player.pas',
135 g_playermodel in 'g_playermodel.pas',
136 g_saveload in 'g_saveload.pas',
137 g_sound in 'g_sound.pas',
138 g_textures in 'g_textures.pas',
139 g_triggers in 'g_triggers.pas',
140 g_weapons in 'g_weapons.pas',
141 g_window in 'g_window.pas',
142 {$IFDEF USE_SYSSTUB}
143 g_system in 'stub/g_system.pas',
144 g_touch in 'stub/g_touch.pas',
145 {$ENDIF}
146 {$IFDEF USE_SDL}
147 g_system in 'sdl/g_system.pas',
148 g_touch in 'sdl/g_touch.pas',
149 {$ENDIF}
150 {$IFDEF USE_SDL2}
151 g_system in 'sdl2/g_system.pas',
152 g_touch in 'sdl2/g_touch.pas',
153 {$ENDIF}
155 r_console in 'opengl/r_console.pas',
156 r_game in 'opengl/r_game.pas',
157 r_gfx in 'opengl/r_gfx.pas',
158 r_graphics in 'opengl/r_graphics.pas',
159 r_items in 'opengl/r_items.pas',
160 r_map in 'opengl/r_map.pas',
161 r_monsters in 'opengl/r_monsters.pas',
162 r_netmaster in 'opengl/r_netmaster.pas',
163 r_panel in 'opengl/r_panel.pas',
164 r_player in 'opengl/r_player.pas',
165 r_playermodel in 'opengl/r_playermodel.pas',
166 r_texture in 'opengl/r_texture.pas',
167 r_weapons in 'opengl/r_weapons.pas',
168 r_window in 'opengl/r_window.pas',
170 {$IFDEF USE_FMOD}
171 fmod in '../lib/FMOD/fmod.pas',
172 fmoderrors in '../lib/FMOD/fmoderrors.pas',
173 fmodpresets in '../lib/FMOD/fmodpresets.pas',
174 fmodtypes in '../lib/FMOD/fmodtypes.pas',
175 {$ENDIF}
176 xprofiler in '../shared/xprofiler.pas',
177 binheap in '../shared/binheap.pas',
178 hashtable in '../shared/hashtable.pas',
179 fhashdb in '../shared/fhashdb.pas',
180 idpool in '../shared/idpool.pas',
181 xparser in '../shared/xparser.pas',
182 xdynrec in '../shared/xdynrec.pas',
183 exoma in '../shared/exoma.pas',
184 envvars in '../shared/envvars.pas',
185 g_panel in 'g_panel.pas',
186 g_language in 'g_language.pas',
188 {$IFDEF ENABLE_HOLMES}
189 g_holmes in 'g_holmes.pas',
191 sdlcarcass in '../flexui/sdlcarcass.pas',
192 //sdlstandalone in '../flexui/sdlstandalone.pas',
194 fui_wadread in '../flexui/fui_wadread.pas',
195 fui_common in '../flexui/fui_common.pas',
196 fui_gfx_gl in '../flexui/fui_gfx_gl.pas',
197 fui_events in '../flexui/fui_events.pas',
198 fui_style in '../flexui/fui_style.pas',
199 fui_flexlay in '../flexui/fui_flexlay.pas',
200 fui_ctls in '../flexui/fui_ctls.pas',
201 {$ENDIF}
202 {$I ../shared/vampimg.inc}
203 SysUtils;
205 {$IFDEF WINDOWS}
206 {$R *.res}
207 {$ENDIF}
209 var
210 noct: Boolean = False;
211 binPath: AnsiString = '';
212 forceBinDir: Boolean = False;
214 function GetBinaryPath (): AnsiString;
215 {$IFDEF LINUX}
216 var sl: AnsiString;
217 {$ENDIF}
218 begin
219 result := ExtractFilePath(ParamStr(0));
220 {$IFDEF LINUX}
221 // it may be a symlink; do some guesswork here
222 sl := fpReadLink(ExtractFileName(ParamStr(0)));
223 if (sl = ParamStr(0)) then
224 begin
225 // use current directory, as we don't have anything better
226 //result := '.';
227 GetDir(0, result);
228 end;
229 {$ENDIF}
230 result := fixSlashes(result);
231 if (length(result) > 0) and (result[length(result)] <> '/') then
232 result := result + '/';
233 end;
235 procedure PrintDirs (msg: AnsiString; dirs: SSArray);
236 var dir: AnsiString;
237 begin
238 e_LogWriteln(msg + ':');
239 for dir in dirs do
240 e_LogWriteln(' ' + dir);
241 end;
243 {$IFDEF DARWIN}
244 function NSStringToAnsiString (s: NSString): AnsiString;
245 var i: Integer;
246 begin
247 result := '';
248 for i := 0 to s.length - 1 do
249 result := result + AnsiChar(s.characterAtIndex(i));
250 end;
252 function GetBundlePath (): AnsiString;
253 var pathRef: CFURLRef; pathCFStr: CFStringRef; pathStr: ShortString;
254 begin
255 pathRef := CFBundleCopyBundleURL(CFBundleGetMainBundle());
256 pathCFStr := CFURLCopyFileSystemPath(pathRef, kCFURLPOSIXPathStyle);
257 CFStringGetPascalString(pathCFStr, @pathStr, 255, CFStringGetSystemEncoding());
258 CFRelease(pathRef);
259 CFRelease(pathCFStr);
260 Result := pathStr;
261 end;
262 {$ENDIF}
264 procedure InitPath;
265 var i: Integer; rwdir, rodir: AnsiString; rwdirs, rodirs: SSArray;
267 procedure AddDir (var dirs: SSArray; append: AnsiString);
268 begin
269 SetLength(dirs, Length(dirs) + 1);
270 dirs[High(dirs)] := ExpandFileName(append)
271 end;
273 function IsSep (ch: Char): Boolean;
274 begin
275 {$IFDEF WINDOWS}
276 result := (ch = '/') or (ch = '\');
277 {$ELSE}
278 result := (ch = '/');
279 {$ENDIF}
280 end;
282 function OptimizePath (dir: AnsiString): AnsiString;
283 var i, len: Integer; s: AnsiString;
284 begin
285 i := 1; len := Length(dir); s := '';
286 while i <= len do
287 begin
288 if IsSep(dir[i]) then
289 begin
290 s := s + DirectorySeparator;
291 Inc(i);
292 while (i <= len) and IsSep(dir[i]) do Inc(i);
293 if (i <= len) and (dir[i] = '.') then
294 begin
295 if (i = len) or IsSep(dir[i + 1]) then
296 begin
297 Inc(i)
298 end
299 else if (i + 1 <= len) and (dir[i + 1] = '.') then
300 begin
301 if (i + 1 = len) or IsSep(dir[i + 2]) then
302 begin
303 s := e_UpperDir(s);
304 Inc(i, 2)
305 end
306 end
307 end
308 end
309 else
310 begin
311 s := s + dir[i];
312 Inc(i)
313 end
314 end;
315 result := s
316 end;
318 procedure OptimizeDirs (var dirs: SSArray);
319 var i, j, k: Integer;
320 begin
321 for i := 0 to High(dirs) do
322 dirs[i] := OptimizePath(dirs[i]);
323 // deduplicate
324 i := High(dirs);
325 while i >= 0 do
326 begin
327 j := 0;
328 while j < i do
329 begin
330 if dirs[j] = dirs[i] then
331 begin
332 for k := j + 1 to High(dirs) do
333 dirs[k - 1] := dirs[k];
334 Dec(i);
335 SetLength(dirs, High(dirs))
336 end
337 else
338 begin
339 Inc(j)
340 end
341 end;
342 Dec(i)
343 end
344 end;
346 procedure AddDef (var dirs: SSArray; base: SSArray; append: AnsiString);
347 var s: AnsiString;
348 begin
349 if Length(dirs) = 0 then
350 for s in base do
351 AddDir(dirs, e_CatPath(s, append));
352 OptimizeDirs(dirs)
353 end;
355 function GetDefaultRODirs (): SSArray;
356 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
357 var home: AnsiString;
358 {$ENDIF}
359 {$IFDEF WINDOWS}
360 var appdata: AnsiString;
361 {$ENDIF}
362 {$IFDEF DARWIN}
363 var bundle, s: AnsiString; dirArr: NSArray; i: Integer;
364 {$ENDIF}
365 begin
366 result := nil;
367 {$IFDEF DARWIN}
368 bundle := GetBundlePath();
369 if ExtractFileExt(bundle) <> '.app' then
370 AddDir(result, binpath);
371 {$ELSE}
372 AddDir(result, binPath);
373 {$ENDIF}
374 if forceBinDir = false then
375 begin
376 {$IFDEF USE_SDL2}
377 AddDir(result, SDL_GetBasePath());
378 AddDir(result, SDL_GetPrefPath('', 'doom2df'));
379 {$ENDIF}
380 {$IFDEF WINDOWS}
381 appdata := GetEnvironmentVariable('APPDATA') + '\doom2df';
382 if appdata <> '' then
383 AddDir(result, appdata);
384 {$ENDIF}
385 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
386 AddDir(result, '/usr/share/doom2df');
387 AddDir(result, '/usr/local/share/doom2df');
388 home := GetEnvironmentVariable('HOME');
389 if home <> '' then
390 AddDir(result, e_CatPath(home, '.doom2df'));
391 {$ENDIF}
392 {$IFDEF DARWIN}
393 bundle := GetBundlePath();
394 if bundle <> '' then
395 AddDir(result, e_CatPath(bundle, 'Contents/Resources'));
396 dirArr := NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, true);
397 for i := 0 to dirArr.count - 1 do
398 begin
399 s := NSStringToAnsiString(dirArr.objectAtIndex(i));
400 AddDir(result, e_CatPath(s, 'Doom 2D Forever'))
401 end;
402 {$ENDIF}
403 {$IF DEFINED(ANDROID) AND DEFINED(USE_SDL2)}
404 AddDir(result, SDL_AndroidGetInternalStoragePath());
405 if SDL_AndroidGetExternalStorageState() <> 0 then
406 AddDir(result, SDL_AndroidGetExternalStoragePath());
407 {$ENDIF}
408 end
409 end;
411 function GetDefaultRWDirs (): SSArray;
412 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
413 var home: AnsiString;
414 {$ENDIF}
415 {$IFDEF WINDOWS}
416 var appdata: AnsiString;
417 {$ENDIF}
418 {$IFDEF DARWIN}
419 var bundle, s: AnsiString; dirArr: NSArray; i: Integer;
420 {$ENDIF}
421 begin
422 result := nil;
423 {$IFDEF DARWIN}
424 bundle := GetBundlePath();
425 if ExtractFileExt(bundle) <> '.app' then
426 AddDir(result, binPath);
427 {$ELSE}
428 AddDir(result, binPath);
429 {$ENDIF}
430 if forceBinDir = false then
431 begin
432 {$IFDEF USE_SDL2}
433 AddDir(result, SDL_GetPrefPath('', 'doom2df'));
434 {$ENDIF}
435 {$IFDEF WINDOWS}
436 appdata := GetEnvironmentVariable('APPDATA') + '\doom2df';
437 if appdata <> '' then
438 AddDir(result, appdata);
439 {$ENDIF}
440 {$IF DEFINED(UNIX) AND NOT DEFINED(DARWIN) AND NOT DEFINED(ANDROID)}
441 home := GetEnvironmentVariable('HOME');
442 if home <> '' then
443 AddDir(result, e_CatPath(home, '.doom2df'));
444 {$ENDIF}
445 {$IFDEF DARWIN}
446 dirArr := NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, true);
447 for i := 0 to dirArr.count - 1 do
448 begin
449 s := NSStringToAnsiString(dirArr.objectAtIndex(i));
450 AddDir(result, e_CatPath(s, 'Doom 2D Forever'))
451 end;
452 {$ENDIF}
453 {$IF DEFINED(ANDROID) AND DEFINED(USE_SDL2)}
454 if SDL_AndroidGetExternalStorageState() <> 0 then
455 AddDir(result, SDL_AndroidGetExternalStoragePath());
456 {$ENDIF}
457 end
458 end;
460 begin
461 forceBinDir := false;
462 binPath := GetBinaryPath();
464 i := 1;
465 while i < ParamCount do
466 begin
467 case ParamStr(i) of
468 '--like-windoze': forceBinDir := true;
469 '--rw-dir':
470 begin
471 Inc(i);
472 rwdir := ParamStr(i);
473 (* RW *)
474 AddDir(LogDirs, e_CatPath(rwdir, ''));
475 AddDir(SaveDirs, e_CatPath(rwdir, 'data'));
476 AddDir(CacheDirs, e_CatPath(rwdir, 'data/cache'));
477 AddDir(ConfigDirs, e_CatPath(rwdir, ''));
478 AddDir(MapDownloadDirs, e_CatPath(rwdir, 'maps/downloads'));
479 AddDir(WadDownloadDirs, e_CatPath(rwdir, 'wads/downloads'));
480 AddDir(ScreenshotDirs, e_CatPath(rwdir, 'screenshots'));
481 AddDir(StatsDirs, e_CatPath(rwdir, 'stats'));
482 (* RO *)
483 AddDir(DataDirs, e_CatPath(rwdir, 'data'));
484 AddDir(ModelDirs, e_CatPath(rwdir, 'data/models'));
485 AddDir(MegawadDirs, e_CatPath(rwdir, 'maps/megawads'));
486 AddDir(MapDirs, e_CatPath(rwdir, 'maps'));
487 AddDir(WadDirs, e_CatPath(rwdir, 'wads'));
488 end;
489 '--ro-dir':
490 begin
491 Inc(i);
492 rodir := ParamStr(i);
493 (* RO *)
494 AddDir(DataDirs, e_CatPath(rodir, 'data'));
495 AddDir(ModelDirs, e_CatPath(rodir, 'data/models'));
496 AddDir(MegawadDirs, e_CatPath(rodir, 'maps/megawads'));
497 AddDir(MapDirs, e_CatPath(rodir, 'maps'));
498 AddDir(WadDirs, e_CatPath(rodir, 'wads'));
499 end;
500 '--game-wad':
501 begin
502 Inc(i);
503 GameWADName := ParamStr(i);
504 end;
505 '--config':
506 begin
507 Inc(i);
508 gConfigScript := ParamStr(i);
509 end;
510 end;
511 Inc(i)
512 end;
514 // prefer bin dir if it writable and contains game.wad
515 if forceBinDir = false then
516 begin
517 if findDiskWad(binPath + 'data' + '/' + GameWADName) <> '' then
518 if e_CanCreateFilesAt(binPath) then
519 forceBinDir := true
520 end;
522 (* RO *)
523 rodirs := GetDefaultRODirs();
524 AddDef(DataDirs, rodirs, 'data');
525 AddDef(ModelDirs, rodirs, 'data/models');
526 AddDef(MegawadDirs, rodirs, 'maps/megawads');
527 AddDef(MapDirs, rodirs, 'maps');
528 AddDef(WadDirs, rodirs, 'wads');
530 (* RW *)
531 rwdirs := GetDefaultRWDirs();
532 AddDef(LogDirs, rwdirs, '');
533 AddDef(SaveDirs, rwdirs, 'data');
534 AddDef(CacheDirs, rwdirs, 'data/cache');
535 AddDef(ConfigDirs, rwdirs, '');
536 AddDef(MapDownloadDirs, rwdirs, 'maps/downloads');
537 AddDef(WadDownloadDirs, rwdirs, 'wads/downloads');
538 AddDef(ScreenshotDirs, rwdirs, 'screenshots');
539 AddDef(StatsDirs, rwdirs, 'stats');
541 for i := 0 to High(MapDirs) do
542 AddDir(AllMapDirs, MapDirs[i]);
543 for i := 0 to High(MegawadDirs) do
544 AddDir(AllMapDirs, MegawadDirs[i]);
545 OptimizeDirs(AllMapDirs);
547 if LogFileName = '' then
548 begin
549 rwdir := e_GetWriteableDir(LogDirs, false);
550 if rwdir <> '' then
551 begin
552 {$IFDEF HEADLESS}
553 LogFileName := e_CatPath(rwdir, 'Doom2DF_H.log');
554 {$ELSE}
555 LogFileName := e_CatPath(rwdir, 'Doom2DF.log');
556 {$ENDIF}
557 end
558 end;
560 // HACK: ensure the screenshots folder also has a stats subfolder in it
561 rwdir := e_GetWriteableDir(ScreenshotDirs, false);
562 if rwdir <> '' then CreateDir(rwdir + '/stats');
563 end;
565 procedure InitPrep;
566 {$IF DEFINED(ANDROID) AND DEFINED(USE_SDLMIXER)}
567 var timiditycfg: AnsiString;
568 {$ENDIF}
569 var i: Integer;
570 begin
571 {$IFDEF HEADLESS}
572 conbufDumpToStdOut := true;
573 {$ENDIF}
574 for i := 1 to ParamCount do
575 begin
576 case ParamStr(i) of
577 '--con-stdout': conbufDumpToStdOut := true;
578 '--no-fbo': glRenderToFBO := false;
579 end
580 end;
582 if LogFileName <> '' then
583 e_InitLog(LogFileName, TWriteMode.WM_NEWFILE);
584 e_InitWritelnDriver();
585 e_WriteLog('Doom 2D: Forever version ' + GAME_VERSION + ' proto ' + IntToStr(NET_PROTOCOL_VER), TMsgType.Notify);
586 e_WriteLog('Build date: ' + GAME_BUILDDATE + ' ' + GAME_BUILDTIME, TMsgType.Notify);
587 e_WriteLog('Build hash: ' + g_GetBuildHash(), TMsgType.Notify);
588 e_WriteLog('Build by: ' + g_GetBuilderName(), TMsgType.Notify);
590 e_LogWritefln('Force bin dir: %s', [forceBinDir], TMsgType.Notify);
591 e_LogWritefln('BINARY PATH: [%s]', [binPath], TMsgType.Notify);
593 PrintDirs('DataDirs', DataDirs);
594 PrintDirs('ModelDirs', ModelDirs);
595 PrintDirs('MegawadDirs', MegawadDirs);
596 PrintDirs('MapDirs', MapDirs);
597 PrintDirs('WadDirs', WadDirs);
599 PrintDirs('LogDirs', LogDirs);
600 PrintDirs('SaveDirs', SaveDirs);
601 PrintDirs('CacheDirs', CacheDirs);
602 PrintDirs('ConfigDirs', ConfigDirs);
603 PrintDirs('ScreenshotDirs', ScreenshotDirs);
604 PrintDirs('StatsDirs', StatsDirs);
605 PrintDirs('MapDownloadDirs', MapDownloadDirs);
606 PrintDirs('WadDownloadDirs', WadDownloadDirs);
608 GameWAD := e_FindWad(DataDirs, GameWADName);
609 if GameWad = '' then
610 begin
611 e_WriteLog('WAD ' + GameWADName + ' not found in data directories.', TMsgType.Fatal);
612 {$IF DEFINED(USE_SDL2) AND NOT DEFINED(HEADLESS)}
613 if forceBinDir = false then
614 SDL_ShowSimpleMessageBox(
615 SDL_MESSAGEBOX_ERROR,
616 'Doom 2D Forever',
617 PChar('WAD ' + GameWADName + ' not found in data directories.'),
618 nil
619 );
620 {$ENDIF}
621 e_DeinitLog;
622 Halt(1);
623 end;
625 {$IF DEFINED(ANDROID) AND DEFINED(USE_SDLMIXER)}
626 timiditycfg := 'timidity.cfg';
627 if e_FindResource(ConfigDirs, timiditycfg) = true then
628 begin
629 timiditycfg := ExpandFileName(timiditycfg);
630 SetEnvVar('TIMIDITY_CFG', timiditycfg);
631 e_LogWritefln('Set TIMIDITY_CFG = "%s"', [timiditycfg]);
632 end;
633 {$ENDIF}
634 end;
636 procedure Main;
637 {$IFDEF ENABLE_HOLMES}
638 var flexloaded: Boolean;
639 {$ENDIF}
640 begin
641 InitPath;
642 InitPrep;
643 e_InitInput;
644 sys_Init;
646 sys_CharPress := @CharPress;
648 g_Options_SetDefault;
649 g_Options_SetDefaultVideo;
650 g_Console_SysInit;
651 if sys_SetDisplayMode(gRC_Width, gRC_Height, gBPP, gRC_FullScreen, gRC_Maximized) = False then
652 raise Exception.Create('Failed to set videomode on startup.');
654 e_WriteLog(gLanguage, TMsgType.Notify);
655 g_Language_Set(gLanguage);
657 {$IF not DEFINED(HEADLESS) and DEFINED(ENABLE_HOLMES)}
658 flexloaded := true;
659 if not fuiAddWad('flexui.wad') then
660 begin
661 if not fuiAddWad('./data/flexui.wad') then fuiAddWad('./flexui.wad');
662 end;
663 try
664 fuiGfxLoadFont('win8', 'flexui/fonts/win8.fuifont');
665 fuiGfxLoadFont('win14', 'flexui/fonts/win14.fuifont');
666 fuiGfxLoadFont('win16', 'flexui/fonts/win16.fuifont');
667 fuiGfxLoadFont('dos8', 'flexui/fonts/dos8.fuifont');
668 fuiGfxLoadFont('msx6', 'flexui/fonts/msx6.fuifont');
669 except on e: Exception do
670 begin
671 writeln('ERROR loading FlexUI fonts');
672 flexloaded := false;
673 //raise;
674 end;
675 else
676 begin
677 flexloaded := false;
678 //raise;
679 end;
680 end;
681 if (flexloaded) then
682 begin
683 try
684 e_LogWriteln('FlexUI: loading stylesheet...');
685 uiLoadStyles('flexui/widgets.wgs');
686 except on e: TParserException do
687 begin
688 writeln('ERROR at (', e.tokLine, ',', e.tokCol, '): ', e.message);
689 //raise;
690 flexloaded := false;
691 end;
692 else
693 begin
694 //raise;
695 flexloaded := false;
696 end;
697 end;
698 end;
699 g_holmes_imfunctional := not flexloaded;
701 if (not g_holmes_imfunctional) then
702 begin
703 uiInitialize();
704 uiContext.font := 'win14';
705 end;
707 if assigned(oglInitCB) then oglInitCB;
708 {$ENDIF}
710 //g_Res_CreateDatabases(true); // it will be done before connecting to the server for the first time
712 e_WriteLog('Entering SDLMain', TMsgType.Notify);
714 {$WARNINGS OFF}
715 SDLMain();
716 {$WARNINGS ON}
718 {$IFDEF ENABLE_HOLMES}
719 if assigned(oglDeinitCB) then oglDeinitCB;
720 {$ENDIF}
722 g_Console_WriteGameConfig;
723 sys_Final;
724 end;
727 procedure EntryParams;
728 var f: Integer;
729 begin
730 f := 1;
731 while f <= ParamCount do
732 begin
733 case ParamStr(f) of
734 '--gdb': noct := true;
735 '--log': conbufDumpToStdOut := true;
736 '--safe-log': e_SetSafeSlowLog(true);
737 '--log-file':
738 if f + 1 <= ParamCount then
739 begin
740 Inc(f);
741 LogFileName := ParamStr(f)
742 end
743 end;
744 Inc(f)
745 end
746 end;
748 procedure EntryPoint;
749 begin
750 SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide, exOverflow, exUnderflow, exPrecision]); //k8: fuck off, that's why
751 EntryParams;
752 if noct then
753 Main
754 else
755 try
756 Main;
757 e_WriteLog('Shutdown with no errors.', TMsgType.Notify)
758 except on e: Exception do
759 e_WriteStackTrace(e.message)
760 else
761 e_WriteStackTrace('FATAL ERROR')
762 end;
764 e_DeinitLog;
765 end;
767 {$IFDEF ANDROID}
768 function SDL_main (argc: CInt; argv: PPChar): CInt; cdecl;
769 begin
770 // TODO pass argc+argv to rtl
771 EntryPoint;
772 result := 0
773 end;
775 exports SDL_main;
776 {$ELSE}
777 begin
778 EntryPoint
779 {$ENDIF}
781 end.