DEADSOFTWARE

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