DEADSOFTWARE

alot of debugging code
[d2df-sdl.git] / src / game / g_console.pas
index 0231729f7bcd8655f9bf088489c1fcab74e30879..c9568f02005d8f09b7f75481eb2d1cb02f38be1b 100644 (file)
@@ -52,6 +52,8 @@ type
   TCommand = record
     Cmd: String;
     Proc: TCmdProc;
+    help: String;
+    hidden: Boolean;
   end;
 
   TAlias = record
@@ -157,7 +159,16 @@ begin
     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
@@ -334,17 +345,19 @@ var
 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();
@@ -365,7 +378,7 @@ begin
       Time := 0;
     end;
 
-  AddCommand('clear', ConsoleCommands);
+  AddCommand('clear', ConsoleCommands, 'clear console');
   AddCommand('clearhistory', ConsoleCommands);
   AddCommand('showhistory', ConsoleCommands);
   AddCommand('commands', ConsoleCommands);
@@ -388,11 +401,20 @@ begin
   AddCommand('d_player', DebugCommands);
   AddCommand('d_joy', DebugCommands);
 
-  AddCommand('dpp', ProfilerCommands);
-  AddCommand('dpu', ProfilerCommands);
-  AddCommand('dpc', ProfilerCommands);
-  AddCommand('r_gridrender', ProfilerCommands);
-  AddCommand('dbg_coldet_grid', ProfilerCommands);
+  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('p1_name', GameCVars);
   AddCommand('p2_name', GameCVars);
@@ -718,39 +740,122 @@ begin
   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;
 
-  t := nil;
+  ll := LowerCase(Line);
+  lpfx := '';
 
+  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