DEADSOFTWARE

fix (?) survival spectator; add space after comma in masterlist
[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 gNoSound: Boolean;
42 gSoundLevel: Integer;
43 gMusicLevel: Integer;
44 gMaxSimSounds: Integer;
45 gMuteWhenInactive: Boolean;
46 gAdvCorpses: Boolean;
47 gAdvBlood: Boolean;
48 gAdvGibs: Boolean;
49 gGibsCount: Integer;
50 gBloodCount: Integer;
51 gFlash: Integer;
52 gDrawBackGround: Boolean;
53 gShowMessages: Boolean;
54 gRevertPlayers: Boolean;
55 gLanguage: String;
56 gAskLanguage: Boolean;
57 gSaveStats: Boolean = False;
58 gScreenshotStats: Boolean = False;
59 gsSDLSampleRate: Integer;
60 gsSDLBufferSize: Integer;
61 gDefaultMegawadStart: AnsiString;
62 gBerserkAutoswitch: Boolean;
63 glNPOTOverride: Boolean = false;
65 (* Latched game settings *)
66 gsMap: String;
67 gsGameMode: String;
68 gsTimeLimit: Word;
69 gsGoalLimit: Word;
70 gsMaxLives: Byte;
71 gsPlayers: Byte;
72 gsGameFlags: LongWord;
73 gsSpawnInvul: Integer = 0;
74 gsItemRespawnTime: Word = 60;
75 gsWarmupTime: Word = 30;
77 implementation
79 uses
80 {$INCLUDE ../nogl/noGLuses.inc}
81 {$IFDEF USE_SDL2}
82 SDL2,
83 {$ENDIF}
84 e_log, e_input, g_console, g_window, g_sound, g_gfx, g_player, Math,
85 g_map, g_net, g_netmaster, SysUtils, CONFIG, g_game, g_main, e_texture,
86 g_items, wadreader, e_graphics, g_touch, envvars, g_system;
88 var
89 machine: Integer;
91 function GenPlayerName (n: Integer): String;
92 begin
93 ASSERT(n >= 1);
94 Result := GetUserName;
95 if Result = '' then
96 Result := 'Player' + IntToStr(machine MOD 10000);
97 if n = 1 then
98 Result := Copy(Result, 1, 12) + ' '
99 else
100 Result := Copy(Result, 1, 10) + ' ' + IntToStr(n)
101 end;
103 {$IFDEF USE_SDL2}
104 procedure g_Options_SetDefaultVideo;
105 var display: TSDL_DisplayMode;
106 {$IFNDEF ANDROID}
107 var target, closest: TSDL_DisplayMode; percentage: Integer;
108 {$ENDIF}
109 begin
110 (* Display 0 = Primary display *)
111 gScreenWidth := 640;
112 gScreenHeight := 480;
113 gWinSizeX := 640;
114 gWinSizeY := 480;
115 //gBPP := SDL_BITSPERPIXEL(dispaly.format);
116 gBPP := 32;
117 {$IFDEF ANDROID}
118 gFullScreen := True; (* rotation not allowed? *)
119 {$ELSE}
120 gFullScreen := False;
121 {$ENDIF}
122 if SDL_GetDesktopDisplayMode(0, @display) = 0 then
123 begin
124 {$IFDEF ANDROID}
125 gWinSizeX := display.w;
126 gWinSizeY := display.h;
127 {$ELSE}
128 (* Window must be smaller than display *)
129 closest.w := display.w;
130 closest.h := display.h;
131 percentage := 75;
132 while (display.w - closest.w < 48) or (display.h - closest.h < 48) do
133 begin
134 if percentage < 25 then
135 begin
136 closest.w := display.w * 75 div 100;
137 closest.h := display.h * 75 div 100;
138 break;
139 end;
140 target.w := display.w * percentage div 100;
141 target.h := display.h * percentage div 100;
142 target.format := 0; (* didn't care *)
143 target.refresh_rate := 0; (* didn't care *)
144 target.driverdata := nil; (* init *)
145 SDL_GetClosestDisplayMode(0, @target, @closest);
146 Dec(percentage);
147 end;
148 gWinSizeX := closest.w;
149 gWinSizeY := closest.h;
150 //gBPP := SDL_BITSPERPIXEL(closest.format); (* Resolution list didn't work for some reason *)
151 {$ENDIF}
152 end
153 else
154 begin
155 e_LogWritefln('SDL: Failed to get desktop display mode: %s', [SDL_GetError])
156 end;
157 (* Must be positioned on primary display *)
158 gWinMaximized := False;
159 gVSync := True;
160 gTextureFilter := True;
161 glLegacyNPOT := False;
162 gRC_Width := gWinSizeX;
163 gRC_Height := gWinSizeY;
164 gRC_FullScreen := gFullScreen;
165 gRC_Maximized := gWinMaximized;
166 e_LogWriteLn('g_Options_SetDefaultVideo: w = ' + IntToStr(gWinSizeX) + ' h = ' + IntToStr(gWinSizeY));
167 g_Console_ResetBinds;
168 end;
169 {$ELSE}
170 procedure g_Options_SetDefaultVideo;
171 begin
172 gWinSizeX := 640;
173 gWinSizeY := 480;
174 gBPP := 32;
175 gFullScreen := False;
176 gWinMaximized := False;
177 gVSync := True;
178 gTextureFilter := True;
179 glLegacyNPOT := False;
180 gScreenWidth := gWinSizeX;
181 gScreenHeight := gWinSizeY;
182 gRC_Width := gWinSizeX;
183 gRC_Height := gWinSizeY;
184 gRC_FullScreen := gFullScreen;
185 gRC_Maximized := gWinMaximized;
186 e_LogWriteLn('g_Options_SetDefaultVideo: w = ' + IntToStr(gWinSizeX) + ' h = ' + IntToStr(gWinSizeY));
187 g_Console_ResetBinds;
188 end;
189 {$ENDIF}
191 procedure g_Options_SetDefault();
192 var
193 i: Integer;
194 begin
195 (* section Sound *)
196 gNoSound := False;
197 gSoundLevel := 75;
198 gMusicLevel := 65;
199 gMaxSimSounds := 8;
200 gMuteWhenInactive := False;
201 gAnnouncer := ANNOUNCE_MEPLUS;
202 gSoundEffectsDF := True;
203 gUseChatSounds := True;
204 gsSDLSampleRate := 44100;
205 gsSDLBufferSize := 2048;
207 g_Sound_SetupAllVolumes(gSoundLevel, gMusicLevel);
209 with gPlayer1Settings do
210 begin
211 Name := GenPlayerName(1);
212 Model := STD_PLAYER_MODEL;
213 Color.R := PLAYER1_DEF_COLOR.R;
214 Color.G := PLAYER1_DEF_COLOR.G;
215 Color.B := PLAYER1_DEF_COLOR.B;
216 Team := TEAM_RED;
217 end;
219 with gPlayer2Settings do
220 begin
221 Name := GenPlayerName(2);
222 Model := STD_PLAYER_MODEL;
223 Color.R := PLAYER2_DEF_COLOR.R;
224 Color.G := PLAYER2_DEF_COLOR.G;
225 Color.B := PLAYER2_DEF_COLOR.B;
226 Team := TEAM_BLUE;
227 end;
229 (* section Joysticks *)
230 for i := 0 to e_MaxJoys - 1 do
231 begin
232 e_JoystickDeadzones[i] := 8192
233 end;
235 (* section Game *)
236 g_GFX_SetMax(2000);
237 g_Shells_SetMax(300);
238 g_Gibs_SetMax(150);
239 g_Corpses_SetMax(20);
240 gGibsCount := 32;
241 gBloodCount := 4;
242 gAdvBlood := True;
243 gAdvCorpses := True;
244 gAdvGibs := True;
245 gFlash := 1;
246 gDrawBackGround := True;
247 gShowMessages := True;
248 gRevertPlayers := False;
249 gChatBubble := 4;
250 wadoptDebug := False;
251 wadoptFast := False;
252 e_FastScreenshots := True;
253 gDefaultMegawadStart := DF_Default_Megawad_Start;
254 gBerserkAutoswitch := True;
255 g_dbg_scale := 1.0;
256 gSaveStats := False;
258 gAskLanguage := True;
259 gLanguage := LANGUAGE_ENGLISH;
261 gsMap := '';
262 gsGameMode := _lc[I_MENU_GAME_TYPE_DM];
263 gsTimeLimit := 0;
264 gsGoalLimit := 0;
265 gsMaxLives := 0;
266 gsPlayers := 1;
267 gsSpawnInvul := 0;
268 gsItemRespawnTime := 60;
269 gsGameFlags := GAME_OPTION_ALLOWEXIT or GAME_OPTION_DMKEYS or
270 GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER;
271 gsPlayers := 1;
273 (* section MasterServer *)
274 NetMasterList := 'mpms.doom2d.org:25665, deadsoftware.ru:25665';
275 g_Net_Slist_Set(NetMasterList);
277 (* section Server *)
278 NetServerName := 'Unnamed Server';
279 NetPassword := '';
280 NetPort := 25666;
281 NetMaxClients := 16;
282 NetAllowRCON := False;
283 NetRCONPassword := 'default';
284 NetUseMaster := True;
285 NetUpdateRate := 0;
286 NetRelupdRate := 18;
287 NetMasterRate := 60000;
288 NetForwardPorts := False;
290 (* section Client *)
291 NetInterpLevel := 2;
292 NetForcePlayerUpdate := False;
293 NetPredictSelf := True;
294 NetClientIP := '127.0.0.1';
295 NetClientPort := NetPort;
296 end;
298 procedure g_Options_ApplyGameSettings;
299 begin
300 with gGameSettings do
301 begin
302 GameMode := g_Game_TextToMode(gsGameMode);
303 if GameMode = GM_NONE then
304 GameMode := GM_DM;
305 if GameMode = GM_SINGLE then
306 GameMode := GM_COOP;
307 TimeLimit := gsTimeLimit;
308 GoalLimit := gsGoalLimit;
309 MaxLives := gsMaxLives;
310 SpawnInvul := gsSpawnInvul;
311 ItemRespawnTime := gsItemRespawnTime;
312 WarmupTime := gsWarmupTime;
313 Options := gsGameFlags;
314 end;
315 end;
317 initialization
318 Randomize;
319 machine := Random(10000);
321 (* Video *)
322 conRegVar('r_width', @gRC_Width, '', '');
323 conRegVar('r_height', @gRC_Height, '', '');
324 conRegVar('r_fullscreen', @gRC_FullScreen, '', '');
325 conRegVar('r_maximized', @gRC_Maximized, '', '');
326 conRegVar('r_bpp', @gBPP, '', '');
327 conRegVar('r_vsync', @gVSync, '', '');
328 conRegVar('r_texfilter', @gTextureFilter, '', '');
329 conRegVar('r_npot', @glNPOTOverride, '', '');
331 (* Sound *)
332 conRegVar('s_nosound', @gNoSound, '', '');
333 conRegVar('s_soundvolume', @gSoundLevel, '', '');
334 conRegVar('s_musicvolume', @gMusicLevel, '', '');
335 conRegVar('s_maxsim', @gMaxSimSounds, '', ''); // e_sound_fmod/sdl?
336 conRegVar('s_muteinactive', @gMuteWhenInactive, '', '');
337 conRegVar('s_announcer', @gAnnouncer, '', '');
338 conRegVar('s_sfx', @gSoundEffectsDF, '', '');
339 conRegVar('s_chatsounds', @gUseChatSounds, '', '');
340 {$IFDEF USE_SDLMIXER}
341 conRegVar('sdl_mixer_samplerate', @gsSDLSampleRate, '', '');
342 conRegVar('sdl_mixer_buffersize', @gsSDLBufferSize, '', '');
343 {$ENDIF}
345 (* Game *)
346 conRegVar('g_gibs_count', @gGibsCount, '', '');
347 conRegVar('g_blood_count', @gBloodCount, '', '');
348 conRegVar('g_adv_blood', @gAdvBlood, '', '');
349 conRegVar('g_adv_corpses', @gAdvCorpses, '', '');
350 conRegVar('g_adv_gibs', @gAdvGibs, '', '');
351 conRegVar('r_flash', @gFlash, '', '');
352 conRegVar('r_background', @gDrawBackGround, '', '');
353 conRegVar('g_show_messages', @gShowMessages, '', '');
354 conRegVar('r_revert_players', @gRevertPlayers, '', '');
355 conRegVar('r_chat_bubble', @gChatBubble, '', '');
356 conRegVar('sfs_debug', @wadoptDebug, '', '');
357 conRegVar('sfs_fastmode', @wadoptFast, '', '');
358 conRegVar('g_fast_screenshots', @e_FastScreenshots, '', '');
359 conRegVar('g_default_megawad', @gDefaultMegawadStart, '', '');
360 conRegVar('g_save_stats', @gSaveStats, '', '');
361 conRegVar('g_screenshot_stats', @gScreenshotStats, '', '');
362 conRegVar('g_lastmap', @gsMap, '', '');
363 end.