From 16333a342f6a12afee83673e55a123f6b700a804 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 | 123 ++++++++++++++++++------------------ 3 files changed, 87 insertions(+), 83 deletions(-) diff --git a/src/game/g_map.pas b/src/game/g_map.pas index a33ceda..026ef9b 100644 --- a/src/game/g_map.pas +++ b/src/game/g_map.pas @@ -242,6 +242,8 @@ type var mapGrid: TPanelGrid = nil; // DO NOT USE! public for debugging only! +var (* private state *) + Textures: TLevelTextureArray = nil; implementation @@ -523,7 +525,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 aa68298..d3e4414 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; @@ -309,6 +309,8 @@ begin SetLength(FTextureIDs, 1); FTextureIDs[0].Anim := False; +{ + // !!! set this case PanelRec.PanelType of PANEL_WATER: FTextureIDs[0].Tex := LongWord(TEXTURE_SPECIAL_WATER); @@ -317,6 +319,7 @@ begin PANEL_ACID2: FTextureIDs[0].Tex := LongWord(TEXTURE_SPECIAL_ACID2); end; +} FCurTexture := 0; Exit; @@ -334,19 +337,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; // Òåêñòóð íåñêîëüêî - íóæíî ñîõðàíÿòü òåêóùóþ: @@ -889,14 +887,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 a844631..de73d72 100644 --- a/src/game/opengl/r_panel.pas +++ b/src/game/opengl/r_panel.pas @@ -28,63 +28,64 @@ implementation {$INCLUDE ../nogl/noGLuses.inc} SysUtils, Classes, Math, r_graphics, g_options, r_animations, r_textures, - g_base, g_basic + g_base, g_basic, g_map ; // TODO: remove WITH operator procedure r_Panel_Draw (constref p: TPanel; hasAmbient: Boolean; constref ambColor: TDFColor); - var xx, yy: Integer; NoTextureID: DWORD; NW, NH: Word; + var 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 + Texture := p.TextureIDs[p.FCurTexture].Texture; + IsAnim := p.TextureIDs[p.FCurTexture].Anim; + if IsAnim then begin - 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 Width div TextureWidth - 1 do - for yy := 0 to Height div TextureHeight - 1 do - r_Animation_Draw(TextureIDs[FCurTexture].AnTex, X + xx * TextureWidth, Y + yy * TextureHeight, TMirrorType.None); + FramesID := Textures[Texture].FramesID; + for xx := 0 to p.Width div p.TextureWidth - 1 do + for yy := 0 to p.Height div p.TextureHeight - 1 do + r_AnimationState_Draw(FramesID, p.TextureIDs[p.FCurTexture].AnTex, p.X + xx * p.TextureWidth, p.Y + yy * p.TextureHeight, TMirrorType.None); end - else - begin - case TextureIDs[FCurTexture].Tex of - LongWord(TEXTURE_SPECIAL_WATER): e_DrawFillQuad(X, Y, X + Width - 1, Y + Height - 1, 0, 0, 255, 0, TBlending.Filter); - LongWord(TEXTURE_SPECIAL_ACID1): e_DrawFillQuad(X, Y, X + Width - 1, Y + Height - 1, 0, 230, 0, 0, TBlending.Filter); - LongWord(TEXTURE_SPECIAL_ACID2): e_DrawFillQuad(X, Y, X + Width - 1, Y + Height - 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, X, Y, Width div NW, Height div NH, 0, False, False); - end - else - begin - xx := X + (Width div 2); - yy := Y + (Height div 2); - e_DrawFillQuad(X, Y, xx, yy, 255, 0, 255, 0); - e_DrawFillQuad(xx, Y, X + Width - 1, yy, 255, 255, 0, 0); - e_DrawFillQuad(X, yy, xx, Y + Height - 1, 255, 255, 0, 0); - e_DrawFillQuad(xx, yy, X + Width - 1, Y + Height - 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(p.X, p.Y, p.X + p.Width - 1, p.Y + p.Height - 1, 0, 0, 255, 0, TBlending.Filter); + LongWord(TEXTURE_SPECIAL_ACID1): e_DrawFillQuad(p.X, p.Y, p.X + p.Width - 1, p.Y + p.Height - 1, 0, 230, 0, 0, TBlending.Filter); + LongWord(TEXTURE_SPECIAL_ACID2): e_DrawFillQuad(p.X, p.Y, p.X + p.Width - 1, p.Y + p.Height - 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, X, Y, Width div TextureWidth, Height div TextureHeight, Alpha, True, Blending, hasAmbient) - else - e_DrawFillX(TextureIDs[FCurTexture].Tex, X, Y, Width, Height, Alpha, True, Blending, g_dbg_scale, hasAmbient); - if hasAmbient then - e_AmbientQuad(X, Y, Width, Height, ambColor.r, ambColor.g, ambColor.b, ambColor.a); + e_GetTextureSize(NoTextureID, @NW, @NH); + e_DrawFill(NoTextureID, p.X, p.Y, p.Width div NW, p.Height div NH, 0, False, False); end - end + else + begin + xx := p.X + (p.Width div 2); + yy := p.Y + (p.Height div 2); + e_DrawFillQuad(p.X, p.Y, xx, yy, 255, 0, 255, 0); + e_DrawFillQuad(xx, p.Y, p.X + p.Width - 1, yy, 255, 255, 0, 0); + e_DrawFillQuad(p.X, yy, xx, p.Y + p.Height - 1, 255, 255, 0, 0); + e_DrawFillQuad(xx, yy, p.X + p.Width - 1, p.Y + p.Height - 1, 255, 0, 255, 0); + end; + else + if not p.movingActive then + e_DrawFill(TextureID, p.X, p.Y, p.Width div p.TextureWidth, p.Height div p.TextureHeight, p.Alpha, True, p.Blending, hasAmbient) + else + e_DrawFillX(TextureID, p.X, p.Y, p.Width, p.Height, p.Alpha, True, p.Blending, g_dbg_scale, hasAmbient); + if hasAmbient then + e_AmbientQuad(p.X, p.Y, p.Width, p.Height, 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 Texture: Cardinal; procedure extrude (x: Integer; y: Integer); begin @@ -105,32 +106,30 @@ 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, Width, Height, 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, Width, Height, sX, sY, sWidth, sHeight)} then + if not p.TextureIDs[p.FCurTexture].Anim then begin - 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 (X + Width < lightX - radius) then exit; - if (Y + Height < lightY - radius) then exit; - if (X > lightX + radius) then exit; - if (Y > lightY + radius) then exit; - //e_DrawFill(TextureIDs[FCurTexture].Tex, X, Y, Width div TextureWidth, Height div TextureHeight, Alpha, True, Blending); - glBegin(GL_QUADS); - drawLine(x, y, x + width, y); // top - drawLine(x + width, y, x + width, y + height); // right - drawLine(x + width, y + height, x, y + height); // bottom - drawLine(x, y + height, x, y); // left - glEnd; - end + end; + if (p.X + p.Width < lightX - radius) then exit; + if (p.Y + p.Height < lightY - radius) then exit; + if (p.X > lightX + radius) then exit; + if (p.Y > lightY + radius) then exit; + //e_DrawFill(TextureIDs[FCurTexture].Tex, X, Y, Width div TextureWidth, Height div TextureHeight, Alpha, True, Blending); + glBegin(GL_QUADS); + drawLine(p.x, p.y, p.x + p.width, p.y); // top + drawLine(p.x + p.width, p.y, p.x + p.width, p.y + p.height); // right + drawLine(p.x + p.width, p.y + p.height, p.x, p.y + p.height); // bottom + drawLine(p.x, p.y + p.height, p.x, p.y); // left + glEnd; end end; -- 2.29.2