From 1523d06ee389ec55d302d9d9fdbb9ad114efdc54 Mon Sep 17 00:00:00 2001 From: MaxED Date: Mon, 28 Nov 2016 20:01:47 +0000 Subject: [PATCH] Updated, Visual mode: some cases when the sky hack must be applied were not handled. Updated, Script editor: script editor was unable to show error location after double-clicking on it in the Warnings and Errors window when said location was inside of a WAD located in a PK3 file. Updated, text lumps tracking: already parsed DECORATE/GLDEFS lumps are now added to the text lumps list even when DECORATE/GLDEFS parsing fails, allowing you to fix errors without the need to use external tools. Fixed: in some cases the editor could stuck in an infinite loop when searching for wad lumps. --- .../Controls/Scripting/ScriptEditorPanel.cs | 42 +++++++++++++++---- .../Scripting/ScriptResourcesControl.cs | 36 ++++++++++++++++ Source/Core/Data/DataManager.cs | 16 +++++-- Source/Core/IO/WAD.cs | 4 +- .../VisualModes/BaseVisualThing.cs | 5 ++- .../BuilderModes/VisualModes/VisualCeiling.cs | 26 +++++++----- .../BuilderModes/VisualModes/VisualFloor.cs | 23 +++++++++- .../BuilderModes/VisualModes/VisualLower.cs | 25 +++++++++++ .../BuilderModes/VisualModes/VisualUpper.cs | 20 +++++++-- 9 files changed, 167 insertions(+), 30 deletions(-) diff --git a/Source/Core/Controls/Scripting/ScriptEditorPanel.cs b/Source/Core/Controls/Scripting/ScriptEditorPanel.cs index 1448dba3..5186b98c 100644 --- a/Source/Core/Controls/Scripting/ScriptEditorPanel.cs +++ b/Source/Core/Controls/Scripting/ScriptEditorPanel.cs @@ -628,12 +628,35 @@ namespace CodeImp.DoomBuilder.Controls { // Resource exists? DataReader dr = null; - foreach(DataReader reader in General.Map.Data.Containers) + + // Resource is a temporary file? + if(item.ResourceLocation.StartsWith(General.Map.TempPath)) { - if(reader.Location.location == item.ResourceLocation) + // Search in PK3-embedded wads only + foreach(DataReader reader in General.Map.Data.Containers) { - dr = reader; - break; + if(!(reader is PK3Reader)) continue; + PK3Reader pkr = (PK3Reader)reader; + foreach(WADReader wadreader in pkr.Wads) + { + if(wadreader.Location.location == item.ResourceLocation) + { + dr = wadreader; + break; + } + } + } + } + else + { + // Search among resources + foreach(DataReader reader in General.Map.Data.Containers) + { + if(reader.Location.location == item.ResourceLocation) + { + dr = reader; + break; + } } } @@ -643,9 +666,14 @@ namespace CodeImp.DoomBuilder.Controls TextResourceData trd = new TextResourceData(dr, dr.LoadFile(item.LumpName, item.LumpIndex), item.LumpName, item.LumpIndex, false); var targettab = OpenResource(new ScriptResource(trd, item.ScriptType)); - // Go to error line - if(targettab != null && item.LineNumber != CompilerError.NO_LINE_NUMBER) - targettab.MoveToLine(item.LineNumber); + if(targettab != null) + { + // Go to error line + if(item.LineNumber != CompilerError.NO_LINE_NUMBER) targettab.MoveToLine(item.LineNumber); + + // Show in resources tree + scriptresources.SelectItem(item.ResourceLocation, item.LumpName, item.LumpIndex, item.ScriptType); + } } //mxd diff --git a/Source/Core/Controls/Scripting/ScriptResourcesControl.cs b/Source/Core/Controls/Scripting/ScriptResourcesControl.cs index c68b6db4..ef5d52e5 100644 --- a/Source/Core/Controls/Scripting/ScriptResourcesControl.cs +++ b/Source/Core/Controls/Scripting/ScriptResourcesControl.cs @@ -185,6 +185,41 @@ namespace CodeImp.DoomBuilder.Controls #region ================== Methods + public void SelectItem(string resourcelocation, string lumpname, int lumpindex, ScriptType scripttype) + { + TreeNode target = FindItem(projecttree.Nodes, resourcelocation, lumpname, lumpindex, scripttype); + if(target != null) + { + projecttree.SelectedNode = target; + } + } + + private static TreeNode FindItem(TreeNodeCollection nodes, string resourcelocation, string lumpname, int lumpindex, ScriptType scripttype) + { + foreach(TreeNode node in nodes) + { + // Is this the item we are looking for? + TextResourceNodeData data = (TextResourceNodeData)node.Tag; + + if(data.NodeType == TextResourceNodeType.NODE && data.ResourceLocation == resourcelocation + && data.ScriptType == scripttype && data.Resource.Filename == lumpname && data.Resource.LumpIndex == lumpindex) + { + // Found it! + return node; + } + + // Try children... + if(node.Nodes.Count > 0) + { + TreeNode item = FindItem(node.Nodes, resourcelocation, lumpname, lumpindex, scripttype); + if(item != null) return item; + } + } + + // No dice... + return null; + } + private void UpdateResourcesTree() { ScriptType targettype = (filterbytype.SelectedIndex > -1 ? ((ScriptTypeItem)filterbytype.SelectedItem).Type : ScriptType.UNKNOWN); @@ -352,6 +387,7 @@ namespace CodeImp.DoomBuilder.Controls LocationInResource = path, NodeType = TextResourceNodeType.NODE, Resource = res, + ScriptType = res.ScriptType, }; string includepath = (res.ScriptType == ScriptType.ACS ? "\nInclude path: \"" + res.Filename + "\"" : ""); TreeNode scriptnode = new TreeNode(res.ToString(), iconindex, iconindex) { Tag = data, ToolTipText = data + includepath }; diff --git a/Source/Core/Data/DataManager.cs b/Source/Core/Data/DataManager.cs index b0f93af9..94bf214a 100644 --- a/Source/Core/Data/DataManager.cs +++ b/Source/Core/Data/DataManager.cs @@ -1831,8 +1831,7 @@ namespace CodeImp.DoomBuilder.Data if(decorate.HasError) { decorate.LogError(); - currentreader = null; - return counter; + break; } } } @@ -2022,6 +2021,11 @@ namespace CodeImp.DoomBuilder.Data } } } + else + { + // Return after adding parsed resources + return counter; + } } // Output info @@ -2375,6 +2379,8 @@ namespace CodeImp.DoomBuilder.Data // Load gldefs from resources foreach(DataReader dr in containers) { + if(parser.HasError) break; + currentreader = dr; parser.ClearIncludesList(); IEnumerable streams = dr.GetGldefsData(General.Map.Config.BaseGame); @@ -2387,8 +2393,7 @@ namespace CodeImp.DoomBuilder.Data if(parser.HasError) { parser.LogError(); - currentreader = null; - return; + break; } } } @@ -2397,6 +2402,9 @@ namespace CodeImp.DoomBuilder.Data scriptresources[parser.ScriptType] = new HashSet(parser.ScriptResources.Values); currentreader = null; + //mxd. Abort on errors, but after adding parsed text resources + if(parser.HasError) return; + // Create Gldefs Entries dictionary foreach(KeyValuePair e in parser.Objects) // { diff --git a/Source/Core/IO/WAD.cs b/Source/Core/IO/WAD.cs index 8d7427d7..b6923d42 100644 --- a/Source/Core/IO/WAD.cs +++ b/Source/Core/IO/WAD.cs @@ -508,12 +508,12 @@ namespace CodeImp.DoomBuilder.IO // This finds a lump by name, returns -1 when not found public int FindLumpIndex(string name, int start, int end) { - if(name.Length > 8 || lumps.Count == 0) return -1; //mxd. Can't be here. Go away! + if(name.Length > 8 || lumps.Count == 0 || start > lumps.Count - 1) return -1; //mxd. Can't be here. Go away! long longname = Lump.MakeLongName(name); // Fix start/end when they exceed safe bounds - start = General.Clamp(start, 0, lumps.Count - 1); + start = Math.Max(start, 0); end = General.Clamp(end, 0, lumps.Count - 1); // Loop through the lumps diff --git a/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs b/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs index 189cc347..c24e8378 100644 --- a/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs +++ b/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs @@ -213,15 +213,16 @@ namespace CodeImp.DoomBuilder.BuilderModes int brightness = level.brightnessbelow; //mxd. Apply lightfloor value + // According to Graf, this is incorrect behaviour... // TECH: In (G)ZDoom, this is ignored when ceiling texture is sky or a thing is below a 3D floor // It's probably more involved than this, but for now let's do it only when there are no 3d floors in Thing.Sector... - if(General.Map.UDMF && sd.LightLevels.Count == 2 && Thing.Sector.CeilTexture != General.Map.Config.SkyFlatName) + /*if(General.Map.UDMF && sd.LightLevels.Count == 2 && Thing.Sector.CeilTexture != General.Map.Config.SkyFlatName) { if(sd.Sector.Fields.GetValue("lightfloorabsolute", false)) brightness = UniFields.GetInteger(sd.Sector.Fields, "lightfloor"); else brightness += UniFields.GetInteger(sd.Sector.Fields, "lightfloor"); - } + }*/ // Level is glowing if(level.affectedbyglow && level.type == SectorLevelType.Floor) diff --git a/Source/Plugins/BuilderModes/VisualModes/VisualCeiling.cs b/Source/Plugins/BuilderModes/VisualModes/VisualCeiling.cs index 4ce5e729..49197d5a 100644 --- a/Source/Plugins/BuilderModes/VisualModes/VisualCeiling.cs +++ b/Source/Plugins/BuilderModes/VisualModes/VisualCeiling.cs @@ -218,20 +218,26 @@ namespace CodeImp.DoomBuilder.BuilderModes foreach(Sidedef side in level.sector.Sidedefs) { VisualSidedefParts parts = Sector.GetSidedefParts(side); - if(parts.upper != null) parts.upper.UpdateSkyRenderFlag(); - else if(parts.middlesingle != null) parts.middlesingle.UpdateSkyRenderFlag(); - - // On the other side as well... - if(side.Other != null && side.Other.Sector != null && - side.Other.Sector.CeilTexture == General.Map.Config.SkyFlatName) + if(parts.upper != null) { - BaseVisualSector other = (BaseVisualSector)mode.GetVisualSector(side.Other.Sector); - if(other != null && other.Sides != null) + parts.upper.UpdateSkyRenderFlag(); + + // On the other side as well... + if(side.Other != null && side.Other.Sector != null && + (side.Other.HighTexture == "-" || side.Other.Sector.CeilTexture == General.Map.Config.SkyFlatName)) { - parts = other.GetSidedefParts(side.Other); - if(parts.upper != null) parts.upper.UpdateSkyRenderFlag(); + BaseVisualSector other = (BaseVisualSector)mode.GetVisualSector(side.Other.Sector); + if(other != null && other.Sides != null) + { + parts = other.GetSidedefParts(side.Other); + if(parts.upper != null) parts.upper.UpdateSkyRenderFlag(); + } } } + else if(parts.middlesingle != null) + { + parts.middlesingle.UpdateSkyRenderFlag(); + } } } } diff --git a/Source/Plugins/BuilderModes/VisualModes/VisualFloor.cs b/Source/Plugins/BuilderModes/VisualModes/VisualFloor.cs index 376b0bf5..5ca68f49 100644 --- a/Source/Plugins/BuilderModes/VisualModes/VisualFloor.cs +++ b/Source/Plugins/BuilderModes/VisualModes/VisualFloor.cs @@ -198,11 +198,30 @@ namespace CodeImp.DoomBuilder.BuilderModes renderassky = (level.sector.FloorTexture == General.Map.Config.SkyFlatName || level.sector.LongFloorTexture == MapSet.EmptyLongName); if(isrenderedassky != renderassky && Sector.Sides != null) { - // Middle geometry may need updating... + // Middle/Lower geometry may need updating... foreach(Sidedef side in level.sector.Sidedefs) { VisualSidedefParts parts = Sector.GetSidedefParts(side); - if(parts.middlesingle != null) parts.middlesingle.UpdateSkyRenderFlag(); + if(parts.lower != null) + { + parts.lower.UpdateSkyRenderFlag(); + + // On the other side as well... + if(side.Other != null && side.Other.Sector != null && + (side.Other.LowTexture == "-" || side.Other.Sector.FloorTexture == General.Map.Config.SkyFlatName)) + { + BaseVisualSector other = (BaseVisualSector)mode.GetVisualSector(side.Other.Sector); + if(other != null && other.Sides != null) + { + parts = other.GetSidedefParts(side.Other); + if(parts.lower != null) parts.lower.UpdateSkyRenderFlag(); + } + } + } + else if(parts.middlesingle != null) + { + parts.middlesingle.UpdateSkyRenderFlag(); + } } } } diff --git a/Source/Plugins/BuilderModes/VisualModes/VisualLower.cs b/Source/Plugins/BuilderModes/VisualModes/VisualLower.cs index 755e7026..dbb01223 100644 --- a/Source/Plugins/BuilderModes/VisualModes/VisualLower.cs +++ b/Source/Plugins/BuilderModes/VisualModes/VisualLower.cs @@ -62,6 +62,9 @@ namespace CodeImp.DoomBuilder.BuilderModes { Vector2D vl, vr; + //mxd. Apply sky hack? + UpdateSkyRenderFlag(); + //mxd. lightfog flag support int lightvalue; bool lightabsolute; @@ -206,6 +209,28 @@ namespace CodeImp.DoomBuilder.BuilderModes base.SetVertices(null); //mxd return false; } + + //mxd + internal void UpdateSkyRenderFlag() + { + bool isdoublesided = (Sidedef.Other != null && Sidedef.Sector != null && Sidedef.Other.Sector != null); + + //TECH: when a side part has no texture, sky hack will be applied when either front or back sectors' floor uses SkyFlatName texture + //TECH: this glitches in both ZDoom and GZDoom when only lower sector's floor has SkyFlatName + if(Sidedef.LowTexture == "-") + { + renderassky = (isdoublesided + && (Sidedef.Sector.FloorTexture == General.Map.Config.SkyFlatName + || Sidedef.Other.Sector.FloorTexture == General.Map.Config.SkyFlatName)); + } + //TECH: otherwise, sky hack will be applied when both front and back sector floors use SkyFlatName texture + else + { + renderassky = (isdoublesided + && Sidedef.Sector.FloorTexture == General.Map.Config.SkyFlatName + && Sidedef.Other.Sector.FloorTexture == General.Map.Config.SkyFlatName); + } + } #endregion diff --git a/Source/Plugins/BuilderModes/VisualModes/VisualUpper.cs b/Source/Plugins/BuilderModes/VisualModes/VisualUpper.cs index f2447194..93fea6db 100644 --- a/Source/Plugins/BuilderModes/VisualModes/VisualUpper.cs +++ b/Source/Plugins/BuilderModes/VisualModes/VisualUpper.cs @@ -204,9 +204,23 @@ namespace CodeImp.DoomBuilder.BuilderModes //mxd internal void UpdateSkyRenderFlag() { - renderassky = (Sidedef.Other != null && Sidedef.Sector != null && Sidedef.Other.Sector != null && - Sidedef.Sector.CeilTexture == General.Map.Config.SkyFlatName && - Sidedef.Other.Sector.CeilTexture == General.Map.Config.SkyFlatName); + bool isdoublesided = (Sidedef.Other != null && Sidedef.Sector != null && Sidedef.Other.Sector != null); + + //TECH: when a side part has no texture, sky hack will be applied when either front or back sectors' ceiling uses SkyFlatName texture + //TECH: this glitches in both ZDoom and GZDoom when only higher sector's ceiling has SkyFlatName + if(Sidedef.HighTexture == "-") + { + renderassky = (isdoublesided + && (Sidedef.Sector.CeilTexture == General.Map.Config.SkyFlatName + || Sidedef.Other.Sector.CeilTexture == General.Map.Config.SkyFlatName)); + } + //TECH: otherwise, sky hack will be applied when both front and back sector ceilings use SkyFlatName texture + else + { + renderassky = (isdoublesided + && Sidedef.Sector.CeilTexture == General.Map.Config.SkyFlatName + && Sidedef.Other.Sector.CeilTexture == General.Map.Config.SkyFlatName); + } } #endregion