summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5484741)
raw | patch | inline | side by side (parent: 5484741)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Fri, 22 Jun 2018 18:29:35 +0000 (21:29 +0300) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Fri, 22 Jun 2018 18:32:44 +0000 (21:32 +0300) |
src/engine/e_graphics.pas | patch | blob | history | |
src/game/g_playermodel.pas | patch | blob | history |
index bfef6d2e7e73f0f8f4476bbdcb49dd2cfc12b951..c5ec8f36e94baae90f47ca21bbd20d32416a36d9 100644 (file)
function e_CreateTextureMem(pData: Pointer; dataSize: LongInt; var ID: DWORD): Boolean;
function e_CreateTextureMemEx(pData: Pointer; dataSize: LongInt; var ID: DWORD; fX, fY, fWidth, fHeight: Word): Boolean;
procedure e_GetTextureSize(ID: DWORD; Width, Height: PWord);
-function e_GetTextureSize2(ID: DWORD): TRectWH;
procedure e_DeleteTexture(ID: DWORD);
procedure e_RemoveAllTextures();
if Height <> nil then Height^ := e_Textures[ID].tx.Height;
end;
-function e_GetTextureSize2(ID: DWORD): TRectWH;
-var
- data: PChar;
- x, y: Integer;
- w, h: Word;
- a: Boolean;
- lastline: Integer;
-begin
- w := e_Textures[ID].tx.Width;
- h := e_Textures[ID].tx.Height;
-
- Result.Y := 0;
- Result.X := 0;
- Result.Width := w;
- Result.Height := h;
-
-{$IFNDEF USE_NANOGL} // FIXIT: nanoGL doesn't support glGetTexImage
- if e_NoGraphics then Exit;
-
- data := GetMemory(w*h*4);
- glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, e_Textures[ID].tx.id);
- glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
-
- for y := h-1 downto 0 do
- begin
- lastline := y;
- a := True;
-
- for x := 1 to w-4 do
- begin
- a := Byte((data+y*w*4+x*4+3)^) <> 0;
- if a then Break;
- end;
-
- if a then
- begin
- Result.Y := h-lastline;
- Break;
- end;
- end;
-
- for y := 0 to h-1 do
- begin
- lastline := y;
- a := True;
-
- for x := 1 to w-4 do
- begin
- a := Byte((data+y*w*4+x*4+3)^) <> 0;
- if a then Break;
- end;
-
- if a then
- begin
- Result.Height := h-lastline-Result.Y;
- Break;
- end;
- end;
-
- for x := 0 to w-1 do
- begin
- lastline := x;
- a := True;
-
- for y := 1 to h-4 do
- begin
- a := Byte((data+y*w*4+x*4+3)^) <> 0;
- if a then Break;
- end;
-
- if a then
- begin
- Result.X := lastline+1;
- Break;
- end;
- end;
-
- for x := w-1 downto 0 do
- begin
- lastline := x;
- a := True;
-
- for y := 1 to h-4 do
- begin
- a := Byte((data+y*w*4+x*4+3)^) <> 0;
- if a then Break;
- end;
-
- if a then
- begin
- Result.Width := lastline-Result.X+1;
- Break;
- end;
- end;
-
- FreeMemory(data);
-{$ENDIF}
-end;
-
procedure e_ResizeWindow(Width, Height: Integer);
begin
if Height = 0 then
index c3bfdac266dcd9090cf9df3b418b988364357a22..5400de6b9b67c34df657353b8f7a09be33f382bd 100644 (file)
uses
{$IFDEF USE_MEMPOOL}mempool,{$ENDIF}
- MAPDEF, g_textures, g_basic, g_weapons, e_graphics, utils;
+ MAPDEF, g_textures, g_basic, g_weapons, e_graphics, utils,
+ ImagingTypes, Imaging, ImagingUtility;
const
A_STAND = 0;
end;
end;
+function g_PlayerModel_CalcGibSize (pData: Pointer; dataSize, x, y, w, h: Integer): TRectWH;
+ var i, j: Integer; done: Boolean; img: TImageData;
+
+ function IsVoid (i, j: Integer): Boolean;
+ begin
+ result := Byte((PByte(img.bits) + (y+j)*img.width*4 + (x+i)*4 + 3)^) = 0
+ end;
+
+begin
+ InitImage(img);
+ assert(LoadImageFromMemory(pData, dataSize, img));
+
+ (* trace x from right to left *)
+ done := false; i := 0;
+ while not done and (i < w) do
+ begin
+ j := 0;
+ while (j < h) and IsVoid(i, j) do inc(j);
+ done := (j < h) and (IsVoid(i, j) = false);
+ result.x := i;
+ inc(i);
+ end;
+
+ (* trace y from up to down *)
+ done := false; j := 0;
+ while not done and (j < h) do
+ begin
+ i := 0;
+ while (i < w) and IsVoid(i, j) do inc(i);
+ done := (i < w) and (IsVoid(i, j) = false);
+ result.y := j;
+ inc(j);
+ end;
+
+ (* trace x from right to left *)
+ done := false; i := w - 1;
+ while not done and (i >= 0) do
+ begin
+ j := 0;
+ while (j < h) and IsVoid(i, j) do inc(j);
+ done := (j < h) and (IsVoid(i, j) = false);
+ result.width := i - result.x + 1;
+ dec(i);
+ end;
+
+ (* trace y from down to up *)
+ done := false; j := h - 1;
+ while not done and (j >= 0) do
+ begin
+ i := 0;
+ while (i < w) and IsVoid(i, j) do inc(i);
+ done := (i < w) and (IsVoid(i, j) = false);
+ result.height := j - result.y + 1;
+ dec(j);
+ end;
+
+ FreeImage(img);
+end;
+
function g_PlayerModel_Load(FileName: string): Boolean;
var
ID: DWORD;
if e_CreateTextureMemEx(pData, lenpd, Gibs[a].ID, a*32, 0, 32, 32) and
e_CreateTextureMemEx(pData2, lenpd2, Gibs[a].MaskID, a*32, 0, 32, 32) then
begin
- Gibs[a].Rect := e_GetTextureSize2(Gibs[a].ID);
+ //Gibs[a].Rect := e_GetTextureSize2(Gibs[a].ID);
+ Gibs[a].Rect := g_PlayerModel_CalcGibSize(pData, lenpd, a*32, 0, 32, 32);
with Gibs[a].Rect do
if Height > 3 then Height := Height-1-Random(2);
Gibs[a].OnlyOne := config.ReadInt('Gibs', 'once', -1) = a+1;