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,
31 {$ENDIF}
32 mempool in '../shared/mempool.pas',
33 conbuf in '../shared/conbuf.pas',
34 geom in '../shared/geom.pas',
35 math,
37 {$INCLUDE ../nogl/noGLuses.inc}
39 {$IFDEF USE_MINIUPNPC}
40 miniupnpc in '../lib/miniupnpc/miniupnpc.pas',
41 {$ENDIF}
43 {$IFDEF USE_SDL}
44 SDL,
45 {$ENDIF}
46 {$IFDEF USE_SDL2}
47 SDL2 in '../lib/sdl2/sdl2.pas',
48 {$IFDEF USE_SDLMIXER}
49 SDL2_mixer in '../lib/sdl2/SDL2_mixer.pas',
50 {$ENDIF}
51 {$ENDIF}
53 {$IFDEF USE_OPENAL}
54 AL in '../lib/openal/al.pas',
55 e_soundfile in '../engine/e_soundfile.pas',
56 {$IF DEFINED(USE_SDL) OR DEFINED(USE_SDL2)}
57 e_soundfile_wav in '../engine/e_soundfile_wav.pas',
58 {$ENDIF}
59 {$IFDEF USE_VORBIS}
60 vorbis in '../lib/vorbis/vorbis.pas',
61 e_soundfile_vorbis in '../engine/e_soundfile_vorbis.pas',
62 {$ENDIF}
63 {$IFDEF USE_FLUIDSYNTH}
64 fluidsynth in '../lib/fluidsynth/fluidsynth.pas',
65 e_soundfile_fluid in '../engine/e_soundfile_fluid.pas',
66 {$ENDIF}
67 {$IFDEF USE_MODPLUG}
68 modplug in '../lib/modplug/modplug.pas',
69 e_soundfile_modplug in '../engine/e_soundfile_modplug.pas',
70 {$ENDIF}
71 {$IFDEF USE_XMP}
72 xmp in '../lib/xmp/xmp.pas',
73 e_soundfile_xmp in '../engine/e_soundfile_xmp.pas',
74 {$ENDIF}
75 {$IFDEF USE_MPG123}
76 mpg123 in '../lib/mpg123/mpg123.pas',
77 e_soundfile_mp3 in '../engine/e_soundfile_mp3.pas',
78 {$ENDIF}
79 {$IFDEF USE_OPUS}
80 opus in '../lib/opus/opus.pas',
81 e_soundfile_opus in '../engine/e_soundfile_opus.pas',
82 {$ENDIF}
83 {$IF DEFINED(USE_VORBIS) OR DEFINED(USE_OPUS)}
84 ogg in '../lib/vorbis/ogg.pas', // this has to come last because link order
85 {$ENDIF}
86 {$ENDIF}
88 ENet in '../lib/enet/enet.pp',
89 e_graphics in '../engine/e_graphics.pas',
90 e_input in '../engine/e_input.pas',
91 e_log in '../engine/e_log.pas',
92 e_sound in '../engine/e_sound.pas',
93 e_texture in '../engine/e_texture.pas',
94 e_msg in '../engine/e_msg.pas',
95 utils in '../shared/utils.pas',
96 xstreams in '../shared/xstreams.pas',
97 sfs in '../sfs/sfs.pas',
98 sfsPlainFS in '../sfs/sfsPlainFS.pas',
99 sfsZipFS in '../sfs/sfsZipFS.pas',
100 wadreader in '../shared/wadreader.pas',
101 MAPDEF in '../shared/MAPDEF.pas',
102 CONFIG in '../shared/CONFIG.pas',
103 g_basic in 'g_basic.pas',
104 g_console in 'g_console.pas',
105 g_net in 'g_net.pas',
106 g_netmsg in 'g_netmsg.pas',
107 g_nethandler in 'g_nethandler.pas',
108 g_netmaster in 'g_netmaster.pas',
109 g_res_downloader in 'g_res_downloader.pas',
110 g_grid in 'g_grid.pas',
111 g_game in 'g_game.pas',
112 g_gfx in 'g_gfx.pas',
113 g_gui in 'g_gui.pas',
114 g_items in 'g_items.pas',
115 g_main in 'g_main.pas',
116 g_map in 'g_map.pas',
117 g_menu in 'g_menu.pas',
118 g_monsters in 'g_monsters.pas',
119 g_options in 'g_options.pas',
120 g_phys in 'g_phys.pas',
121 g_player in 'g_player.pas',
122 g_playermodel in 'g_playermodel.pas',
123 g_saveload in 'g_saveload.pas',
124 g_sound in 'g_sound.pas',
125 g_textures in 'g_textures.pas',
126 g_triggers in 'g_triggers.pas',
127 g_weapons in 'g_weapons.pas',
128 g_window in 'g_window.pas',
129 {$IFDEF USE_SYSSTUB}
130 g_system in 'stub/g_system.pas',
131 g_touch in 'stub/g_touch.pas',
132 {$ENDIF}
133 {$IFDEF USE_SDL}
134 g_system in 'sdl/g_system.pas',
135 g_touch in 'sdl/g_touch.pas',
136 {$ENDIF}
137 {$IFDEF USE_SDL2}
138 g_system in 'sdl2/g_system.pas',
139 g_touch in 'sdl2/g_touch.pas',
140 {$ENDIF}
142 SysUtils,
143 {$IFDEF USE_FMOD}
144 fmod in '../lib/FMOD/fmod.pas',
145 fmoderrors in '../lib/FMOD/fmoderrors.pas',
146 fmodpresets in '../lib/FMOD/fmodpresets.pas',
147 fmodtypes in '../lib/FMOD/fmodtypes.pas',
148 {$ENDIF}
149 xprofiler in '../shared/xprofiler.pas',
150 binheap in '../shared/binheap.pas',
151 hashtable in '../shared/hashtable.pas',
152 fhashdb in '../shared/fhashdb.pas',
153 idpool in '../shared/idpool.pas',
154 xparser in '../shared/xparser.pas',
155 xdynrec in '../shared/xdynrec.pas',
156 exoma in '../shared/exoma.pas',
157 envvars in '../shared/envvars.pas',
158 g_panel in 'g_panel.pas',
159 g_language in 'g_language.pas',
161 {$IFDEF ENABLE_HOLMES}
162 g_holmes in 'g_holmes.pas',
164 sdlcarcass in '../flexui/sdlcarcass.pas',
165 //sdlstandalone in '../flexui/sdlstandalone.pas',
167 fui_wadread in '../flexui/fui_wadread.pas',
168 fui_common in '../flexui/fui_common.pas',
169 fui_gfx_gl in '../flexui/fui_gfx_gl.pas',
170 fui_events in '../flexui/fui_events.pas',
171 fui_style in '../flexui/fui_style.pas',
172 fui_flexlay in '../flexui/fui_flexlay.pas',
173 fui_ctls in '../flexui/fui_ctls.pas',
174 {$ENDIF}
176 ImagingTypes,
177 Imaging,
178 ImagingUtility;
180 {$IFDEF WINDOWS}
181 {$R *.res}
182 {$ENDIF}
184 {$IFDEF ANDROID}
185 function SDL_main(argc: CInt; argv: PPChar): CInt; cdecl;
186 {$ENDIF ANDROID}
188 var
189 f: Integer;
190 noct: Boolean = false;
191 {$IFDEF ANDROID}
192 storage: String;
193 {$ENDIF}
194 //tfo: Text;
195 begin
196 SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide, exOverflow, exUnderflow, exPrecision]); //k8: fuck off, that's why
198 {$IFDEF ANDROID}
199 {$I-}
200 e_SetSafeSlowLog(true);
201 if SDL_AndroidGetExternalStorageState() <> 0 then
202 begin
203 storage := SDL_AndroidGetExternalStoragePath();
204 Chdir(storage);
205 e_WriteLog('Use external storage: ' + storage, TMsgType.Notify)
206 end
207 else
208 begin
209 storage := SDL_AndroidGetInternalStoragePath();
210 Chdir(storage);
211 e_WriteLog('Use internal storage: ' + storage, TMsgType.Notify)
212 end;
213 if IOresult <> 0 then
214 begin
215 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, PChar('Invalid path'), PChar('Can''t chdir to ' + storage), nil);
216 result := 1;
217 exit
218 end;
219 SetEnvVar('TIMIDITY_CFG', 'timidity.cfg');
220 {$ENDIF ANDROID}
222 f := 1;
223 while f <= ParamCount do
224 begin
225 case ParamStr(f) of
226 '--gdb': noct := true;
227 '--log': conbufDumpToStdOut := true;
228 '--safe-log': e_SetSafeSlowLog(true);
229 '--log-file':
230 if f + 1 <= ParamCount then
231 begin
232 Inc(f);
233 LogFileName := ParamStr(f)
234 end;
235 end;
236 Inc(f)
237 end;
239 if LogFileName = '' then
240 begin
241 {$IFDEF HEADLESS}
242 LogFileName := 'Doom2DF_H.log';
243 {$ELSE}
244 LogFileName := 'Doom2DF.log';
245 {$ENDIF}
246 end;
248 if noct then
249 begin
250 Main()
251 end
252 else
253 begin
254 try
255 Main();
256 e_WriteLog('Shutdown with no errors.', TMsgType.Notify);
257 except
258 on e: Exception do
259 begin
260 e_WriteStackTrace(e.message);
261 //e_WriteLog(Format(_lc[I_SYSTEM_ERROR_MSG], [E.Message]), MSG_FATALERROR);
262 (*
263 AssignFile(tfo, GameDir+'/trace.log');
264 {$I-}
265 Append(tfo);
266 if (IOResult <> 0) then Rewrite(tfo);
267 if (IOResult = 0) then begin writeln(tfo, '====================='); DumpExceptionBackTrace(tfo); CloseFile(tfo); end;
268 *)
269 end
270 else
271 begin
272 //e_WriteLog(Format(_lc[I_SYSTEM_ERROR_UNKNOWN], [NativeUInt(ExceptAddr())]), MSG_FATALERROR);
273 e_WriteStackTrace('FATAL ERROR');
274 end;
275 end;
276 end;
277 e_DeinitLog();
279 {$IFDEF ANDROID}
280 result := 0;
281 end; // SDL_main
282 exports SDL_main;
283 {$ENDIF ANDROID}
284 end.