DEADSOFTWARE

cleanup: remove g_main.pas
[d2df-sdl.git] / src / game / g_options.pas
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 unit g_options;
18 interface
20 uses
21 g_language, g_weapons, utils;
23 function GenPlayerName (n: Integer): String;
25 procedure g_Options_SetDefault;
26 procedure g_Options_SetDefaultVideo;
27 procedure g_Options_ApplyGameSettings;
29 const DF_Default_Megawad_Start = 'megawads/DOOM2D.WAD:\MAP01';
31 var
32 gBPP: Integer;
33 gFreq: Byte;
34 gFullscreen: Boolean;
35 gWinSizeX, gWinSizeY: Integer;
36 gWinMaximized: Boolean;
37 gVSync: Boolean;
38 glLegacyNPOT: Boolean;
39 glRenderToFBO: Boolean = True;
40 gTextureFilter: Boolean;
41 gLerpActors: Boolean = True;
42 gFrameTime: Integer = 5;
43 gMaxFPS: Integer = 200;
44 gNoSound: Boolean;
45 gSoundLevel: Integer;
46 gMusicLevel: Integer;
47 gMaxSimSounds: Integer;
48 gMuteWhenInactive: Boolean;
49 gAdvCorpses: Boolean;
50 gAdvBlood: Boolean;
51 gAdvGibs: Boolean;
52 gGibsCount: Integer;
53 gBloodCount: Integer;
54 gFlash: Integer;
55 gDrawBackGround: Boolean;
56 gShowMessages: Boolean;
57 gRevertPlayers: Boolean;
58 gLanguage: String;
59 gAskLanguage: Boolean;
60 gSaveStats: Boolean = False;
61 gScreenshotStats: Boolean = False;
62 gsSDLSampleRate: Integer;
63 gsSDLBufferSize: Integer;
64 gDefaultMegawadStart: AnsiString;
65 glNPOTOverride: Boolean = false;
67 (* Latched game settings *)
68 gsMap: String;
69 gsGameMode: String;
70 gsTimeLimit: Word;
71 gsScoreLimit: Word;
72 gsMaxLives: Byte;
73 gsPlayers: Byte;
74 gsGameFlags: LongWord;
75 gsSpawnInvul: Integer = 0;
76 gsItemRespawnTime: Word = 60;
77 gsWarmupTime: Word = 30;
79 {$IFDEF HEADLESS}
80 e_NoGraphics: Boolean = True;
81 {$ELSE}
82 e_NoGraphics: Boolean = False;
83 {$ENDIF}
84 e_FastScreenshots: Boolean = true; // it's REALLY SLOW with `false`
85 g_dbg_scale: Single = 1.0;
86 r_pixel_scale: Single = 1.0;
88 {--- Read-only dirs ---}
89 GameWAD: string;
90 DataDirs: SSArray;
91 ModelDirs: SSArray;
92 MegawadDirs: SSArray;
93 MapDirs: SSArray;
94 WadDirs: SSArray;
95 AllMapDirs: SSArray; // Maps + Megawads
97 {--- Read-Write dirs ---}
98 LogFileName: string;
99 LogDirs: SSArray;
100 SaveDirs: SSArray;
101 CacheDirs: SSArray;
102 ConfigDirs: SSArray;
103 ScreenshotDirs: SSArray;
104 StatsDirs: SSArray;
105 MapDownloadDirs: SSArray;
106 WadDownloadDirs: SSArray;
108 GameWADName: string = 'GAME';
110 implementation
112 uses
113 {$IFDEF USE_SDL2}
114 SDL2,
115 {$ENDIF}
116 e_log, e_input, g_console, g_window, g_sound, g_gfx, g_player, Math,
117 g_map, g_net, g_netmaster, SysUtils, CONFIG, g_game,
118 g_items, wadreader, g_touch, envvars, g_system;
120 var
121 machine: Integer;
123 function GenPlayerName (n: Integer): String;
124 begin
125 ASSERT(n >= 1);
126 Result := GetUserName;
127 if Result = '' then
128 Result := 'Player' + IntToStr(machine MOD 10000);
129 if n = 1 then
130 Result := Copy(Result, 1, 12) + ' '
131 else
132 Result := Copy(Result, 1, 10) + ' ' + IntToStr(n)
133 end;
135 {$IFDEF USE_SDL2}
136 procedure g_Options_SetDefaultVideo;
137 var display: TSDL_DisplayMode;
138 {$IFNDEF ANDROID}
139 var target, closest: TSDL_DisplayMode; percentage: Integer;
140 {$ENDIF}
141 begin
142 (* Display 0 = Primary display *)
143 gScreenWidth := 640;
144 gScreenHeight := 480;
145 gWinSizeX := 640;
146 gWinSizeY := 480;
147 //gBPP := SDL_BITSPERPIXEL(display.format);
148 gBPP := 32;
149 {$IFDEF ANDROID}
150 gFullScreen := True; (* rotation not allowed? *)
151 {$ELSE}
152 gFullScreen := False;
153 {$ENDIF}
154 if SDL_GetDesktopDisplayMode(0, @display) = 0 then
155 begin
156 {$IFDEF ANDROID}
157 gWinSizeX := display.w;
158 gWinSizeY := display.h;
159 {$ELSE}
160 (* Window must be smaller than display *)
161 closest.w := display.w;
162 closest.h := display.h;
163 percentage := 75;
164 while (display.w - closest.w < 48) or (display.h - closest.h < 48) do
165 begin
166 if percentage < 25 then
167 begin
168 closest.w := display.w * 75 div 100;
169 closest.h := display.h * 75 div 100;
170 break;
171 end;
172 target.w := display.w * percentage div 100;
173 target.h := display.h * percentage div 100;
174 target.format := 0; (* didn't care *)
175 target.refresh_rate := 0; (* didn't care *)
176 target.driverdata := nil; (* init *)
177 SDL_GetClosestDisplayMode(0, @target, @closest);
178 Dec(percentage);
179 end;
180 gWinSizeX := closest.w;
181 gWinSizeY := closest.h;
182 //gBPP := SDL_BITSPERPIXEL(closest.format); (* Resolution list didn't work for some reason *)
183 {$ENDIF}
184 end
185 else
186 begin
187 e_LogWritefln('SDL: Failed to get desktop display mode: %s', [SDL_GetError])
188 end;
189 (* Must be positioned on primary display *)
190 gWinMaximized := False;
191 gVSync := True;
192 gTextureFilter := True;
193 glLegacyNPOT := False;
194 gRC_Width := gWinSizeX;
195 gRC_Height := gWinSizeY;
196 gRC_FullScreen := gFullScreen;
197 gRC_Maximized := gWinMaximized;
198 e_LogWriteLn('g_Options_SetDefaultVideo: w = ' + IntToStr(gWinSizeX) + ' h = ' + IntToStr(gWinSizeY));
199 g_Console_ResetBinds;
200 end;
201 {$ELSE}
202 procedure g_Options_SetDefaultVideo;
203 begin
204 gWinSizeX := 640;
205 gWinSizeY := 480;
206 gBPP := 32;
207 gFullScreen := False;
208 gWinMaximized := False;
209 gVSync := True;
210 gTextureFilter := True;
211 glLegacyNPOT := False;
212 gScreenWidth := gWinSizeX;
213 gScreenHeight := gWinSizeY;
214 gRC_Width := gWinSizeX;
215 gRC_Height := gWinSizeY;
216 gRC_FullScreen := gFullScreen;
217 gRC_Maximized := gWinMaximized;
218 e_LogWriteLn('g_Options_SetDefaultVideo: w = ' + IntToStr(gWinSizeX) + ' h = ' + IntToStr(gWinSizeY));
219 g_Console_ResetBinds;
220 end;
221 {$ENDIF}
223 procedure g_Options_SetDefault();
224 var
225 i: Integer;
226 begin
227 (* section Sound *)
228 gNoSound := False;
229 gSoundLevel := 75;
230 gMusicLevel := 65;
231 gMaxSimSounds := 8;
232 gMuteWhenInactive := False;
233 gAnnouncer := ANNOUNCE_MEPLUS;
234 gSoundEffectsDF := True;
235 gUseChatSounds := True;
236 gsSDLSampleRate := 44100;
237 gsSDLBufferSize := 2048;
239 g_Sound_SetupAllVolumes(gSoundLevel, gMusicLevel);
241 with gPlayer1Settings do
242 begin
243 Name := GenPlayerName(1);
244 Model := STD_PLAYER_MODEL;
245 Color.R := PLAYER1_DEF_COLOR.R;
246 Color.G := PLAYER1_DEF_COLOR.G;
247 Color.B := PLAYER1_DEF_COLOR.B;
248 Team := TEAM_RED;
249 end;
251 with gPlayer2Settings do
252 begin
253 Name := GenPlayerName(2);
254 Model := STD_PLAYER_MODEL;
255 Color.R := PLAYER2_DEF_COLOR.R;
256 Color.G := PLAYER2_DEF_COLOR.G;
257 Color.B := PLAYER2_DEF_COLOR.B;
258 Team := TEAM_BLUE;
259 end;
261 (* section Joysticks *)
262 for i := 0 to e_MaxJoys - 1 do
263 begin
264 e_JoystickDeadzones[i] := 8192
265 end;
267 (* section Game *)
268 g_GFX_SetMax(2000);
269 g_Shells_SetMax(300);
270 g_Gibs_SetMax(150);
271 g_Corpses_SetMax(20);
272 gGibsCount := 32;
273 gBloodCount := 4;
274 gAdvBlood := True;
275 gAdvCorpses := True;
276 gAdvGibs := True;
277 gFlash := 1;
278 gDrawBackGround := True;
279 gShowMessages := True;
280 gRevertPlayers := False;
281 gChatBubble := 4;
282 wadoptDebug := False;
283 wadoptFast := False;
284 e_FastScreenshots := True;
285 gDefaultMegawadStart := DF_Default_Megawad_Start;
286 g_dbg_scale := 1.0;
287 gSaveStats := False;
289 gAskLanguage := True;
290 gLanguage := LANGUAGE_ENGLISH;
292 gsMap := '';
293 gsGameMode := _lc[I_MENU_GAME_TYPE_DM];
294 gsTimeLimit := 0;
295 gsScoreLimit := 0;
296 gsMaxLives := 0;
297 gsPlayers := 1;
298 gsSpawnInvul := 0;
299 gsItemRespawnTime := 60;
300 gsGameFlags := GAME_OPTION_ALLOWEXIT or GAME_OPTION_DMKEYS or
301 GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER or
302 GAME_OPTION_TEAMHITTRACE or GAME_OPTION_TEAMHITPROJECTILE or
303 GAME_OPTION_ALLOWDROPFLAG;
304 gsPlayers := 1;
306 if not gGameOn then
307 g_Options_ApplyGameSettings;
309 (* section MasterServer *)
310 NetMasterList := 'mpms.doom2d.org:25665, deadsoftware.ru:25665, terminalcorner.ru:25665';
311 g_Net_Slist_Set(NetMasterList);
313 (* section Server *)
314 NetServerName := 'Unnamed Server';
315 NetPassword := '';
316 NetPort := 25666;
317 NetMaxClients := 16;
318 NetAllowRCON := False;
319 NetRCONPassword := 'default';
320 NetUseMaster := True;
321 NetUpdateRate := 0;
322 NetRelupdRate := 18;
323 NetMasterRate := 60000;
324 NetForwardPorts := False;
326 (* section Client *)
327 NetInterpLevel := 2;
328 NetForcePlayerUpdate := False;
329 NetPredictSelf := True;
330 NetClientIP := '127.0.0.1';
331 NetClientPort := NetPort;
332 end;
334 procedure g_Options_ApplyGameSettings;
335 begin
336 with gGameSettings do
337 begin
338 GameMode := g_Game_TextToMode(gsGameMode);
339 if GameMode = GM_NONE then
340 GameMode := GM_DM;
341 if GameMode = GM_SINGLE then
342 GameMode := GM_COOP;
343 TimeLimit := gsTimeLimit;
344 ScoreLimit := gsScoreLimit;
345 MaxLives := gsMaxLives;
346 SpawnInvul := gsSpawnInvul;
347 ItemRespawnTime := gsItemRespawnTime;
348 WarmupTime := gsWarmupTime;
349 Options := gsGameFlags;
350 end;
351 end;
353 initialization
354 Randomize;
355 machine := Random(10000);
357 (* Video *)
358 conRegVar('r_width', @gRC_Width, '', '');
359 conRegVar('r_height', @gRC_Height, '', '');
360 conRegVar('r_fullscreen', @gRC_FullScreen, '', '');
361 conRegVar('r_maximized', @gRC_Maximized, '', '');
362 conRegVar('r_bpp', @gBPP, '', '');
363 conRegVar('r_vsync', @gVSync, '', '');
364 conRegVar('r_texfilter', @gTextureFilter, '', '');
365 conRegVar('r_npot', @glNPOTOverride, '', '');
366 conRegVar('r_interp', @gLerpActors, '', 'interpolate actors');
367 conRegVar('r_scale', @g_dbg_scale, 0.01, 100.0, 'render scale', '', false);
368 conRegVar('r_resolution_scale', @r_pixel_scale, 0.01, 100.0, 'upscale factor', '', false);
370 (* Sound *)
371 conRegVar('s_nosound', @gNoSound, '', '');
372 conRegVar('s_soundvolume', @gSoundLevel, '', '');
373 conRegVar('s_musicvolume', @gMusicLevel, '', '');
374 conRegVar('s_maxsim', @gMaxSimSounds, '', ''); // e_sound_fmod/sdl?
375 conRegVar('s_muteinactive', @gMuteWhenInactive, '', '');
376 conRegVar('s_announcer', @gAnnouncer, '', '');
377 conRegVar('s_sfx', @gSoundEffectsDF, '', '');
378 conRegVar('s_chatsounds', @gUseChatSounds, '', '');
379 {$IFDEF USE_SDLMIXER}
380 conRegVar('sdl_mixer_samplerate', @gsSDLSampleRate, '', '');
381 conRegVar('sdl_mixer_buffersize', @gsSDLBufferSize, '', '');
382 {$ENDIF}
384 (* Game *)
385 conRegVar('g_gibs_count', @gGibsCount, '', '');
386 conRegVar('g_blood_count', @gBloodCount, '', '');
387 conRegVar('g_adv_blood', @gAdvBlood, '', '');
388 conRegVar('g_adv_corpses', @gAdvCorpses, '', '');
389 conRegVar('g_adv_gibs', @gAdvGibs, '', '');
390 conRegVar('r_flash', @gFlash, '', '');
391 conRegVar('r_background', @gDrawBackGround, '', '');
392 conRegVar('g_show_messages', @gShowMessages, '', '');
393 conRegVar('r_revert_players', @gRevertPlayers, '', '');
394 conRegVar('r_chat_bubble', @gChatBubble, '', '');
395 conRegVar('sfs_debug', @wadoptDebug, '', '');
396 conRegVar('sfs_fastmode', @wadoptFast, '', '');
397 conRegVar('g_fast_screenshots', @e_FastScreenshots, '', '');
398 conRegVar('g_default_megawad', @gDefaultMegawadStart, '', '');
399 conRegVar('g_save_stats', @gSaveStats, '', '');
400 conRegVar('g_screenshot_stats', @gScreenshotStats, '', '');
401 conRegVar('g_lastmap', @gsMap, '', '');
402 end.