From bb484af1855ae19d0fed042828f780889d8e1eec Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Mon, 17 Jan 2022 00:01:34 +0300 Subject: [PATCH] render: remove TAnimation --- src/game/g_textures.pas | 218 ------------------------------- src/game/opengl/r_animations.pas | 17 +-- 2 files changed, 1 insertion(+), 234 deletions(-) diff --git a/src/game/g_textures.pas b/src/game/g_textures.pas index 727e94a..ae951fc 100644 --- a/src/game/g_textures.pas +++ b/src/game/g_textures.pas @@ -76,65 +76,12 @@ type 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); @@ -297,169 +244,4 @@ begin 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. diff --git a/src/game/opengl/r_animations.pas b/src/game/opengl/r_animations.pas index 156869b..74c2ebb 100644 --- a/src/game/opengl/r_animations.pas +++ b/src/game/opengl/r_animations.pas @@ -17,10 +17,7 @@ unit r_animations; 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); @@ -59,18 +56,6 @@ implementation 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 -- 2.29.2