From bf2b6c0e1c85ff864d7fe018903c372ee5d06abf Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Mon, 17 Jan 2022 01:39:30 +0300 Subject: [PATCH] render: use TAnimationState instead of TAnimation --- src/game/g_map.pas | 3 +- src/game/g_panel.pas | 44 +++++++------ src/game/opengl/r_panel.pas | 128 ++++++++++++++++++------------------ 3 files changed, 89 insertions(+), 86 deletions(-) diff --git a/src/game/g_map.pas b/src/game/g_map.pas index 8d64ebb..c8adfdf 100644 --- a/src/game/g_map.pas +++ b/src/game/g_map.pas @@ -243,6 +243,8 @@ type var mapGrid: TPanelGrid = nil; // DO NOT USE! public for debugging only! +var (* private state *) + Textures: TLevelTextureArray = nil; implementation @@ -524,7 +526,6 @@ begin end; var - Textures: TLevelTextureArray = nil; TextNameHash: THashStrInt = nil; // key: texture name; value: index in `Textures` BadTextNameHash: THashStrInt = nil; // set; so we won't spam with non-existing texture messages RespawnPoints: array of TRespawnPoint; diff --git a/src/game/g_panel.pas b/src/game/g_panel.pas index f8a252e..9d08ba3 100644 --- a/src/game/g_panel.pas +++ b/src/game/g_panel.pas @@ -23,16 +23,16 @@ uses MAPDEF, g_textures, xdynrec; type - TAddTextureArray = Array of - record - Texture: Cardinal; - Anim: Boolean; - end; + TAddTextureArray = array of record + Texture: Cardinal; // Textures[Texture] + Anim: Boolean; + end; ATextureID = array of record + Texture: Cardinal; // Textures[Texture] case Anim: Boolean of - False: (Tex: Cardinal); - True: (AnTex: TAnimation); + False: (); + True: (AnTex: TAnimationState); end; PPanel = ^TPanel; @@ -319,6 +319,8 @@ begin SetLength(FTextureIDs, 1); FTextureIDs[0].Anim := False; +{ + // !!! set this case PanelRec.PanelType of PANEL_WATER: FTextureIDs[0].Tex := LongWord(TEXTURE_SPECIAL_WATER); @@ -327,6 +329,7 @@ begin PANEL_ACID2: FTextureIDs[0].Tex := LongWord(TEXTURE_SPECIAL_ACID2); end; +} FCurTexture := 0; Exit; @@ -344,19 +347,14 @@ begin for i := 0 to Length(FTextureIDs)-1 do begin + FTextureIDs[i].Texture := AddTextures[i].Texture; FTextureIDs[i].Anim := AddTextures[i].Anim; if FTextureIDs[i].Anim then - begin // Àíèìèðîâàííàÿ òåêñòóðà - FTextureIDs[i].AnTex := - TAnimation.Create(Textures[AddTextures[i].Texture].FramesID, - True, Textures[AddTextures[i].Texture].Speed); - FTextureIDs[i].AnTex.Blending := ByteBool(PanelRec.Flags and PANEL_FLAG_BLENDING); - FTextureIDs[i].AnTex.Alpha := PanelRec.Alpha; - end - else - begin // Îáû÷íàÿ òåêñòóðà - FTextureIDs[i].Tex := Textures[AddTextures[i].Texture].TextureID; - end; + begin // Àíèìèðîâàííàÿ òåêñòóðà + FTextureIDs[i].AnTex := TAnimationState.Create(True, Textures[AddTextures[i].Texture].Speed, Textures[AddTextures[i].Texture].FramesCount); + FTextureIDs[i].AnTex.Blending := ByteBool(PanelRec.Flags and PANEL_FLAG_BLENDING); + FTextureIDs[i].AnTex.Alpha := PanelRec.Alpha; + end end; // Òåêñòóð íåñêîëüêî - íóæíî ñîõðàíÿòü òåêóùóþ: @@ -952,14 +950,20 @@ end; function TPanel.GetTextureID(): DWORD; begin Result := LongWord(TEXTURE_NONE); - if (FCurTexture >= 0) then begin + if FTextureIDs[FCurTexture].Anim then + Result := Textures[FTextureIDs[FCurTexture].Texture].FramesID + else + Result := Textures[FTextureIDs[FCurTexture].Texture].TextureID +{ + // !!! old behavior if FTextureIDs[FCurTexture].Anim then Result := FTextureIDs[FCurTexture].AnTex.FramesID else Result := FTextureIDs[FCurTexture].Tex; - end; +} + end end; function TPanel.GetTextureCount(): Integer; diff --git a/src/game/opengl/r_panel.pas b/src/game/opengl/r_panel.pas index 4cd4f38..539c9a7 100644 --- a/src/game/opengl/r_panel.pas +++ b/src/game/opengl/r_panel.pas @@ -28,7 +28,7 @@ implementation {$INCLUDE ../nogl/noGLuses.inc} SysUtils, Classes, Math, utils, r_graphics, g_options, r_animations, r_textures, - g_base, g_basic, g_game + g_base, g_basic, g_map, g_game ; procedure Panel_Lerp (p: TPanel; t: Single; out tX, tY, tW, tH: Integer); @@ -52,59 +52,59 @@ implementation // TODO: remove WITH operator procedure r_Panel_Draw (constref p: TPanel; hasAmbient: Boolean; constref ambColor: TDFColor); - var tx, ty, tw, th, xx, yy: Integer; NoTextureID: DWORD; NW, NH: Word; + var tx, ty, tw, th, xx, yy: Integer; NoTextureID, TextureID, FramesID: DWORD; NW, NH: Word; Texture: Cardinal; IsAnim: Boolean; begin - with p do + if {p.Enabled and} (p.FCurTexture >= 0) and (p.Width > 0) and (p.Height > 0) and (p.Alpha < 255) {and g_Collide(X, Y, Width, Height, sX, sY, sWidth, sHeight)} then begin - if {Enabled and} (FCurTexture >= 0) and (Width > 0) and (Height > 0) and (Alpha < 255) {and g_Collide(X, Y, Width, Height, sX, sY, sWidth, sHeight)} then + Panel_Lerp(p, gLerpFactor, tx, ty, tw, th); + Texture := p.TextureIDs[p.FCurTexture].Texture; + IsAnim := p.TextureIDs[p.FCurTexture].Anim; + if IsAnim then begin - Panel_Lerp(p, gLerpFactor, tx, ty, tw, th); - if TextureIDs[FCurTexture].Anim then + if p.TextureIDs[p.FCurTexture].AnTex <> nil then begin - if TextureIDs[FCurTexture].AnTex = nil then - Exit; - for xx := 0 to tw div TextureWidth - 1 do - for yy := 0 to th div TextureHeight - 1 do - r_Animation_Draw(TextureIDs[FCurTexture].AnTex, tx + xx * TextureWidth, ty + yy * TextureHeight, TMirrorType.None); + FramesID := Textures[Texture].FramesID; + for xx := 0 to tw div p.TextureWidth - 1 do + for yy := 0 to th div p.TextureHeight - 1 do + r_AnimationState_Draw(FramesID, p.TextureIDs[p.FCurTexture].AnTex, tx + xx * p.TextureWidth, ty + yy * p.TextureHeight, TMirrorType.None); end - else - begin - case TextureIDs[FCurTexture].Tex of - LongWord(TEXTURE_SPECIAL_WATER): e_DrawFillQuad(tx, ty, tx + tw - 1, ty + th - 1, 0, 0, 255, 0, TBlending.Filter); - LongWord(TEXTURE_SPECIAL_ACID1): e_DrawFillQuad(tx, ty, tx + tw - 1, ty + th - 1, 0, 230, 0, 0, TBlending.Filter); - LongWord(TEXTURE_SPECIAL_ACID2): e_DrawFillQuad(tx, ty, tx + tw - 1, ty + th - 1, 230, 0, 0, 0, TBlending.Filter); - LongWord(TEXTURE_NONE): - if g_Texture_Get('NOTEXTURE', NoTextureID) then - begin - e_GetTextureSize(NoTextureID, @NW, @NH); - e_DrawFill(NoTextureID, tx, ty, tw div NW, th div NH, 0, False, False); - end - else - begin - xx := tx + (tw div 2); - yy := ty + (th div 2); - e_DrawFillQuad(tx, ty, xx, yy, 255, 0, 255, 0); - e_DrawFillQuad(xx, ty, tx + tw - 1, yy, 255, 255, 0, 0); - e_DrawFillQuad(X, yy, xx, ty + th - 1, 255, 255, 0, 0); - e_DrawFillQuad(xx, yy, tx + tw - 1, ty + th - 1, 255, 0, 255, 0); - end; - else + end + else + begin + TextureID := Textures[Texture].TextureID; // GL texture + case TextureID of + LongWord(TEXTURE_SPECIAL_WATER): e_DrawFillQuad(tx, ty, tx + tw - 1, ty + th - 1, 0, 0, 255, 0, TBlending.Filter); + LongWord(TEXTURE_SPECIAL_ACID1): e_DrawFillQuad(tx, ty, tx + tw - 1, ty + th - 1, 0, 230, 0, 0, TBlending.Filter); + LongWord(TEXTURE_SPECIAL_ACID2): e_DrawFillQuad(tx, ty, tx + tw - 1, ty + th - 1, 230, 0, 0, 0, TBlending.Filter); + LongWord(TEXTURE_NONE): + if g_Texture_Get('NOTEXTURE', NoTextureID) then begin - if not movingActive then - e_DrawFill(TextureIDs[FCurTexture].Tex, tx, ty, tw div TextureWidth, th div TextureHeight, Alpha, True, Blending, hasAmbient) - else - e_DrawFillX(TextureIDs[FCurTexture].Tex, tx, ty, tw, th, Alpha, True, Blending, g_dbg_scale, hasAmbient); - if hasAmbient then - e_AmbientQuad(tx, ty, tw, th, ambColor.r, ambColor.g, ambColor.b, ambColor.a); + e_GetTextureSize(NoTextureID, @NW, @NH); + e_DrawFill(NoTextureID, tx, ty, tw div NW, th div NH, 0, False, False); end - end + else + begin + xx := tx + (tw div 2); + yy := ty + (th div 2); + e_DrawFillQuad(tx, ty, xx, yy, 255, 0, 255, 0); + e_DrawFillQuad(xx, ty, tx + tw - 1, yy, 255, 255, 0, 0); + e_DrawFillQuad(tx, yy, xx, ty + th - 1, 255, 255, 0, 0); + e_DrawFillQuad(xx, yy, tx + tw - 1, ty + th - 1, 255, 0, 255, 0); + end; + else + if not p.movingActive then + e_DrawFill(TextureID, tx, ty, tw div p.TextureWidth, th div p.TextureHeight, p.Alpha, True, p.Blending, hasAmbient) + else + e_DrawFillX(TextureID, tx, ty, tw, th, p.Alpha, True, p.Blending, g_dbg_scale, hasAmbient); + if hasAmbient then + e_AmbientQuad(tx, ty, tw, th, ambColor.r, ambColor.g, ambColor.b, ambColor.a); end end end end; procedure r_Panel_DrawShadowVolume (constref p: TPanel; lightX, lightY: Integer; radius: Integer); - var tx, ty, tw, th: Integer; + var tx, ty, tw, th: Integer; Texture: Cardinal; procedure extrude (x: Integer; y: Integer); begin @@ -125,33 +125,31 @@ implementation end; begin - with p do + if radius < 4 then exit; + if p.Enabled and (p.FCurTexture >= 0) and (p.Width > 0) and (p.Height > 0) and (p.Alpha < 255) {and g_Collide(X, Y, tw, th, sX, sY, sWidth, sHeight)} then begin - if radius < 4 then exit; - if Enabled and (FCurTexture >= 0) and (Width > 0) and (Height > 0) and (Alpha < 255) {and g_Collide(X, Y, tw, th, sX, sY, sWidth, sHeight)} then + Panel_Lerp(p, gLerpFactor, tx, ty, tw, th); + if not p.TextureIDs[p.FCurTexture].Anim then begin - Panel_Lerp(p, gLerpFactor, tx, ty, tw, th); - if not TextureIDs[FCurTexture].Anim then - begin - case TextureIDs[FCurTexture].Tex of - LongWord(TEXTURE_SPECIAL_WATER): exit; - LongWord(TEXTURE_SPECIAL_ACID1): exit; - LongWord(TEXTURE_SPECIAL_ACID2): exit; - LongWord(TEXTURE_NONE): exit; - end; + Texture := p.TextureIDs[p.FCurTexture].Texture; + case Textures[Texture].TextureID of + LongWord(TEXTURE_SPECIAL_WATER): exit; + LongWord(TEXTURE_SPECIAL_ACID1): exit; + LongWord(TEXTURE_SPECIAL_ACID2): exit; + LongWord(TEXTURE_NONE): exit; end; - if (tx + tw < lightX - radius) then exit; - if (ty + th < lightY - radius) then exit; - if (tx > lightX + radius) then exit; - if (ty > lightY + radius) then exit; - //e_DrawFill(TextureIDs[FCurTexture].Tex, X, Y, tw div TextureWidth, th div TextureHeight, Alpha, True, Blending); - glBegin(GL_QUADS); - drawLine(tx, ty, tx + tw, ty); // top - drawLine(tx + tw, ty, tx + tw, ty + th); // right - drawLine(tx + tw, ty + th, tx, ty + th); // bottom - drawLine(tx, ty + th, tx, ty); // left - glEnd; - end + end; + if (tx + tw < lightX - radius) then exit; + if (ty + th < lightY - radius) then exit; + if (tx > lightX + radius) then exit; + if (ty > lightY + radius) then exit; + //e_DrawFill(TextureIDs[FCurTexture].Tex, X, Y, tw div TextureWidth, th div TextureHeight, Alpha, True, Blending); + glBegin(GL_QUADS); + drawLine(tx, ty, tx + tw, ty); // top + drawLine(tx + tw, ty, tx + tw, ty + th); // right + drawLine(tx + tw, ty + th, tx, ty + th); // bottom + drawLine(tx, ty + th, tx, ty); // left + glEnd; end end; -- 2.29.2