summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: afc0101)
raw | patch | inline | side by side (parent: afc0101)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Wed, 13 Apr 2022 18:42:19 +0000 (21:42 +0300) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Fri, 9 Jun 2023 08:27:21 +0000 (11:27 +0300) |
src/game/g_textures.pas | patch | blob | history | |
src/game/opengl/r_animations.pas | patch | blob | history |
index 16b0655a01dbcd0f81117770a592c9104fa1d027..8a215c0e157c2e5ca995b23b81a3ab5c4cb9a05c 100644 (file)
--- a/src/game/g_textures.pas
+++ b/src/game/g_textures.pas
TLevelTextureArray = array of TLevelTexture;
- TAnimationState = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF}
- private
- mCounter: Byte; // Ñ÷åò÷èê îæèäàíèÿ ìåæäó êàäðàìè
- mSpeed: Byte; // Âðåìÿ îæèäàíèÿ ìåæäó êàäðàìè
- mCurrentFrame: Integer; // Òåêóùèé êàäð (íà÷èíàÿ ñ 0)
- mLoop: Boolean; // Ïåðåõîäèòü íà ïåðâûé êàäð ïîñëå ïîñëåäíåãî?
- mEnabled: Boolean; // Ðàáîòà ðàçðåøåíà?
- mPlayed: Boolean; // Ïðîèãðàíà âñÿ õîòÿ áû ðàç?
- mMinLength: Byte; // Îæèäàíèå ïîñëå ïðîèãðûâàíèÿ
- mRevert: Boolean; // Ñìåíà êàäðîâ îáðàòíàÿ?
-
- mLength: Integer;
-
- public
- constructor Create (aloop: Boolean; aspeed: Byte; len: Integer);
- destructor Destroy (); override;
-
- procedure reset ();
- procedure update ();
- procedure enable ();
- procedure disable ();
- procedure revert (r: Boolean);
-
- procedure saveState (st: TStream; mAlpha: Byte; mBlending: Boolean);
- procedure loadState (st: TStream; out mAlpha: Byte; out mBlending: Boolean);
-
- function totalFrames (): Integer; inline;
-
- public
- property played: Boolean read mPlayed;
- property enabled: Boolean read mEnabled;
- property isReverse: Boolean read mRevert;
- property loop: Boolean read mLoop write mLoop;
- property speed: Byte read mSpeed write mSpeed;
- property minLength: Byte read mMinLength write mMinLength;
- property currentFrame: Integer read mCurrentFrame write mCurrentFrame;
- property currentCounter: Byte read mCounter write mCounter;
- property counter: Byte read mCounter;
- property length: Integer read mLength;
- end;
-
TAnimState = record
private
mCounter: Byte; // Ñ÷åò÷èê îæèäàíèÿ ìåæäó êàäðàìè
g_game, e_log, g_basic, g_console, wadreader,
g_language, utils, xstreams;
-constructor TAnimationState.Create (aloop: Boolean; aspeed: Byte; len: Integer);
-begin
- assert(len >= 0);
- mLength := len;
-
- mMinLength := 0;
- mLoop := aloop;
- mSpeed := aspeed;
- mEnabled := true;
- mCurrentFrame := 0;
- mPlayed := false;
-end;
-
-destructor TAnimationState.Destroy;
-begin
- inherited;
-end;
-
-procedure TAnimationState.update;
-begin
- if (not mEnabled) then exit;
-
- mCounter += 1;
-
- if (mCounter >= mSpeed) then
- begin
- // Îæèäàíèå ìåæäó êàäðàìè çàêîí÷èëîñü
- // Îáðàòíûé ïîðÿäîê êàäðîâ?
- if mRevert then
- begin
- // Äîøëè äî êîíöà àíèìàöèè. Âîçìîæíî, æäåì åùå
- if (mCurrentFrame = 0) then
- begin
- if (mLength * mSpeed + mCounter < mMinLength) then exit;
- end;
-
- mCurrentFrame -= 1;
- mPlayed := (mCurrentFrame < 0);
-
- // Ïîâòîðÿòü ëè àíèìàöèþ ïî êðóãó?
- if mPlayed then
- begin
- if mLoop then
- mCurrentFrame := mLength - 1
- else
- mCurrentFrame += 1
- end;
-
- mCounter := 0;
- end
- else
- begin
- // Ïðÿìîé ïîðÿäîê êàäðîâ
- // Äîøëè äî êîíöà àíèìàöèè. Âîçìîæíî, æäåì åùå
- if (mCurrentFrame = mLength - 1) then
- begin
- if (mLength * mSpeed + mCounter < mMinLength) then exit;
- end;
-
- mCurrentFrame += 1;
- mPlayed := (mCurrentFrame > mLength - 1);
-
- // Ïîâòîðÿòü ëè àíèìàöèþ ïî êðóãó?
- if mPlayed then
- begin
- if mLoop then mCurrentFrame := 0 else mCurrentFrame -= 1;
- end;
-
- mCounter := 0;
- end;
- end;
-end;
-
-procedure TAnimationState.reset;
-begin
- if mRevert then
- mCurrentFrame := mLength - 1
- else
- mCurrentFrame := 0;
- mCounter := 0;
- mPlayed := false
-end;
-
-procedure TAnimationState.disable;
-begin
- mEnabled := false
-end;
-
-procedure TAnimationState.enable;
-begin
- mEnabled := true
-end;
-
-procedure TAnimationState.revert (r: Boolean);
-begin
- mRevert := r;
- reset
-end;
-
-function TAnimationState.totalFrames (): Integer; inline;
-begin
- result := mLength
-end;
-
-procedure TAnimationState.saveState (st: TStream; mAlpha: Byte; mBlending: Boolean);
-begin
- if (st = nil) then exit;
-
- utils.writeSign(st, 'ANIM');
- utils.writeInt(st, Byte(0)); // version
- // Ñ÷åò÷èê îæèäàíèÿ ìåæäó êàäðàìè
- utils.writeInt(st, Byte(mCounter));
- // Òåêóùèé êàäð
- utils.writeInt(st, LongInt(mCurrentFrame));
- // Ïðîèãðàíà ëè àíèìàöèÿ öåëèêîì
- utils.writeBool(st, mPlayed);
- // Alpha-êàíàë âñåé òåêñòóðû
- utils.writeInt(st, Byte(mAlpha));
- // Ðàçìûòèå òåêñòóðû
- utils.writeInt(st, Byte(mBlending));
- // Âðåìÿ îæèäàíèÿ ìåæäó êàäðàìè
- utils.writeInt(st, Byte(mSpeed));
- // Çàöèêëåíà ëè àíèìàöèÿ
- utils.writeBool(st, mLoop);
- // Âêëþ÷åíà ëè
- utils.writeBool(st, mEnabled);
- // Îæèäàíèå ïîñëå ïðîèãðûâàíèÿ
- utils.writeInt(st, Byte(mMinLength));
- // Îáðàòíûé ëè ïîðÿäîê êàäðîâ
- utils.writeBool(st, mRevert);
-end;
-
-
-procedure TAnimationState.loadState (st: TStream; out mAlpha: Byte; out mBlending: Boolean);
-begin
- if (st = nil) then exit;
-
- if not utils.checkSign(st, 'ANIM') then raise XStreamError.Create('animation chunk expected');
- if (utils.readByte(st) <> 0) then raise XStreamError.Create('invalid animation chunk version');
- // Ñ÷åò÷èê îæèäàíèÿ ìåæäó êàäðàìè
- mCounter := utils.readByte(st);
- // Òåêóùèé êàäð
- mCurrentFrame := utils.readLongInt(st);
- // Ïðîèãðàíà ëè àíèìàöèÿ öåëèêîì
- mPlayed := utils.readBool(st);
- // Alpha-êàíàë âñåé òåêñòóðû
- mAlpha := utils.readByte(st);
- // Ðàçìûòèå òåêñòóðû
- mBlending := utils.readBool(st);
- // Âðåìÿ îæèäàíèÿ ìåæäó êàäðàìè
- mSpeed := utils.readByte(st);
- // Çàöèêëåíà ëè àíèìàöèÿ
- mLoop := utils.readBool(st);
- // Âêëþ÷åíà ëè
- mEnabled := utils.readBool(st);
- // Îæèäàíèå ïîñëå ïðîèãðûâàíèÿ
- mMinLength := utils.readByte(st);
- // Îáðàòíûé ëè ïîðÿäîê êàäðîâ
- mRevert := utils.readBool(st);
-end;
-
-
-(* ------------- *)
-
constructor TAnimState.Create (aloop: Boolean; aspeed: Byte; len: Integer);
begin
Self := Default(TAnimState);
index 6e02aec1ed0c9c95aed1c832ec194b6261ca3b69..26d15c7a087cd1d259e439e237ae4af28ed6f27d 100644 (file)
uses g_base, g_textures, MAPDEF, Imaging; // TMirrorType, TAnimationState, TDFPoint, TDynImageDataArray
- procedure r_AnimationState_Draw (FID: DWORD; t: TAnimationState; x, y: Integer; alpha: Byte; mirror: TMirrorType; blending: Boolean);
- procedure r_AnimationState_DrawEx (FID: DWORD; t: TAnimationState; x, y: Integer; alpha: Byte; mirror: TMirrorType; blending: Boolean; rpoint: TDFPoint; angle: SmallInt);
-
procedure r_AnimState_Draw (FID: DWORD; const t: TAnimState; x, y: Integer; alpha: Byte; mirror: TMirrorType; blending: Boolean);
procedure r_AnimState_DrawEx (FID: DWORD; const t: TAnimState; x, y: Integer; alpha: Byte; mirror: TMirrorType; blending: Boolean; rpoint: TDFPoint; angle: SmallInt);
end
end;
- procedure r_AnimationState_Draw (FID: DWORD; t: TAnimationState; x, y: Integer; alpha: Byte; mirror: TMirrorType; blending: Boolean);
- begin
- if t.enabled then
- e_DrawAdv(framesArray[FID].TexturesID[t.currentFrame], x, y, alpha, true, blending, 0, nil, mirror)
- end;
-
- procedure r_AnimationState_DrawEx (FID: DWORD; t: TAnimationState; x, y: Integer; alpha: Byte; mirror: TMirrorType; blending: Boolean; rpoint: TDFPoint; angle: SmallInt);
- begin
- if t.enabled then
- e_DrawAdv(framesArray[FID].TexturesID[t.currentFrame], x, y, alpha, true, blending, angle, @rpoint, mirror)
- end;
-
procedure r_AnimState_Draw (FID: DWORD; const t: TAnimState; x, y: Integer; alpha: Byte; mirror: TMirrorType; blending: Boolean);
begin
if t.enabled then