DEADSOFTWARE

gfx: fixed OpenGL extension checks; fixed NPOT emulation detection
[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;
23 function GenPlayerName (n: Integer): String;
25 procedure g_Options_SetDefault();
26 procedure g_Options_Read(FileName: String);
27 procedure g_Options_Write(FileName: String);
28 procedure g_Options_Write_Language(FileName: String);
29 procedure g_Options_Write_Video(FileName: String);
30 procedure g_Options_Write_Gameplay_Custom(FileName: String);
31 procedure g_Options_Write_Gameplay_Net(FileName: String);
32 procedure g_Options_Write_Net_Server(FileName: String);
33 procedure g_Options_Write_Net_Client(FileName: String);
35 const DF_Default_Megawad_Start = 'megawads/DOOM2D.WAD:\MAP01';
37 var
38 // gGameControls: TControls;
39 gScreenWidth: Word;
40 gScreenHeight: Word;
41 gWinRealPosX: Integer;
42 gWinRealPosY: Integer;
43 gBPP: Byte;
44 gFreq: Byte;
45 gFullscreen: Boolean;
46 gWinMaximized: Boolean;
47 gVSync: Boolean;
48 glLegacyNPOT: Boolean;
49 gTextureFilter: Boolean;
50 gNoSound: Boolean;
51 gSoundLevel: Byte;
52 gMusicLevel: Byte;
53 gMaxSimSounds: Byte;
54 gMuteWhenInactive: Boolean;
55 gAdvCorpses: Boolean;
56 gAdvBlood: Boolean;
57 gAdvGibs: Boolean;
58 gGibsCount: Integer;
59 gBloodCount: Byte;
60 gFlash: Byte;
61 gDrawBackGround: Boolean;
62 gShowMessages: Boolean;
63 gRevertPlayers: Boolean;
64 gLanguage: String;
65 gAskLanguage: Boolean;
66 gcMap: String;
67 gcGameMode: String;
68 gcTimeLimit: Word;
69 gcGoalLimit: Word;
70 gcMaxLives: Byte;
71 gcPlayers: Byte;
72 gcTeamDamage: Boolean;
73 gcAllowExit: Boolean;
74 gcWeaponStay: Boolean;
75 gcMonsters: Boolean;
76 gcBotsVS: String;
77 gnMap: String;
78 gnGameMode: String;
79 gnTimeLimit: Word;
80 gnGoalLimit: Word;
81 gnMaxLives: Byte;
82 gnPlayers: Byte;
83 gnTeamDamage: Boolean;
84 gnAllowExit: Boolean;
85 gnWeaponStay: Boolean;
86 gnMonsters: Boolean;
87 gnBotsVS: String;
88 gsSDLSampleRate: Integer;
89 gsSDLBufferSize: Integer;
90 gSFSDebug: Boolean;
91 gSFSFastMode: Boolean;
92 gDefaultMegawadStart: AnsiString;
93 gBerserkAutoswitch: Boolean;
94 glNPOTOverride: Boolean = false;
96 implementation
98 uses
99 {$INCLUDE ../nogl/noGLuses.inc}
100 {$IFDEF USE_SDL2}
101 SDL2,
102 {$ENDIF}
103 e_log, e_input, g_console, g_window, g_sound, g_gfx, g_player, Math,
104 g_map, g_net, g_netmaster, SysUtils, CONFIG, g_game, g_main, e_texture,
105 g_items, wadreader, e_graphics, g_touch, envvars;
107 var
108 machine: Integer;
110 function GenPlayerName (n: Integer): String;
111 begin
112 ASSERT(n >= 1);
113 Result := GetUserName;
114 if Result = '' then
115 Result := 'Player' + IntToStr(machine MOD 10000);
116 if n = 1 then
117 Result := Copy(Result, 1, 12) + ' '
118 else
119 Result := Copy(Result, 1, 10) + ' ' + IntToStr(n)
120 end;
122 {$IFDEF USE_SDL2}
123 procedure g_Options_SetDefaultVideo;
124 var
125 target, closest, display: TSDL_DisplayMode;
126 percentage: Integer;
127 begin
128 (* Display 0 = Primary display *)
129 gScreenWidth := 640;
130 gScreenHeight := 480;
131 //gBPP := SDL_BITSPERPIXEL(dispaly.format);
132 gBPP := 32;
133 {$IFDEF ANDROID}
134 gFullScreen := True; (* rotation not allowed? *)
135 {$ELSE}
136 gFullScreen := False;
137 {$ENDIF}
138 if SDL_GetDesktopDisplayMode(0, @display) = 0 then
139 begin
140 {$IFDEF ANDROID}
141 gScreenWidth := display.w;
142 gScreenHeight := display.h;
143 {$ELSE}
144 (* Window must be smaller than display *)
145 closest.w := display.w;
146 closest.h := display.h;
147 percentage := 75;
148 while (display.w - closest.w < 48) or (display.h - closest.h < 48) do
149 begin
150 if percentage < 25 then
151 begin
152 closest.w := display.w * 75 div 100;
153 closest.h := display.h * 75 div 100;
154 break;
155 end;
156 target.w := display.w * percentage div 100;
157 target.h := display.h * percentage div 100;
158 target.format := 0; (* didn't care *)
159 target.refresh_rate := 0; (* didn't care *)
160 target.driverdata := nil; (* init *)
161 SDL_GetClosestDisplayMode(0, @target, @closest);
162 Dec(percentage);
163 end;
164 gScreenWidth := closest.w;
165 gScreenHeight := closest.h;
166 //gBPP := SDL_BITSPERPIXEL(closest.format); (* Resolution list didn't work for some reason *)
167 {$ENDIF}
168 end
169 else
170 begin
171 e_LogWritefln('SDL: Failed to get desktop display mode: %s', [SDL_GetError])
172 end;
173 (* Must be positioned on primary display *)
174 gWinRealPosX := SDL_WINDOWPOS_CENTERED;
175 gWinRealPosY := SDL_WINDOWPOS_CENTERED;
176 gWinMaximized := False;
177 gVSync := True;
178 gTextureFilter := True;
179 glLegacyNPOT := False;
180 e_LogWriteLn('g_Options_SetDefaultVideo: w = ' + IntToStr(gScreenWidth) + ' h = ' + IntToStr(gScreenHeight));
181 g_Console_ResetBinds;
182 end;
183 {$ELSE}
184 procedure g_Options_SetDefaultVideo;
185 begin
186 gScreenWidth := 640;
187 gScreenHeight := 480;
188 gBPP := 32;
189 gFullScreen := False;
190 gWinRealPosX := 0;
191 gWinRealPosY := 0;
192 gWinMaximized := False;
193 gVSync := True;
194 gTextureFilter := True;
195 glLegacyNPOT := False;
196 e_LogWriteLn('g_Options_SetDefaultVideo: w = ' + IntToStr(gScreenWidth) + ' h = ' + IntToStr(gScreenHeight));
197 g_Console_ResetBinds;
198 end;
199 {$ENDIF}
201 procedure g_Options_SetDefault();
202 var
203 i: Integer;
204 begin
205 (* section Sound *)
206 gNoSound := False;
207 gSoundLevel := 75;
208 gMusicLevel := 65;
209 gMaxSimSounds := 8;
210 gMuteWhenInactive := False;
211 gAnnouncer := ANNOUNCE_MEPLUS;
212 gSoundEffectsDF := True;
213 gUseChatSounds := True;
214 gsSDLSampleRate := 44100;
215 gsSDLBufferSize := 2048;
217 g_Sound_SetupAllVolumes(gSoundLevel, gMusicLevel);
219 with gPlayer1Settings do
220 begin
221 Name := GenPlayerName(1);
222 Model := STD_PLAYER_MODEL;
223 Color.R := PLAYER1_DEF_COLOR.R;
224 Color.G := PLAYER1_DEF_COLOR.G;
225 Color.B := PLAYER1_DEF_COLOR.B;
226 Team := TEAM_RED;
227 end;
229 with gPlayer2Settings do
230 begin
231 Name := GenPlayerName(2);
232 Model := STD_PLAYER_MODEL;
233 Color.R := PLAYER2_DEF_COLOR.R;
234 Color.G := PLAYER2_DEF_COLOR.G;
235 Color.B := PLAYER2_DEF_COLOR.B;
236 Team := TEAM_BLUE;
237 end;
239 (* section Joysticks *)
240 for i := 0 to e_MaxJoys - 1 do
241 begin
242 e_JoystickDeadzones[i] := 8192
243 end;
245 (* section Game *)
246 g_GFX_SetMax(2000);
247 g_Shells_SetMax(300);
248 g_Gibs_SetMax(150);
249 g_Corpses_SetMax(20);
250 gGibsCount := 32;
251 ITEM_RESPAWNTIME := 60 * 36;
252 gBloodCount := 4;
253 gAdvBlood := True;
254 gAdvCorpses := True;
255 gAdvGibs := True;
256 gFlash := 1;
257 gDrawBackGround := True;
258 gShowMessages := True;
259 gRevertPlayers := False;
260 gChatBubble := 4;
261 gSFSDebug := False;
262 gSFSFastMode := False;
263 e_FastScreenshots := True;
264 gDefaultMegawadStart := DF_Default_Megawad_Start;
265 gBerserkAutoswitch := True;
266 g_dbg_scale := 1.0;
268 gAskLanguage := True;
269 gLanguage := LANGUAGE_ENGLISH;
271 (* section GameplayCustom *)
272 gcMap := '';
273 gcGameMode := _lc[I_MENU_GAME_TYPE_DM];
274 gcTimeLimit := 0;
275 gcGoalLimit := 0;
276 gcMaxLives := 0;
277 gcPlayers := 1;
278 gcTeamDamage := False;
279 gcAllowExit := True;
280 gcWeaponStay := False;
281 gcMonsters := False;
282 gcBotsVS := 'Everybody';
284 (* section GameplayNetwork *)
285 gnMap := '';
286 gnGameMode := _lc[I_MENU_GAME_TYPE_DM];
287 gnTimeLimit := 0;
288 gnGoalLimit := 0;
289 gnMaxLives := 0;
290 gnPlayers := 1;
291 gnTeamDamage := False;
292 gnAllowExit := True;
293 gnWeaponStay := False;
294 gnMonsters := False;
295 gnBotsVS := 'Everybody';
297 (* section MasterServer *)
298 NetSlistIP := 'mpms.doom2d.org';
299 NetSlistPort := 25665;
300 g_Net_Slist_Set(NetSlistIP, NetSlistPort, NetSlistList);
302 (* section Server *)
303 NetServerName := 'Unnamed Server';
304 NetPassword := '';
305 NetPort := 25666;
306 NetMaxClients := 16;
307 NetAllowRCON := False;
308 NetRCONPassword := 'default';
309 NetUseMaster := True;
310 NetUpdateRate := 0;
311 NetRelupdRate := 18;
312 NetMasterRate := 60000;
313 NetForwardPorts := False;
315 (* section Client *)
316 NetInterpLevel := 2;
317 NetForcePlayerUpdate := False;
318 NetPredictSelf := True;
319 NetClientIP := '127.0.0.1';
320 NetClientPort := NetPort;
321 end;
323 procedure g_Options_Read(FileName: String);
324 var
325 i: Integer;
326 config: TConfig;
327 section: String;
329 procedure ReadInteger (VAR v: Integer; param: String; minv: Integer = Low(Integer); maxv: Integer = High(Integer));
330 begin
331 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
332 end;
334 procedure ReadInteger (VAR v: LongWord; param: String; minv: LongWord = Low(LongWord); maxv: LongWord = High(LongWord)); overload;
335 begin
336 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
337 end;
339 procedure ReadInteger (VAR v: Word; param: String; minv: Word = Low(Word); maxv: Word = High(Word)); overload;
340 begin
341 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
342 end;
344 procedure ReadInteger (VAR v: Byte; param: String; minv: Byte = Low(Byte); maxv: Byte = High(Byte)); overload;
345 begin
346 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
347 end;
349 procedure ReadBoolean (VAR v: Boolean; param: String);
350 begin
351 v := config.ReadBool(section, param, v)
352 end;
354 procedure ReadString (VAR v: String; param: String);
355 begin
356 v := config.ReadStr(section, param, v)
357 end;
359 begin
360 gAskLanguage := True;
361 e_WriteLog('Reading config', TMsgType.Notify);
362 g_Options_SetDefault;
364 if FileExists(FileName) = False then
365 begin
366 e_WriteLog('Config file '+FileName+' not found', TMsgType.Warning);
367 g_Options_SetDefaultVideo;
368 Exit
369 end;
371 config := TConfig.CreateFile(FileName);
373 section := 'Video';
374 ReadInteger(gScreenWidth, 'ScreenWidth', 0);
375 ReadInteger(gScreenHeight, 'ScreenHeight', 0);
376 ReadInteger(gWinRealPosX, 'WinPosX', 60);
377 ReadInteger(gWinRealPosY, 'WinPosY', 60);
378 ReadBoolean(gFullScreen, 'Fullscreen');
379 ReadBoolean(gWinMaximized, 'Maximized');
380 ReadInteger(gBPP, 'BPP', 0);
381 ReadInteger(gFreq, 'Freq', 0);
382 ReadBoolean(gVSync, 'VSync');
383 ReadBoolean(gTextureFilter, 'TextureFilter');
384 ReadBoolean(glNPOTOverride, 'LegacyCompatibleForce');
386 section := 'Sound';
387 ReadBoolean(gNoSound, 'NoSound');
388 ReadInteger(gSoundLevel, 'SoundLevel', 0, 255);
389 ReadInteger(gMusicLevel, 'MusicLevel', 0, 255);
390 ReadInteger(gMaxSimSounds, 'MaxSimSounds', 2, 66);
391 ReadBoolean(gMuteWhenInactive, 'MuteInactive');
392 ReadInteger(gAnnouncer, 'Announcer', ANNOUNCE_NONE, ANNOUNCE_ALL);
393 ReadBoolean(gSoundEffectsDF, 'SoundEffectsDF');
394 ReadBoolean(gUseChatSounds, 'ChatSounds');
395 ReadInteger(gsSDLSampleRate, 'SDLSampleRate', 11025, 96000);
396 ReadInteger(gsSDLBufferSize, 'SDLBufferSize', 64, 16384);
398 section := 'Player1';
399 with gPlayer1Settings do
400 begin
401 ReadString(Name, 'name');
402 ReadString(Model, 'model');
403 ReadInteger(Color.R, 'red', 0, 255);
404 ReadInteger(Color.G, 'green', 0, 255);
405 ReadInteger(Color.B, 'blue', 0, 255);
406 ReadInteger(Team, 'team');
407 if (Team < TEAM_RED) or (Team > TEAM_BLUE) then
408 Team := TEAM_RED;
409 end;
411 section := 'Player2';
412 with gPlayer2Settings do
413 begin
414 ReadString(Name, 'name');
415 ReadString(Model, 'model');
416 ReadInteger(Color.R, 'red', 0, 255);
417 ReadInteger(Color.G, 'green', 0, 255);
418 ReadInteger(Color.B, 'blue', 0, 255);
419 ReadInteger(Team, 'team');
420 if (Team < TEAM_RED) or (Team > TEAM_BLUE) then
421 Team := TEAM_RED;
422 end;
424 section := 'Joysticks';
425 for i := 0 to e_MaxJoys - 1 do
426 begin
427 ReadInteger(e_JoystickDeadzones[i], 'Deadzone' + IntToStr(i))
428 end;
430 section := 'Game';
431 ReadInteger(i, 'MaxParticles', 0, 50000); g_GFX_SetMax(i);
432 ReadInteger(i, 'MaxShells', 0, 600); g_Shells_SetMax(i);
433 ReadInteger(i, 'MaxGibs', 0, 500); g_Gibs_SetMax(i);
434 ReadInteger(i, 'MaxCorpses', 0, 100); g_Corpses_SetMax(i);
435 ReadInteger(i, 'GibsCount');
436 case i of
437 0: gGibsCount := 0;
438 1: gGibsCount := 8;
439 2: gGibsCount := 16;
440 3: gGibsCount := 32;
441 else gGibsCount := 48;
442 end;
443 i := ITEM_RESPAWNTIME div 36; ReadInteger(i, 'ItemRespawnTime', 0); ITEM_RESPAWNTIME := i * 36;
444 ReadInteger(gBloodCount, 'BloodCount', 0, 4);
445 ReadBoolean(gAdvBlood, 'AdvancesBlood');
446 ReadBoolean(gAdvCorpses, 'AdvancesCorpses');
447 ReadBoolean(gAdvGibs, 'AdvancesGibs');
448 ReadInteger(gFlash, 'Flash', 0, 2);
449 ReadBoolean(gDrawBackGround, 'BackGround');
450 ReadBoolean(gShowMessages, 'Messages');
451 ReadBoolean(gRevertPlayers, 'RevertPlayers');
452 ReadInteger(gChatBubble, 'ChatBubble', 0, 4);
453 ReadBoolean(gSFSDebug, 'SFSDebug'); wadoptDebug := gSFSDebug;
454 ReadBoolean(gSFSFastMode, 'SFSFastMode'); wadoptFast := gSFSFastMode;
455 ReadBoolean(e_FastScreenshots, 'FastScreenshots');
456 ReadString(gDefaultMegawadStart, 'DefaultMegawadStart');
457 ReadBoolean(gBerserkAutoswitch, 'BerserkAutoswitching');
458 i := Trunc(g_dbg_scale * 100); ReadInteger(i, 'Scale', 100); g_dbg_scale := i / 100;
459 ReadString(gLanguage, 'Language');
460 if (gLanguage = LANGUAGE_RUSSIAN) or (gLanguage = LANGUAGE_ENGLISH) then
461 gAskLanguage := False
462 else
463 gLanguage := LANGUAGE_ENGLISH;
465 section := 'GameplayCustom';
466 ReadString(gcMap, 'Map');
467 ReadString(gcGameMode, 'GameMode');
468 ReadInteger(gcTimeLimit, 'TimeLimit', 0, 65535);
469 ReadInteger(gcGoalLimit, 'GoalLimit', 0, 65535);
470 ReadInteger(gcMaxLives, 'MaxLives', 0, 255);
471 ReadInteger(gcPlayers, 'Players', 0, 2);
472 ReadBoolean(gcTeamDamage, 'TeamDamage');
473 ReadBoolean(gcAllowExit, 'AllowExit');
474 ReadBoolean(gcWeaponStay, 'WeaponStay');
475 ReadBoolean(gcMonsters, 'Monsters');
476 ReadString(gcBotsVS, 'BotsVS');
478 with gGameSettings do
479 begin
480 GameMode := g_Game_TextToMode(gcGameMode);
481 if GameMode = GM_NONE then
482 GameMode := GM_DM;
483 if GameMode = GM_SINGLE then
484 GameMode := GM_COOP;
485 TimeLimit := gcTimeLimit;
486 GoalLimit := gcGoalLimit;
487 MaxLives := gcMaxLives;
489 Options := 0;
490 if gcTeamDamage then
491 Options := Options or GAME_OPTION_TEAMDAMAGE;
492 if gcAllowExit then
493 Options := Options or GAME_OPTION_ALLOWEXIT;
494 if gcWeaponStay then
495 Options := Options or GAME_OPTION_WEAPONSTAY;
496 if gcMonsters then
497 Options := Options or GAME_OPTION_MONSTERS;
498 if gcBotsVS = 'Everybody' then
499 Options := Options or GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER;
500 if gcBotsVS = 'Players' then
501 Options := Options or GAME_OPTION_BOTVSPLAYER;
502 if gcBotsVS = 'Monsters' then
503 Options := Options or GAME_OPTION_BOTVSMONSTER;
504 end;
506 section := 'GameplayNetwork';
507 ReadString(gnMap, 'Map');
508 ReadString(gnGameMode, 'GameMode');
509 ReadInteger(gnTimeLimit, 'TimeLimit', 0, 65535);
510 ReadInteger(gnGoalLimit, 'GoalLimit', 0, 65535);
511 ReadInteger(gnMaxLives, 'MaxLives', 0, 255);
512 ReadInteger(gnPlayers, 'Players', 0, 2);
513 ReadBoolean(gnTeamDamage, 'TeamDamage');
514 ReadBoolean(gnAllowExit, 'AllowExit');
515 ReadBoolean(gnWeaponStay, 'WeaponStay');
516 ReadBoolean(gnMonsters, 'Monsters');
517 ReadString(gnBotsVS, 'BotsVS');
519 section := 'MasterServer';
520 ReadString(NetSlistIP, 'IP');
521 ReadInteger(NetSlistPort, 'Port', 0, 65535);
522 ReadString(NetSlistList, 'List');
523 g_Net_Slist_Set(NetSlistIP, NetSlistPort, NetSlistList);
525 section := 'Server';
526 ReadString(NetServerName, 'Name');
527 ReadString(NetPassword, 'Password');
528 ReadInteger(NetPort, 'Port', 0, 65535);
529 ReadInteger(NetMaxClients, 'MaxClients', 0, NET_MAXCLIENTS);
530 ReadBoolean(NetAllowRCON, 'RCON');
531 ReadString(NetRCONPassword, 'RCONPassword');
532 ReadBoolean(NetUseMaster, 'SyncWithMaster');
533 ReadInteger(NetUpdateRate, 'UpdateInterval', 0);
534 ReadInteger(NetRelupdRate, 'ReliableUpdateInterval', 0);
535 ReadInteger(NetMasterRate, 'MasterSyncInterval', 1);
536 ReadBoolean(NetForwardPorts, 'ForwardPorts');
538 section := 'Client';
539 ReadInteger(NetInterpLevel, 'InterpolationSteps', 0);
540 ReadBoolean(NetForcePlayerUpdate, 'ForcePlayerUpdate');
541 ReadBoolean(NetPredictSelf, 'PredictSelf');
542 ReadString(NetClientIP, 'LastIP');
543 ReadInteger(NetClientPort, 'LastPort', 0, 65535);
545 config.Free();
547 //if gTextureFilter then TEXTUREFILTER := GL_LINEAR else TEXTUREFILTER := GL_NEAREST;
548 end;
550 procedure g_Options_Write(FileName: String);
551 var
552 config: TConfig;
553 i: Integer;
554 begin
555 e_WriteLog('Writing config', TMsgType.Notify);
557 config := TConfig.CreateFile(FileName);
559 config.WriteInt('Video', 'ScreenWidth', gScreenWidth);
560 config.WriteInt('Video', 'ScreenHeight', gScreenHeight);
561 config.WriteInt('Video', 'WinPosX', gWinRealPosX);
562 config.WriteInt('Video', 'WinPosY', gWinRealPosY);
563 config.WriteBool('Video', 'Fullscreen', gFullScreen);
564 config.WriteBool('Video', 'Maximized', gWinMaximized);
565 config.WriteInt('Video', 'BPP', gBPP);
566 config.WriteBool('Video', 'VSync', gVSync);
567 config.WriteBool('Video', 'TextureFilter', gTextureFilter);
568 config.WriteBool('Video', 'LegacyCompatibleForce', glNPOTOverride);
570 config.WriteBool('Sound', 'NoSound', gNoSound);
571 config.WriteInt('Sound', 'SoundLevel', gSoundLevel);
572 config.WriteInt('Sound', 'MusicLevel', gMusicLevel);
573 config.WriteInt('Sound', 'MaxSimSounds', gMaxSimSounds);
574 config.WriteBool('Sound', 'MuteInactive', gMuteWhenInactive);
575 config.WriteInt('Sound', 'Announcer', gAnnouncer);
576 config.WriteBool('Sound', 'SoundEffectsDF', gSoundEffectsDF);
577 config.WriteBool('Sound', 'ChatSounds', gUseChatSounds);
578 config.WriteInt('Sound', 'SDLSampleRate', gsSDLSampleRate);
579 config.WriteInt('Sound', 'SDLBufferSize', gsSDLBufferSize);
581 with config, gPlayer1Settings do
582 begin
583 WriteStr('Player1', 'Name', Name);
584 WriteStr('Player1', 'model', Model);
585 WriteInt('Player1', 'red', Color.R);
586 WriteInt('Player1', 'green', Color.G);
587 WriteInt('Player1', 'blue', Color.B);
588 WriteInt('Player1', 'team', Team);
589 end;
591 with config, gPlayer2Settings do
592 begin
593 WriteStr('Player2', 'Name', Name);
594 WriteStr('Player2', 'model', Model);
595 WriteInt('Player2', 'red', Color.R);
596 WriteInt('Player2', 'green', Color.G);
597 WriteInt('Player2', 'blue', Color.B);
598 WriteInt('Player2', 'team', Team);
599 end;
601 for i := 0 to e_MaxJoys-1 do
602 config.WriteInt('Joysticks', 'Deadzone' + IntToStr(i), e_JoystickDeadzones[i]);
604 with config do
605 case gGibsCount of
606 0: config.WriteInt('Game', 'GibsCount', 0);
607 8: config.WriteInt('Game', 'GibsCount', 1);
608 16: config.WriteInt('Game', 'GibsCount', 2);
609 32: config.WriteInt('Game', 'GibsCount', 3);
610 else config.WriteInt('Game', 'GibsCount', 4);
611 end;
613 config.WriteInt('Game', 'ItemRespawnTime', ITEM_RESPAWNTIME div 36);
614 config.WriteInt('Game', 'MaxParticles', g_GFX_GetMax());
615 config.WriteInt('Game', 'MaxShells', g_Shells_GetMax());
616 config.WriteInt('Game', 'MaxGibs', g_Gibs_GetMax());
617 config.WriteInt('Game', 'MaxCorpses', g_Corpses_GetMax());
618 config.WriteInt('Game', 'BloodCount', gBloodCount);
619 config.WriteBool('Game', 'AdvancesBlood', gAdvBlood);
620 config.WriteBool('Game', 'AdvancesCorpses', gAdvCorpses);
621 config.WriteBool('Game', 'AdvancesGibs', gAdvGibs);
622 config.WriteInt('Game', 'Flash', gFlash);
623 config.WriteBool('Game', 'BackGround', gDrawBackGround);
624 config.WriteBool('Game', 'Messages', gShowMessages);
625 config.WriteBool('Game', 'RevertPlayers', gRevertPlayers);
626 config.WriteInt('Game', 'ChatBubble', gChatBubble);
627 config.WriteBool('Game', 'SFSDebug', gSFSDebug);
628 config.WriteBool('Game', 'SFSFastMode', gSFSFastMode);
629 config.WriteBool('Game', 'FastScreenshots', e_FastScreenshots);
630 config.WriteStr('Game', 'DefaultMegawadStart', gDefaultMegawadStart);
631 config.WriteBool('Game', 'BerserkAutoswitching', gBerserkAutoswitch);
632 config.WriteInt('Game', 'Scale', Round(g_dbg_scale * 100));
634 config.WriteStr ('GameplayCustom', 'Map', gcMap);
635 config.WriteStr ('GameplayCustom', 'GameMode', gcGameMode);
636 config.WriteInt ('GameplayCustom', 'TimeLimit', gcTimeLimit);
637 config.WriteInt ('GameplayCustom', 'GoalLimit', gcGoalLimit);
638 config.WriteInt ('GameplayCustom', 'MaxLives', gcMaxLives);
639 config.WriteInt ('GameplayCustom', 'Players', gcPlayers);
640 config.WriteBool('GameplayCustom', 'TeamDamage', gcTeamDamage);
641 config.WriteBool('GameplayCustom', 'AllowExit', gcAllowExit);
642 config.WriteBool('GameplayCustom', 'WeaponStay', gcWeaponStay);
643 config.WriteBool('GameplayCustom', 'Monsters', gcMonsters);
644 config.WriteStr ('GameplayCustom', 'BotsVS', gcBotsVS);
646 config.WriteStr ('GameplayNetwork', 'Map', gnMap);
647 config.WriteStr ('GameplayNetwork', 'GameMode', gnGameMode);
648 config.WriteInt ('GameplayNetwork', 'TimeLimit', gnTimeLimit);
649 config.WriteInt ('GameplayNetwork', 'GoalLimit', gnGoalLimit);
650 config.WriteInt ('GameplayNetwork', 'MaxLives', gnMaxLives);
651 config.WriteInt ('GameplayNetwork', 'Players', gnPlayers);
652 config.WriteBool('GameplayNetwork', 'TeamDamage', gnTeamDamage);
653 config.WriteBool('GameplayNetwork', 'AllowExit', gnAllowExit);
654 config.WriteBool('GameplayNetwork', 'WeaponStay', gnWeaponStay);
655 config.WriteBool('GameplayNetwork', 'Monsters', gnMonsters);
656 config.WriteStr ('GameplayNetwork', 'BotsVS', gnBotsVS);
658 config.WriteStr('MasterServer', 'IP', NetSlistIP);
659 config.WriteInt('MasterServer', 'Port', NetSlistPort);
660 config.WriteStr('MasterServer', 'List', NetSlistList);
662 config.WriteStr ('Server', 'Name', NetServerName);
663 config.WriteStr ('Server', 'Password', NetPassword);
664 config.WriteInt ('Server', 'Port', NetPort);
665 config.WriteInt ('Server', 'MaxClients', NetMaxClients);
666 config.WriteBool('Server', 'RCON', NetAllowRCON);
667 config.WriteStr ('Server', 'RCONPassword', NetRCONPassword);
668 config.WriteBool('Server', 'SyncWithMaster', NetUseMaster);
669 config.WriteBool('Server', 'ForwardPorts', NetForwardPorts);
670 config.WriteInt ('Server', 'UpdateInterval', NetUpdateRate);
671 config.WriteInt ('Server', 'ReliableUpdateInterval', NetRelupdRate);
672 config.WriteInt ('Server', 'MasterSyncInterval', NetMasterRate);
674 config.WriteInt ('Client', 'InterpolationSteps', NetInterpLevel);
675 config.WriteBool ('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate);
676 config.WriteBool ('Client', 'PredictSelf', NetPredictSelf);
677 config.WriteStr ('Client', 'LastIP', NetClientIP);
678 config.WriteInt ('Client', 'LastPort', NetClientPort);
680 config.SaveFile(FileName);
681 config.Free();
682 end;
684 procedure g_Options_Write_Language(FileName: String);
685 var
686 config: TConfig;
687 begin
688 e_WriteLog('Writing language config', TMsgType.Notify);
690 config := TConfig.CreateFile(FileName);
691 config.WriteStr('Game', 'Language', gLanguage);
692 config.SaveFile(FileName);
693 config.Free();
694 end;
696 procedure g_Options_Write_Video(FileName: String);
697 var
698 config: TConfig;
699 sW, sH: Integer;
700 begin
701 e_WriteLog('Writing resolution to config', TMsgType.Notify);
703 config := TConfig.CreateFile(FileName);
705 if gWinMaximized and (not gFullscreen) then
706 begin
707 sW := gWinSizeX;
708 sH := gWinSizeY;
709 end
710 else
711 begin
712 sW := gScreenWidth;
713 sH := gScreenHeight;
714 end;
715 e_LogWritefln(' (ws=%dx%d) (ss=%dx%d)', [gWinSizeX, gWinSizeY, gScreenWidth, gScreenHeight]);
717 config.WriteInt('Video', 'ScreenWidth', sW);
718 config.WriteInt('Video', 'ScreenHeight', sH);
719 config.WriteInt('Video', 'WinPosX', gWinRealPosX);
720 config.WriteInt('Video', 'WinPosY', gWinRealPosY);
721 config.WriteBool('Video', 'Fullscreen', gFullscreen);
722 config.WriteBool('Video', 'Maximized', gWinMaximized);
724 config.WriteStr('Player1', 'Name', gPlayer1Settings.Name);
725 config.WriteStr('Player2', 'Name', gPlayer2Settings.Name);
727 config.SaveFile(FileName);
728 config.Free();
729 end;
731 procedure g_Options_Write_Gameplay_Custom(FileName: String);
732 var
733 config: TConfig;
734 begin
735 e_WriteLog('Writing custom gameplay config', TMsgType.Notify);
737 config := TConfig.CreateFile(FileName);
739 config.WriteStr ('GameplayCustom', 'Map', gcMap);
740 config.WriteStr ('GameplayCustom', 'GameMode', gcGameMode);
741 config.WriteInt ('GameplayCustom', 'TimeLimit', gcTimeLimit);
742 config.WriteInt ('GameplayCustom', 'GoalLimit', gcGoalLimit);
743 config.WriteInt ('GameplayCustom', 'MaxLives', gcMaxLives);
744 config.WriteInt ('GameplayCustom', 'Players', gcPlayers);
745 config.WriteBool('GameplayCustom', 'TeamDamage', gcTeamDamage);
746 config.WriteBool('GameplayCustom', 'AllowExit', gcAllowExit);
747 config.WriteBool('GameplayCustom', 'WeaponStay', gcWeaponStay);
748 config.WriteBool('GameplayCustom', 'Monsters', gcMonsters);
749 config.WriteStr ('GameplayCustom', 'BotsVS', gcBotsVS);
751 config.SaveFile(FileName);
752 config.Free();
753 end;
755 procedure g_Options_Write_Gameplay_Net(FileName: String);
756 var
757 config: TConfig;
758 begin
759 e_WriteLog('Writing network gameplay config', TMsgType.Notify);
761 config := TConfig.CreateFile(FileName);
763 config.WriteStr ('GameplayNetwork', 'Map', gnMap);
764 config.WriteStr ('GameplayNetwork', 'GameMode', gnGameMode);
765 config.WriteInt ('GameplayNetwork', 'TimeLimit', gnTimeLimit);
766 config.WriteInt ('GameplayNetwork', 'GoalLimit', gnGoalLimit);
767 config.WriteInt ('GameplayNetwork', 'MaxLives', gnMaxLives);
768 config.WriteInt ('GameplayNetwork', 'Players', gnPlayers);
769 config.WriteBool('GameplayNetwork', 'TeamDamage', gnTeamDamage);
770 config.WriteBool('GameplayNetwork', 'AllowExit', gnAllowExit);
771 config.WriteBool('GameplayNetwork', 'WeaponStay', gnWeaponStay);
772 config.WriteBool('GameplayNetwork', 'Monsters', gnMonsters);
773 config.WriteStr ('GameplayNetwork', 'BotsVS', gnBotsVS);
775 config.SaveFile(FileName);
776 config.Free();
777 end;
779 procedure g_Options_Write_Net_Server(FileName: String);
780 var
781 config: TConfig;
782 begin
783 e_WriteLog('Writing server config', TMsgType.Notify);
785 config := TConfig.CreateFile(FileName);
787 config.WriteStr ('Server', 'Name', NetServerName);
788 config.WriteStr ('Server', 'Password', NetPassword);
789 config.WriteInt ('Server', 'Port', NetPort);
790 config.WriteInt ('Server', 'MaxClients', NetMaxClients);
791 config.WriteBool('Server', 'SyncWithMaster', NetUseMaster);
792 config.WriteBool('Server', 'ForwardPorts', NetForwardPorts);
794 config.SaveFile(FileName);
795 config.Free();
796 end;
798 procedure g_Options_Write_Net_Client(FileName: String);
799 var
800 config: TConfig;
801 begin
802 e_WriteLog('Writing client config', TMsgType.Notify);
804 config := TConfig.CreateFile(FileName);
806 config.WriteStr('Client', 'LastIP', NetClientIP);
807 config.WriteInt('Client', 'LastPort', NetClientPort);
809 config.SaveFile(FileName);
810 config.Free();
811 end;
813 initialization
814 Randomize;
815 machine := Random(10000)
816 end.