index 34fc9e71ef620206bbe9a4eda0a0f21923294519..7a55bf758b8b9744c5a7883c43fbcb0659d23351 100644 (file)
interface
-uses
- MAPDEF, g_textures, g_base, g_basic, g_weapons, r_graphics, utils, g_gfx,
- ImagingTypes, Imaging, ImagingUtility;
+ uses MAPDEF, g_animations, g_base, g_basic, g_weapons, utils;
const
A_STAND = 0;
W_POS_NORMAL = 0;
W_POS_UP = 1;
W_POS_DOWN = 2;
+ W_POS_LAST = W_POS_DOWN;
W_ACT_NORMAL = 0;
W_ACT_FIRE = 1;
+ W_ACT_LAST = W_ACT_FIRE;
FLAG_BASEPOINT: TDFPoint = (X:16; Y:43);
type
TWeaponPoints = Array [WP_FIRST + 1..WP_LAST, A_STAND..A_LAST, TDirection.D_LEFT..TDirection.D_RIGHT] of Array of TDFPoint;
- TModelMatrix = Array [TDirection.D_LEFT..TDirection.D_RIGHT, A_STAND..A_LAST] of TAnimationState;
-
TModelTextures = Array [TDirection.D_LEFT..TDirection.D_RIGHT, A_STAND..A_LAST] of record
Resource: String;
Mask: String;
Back: Boolean;
end;
+{$IFDEF ENABLE_GFX}
TModelBlood = record
R, G, B, Kind: Byte;
end;
-
- TModelInfo = record
- Name: String;
- Author: String;
- Description: String;
- HaveWeapon: Boolean;
- 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;
TPlayerModel = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF}
private
FDirection: TDirection;
FColor: TRGB;
FCurrentAnimation: Byte;
- FAnimState: TAnimationState;
+ FAnimState: TAnimState;
FCurrentWeapon: Byte;
FFlag: Byte;
- FFire: Boolean;
FFireCounter: Byte;
FID: Integer;
procedure SetColor(Red, Green, Blue: Byte);
procedure SetWeapon(Weapon: Byte);
procedure SetFlag(Flag: Byte);
- procedure SetFire(Fire: Boolean);
+ procedure SetFire (Fire: Boolean);
+ function GetFire (): Boolean;
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
- property Fire: Boolean read FFire;
property Direction: TDirection read FDirection write FDirection;
property Animation: Byte read FCurrentAnimation;
property Weapon: Byte read FCurrentWeapon;
public
property Color: TRGB read FColor write FColor;
- property AnimState: TAnimationState read FAnimState;
+ property AnimState: TAnimState read FAnimState;
property CurrentAnimation: Byte read FCurrentAnimation;
property CurrentWeapon: Byte read FCurrentWeapon;
property Flag: Byte read FFlag;
procedure g_PlayerModel_FreeData();
function g_PlayerModel_Load(FileName: String): Boolean;
function g_PlayerModel_GetNames(): SSArray;
-function g_PlayerModel_GetInfo(ModelName: String): TModelInfo;
-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_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
TPlayerModelInfo = record
- Info: TModelInfo;
+ Name: String;
+ Author: String;
+ Description: String;
+ HaveWeapon: Boolean;
ModelSpeed: Array [A_STAND..A_PAIN] of Byte;
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;
- GibsCount: Integer;
- GibsResource:String;
- GibsMask: String;
- GibsOnce: Integer;
+ {$IFDEF ENABLE_GIBS}
+ GibsCount: Integer;
+ GibsResource:String;
+ GibsMask: String;
+ GibsOnce: Integer;
+ {$ENDIF}
end;
var
@@ -180,9 +176,13 @@ function g_PlayerModel_GetGibs(ModelName: String; var Gibs: TGibsArray): Boolea
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);
WeapNames: Array [WP_FIRST + 1..WP_LAST] of String =
('csaw', 'hgun', 'sg', 'ssg', 'mgun', 'rkt', 'plz', 'bfg', 'spl', 'flm');
+ function g_PlayerModel_GetIndex (ModelName: String): Integer;
+ var i: Integer;
+ begin
+ Result := -1;
+ if PlayerModelsArray <> nil then
+ begin
+ i := 0;
+ while (i < Length(PlayerModelsArray)) and (PlayerModelsArray[i].Name <> ModelName) do
+ Inc(i);
+ if i < Length(PlayerModelsArray) then
+ Result := i
+ end
+ end;
+
function GetPoint(var str: String; var point: TDFPoint): Boolean;
var
a, x, y: Integer;
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;
- 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;
prefix := FileName+':TEXTURES\';
- with PlayerModelsArray[ID].Info do
- begin
- Name := s;
- Author := config.ReadStr('Model', 'author', '');
- Description := config.ReadStr('Model', 'description', '');
- end;
-
+ PlayerModelsArray[ID].Name := s;
+ 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
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);
-
- 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;
+ {$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
end;
{if ok then g_Console_Add(Info.Name+' weapon points ok')
else g_Console_Add(Info.Name+' weapon points fail');}
- Info.HaveWeapon := ok;
+ PlayerModelsArray[ID].HaveWeapon := ok;
s := config.ReadStr('Model', 'flag_point', '');
if not GetPoint(s, FlagPoint) then
Result := True;
end;
-function g_PlayerModel_Get(ModelName: String): TPlayerModel;
+function g_PlayerModel_Get (ModelName: String): TPlayerModel;
var a: Integer;
begin
Result := nil;
for a := 0 to High(PlayerModelsArray) do
begin
- if AnsiLowerCase(PlayerModelsArray[a].Info.Name) = AnsiLowerCase(ModelName) then
+ if AnsiLowerCase(PlayerModelsArray[a].Name) = AnsiLowerCase(ModelName) then
begin
Result := TPlayerModel.Create;
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].Info.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, Info.Name+'_RIGHTANIM'+IntToStr(AnimTyp)) then
- if not g_Frames_Get(ID, Info.Name+'_LEFTANIM'+IntToStr(AnimTyp)) then Exit;
-
- _Anim := TAnimation.Create(ID, c, ModelSpeed[AnimTyp]);
- _Anim.Speed := ModelSpeed[AnimTyp];
-
- if not g_Frames_Get(ID, Info.Name+'_RIGHTANIM'+IntToStr(AnimTyp)+'_MASK') then
- if not g_Frames_Get(ID, Info.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(ModelName: string; var Gibs: TGibsArray): Boolean;
-var
- a, i, b: Integer;
- c: Boolean;
-begin
- Result := False;
-
- 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].Info.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;
- end;
-end;
-
function g_PlayerModel_GetNames(): SSArray;
var
i: DWORD;
for i := 0 to High(PlayerModelsArray) do
begin
SetLength(Result, Length(Result)+1);
- Result[High(Result)] := PlayerModelsArray[i].Info.Name;
+ Result[High(Result)] := PlayerModelsArray[i].Name;
end;
end;
-function g_PlayerModel_GetInfo(ModelName: string): TModelInfo;
-var
- a: Integer;
-begin
- FillChar(Result, SizeOf(Result), 0);
- if PlayerModelsArray = nil then Exit;
-
- for a := 0 to High(PlayerModelsArray) do
- if PlayerModelsArray[a].Info.Name = ModelName then
- begin
- Result := PlayerModelsArray[a].Info;
- Break;
- end;
-end;
-
+{$IFDEF ENABLE_GFX}
function g_PlayerModel_GetBlood(ModelName: string): TModelBlood;
var
a: Integer;
if PlayerModelsArray = nil then Exit;
for a := 0 to High(PlayerModelsArray) do
- if PlayerModelsArray[a].Info.Name = ModelName then
+ if PlayerModelsArray[a].Name = ModelName then
begin
Result := PlayerModelsArray[a].Blood;
Break;
end;
end;
+{$ENDIF}
procedure g_PlayerModel_FreeData();
var i, b: Integer;
{ TPlayerModel }
procedure TPlayerModel.ChangeAnimation (Animation: Byte; Force: Boolean = False);
- var once: Boolean; speed, count: Integer;
+ var loop: Boolean; speed, count: Integer;
begin
if not Force then
if FCurrentAnimation = Animation then
Exit;
FCurrentAnimation := Animation;
- once := FCurrentAnimation in [A_STAND, A_WALK];
+ loop := FCurrentAnimation in [A_STAND, A_WALK];
speed := PlayerModelsArray[FID].ModelSpeed[FCurrentAnimation];
count := PlayerModelsArray[FID].Anim[FDirection, FCurrentAnimation].Frames;
- FAnimState := TAnimationState.Create(once, speed, count);
+ FAnimState := TAnimState.Create(loop, speed, count);
end;
destructor TPlayerModel.Destroy();
begin
- FAnimState.Free;
+ FAnimState.Invalidate;
inherited;
end;
FColor.B := Blue;
end;
-procedure TPlayerModel.SetFire(Fire: Boolean);
-begin
- FFire := Fire;
- if FFire then
- FFireCounter := PlayerModelsArray[FID].ModelSpeed[A_ATTACK] * PlayerModelsArray[FID].Anim[TDirection.D_RIGHT, A_ATTACK].Frames
- else
- FFireCounter := 0
-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 + 1
+ else
+ FFireCounter := 0
+ end;
+
+ function TPlayerModel.GetFire (): Boolean;
+ begin
+ Result := FFireCounter > 0
+ end;
procedure TPlayerModel.SetFlag (Flag: Byte);
begin
FCurrentWeapon := Weapon
end;
+{$IFDEF ENABLE_GFX}
function TPlayerModel.GetBlood (): TModelBlood;
begin
Result := PlayerModelsArray[FID].Blood
end;
+{$ENDIF}
function TPlayerModel.GetName (): String;
begin
- Result := PlayerModelsArray[FID].Info.Name
+ Result := PlayerModelsArray[FID].Name
end;
procedure TPlayerModel.Update;
begin
- if FAnimState <> nil then
+ if FAnimState.IsValid() then
FAnimState.Update;
if FFireCounter > 0 then
Dec(FFireCounter)
- else
- FFire := False
end;
procedure g_PlayerModel_LoadAll;