DEADSOFTWARE

render: add option -dDISABLE_RENDER
[d2df-sdl.git] / src / game / g_game.pas
index 0123ecd695f4fbcd8769477f23d9c9529a1125ed..69c12409394213a367cff2e2da5ad6d95ce50769 100644 (file)
@@ -18,8 +18,8 @@ unit g_game;
 interface
 
   uses
-    {$IFNDEF HEADLESS}
-      g_gui, g_touch,
+    {$IFDEF ENABLE_MENU}
+      g_gui,
     {$ENDIF}
     SysUtils, Classes, MAPDEF,
     g_base, g_basic, g_player, g_res_downloader,
@@ -113,9 +113,6 @@ function  g_Game_GetNextMap(): String;
 procedure g_Game_NextLevel();
 procedure g_Game_Pause(Enable: Boolean);
 procedure g_Game_HolmesPause(Enable: Boolean);
-{$IFNDEF HEADLESS}
-  procedure g_Game_InGameMenu(Show: Boolean);
-{$ENDIF}
 function  g_Game_IsWatchedPlayer(UID: Word): Boolean;
 function  g_Game_IsWatchedTeam(Team: Byte): Boolean;
 procedure g_Game_Message(Msg: String; Time: Word);
@@ -130,7 +127,7 @@ procedure g_Game_Announce_KillCombo(Param: Integer);
 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
 procedure g_Game_StartVote(Command, Initiator: string);
 procedure g_Game_CheckVote;
-{$IFNDEF HEADLESS}
+{$IFDEF ENABLE_RENDER}
   procedure g_TakeScreenShot(Filename: string = '');
 {$ENDIF}
 procedure g_FatalError(Text: String);
@@ -153,11 +150,14 @@ function IsActivePlayer(p: TPlayer): Boolean;
 function GetActivePlayerID_Next(Skip: Integer = -1): Integer;
 procedure SortGameStat(var stat: TPlayerStatArray);
 
-procedure KeyPress (K: Word);
 
+{$IFDEF ENABLE_MENU}
+  procedure g_Game_InGameMenu(Show: Boolean);
+{$ENDIF}
 {$IFNDEF HEADLESS}
   procedure CharPress (C: AnsiChar);
 {$ENDIF}
+  procedure KeyPress (K: Word);
 
 { procedure SetWinPause(Enable: Boolean); }
 
@@ -445,12 +445,30 @@ uses
   {$IFDEF ENABLE_HOLMES}
     g_holmes,
   {$ENDIF}
+  {$IFDEF ENABLE_MENU}
+    g_menu,
+  {$ENDIF}
+  {$IFDEF ENABLE_GFX}
+    g_gfx,
+  {$ENDIF}
+  {$IFDEF ENABLE_GIBS}
+    g_gibs,
+  {$ENDIF}
+  {$IFDEF ENABLE_SHELLS}
+    g_shells,
+  {$ENDIF}
+  {$IFDEF ENABLE_CORPSES}
+    g_corpses,
+  {$ENDIF}
+  {$IFDEF ENABLE_RENDER}
+    r_render,
+  {$ENDIF}
   {$IFNDEF HEADLESS}
-    r_render, g_menu, r_playermodel, g_system,
+    g_system,
   {$ENDIF}
   e_res, g_window,
   e_input, e_log, g_console, g_items, g_map, g_panel,
-  g_playermodel, g_gfx, g_options, Math,
+  g_playermodel, g_options, Math,
   g_triggers, g_monsters, e_sound, CONFIG,
   g_language, g_net, g_phys,
   ENet, e_msg, g_netmsg, g_netmaster,
@@ -696,13 +714,10 @@ Cheated:
 end;
 
 
+{$IFDEF ENABLE_MENU}
 procedure KeyPress (K: Word);
-{$IFNDEF HEADLESS}
-var
-  Msg: g_gui.TMessage;
-{$ENDIF}
+  var Msg: g_gui.TMessage;
 begin
-{$IFNDEF HEADLESS}
   case K of
     VK_ESCAPE: // <Esc>:
       begin
@@ -775,32 +790,47 @@ begin
         end;
       end;
   end;
-{$ENDIF}
 end;
+{$ELSE}
+  procedure KeyPress (K: Word);
+  begin
+    gJustChatted := False;
+    if gConsoleShow or gChatShow then
+    begin
+      g_Console_Control(K);
+    end
+  end;
+{$ENDIF}
 
 {$IFNDEF HEADLESS}
-procedure CharPress (C: AnsiChar);
-var
-  Msg: g_gui.TMessage;
-  a: Integer;
-begin
-  if gConsoleShow or gChatShow then
-  begin
-    g_Console_Char(C)
-  end
-  else if (g_ActiveWindow <> nil) then
-  begin
-    Msg.Msg := WM_CHAR;
-    Msg.WParam := Ord(C);
-    g_ActiveWindow.OnMessage(Msg);
-  end
-  else
+  procedure CharPress (C: AnsiChar);
+    {$IFDEF ENABLE_MENU}
+      var Msg: g_gui.TMessage;
+    {$ENDIF}
+    var a: Integer;
   begin
-    for a := 0 to 14 do charbuff[a] := charbuff[a+1];
-    charbuff[15] := upcase1251(C);
-    Cheat();
+    if gConsoleShow or gChatShow then
+    begin
+      g_Console_Char(C);
+    end
+    {$IFDEF ENABLE_MENU}
+      else if g_ActiveWindow <> nil then
+      begin
+        Msg.Msg := WM_CHAR;
+        Msg.WParam := Ord(C);
+        g_ActiveWindow.OnMessage(Msg);
+      end
+    {$ENDIF}
+    else
+    begin
+      for a := 0 to 14 do
+      begin
+        charbuff[a] := charbuff[a + 1];
+      end;
+      charbuff[15] := upcase1251(C);
+      Cheat;
+    end;
   end;
-end;
 {$ENDIF}
 
 
@@ -1239,7 +1269,7 @@ begin
 
   EndingGameCounter := 0;
 
-{$IFNDEF HEADLESS}
+{$IFDEF ENABLE_MENU}
   g_ActiveWindow := nil;
 {$ENDIF}
 
@@ -1256,29 +1286,30 @@ begin
         end
         else
         begin // Выход в главное меню
-{$IFDEF HEADLESS}
-          gState := STATE_MENU; // ???
-{$ELSE}
-          gMusic.SetByName('MUSIC_MENU');
-          gMusic.Play();
-          if gState <> STATE_SLIST then
-          begin
-            g_GUI_ShowWindow('MainMenu');
-            gState := STATE_MENU;
-          end else
-          begin
-            // Обновляем список серверов
-            slReturnPressed := True;
-            if g_Net_Slist_Fetch(slCurrent) then
+          {$IFDEF DISABLE_MENU}
+            gState := STATE_MENU; // ???
+          {$ELSE}
+            gMusic.SetByName('MUSIC_MENU');
+            gMusic.Play();
+            if gState <> STATE_SLIST then
             begin
-              if slCurrent = nil then
-                slWaitStr := _lc[I_NET_SLIST_NOSERVERS];
+              g_GUI_ShowWindow('MainMenu');
+              gState := STATE_MENU;
             end
             else
-              slWaitStr := _lc[I_NET_SLIST_ERROR];
-            g_Serverlist_GenerateTable(slCurrent, slTable);
-          end;
-{$ENDIF}
+            begin
+              // Обновляем список серверов
+              slReturnPressed := True;
+              if g_Net_Slist_Fetch(slCurrent) then
+              begin
+                if slCurrent = nil then
+                  slWaitStr := _lc[I_NET_SLIST_NOSERVERS];
+              end
+              else
+                slWaitStr := _lc[I_NET_SLIST_ERROR];
+              g_Serverlist_GenerateTable(slCurrent, slTable);
+            end;
+          {$ENDIF}
           g_Game_ExecuteEvent('ongameend');
         end;
       end;
@@ -1452,7 +1483,16 @@ begin
 
   g_Map_Free(freeTextures);
   g_Player_Free();
-  g_Player_RemoveAllCorpses();
+
+  {$IFDEF ENABLE_GIBS}
+    g_Gibs_RemoveAll;
+  {$ENDIF}
+  {$IFDEF ENALBE_SHELLS}
+    g_Shells_RemoveAll;
+  {$ENDIF}
+  {$IFDEF ENABLE_CORPSES}
+    g_Corpses_RemoveAll;
+  {$ENDIF}
 
   gGameSettings.GameType := GT_NONE;
   if gGameSettings.GameMode = GM_SINGLE then
@@ -1650,7 +1690,7 @@ begin
     end
   end;
 
-{$IFNDEF HEADLESS}
+{$IFDEF ENABLE_MENU}
   // HACK: add dynlight here
   if gwin_k8_enable_light_experiments then
   begin
@@ -1689,7 +1729,7 @@ end;
 
 procedure g_Game_Update();
   var
-    {$IFNDEF HEADLESS}
+    {$IFDEF ENABLE_MENU}
       Msg: g_gui.TMessage;
       w: Word;
     {$ENDIF}
@@ -1782,7 +1822,7 @@ begin
               e_KeyPressed(JOY2_ATTACK) or e_KeyPressed(JOY3_ATTACK)
             )
             and (not gJustChatted) and (not gConsoleShow) and (not gChatShow)
-{$IFNDEF HEADLESS}
+{$IFDEF ENABLE_MENU}
             and (g_ActiveWindow = nil)
 {$ENDIF}
           )
@@ -1803,7 +1843,7 @@ begin
               begin
               // Выход в главное меню:
                 g_Game_Free;
-{$IFNDEF HEADLESS}
+{$IFDEF ENABLE_MENU}
                 g_GUI_ShowWindow('MainMenu');
                 gMusic.SetByName('MUSIC_MENU');
                 gMusic.Play();
@@ -1833,7 +1873,7 @@ begin
             e_KeyPressed(JOY2_ATTACK) or e_KeyPressed(JOY3_ATTACK)
           )
           and (not gJustChatted) and (not gConsoleShow) and (not gChatShow)
-{$IFNDEF HEADLESS}
+{$IFDEF ENABLE_MENU}
           and (g_ActiveWindow = nil)
 {$ENDIF}
         )
@@ -1970,7 +2010,7 @@ begin
     // Обрабатываем клавиши игроков:
       if gPlayer1 <> nil then gPlayer1.ReleaseKeys();
       if gPlayer2 <> nil then gPlayer2.ReleaseKeys();
-{$IFDEF HEADLESS}
+{$IFDEF DISABLE_MENU}
       if (not gConsoleShow) and (not gChatShow) then
 {$ELSE}
       if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
@@ -1989,7 +2029,7 @@ begin
   // Наблюдатель
     if (gPlayer1 = nil) and (gPlayer2 = nil)
       and (not gConsoleShow) and (not gChatShow)
-{$IFNDEF HEADLESS}
+{$IFDEF ENABLE_MENU}
       and (g_ActiveWindow = nil)
 {$ENDIF}
     then
@@ -2155,9 +2195,19 @@ begin
     g_Triggers_Update();
     g_Weapon_Update();
     g_Monsters_Update();
-    g_GFX_Update();
+    {$IFDEF ENABLE_GFX}
+      g_GFX_Update;
+    {$ENDIF}
     g_Player_UpdateAll();
-    g_Player_UpdatePhysicalObjects();
+    {$IFDEF ENABLE_GIBS}
+      g_Gibs_Update;
+    {$ENDIF}
+    {$IFDEF ENABLE_CORPSES}
+      g_Corpses_Update;
+    {$ENDIF}
+    {$IFDEF ENABLE_SHELLS}
+      g_Shells_Update;
+    {$ENDIF}
 
     // server: send newly spawned monsters unconditionally
     if (gGameSettings.GameType = GT_SERVER) then
@@ -2236,7 +2286,7 @@ begin
   end; // if gameOn ...
 
 // Активно окно интерфейса - передаем клавиши ему:
-{$IFNDEF HEADLESS}
+{$IFDEF ENABLE_MENU}
   if g_ActiveWindow <> nil then
   begin
     w := e_GetFirstKeyPressed();
@@ -2282,7 +2332,7 @@ begin
   begin
     KeyPress(IK_F10);
   end;
-{$ENDIF} // NOT HEADLESS
+{$ENDIF}
 
   Time := GetTickCount64() {div 1000};
 
@@ -3251,7 +3301,16 @@ var
   nws: AnsiString;
 begin
   g_Map_Free((Map <> gCurrentMapFileName) and (oldMapPath <> gCurrentMapFileName));
-  g_Player_RemoveAllCorpses();
+
+  {$IFDEF ENABLE_GIBS}
+    g_Gibs_RemoveAll;
+  {$ENDIF}
+  {$IFDEF ENALBE_SHELLS}
+    g_Shells_RemoveAll;
+  {$ENDIF}
+  {$IFDEF ENABLE_CORPSES}
+    g_Corpses_RemoveAll;
+  {$ENDIF}
 
   if (not g_Game_IsClient) and
      (gSwitchGameMode <> gGameSettings.GameMode) and
@@ -3320,7 +3379,7 @@ begin
   begin
     //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
     result := g_Map_Load(NewWAD+':\'+ResName);
-    {$IFNDEF HEADLESS}
+    {$IFDEF ENABLE_RENDER}
       r_Render_LoadTextures;
     {$ENDIF}
   end;
@@ -3329,7 +3388,7 @@ begin
       g_Player_ResetAll(Force or gLastMap, gGameSettings.GameType = GT_SINGLE);
 
       gState := STATE_NONE;
-      {$IFNDEF HEADLESS}
+      {$IFDEF ENABLE_MENU}
         g_ActiveWindow := nil;
       {$ENDIF}
       gGameOn := True;
@@ -3576,7 +3635,16 @@ begin
     Exit;
   end;
 
-  g_Player_RemoveAllCorpses;
+  {$IFDEF ENABLE_GIBS}
+    g_Gibs_RemoveAll;
+  {$ENDIF}
+  {$IFDEF ENALBE_SHELLS}
+    g_Shells_RemoveAll;
+  {$ENDIF}
+  {$IFDEF ENABLE_CORPSES}
+    g_Corpses_RemoveAll;
+  {$ENDIF}
+
   g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
   if g_Game_IsNet then
     MH_SEND_GameEvent(NET_EV_LMS_START);
@@ -3927,12 +3995,18 @@ begin
   begin
     if Length(p) = 2 then
     begin
-      a := Max(0, StrToInt(p[1]));
-      g_GFX_SetMax(a)
+      {$IFDEF ENABLE_GFX}
+        a := Max(0, StrToInt(p[1]));
+        g_GFX_SetMax(a)
+      {$ENDIF}
     end
     else if Length(p) = 1 then
     begin
-      e_LogWritefln('%s', [g_GFX_GetMax()])
+      {$IFDEF ENABLE_GFX}
+        e_LogWritefln('%s', [g_GFX_GetMax()])
+      {$ELSE}
+        e_LogWritefln('%s', [0])
+      {$ENDIF}
     end
     else
     begin
@@ -3943,12 +4017,18 @@ begin
   begin
     if Length(p) = 2 then
     begin
-      a := Max(0, StrToInt(p[1]));
-      g_Shells_SetMax(a)
+      {$IFDEF ENABLE_SHELLS}
+        a := Max(0, StrToInt(p[1]));
+        g_Shells_SetMax(a)
+      {$ENDIF}
     end
     else if Length(p) = 1 then
     begin
-      e_LogWritefln('%s', [g_Shells_GetMax()])
+      {$IFDEF ENABLE_SHELLS}
+        e_LogWritefln('%s', [g_Shells_GetMax()])
+      {$ELSE}
+        e_LogWritefln('%s', [0])
+      {$ENDIF}
     end
     else
     begin
@@ -3959,12 +4039,18 @@ begin
   begin
     if Length(p) = 2 then
     begin
-      a := Max(0, StrToInt(p[1]));
-      g_Gibs_SetMax(a)
+      {$IFDEF ENABLE_GIBS}
+        a := Max(0, StrToInt(p[1]));
+        g_Gibs_SetMax(a)
+      {$ENDIF}
     end
     else if Length(p) = 1 then
     begin
-      e_LogWritefln('%s', [g_Gibs_GetMax()])
+      {$IFDEF ENABLE_GIBS}
+        e_LogWritefln('%s', [g_Gibs_GetMax()])
+      {$ELSE}
+        e_LogWritefln('%s', [0])
+      {$ENDIF}
     end
     else
     begin
@@ -3975,12 +4061,18 @@ begin
   begin
     if Length(p) = 2 then
     begin
-      a := Max(0, StrToInt(p[1]));
-      g_Corpses_SetMax(a)
+      {$IFDEF ENABLE_CORPSES}
+        a := Max(0, StrToInt(p[1]));
+        g_Corpses_SetMax(a)
+      {$ENDIF}
     end
     else if Length(p) = 1 then
     begin
-      e_LogWritefln('%s', [g_Corpses_GetMax()])
+      {$IFDEF ENABLE_CORPSES}
+        e_LogWritefln('%s', [g_Corpses_GetMax()])
+      {$ELSE}
+        e_LogWritefln('%s', [0])
+      {$ENDIF}
     end
     else
     begin
@@ -4562,7 +4654,7 @@ begin
   chstr := '';
   if cmd = 'pause' then
   begin
-    {$IFNDEF HEADLESS}
+    {$IFDEF ENABLE_MENU}
       if (g_ActiveWindow = nil) then
         g_Game_Pause(not gPauseMain);
     {$ELSE}
@@ -5498,8 +5590,8 @@ begin
   end
   else if cmd = 'screenshot' then
   begin
-    {$IFNDEF HEADLESS}
-      g_TakeScreenShot()
+    {$IFDEF ENABLE_RENDER}
+      g_TakeScreenShot;
     {$ENDIF}
   end
   else if cmd = 'weapon' then
@@ -5737,7 +5829,7 @@ begin
         g_Game_Free();
         g_Game_Quit();
       end;
-{$IFNDEF HEADLESS}
+{$IFDEF ENABLE_RENDER}
     'r_reset':
          r_Render_Apply;
 {$ENDIF}
@@ -5786,7 +5878,7 @@ begin
   end;
 end;
 
-{$IFNDEF HEADLESS}
+{$IFDEF ENABLE_RENDER}
 procedure g_TakeScreenShot(Filename: string = '');
   var t: TDateTime; dir, date, name: String;
 begin
@@ -5809,7 +5901,7 @@ begin
 end;
 {$ENDIF}
 
-{$IFNDEF HEADLESS}
+{$IFDEF ENABLE_MENU}
 procedure g_Game_InGameMenu(Show: Boolean);
 begin
   if (g_ActiveWindow = nil) and Show then
@@ -6289,7 +6381,7 @@ begin
     PBarWasHere := false;
   end;
 
-  {$IFNDEF HEADLESS}
+  {$IFDEF ENABLE_MENU}
     g_ActiveWindow := nil;
   {$ENDIF}
 
@@ -6573,8 +6665,10 @@ begin
   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');
 
+{$IFDEF ENABLE_GFX}
   conRegVar('pr_enabled', @gpart_dbg_enabled, 'enable/disable particles', 'particles');
   conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled, 'enable/disable particle physics', 'particle physics');
+{$ENDIF}
 
   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);