From: DeaDDooMER Date: Thu, 30 Jun 2022 11:03:13 +0000 (+0300) Subject: gl: remove bacanim flag from multitexture structure X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=90cf86c8e9339852b3c1831c446e242dea4d1074;p=d2df-sdl.git gl: remove bacanim flag from multitexture structure --- diff --git a/src/game/g_animations.pas b/src/game/g_animations.pas index 1e9078e..9c6dd4c 100644 --- a/src/game/g_animations.pas +++ b/src/game/g_animations.pas @@ -70,12 +70,15 @@ interface back: Boolean; (* back animation normalization *) end; + function g_Anim_GetTotalFrames (const a: TAnimInfo): LongWord; function g_Anim_GetTotalTime (const a: TAnimInfo): LongWord; function g_Anim_GetCountByTime (const a: TAnimInfo; time: LongWord): LongInt; procedure g_Anim_GetFrameByTime (const a: TAnimInfo; time: LongWord; out count, frame: LongInt); procedure g_Anim_GetState (const anim: TAnimInfo; time: LongWord; out state: TAnimState); + procedure g_Anim_GetFrameFromState (const s: TAnimState; backanim: Boolean; out frame: LongInt); + implementation uses Math, utils, xstreams; @@ -287,4 +290,17 @@ implementation state.mPlayed := count >= 1; end; + procedure g_Anim_GetFrameFromState (const s: TAnimState; backanim: Boolean; out frame: LongInt); + var total: LongInt; + begin + ASSERT(s.length > 0); + frame := s.CurrentFrame mod s.length; + if backanim then + begin + total := (s.length + 1) div 2; + if frame >= total then + frame := s.length - frame - 1; + end; + end; + end. diff --git a/src/game/renders/opengl/r_draw.pas b/src/game/renders/opengl/r_draw.pas index fbdae7e..b8b9021 100644 --- a/src/game/renders/opengl/r_draw.pas +++ b/src/game/renders/opengl/r_draw.pas @@ -26,8 +26,8 @@ interface procedure r_Draw_TextureRepeat (img: TGLTexture; x, y, w, h: Integer; flip: Boolean; r, g, b, a: Byte; blend: Boolean); procedure r_Draw_TextureRepeatRotate (img: TGLTexture; x, y, w, h: Integer; flip: Boolean; r, g, b, a: Byte; blend: Boolean; rx, ry, angle: Integer); - procedure r_Draw_MultiTextureRepeat (m: TGLMultiTexture; const anim: TAnimState; x, y, w, h: Integer; flip: Boolean; r, g, b, a: Byte; blend: Boolean); - procedure r_Draw_MultiTextureRepeatRotate (m: TGLMultiTexture; const anim: TAnimState; x, y, w, h: Integer; flip: Boolean; r, g, b, a: Byte; blend: Boolean; rx, ry, angle: Integer); + procedure r_Draw_MultiTextureRepeat (m: TGLMultiTexture; const anim: TAnimState; backanim: Boolean; x, y, w, h: Integer; flip: Boolean; r, g, b, a: Byte; blend: Boolean); + procedure r_Draw_MultiTextureRepeatRotate (m: TGLMultiTexture; const anim: TAnimState; backanim: Boolean; x, y, w, h: Integer; flip: Boolean; r, g, b, a: Byte; blend: Boolean; rx, ry, angle: Integer); procedure r_Draw_Filter (l, t, r, b: Integer; rr, gg, bb, aa: Byte); procedure r_Draw_FillRect (l, t, r, b: Integer; rr, gg, bb, aa: Byte); @@ -172,28 +172,23 @@ implementation r_Draw_TextureRepeat(img, x, y, w, h, flip, r, g, b, a, blend); end; - procedure r_Draw_MultiTextureRepeat (m: TGLMultiTexture; const anim: TAnimState; x, y, w, h: Integer; flip: Boolean; r, g, b, a: Byte; blend: Boolean); - var img: TGLTexture; cur, total, i: Integer; + procedure r_Draw_MultiTextureRepeat (m: TGLMultiTexture; const anim: TAnimState; backanim: Boolean; x, y, w, h: Integer; flip: Boolean; r, g, b, a: Byte; blend: Boolean); + var img: TGLTexture; frame: LongInt; begin ASSERT(anim.IsValid()); if m = nil then r_Draw_TextureRepeat(nil, x, y, w, h, flip, NTR, NTG, NTB, NTB, blend) else begin - if m.BackAnim then - begin - total := m.count * 2 - 1; - cur := anim.CurrentFrame mod total; - if cur < m.count then i := cur else i := total - cur - 1; - end - else - i := anim.CurrentFrame mod m.count; - img := m.GetTexture(i); + g_Anim_GetFrameFromState(anim, backanim, frame); + ASSERT(frame >= 0); + ASSERT(frame < m.count); + img := m.GetTexture(frame); r_Draw_TextureRepeat(img, x, y, w, h, flip, r, g, b, a, blend); end end; - procedure r_Draw_MultiTextureRepeatRotate (m: TGLMultiTexture; const anim: TAnimState; x, y, w, h: Integer; flip: Boolean; r, g, b, a: Byte; blend: Boolean; rx, ry, angle: Integer); + procedure r_Draw_MultiTextureRepeatRotate (m: TGLMultiTexture; const anim: TAnimState; backanim: Boolean; x, y, w, h: Integer; flip: Boolean; r, g, b, a: Byte; blend: Boolean; rx, ry, angle: Integer); begin ASSERT(w >= 0); ASSERT(h >= 0); @@ -203,11 +198,11 @@ implementation glTranslatef(x + rx, y + ry, 0); glRotatef(angle, 0, 0, 1); glTranslatef(-(x + rx), -(y + ry), 0); - r_Draw_MultiTextureRepeat(m, anim, x, y, w, h, flip, r, g, b, a, blend); + r_Draw_MultiTextureRepeat(m, anim, backanim, x, y, w, h, flip, r, g, b, a, blend); glPopMatrix; end else - r_Draw_MultiTextureRepeat(m, anim, x, y, w, h, flip, r, g, b, a, blend); + r_Draw_MultiTextureRepeat(m, anim, backanim, x, y, w, h, flip, r, g, b, a, blend); end; procedure r_Draw_Filter (l, t, r, b: Integer; rr, gg, bb, aa: Byte); diff --git a/src/game/renders/opengl/r_map.pas b/src/game/renders/opengl/r_map.pas index 786bd54..8737969 100644 --- a/src/game/renders/opengl/r_map.pas +++ b/src/game/renders/opengl/r_map.pas @@ -343,9 +343,9 @@ implementation Models[i].anim[d, a].base := nil; Models[i].anim[d, a].mask := nil; if m.anim[d, a].resource <> '' then - Models[i].anim[d, a].base := r_Textures_LoadMultiFromFileAndInfo(prefix + m.anim[d, a].resource, 64, 64, m.anim[d, a].frames, m.anim[d, a].back, true); + Models[i].anim[d, a].base := r_Textures_LoadMultiFromFileAndInfo(prefix + m.anim[d, a].resource, 64, 64, m.anim[d, a].frames, true); if m.anim[d, a].mask <> '' then - Models[i].anim[d, a].mask := r_Textures_LoadMultiFromFileAndInfo(prefix + m.anim[d, a].mask, 64, 64, m.anim[d, a].frames, m.anim[d, a].back, true); + Models[i].anim[d, a].mask := r_Textures_LoadMultiFromFileAndInfo(prefix + m.anim[d, a].mask, 64, 64, m.anim[d, a].frames, true); end end; {$IFDEF ENABLE_GIBS} @@ -390,7 +390,6 @@ implementation w, h, count, - False, False ); end @@ -415,7 +414,6 @@ implementation ItemAnim[i].w, ItemAnim[i].h, ItemAnim[i].anim.frames, - ItemAnim[i].anim.back, false ); Items[i].frame := 0; @@ -425,7 +423,7 @@ implementation for j := 0 to ANIM_LAST do for d := TDirection.D_LEFT to TDirection.D_RIGHT do r_Map_LoadMonsterAnim(i, j, d); - VileFire := r_Textures_LoadMultiFromFileAndInfo(GameWAD + ':TEXTURES/FIRE', 64, 128, VileFireAnim.frames, VileFireAnim.back); + VileFire := r_Textures_LoadMultiFromFileAndInfo(GameWAD + ':TEXTURES/FIRE', 64, 128, VileFireAnim.frames); // --------- player models --------- // if PlayerModelsArray <> nil then begin @@ -442,17 +440,17 @@ implementation {$IFDEF ENABLE_GFX} for i := 1 to R_GFX_LAST do if GFXAnim[i].anim.frames > 0 then - GFXTextures[i] := r_Textures_LoadMultiFromFileAndInfo(GameWad + ':TEXTURES/' + GFXAnim[i].name, GFXAnim[i].w, GFXAnim[i].h, GFXAnim[i].anim.frames, GFXAnim[i].anim.back); + GFXTextures[i] := r_Textures_LoadMultiFromFileAndInfo(GameWad + ':TEXTURES/' + GFXAnim[i].name, GFXAnim[i].w, GFXAnim[i].h, GFXAnim[i].anim.frames); {$ENDIF} // --------- shots --------- // for i := 0 to WEAPON_LAST do if ShotAnim[i].anim.frames > 0 then - ShotTextures[i] := r_Textures_LoadMultiFromFileAndInfo(GameWad + ':TEXTURES/' + ShotAnim[i].name, ShotAnim[i].w, ShotAnim[i].h, ShotAnim[i].anim.frames, ShotAnim[i].anim.back); + ShotTextures[i] := r_Textures_LoadMultiFromFileAndInfo(GameWad + ':TEXTURES/' + ShotAnim[i].name, ShotAnim[i].w, ShotAnim[i].h, ShotAnim[i].anim.frames); // --------- flags --------- // FlagTextures[FLAG_NONE] := nil; - FlagTextures[FLAG_RED] := r_Textures_LoadMultiFromFileAndInfo(GameWad + ':TEXTURES/FLAGRED', 64, 64, 5, false); - FlagTextures[FLAG_BLUE] := r_Textures_LoadMultiFromFileAndInfo(GameWad + ':TEXTURES/FLAGBLUE', 64, 64, 5, false); - // FlagTextures[FLAG_DOM] := r_Textures_LoadMultiFromFileAndInfo(GameWad + ':TEXTURES/FLAGDOM', 64, 64, 8, false); + FlagTextures[FLAG_RED] := r_Textures_LoadMultiFromFileAndInfo(GameWad + ':TEXTURES/FLAGRED', 64, 64, 5); + FlagTextures[FLAG_BLUE] := r_Textures_LoadMultiFromFileAndInfo(GameWad + ':TEXTURES/FLAGBLUE', 64, 64, 5); + // FlagTextures[FLAG_DOM] := r_Textures_LoadMultiFromFileAndInfo(GameWad + ':TEXTURES/FLAGDOM', 64, 64, 8); // --------- shells --------- // {$IFDEF ENABLE_SHELLS} for i := 0 to SHELL_LAST do @@ -462,7 +460,7 @@ implementation for b := false to true do begin for i := 0 to 2 do - PunchTextures[b, i] := r_Textures_LoadMultiFromFileAndInfo(GameWad + ':WEAPONS/' + PunchName[b] + WeapPos[i], 64, 64, PunchAnim.frames, PunchAnim.back); + PunchTextures[b, i] := r_Textures_LoadMultiFromFileAndInfo(GameWad + ':WEAPONS/' + PunchName[b] + WeapPos[i], 64, 64, PunchAnim.frames); end; // --------- other --------- // InvulPenta := r_Textures_LoadFromFile(GameWad + ':TEXTURES/PENTA'); @@ -725,7 +723,7 @@ implementation mon.obj.Lerp(gLerpFactor, fX, fY); if r_Map_GetMonsterTexture(m, a, d, t, dx, dy, flip) then - r_Draw_MultiTextureRepeat(t, mon.DirAnim[a, d], fX + dx, fY + dy, t.width, t.height, flip, 255, 255, 255, 255, false); + r_Draw_MultiTextureRepeat(t, mon.DirAnim[a, d], false, fX + dx, fY + dy, t.width, t.height, flip, 255, 255, 255, 255, false); // TODO draw g_debug_frames end; @@ -762,7 +760,7 @@ implementation end; procedure r_Map_DrawPlayerModel (pm: TPlayerModel; x, y: Integer; alpha: Byte); - var a, pos, act, xx, yy, angle: Integer; d: TDirection; flip: Boolean; t: TGLMultiTexture; tex: TGLTexture; c: TRGB; + var a, pos, act, xx, yy, angle: Integer; d: TDirection; flip, back: Boolean; t: TGLMultiTexture; tex: TGLTexture; c: TRGB; begin a := pm.CurrentAnimation; d := pm.Direction; @@ -823,12 +821,13 @@ implementation if r_Map_GetPlayerModelTex(pm.id, a, d, flip) then begin t := Models[pm.id].anim[d, a].base; - r_Draw_MultiTextureRepeat(t, pm.AnimState, x, y, t.width, t.height, flip, 255, 255, 255, alpha, false); + back := PlayerModelsArray[pm.id].anim[d, a].back; + r_Draw_MultiTextureRepeat(t, pm.AnimState, back, x, y, t.width, t.height, flip, 255, 255, 255, alpha, false); t := Models[pm.id].anim[d, a].mask; if t <> nil then begin c := pm.Color; - r_Draw_MultiTextureRepeat(t, pm.AnimState, x, y, t.width, t.height, flip, c.r, c.g, c.b, alpha, false); + r_Draw_MultiTextureRepeat(t, pm.AnimState, back, x, y, t.width, t.height, flip, c.r, c.g, c.b, alpha, false); end; end; end; diff --git a/src/game/renders/opengl/r_textures.pas b/src/game/renders/opengl/r_textures.pas index 062f76b..1f3f238 100644 --- a/src/game/renders/opengl/r_textures.pas +++ b/src/game/renders/opengl/r_textures.pas @@ -82,7 +82,6 @@ interface TGLMultiTexture = class private mTexture: array of TGLTexture; - mBackanim: Boolean; public destructor Destroy; override; @@ -95,7 +94,6 @@ interface property width: Integer read GetWidth; property height: Integer read GetHeight; property count: Integer read GetCount; - property backAnim: Boolean read mBackanim; (* this property must be located at TAnimState? *) end; TGLTextureArray = array of TGLTexture; @@ -127,7 +125,7 @@ interface function r_Textures_LoadFromFile (const filename: AnsiString; log: Boolean = True): TGLTexture; function r_Textures_LoadMultiFromFile (const filename: AnsiString; log: Boolean = True): TGLMultiTexture; - function r_Textures_LoadMultiFromFileAndInfo (const filename: AnsiString; w, h, count: Integer; backanim: Boolean; log: Boolean = True): TGLMultiTexture; + function r_Textures_LoadMultiFromFileAndInfo (const filename: AnsiString; w, h, count: Integer; log: Boolean = True): TGLMultiTexture; function r_Textures_LoadMultiTextFromFile (const filename: AnsiString; var txt: TAnimTextInfo; log: Boolean = True): TGLMultiTexture; function r_Textures_LoadStreamFromFile (const filename: AnsiString; w, h, count, cw: Integer; st: TGLTextureArray; rs: TRectArray; log: Boolean = True): Boolean; @@ -458,7 +456,7 @@ implementation end end; - function r_Textures_LoadMultiFromImageAndInfo (var img: TImageData; w, h, c: Integer; b: Boolean): TGLMultiTexture; + function r_Textures_LoadMultiFromImageAndInfo (var img: TImageData; w, h, c: Integer): TGLMultiTexture; var t: TImageData; a: array of TGLTexture; i: Integer; m: TGLMultiTexture; begin ASSERT(w >= 0); @@ -477,12 +475,11 @@ implementation end; m := TGLMultiTexture.Create(); m.mTexture := a; - m.mBackanim := b; ASSERT(m.mTexture <> nil); result := m; end; - function r_Textures_LoadMultiFromDataAndInfo (data: Pointer; size: LongInt; w, h, c: Integer; b: Boolean): TGLMultiTexture; + function r_Textures_LoadMultiFromDataAndInfo (data: Pointer; size: LongInt; w, h, c: Integer): TGLMultiTexture; var img: TImageData; begin ASSERT(w > 0); @@ -495,7 +492,7 @@ implementation try if LoadImageFromMemory(data, size, img) then if r_Textures_FixImageData(img) then - result := r_Textures_LoadMultiFromImageAndInfo(img, w, h, c, b) + result := r_Textures_LoadMultiFromImageAndInfo(img, w, h, c) except end; FreeImage(img); @@ -540,7 +537,7 @@ implementation try if LoadImageFromMemory(data, size, img) then if r_Textures_FixImageData(img) then - result := r_Textures_LoadMultiFromImageAndInfo(img, txt.w, txt.h, txt.anim.frames, txt.anim.back); + result := r_Textures_LoadMultiFromImageAndInfo(img, txt.w, txt.h, txt.anim.frames); finally FreeMem(data); end; @@ -564,7 +561,6 @@ implementation m := TGLMultiTexture.Create(); SetLength(m.mTexture, 1); m.mTexture[0] := t; - m.mBackanim := false; txt.name := ''; txt.w := m.width; txt.h := m.height; @@ -610,7 +606,7 @@ implementation result := r_Textures_LoadMultiTextFromFile(filename, txt, log); end; - function r_Textures_LoadMultiFromFileAndInfo (const filename: AnsiString; w, h, count: Integer; backanim: Boolean; log: Boolean = True): TGLMultiTexture; + function r_Textures_LoadMultiFromFileAndInfo (const filename: AnsiString; w, h, count: Integer; log: Boolean = True): TGLMultiTexture; var wad: TWADFile; wadName, resName: AnsiString; data: Pointer; size: Integer; begin ASSERT(w > 0); @@ -624,7 +620,7 @@ implementation resName := g_ExtractFilePathName(filename); if wad.GetResource(resName, data, size, log) then begin - result := r_Textures_LoadMultiFromDataAndInfo(data, size, w, h, count, backanim); + result := r_Textures_LoadMultiFromDataAndInfo(data, size, w, h, count); FreeMem(data); end; wad.Free