DEADSOFTWARE

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