X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Fg_playermodel.pas;h=c2c7d4eb8557e2aadf0a8eee1c032b245baabcdd;hb=16342bee09fa001d05697571124e48a93cd35f2c;hp=820c7c5c52ad72bcfa0e5a49dfef8afb19e2381b;hpb=f517a19e84dae6941cff317aaf6fbcc3a5c5bb6f;p=d2df-sdl.git diff --git a/src/game/g_playermodel.pas b/src/game/g_playermodel.pas index 820c7c5..c2c7d4e 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,9 +74,11 @@ type Back: Boolean; end; +{$IFDEF ENABLE_GFX} TModelBlood = record R, G, B, Kind: Byte; end; +{$ENDIF} TModelSound = record ID: DWORD; @@ -87,8 +87,6 @@ type TModelSoundArray = Array of TModelSound; - TGibsArray = Array of Integer; - TPlayerModel = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF} private FDirection: TDirection; @@ -111,7 +109,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 @@ -132,12 +133,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 (ModelID: Integer; var Gibs: TGibsArray): Boolean; function g_PlayerModel_GetIndex (ModelName: String): Integer; +{$IFDEF ENABLE_GFX} + function g_PlayerModel_GetBlood(ModelName: String): TModelBlood; +{$ENDIF} + +procedure g_PlayerModel_LoadFake (ModelName, FileName: String); + (* --- private data --- *) type @@ -153,14 +157,18 @@ function g_PlayerModel_GetIndex (ModelName: String): Integer; PainSounds: TModelSoundArray; DieSounds: TModelSoundArray; SlopSound: Byte; - Blood: TModelBlood; + {$IFDEF ENABLE_GFX} + Blood: TModelBlood; + {$ENDIF} // ======================= FileName: String; Anim: TModelTextures; - GibsCount: Integer; - GibsResource:String; - GibsMask: String; - GibsOnce: Integer; + {$IFDEF ENABLE_GIBS} + GibsCount: Integer; + GibsResource:String; + GibsMask: String; + GibsOnce: Integer; + {$ENDIF} end; var @@ -168,9 +176,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); @@ -298,65 +310,16 @@ 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 + procedure g_PlayerModel_LoadFake (ModelName, FileName: String); + var id: Integer; 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); + SetLength(PlayerModelsArray, Length(PlayerModelsArray) + 1); + id := High(PlayerModelsArray); + PlayerModelsArray[id].Name := ModelName; + PlayerModelsArray[id].HaveWeapon := False; + PlayerModelsArray[id].FileName := FileName; 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; @@ -408,19 +371,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 @@ -495,10 +461,12 @@ begin SlopSound := Min(Max(config.ReadInt('Sound', 'slop', 0), 0), 2); - GibsCount := config.ReadInt('Gibs', 'count', 0); - GibsResource := config.ReadStr('Gibs', 'resource', 'GIBS'); - GibsMask := config.ReadStr('Gibs', 'mask', 'GIBSMASK'); - GibsOnce := config.ReadInt('Gibs', 'once', -1); + {$IFDEF ENABLE_GIBS} + GibsCount := config.ReadInt('Gibs', 'count', 0); + GibsResource := config.ReadStr('Gibs', 'resource', 'GIBS'); + GibsMask := config.ReadStr('Gibs', 'mask', 'GIBSMASK'); + GibsOnce := config.ReadInt('Gibs', 'once', -1); + {$ENDIF} ok := True; for aa := WP_FIRST + 1 to WP_LAST do @@ -631,69 +599,6 @@ 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; - - if PlayerModelsArray = nil then Exit; - for a := 0 to High(PlayerModelsArray) do - if PlayerModelsArray[a].Name = ModelName then - with PlayerModelsArray[a] do - 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]; - - Break; - end; - - Result := True; -end; - - 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; - - c := False; - SetLength(Gibs, gGibsCount); - for i := 0 to High(Gibs) do - begin - if c and (PlayerModelsArray[ModelID].GibsCount = 1) then - begin - SetLength(Gibs, i); - Break; - end; - - repeat - b := Random(PlayerModelsArray[ModelID].GibsCount); - until not ((PlayerModelsArray[ModelID].GibsOnce = b + 1) and c); - - Gibs[i] := b; - - c := PlayerModelsArray[ModelID].GibsOnce = b + 1; - end; - Result := True; - end; - function g_PlayerModel_GetNames(): SSArray; var i: DWORD; @@ -709,6 +614,7 @@ begin end; end; +{$IFDEF ENABLE_GFX} function g_PlayerModel_GetBlood(ModelName: string): TModelBlood; var a: Integer; @@ -726,6 +632,7 @@ begin Break; end; end; +{$ENDIF} procedure g_PlayerModel_FreeData(); var i, b: Integer; @@ -833,7 +740,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; @@ -853,10 +760,12 @@ end; FCurrentWeapon := Weapon end; +{$IFDEF ENABLE_GFX} function TPlayerModel.GetBlood (): TModelBlood; begin Result := PlayerModelsArray[FID].Blood end; +{$ENDIF} function TPlayerModel.GetName (): String; begin