From: Ketmar Dark Date: Fri, 25 Aug 2017 01:42:59 +0000 (+0300) Subject: started `conRegVar()` API (only for booleans for now) X-Git-Url: http://deadsoftware.ru/gitweb?p=d2df-sdl.git;a=commitdiff_plain;h=7722f998fcc4984ad63c84975955eddc4ba7a2a9 started `conRegVar()` API (only for booleans for now) --- diff --git a/src/game/g_console.pas b/src/game/g_console.pas index 0668507..d16d9d6 100644 --- a/src/game/g_console.pas +++ b/src/game/g_console.pas @@ -18,6 +18,9 @@ unit g_console; interface +uses + wadreader; // for SArray + procedure g_Console_Init(); procedure g_Console_Update(); procedure g_Console_Draw(); @@ -32,8 +35,14 @@ function g_Console_CommandBlacklisted(C: String): Boolean; procedure conwriteln (const s: AnsiString; show: Boolean=false); procedure conwritefln (const s: AnsiString; args: array of const; show: Boolean=false); +// <0: no arg; 0/1: true/false +function conGetBoolArg (P: SArray; idx: Integer): Integer; + procedure g_Console_Chat_Switch(Team: Boolean = False); +procedure conRegVar (const conname: AnsiString; pvar: PBoolean; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false); + + var gConsoleShow: Boolean; // True - êîíñîëü îòêðûòà èëè îòêðûâàåòñÿ gChatShow: Boolean; @@ -46,17 +55,24 @@ implementation uses g_textures, g_main, e_graphics, e_input, g_game, - SysUtils, g_basic, g_options, wadreader, Math, + SysUtils, g_basic, g_options, Math, g_menu, g_language, g_net, g_netmsg, e_log, conbuf, utils; type + PCommand = ^TCommand; + TCmdProc = procedure (P: SArray); + TCmdProcEx = procedure (me: PCommand; P: SArray); TCommand = record Cmd: String; Proc: TCmdProc; + ProcEx: TCmdProcEx; help: String; hidden: Boolean; + ptr: Pointer; // various data + msg: AnsiString; // message for var changes + cheat: Boolean; end; TAlias = record @@ -64,6 +80,7 @@ type Commands: SArray; end; + const Step = 32; Alpha = 25; @@ -83,8 +100,8 @@ var //ConsoleHistory: SArray; CommandHistory: SArray; Whitelist: SArray; - Commands: Array of TCommand; - Aliases: Array of TAlias; + Commands: Array of TCommand = nil; + Aliases: Array of TAlias = nil; CmdIndex: Word; conSkipLines: Integer = 0; MsgArray: Array [0..4] of record @@ -92,6 +109,60 @@ var Time: Word; end; + +// <0: no arg; 0/1: true/false +function conGetBoolArg (P: SArray; idx: Integer): Integer; +begin + if (idx < 0) or (idx > High(P)) then begin result := -1; exit; end; + result := 0; + if (P[idx] = '1') or (CompareText(P[idx], 'on') = 0) or (CompareText(P[idx], 'true') = 0) or + (CompareText(P[idx], 'tan') = 0) or (CompareText(P[idx], 'yes') = 0) then result := 1; +end; + + +procedure boolVarHandler (me: PCommand; P: SArray); + + procedure binaryFlag (var flag: Boolean; msg: string); + begin + if (Length(p) > 2) then + begin + conwritefln('too many arguments to ''%s''', [P[0]]); + end + else + begin + case conGetBoolArg(P, 1) of + -1: begin end; + 0: if conIsCheatsEnabled then flag := false else begin conwriteln('not available'); exit; end; + 1: if conIsCheatsEnabled then flag := true else begin conwriteln('not available'); exit; end; + end; + if flag then conwritefln('%s: tan', [msg]) else conwritefln('%s: ona', [msg]); + end; + end; + +begin + binaryFlag(PBoolean(me.ptr)^, me.msg); +end; + + +procedure conRegVar (const conname: AnsiString; pvar: PBoolean; const ahelp: AnsiString; const amsg: AnsiString; acheat: Boolean=false); +var + f: Integer; + cp: PCommand; +begin + f := Length(Commands); + SetLength(Commands, f+1); + cp := @Commands[f]; + cp.Cmd := LowerCase(conname); + cp.Proc := nil; + cp.ProcEx := boolVarHandler; + cp.help := ahelp; + cp.hidden := false; + cp.ptr := pvar; + cp.msg := amsg; + cp.cheat := acheat; +end; + + function GetStrACmd(var Str: String): String; var a: Integer; @@ -351,16 +422,22 @@ begin Whitelist[a] := LowerCase(Cmd); end; -procedure AddCommand(Cmd: String; Proc: TCmdProc; ahelp: String=''; ahidden: Boolean=false); +procedure AddCommand(Cmd: String; Proc: TCmdProc; ahelp: String=''; ahidden: Boolean=false; acheat: Boolean=false); var a: Integer; + cp: PCommand; begin SetLength(Commands, Length(Commands)+1); a := High(Commands); - Commands[a].Cmd := LowerCase(Cmd); - Commands[a].Proc := Proc; - Commands[a].hidden := ahidden; - Commands[a].help := ahelp; + cp := @Commands[a]; + cp.Cmd := LowerCase(Cmd); + cp.Proc := Proc; + cp.ProcEx := nil; + cp.help := ahelp; + cp.hidden := ahidden; + cp.ptr := nil; + cp.msg := ''; + cp.cheat := acheat; end; procedure g_Console_Init(); @@ -404,22 +481,6 @@ begin AddCommand('d_player', DebugCommands); AddCommand('d_joy', DebugCommands); - AddCommand('pf_draw_frame', ProfilerCommands, 'draw frame rendering profiles'); - //AddCommand('pf_update_frame', ProfilerCommands); - AddCommand('pf_coldet', ProfilerCommands, 'draw collision detection profiles'); - AddCommand('pf_los', ProfilerCommands, 'draw monster LOS profiles'); - AddCommand('r_sq_draw', ProfilerCommands, 'accelerated spatial queries in rendering'); - AddCommand('cd_sq_enabled', ProfilerCommands, 'accelerated spatial queries in map coldet'); - AddCommand('mon_sq_enabled', ProfilerCommands, 'use accelerated spatial queries for monsters'); - AddCommand('wtrace_sq_enabled', ProfilerCommands, 'use accelerated weapon hitscan trace'); - - AddCommand('pr_enabled', ProfilerCommands, 'enable/disable particles'); - AddCommand('pr_phys_enabled', ProfilerCommands, 'enable/disable particle physics'); - AddCommand('los_enabled', ProfilerCommands, 'enable/disable LOS calculations'); - - AddCommand('mon_think', ProfilerCommands, 'enable/disable monster thinking'); - AddCommand('dbg_holmes', ProfilerCommands, 'turn Holmes on/off'); - AddCommand('p1_name', GameCVars); AddCommand('p2_name', GameCVars); AddCommand('p1_color', GameCVars); @@ -1181,12 +1242,21 @@ begin AddToHistory(L); for i := 0 to High(Commands) do + begin if Commands[i].Cmd = LowerCase(Arr[0]) then - if @Commands[i].Proc <> nil then + begin + if assigned(Commands[i].ProcEx) then + begin + Commands[i].ProcEx(@Commands[i], Arr); + exit; + end; + if assigned(Commands[i].Proc) then begin Commands[i].Proc(Arr); - Exit; + exit; end; + end; + end; g_Console_Add(Format(_lc[I_CONSOLE_UNKNOWN], [Arr[0]])); end; diff --git a/src/game/g_game.pas b/src/game/g_game.pas index 02a46f2..75d2693 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -124,7 +124,7 @@ procedure GameCVars(P: SArray); procedure GameCommands(P: SArray); procedure GameCheats(P: SArray); procedure DebugCommands(P: SArray); -procedure ProfilerCommands(P: SArray); +//procedure ProfilerCommands(P: SArray); procedure g_Game_Process_Params; procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean); procedure g_Game_StepLoading(); @@ -321,6 +321,8 @@ procedure g_ResetDynlights (); procedure g_AddDynLight (x, y, radius: Integer; r, g, b, a: Single); procedure g_DynLightExplosion (x, y, radius: Integer; r, g, b: Single); +function conIsCheatsEnabled (): Boolean; + implementation @@ -334,6 +336,16 @@ uses utils, sfs, g_holmes; +// ////////////////////////////////////////////////////////////////////////// // +function conIsCheatsEnabled (): Boolean; +begin + result := false; + if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and + (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode)) or g_Game_IsNet then exit; + result := true; +end; + + // ////////////////////////////////////////////////////////////////////////// // var profileFrameDraw: TProfiler = nil; @@ -4963,6 +4975,7 @@ begin end; end; +(* // profiler console commands procedure ProfilerCommands (P: SArray); var @@ -5014,7 +5027,7 @@ begin if (cmd = 'mon_think') then begin binaryFlag(gmon_debug_think, 'monster thinking'); exit; end; if (cmd = 'dbg_holmes') then begin binaryFlag(g_holmes_enabled, 'Holmes'); exit; end; end; - +*) procedure DebugCommands(P: SArray); var @@ -6996,4 +7009,22 @@ begin SetLength(pars, 0); end; +begin + conRegVar('pf_draw_frame', @g_profile_frame_draw, 'draw frame rendering profiles', 'render profiles'); + //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles'); + conRegVar('pf_coldet', @g_profile_collision, 'draw collision detection profiles', 'coldet profiles'); + conRegVar('pf_los', @g_profile_los, 'draw monster LOS profiles', 'monster LOS profiles'); + + conRegVar('r_sq_draw', @gdbg_map_use_accel_render, 'accelerated spatial queries in rendering', 'accelerated rendering'); + conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet, 'accelerated spatial queries in map coldet', 'accelerated map coldet'); + conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel, 'accelerated spatial queries for monsters', 'accelerated monster coldet'); + conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan'); + + conRegVar('pr_enabled', @gpart_dbg_enabled, 'enable/disable particles', 'particles'); + conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled, 'enable/disable particle physics', 'particle physics'); + + conRegVar('los_enabled', @gmon_dbg_los_enabled, 'enable/disable monster LOS calculations', 'monster LOS', true); + conRegVar('mon_think', @gmon_debug_think, 'enable/disable monster thinking', 'monster thinking', true); + + conRegVar('dbg_holmes', @g_holmes_enabled, 'enable/disable Holmes', 'Holmes', true); end. diff --git a/src/shared/MAPDEF.pas b/src/shared/MAPDEF.pas index 640b69d..f6678e9 100644 --- a/src/shared/MAPDEF.pas +++ b/src/shared/MAPDEF.pas @@ -30,6 +30,9 @@ interface uses MAPSTRUCT; +// *** WARNING! *** +// keep all constants in sync with "mapdesc.txt"! +// or even better: regenerate this part directly from "mapdesc.txt". const PANEL_NONE = 0; PANEL_WALL = 1;