DEADSOFTWARE

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