Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions CodeWalker/Project/ProjectForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1393,6 +1393,7 @@ public void CloseProject()
CurrentYmapFile = ymap;
SaveYmap();
}
ymap.HasChanged = false;
}
}

Expand Down Expand Up @@ -1519,6 +1520,15 @@ public void CloseProject()

}

if (!renderitems)
{
renderitems = true;
}

if (hidegtavmap)
{
hidegtavmap = false;
}

if (WorldForm != null)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1996,7 +2010,7 @@ public void SaveYmap(bool saveas = false)
File.WriteAllBytes(filepath, data);
}

SetYmapHasChanged(false);
SetYmapHasChanged(true);

if (saveas)
{
Expand Down Expand Up @@ -2061,6 +2075,7 @@ public void RemoveYmapFromProject()
{
if (CurrentYmapFile == null) return;
if (CurrentProjectFile == null) return;
CurrentYmapFile.HasChanged = false;
CurrentProjectFile.RemoveYmapFile(CurrentYmapFile);
CurrentYmapFile = null;
LoadProjectTree();
Expand Down Expand Up @@ -7214,10 +7229,10 @@ public bool YtdExistsInProject(YtdFile ytd)

public void GetVisibleYmaps(Camera camera, Dictionary<MetaHash, YmapFile> ymaps)
{
if (hidegtavmap)
{
ymaps.Clear(); //remove all the gtav ymaps.
}
//if (hidegtavmap)
//{
// ymaps.Clear(); //remove all the gtav ymaps.
//}

lock (projectsyncroot)
{
Expand Down
67 changes: 49 additions & 18 deletions CodeWalker/Rendering/Renderer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CodeWalker.GameFiles;
using CodeWalker.Project;
using CodeWalker.Properties;
using CodeWalker.World;
using SharpDX;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -4061,10 +4064,10 @@ public void Update(Dictionary<MetaHash, YmapFile> 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];
Expand All @@ -4075,16 +4078,16 @@ public void Update(Dictionary<MetaHash, YmapFile> 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)
{
Expand Down Expand Up @@ -4136,18 +4139,33 @@ public void Update(Dictionary<MetaHash, YmapFile> 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)
Expand Down Expand Up @@ -4178,7 +4196,17 @@ public void Update(Dictionary<MetaHash, YmapFile> 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);
Expand All @@ -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))
Expand Down