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