diff --git a/CodeWalker/Project/ProjectForm.cs b/CodeWalker/Project/ProjectForm.cs index 367ff83c9..2981859f6 100644 --- a/CodeWalker/Project/ProjectForm.cs +++ b/CodeWalker/Project/ProjectForm.cs @@ -92,8 +92,8 @@ public bool IsProjectLoaded - private bool renderitems = true; - private bool hidegtavmap = false; + public static bool renderitems = true; + public static bool hidegtavmap = false; private bool autoymapflags = true; private bool autoymapextents = true; public bool displayentityindexes = false; @@ -1393,6 +1393,7 @@ public void CloseProject() CurrentYmapFile = ymap; SaveYmap(); } + ymap.HasChanged = false; } } @@ -1519,6 +1520,15 @@ public void CloseProject() } + if (!renderitems) + { + renderitems = true; + } + + if (hidegtavmap) + { + hidegtavmap = false; + } if (WorldForm != null) { @@ -1614,7 +1624,11 @@ public void OpenFiles(string[] files = null) { case ".ymap": var ymap = CurrentProjectFile.AddYmapFile(file); - if (ymap != null) LoadYmapFromFile(ymap, file); + if (ymap != null) + { + LoadYmapFromFile(ymap, file); + ymap.HasChanged = true; + } break; case ".ytyp": var ytyp = CurrentProjectFile.AddYtypFile(file); @@ -1996,7 +2010,7 @@ public void SaveYmap(bool saveas = false) File.WriteAllBytes(filepath, data); } - SetYmapHasChanged(false); + SetYmapHasChanged(true); if (saveas) { @@ -2061,6 +2075,7 @@ public void RemoveYmapFromProject() { if (CurrentYmapFile == null) return; if (CurrentProjectFile == null) return; + CurrentYmapFile.HasChanged = false; CurrentProjectFile.RemoveYmapFile(CurrentYmapFile); CurrentYmapFile = null; LoadProjectTree(); @@ -7214,10 +7229,10 @@ public bool YtdExistsInProject(YtdFile ytd) public void GetVisibleYmaps(Camera camera, Dictionary ymaps) { - if (hidegtavmap) - { - ymaps.Clear(); //remove all the gtav ymaps. - } + //if (hidegtavmap) + //{ + // ymaps.Clear(); //remove all the gtav ymaps. + //} lock (projectsyncroot) { diff --git a/CodeWalker/Rendering/Renderer.cs b/CodeWalker/Rendering/Renderer.cs index afe3d1eda..20fa9c8b5 100644 --- a/CodeWalker/Rendering/Renderer.cs +++ b/CodeWalker/Rendering/Renderer.cs @@ -1,4 +1,5 @@ using CodeWalker.GameFiles; +using CodeWalker.Project; using CodeWalker.Properties; using CodeWalker.World; using SharpDX; @@ -4022,6 +4023,8 @@ public class RenderLodManager public bool ShowScriptedYmaps = true; public bool HDLightsEnabled = true; public bool LODLightsEnabled = true; + public bool RenderItems => ProjectForm.renderitems; + public bool HideGtavMap => ProjectForm.hidegtavmap; public Camera Camera = null; public Vector3 Position = Vector3.Zero; @@ -4061,10 +4064,10 @@ public void Update(Dictionary ymaps, Camera camera, float el { YmapFile ymap = null; if (!ymaps.TryGetValue(kvp.Key, out ymap) || (ymap != kvp.Value) || (ymap.IsScripted && !ShowScriptedYmaps) || (ymap.LodManagerUpdate)) - { - RemoveYmaps.Add(kvp.Key); + { + RemoveYmaps.Add(kvp.Key); + } } - } foreach (var remYmap in RemoveYmaps) { var ymap = CurrentYmaps[remYmap]; @@ -4075,16 +4078,16 @@ public void Update(Dictionary ymaps, Camera camera, float el for (int i = 0; i < remEnts.Length; i++) { var ent = remEnts[i]; - RootEntities.Remove(ent); - ent.LodManagerChildren?.Clear(); - ent.LodManagerChildren = null; - ent.LodManagerRenderable = null; - if ((ent.Parent != null) && (ent.Parent.Ymap != ymap)) - { - ent.Parent.LodManagerRemoveChild(ent); + RootEntities.Remove(ent); + ent.LodManagerChildren?.Clear(); + ent.LodManagerChildren = null; + ent.LodManagerRenderable = null; + if ((ent.Parent != null) && (ent.Parent.Ymap != ymap)) + { + ent.Parent.LodManagerRemoveChild(ent); + } } } - } var remLodLights = ymap.LODLights?.LodLights; if (remLodLights != null) { @@ -4136,18 +4139,33 @@ public void Update(Dictionary ymaps, Camera camera, float el VisibleLeaves.Clear(); VisibleLights.Clear(); - foreach (var kvp in RootEntities) + + if (HideGtavMap) { - var ent = kvp.Key; - if (EntityVisibleAtMaxLodLevel(ent)) + foreach (var kvp in CurrentYmaps) { - ent.Distance = MapViewEnabled ? MapViewDist : (ent.Position - Position).Length(); - if (ent.Distance <= (ent.LodDist * LodDistMult)) + var ymap = kvp.Value; + if (ymap.HasChanged && ymap.AllEntities != null) { - RecurseAddVisibleLeaves(ent); + if (!RenderItems) continue; + foreach (var ent in ymap.AllEntities) + { + ProcessEntitiesForVisibility(ent); + } } } } + else + { + foreach (var kvp in RootEntities) + { + var ent = kvp.Key; + if (ent.Ymap.HasChanged && !RenderItems) + continue; + + ProcessEntitiesForVisibility(ent); + } + } UpdateLodLights.Clear(); foreach (var light in VisibleLights) @@ -4178,7 +4196,17 @@ public void Update(Dictionary ymaps, Camera camera, float el VisibleLights = VisibleLightsPrev; VisibleLightsPrev = vl; } - + private void ProcessEntitiesForVisibility(YmapEntityDef ent) + { + if (EntityVisibleAtMaxLodLevel(ent)) + { + ent.Distance = MapViewEnabled ? MapViewDist : (ent.Position - Position).Length(); + if (ent.Distance <= (ent.LodDist * LodDistMult)) + { + RecurseAddVisibleLeaves(ent); + } + } + } private void RecurseAddVisibleLeaves(YmapEntityDef ent) { var clist = GetEntityChildren(ent); @@ -4195,6 +4223,9 @@ private void RecurseAddVisibleLeaves(YmapEntityDef ent) { if (EntityVisible(ent)) { + if (!RenderItems && ent.Ymap.HasChanged) + return; + VisibleLeaves.Add(ent); if (HDLightsEnabled && (ent.Lights != null))