summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b01cc2e)
raw | patch | inline | side by side (parent: b01cc2e)
author | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Sun, 16 Jan 2022 21:01:34 +0000 (00:01 +0300) | ||
committer | DeaDDooMER <deaddoomer@deadsoftware.ru> | |
Fri, 9 Jun 2023 07:53:02 +0000 (10:53 +0300) |
src/game/g_textures.pas | patch | blob | history | |
src/game/opengl/r_animations.pas | patch | blob | history |
index 727e94ac7632e0b1e5b6e88e6f6a13f8876bfeb1..ae951fc94258fd3f930fa18e2355a4c7a08155fd 100644 (file)
--- a/src/game/g_textures.pas
+++ b/src/game/g_textures.pas
property length: Integer read mLength;
end;
- TAnimation = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF}
- private
- mId: LongWord;
- mAlpha: Byte;
- mBlending: Boolean;
- mCounter: Byte; // Ñ÷åò÷èê îæèäàíèÿ ìåæäó êàäðàìè
- mSpeed: Byte; // Âðåìÿ îæèäàíèÿ ìåæäó êàäðàìè
- mCurrentFrame: Integer; // Òåêóùèé êàäð (íà÷èíàÿ ñ 0)
- mLoop: Boolean; // Ïåðåõîäèòü íà ïåðâûé êàäð ïîñëå ïîñëåäíåãî?
- mEnabled: Boolean; // Ðàáîòà ðàçðåøåíà?
- mPlayed: Boolean; // Ïðîèãðàíà âñÿ õîòÿ áû ðàç?
- mHeight: Word;
- mWidth: Word;
- mMinLength: Byte; // Îæèäàíèå ïîñëå ïðîèãðûâàíèÿ
- mRevert: Boolean; // Ñìåíà êàäðîâ îáðàòíàÿ?
-
- public
- constructor Create (aframesID: LongWord; aloop: Boolean; aspeed: Byte);
- destructor Destroy (); override;
-
- procedure reset ();
- procedure update ();
- procedure enable ();
- procedure disable ();
- procedure revert (r: Boolean);
-
- procedure saveState (st: TStream);
- procedure loadState (st: TStream);
-
- 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 blending: Boolean read mBlending write mBlending;
- property alpha: Byte read mAlpha write mAlpha;
- property framesId: LongWord read mId;
- property width: Word read mWidth;
- property height: Word read mHeight;
-
- property id: LongWord read mId;
- end;
-
implementation
uses
g_game, e_log, g_basic, g_console, wadreader, r_animations,
g_language, utils, xstreams;
-
-
-
constructor TAnimationState.Create (aloop: Boolean; aspeed: Byte; len: Integer);
begin
assert(len >= 0);
mRevert := utils.readBool(st);
end;
-
-
-
-
-
-constructor TAnimation.Create (aframesID: LongWord; aloop: Boolean; aspeed: Byte);
-begin
- if (aframesID >= Length(framesArray)) then
- begin
- //raise Exception.Create('trying to create inexisting frame: something is very wrong here');
- e_LogWritefln('trying to create inexisting frame %u of %u: something is very wrong here', [aframesID, LongWord(Length(framesArray))], TMsgType.Warning);
- aframesID := 0;
- if (Length(framesArray) = 0) then raise Exception.Create('trying to create inexisting frame: something is very wrong here');
- end;
- mId := aframesID;
- mMinLength := 0;
- mLoop := aloop;
- mSpeed := aspeed;
- mEnabled := true;
- mCurrentFrame := 0;
- mPlayed := false;
- mAlpha := 0;
- mWidth := framesArray[mId].FrameWidth;
- mHeight := framesArray[mId].FrameHeight;
-end;
-
-
-destructor TAnimation.Destroy ();
-begin
- inherited;
-end;
-
-
-procedure TAnimation.update ();
-begin
- if (not mEnabled) then exit;
-
- mCounter += 1;
-
- if (mCounter >= mSpeed) then
- begin
- // Îæèäàíèå ìåæäó êàäðàìè çàêîí÷èëîñü
- // Îáðàòíûé ïîðÿäîê êàäðîâ?
- if mRevert then
- begin
- // Äîøëè äî êîíöà àíèìàöèè. Âîçìîæíî, æäåì åùå
- if (mCurrentFrame = 0) then
- begin
- if (Length(framesArray[mId].TexturesID)*mSpeed+mCounter < mMinLength) then exit;
- end;
-
- mCurrentFrame -= 1;
- mPlayed := (mCurrentFrame < 0);
-
- // Ïîâòîðÿòü ëè àíèìàöèþ ïî êðóãó?
- if mPlayed then
- begin
- if mLoop then mCurrentFrame := High(framesArray[mId].TexturesID) else mCurrentFrame += 1;
- end;
-
- mCounter := 0;
- end
- else
- begin
- // Ïðÿìîé ïîðÿäîê êàäðîâ
- // Äîøëè äî êîíöà àíèìàöèè. Âîçìîæíî, æäåì åùå
- if (mCurrentFrame = High(framesArray[mId].TexturesID)) then
- begin
- if (Length(framesArray[mId].TexturesID)*mSpeed+mCounter < mMinLength) then exit;
- end;
-
- mCurrentFrame += 1;
- mPlayed := (mCurrentFrame > High(framesArray[mId].TexturesID));
-
- // Ïîâòîðÿòü ëè àíèìàöèþ ïî êðóãó?
- if mPlayed then
- begin
- if mLoop then mCurrentFrame := 0 else mCurrentFrame -= 1;
- end;
-
- mCounter := 0;
- end;
- end;
-end;
-
-
-procedure TAnimation.reset ();
-begin
- if mRevert then mCurrentFrame := High(framesArray[mId].TexturesID) else mCurrentFrame := 0;
- mCounter := 0;
- mPlayed := false;
-end;
-
-
-procedure TAnimation.disable (); begin mEnabled := false; end;
-procedure TAnimation.enable (); begin mEnabled := true; end;
-
-
-function TAnimation.totalFrames (): Integer; inline; begin result := Length(framesArray[mId].TexturesID); end;
-
-
-procedure TAnimation.revert (r: Boolean);
-begin
- mRevert := r;
- reset();
-end;
-
-
-procedure TAnimation.saveState (st: TStream);
-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 TAnimation.loadState (st: TStream);
-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;
-
end.
index 156869b82640047a1f888265e1c36887b932736a..74c2ebbdcddc236df3d1a84048675cea617adba9 100644 (file)
interface
- uses g_base, g_textures, MAPDEF, Imaging; // TMirrorType, TAnimation, TDFPoint, TDynImageDataArray
-
- procedure r_Animation_Draw (t: TAnimation; x, y: Integer; mirror: TMirrorType);
- procedure r_Animation_DrawEx (t: TAnimation; x, y: Integer; mirror: TMirrorType; rpoint: TDFPoint; angle: SmallInt);
+ uses g_base, g_textures, MAPDEF, Imaging; // TMirrorType, TAnimationState, TDFPoint, TDynImageDataArray
procedure r_AnimationState_Draw (TID: DWORD; t: TAnimationState; x, y: Integer; mirror: TMirrorType);
procedure r_AnimationState_DrawEx (FID: DWORD; t: TAnimationState; x, y: Integer; mirror: TMirrorType; rpoint: TDFPoint; angle: SmallInt);
g_language, g_game
;
- procedure r_Animation_Draw (t: TAnimation; x, y: Integer; mirror: TMirrorType);
- begin
- if t.enabled then
- e_DrawAdv(framesArray[t.id].TexturesID[t.currentFrame], x, y, t.alpha, true, t.blending, 0, nil, mirror)
- end;
-
- procedure r_Animation_DrawEx (t: TAnimation; x, y: Integer; mirror: TMirrorType; rpoint: TDFPoint; angle: SmallInt);
- begin
- if t.enabled then
- e_DrawAdv(framesArray[t.id].TexturesID[t.currentFrame], x, y, t.alpha, true, t.blending, angle, @rpoint, mirror)
- end;
-
procedure r_AnimationState_Draw (TID: DWORD; t: TAnimationState; x, y: Integer; mirror: TMirrorType);
begin
if t.enabled then