DEADSOFTWARE

Default window size and position setted according with display resolution
[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, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *)
16 {$INCLUDE ../shared/a_modes.inc}
17 unit g_options;
19 interface
21 uses
22 g_language, g_weapons;
24 type
25 TPlayerControl = record
26 KeyRight: Word;
27 KeyLeft: Word;
28 KeyUp: Word;
29 KeyDown: Word;
30 KeyFire: Word;
31 KeyJump: Word;
32 KeyNextWeapon: Word;
33 KeyPrevWeapon: Word;
34 KeyOpen: Word;
35 KeyStrafe: Word;
36 KeyWeapon: array [WP_FIRST..WP_LAST] of Word;
38 KeyRight2: Word;
39 KeyLeft2: Word;
40 KeyUp2: Word;
41 KeyDown2: Word;
42 KeyFire2: Word;
43 KeyJump2: Word;
44 KeyNextWeapon2: Word;
45 KeyPrevWeapon2: Word;
46 KeyOpen2: Word;
47 KeyStrafe2: Word;
48 KeyWeapon2: array [WP_FIRST..WP_LAST] of Word;
49 end;
51 TGameControls = record
52 TakeScreenshot: Word;
53 Stat: Word;
54 Chat: Word;
55 TeamChat: Word;
56 end;
58 TControls = record
59 GameControls: TGameControls;
60 P1Control: TPlayerControl;
61 P2Control: TPlayerControl;
62 end;
64 procedure g_Options_SetDefault();
65 procedure g_Options_Read(FileName: String);
66 procedure g_Options_Write(FileName: String);
67 procedure g_Options_Write_Language(FileName: String);
68 procedure g_Options_Write_Video(FileName: String);
69 procedure g_Options_Write_Gameplay_Custom(FileName: String);
70 procedure g_Options_Write_Gameplay_Net(FileName: String);
71 procedure g_Options_Write_Net_Server(FileName: String);
72 procedure g_Options_Write_Net_Client(FileName: String);
74 const DF_Default_Megawad_Start = 'megawads/DOOM2D.WAD:\MAP01';
76 var
77 gGameControls: TControls;
78 gScreenWidth: Word;
79 gScreenHeight: Word;
80 gWinRealPosX: Integer;
81 gWinRealPosY: Integer;
82 gBPP: Byte;
83 gFreq: Byte;
84 gFullscreen: Boolean;
85 gWinMaximized: Boolean;
86 gVSync: Boolean;
87 glLegacyNPOT: Boolean;
88 gTextureFilter: Boolean;
89 gNoSound: Boolean;
90 gSoundLevel: Byte;
91 gMusicLevel: Byte;
92 gMaxSimSounds: Byte;
93 gMuteWhenInactive: Boolean;
94 gAdvCorpses: Boolean;
95 gAdvBlood: Boolean;
96 gAdvGibs: Boolean;
97 gGibsCount: Integer;
98 gBloodCount: Byte;
99 gFlash: Byte;
100 gDrawBackGround: Boolean;
101 gShowMessages: Boolean;
102 gRevertPlayers: Boolean;
103 gLanguage: String;
104 gAskLanguage: Boolean;
105 gcMap: String;
106 gcGameMode: String;
107 gcTimeLimit: Word;
108 gcGoalLimit: Word;
109 gcMaxLives: Byte;
110 gcPlayers: Byte;
111 gcTeamDamage: Boolean;
112 gcAllowExit: Boolean;
113 gcWeaponStay: Boolean;
114 gcMonsters: Boolean;
115 gcBotsVS: String;
116 gnMap: String;
117 gnGameMode: String;
118 gnTimeLimit: Word;
119 gnGoalLimit: Word;
120 gnMaxLives: Byte;
121 gnPlayers: Byte;
122 gnTeamDamage: Boolean;
123 gnAllowExit: Boolean;
124 gnWeaponStay: Boolean;
125 gnMonsters: Boolean;
126 gnBotsVS: String;
127 gsSDLSampleRate: Integer;
128 gsSDLBufferSize: Integer;
129 gSFSDebug: Boolean;
130 gSFSFastMode: Boolean;
131 gDefaultMegawadStart: AnsiString;
132 gBerserkAutoswitch: Boolean;
134 implementation
136 uses
137 {$INCLUDE ../nogl/noGLuses.inc}
138 e_log, e_input, g_window, g_sound, g_gfx, g_player, Math,
139 g_map, g_net, g_netmaster, SysUtils, CONFIG, g_game, g_main, e_texture,
140 g_items, wadreader, e_graphics, g_touch, SDL2;
142 procedure g_Options_SetDefaultVideo;
143 var
144 target, closest, display: TSDL_DisplayMode;
145 begin
146 (* Display 0 = Primary display *)
147 SDL_GetDesktopDisplayMode(0, @display);
148 {$IF DEFINED(ANDROID)}
149 gScreenWidth := display.w;
150 gScreenHeight := display.h;
151 //gBPP := SDL_BITSPERPIXEL(dispaly.format);
152 gBPP := 32;
153 gFullScreen := True; (* rotation not allowed? *)
154 {$ELSE}
155 (* Window must be smaller than display *)
156 target.w := display.w * 75 div 100;
157 target.h := display.h * 75 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 gScreenWidth := closest.w;
163 gScreenHeight := closest.h;
164 //gBPP := SDL_BITSPERPIXEL(closest.format); (* Resolution list didn't work for some reason *)
165 gBPP := 32;
166 gFullScreen := False;
167 {$ENDIF}
168 (* Must be positioned on primary display *)
169 gWinRealPosX := SDL_WINDOWPOS_CENTERED;
170 gWinRealPosY := SDL_WINDOWPOS_CENTERED;
171 gWinMaximized := False;
172 gVSync := True;
173 gTextureFilter := True;
174 glLegacyNPOT := False;
175 e_LogWriteLn('g_Options_SetDefaultVideo: w = ' + IntToStr(gScreenWidth) + ' h = ' + IntToStr(gScreenHeight));
176 end;
178 procedure g_Options_SetDefault();
179 var
180 i: Integer;
181 begin
182 (* section Sound *)
183 gNoSound := False;
184 gSoundLevel := 75;
185 gMusicLevel := 65;
186 gMaxSimSounds := 8;
187 gMuteWhenInactive := False;
188 gAnnouncer := ANNOUNCE_MEPLUS;
189 gSoundEffectsDF := True;
190 gUseChatSounds := True;
191 gsSDLSampleRate := 44100;
192 gsSDLBufferSize := 2048;
194 g_Sound_SetupAllVolumes(gSoundLevel, gMusicLevel);
196 (* section GameControls *)
197 with gGameControls.GameControls do
198 begin
199 TakeScreenshot := SDL_SCANCODE_F12;
200 Stat := SDL_SCANCODE_TAB;
201 Chat := SDL_SCANCODE_T;
202 TeamChat := SDL_SCANCODE_Y;
203 end;
205 (* section Player1 *)
206 with gGameControls.P1Control do
207 begin
208 KeyRight := SDL_SCANCODE_KP_6;
209 KeyLeft := SDL_SCANCODE_KP_4;
210 KeyUp := SDL_SCANCODE_KP_8;
211 KeyDown := SDL_SCANCODE_KP_5;
212 KeyFire := SDL_SCANCODE_SLASH;
213 KeyJump := SDL_SCANCODE_RCTRL;
214 KeyNextWeapon := SDL_SCANCODE_KP_9;
215 KeyPrevWeapon := SDL_SCANCODE_KP_7;
216 KeyOpen := SDL_SCANCODE_RSHIFT;
217 KeyStrafe := SDL_SCANCODE_PERIOD;
219 for i := 0 to 9 do
220 begin
221 KeyWeapon[i] := SDL_SCANCODE_1 + i (* 1, ..., 9, 0 *)
222 end;
223 KeyWeapon[10] := SDL_SCANCODE_MINUS;
224 for i := 11 to High(KeyWeapon) do
225 begin
226 KeyWeapon[i] := 0
227 end;
229 KeyRight2 := VK_RIGHT;
230 KeyLeft2 := VK_LEFT;
231 KeyUp2 := VK_UP;
232 KeyDown2 := VK_DOWN;
233 KeyFire2 := VK_FIRE;
234 KeyJump2 := VK_JUMP;
235 KeyNextWeapon2 := VK_NEXT;
236 KeyPrevWeapon2 := VK_PREV;
237 KeyOpen2 := VK_OPEN;
238 KeyStrafe2 := VK_STRAFE;
240 for i := 0 to High(KeyWeapon2) do
241 begin
242 KeyWeapon2[i] := VK_0 + i
243 end;
244 end;
246 with gPlayer1Settings do
247 begin
248 Name := 'Player1';
249 Model := STD_PLAYER_MODEL;
250 Color.R := PLAYER1_DEF_COLOR.R;
251 Color.G := PLAYER1_DEF_COLOR.G;
252 Color.B := PLAYER1_DEF_COLOR.B;
253 Team := TEAM_RED;
254 end;
256 (* section Player2 *)
257 with gGameControls.P2Control do
258 begin
259 KeyRight := SDL_SCANCODE_D;
260 KeyLeft := SDL_SCANCODE_A;
261 KeyUp := SDL_SCANCODE_W;
262 KeyDown := SDL_SCANCODE_S;
263 KeyFire := SDL_SCANCODE_G;
264 KeyJump := SDL_SCANCODE_SPACE;
265 KeyNextWeapon := SDL_SCANCODE_E;
266 KeyPrevWeapon := SDL_SCANCODE_Q;
267 KeyOpen := SDL_SCANCODE_F;
268 KeyStrafe := SDL_SCANCODE_LSHIFT;
269 for i := 0 to High(KeyWeapon) do
270 begin
271 KeyWeapon[i] := 0
272 end;
274 KeyRight2 := 0;
275 KeyLeft2 := 0;
276 KeyUp2 := 0;
277 KeyDown2 := 0;
278 KeyFire2 := 0;
279 KeyJump2 := 0;
280 KeyNextWeapon2 := 0;
281 KeyPrevWeapon2 := 0;
282 KeyOpen2 := 0;
283 KeyStrafe2 := 0;
285 for i := 0 to High(KeyWeapon2) do
286 begin
287 KeyWeapon2[i] := 0;
288 end
289 end;
291 with gPlayer2Settings do
292 begin
293 Name := 'Player2';
294 Model := STD_PLAYER_MODEL;
295 Color.R := PLAYER2_DEF_COLOR.R;
296 Color.G := PLAYER2_DEF_COLOR.G;
297 Color.B := PLAYER2_DEF_COLOR.B;
298 Team := TEAM_BLUE;
299 end;
301 (* section Joysticks *)
302 for i := 0 to e_MaxJoys - 1 do
303 begin
304 e_JoystickDeadzones[i] := 8192
305 end;
307 (* section Touch *)
308 g_touch_size := 1.0;
309 g_touch_fire := True;
310 g_touch_offset := 50;
311 g_touch_alt := False;
313 (* section Game *)
314 g_GFX_SetMax(2000);
315 g_Shells_SetMax(300);
316 g_Gibs_SetMax(150);
317 g_Corpses_SetMax(20);
318 gGibsCount := 32;
319 ITEM_RESPAWNTIME := 60 * 36;
320 gBloodCount := 4;
321 gAdvBlood := True;
322 gAdvCorpses := True;
323 gAdvGibs := True;
324 gFlash := 1;
325 gDrawBackGround := True;
326 gShowMessages := True;
327 gRevertPlayers := False;
328 gChatBubble := 4;
329 gSFSDebug := False;
330 gSFSFastMode := False;
331 e_FastScreenshots := True;
332 gDefaultMegawadStart := DF_Default_Megawad_Start;
333 gBerserkAutoswitch := True;
334 g_dbg_scale := 1.0;
336 gAskLanguage := True;
337 gLanguage := LANGUAGE_ENGLISH;
339 (* section GameplayCustom *)
340 gcMap := '';
341 gcGameMode := _lc[I_MENU_GAME_TYPE_DM];
342 gcTimeLimit := 0;
343 gcGoalLimit := 0;
344 gcMaxLives := 0;
345 gcPlayers := 1;
346 gcTeamDamage := False;
347 gcAllowExit := True;
348 gcWeaponStay := False;
349 gcMonsters := False;
350 gcBotsVS := 'Everybody';
352 (* section GameplayNetwork *)
353 gnMap := '';
354 gnGameMode := _lc[I_MENU_GAME_TYPE_DM];
355 gnTimeLimit := 0;
356 gnGoalLimit := 0;
357 gnMaxLives := 0;
358 gnPlayers := 1;
359 gnTeamDamage := False;
360 gnAllowExit := True;
361 gnWeaponStay := False;
362 gnMonsters := False;
363 gnBotsVS := 'Everybody';
365 (* section MasterServer *)
366 NetSlistIP := 'mpms.doom2d.org';
367 NetSlistPort := 25665;
368 g_Net_Slist_Set(NetSlistIP, NetSlistPort);
370 (* section Server *)
371 NetServerName := 'Unnamed Server';
372 NetPassword := '';
373 NetPort := 25666;
374 NetMaxClients := 16;
375 NetAllowRCON := False;
376 NetRCONPassword := 'default';
377 NetUseMaster := True;
378 NetUpdateRate := 0;
379 NetRelupdRate := 18;
380 NetMasterRate := 60000;
381 NetForwardPorts := False;
383 (* section Client *)
384 NetInterpLevel := 2;
385 NetForcePlayerUpdate := False;
386 NetPredictSelf := True;
387 NetClientIP := '127.0.0.1';
388 NetClientPort := NetPort;
389 end;
391 procedure g_Options_Read(FileName: String);
392 var
393 i: Integer;
394 config: TConfig;
395 section: String;
397 procedure ReadInteger (VAR v: Integer; param: String; minv: Integer = Low(Integer); maxv: Integer = High(Integer));
398 begin
399 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
400 end;
402 procedure ReadInteger (VAR v: LongWord; param: String; minv: LongWord = Low(LongWord); maxv: LongWord = High(LongWord)); overload;
403 begin
404 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
405 end;
407 procedure ReadInteger (VAR v: Word; param: String; minv: Word = Low(Word); maxv: Word = High(Word)); overload;
408 begin
409 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
410 end;
412 procedure ReadInteger (VAR v: Byte; param: String; minv: Byte = Low(Byte); maxv: Byte = High(Byte)); overload;
413 begin
414 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
415 end;
417 procedure ReadBoolean (VAR v: Boolean; param: String);
418 begin
419 v := config.ReadBool(section, param, v)
420 end;
422 procedure ReadString (VAR v: String; param: String);
423 begin
424 v := config.ReadStr(section, param, v)
425 end;
427 begin
428 gAskLanguage := True;
429 e_WriteLog('Reading config', TMsgType.Notify);
430 g_Options_SetDefault;
432 if FileExists(FileName) = False then
433 begin
434 e_WriteLog('Config file '+FileName+' not found', TMsgType.Warning);
435 g_Options_SetDefaultVideo;
436 Exit
437 end;
439 config := TConfig.CreateFile(FileName);
441 section := 'Video';
442 ReadInteger(gScreenWidth, 'ScreenWidth', 0);
443 ReadInteger(gScreenHeight, 'ScreenHeight', 0);
444 ReadInteger(gWinRealPosX, 'WinPosX', 60);
445 ReadInteger(gWinRealPosY, 'WinPosY', 60);
446 ReadBoolean(gFullScreen, 'Fullscreen');
447 ReadBoolean(gWinMaximized, 'Maximized');
448 ReadInteger(gBPP, 'BPP', 0);
449 ReadInteger(gFreq, 'Freq', 0);
450 ReadBoolean(gVSync, 'VSync');
451 ReadBoolean(gTextureFilter, 'TextureFilter');
452 ReadBoolean(glLegacyNPOT, 'LegacyCompatible');
454 section := 'Sound';
455 ReadBoolean(gNoSound, 'NoSound');
456 ReadInteger(gSoundLevel, 'SoundLevel', 0, 255);
457 ReadInteger(gMusicLevel, 'MusicLevel', 0, 255);
458 ReadInteger(gMaxSimSounds, 'MaxSimSounds', 2, 66);
459 ReadBoolean(gMuteWhenInactive, 'MuteInactive');
460 ReadInteger(gAnnouncer, 'Announcer', ANNOUNCE_NONE, ANNOUNCE_ALL);
461 ReadBoolean(gSoundEffectsDF, 'SoundEffectsDF');
462 ReadBoolean(gUseChatSounds, 'ChatSounds');
463 ReadInteger(gsSDLSampleRate, 'SDLSampleRate', 11025, 96000);
464 ReadInteger(gsSDLBufferSize, 'SDLBufferSize', 64, 16384);
466 section := 'GameControls';
467 with gGameControls.GameControls do
468 begin
469 ReadInteger(TakeScreenshot, 'TakeScreenshot');
470 ReadInteger(Stat, 'Stat');
471 ReadInteger(Chat, 'Chat');
472 ReadInteger(TeamChat, 'TeamChat');
473 end;
475 section := 'Player1';
476 with gGameControls.P1Control do
477 begin
478 ReadInteger(KeyRight, 'KeyRight');
479 ReadInteger(KeyLeft, 'KeyLeft');
480 ReadInteger(KeyUp, 'KeyUp');
481 ReadInteger(KeyDown, 'KeyDown');
482 ReadInteger(KeyFire, 'KeyFire');
483 ReadInteger(KeyJump, 'KeyJump');
484 ReadInteger(KeyNextWeapon, 'KeyNextWeapon');
485 ReadInteger(KeyPrevWeapon, 'KeyPrevWeapon');
486 ReadInteger(KeyOpen, 'KeyOpen');
487 ReadInteger(KeyStrafe, 'KeyStrafe');
489 for i := 0 to High(KeyWeapon) do
490 begin
491 ReadInteger(KeyWeapon[i], 'KeyWeapon' + IntToStr(i))
492 end;
494 ReadInteger(KeyRight2, 'KeyRight2');
495 ReadInteger(KeyLeft2, 'KeyLeft2');
496 ReadInteger(KeyUp2, 'KeyUp2');
497 ReadInteger(KeyDown2, 'KeyDown2');
498 ReadInteger(KeyFire2, 'KeyFire2');
499 ReadInteger(KeyJump2, 'KeyJump2');
500 ReadInteger(KeyNextWeapon2, 'KeyNextWeapon2');
501 ReadInteger(KeyPrevWeapon2, 'KeyPrevWeapon2');
502 ReadInteger(KeyOpen2, 'KeyOpen2');
503 ReadInteger(KeyStrafe2, 'KeyStrafe2');
505 for i := 0 to High(KeyWeapon2) do
506 begin
507 ReadInteger(KeyWeapon2[i], 'KeyWeapon2' + IntToStr(i))
508 end;
509 end;
511 section := 'Player1';
512 with gPlayer1Settings do
513 begin
514 ReadString(Name, 'name');
515 ReadString(Model, 'model');
516 ReadInteger(Color.R, 'red', 0, 255);
517 ReadInteger(Color.G, 'green', 0, 255);
518 ReadInteger(Color.B, 'blue', 0, 255);
519 ReadInteger(Team, 'team');
520 if (Team < TEAM_RED) or (Team > TEAM_BLUE) then
521 Team := TEAM_RED;
522 end;
524 section := 'Player2';
525 with gGameControls.P2Control do
526 begin
527 ReadInteger(KeyRight, 'KeyRight');
528 ReadInteger(KeyLeft, 'KeyLeft');
529 ReadInteger(KeyUp, 'KeyUp');
530 ReadInteger(KeyDown, 'KeyDown');
531 ReadInteger(KeyFire, 'KeyFire');
532 ReadInteger(KeyJump, 'KeyJump');
533 ReadInteger(KeyNextWeapon, 'KeyNextWeapon');
534 ReadInteger(KeyPrevWeapon, 'KeyPrevWeapon');
535 ReadInteger(KeyOpen, 'KeyOpen');
536 ReadInteger(KeyStrafe, 'KeyStrafe');
538 for i := 0 to High(KeyWeapon) do
539 begin
540 ReadInteger(KeyWeapon[i], 'KeyWeapon' + IntToStr(i))
541 end;
543 ReadInteger(KeyRight2, 'KeyRight2');
544 ReadInteger(KeyLeft2, 'KeyLeft2');
545 ReadInteger(KeyUp2, 'KeyUp2');
546 ReadInteger(KeyDown2, 'KeyDown2');
547 ReadInteger(KeyFire2, 'KeyFire2');
548 ReadInteger(KeyJump2, 'KeyJump2');
549 ReadInteger(KeyNextWeapon2, 'KeyNextWeapon2');
550 ReadInteger(KeyPrevWeapon2, 'KeyPrevWeapon2');
551 ReadInteger(KeyOpen2, 'KeyOpen2');
552 ReadInteger(KeyStrafe2, 'KeyStrafe2');
554 for i := 0 to High(KeyWeapon2) do
555 begin
556 ReadInteger(KeyWeapon2[i], 'KeyWeapon2' + IntToStr(i))
557 end;
558 end;
560 section := 'Player2';
561 with gPlayer2Settings do
562 begin
563 ReadString(Name, 'name');
564 ReadString(Model, 'model');
565 ReadInteger(Color.R, 'red', 0, 255);
566 ReadInteger(Color.G, 'green', 0, 255);
567 ReadInteger(Color.B, 'blue', 0, 255);
568 ReadInteger(Team, 'team');
569 if (Team < TEAM_RED) or (Team > TEAM_BLUE) then
570 Team := TEAM_RED;
571 end;
573 section := 'Joysticks';
574 for i := 0 to e_MaxJoys - 1 do
575 begin
576 ReadInteger(e_JoystickDeadzones[i], 'Deadzone' + IntToStr(i))
577 end;
579 section := 'Touch';
580 i := Trunc(g_touch_size * 10); ReadInteger(i, 'Size', 0); g_touch_size := i / 10;
581 ReadBoolean(g_touch_fire, 'Fire');
582 i := Round(g_touch_offset); ReadInteger(i, 'Offset', 0, 100); g_touch_offset := i;
583 ReadBoolean(g_touch_alt, 'Alt');
585 section := 'Game';
586 ReadInteger(i, 'MaxParticles', 1000, 50000); g_GFX_SetMax(i);
587 ReadInteger(i, 'MaxShells', 300, 600); g_Shells_SetMax(i);
588 ReadInteger(i, 'MaxGibs', 150, 500); g_Gibs_SetMax(i);
589 ReadInteger(i, 'MaxCorpses', 20, 100); g_Corpses_SetMax(i);
590 ReadInteger(i, 'GibsCount');
591 case i of
592 0: gGibsCount := 0;
593 1: gGibsCount := 8;
594 2: gGibsCount := 16;
595 3: gGibsCount := 32;
596 else gGibsCount := 48;
597 end;
598 i := ITEM_RESPAWNTIME div 36; ReadInteger(i, 'ItemRespawnTime', 0); ITEM_RESPAWNTIME := i * 36;
599 ReadInteger(gBloodCount, 'BloodCount', 0, 4);
600 ReadBoolean(gAdvBlood, 'AdvancesBlood');
601 ReadBoolean(gAdvCorpses, 'AdvancesCorpses');
602 ReadBoolean(gAdvGibs, 'AdvancesGibs');
603 ReadInteger(gFlash, 'Flash', 0, 2);
604 ReadBoolean(gDrawBackGround, 'BackGround');
605 ReadBoolean(gShowMessages, 'Messages');
606 ReadBoolean(gRevertPlayers, 'RevertPlayers');
607 ReadInteger(gChatBubble, 'ChatBubble', 0, 4);
608 ReadBoolean(gSFSDebug, 'SFSDebug'); wadoptDebug := gSFSDebug;
609 ReadBoolean(gSFSFastMode, 'SFSFastMode'); wadoptFast := gSFSFastMode;
610 ReadBoolean(e_FastScreenshots, 'FastScreenshots');
611 ReadString(gDefaultMegawadStart, 'DefaultMegawadStart');
612 ReadBoolean(gBerserkAutoswitch, 'BerserkAutoswitching');
613 i := Trunc(g_dbg_scale * 100); ReadInteger(i, 'Scale', 100); g_dbg_scale := i / 100;
614 ReadString(gLanguage, 'Language');
615 if (gLanguage = LANGUAGE_RUSSIAN) or (gLanguage = LANGUAGE_ENGLISH) then
616 gAskLanguage := False
617 else
618 gLanguage := LANGUAGE_ENGLISH;
620 section := 'GameplayCustom';
621 ReadString(gcMap, 'Map');
622 ReadString(gcGameMode, 'GameMode');
623 ReadInteger(gcTimeLimit, 'TimeLimit', 0, 65535);
624 ReadInteger(gcGoalLimit, 'GoalLimit', 0, 65535);
625 ReadInteger(gcMaxLives, 'MaxLives', 0, 255);
626 ReadInteger(gcPlayers, 'Players', 0, 2);
627 ReadBoolean(gcTeamDamage, 'TeamDamage');
628 ReadBoolean(gcAllowExit, 'AllowExit');
629 ReadBoolean(gcWeaponStay, 'WeaponStay');
630 ReadBoolean(gcMonsters, 'Monsters');
631 ReadString(gcBotsVS, 'BotsVS');
633 with gGameSettings do
634 begin
635 GameMode := g_Game_TextToMode(gcGameMode);
636 if GameMode = GM_NONE then
637 GameMode := GM_DM;
638 if GameMode = GM_SINGLE then
639 GameMode := GM_COOP;
640 TimeLimit := gcTimeLimit;
641 GoalLimit := gcGoalLimit;
642 MaxLives := gcMaxLives;
644 Options := 0;
645 if gcTeamDamage then
646 Options := Options or GAME_OPTION_TEAMDAMAGE;
647 if gcAllowExit then
648 Options := Options or GAME_OPTION_ALLOWEXIT;
649 if gcWeaponStay then
650 Options := Options or GAME_OPTION_WEAPONSTAY;
651 if gcMonsters then
652 Options := Options or GAME_OPTION_MONSTERS;
653 if gcBotsVS = 'Everybody' then
654 Options := Options or GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER;
655 if gcBotsVS = 'Players' then
656 Options := Options or GAME_OPTION_BOTVSPLAYER;
657 if gcBotsVS = 'Monsters' then
658 Options := Options or GAME_OPTION_BOTVSMONSTER;
659 end;
661 section := 'GameplayNetwork';
662 ReadString(gnMap, 'Map');
663 ReadString(gnGameMode, 'GameMode');
664 ReadInteger(gnTimeLimit, 'TimeLimit', 0, 65535);
665 ReadInteger(gnGoalLimit, 'GoalLimit', 0, 65535);
666 ReadInteger(gnMaxLives, 'MaxLives', 0, 255);
667 ReadInteger(gnPlayers, 'Players', 0, 2);
668 ReadBoolean(gnTeamDamage, 'TeamDamage');
669 ReadBoolean(gnAllowExit, 'AllowExit');
670 ReadBoolean(gnWeaponStay, 'WeaponStay');
671 ReadBoolean(gnMonsters, 'Monsters');
672 ReadString(gnBotsVS, 'BotsVS');
674 section := 'MasterServer';
675 ReadString(NetSlistIP, 'IP');
676 ReadInteger(NetSlistPort, 'Port', 0, 65535);
677 g_Net_Slist_Set(NetSlistIP, NetSlistPort);
679 section := 'Server';
680 ReadString(NetServerName, 'Name');
681 ReadString(NetPassword, 'Password');
682 ReadInteger(NetPort, 'Port', 0, 65535);
683 ReadInteger(NetMaxClients, 'MaxClients', 0, NET_MAXCLIENTS);
684 ReadBoolean(NetAllowRCON, 'RCON');
685 ReadString(NetRCONPassword, 'RCONPassword');
686 ReadBoolean(NetUseMaster, 'SyncWithMaster');
687 ReadInteger(NetUpdateRate, 'UpdateInterval', 0);
688 ReadInteger(NetRelupdRate, 'ReliableUpdateInterval', 0);
689 ReadInteger(NetMasterRate, 'MasterSyncInterval', 1);
690 ReadBoolean(NetForwardPorts, 'ForwardPorts');
692 section := 'Client';
693 ReadInteger(NetInterpLevel, 'InterpolationSteps', 0);
694 ReadBoolean(NetForcePlayerUpdate, 'ForcePlayerUpdate');
695 ReadBoolean(NetPredictSelf, 'PredictSelf');
696 ReadString(NetClientIP, 'LastIP');
697 ReadInteger(NetClientPort, 'LastPort', 0, 65535);
699 config.Free();
701 //if gTextureFilter then TEXTUREFILTER := GL_LINEAR else TEXTUREFILTER := GL_NEAREST;
702 end;
704 procedure g_Options_Write(FileName: String);
705 var
706 config: TConfig;
707 i: Integer;
708 begin
709 e_WriteLog('Writing config', TMsgType.Notify);
711 config := TConfig.CreateFile(FileName);
713 config.WriteInt('Video', 'ScreenWidth', gScreenWidth);
714 config.WriteInt('Video', 'ScreenHeight', gScreenHeight);
715 config.WriteInt('Video', 'WinPosX', gWinRealPosX);
716 config.WriteInt('Video', 'WinPosY', gWinRealPosY);
717 config.WriteBool('Video', 'Fullscreen', gFullScreen);
718 config.WriteBool('Video', 'Maximized', gWinMaximized);
719 config.WriteInt('Video', 'BPP', gBPP);
720 config.WriteBool('Video', 'VSync', gVSync);
721 config.WriteBool('Video', 'TextureFilter', gTextureFilter);
722 config.WriteBool('Video', 'LegacyCompatible', glLegacyNPOT);
724 config.WriteBool('Sound', 'NoSound', gNoSound);
725 config.WriteInt('Sound', 'SoundLevel', gSoundLevel);
726 config.WriteInt('Sound', 'MusicLevel', gMusicLevel);
727 config.WriteInt('Sound', 'MaxSimSounds', gMaxSimSounds);
728 config.WriteBool('Sound', 'MuteInactive', gMuteWhenInactive);
729 config.WriteInt('Sound', 'Announcer', gAnnouncer);
730 config.WriteBool('Sound', 'SoundEffectsDF', gSoundEffectsDF);
731 config.WriteBool('Sound', 'ChatSounds', gUseChatSounds);
732 config.WriteInt('Sound', 'SDLSampleRate', gsSDLSampleRate);
733 config.WriteInt('Sound', 'SDLBufferSize', gsSDLBufferSize);
735 with config, gGameControls.GameControls do
736 begin
737 WriteInt('GameControls', 'TakeScreenshot', TakeScreenshot);
738 WriteInt('GameControls', 'Stat', Stat);
739 WriteInt('GameControls', 'Chat', Chat);
740 WriteInt('GameControls', 'TeamChat', TeamChat);
741 end;
743 with config, gGameControls.P1Control, gPlayer1Settings do
744 begin
745 WriteInt('Player1', 'KeyRight', KeyRight);
746 WriteInt('Player1', 'KeyLeft', KeyLeft);
747 WriteInt('Player1', 'KeyUp', KeyUp);
748 WriteInt('Player1', 'KeyDown', KeyDown);
749 WriteInt('Player1', 'KeyFire', KeyFire);
750 WriteInt('Player1', 'KeyJump', KeyJump);
751 WriteInt('Player1', 'KeyNextWeapon', KeyNextWeapon);
752 WriteInt('Player1', 'KeyPrevWeapon', KeyPrevWeapon);
753 WriteInt('Player1', 'KeyOpen', KeyOpen);
754 WriteInt('Player1', 'KeyStrafe', KeyStrafe);
755 for i := 0 to High(KeyWeapon) do
756 WriteInt('Player1', 'KeyWeapon' + IntToStr(i), KeyWeapon[i]);
758 WriteInt('Player1', 'KeyRight2', KeyRight2);
759 WriteInt('Player1', 'KeyLeft2', KeyLeft2);
760 WriteInt('Player1', 'KeyUp2', KeyUp2);
761 WriteInt('Player1', 'KeyDown2', KeyDown2);
762 WriteInt('Player1', 'KeyFire2', KeyFire2);
763 WriteInt('Player1', 'KeyJump2', KeyJump2);
764 WriteInt('Player1', 'KeyNextWeapon2', KeyNextWeapon2);
765 WriteInt('Player1', 'KeyPrevWeapon2', KeyPrevWeapon2);
766 WriteInt('Player1', 'KeyOpen2', KeyOpen2);
767 WriteInt('Player1', 'KeyStrafe2', KeyStrafe2);
768 for i := 0 to High(KeyWeapon2) do
769 WriteInt('Player1', 'KeyWeapon2' + IntToStr(i), KeyWeapon2[i]);
771 WriteStr('Player1', 'Name', Name);
772 WriteStr('Player1', 'model', Model);
773 WriteInt('Player1', 'red', Color.R);
774 WriteInt('Player1', 'green', Color.G);
775 WriteInt('Player1', 'blue', Color.B);
776 WriteInt('Player1', 'team', Team);
777 end;
779 with config, gGameControls.P2Control, gPlayer2Settings do
780 begin
781 WriteInt('Player2', 'KeyRight', KeyRight);
782 WriteInt('Player2', 'KeyLeft', KeyLeft);
783 WriteInt('Player2', 'KeyUp', KeyUp);
784 WriteInt('Player2', 'KeyDown', KeyDown);
785 WriteInt('Player2', 'KeyFire', KeyFire);
786 WriteInt('Player2', 'KeyJump', KeyJump);
787 WriteInt('Player2', 'KeyNextWeapon', KeyNextWeapon);
788 WriteInt('Player2', 'KeyPrevWeapon', KeyPrevWeapon);
789 WriteInt('Player2', 'KeyOpen', KeyOpen);
790 WriteInt('Player2', 'KeyStrafe', KeyStrafe);
791 for i := 0 to High(KeyWeapon) do
792 WriteInt('Player2', 'KeyWeapon' + IntToStr(i), KeyWeapon[i]);
794 WriteInt('Player2', 'KeyRight2', KeyRight2);
795 WriteInt('Player2', 'KeyLeft2', KeyLeft2);
796 WriteInt('Player2', 'KeyUp2', KeyUp2);
797 WriteInt('Player2', 'KeyDown2', KeyDown2);
798 WriteInt('Player2', 'KeyFire2', KeyFire2);
799 WriteInt('Player2', 'KeyJump2', KeyJump2);
800 WriteInt('Player2', 'KeyNextWeapon2', KeyNextWeapon2);
801 WriteInt('Player2', 'KeyPrevWeapon2', KeyPrevWeapon2);
802 WriteInt('Player2', 'KeyOpen2', KeyOpen2);
803 WriteInt('Player2', 'KeyStrafe2', KeyStrafe2);
804 for i := 0 to High(KeyWeapon2) do
805 WriteInt('Player2', 'KeyWeapon2' + IntToStr(i), KeyWeapon2[i]);
807 WriteStr('Player2', 'Name', Name);
808 WriteStr('Player2', 'model', Model);
809 WriteInt('Player2', 'red', Color.R);
810 WriteInt('Player2', 'green', Color.G);
811 WriteInt('Player2', 'blue', Color.B);
812 WriteInt('Player2', 'team', Team);
813 end;
815 for i := 0 to e_MaxJoys-1 do
816 config.WriteInt('Joysticks', 'Deadzone' + IntToStr(i), e_JoystickDeadzones[i]);
818 config.WriteInt('Touch', 'Size', Round(g_touch_size * 10));
819 config.WriteBool('Touch', 'Fire', g_touch_fire);
820 config.WriteInt('Touch', 'Offset', Round(g_touch_offset));
821 config.WriteBool('Touch', 'Alt', g_touch_alt);
823 with config do
824 case gGibsCount of
825 0: config.WriteInt('Game', 'GibsCount', 0);
826 8: config.WriteInt('Game', 'GibsCount', 1);
827 16: config.WriteInt('Game', 'GibsCount', 2);
828 32: config.WriteInt('Game', 'GibsCount', 3);
829 else config.WriteInt('Game', 'GibsCount', 4);
830 end;
832 config.WriteInt('Game', 'ItemRespawnTime', ITEM_RESPAWNTIME div 36);
833 config.WriteInt('Game', 'MaxParticles', g_GFX_GetMax());
834 config.WriteInt('Game', 'MaxShells', g_Shells_GetMax());
835 config.WriteInt('Game', 'MaxGibs', g_Gibs_GetMax());
836 config.WriteInt('Game', 'MaxCorpses', g_Corpses_GetMax());
837 config.WriteInt('Game', 'BloodCount', gBloodCount);
838 config.WriteBool('Game', 'AdvancesBlood', gAdvBlood);
839 config.WriteBool('Game', 'AdvancesCorpses', gAdvCorpses);
840 config.WriteBool('Game', 'AdvancesGibs', gAdvGibs);
841 config.WriteInt('Game', 'Flash', gFlash);
842 config.WriteBool('Game', 'BackGround', gDrawBackGround);
843 config.WriteBool('Game', 'Messages', gShowMessages);
844 config.WriteBool('Game', 'RevertPlayers', gRevertPlayers);
845 config.WriteInt('Game', 'ChatBubble', gChatBubble);
846 config.WriteBool('Game', 'SFSDebug', gSFSDebug);
847 config.WriteBool('Game', 'SFSFastMode', gSFSFastMode);
848 config.WriteBool('Game', 'FastScreenshots', e_FastScreenshots);
849 config.WriteStr('Game', 'DefaultMegawadStart', gDefaultMegawadStart);
850 config.WriteBool('Game', 'BerserkAutoswitching', gBerserkAutoswitch);
851 config.WriteInt('Game', 'Scale', Round(g_dbg_scale * 100));
853 config.WriteStr ('GameplayCustom', 'Map', gcMap);
854 config.WriteStr ('GameplayCustom', 'GameMode', gcGameMode);
855 config.WriteInt ('GameplayCustom', 'TimeLimit', gcTimeLimit);
856 config.WriteInt ('GameplayCustom', 'GoalLimit', gcGoalLimit);
857 config.WriteInt ('GameplayCustom', 'MaxLives', gcMaxLives);
858 config.WriteInt ('GameplayCustom', 'Players', gcPlayers);
859 config.WriteBool('GameplayCustom', 'TeamDamage', gcTeamDamage);
860 config.WriteBool('GameplayCustom', 'AllowExit', gcAllowExit);
861 config.WriteBool('GameplayCustom', 'WeaponStay', gcWeaponStay);
862 config.WriteBool('GameplayCustom', 'Monsters', gcMonsters);
863 config.WriteStr ('GameplayCustom', 'BotsVS', gcBotsVS);
865 config.WriteStr ('GameplayNetwork', 'Map', gnMap);
866 config.WriteStr ('GameplayNetwork', 'GameMode', gnGameMode);
867 config.WriteInt ('GameplayNetwork', 'TimeLimit', gnTimeLimit);
868 config.WriteInt ('GameplayNetwork', 'GoalLimit', gnGoalLimit);
869 config.WriteInt ('GameplayNetwork', 'MaxLives', gnMaxLives);
870 config.WriteInt ('GameplayNetwork', 'Players', gnPlayers);
871 config.WriteBool('GameplayNetwork', 'TeamDamage', gnTeamDamage);
872 config.WriteBool('GameplayNetwork', 'AllowExit', gnAllowExit);
873 config.WriteBool('GameplayNetwork', 'WeaponStay', gnWeaponStay);
874 config.WriteBool('GameplayNetwork', 'Monsters', gnMonsters);
875 config.WriteStr ('GameplayNetwork', 'BotsVS', gnBotsVS);
877 config.WriteStr('MasterServer', 'IP', NetSlistIP);
878 config.WriteInt('MasterServer', 'Port', NetSlistPort);
880 config.WriteStr ('Server', 'Name', NetServerName);
881 config.WriteStr ('Server', 'Password', NetPassword);
882 config.WriteInt ('Server', 'Port', NetPort);
883 config.WriteInt ('Server', 'MaxClients', NetMaxClients);
884 config.WriteBool('Server', 'RCON', NetAllowRCON);
885 config.WriteStr ('Server', 'RCONPassword', NetRCONPassword);
886 config.WriteBool('Server', 'SyncWithMaster', NetUseMaster);
887 config.WriteBool('Server', 'ForwardPorts', NetForwardPorts);
888 config.WriteInt ('Server', 'UpdateInterval', NetUpdateRate);
889 config.WriteInt ('Server', 'ReliableUpdateInterval', NetRelupdRate);
890 config.WriteInt ('Server', 'MasterSyncInterval', NetMasterRate);
892 config.WriteInt ('Client', 'InterpolationSteps', NetInterpLevel);
893 config.WriteBool ('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate);
894 config.WriteBool ('Client', 'PredictSelf', NetPredictSelf);
895 config.WriteStr ('Client', 'LastIP', NetClientIP);
896 config.WriteInt ('Client', 'LastPort', NetClientPort);
898 config.SaveFile(FileName);
899 config.Free();
900 end;
902 procedure g_Options_Write_Language(FileName: String);
903 var
904 config: TConfig;
905 begin
906 e_WriteLog('Writing language config', TMsgType.Notify);
908 config := TConfig.CreateFile(FileName);
909 config.WriteStr('Game', 'Language', gLanguage);
910 config.SaveFile(FileName);
911 config.Free();
912 end;
914 procedure g_Options_Write_Video(FileName: String);
915 var
916 config: TConfig;
917 sW, sH: Integer;
918 begin
919 e_WriteLog('Writing resolution to config', TMsgType.Notify);
921 config := TConfig.CreateFile(FileName);
923 if gWinMaximized and (not gFullscreen) then
924 begin
925 sW := gWinSizeX;
926 sH := gWinSizeY;
927 end
928 else
929 begin
930 sW := gScreenWidth;
931 sH := gScreenHeight;
932 end;
933 e_LogWritefln(' (ws=%dx%d) (ss=%dx%d)', [gWinSizeX, gWinSizeY, gScreenWidth, gScreenHeight]);
935 config.WriteInt('Video', 'ScreenWidth', sW);
936 config.WriteInt('Video', 'ScreenHeight', sH);
937 config.WriteInt('Video', 'WinPosX', gWinRealPosX);
938 config.WriteInt('Video', 'WinPosY', gWinRealPosY);
939 config.WriteBool('Video', 'Fullscreen', gFullscreen);
940 config.WriteBool('Video', 'Maximized', gWinMaximized);
942 config.SaveFile(FileName);
943 config.Free();
944 end;
946 procedure g_Options_Write_Gameplay_Custom(FileName: String);
947 var
948 config: TConfig;
949 begin
950 e_WriteLog('Writing custom gameplay config', TMsgType.Notify);
952 config := TConfig.CreateFile(FileName);
954 config.WriteStr ('GameplayCustom', 'Map', gcMap);
955 config.WriteStr ('GameplayCustom', 'GameMode', gcGameMode);
956 config.WriteInt ('GameplayCustom', 'TimeLimit', gcTimeLimit);
957 config.WriteInt ('GameplayCustom', 'GoalLimit', gcGoalLimit);
958 config.WriteInt ('GameplayCustom', 'MaxLives', gcMaxLives);
959 config.WriteInt ('GameplayCustom', 'Players', gcPlayers);
960 config.WriteBool('GameplayCustom', 'TeamDamage', gcTeamDamage);
961 config.WriteBool('GameplayCustom', 'AllowExit', gcAllowExit);
962 config.WriteBool('GameplayCustom', 'WeaponStay', gcWeaponStay);
963 config.WriteBool('GameplayCustom', 'Monsters', gcMonsters);
964 config.WriteStr ('GameplayCustom', 'BotsVS', gcBotsVS);
966 config.SaveFile(FileName);
967 config.Free();
968 end;
970 procedure g_Options_Write_Gameplay_Net(FileName: String);
971 var
972 config: TConfig;
973 begin
974 e_WriteLog('Writing network gameplay config', TMsgType.Notify);
976 config := TConfig.CreateFile(FileName);
978 config.WriteStr ('GameplayNetwork', 'Map', gnMap);
979 config.WriteStr ('GameplayNetwork', 'GameMode', gnGameMode);
980 config.WriteInt ('GameplayNetwork', 'TimeLimit', gnTimeLimit);
981 config.WriteInt ('GameplayNetwork', 'GoalLimit', gnGoalLimit);
982 config.WriteInt ('GameplayNetwork', 'MaxLives', gnMaxLives);
983 config.WriteInt ('GameplayNetwork', 'Players', gnPlayers);
984 config.WriteBool('GameplayNetwork', 'TeamDamage', gnTeamDamage);
985 config.WriteBool('GameplayNetwork', 'AllowExit', gnAllowExit);
986 config.WriteBool('GameplayNetwork', 'WeaponStay', gnWeaponStay);
987 config.WriteBool('GameplayNetwork', 'Monsters', gnMonsters);
988 config.WriteStr ('GameplayNetwork', 'BotsVS', gnBotsVS);
990 config.SaveFile(FileName);
991 config.Free();
992 end;
994 procedure g_Options_Write_Net_Server(FileName: String);
995 var
996 config: TConfig;
997 begin
998 e_WriteLog('Writing server config', TMsgType.Notify);
1000 config := TConfig.CreateFile(FileName);
1002 config.WriteStr ('Server', 'Name', NetServerName);
1003 config.WriteStr ('Server', 'Password', NetPassword);
1004 config.WriteInt ('Server', 'Port', NetPort);
1005 config.WriteInt ('Server', 'MaxClients', NetMaxClients);
1006 config.WriteBool('Server', 'SyncWithMaster', NetUseMaster);
1007 config.WriteBool('Server', 'ForwardPorts', NetForwardPorts);
1009 config.SaveFile(FileName);
1010 config.Free();
1011 end;
1013 procedure g_Options_Write_Net_Client(FileName: String);
1014 var
1015 config: TConfig;
1016 begin
1017 e_WriteLog('Writing client config', TMsgType.Notify);
1019 config := TConfig.CreateFile(FileName);
1021 config.WriteStr('Client', 'LastIP', NetClientIP);
1022 config.WriteInt('Client', 'LastPort', NetClientPort);
1024 config.SaveFile(FileName);
1025 config.Free();
1026 end;
1028 end.