From: DeaDDooMER <deaddoomer@deadsoftware.ru>
Date: Tue, 8 Jun 2021 08:00:30 +0000 (+0300)
Subject: cleanup: remove unneeded graphics dependencies
X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=f356426288dc03a804636aaa21c0d7e049e628ac;p=d2df-sdl.git

cleanup: remove unneeded graphics dependencies
---

diff --git a/src/engine/e_graphics.pas b/src/engine/e_graphics.pas
index 5edceb2..0f691ae 100644
--- a/src/engine/e_graphics.pas
+++ b/src/engine/e_graphics.pas
@@ -132,6 +132,7 @@ procedure e_TextureFontPrintCharEx (X, Y: Integer; Ch: Char; FontID: DWORD; Shad
 procedure e_ReleaseEngine();
 procedure e_BeginRender();
 procedure e_Clear(Mask: TGLbitfield; Red, Green, Blue: Single); overload;
+procedure e_Clear(Red, Green, Blue: Single); overload;
 procedure e_Clear(); overload;
 procedure e_EndRender();
 
@@ -1169,6 +1170,13 @@ begin
   glClear(Mask);
 end;
 
+procedure e_Clear(Red, Green, Blue: Single); overload;
+begin
+  if e_NoGraphics then Exit;
+  glClearColor(Red, Green, Blue, 0);
+  glClear(GL_COLOR_BUFFER_BIT);
+end;
+
 procedure e_Clear(); overload;
 begin
   if e_NoGraphics then Exit;
diff --git a/src/game/g_basic.pas b/src/game/g_basic.pas
index 7df493f..d58e487 100644
--- a/src/game/g_basic.pas
+++ b/src/game/g_basic.pas
@@ -76,8 +76,6 @@ function Sign(A: Single): ShortInt; overload;
 function PointToRect(X, Y, X1, Y1: Integer; Width, Height: Word): Integer;
 function GetAngle(baseX, baseY, pointX, PointY: Integer): SmallInt;
 function GetAngle2(vx, vy: Integer): SmallInt;
-function GetLines(Text: string; FontID: DWORD; MaxWidth: Word): SSArray;
-procedure Sort(var a: SSArray);
 function Sscanf(const s: string; const fmt: string;
                 const Pointers: array of Pointer): Integer;
 function InDWArray(a: DWORD; arr: DWArray): Boolean;
@@ -101,7 +99,7 @@ implementation
 
 uses
   Math, geom, e_log, g_map, g_gfx, g_player, SysUtils, MAPDEF,
-  StrUtils, e_graphics, g_monsters, g_items, g_game;
+  StrUtils, g_monsters, g_items, g_game;
 
 {$PUSH}
 {$WARN 2054 OFF} // unknwon env var
@@ -658,62 +656,6 @@ begin
     end;
 end;
 
-function GetLines (Text: string; FontID: DWORD; MaxWidth: Word): SSArray;
-  var i, j, len, lines: Integer;
-
-  function GetLine (j, i: Integer): String;
-  begin
-    result := Copy(text, j, i - j + 1);
-  end;
-
-  function GetWidth (j, i: Integer): Integer;
-    var w, h: Word;
-  begin
-    e_CharFont_GetSize(FontID, GetLine(j, i), w, h);
-    result := w
-  end;
-
-begin
-  result := nil; lines := 0;
-  j := 1; i := 1; len := Length(Text);
-  // e_LogWritefln('GetLines @%s len=%s [%s]', [MaxWidth, len, Text]);
-  while j <= len do
-  begin
-    (* --- Get longest possible sequence --- *)
-    while (i + 1 <= len) and (GetWidth(j, i + 1) <= MaxWidth) do Inc(i);
-    (* --- Do not include part of word --- *)
-    if (i < len) and (text[i] <> ' ') then
-      while (i >= j) and (text[i] <> ' ') do Dec(i);
-    (* --- Do not include spaces --- *)
-    while (i >= j) and (text[i] = ' ') do Dec(i);
-    (* --- Add line --- *)
-    SetLength(result, lines + 1);
-    result[lines] := GetLine(j, i);
-    // e_LogWritefln('  -> (%s:%s::%s) [%s]', [j, i, GetWidth(j, i), result[lines]]);
-    Inc(lines);
-    (* --- Skip spaces --- *)
-    while (i <= len) and (text[i] = ' ') do Inc(i);
-    j := i + 2;
-  end;
-end;
-
-procedure Sort(var a: SSArray);
-var
-  i, j: Integer;
-  s: string;
-begin
-  if a = nil then Exit;
-
-  for i := High(a) downto Low(a) do
-    for j := Low(a) to High(a)-1 do
-      if LowerCase(a[j]) > LowerCase(a[j+1]) then
-      begin
-        s := a[j];
-        a[j] := a[j+1];
-        a[j+1] := s;
-      end;
-end;
-
 function Sscanf(const s: String; const fmt: String;
                 const Pointers: array of Pointer): Integer;
 var
diff --git a/src/game/g_gui.pas b/src/game/g_gui.pas
index 7329f52..3ab72ed 100644
--- a/src/game/g_gui.pas
+++ b/src/game/g_gui.pas
@@ -550,7 +550,6 @@ procedure g_GUI_LoadMenuPos();
 implementation
 
 uses
-  {$INCLUDE ../nogl/noGLuses.inc}
   g_textures, g_sound, SysUtils, e_res,
   g_game, Math, StrUtils, g_player, g_options, r_playermodel,
   g_map, g_weapons, xdynrec, wadreader;
@@ -560,6 +559,59 @@ var
   Box: Array [0..8] of DWORD;
   Saved_Windows: SSArray;
 
+function GetLines (Text: string; FontID: DWORD; MaxWidth: Word): SSArray;
+  var i, j, len, lines: Integer;
+
+  function GetLine (j, i: Integer): String;
+  begin
+    result := Copy(text, j, i - j + 1);
+  end;
+
+  function GetWidth (j, i: Integer): Integer;
+    var w, h: Word;
+  begin
+    e_CharFont_GetSize(FontID, GetLine(j, i), w, h);
+    result := w
+  end;
+
+begin
+  result := nil; lines := 0;
+  j := 1; i := 1; len := Length(Text);
+  // e_LogWritefln('GetLines @%s len=%s [%s]', [MaxWidth, len, Text]);
+  while j <= len do
+  begin
+    (* --- Get longest possible sequence --- *)
+    while (i + 1 <= len) and (GetWidth(j, i + 1) <= MaxWidth) do Inc(i);
+    (* --- Do not include part of word --- *)
+    if (i < len) and (text[i] <> ' ') then
+      while (i >= j) and (text[i] <> ' ') do Dec(i);
+    (* --- Do not include spaces --- *)
+    while (i >= j) and (text[i] = ' ') do Dec(i);
+    (* --- Add line --- *)
+    SetLength(result, lines + 1);
+    result[lines] := GetLine(j, i);
+    // e_LogWritefln('  -> (%s:%s::%s) [%s]', [j, i, GetWidth(j, i), result[lines]]);
+    Inc(lines);
+    (* --- Skip spaces --- *)
+    while (i <= len) and (text[i] = ' ') do Inc(i);
+    j := i + 2;
+  end;
+end;
+
+procedure Sort (var a: SSArray);
+  var i, j: Integer; s: string;
+begin
+  if a = nil then Exit;
+
+  for i := High(a) downto Low(a) do
+    for j := Low(a) to High(a) - 1 do
+      if LowerCase(a[j]) > LowerCase(a[j + 1]) then
+      begin
+        s := a[j];
+        a[j] := a[j + 1];
+        a[j + 1] := s;
+      end;
+end;
 
 procedure g_GUI_Init();
 begin
@@ -819,7 +871,7 @@ begin
   if FBackTexture <> '' then  // Here goes code duplication from g_game.pas:DrawMenuBackground()
     if g_Texture_Get(FBackTexture, ID) then
     begin
-      e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
+      e_Clear(0, 0, 0);
       e_GetTextureSize(ID, @tw, @th);
       if tw = th then
         tw := round(tw * 1.333 * (gScreenHeight / th))
@@ -828,7 +880,7 @@ begin
       e_DrawSize(ID, (gScreenWidth - tw) div 2, 0, 0, False, False, tw, gScreenHeight);
     end
     else
-      e_Clear(GL_COLOR_BUFFER_BIT, 0.5, 0.5, 0.5);
+      e_Clear(0.5, 0.5, 0.5);
 
   // small hack here
   if FName = 'AuthorsMenu' then
@@ -2985,7 +3037,7 @@ begin
   SetLength(FItems, Length(FItems)+1);
   FItems[High(FItems)] := Item;
 
-  if FSort then g_Basic.Sort(FItems);
+  if FSort then g_gui.Sort(FItems);
 end;
 
 function TGUIListBox.ItemExists (item: String): Boolean;
@@ -3140,7 +3192,7 @@ begin
   FStartLine := 0;
   FIndex := -1;
 
-  if FSort then g_Basic.Sort(FItems);
+  if FSort then g_gui.Sort(FItems);
 end;
 
 procedure TGUIListBox.SelectItem(Item: String);
diff --git a/src/game/g_menu.pas b/src/game/g_menu.pas
index 67814ad..0e8b8af 100644
--- a/src/game/g_menu.pas
+++ b/src/game/g_menu.pas
@@ -43,7 +43,6 @@ var
 implementation
 
 uses
-  {$INCLUDE ../nogl/noGLuses.inc}
   g_gui, g_textures, e_graphics, g_main, g_window, g_game, g_map,
   g_basic, g_console, g_sound, g_gfx, g_player, g_options, g_weapons,
   e_log, SysUtils, CONFIG, g_playermodel, DateUtils,
diff --git a/src/game/g_netmaster.pas b/src/game/g_netmaster.pas
index d9c62c9..fb2729b 100644
--- a/src/game/g_netmaster.pas
+++ b/src/game/g_netmaster.pas
@@ -176,7 +176,7 @@ function GetTimerMS (): Int64;
 implementation
 
 uses
-  e_input, e_graphics, e_log, g_window, g_net, g_console,
+  e_input, e_log, g_window, g_net, g_console,
   g_map, g_game, g_sound, g_gui, g_menu, g_options, g_language, g_basic, r_game,
   wadreader, g_system, utils, hashtable;
 
diff --git a/src/game/g_options.pas b/src/game/g_options.pas
index c29bb4d..20eb210 100644
--- a/src/game/g_options.pas
+++ b/src/game/g_options.pas
@@ -80,7 +80,6 @@ var
 implementation
 
 uses
-  {$INCLUDE ../nogl/noGLuses.inc}
   {$IFDEF USE_SDL2}
     SDL2,
   {$ENDIF}
diff --git a/src/game/g_panel.pas b/src/game/g_panel.pas
index 07d1622..854a15c 100644
--- a/src/game/g_panel.pas
+++ b/src/game/g_panel.pas
@@ -222,7 +222,6 @@ var
 implementation
 
 uses
-  {$INCLUDE ../nogl/noGLuses.inc}
   e_texture, g_basic, g_map, g_game, g_gfx, g_weapons, g_triggers,
   g_console, g_language, g_monsters, g_player, g_grid, e_log, geom, utils, xstreams;
 
diff --git a/src/game/g_player.pas b/src/game/g_player.pas
index 0237b44..dbef498 100644
--- a/src/game/g_player.pas
+++ b/src/game/g_player.pas
@@ -632,7 +632,6 @@ procedure g_Bot_RemoveAll();
 implementation
 
 uses
-{$INCLUDE ../nogl/noGLuses.inc}
 {$IFDEF ENABLE_HOLMES}
   g_holmes,
 {$ENDIF}
diff --git a/src/game/g_playermodel.pas b/src/game/g_playermodel.pas
index f91620e..40a3489 100644
--- a/src/game/g_playermodel.pas
+++ b/src/game/g_playermodel.pas
@@ -19,7 +19,6 @@ unit g_playermodel;
 interface
 
 uses
-  {$IFDEF USE_MEMPOOL}mempool,{$ENDIF}
   MAPDEF, g_textures, g_basic, g_weapons, e_graphics, utils, g_gfx,
   ImagingTypes, Imaging, ImagingUtility;
 
@@ -168,7 +167,6 @@ function  g_PlayerModel_GetGibs(ModelName: String; var Gibs: TGibsArray): Boolea
 implementation
 
 uses
-  {$INCLUDE ../nogl/noGLuses.inc}
   g_main, g_sound, g_console, SysUtils, g_player, CONFIG,
   e_sound, g_options, g_map, Math, e_log, wadreader;
 
diff --git a/src/game/g_saveload.pas b/src/game/g_saveload.pas
index 80fcbfc..eb1a79a 100644
--- a/src/game/g_saveload.pas
+++ b/src/game/g_saveload.pas
@@ -18,8 +18,7 @@ unit g_saveload;
 interface
 
 uses
-  SysUtils, Classes,
-  e_graphics, g_phys, g_textures;
+  SysUtils, Classes, g_phys, g_textures;
 
 
 function g_GetSaveName (n: Integer; out valid: Boolean): AnsiString;
diff --git a/src/game/g_triggers.pas b/src/game/g_triggers.pas
index 779a9a1..f89aa9f 100644
--- a/src/game/g_triggers.pas
+++ b/src/game/g_triggers.pas
@@ -19,7 +19,7 @@ interface
 
 uses
   SysUtils, Variants, Classes,
-  MAPDEF, e_graphics, g_basic, g_sound,
+  MAPDEF, g_basic, g_sound,
   xdynrec, hashtable, exoma;
 
 type
diff --git a/src/game/g_weapons.pas b/src/game/g_weapons.pas
index c94282d..21c5803 100644
--- a/src/game/g_weapons.pas
+++ b/src/game/g_weapons.pas
@@ -20,7 +20,7 @@ interface
 
 uses
   SysUtils, Classes, mempool,
-  g_textures, g_basic, e_graphics, g_phys, xprofiler;
+  g_textures, g_basic, g_phys, xprofiler;
 
 
 type