DEADSOFTWARE

added optional framebuffer and resolution scaling
[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_Read(FileName: String);
28 procedure g_Options_Write(FileName: String);
29 procedure g_Options_Write_Gameplay_Custom(FileName: String);
30 procedure g_Options_Write_Gameplay_Net(FileName: String);
31 procedure g_Options_Write_Net_Server(FileName: String);
32 procedure g_Options_Write_Net_Client(FileName: String);
33 procedure g_Options_Commands (p: SSArray);
35 const DF_Default_Megawad_Start = 'megawads/DOOM2D.WAD:\MAP01';
37 var
38 gBPP: Integer;
39 gFreq: Byte;
40 gFullscreen: Boolean;
41 gWinSizeX, gWinSizeY: Integer;
42 gWinMaximized: Boolean;
43 gVSync: Boolean;
44 glLegacyNPOT: Boolean;
45 glRenderToFBO: Boolean = True;
46 gTextureFilter: Boolean;
47 gNoSound: Boolean;
48 gSoundLevel: Integer;
49 gMusicLevel: Integer;
50 gMaxSimSounds: Integer;
51 gMuteWhenInactive: Boolean;
52 gAdvCorpses: Boolean;
53 gAdvBlood: Boolean;
54 gAdvGibs: Boolean;
55 gGibsCount: Integer;
56 gBloodCount: Integer;
57 gFlash: Integer;
58 gDrawBackGround: Boolean;
59 gShowMessages: Boolean;
60 gRevertPlayers: Boolean;
61 gLanguage: String;
62 gAskLanguage: Boolean;
63 gSaveStats: Boolean = False;
64 gScreenshotStats: Boolean = False;
65 gcMap: String;
66 gcGameMode: String;
67 gcTimeLimit: Word;
68 gcGoalLimit: Word;
69 gcMaxLives: Byte;
70 gcPlayers: Byte;
71 gcTeamDamage: Boolean;
72 gcAllowExit: Boolean;
73 gcWeaponStay: Boolean;
74 gcMonsters: Boolean;
75 gcBotsVS: String;
76 gcDeathmatchKeys: Boolean = True;
77 gcRespawnItems: Boolean = True;
78 gcSpawnInvul: Integer = 0;
79 gnMap: String;
80 gnGameMode: String;
81 gnTimeLimit: Word;
82 gnGoalLimit: Word;
83 gnMaxLives: Byte;
84 gnPlayers: Byte;
85 gnTeamDamage: Boolean;
86 gnAllowExit: Boolean;
87 gnWeaponStay: Boolean;
88 gnMonsters: Boolean;
89 gnBotsVS: String;
90 gnDeathmatchKeys: Boolean = True;
91 gnRespawnItems: Boolean = True;
92 gnSpawnInvul: Integer = 0;
93 gsSDLSampleRate: Integer;
94 gsSDLBufferSize: Integer;
95 gDefaultMegawadStart: AnsiString;
96 gBerserkAutoswitch: Boolean;
97 glNPOTOverride: Boolean = false;
99 implementation
101 uses
102 {$INCLUDE ../nogl/noGLuses.inc}
103 {$IFDEF USE_SDL2}
104 SDL2,
105 {$ENDIF}
106 e_log, e_input, g_console, g_window, g_sound, g_gfx, g_player, Math,
107 g_map, g_net, g_netmaster, SysUtils, CONFIG, g_game, g_main, e_texture,
108 g_items, wadreader, e_graphics, g_touch, envvars, g_system;
110 var
111 machine: Integer;
113 function GenPlayerName (n: Integer): String;
114 begin
115 ASSERT(n >= 1);
116 Result := GetUserName;
117 if Result = '' then
118 Result := 'Player' + IntToStr(machine MOD 10000);
119 if n = 1 then
120 Result := Copy(Result, 1, 12) + ' '
121 else
122 Result := Copy(Result, 1, 10) + ' ' + IntToStr(n)
123 end;
125 {$IFDEF USE_SDL2}
126 procedure g_Options_SetDefaultVideo;
127 var display: TSDL_DisplayMode;
128 {$IFNDEF ANDROID}
129 var target, closest: TSDL_DisplayMode; percentage: Integer;
130 {$ENDIF}
131 begin
132 (* Display 0 = Primary display *)
133 gScreenWidth := 640;
134 gScreenHeight := 480;
135 gWinSizeX := 640;
136 gWinSizeY := 480;
137 //gBPP := SDL_BITSPERPIXEL(dispaly.format);
138 gBPP := 32;
139 {$IFDEF ANDROID}
140 gFullScreen := True; (* rotation not allowed? *)
141 {$ELSE}
142 gFullScreen := False;
143 {$ENDIF}
144 if SDL_GetDesktopDisplayMode(0, @display) = 0 then
145 begin
146 {$IFDEF ANDROID}
147 gWinSizeX := display.w;
148 gWinSizeY := display.h;
149 {$ELSE}
150 (* Window must be smaller than display *)
151 closest.w := display.w;
152 closest.h := display.h;
153 percentage := 75;
154 while (display.w - closest.w < 48) or (display.h - closest.h < 48) do
155 begin
156 if percentage < 25 then
157 begin
158 closest.w := display.w * 75 div 100;
159 closest.h := display.h * 75 div 100;
160 break;
161 end;
162 target.w := display.w * percentage div 100;
163 target.h := display.h * percentage div 100;
164 target.format := 0; (* didn't care *)
165 target.refresh_rate := 0; (* didn't care *)
166 target.driverdata := nil; (* init *)
167 SDL_GetClosestDisplayMode(0, @target, @closest);
168 Dec(percentage);
169 end;
170 gWinSizeX := closest.w;
171 gWinSizeY := closest.h;
172 //gBPP := SDL_BITSPERPIXEL(closest.format); (* Resolution list didn't work for some reason *)
173 {$ENDIF}
174 end
175 else
176 begin
177 e_LogWritefln('SDL: Failed to get desktop display mode: %s', [SDL_GetError])
178 end;
179 (* Must be positioned on primary display *)
180 gWinMaximized := False;
181 gVSync := True;
182 gTextureFilter := True;
183 glLegacyNPOT := False;
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 {$ELSE}
192 procedure g_Options_SetDefaultVideo;
193 begin
194 gWinSizeX := 640;
195 gWinSizeY := 480;
196 gBPP := 32;
197 gFullScreen := False;
198 gWinMaximized := False;
199 gVSync := True;
200 gTextureFilter := True;
201 glLegacyNPOT := False;
202 gScreenWidth := gWinSizeX;
203 gScreenHeight := gWinSizeY;
204 gRC_Width := gWinSizeX;
205 gRC_Height := gWinSizeY;
206 gRC_FullScreen := gFullScreen;
207 gRC_Maximized := gWinMaximized;
208 e_LogWriteLn('g_Options_SetDefaultVideo: w = ' + IntToStr(gWinSizeX) + ' h = ' + IntToStr(gWinSizeY));
209 g_Console_ResetBinds;
210 end;
211 {$ENDIF}
213 procedure g_Options_SetDefault();
214 var
215 i: Integer;
216 begin
217 (* section Sound *)
218 gNoSound := False;
219 gSoundLevel := 75;
220 gMusicLevel := 65;
221 gMaxSimSounds := 8;
222 gMuteWhenInactive := False;
223 gAnnouncer := ANNOUNCE_MEPLUS;
224 gSoundEffectsDF := True;
225 gUseChatSounds := True;
226 gsSDLSampleRate := 44100;
227 gsSDLBufferSize := 2048;
229 g_Sound_SetupAllVolumes(gSoundLevel, gMusicLevel);
231 with gPlayer1Settings do
232 begin
233 Name := GenPlayerName(1);
234 Model := STD_PLAYER_MODEL;
235 Color.R := PLAYER1_DEF_COLOR.R;
236 Color.G := PLAYER1_DEF_COLOR.G;
237 Color.B := PLAYER1_DEF_COLOR.B;
238 Team := TEAM_RED;
239 end;
241 with gPlayer2Settings do
242 begin
243 Name := GenPlayerName(2);
244 Model := STD_PLAYER_MODEL;
245 Color.R := PLAYER2_DEF_COLOR.R;
246 Color.G := PLAYER2_DEF_COLOR.G;
247 Color.B := PLAYER2_DEF_COLOR.B;
248 Team := TEAM_BLUE;
249 end;
251 (* section Joysticks *)
252 for i := 0 to e_MaxJoys - 1 do
253 begin
254 e_JoystickDeadzones[i] := 8192
255 end;
257 (* section Game *)
258 g_GFX_SetMax(2000);
259 g_Shells_SetMax(300);
260 g_Gibs_SetMax(150);
261 g_Corpses_SetMax(20);
262 gGibsCount := 32;
263 ITEM_RESPAWNTIME := 60 * 36;
264 gBloodCount := 4;
265 gAdvBlood := True;
266 gAdvCorpses := True;
267 gAdvGibs := True;
268 gFlash := 1;
269 gDrawBackGround := True;
270 gShowMessages := True;
271 gRevertPlayers := False;
272 gChatBubble := 4;
273 wadoptDebug := False;
274 wadoptFast := False;
275 e_FastScreenshots := True;
276 gDefaultMegawadStart := DF_Default_Megawad_Start;
277 gBerserkAutoswitch := True;
278 g_dbg_scale := 1.0;
279 gSaveStats := False;
281 gAskLanguage := True;
282 gLanguage := LANGUAGE_ENGLISH;
284 (* section GameplayCustom *)
285 gcMap := '';
286 gcGameMode := _lc[I_MENU_GAME_TYPE_DM];
287 gcTimeLimit := 0;
288 gcGoalLimit := 0;
289 gcMaxLives := 0;
290 gcPlayers := 1;
291 gcTeamDamage := False;
292 gcAllowExit := True;
293 gcWeaponStay := False;
294 gcMonsters := False;
295 gcBotsVS := 'Everybody';
296 gcDeathmatchKeys := True;
297 gcRespawnItems := True;
298 gcSpawnInvul := 0;
300 (* section GameplayNetwork *)
301 gnMap := '';
302 gnGameMode := _lc[I_MENU_GAME_TYPE_DM];
303 gnTimeLimit := 0;
304 gnGoalLimit := 0;
305 gnMaxLives := 0;
306 gnPlayers := 1;
307 gnTeamDamage := False;
308 gnAllowExit := True;
309 gnWeaponStay := False;
310 gnMonsters := False;
311 gnBotsVS := 'Everybody';
312 gnDeathmatchKeys := True;
313 gnRespawnItems := True;
314 gnSpawnInvul := 0;
316 (* section MasterServer *)
317 NetSlistIP := 'mpms.doom2d.org';
318 NetSlistPort := 25665;
319 g_Net_Slist_Set(NetSlistIP, NetSlistPort, NetSlistList);
321 (* section Server *)
322 NetServerName := 'Unnamed Server';
323 NetPassword := '';
324 NetPort := 25666;
325 NetMaxClients := 16;
326 NetAllowRCON := False;
327 NetRCONPassword := 'default';
328 NetUseMaster := True;
329 NetUpdateRate := 0;
330 NetRelupdRate := 18;
331 NetMasterRate := 60000;
332 NetForwardPorts := False;
334 (* section Client *)
335 NetInterpLevel := 2;
336 NetForcePlayerUpdate := False;
337 NetPredictSelf := True;
338 NetClientIP := '127.0.0.1';
339 NetClientPort := NetPort;
340 end;
342 procedure g_Options_Read(FileName: String);
343 var
344 config: TConfig;
345 section: String;
347 procedure ReadInteger (VAR v: Integer; param: String; minv: Integer = Low(Integer); maxv: Integer = High(Integer));
348 begin
349 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
350 end;
352 procedure ReadInteger (VAR v: LongWord; param: String; minv: LongWord = Low(LongWord); maxv: LongWord = High(LongWord)); overload;
353 begin
354 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
355 end;
357 procedure ReadInteger (VAR v: Word; param: String; minv: Word = Low(Word); maxv: Word = High(Word)); overload;
358 begin
359 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
360 end;
362 procedure ReadInteger (VAR v: Byte; param: String; minv: Byte = Low(Byte); maxv: Byte = High(Byte)); overload;
363 begin
364 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
365 end;
367 procedure ReadBoolean (VAR v: Boolean; param: String);
368 begin
369 v := config.ReadBool(section, param, v)
370 end;
372 procedure ReadString (VAR v: String; param: String);
373 begin
374 v := config.ReadStr(section, param, v)
375 end;
377 begin
378 gAskLanguage := True;
379 e_WriteLog('Reading config', TMsgType.Notify);
380 g_Options_SetDefault;
382 if FileExists(FileName) = False then
383 begin
384 e_WriteLog('Config file '+FileName+' not found', TMsgType.Warning);
385 g_Options_SetDefaultVideo;
386 Exit
387 end;
389 config := TConfig.CreateFile(FileName);
391 section := 'Player1';
392 with gPlayer1Settings do
393 begin
394 ReadString(Name, 'name');
395 ReadString(Model, 'model');
396 ReadInteger(Color.R, 'red', 0, 255);
397 ReadInteger(Color.G, 'green', 0, 255);
398 ReadInteger(Color.B, 'blue', 0, 255);
399 ReadInteger(Team, 'team');
400 if (Team < TEAM_RED) or (Team > TEAM_BLUE) then
401 Team := TEAM_RED;
402 end;
404 section := 'Player2';
405 with gPlayer2Settings do
406 begin
407 ReadString(Name, 'name');
408 ReadString(Model, 'model');
409 ReadInteger(Color.R, 'red', 0, 255);
410 ReadInteger(Color.G, 'green', 0, 255);
411 ReadInteger(Color.B, 'blue', 0, 255);
412 ReadInteger(Team, 'team');
413 if (Team < TEAM_RED) or (Team > TEAM_BLUE) then
414 Team := TEAM_RED;
415 end;
417 section := 'GameplayCustom';
418 ReadString(gcMap, 'Map');
419 ReadString(gcGameMode, 'GameMode');
420 ReadInteger(gcTimeLimit, 'TimeLimit', 0, 65535);
421 ReadInteger(gcGoalLimit, 'GoalLimit', 0, 65535);
422 ReadInteger(gcMaxLives, 'MaxLives', 0, 255);
423 ReadInteger(gcPlayers, 'Players', 0, 2);
424 ReadBoolean(gcTeamDamage, 'TeamDamage');
425 ReadBoolean(gcAllowExit, 'AllowExit');
426 ReadBoolean(gcWeaponStay, 'WeaponStay');
427 ReadBoolean(gcMonsters, 'Monsters');
428 ReadString(gcBotsVS, 'BotsVS');
429 ReadBoolean(gcDeathmatchKeys, 'DeathmatchKeys');
430 ReadBoolean(gcRespawnItems, 'RespawnItems');
431 ReadInteger(gcSpawnInvul, 'SpawnInvul');
433 with gGameSettings do
434 begin
435 GameMode := g_Game_TextToMode(gcGameMode);
436 if GameMode = GM_NONE then
437 GameMode := GM_DM;
438 if GameMode = GM_SINGLE then
439 GameMode := GM_COOP;
440 TimeLimit := gcTimeLimit;
441 GoalLimit := gcGoalLimit;
442 MaxLives := gcMaxLives;
444 Options := 0;
445 if gcTeamDamage then
446 Options := Options or GAME_OPTION_TEAMDAMAGE;
447 if gcAllowExit then
448 Options := Options or GAME_OPTION_ALLOWEXIT;
449 if gcWeaponStay then
450 Options := Options or GAME_OPTION_WEAPONSTAY;
451 if gcMonsters then
452 Options := Options or GAME_OPTION_MONSTERS;
453 if gcBotsVS = 'Everybody' then
454 Options := Options or GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER;
455 if gcBotsVS = 'Players' then
456 Options := Options or GAME_OPTION_BOTVSPLAYER;
457 if gcBotsVS = 'Monsters' then
458 Options := Options or GAME_OPTION_BOTVSMONSTER;
459 if gcDeathmatchKeys then
460 Options := Options or GAME_OPTION_DMKEYS;
461 if gcRespawnItems then
462 Options := Options or GAME_OPTION_RESPAWNITEMS;
463 end;
465 section := 'GameplayNetwork';
466 ReadString(gnMap, 'Map');
467 ReadString(gnGameMode, 'GameMode');
468 ReadInteger(gnTimeLimit, 'TimeLimit', 0, 65535);
469 ReadInteger(gnGoalLimit, 'GoalLimit', 0, 65535);
470 ReadInteger(gnMaxLives, 'MaxLives', 0, 255);
471 ReadInteger(gnPlayers, 'Players', 0, 2);
472 ReadBoolean(gnTeamDamage, 'TeamDamage');
473 ReadBoolean(gnAllowExit, 'AllowExit');
474 ReadBoolean(gnWeaponStay, 'WeaponStay');
475 ReadBoolean(gnMonsters, 'Monsters');
476 ReadString(gnBotsVS, 'BotsVS');
477 ReadBoolean(gnDeathmatchKeys, 'DeathmatchKeys');
478 ReadBoolean(gnRespawnItems, 'RespawnItems');
479 ReadInteger(gnSpawnInvul, 'SpawnInvul');
481 section := 'MasterServer';
482 ReadString(NetSlistIP, 'IP');
483 ReadInteger(NetSlistPort, 'Port', 0, 65535);
484 ReadString(NetSlistList, 'List');
485 g_Net_Slist_Set(NetSlistIP, NetSlistPort, NetSlistList);
487 section := 'Server';
488 ReadString(NetServerName, 'Name');
489 ReadString(NetPassword, 'Password');
490 ReadInteger(NetPort, 'Port', 0, 65535);
491 ReadInteger(NetMaxClients, 'MaxClients', 0, NET_MAXCLIENTS);
492 ReadBoolean(NetAllowRCON, 'RCON');
493 ReadString(NetRCONPassword, 'RCONPassword');
494 ReadBoolean(NetUseMaster, 'SyncWithMaster');
495 ReadInteger(NetUpdateRate, 'UpdateInterval', 0);
496 ReadInteger(NetRelupdRate, 'ReliableUpdateInterval', 0);
497 ReadInteger(NetMasterRate, 'MasterSyncInterval', 1);
498 ReadBoolean(NetForwardPorts, 'ForwardPorts');
500 section := 'Client';
501 ReadInteger(NetInterpLevel, 'InterpolationSteps', 0);
502 ReadBoolean(NetForcePlayerUpdate, 'ForcePlayerUpdate');
503 ReadBoolean(NetPredictSelf, 'PredictSelf');
504 ReadString(NetClientIP, 'LastIP');
505 ReadInteger(NetClientPort, 'LastPort', 0, 65535);
507 config.Free();
509 //if gTextureFilter then TEXTUREFILTER := GL_LINEAR else TEXTUREFILTER := GL_NEAREST;
510 end;
512 procedure g_Options_Write(FileName: String);
513 var config: TConfig;
514 begin
515 e_WriteLog('Writing config', TMsgType.Notify);
517 config := TConfig.CreateFile(FileName);
519 with config, gPlayer1Settings do
520 begin
521 WriteStr('Player1', 'Name', Name);
522 WriteStr('Player1', 'model', Model);
523 WriteInt('Player1', 'red', Color.R);
524 WriteInt('Player1', 'green', Color.G);
525 WriteInt('Player1', 'blue', Color.B);
526 WriteInt('Player1', 'team', Team);
527 end;
529 with config, gPlayer2Settings do
530 begin
531 WriteStr('Player2', 'Name', Name);
532 WriteStr('Player2', 'model', Model);
533 WriteInt('Player2', 'red', Color.R);
534 WriteInt('Player2', 'green', Color.G);
535 WriteInt('Player2', 'blue', Color.B);
536 WriteInt('Player2', 'team', Team);
537 end;
539 config.WriteStr ('GameplayCustom', 'Map', gcMap);
540 config.WriteStr ('GameplayCustom', 'GameMode', gcGameMode);
541 config.WriteInt ('GameplayCustom', 'TimeLimit', gcTimeLimit);
542 config.WriteInt ('GameplayCustom', 'GoalLimit', gcGoalLimit);
543 config.WriteInt ('GameplayCustom', 'MaxLives', gcMaxLives);
544 config.WriteInt ('GameplayCustom', 'Players', gcPlayers);
545 config.WriteBool('GameplayCustom', 'TeamDamage', gcTeamDamage);
546 config.WriteBool('GameplayCustom', 'AllowExit', gcAllowExit);
547 config.WriteBool('GameplayCustom', 'WeaponStay', gcWeaponStay);
548 config.WriteBool('GameplayCustom', 'Monsters', gcMonsters);
549 config.WriteStr ('GameplayCustom', 'BotsVS', gcBotsVS);
550 config.WriteBool('GameplayCustom', 'DeathmatchKeys', gcDeathmatchKeys);
551 config.WriteBool('GameplayCustom', 'RespawnItems', gcRespawnItems);
552 config.WriteInt ('GameplayCustom', 'SpawnInvul', gcSpawnInvul);
554 config.WriteStr ('GameplayNetwork', 'Map', gnMap);
555 config.WriteStr ('GameplayNetwork', 'GameMode', gnGameMode);
556 config.WriteInt ('GameplayNetwork', 'TimeLimit', gnTimeLimit);
557 config.WriteInt ('GameplayNetwork', 'GoalLimit', gnGoalLimit);
558 config.WriteInt ('GameplayNetwork', 'MaxLives', gnMaxLives);
559 config.WriteInt ('GameplayNetwork', 'Players', gnPlayers);
560 config.WriteBool('GameplayNetwork', 'TeamDamage', gnTeamDamage);
561 config.WriteBool('GameplayNetwork', 'AllowExit', gnAllowExit);
562 config.WriteBool('GameplayNetwork', 'WeaponStay', gnWeaponStay);
563 config.WriteBool('GameplayNetwork', 'Monsters', gnMonsters);
564 config.WriteStr ('GameplayNetwork', 'BotsVS', gnBotsVS);
565 config.WriteBool('GameplayNetwork', 'DeathmatchKeys', gnDeathmatchKeys);
566 config.WriteBool('GameplayNetwork', 'RespawnItems', gnRespawnItems);
567 config.WriteInt ('GameplayNetwork', 'SpawnInvul', gnSpawnInvul);
569 config.WriteStr('MasterServer', 'IP', NetSlistIP);
570 config.WriteInt('MasterServer', 'Port', NetSlistPort);
571 config.WriteStr('MasterServer', 'List', NetSlistList);
573 config.WriteStr ('Server', 'Name', NetServerName);
574 config.WriteStr ('Server', 'Password', NetPassword);
575 config.WriteInt ('Server', 'Port', NetPort);
576 config.WriteInt ('Server', 'MaxClients', NetMaxClients);
577 config.WriteBool('Server', 'RCON', NetAllowRCON);
578 config.WriteStr ('Server', 'RCONPassword', NetRCONPassword);
579 config.WriteBool('Server', 'SyncWithMaster', NetUseMaster);
580 config.WriteBool('Server', 'ForwardPorts', NetForwardPorts);
581 config.WriteInt ('Server', 'UpdateInterval', NetUpdateRate);
582 config.WriteInt ('Server', 'ReliableUpdateInterval', NetRelupdRate);
583 config.WriteInt ('Server', 'MasterSyncInterval', NetMasterRate);
585 config.WriteInt ('Client', 'InterpolationSteps', NetInterpLevel);
586 config.WriteBool ('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate);
587 config.WriteBool ('Client', 'PredictSelf', NetPredictSelf);
588 config.WriteStr ('Client', 'LastIP', NetClientIP);
589 config.WriteInt ('Client', 'LastPort', NetClientPort);
591 config.SaveFile(FileName);
592 config.Free();
593 end;
595 procedure g_Options_Write_Gameplay_Custom(FileName: String);
596 var
597 config: TConfig;
598 begin
599 e_WriteLog('Writing custom gameplay config', TMsgType.Notify);
601 config := TConfig.CreateFile(FileName);
603 config.WriteStr ('GameplayCustom', 'Map', gcMap);
604 config.WriteStr ('GameplayCustom', 'GameMode', gcGameMode);
605 config.WriteInt ('GameplayCustom', 'TimeLimit', gcTimeLimit);
606 config.WriteInt ('GameplayCustom', 'GoalLimit', gcGoalLimit);
607 config.WriteInt ('GameplayCustom', 'MaxLives', gcMaxLives);
608 config.WriteInt ('GameplayCustom', 'Players', gcPlayers);
609 config.WriteBool('GameplayCustom', 'TeamDamage', gcTeamDamage);
610 config.WriteBool('GameplayCustom', 'AllowExit', gcAllowExit);
611 config.WriteBool('GameplayCustom', 'WeaponStay', gcWeaponStay);
612 config.WriteBool('GameplayCustom', 'Monsters', gcMonsters);
613 config.WriteStr ('GameplayCustom', 'BotsVS', gcBotsVS);
614 config.WriteBool('GameplayCustom', 'DeathmatchKeys', gcDeathmatchKeys);
615 config.WriteBool('GameplayCustom', 'RespawnItems', gcRespawnItems);
616 config.WriteInt ('GameplayCustom', 'SpawnInvul', gcSpawnInvul);
618 config.SaveFile(FileName);
619 config.Free();
620 end;
622 procedure g_Options_Write_Gameplay_Net(FileName: String);
623 var
624 config: TConfig;
625 begin
626 e_WriteLog('Writing network gameplay config', TMsgType.Notify);
628 config := TConfig.CreateFile(FileName);
630 config.WriteStr ('GameplayNetwork', 'Map', gnMap);
631 config.WriteStr ('GameplayNetwork', 'GameMode', gnGameMode);
632 config.WriteInt ('GameplayNetwork', 'TimeLimit', gnTimeLimit);
633 config.WriteInt ('GameplayNetwork', 'GoalLimit', gnGoalLimit);
634 config.WriteInt ('GameplayNetwork', 'MaxLives', gnMaxLives);
635 config.WriteInt ('GameplayNetwork', 'Players', gnPlayers);
636 config.WriteBool('GameplayNetwork', 'TeamDamage', gnTeamDamage);
637 config.WriteBool('GameplayNetwork', 'AllowExit', gnAllowExit);
638 config.WriteBool('GameplayNetwork', 'WeaponStay', gnWeaponStay);
639 config.WriteBool('GameplayNetwork', 'Monsters', gnMonsters);
640 config.WriteStr ('GameplayNetwork', 'BotsVS', gnBotsVS);
641 config.WriteBool('GameplayNetwork', 'DeathmatchKeys', gnDeathmatchKeys);
642 config.WriteBool('GameplayNetwork', 'RespawnItems', gnRespawnItems);
643 config.WriteInt ('GameplayNetwork', 'SpawnInvul', gnSpawnInvul);
645 config.SaveFile(FileName);
646 config.Free();
647 end;
649 procedure g_Options_Write_Net_Server(FileName: String);
650 var
651 config: TConfig;
652 begin
653 e_WriteLog('Writing server config', TMsgType.Notify);
655 config := TConfig.CreateFile(FileName);
657 config.WriteStr ('Server', 'Name', NetServerName);
658 config.WriteStr ('Server', 'Password', NetPassword);
659 config.WriteInt ('Server', 'Port', NetPort);
660 config.WriteInt ('Server', 'MaxClients', NetMaxClients);
661 config.WriteBool('Server', 'SyncWithMaster', NetUseMaster);
662 config.WriteBool('Server', 'ForwardPorts', NetForwardPorts);
664 config.SaveFile(FileName);
665 config.Free();
666 end;
668 procedure g_Options_Write_Net_Client(FileName: String);
669 var
670 config: TConfig;
671 begin
672 e_WriteLog('Writing client config', TMsgType.Notify);
674 config := TConfig.CreateFile(FileName);
676 config.WriteStr('Client', 'LastIP', NetClientIP);
677 config.WriteInt('Client', 'LastPort', NetClientPort);
679 config.SaveFile(FileName);
680 config.Free();
681 end;
683 procedure g_Options_Commands (p: SSArray);
684 var cmd: AnsiString; i: Integer;
685 begin
686 cmd := LowerCase(p[0]);
687 case cmd of
688 'r_reset':
689 begin
690 sys_EnableVSync(gVSync);
691 gRC_Width := Max(1, gRC_Width);
692 gRC_Height := Max(1, gRC_Height);
693 gBPP := Max(1, gBPP);
694 if sys_SetDisplayMode(gRC_Width, gRC_Height, gBPP, gRC_FullScreen, gRC_Maximized) = True then
695 e_LogWriteln('resolution changed')
696 else
697 e_LogWriteln('resolution not changed')
698 end;
699 'g_language':
700 begin
701 if Length(p) = 2 then
702 begin
703 gAskLanguage := true;
704 gLanguage := LANGUAGE_ENGLISH;
705 case LowerCase(p[1]) of
706 'english':
707 begin
708 gAskLanguage := false;
709 gLanguage := LANGUAGE_ENGLISH;
710 end;
711 'russian':
712 begin
713 gAskLanguage := false;
714 gLanguage := LANGUAGE_RUSSIAN;
715 end;
716 'ask':
717 begin
718 gAskLanguage := true;
719 gLanguage := LANGUAGE_ENGLISH;
720 end;
721 end;
722 g_Language_Set(gLanguage)
723 end
724 else
725 begin
726 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd])
727 end
728 end;
729 'g_max_particles':
730 begin
731 if Length(p) = 2 then
732 begin
733 i := Max(0, StrToInt(p[1]));
734 g_GFX_SetMax(i)
735 end
736 else if Length(p) = 1 then
737 begin
738 e_LogWritefln('%s', [g_GFX_GetMax()])
739 end
740 else
741 begin
742 e_LogWritefln('usage: %s <n>', [cmd])
743 end
744 end;
745 'g_max_shells':
746 begin
747 if Length(p) = 2 then
748 begin
749 i := Max(0, StrToInt(p[1]));
750 g_Shells_SetMax(i)
751 end
752 else if Length(p) = 1 then
753 begin
754 e_LogWritefln('%s', [g_Shells_GetMax()])
755 end
756 else
757 begin
758 e_LogWritefln('usage: %s <n>', [cmd])
759 end
760 end;
761 'g_max_gibs':
762 begin
763 if Length(p) = 2 then
764 begin
765 i := Max(0, StrToInt(p[1]));
766 g_Gibs_SetMax(i)
767 end
768 else if Length(p) = 1 then
769 begin
770 e_LogWritefln('%s', [g_Gibs_GetMax()])
771 end
772 else
773 begin
774 e_LogWritefln('usage: %s <n>', [cmd])
775 end
776 end;
777 'g_max_corpses':
778 begin
779 if Length(p) = 2 then
780 begin
781 i := Max(0, StrToInt(p[1]));
782 g_Corpses_SetMax(i)
783 end
784 else if Length(p) = 1 then
785 begin
786 e_LogWritefln('%s', [g_Corpses_GetMax()])
787 end
788 else
789 begin
790 e_LogWritefln('usage: %s <n>', [cmd])
791 end
792 end;
793 'g_item_respawn_time':
794 begin
795 if Length(p) = 2 then
796 ITEM_RESPAWNTIME := Max(0, StrToInt(p[1])) * 36
797 else if Length(p) = 1 then
798 e_LogWritefln('%s', [ITEM_RESPAWNTIME div 36])
799 else
800 e_LogWritefln('usage: %s <n>', [cmd])
801 end;
802 end;
803 end;
805 initialization
806 Randomize;
807 machine := Random(10000);
809 (* Video *)
810 conRegVar('r_width', @gRC_Width, '', '');
811 conRegVar('r_height', @gRC_Height, '', '');
812 conRegVar('r_fullscreen', @gRC_FullScreen, '', '');
813 conRegVar('r_maximized', @gRC_Maximized, '', '');
814 conRegVar('r_bpp', @gBPP, '', '');
815 conRegVar('r_vsync', @gVSync, '', '');
816 conRegVar('r_texfilter', @gTextureFilter, '', '');
817 conRegVar('r_npot', @glNPOTOverride, '', '');
818 conRegVar('r_fbo', @glRenderToFBO, '', '');
820 (* Sound *)
821 conRegVar('s_nosound', @gNoSound, '', '');
822 conRegVar('s_soundvolume', @gSoundLevel, '', '');
823 conRegVar('s_musicvolume', @gMusicLevel, '', '');
824 conRegVar('s_maxsim', @gMaxSimSounds, '', ''); // e_sound_fmod/sdl?
825 conRegVar('s_muteinactive', @gMuteWhenInactive, '', '');
826 conRegVar('s_announcer', @gAnnouncer, '', '');
827 conRegVar('s_sfx', @gSoundEffectsDF, '', '');
828 conRegVar('s_chatsounds', @gUseChatSounds, '', '');
829 {$IFDEF USE_SDLMIXER}
830 conRegVar('sdl_mixer_samplerate', @gsSDLSampleRate, '', '');
831 conRegVar('sdl_mixer_buffersize', @gsSDLBufferSize, '', '');
832 {$ENDIF}
834 (* Game *)
835 conRegVar('g_gibs_count', @gGibsCount, '', '');
836 conRegVar('g_blood_count', @gBloodCount, '', '');
837 conRegVar('g_adv_blood', @gAdvBlood, '', '');
838 conRegVar('g_adv_corpses', @gAdvCorpses, '', '');
839 conRegVar('g_adv_gibs', @gAdvGibs, '', '');
840 conRegVar('r_flash', @gFlash, '', '');
841 conRegVar('r_background', @gDrawBackGround, '', '');
842 conRegVar('g_show_messages', @gShowMessages, '', '');
843 conRegVar('r_revert_players', @gRevertPlayers, '', '');
844 conRegVar('r_chat_bubble', @gChatBubble, '', '');
845 conRegVar('sfs_debug', @wadoptDebug, '', '');
846 conRegVar('sfs_fastmode', @wadoptFast, '', '');
847 conRegVar('g_fast_screenshots', @e_FastScreenshots, '', '');
848 conRegVar('g_default_megawad', @gDefaultMegawadStart, '', '');
849 conRegVar('g_save_stats', @gSaveStats, '', '');
850 conRegVar('g_screenshot_stats', @gScreenshotStats, '', '');
851 end.