From da935dd8d7446a6a88b5343f6e6f061c8a3abddc Mon Sep 17 00:00:00 2001 From: Derek MacDonald Date: Thu, 8 Apr 2021 15:41:40 -0400 Subject: [PATCH] VPO limit configurable for Visplane Explorer (#546) https://doomwiki.org/wiki/Static_limits The VPO limit is raised by Hexen (160) & Strife (200) so make it configurable in the basegame. The hover tooltip will reflect the adjusted max limit and the heatmap is interpolated to 0-255 for the 256x10 visplane_pal.png colour range gradient. --- Build/Configurations/Includes/Doom_common.cfg | 7 +- .../Includes/Heretic_common.cfg | 7 +- .../Configurations/Includes/Hexen_common.cfg | 7 +- .../Configurations/Includes/Strife_common.cfg | 7 +- Source/Core/Builder.csproj | 1 + Source/Core/BuilderMono.csproj | 1 + Source/Core/Config/GameConfiguration.cs | 11 ++- Source/Core/Config/StaticLimits.cs | 74 +++++++++++++++++++ Source/Plugins/VisplaneExplorer/Tile.cs | 10 ++- .../VisplaneExplorer/VisplaneExplorerMode.cs | 21 +++++- 10 files changed, 138 insertions(+), 8 deletions(-) create mode 100644 Source/Core/Config/StaticLimits.cs diff --git a/Build/Configurations/Includes/Doom_common.cfg b/Build/Configurations/Includes/Doom_common.cfg index b3f1d0cb..dab89ded 100755 --- a/Build/Configurations/Includes/Doom_common.cfg +++ b/Build/Configurations/Includes/Doom_common.cfg @@ -73,7 +73,12 @@ mapformat_doom // Generalized actions generalizedlinedefs = false; generalizedsectors = false; - + + staticlimits + { + visplanes = 128; + } + // DEFAULT SECTOR BRIGHTNESS LEVELS sectorbrightness { diff --git a/Build/Configurations/Includes/Heretic_common.cfg b/Build/Configurations/Includes/Heretic_common.cfg index 8b170df7..65dea8ee 100755 --- a/Build/Configurations/Includes/Heretic_common.cfg +++ b/Build/Configurations/Includes/Heretic_common.cfg @@ -27,7 +27,12 @@ mapformat_doom // Generalized actions generalizedlinedefs = false; generalizedsectors = false; - + + staticlimits + { + visplanes = 128; + } + // DEFAULT SECTOR BRIGHTNESS LEVELS sectorbrightness { diff --git a/Build/Configurations/Includes/Hexen_common.cfg b/Build/Configurations/Includes/Hexen_common.cfg index 0deba779..9ab26cd9 100755 --- a/Build/Configurations/Includes/Hexen_common.cfg +++ b/Build/Configurations/Includes/Hexen_common.cfg @@ -27,7 +27,12 @@ mapformat_hexen // Generalized actions generalizedlinedefs = false; generalizedsectors = false; - + + staticlimits + { + visplanes = 160; + } + // DEFAULT SECTOR BRIGHTNESS LEVELS sectorbrightness { diff --git a/Build/Configurations/Includes/Strife_common.cfg b/Build/Configurations/Includes/Strife_common.cfg index 6c3d12b2..6170c3a0 100755 --- a/Build/Configurations/Includes/Strife_common.cfg +++ b/Build/Configurations/Includes/Strife_common.cfg @@ -27,7 +27,12 @@ mapformat_doom // Generalized actions generalizedlinedefs = false; generalizedsectors = false; - + + staticlimits + { + visplanes = 200; + } + // DEFAULT SECTOR BRIGHTNESS LEVELS sectorbrightness { diff --git a/Source/Core/Builder.csproj b/Source/Core/Builder.csproj index c33586e3..59cd5e20 100644 --- a/Source/Core/Builder.csproj +++ b/Source/Core/Builder.csproj @@ -143,6 +143,7 @@ + diff --git a/Source/Core/BuilderMono.csproj b/Source/Core/BuilderMono.csproj index faa82e6d..13d2c444 100644 --- a/Source/Core/BuilderMono.csproj +++ b/Source/Core/BuilderMono.csproj @@ -159,6 +159,7 @@ + diff --git a/Source/Core/Config/GameConfiguration.cs b/Source/Core/Config/GameConfiguration.cs index d27fee75..4f4f7376 100755 --- a/Source/Core/Config/GameConfiguration.cs +++ b/Source/Core/Config/GameConfiguration.cs @@ -108,7 +108,10 @@ namespace CodeImp.DoomBuilder.Config private readonly bool doommapformat; private readonly bool hexenmapformat; private readonly bool universalmapformat; - + + // Static limits for the base game and map format. + private readonly StaticLimits staticlimits; + // Texture/flat/voxel sources private readonly IDictionary textureranges; private readonly IDictionary hiresranges; //mxd @@ -247,6 +250,9 @@ namespace CodeImp.DoomBuilder.Config public bool HEXEN { get { return hexenmapformat; } } public bool DOOM { get { return doommapformat; } } + // Static limits for the base game and map format. + public StaticLimits StaticLimits { get { return staticlimits; } } + public bool UseLocalSidedefTextureOffsets { get { return localsidedeftextureoffsets; } } //MaxW public bool Effect3DFloorSupport { get { return effect3dfloorsupport; } } public bool PlaneEquationSupport { get { return planeequationsupport; } } @@ -425,6 +431,9 @@ namespace CodeImp.DoomBuilder.Config hexenmapformat = (formatinterface == "HexenMapSetIO"); doommapformat = (formatinterface == "DoomMapSetIO"); + // Read static limits for the base game and map format. + staticlimits = new StaticLimits(cfg); + //mxd. Texture names length longtexturenames = cfg.ReadSetting("longtexturenames", false); maxtexturenamelength = (longtexturenames ? short.MaxValue : DataManager.CLASIC_IMAGE_NAME_LENGTH); diff --git a/Source/Core/Config/StaticLimits.cs b/Source/Core/Config/StaticLimits.cs new file mode 100644 index 00000000..eac19509 --- /dev/null +++ b/Source/Core/Config/StaticLimits.cs @@ -0,0 +1,74 @@ +#region ================== Copyright (c) 2021 Derek MacDonald + +/* + * Copyright (c) 2021 Derek MacDonald + * This program is released under GNU General Public License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#endregion + +#region ================== Namespaces + +using CodeImp.DoomBuilder.IO; +using System; + +#endregion + +namespace CodeImp.DoomBuilder.Config +{ + public class StaticLimits + { + #region ================== Constants + + private const uint DEFAULT_MAX_VISPLANES = 128; + private const uint DEFAULT_MAX_VISPLANES_LIMIT = DEFAULT_MAX_VISPLANES * 2; + private const uint MAX_DRAWSEGS = 256; + private const uint MAX_SOLIDSEGS = 32; + private const uint MAX_OPENINGS = 320 * 64; + + #endregion + + #region ================== Variables + + private uint visplanes; + private static uint maxvisplaneslimit; + + #endregion + + #region ================== Properties + + public uint Visplanes { get { return visplanes; } } + public uint Drawsegs { get { return MAX_DRAWSEGS; } } + public uint Solidsegs { get { return MAX_SOLIDSEGS; } } + public uint Openings { get { return MAX_OPENINGS; } } + + #endregion + + // Constructor + internal StaticLimits(Configuration cfg) + { + visplanes = (uint)cfg.ReadSetting("staticlimits.visplanes", DEFAULT_MAX_VISPLANES); + maxvisplaneslimit = visplanes * 2; + } + + #region ================== Methods + + // This interpolates the supported visplane count to default range 1-255 + // where 128 is the configured static limit. + public byte InterpolateVisplanes(byte value) + { + if (visplanes == DEFAULT_MAX_VISPLANES) return value; + + double v = DEFAULT_MAX_VISPLANES_LIMIT * value / maxvisplaneslimit; + return (byte)Math.Ceiling(v); + } + + #endregion + } +} diff --git a/Source/Plugins/VisplaneExplorer/Tile.cs b/Source/Plugins/VisplaneExplorer/Tile.cs index f7e22c5f..6fb7a2c8 100755 --- a/Source/Plugins/VisplaneExplorer/Tile.cs +++ b/Source/Plugins/VisplaneExplorer/Tile.cs @@ -13,7 +13,6 @@ namespace CodeImp.DoomBuilder.Plugins.VisplaneExplorer // Constants public const int TILE_SIZE = 64; public static readonly int[] STATS_COMPRESSOR = new[] { 1, 2, 1, 160 }; - public static readonly int[] STATS_LIMITS = new[] { 128, 256, 32, 320 * 64 }; public const uint POINT_MAXRANGE = 254; public const uint POINT_OVERFLOW = 0xFEFEFEFE; public const uint POINT_VOID = 0xFFFFFFFF; @@ -93,6 +92,15 @@ namespace CodeImp.DoomBuilder.Plugins.VisplaneExplorer } } + // This returns a point value for the heatmap + public byte GetHeatmapByte(int x, int y, int stat) + { + byte b = GetPointByte(x, y, stat); + if (stat == (int)ViewStats.Visplanes && b != 0 && b != POINT_VOID_B) + b = General.Map.Config.StaticLimits.InterpolateVisplanes(b); + return b; + } + // This returns a point value public byte GetPointByte(int x, int y, int stat) { diff --git a/Source/Plugins/VisplaneExplorer/VisplaneExplorerMode.cs b/Source/Plugins/VisplaneExplorer/VisplaneExplorerMode.cs index f0b18a3b..41c5d4cf 100755 --- a/Source/Plugins/VisplaneExplorer/VisplaneExplorerMode.cs +++ b/Source/Plugins/VisplaneExplorer/VisplaneExplorerMode.cs @@ -165,7 +165,7 @@ namespace CodeImp.DoomBuilder.Plugins.VisplaneExplorer float uy = y * hinv * Tile.TILE_SIZE; // Get the data and apply the color - byte value = t.Value.GetPointByte((int)ux, Tile.TILE_SIZE - 1 - (int)uy, viewstats); + byte value = t.Value.GetHeatmapByte((int)ux, Tile.TILE_SIZE - 1 - (int)uy, viewstats); p[screeny * bd.Width + screenx] = (uint)pal.Colors[value]; } } @@ -456,7 +456,7 @@ namespace CodeImp.DoomBuilder.Plugins.VisplaneExplorer int value = t.GetPointValue(x, y, viewstats); Point p = new Point((int)mousepos.x + 5, (int)mousepos.y + 5); string appendoverflow = (b == Tile.POINT_OVERFLOW_B) ? "+" : ""; - BuilderPlug.InterfaceForm.ShowTooltip(value + appendoverflow + " / " + Tile.STATS_LIMITS[viewstats], p); + BuilderPlug.InterfaceForm.ShowTooltip(value + appendoverflow + " / " + StaticLimit(BuilderPlug.InterfaceForm.ViewStats), p); } else { @@ -489,6 +489,23 @@ namespace CodeImp.DoomBuilder.Plugins.VisplaneExplorer General.Interface.RedrawDisplay(); } + // Get the configured static limit for the given stat. + private uint StaticLimit(ViewStats stat) + { + switch (stat) + { + case ViewStats.Visplanes: + return General.Map.Config.StaticLimits.Visplanes; + case ViewStats.Drawsegs: + return General.Map.Config.StaticLimits.Drawsegs; + case ViewStats.Solidsegs: + return General.Map.Config.StaticLimits.Solidsegs; + case ViewStats.Openings: + return General.Map.Config.StaticLimits.Openings; + default: + return 0; + } + } #endregion } }