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