From: DeaDDooMER 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=98283c5d58028cf0b5204c44412f51c4a15e98a6;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 ccfd5d9..bc61b88 100644 --- a/src/game/g_basic.pas +++ b/src/game/g_basic.pas @@ -77,8 +77,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; @@ -102,7 +100,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 @@ -743,82 +741,6 @@ begin end; end; -function GetLines (text: string; FontID: DWORD; MaxWidth: Word): SSArray; - var - k: Integer = 1; - lines: Integer = 0; - i, len, lastsep: Integer; - - function PrepareStep (): Boolean; inline; - begin - // Skip leading spaces. - while PChar(text)[k-1] = ' ' do k += 1; - Result := k <= len; - i := k; - end; - - function GetLine (j: Integer; Strip: Boolean): String; inline; - begin - // Exclude trailing spaces from the line. - if Strip then - while text[j] = ' ' do j -= 1; - - Result := Copy(text, k, j-k+1); - end; - - function LineWidth (): Integer; inline; - var w, h: Word; - begin - e_CharFont_GetSize(FontID, GetLine(i, False), w, h); - Result := w; - end; - -begin - Result := nil; - len := Length(text); - //e_LogWritefln('GetLines @%s len=%s [%s]', [MaxWidth, len, text]); - - while PrepareStep() do - begin - // Get longest possible sequence (this is not constant because fonts are not monospaced). - lastsep := 0; - repeat - if text[i] in [' ', '.', ',', ':', ';'] - then lastsep := i; - i += 1; - until (i > len) or (LineWidth() > MaxWidth); - - // Do not include part of a word if possible. - if (lastsep-k > 3) and (i <= len) and (text[i] <> ' ') - then i := lastsep + 1; - - // Add line. - SetLength(Result, lines + 1); - Result[lines] := GetLine(i-1, True); - //e_LogWritefln(' -> (%s:%s::%s) [%s]', [k, i, LineWidth(), Result[lines]]); - lines += 1; - - k := i; - 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 fb46178..5ed507d 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, g_console, r_playermodel, g_map, g_weapons, xdynrec, wadreader; @@ -560,6 +559,81 @@ var Box: Array [0..8] of DWORD; Saved_Windows: SSArray; +function GetLines (text: string; FontID: DWORD; MaxWidth: Word): SSArray; + var + k: Integer = 1; + lines: Integer = 0; + i, len, lastsep: Integer; + + function PrepareStep (): Boolean; inline; + begin + // Skip leading spaces. + while PChar(text)[k-1] = ' ' do k += 1; + Result := k <= len; + i := k; + end; + + function GetLine (j: Integer; Strip: Boolean): String; inline; + begin + // Exclude trailing spaces from the line. + if Strip then + while text[j] = ' ' do j -= 1; + + Result := Copy(text, k, j-k+1); + end; + + function LineWidth (): Integer; inline; + var w, h: Word; + begin + e_CharFont_GetSize(FontID, GetLine(i, False), w, h); + Result := w; + end; + +begin + Result := nil; + len := Length(text); + //e_LogWritefln('GetLines @%s len=%s [%s]', [MaxWidth, len, text]); + + while PrepareStep() do + begin + // Get longest possible sequence (this is not constant because fonts are not monospaced). + lastsep := 0; + repeat + if text[i] in [' ', '.', ',', ':', ';'] + then lastsep := i; + i += 1; + until (i > len) or (LineWidth() > MaxWidth); + + // Do not include part of a word if possible. + if (lastsep-k > 3) and (i <= len) and (text[i] <> ' ') + then i := lastsep + 1; + + // Add line. + SetLength(Result, lines + 1); + Result[lines] := GetLine(i-1, True); + //e_LogWritefln(' -> (%s:%s::%s) [%s]', [k, i, LineWidth(), Result[lines]]); + lines += 1; + + k := i; + 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 +893,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 +902,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 @@ -2947,7 +3021,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; @@ -3102,7 +3176,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 3bc2d4c..1af2cbd 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 ba17540..bb6f10e 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 ace7191..6fb6434 100644 --- a/src/game/g_options.pas +++ b/src/game/g_options.pas @@ -79,7 +79,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 7d2752c..734e4cf 100644 --- a/src/game/g_panel.pas +++ b/src/game/g_panel.pas @@ -228,7 +228,6 @@ var implementation uses - {$INCLUDE ../nogl/noGLuses.inc} e_texture, g_basic, g_map, g_game, g_gfx, g_weapons, g_triggers, g_items, 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 f31bcee..c082c00 100644 --- a/src/game/g_player.pas +++ b/src/game/g_player.pas @@ -656,7 +656,6 @@ function g_Bot_GetCount(): Integer; 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 6b01c06..55e77cd 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 2509650..557ad14 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 81b3a03..26b8435 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