DEADSOFTWARE

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