From: DeaDDooMER Date: Mon, 20 Feb 2023 13:01:01 +0000 (+0300) Subject: gl: fix fluid textures X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=2d4aaa4d7c605f6641a04615283eaf941c59fb59;p=d2df-sdl.git gl: fix fluid textures --- diff --git a/src/game/g_panel.pas b/src/game/g_panel.pas index f259aa3..2681f1d 100644 --- a/src/game/g_panel.pas +++ b/src/game/g_panel.pas @@ -246,21 +246,25 @@ const { T P a n e l : } - function FindTextureByName (const name: String): Integer; - var i: Integer; + function GetSpecialTexture (const name: String): Integer; + (* HACK: get texture id, if not present -> insert it into list *) + (* required for older maps *) + var i, len: Integer; begin - Result := -1; + i := 0; len := 0; if Textures <> nil then begin - for i := 0 to High(Textures) do - begin - if Textures[i].TextureName = name then - begin - Result := i; - break; - end - end - end + len := Length(Textures); + while (i < len) and (Textures[i].TextureName <> name) do + Inc(i); + end; + if i >= len then + begin + i := len; + SetLength(Textures, len + 1); + Textures[i].TextureName := name; + end; + result := i; end; constructor TPanel.Create(PanelRec: TDynRecord; @@ -343,9 +347,9 @@ begin begin SetLength(FTextureIDs, 1); case PanelRec.PanelType of - PANEL_WATER: FTextureIDs[0].Texture := FindTextureByName(TEXTURE_NAME_WATER); - PANEL_ACID1: FTextureIDs[0].Texture := FindTextureByName(TEXTURE_NAME_ACID1); - PANEL_ACID2: FTextureIDs[0].Texture := FindTextureByName(TEXTURE_NAME_ACID2); + PANEL_WATER: FTextureIDs[0].Texture := GetSpecialTexture(TEXTURE_NAME_WATER); + PANEL_ACID1: FTextureIDs[0].Texture := GetSpecialTexture(TEXTURE_NAME_ACID1); + PANEL_ACID2: FTextureIDs[0].Texture := GetSpecialTexture(TEXTURE_NAME_ACID2); end; FCurTexture := 0; Exit; diff --git a/src/game/renders/opengl/r_map.pas b/src/game/renders/opengl/r_map.pas index 927d251..371b13d 100644 --- a/src/game/renders/opengl/r_map.pas +++ b/src/game/renders/opengl/r_map.pas @@ -587,17 +587,15 @@ implementation var Texture, spec: Integer; t: TGLMultiTexture; count, frame: LongInt; a: TAnimInfo; begin ASSERT(p <> nil); - - spec := -1; + ASSERT(p.FCurTexture >= -1); (* p.FCurTexture = -1 -> invisible texture *) if p.FCurTexture >= 0 then begin ASSERT(p.FCurTexture <= High(p.TextureIDs)); Texture := p.TextureIDs[p.FCurTexture].Texture; - ASSERT(Texture >= -1); + ASSERT(Texture >= -1); (* Texture = -1 -> texture not found *) if Texture >= 0 then begin ASSERT(Texture <= High(RenTextures)); - spec := RenTextures[Texture].spec; t := RenTextures[Texture].tex; if t <> nil then begin @@ -614,26 +612,17 @@ implementation begin r_Draw_TextureRepeat(nil, p.x, p.y, p.width, p.height, false, 255, 255, 255, 255, false); end; + case RenTextures[Texture].spec of + TEXTURE_SPECIAL_WATER: r_Draw_Filter(p.x, p.y, p.x + p.width, p.y + p.height, 0, 0, 255, 255); + TEXTURE_SPECIAL_ACID1: r_Draw_Filter(p.x, p.y, p.x + p.width, p.y + p.height, 0, 230, 0, 255); + TEXTURE_SPECIAL_ACID2: r_Draw_Filter(p.x, p.y, p.x + p.width, p.y + p.height, 230, 0, 0, 255); + end; + end + else + begin + r_Draw_TextureRepeat(nil, p.x, p.y, p.width, p.height, false, 255, 255, 255, 255, false); end; end; - - // legacy support: - // older maps may omit textures for fluid panels - // in such case default filters must be used automatically - if spec = -1 then - begin - case p.PanelType of - PANEL_WATER: spec := TEXTURE_SPECIAL_WATER; - PANEL_ACID1: spec := TEXTURE_SPECIAL_ACID1; - PANEL_ACID2: spec := TEXTURE_SPECIAL_ACID2; - end; - end; - - case spec of - TEXTURE_SPECIAL_WATER: r_Draw_Filter(p.x, p.y, p.x + p.width, p.y + p.height, 0, 0, 255, 255); - TEXTURE_SPECIAL_ACID1: r_Draw_Filter(p.x, p.y, p.x + p.width, p.y + p.height, 0, 230, 0, 255); - TEXTURE_SPECIAL_ACID2: r_Draw_Filter(p.x, p.y, p.x + p.width, p.y + p.height, 230, 0, 0, 255); - end; end; procedure r_Map_DrawPanels (constref panels: TPanelArray; drawDoors: Boolean = false);