diff --git a/src/game/g_console.pas b/src/game/g_console.pas
index aa5713030ed50452c92a87ddeb73d5d468c0a72a..3c2e7aa4420f2ee156c2f2fbf37e61e60bbb6ed7 100644 (file)
--- a/src/game/g_console.pas
+++ b/src/game/g_console.pas
-{$MODE DELPHI}
+(* Copyright (C) DooM 2D:Forever Developers
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *)
+{$INCLUDE ../shared/a_modes.inc}
unit g_console;
interface
TCommand = record
Cmd: String;
Proc: TCmdProc;
+ help: String;
+ hidden: Boolean;
end;
TAlias = record
g_Console_Add('');
g_Console_Add('Commands list:');
for a := High(Commands) downto 0 do
- g_Console_Add(' '+Commands[a].Cmd);
+ begin
+ if (Length(Commands[a].help) > 0) then
+ begin
+ g_Console_Add(' '+Commands[a].Cmd+' -- '+Commands[a].help);
+ end
+ else
+ begin
+ g_Console_Add(' '+Commands[a].Cmd);
+ end;
+ end;
end;
if Cmd = 'time' then
begin
SetLength(Whitelist, Length(Whitelist)+1);
a := High(Whitelist);
- Whitelist[a] := Cmd;
+ Whitelist[a] := LowerCase(Cmd);
end;
-procedure AddCommand(Cmd: String; Proc: TCmdProc);
+procedure AddCommand(Cmd: String; Proc: TCmdProc; ahelp: String=''; ahidden: Boolean=false);
var
a: Integer;
begin
SetLength(Commands, Length(Commands)+1);
a := High(Commands);
- Commands[a].Cmd := Cmd;
+ Commands[a].Cmd := LowerCase(Cmd);
Commands[a].Proc := Proc;
+ Commands[a].hidden := ahidden;
+ Commands[a].help := ahelp;
end;
procedure g_Console_Init();
Time := 0;
end;
- AddCommand('clear', ConsoleCommands);
+ AddCommand('clear', ConsoleCommands, 'clear console');
AddCommand('clearhistory', ConsoleCommands);
AddCommand('showhistory', ConsoleCommands);
AddCommand('commands', ConsoleCommands);
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('r_sq_draw', ProfilerCommands, 'accelerated spatial queries in rendering');
+ AddCommand('r_sq_use_grid', ProfilerCommands, 'use grid for render acceleration');
+ AddCommand('r_sq_use_tree', ProfilerCommands, 'use tree for render acceleration');
+ AddCommand('dbg_sq_coldet', ProfilerCommands, 'accelerated spatial queries in map coldet');
+
+ AddCommand('t_dump_node_queries', ProfilerCommands);
+
+ AddCommand('sq_use_grid', ProfilerCommands, 'use grid for map coldet acceleration');
+ AddCommand('sq_use_tree', ProfilerCommands, 'use tree for map coldet acceleration');
+
+ AddCommand('mon_sq_enabled', ProfilerCommands, 'use accelerated spatial queries for monsters');
+ AddCommand('wtrace_sq_enabled', ProfilerCommands, 'use accelerated weapon hitscan trace');
+
AddCommand('p1_name', GameCVars);
AddCommand('p2_name', GameCVars);
AddCommand('p1_color', GameCVars);
CPos := CPos + 1;
end;
-procedure Complete();
+
var
- i: Integer;
- t: Array of String;
+ tcomplist: array of string = nil;
+ tcompidx: array of Integer = nil;
+
+procedure Complete ();
+var
+ i, c: Integer;
+ tused: Integer;
+ ll, lpfx, cmd: string;
begin
- if Line = '' then
- Exit;
+ if (Length(Line) = 0) then
+ begin
+ g_Console_Add('');
+ for i := 0 to High(Commands) do
+ begin
+ if not Commands[i].hidden then
+ begin
+ if (Length(Commands[i].help) > 0) then
+ begin
+ g_Console_Add(' '+Commands[i].Cmd+' -- '+Commands[i].help);
+ end
+ else
+ begin
+ g_Console_Add(' '+Commands[i].Cmd);
+ end;
+ end;
+ end;
+ exit;
+ end;
+
+ ll := LowerCase(Line);
+ lpfx := '';
- t := nil;
+ if (Length(ll) > 1) and (ll[Length(ll)] = ' ') then
+ begin
+ ll := Copy(ll, 0, Length(ll)-1);
+ for i := 0 to High(Commands) do
+ begin
+ if Commands[i].hidden then continue;
+ if (Commands[i].Cmd = ll) then
+ begin
+ if (Length(Commands[i].help) > 0) then
+ begin
+ g_Console_Add(' '+Commands[i].Cmd+' -- '+Commands[i].help);
+ end;
+ end;
+ end;
+ exit;
+ end;
+ // build completion list
+ tused := 0;
for i := 0 to High(Commands) do
- if LowerCase(Line) = LowerCase(Copy(Commands[i].Cmd, 0, Length(Line))) then
+ begin
+ if Commands[i].hidden then continue;
+ cmd := Commands[i].Cmd;
+ if (Length(cmd) >= Length(ll)) and (ll = Copy(cmd, 0, Length(ll))) then
begin
- SetLength(t, Length(t) + 1);
- t[Length(t)-1] := Commands[i].Cmd;
+ if (tused = Length(tcomplist)) then
+ begin
+ SetLength(tcomplist, Length(tcomplist)+128);
+ SetLength(tcompidx, Length(tcompidx)+128);
+ end;
+ tcomplist[tused] := cmd;
+ tcompidx[tused] := i;
+ Inc(tused);
+ if (Length(cmd) > Length(lpfx)) then lpfx := cmd;
end;
+ end;
- if t = nil then
- Exit;
+ // get longest prefix
+ for i := 0 to tused-1 do
+ begin
+ cmd := tcomplist[i];
+ for c := 1 to Length(lpfx) do
+ begin
+ if (c > Length(cmd)) then break;
+ if (cmd[c] <> lpfx[c]) then begin lpfx := Copy(lpfx, 0, c-1); break; end;
+ end;
+ end;
- if Length(t) = 1 then
+ if (tused = 0) then exit;
+
+ if (tused = 1) then
+ begin
+ Line := tcomplist[0]+' ';
+ CPos := Length(Line)+1;
+ end
+ else
+ begin
+ // has longest prefix?
+ if (Length(lpfx) > Length(ll)) then
begin
- Line := t[0]+' ';
- CPos := Length(Line)+1;
+ Line := lpfx;
+ CPos:= Length(Line)+1;
end
- else
+ else
begin
g_Console_Add('');
- for i := 0 to High(t) do
- g_Console_Add(' '+t[i]);
+ for i := 0 to tused-1 do
+ begin
+ if (Length(Commands[tcompidx[i]].help) > 0) then
+ begin
+ g_Console_Add(' '+tcomplist[i]+' -- '+Commands[tcompidx[i]].help);
+ end
+ else
+ begin
+ g_Console_Add(' '+tcomplist[i]);
+ end;
+ end;
end;
+ end;
end;
+
procedure g_Console_Control(K: Word);
begin
case K of
end;
end;
-procedure g_Console_Add(L: String; Show: Boolean = False);
-{var
- a: Integer;}
-begin
- // Âûâîä ñòðîê ñ ïåðåíîñàìè ïî î÷åðåäè
- {
- while Pos(#10, L) > 0 do
- begin
- g_Console_Add(Copy(L, 1, Pos(#10, L) - 1), Show);
- Delete(L, 1, Pos(#10, L));
- end;
- }
-
- //SetLength(ConsoleHistory, Length(ConsoleHistory)+1);
- //ConsoleHistory[High(ConsoleHistory)] := L;
+procedure g_Console_Add (L: string; Show: Boolean=false);
- cbufPut(L);
- if (length(L) = 0) or ((L[length(L)] <> #10) and (L[length(L)] <> #13)) then cbufPut(#10);
-
- (*
- Show := Show and gAllowConsoleMessages;
-
- if Show and gShowMessages then
+ procedure conmsg (s: AnsiString);
+ var
+ a: Integer;
begin
+ if length(s) = 0 then exit;
for a := 0 to High(MsgArray) do
+ begin
with MsgArray[a] do
+ begin
if Time = 0 then
begin
- Msg := L;
+ Msg := s;
Time := MsgTime;
- Exit;
+ exit;
end;
-
- for a := 0 to High(MsgArray)-1 do
- MsgArray[a] := MsgArray[a+1];
-
+ end;
+ end;
+ for a := 0 to High(MsgArray)-1 do MsgArray[a] := MsgArray[a+1];
with MsgArray[High(MsgArray)] do
begin
Msg := L;
end;
end;
+var
+ f: Integer;
+begin
+ // put it to console
+ cbufPut(L);
+ if (length(L) = 0) or ((L[length(L)] <> #10) and (L[length(L)] <> #13)) then cbufPut(#10);
+
+ // now show 'em out of console too
+ Show := Show and gAllowConsoleMessages;
+ if Show and gShowMessages then
+ begin
+ // Âûâîä ñòðîê ñ ïåðåíîñàìè ïî î÷åðåäè
+ while length(L) > 0 do
+ begin
+ f := Pos(#10, L);
+ if f <= 0 then f := length(L)+1;
+ conmsg(Copy(L, 1, f-1));
+ Delete(L, 1, f);
+ end;
+ end;
+
+ //SetLength(ConsoleHistory, Length(ConsoleHistory)+1);
+ //ConsoleHistory[High(ConsoleHistory)] := L;
+
+ (*
{$IFDEF HEADLESS}
e_WriteLog('CON: ' + L, MSG_NOTIFY);
{$ENDIF}
if Trim(L) = '' then
Exit;
+ conSkipLines := 0; // "unscroll"
+
if L = 'goobers' then
begin
Line := '';