DEADSOFTWARE

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