DEADSOFTWARE

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