X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Fg_playermodel.pas;h=af85837aaa8a16e9c88514b2bdf1e5de26c6be97;hb=e24864cf808f2ef7a10fc41999b341ef8212fbe7;hp=e4b485d9eac079280c34118ec8e237be918097c3;hpb=d7d166dc3cd287276202e862746208892c4cc89f;p=d2df-sdl.git diff --git a/src/game/g_playermodel.pas b/src/game/g_playermodel.pas index e4b485d..af85837 100644 --- a/src/game/g_playermodel.pas +++ b/src/game/g_playermodel.pas @@ -1,4 +1,4 @@ -(* Copyright (C) DooM 2D:Forever Developers +(* Copyright (C) Doom 2D: Forever Developers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,8 +20,9 @@ unit g_playermodel; interface uses - mempool, - MAPDEF, g_textures, g_basic, g_weapons, e_graphics, wadreader; + {$IFDEF USE_MEMPOOL}mempool,{$ENDIF} + MAPDEF, g_textures, g_basic, g_weapons, e_graphics, utils, + ImagingTypes, Imaging, ImagingUtility; const A_STAND = 0; @@ -82,7 +83,7 @@ type Array [A_STAND..A_LAST] of Array [TDirection.D_LEFT..TDirection.D_RIGHT] of Array of TDFPoint; - TPlayerModel = class(TPoolObject) + TPlayerModel = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF} private FName: String; FDirection: TDirection; @@ -130,17 +131,19 @@ type procedure g_PlayerModel_LoadData(); procedure g_PlayerModel_FreeData(); function g_PlayerModel_Load(FileName: String): Boolean; -function g_PlayerModel_GetNames(): SArray; +function g_PlayerModel_GetNames(): SSArray; function g_PlayerModel_GetInfo(ModelName: String): TModelInfo; function g_PlayerModel_Get(ModelName: String): TPlayerModel; function g_PlayerModel_GetAnim(ModelName: String; Anim: Byte; var _Anim, _Mask: TAnimation): Boolean; function g_PlayerModel_GetGibs(ModelName: String; var Gibs: TGibsArray): Boolean; + implementation uses + {$INCLUDE ../nogl/noGLuses.inc} g_main, g_sound, g_console, SysUtils, g_player, CONFIG, - GL, GLExt, e_sound, g_options, g_map, Math, e_log; + e_sound, g_options, g_map, Math, e_log, wadreader; type TPlayerModelInfo = record @@ -316,6 +319,65 @@ begin 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; @@ -464,7 +526,8 @@ begin 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; @@ -692,7 +755,7 @@ begin end; end; -function g_PlayerModel_GetNames(): SArray; +function g_PlayerModel_GetNames(): SSArray; var i: DWORD; begin