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