DEADSOFTWARE

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