DEADSOFTWARE

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