X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Fg_playermodel.pas;h=34dbdfdbe02be7ea1dc9a4056f684f3a3b92e5cd;hb=23a883f6c44413c380997e61b00a756bda95bc03;hp=ca4b6dc6c4fc92ae6e1ef9eab5f6171cc5c36cd4;hpb=79b65a82e3f122c0715a55b683ef2a92eff39a29;p=d2df-sdl.git diff --git a/src/game/g_playermodel.pas b/src/game/g_playermodel.pas index ca4b6dc..34dbdfd 100644 --- a/src/game/g_playermodel.pas +++ b/src/game/g_playermodel.pas @@ -18,9 +18,7 @@ unit g_playermodel; interface -uses - MAPDEF, g_textures, g_base, g_basic, g_weapons, r_graphics, utils, g_gfx, - ImagingTypes, Imaging, ImagingUtility; + uses MAPDEF, g_textures, g_base, g_basic, g_weapons, utils; const A_STAND = 0; @@ -76,24 +74,20 @@ type Back: Boolean; end; +{$IFDEF ENABLE_GFX} TModelBlood = record R, G, B, Kind: Byte; end; +{$ENDIF} TModelSound = record ID: DWORD; Level: Byte; end; - TGibSprite = record - ID: DWORD; - MaskID: DWORD; - Rect: TRectWH; - OnlyOne: Boolean; - end; - TModelSoundArray = Array of TModelSound; - TGibsArray = Array of TGibSprite; + + TGibsArray = Array of Integer; TPlayerModel = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF} private @@ -117,7 +111,10 @@ type function PlaySound(SoundType, Level: Byte; X, Y: Integer): Boolean; procedure Update(); - function GetBlood (): TModelBlood; + {$IFDEF ENABLE_GFX} + function GetBlood (): TModelBlood; + {$ENDIF} + function GetName (): String; published @@ -138,12 +135,15 @@ procedure g_PlayerModel_LoadAll; procedure g_PlayerModel_FreeData(); function g_PlayerModel_Load(FileName: String): Boolean; function g_PlayerModel_GetNames(): SSArray; -function g_PlayerModel_GetBlood(ModelName: String): TModelBlood; function g_PlayerModel_Get(ModelName: String): TPlayerModel; -function g_PlayerModel_GetAnim(ModelName: String; AnimTyp: Byte; var _Anim, _Mask: TAnimation): Boolean; -function g_PlayerModel_GetGibs(ModelName: String; var Gibs: TGibsArray): Boolean; +function g_PlayerModel_GetGibs (ModelID: Integer; var Gibs: TGibsArray): Boolean; +function g_PlayerModel_GetIndex (ModelName: String): Integer; + +{$IFDEF ENABLE_GFX} + function g_PlayerModel_GetBlood(ModelName: String): TModelBlood; +{$ENDIF} -function g_PlayerModel_GetIndex (ModelName: String): Integer; +procedure g_PlayerModel_LoadFake (ModelName, FileName: String); (* --- private data --- *) @@ -157,11 +157,12 @@ function g_PlayerModel_GetIndex (ModelName: String): Integer; FlagPoint: TDFPoint; FlagAngle: SmallInt; WeaponPoints: TWeaponPoints; - Gibs: TGibsArray; // !!! move to render PainSounds: TModelSoundArray; DieSounds: TModelSoundArray; SlopSound: Byte; - Blood: TModelBlood; + {$IFDEF ENABLE_GFX} + Blood: TModelBlood; + {$ENDIF} // ======================= FileName: String; Anim: TModelTextures; @@ -176,9 +177,13 @@ function g_PlayerModel_GetIndex (ModelName: String): Integer; implementation -uses - g_sound, g_console, SysUtils, g_player, CONFIG, r_textures, r_animations, - e_sound, g_options, g_map, Math, e_log, wadreader; + uses + {$IFDEF ENABLE_GFX} + g_gfx, + {$ENDIF} + g_sound, g_console, SysUtils, g_player, CONFIG, + e_sound, g_options, g_map, Math, e_log, wadreader + ; const FLAG_DEFPOINT: TDFPoint = (X:32; Y:16); @@ -306,72 +311,23 @@ end; 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 + procedure g_PlayerModel_LoadFake (ModelName, FileName: String); + var id: Integer; 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); + SetLength(PlayerModelsArray, Length(PlayerModelsArray) + 1); + id := High(PlayerModelsArray); + PlayerModelsArray[id].Name := ModelName; + PlayerModelsArray[id].HaveWeapon := False; + PlayerModelsArray[id].FileName := FileName; end; - FreeImage(img); -end; - function g_PlayerModel_Load(FileName: string): Boolean; var ID: DWORD; - a, b, len, lenpd, lenpd2, aa, bb, f: Integer; + a, b, len, aa, bb, f: Integer; cc: TDirection; config: TConfig; - pData, pData2: Pointer; + pData: Pointer; WAD: TWADFile; s: string; prefix: string; @@ -416,19 +372,22 @@ begin PlayerModelsArray[ID].Author := config.ReadStr('Model', 'author', ''); PlayerModelsArray[ID].Description := config.ReadStr('Model', 'description', ''); PlayerModelsArray[ID].FileName := FileName; - with PlayerModelsArray[ID] do - begin - Blood.R := MAX(0, MIN(255, config.ReadInt('Blood', 'R', 150))); - Blood.G := MAX(0, MIN(255, config.ReadInt('Blood', 'G', 0))); - Blood.B := MAX(0, MIN(255, config.ReadInt('Blood', 'B', 0))); - case config.ReadStr('Blood', 'Kind', 'NORMAL') of - 'NORMAL': Blood.Kind := BLOOD_NORMAL; - 'SPARKS': Blood.Kind := BLOOD_CSPARKS; - 'COMBINE': Blood.Kind := BLOOD_COMBINE; - else - Blood.Kind := BLOOD_NORMAL - end - end; + + {$IFDEF ENABLE_GFX} + with PlayerModelsArray[ID] do + begin + Blood.R := MAX(0, MIN(255, config.ReadInt('Blood', 'R', 150))); + Blood.G := MAX(0, MIN(255, config.ReadInt('Blood', 'G', 0))); + Blood.B := MAX(0, MIN(255, config.ReadInt('Blood', 'B', 0))); + case config.ReadStr('Blood', 'Kind', 'NORMAL') of + 'NORMAL': Blood.Kind := BLOOD_NORMAL; + 'SPARKS': Blood.Kind := BLOOD_CSPARKS; + 'COMBINE': Blood.Kind := BLOOD_COMBINE; + else + Blood.Kind := BLOOD_NORMAL + end + end; + {$ENDIF} for b := A_STAND to A_LAST do begin @@ -508,26 +467,6 @@ begin GibsMask := config.ReadStr('Gibs', 'mask', 'GIBSMASK'); GibsOnce := config.ReadInt('Gibs', 'once', -1); - SetLength(Gibs, GibsCount); // !!! remove load - if (Gibs <> nil) and - (WAD.GetResource('TEXTURES/' + GibsResource, pData, lenpd)) and - (WAD.GetResource('TEXTURES/' + GibsMask, pData2, lenpd2)) then - begin - for a := 0 to High(Gibs) do - 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 := 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 := GibsOnce = a + 1; - end; - - FreeMem(pData); - FreeMem(pData2); - end; - ok := True; for aa := WP_FIRST + 1 to WP_LAST do for bb := A_STAND to A_LAST do @@ -659,78 +598,34 @@ begin end; end; -function g_PlayerModel_GetAnim(ModelName: string; AnimTyp: Byte; var _Anim, _Mask: TAnimation): Boolean; -var - a: Integer; - c: Boolean; - ID: DWORD; -begin - Result := False; + function g_PlayerModel_GetGibs (ModelID: Integer; var Gibs: TGibsArray): Boolean; + var i, b: Integer; c: Boolean; + begin + Gibs := nil; + Result := False; + if (PlayerModelsArray = nil) or (gGibsCount = 0) then + Exit; - if PlayerModelsArray = nil then Exit; - for a := 0 to High(PlayerModelsArray) do - if PlayerModelsArray[a].Name = ModelName then - with PlayerModelsArray[a] do + c := False; + SetLength(Gibs, gGibsCount); + for i := 0 to High(Gibs) do + begin + if c and (PlayerModelsArray[ModelID].GibsCount = 1) then begin - if AnimTyp in [A_STAND, A_WALK] then c := True else c := False; - - if not g_Frames_Get(ID, Name + '_RIGHTANIM' + IntToStr(AnimTyp)) then - if not g_Frames_Get(ID, Name + '_LEFTANIM' + IntToStr(AnimTyp)) then Exit; - - _Anim := TAnimation.Create(ID, c, ModelSpeed[AnimTyp]); - _Anim.Speed := ModelSpeed[AnimTyp]; - - if not g_Frames_Get(ID, Name + '_RIGHTANIM' + IntToStr(AnimTyp) + '_MASK') then - if not g_Frames_Get(ID, Name + '_LEFTANIM' + IntToStr(AnimTyp) + '_MASK') then - Exit; - - _Mask := TAnimation.Create(ID, c, ModelSpeed[AnimTyp]); - _Mask.Speed := ModelSpeed[AnimTyp]; - + SetLength(Gibs, i); Break; end; - Result := True; -end; + repeat + b := Random(PlayerModelsArray[ModelID].GibsCount); + until not ((PlayerModelsArray[ModelID].GibsOnce = b + 1) and c); -function g_PlayerModel_GetGibs(ModelName: string; var Gibs: TGibsArray): Boolean; -var - a, i, b: Integer; - c: Boolean; -begin - Result := False; + Gibs[i] := b; - if PlayerModelsArray = nil then Exit; - if gGibsCount = 0 then Exit; - - c := False; - - SetLength(Gibs, gGibsCount); - - for a := 0 to High(PlayerModelsArray) do - if PlayerModelsArray[a].Name = ModelName then - begin - for i := 0 to High(Gibs) do - begin - if c and (Length(PlayerModelsArray[a].Gibs) = 1) then - begin - SetLength(Gibs, i); - Break; - end; - - repeat - b := Random(Length(PlayerModelsArray[a].Gibs)); - until not (PlayerModelsArray[a].Gibs[b].OnlyOne and c); - - Gibs[i] := PlayerModelsArray[a].Gibs[b]; - - if Gibs[i].OnlyOne then c := True; - end; - - Result := True; - Break; + c := PlayerModelsArray[ModelID].GibsOnce = b + 1; end; -end; + Result := True; + end; function g_PlayerModel_GetNames(): SSArray; var @@ -747,6 +642,7 @@ begin end; end; +{$IFDEF ENABLE_GFX} function g_PlayerModel_GetBlood(ModelName: string): TModelBlood; var a: Integer; @@ -764,6 +660,7 @@ begin Break; end; end; +{$ENDIF} procedure g_PlayerModel_FreeData(); var i, b: Integer; @@ -871,7 +768,7 @@ end; procedure TPlayerModel.SetFire (Fire: Boolean); begin if Fire then - FFireCounter := PlayerModelsArray[FID].ModelSpeed[A_ATTACK] * PlayerModelsArray[FID].Anim[TDirection.D_RIGHT, A_ATTACK].Frames + FFireCounter := PlayerModelsArray[FID].ModelSpeed[A_ATTACK] * PlayerModelsArray[FID].Anim[TDirection.D_RIGHT, A_ATTACK].Frames + 1 else FFireCounter := 0 end; @@ -891,10 +788,12 @@ end; FCurrentWeapon := Weapon end; +{$IFDEF ENABLE_GFX} function TPlayerModel.GetBlood (): TModelBlood; begin Result := PlayerModelsArray[FID].Blood end; +{$ENDIF} function TPlayerModel.GetName (): String; begin