DEADSOFTWARE

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