Skip to content

Commit 73f7914

Browse files
author
Dolu
committed
fix(CodeWalker): render 'GTAV Map' and 'Project Items'
Another key feature of the method is the ability to isolate interiors that have a parent. Thanks to kirill-mapper: dexyfex#292
2 parents e7b49ad + 1a8bdb6 commit 73f7914

File tree

2 files changed

+72
-26
lines changed

2 files changed

+72
-26
lines changed

CodeWalker/Project/ProjectForm.cs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ public bool IsProjectLoaded
9292

9393

9494

95-
private bool renderitems = true;
96-
private bool hidegtavmap = false;
95+
public static bool renderitems = true;
96+
public static bool hidegtavmap = false;
9797
private bool autoymapflags = true;
9898
private bool autoymapextents = true;
9999
public bool displayentityindexes = false;
@@ -1393,6 +1393,7 @@ public void CloseProject()
13931393
CurrentYmapFile = ymap;
13941394
SaveYmap();
13951395
}
1396+
ymap.HasChanged = false;
13961397
}
13971398
}
13981399

@@ -1519,6 +1520,15 @@ public void CloseProject()
15191520

15201521
}
15211522

1523+
if (!renderitems)
1524+
{
1525+
renderitems = true;
1526+
}
1527+
1528+
if (hidegtavmap)
1529+
{
1530+
hidegtavmap = false;
1531+
}
15221532

15231533
if (WorldForm != null)
15241534
{
@@ -1614,7 +1624,11 @@ public void OpenFiles(string[] files = null)
16141624
{
16151625
case ".ymap":
16161626
var ymap = CurrentProjectFile.AddYmapFile(file);
1617-
if (ymap != null) LoadYmapFromFile(ymap, file);
1627+
if (ymap != null)
1628+
{
1629+
LoadYmapFromFile(ymap, file);
1630+
ymap.HasChanged = true;
1631+
}
16181632
break;
16191633
case ".ytyp":
16201634
var ytyp = CurrentProjectFile.AddYtypFile(file);
@@ -1996,7 +2010,7 @@ public void SaveYmap(bool saveas = false)
19962010
File.WriteAllBytes(filepath, data);
19972011
}
19982012

1999-
SetYmapHasChanged(false);
2013+
SetYmapHasChanged(true);
20002014

20012015
if (saveas)
20022016
{
@@ -2061,6 +2075,7 @@ public void RemoveYmapFromProject()
20612075
{
20622076
if (CurrentYmapFile == null) return;
20632077
if (CurrentProjectFile == null) return;
2078+
CurrentYmapFile.HasChanged = false;
20642079
CurrentProjectFile.RemoveYmapFile(CurrentYmapFile);
20652080
CurrentYmapFile = null;
20662081
LoadProjectTree();
@@ -7214,10 +7229,10 @@ public bool YtdExistsInProject(YtdFile ytd)
72147229

72157230
public void GetVisibleYmaps(Camera camera, Dictionary<MetaHash, YmapFile> ymaps)
72167231
{
7217-
if (hidegtavmap)
7218-
{
7219-
ymaps.Clear(); //remove all the gtav ymaps.
7220-
}
7232+
//if (hidegtavmap)
7233+
//{
7234+
// ymaps.Clear(); //remove all the gtav ymaps.
7235+
//}
72217236

72227237
lock (projectsyncroot)
72237238
{

CodeWalker/Rendering/Renderer.cs

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using CodeWalker.GameFiles;
2+
using CodeWalker.Project;
23
using CodeWalker.Properties;
34
using CodeWalker.World;
45
using SharpDX;
@@ -4023,6 +4024,8 @@ public class RenderLodManager
40234024
public bool ShowScriptedYmaps = true;
40244025
public bool HDLightsEnabled = true;
40254026
public bool LODLightsEnabled = true;
4027+
public bool RenderItems => ProjectForm.renderitems;
4028+
public bool HideGtavMap => ProjectForm.hidegtavmap;
40264029

40274030
public Camera Camera = null;
40284031
public Vector3 Position = Vector3.Zero;
@@ -4062,10 +4065,10 @@ public void Update(Dictionary<MetaHash, YmapFile> ymaps, Camera camera, float el
40624065
{
40634066
YmapFile ymap = null;
40644067
if (!ymaps.TryGetValue(kvp.Key, out ymap) || (ymap != kvp.Value) || (ymap.IsScripted && !ShowScriptedYmaps) || (ymap.LodManagerUpdate))
4065-
{
4066-
RemoveYmaps.Add(kvp.Key);
4068+
{
4069+
RemoveYmaps.Add(kvp.Key);
4070+
}
40674071
}
4068-
}
40694072
foreach (var remYmap in RemoveYmaps)
40704073
{
40714074
var ymap = CurrentYmaps[remYmap];
@@ -4076,16 +4079,16 @@ public void Update(Dictionary<MetaHash, YmapFile> ymaps, Camera camera, float el
40764079
for (int i = 0; i < remEnts.Length; i++)
40774080
{
40784081
var ent = remEnts[i];
4079-
RootEntities.Remove(ent);
4080-
ent.LodManagerChildren?.Clear();
4081-
ent.LodManagerChildren = null;
4082-
ent.LodManagerRenderable = null;
4083-
if ((ent.Parent != null) && (ent.Parent.Ymap != ymap))
4084-
{
4085-
ent.Parent.LodManagerRemoveChild(ent);
4082+
RootEntities.Remove(ent);
4083+
ent.LodManagerChildren?.Clear();
4084+
ent.LodManagerChildren = null;
4085+
ent.LodManagerRenderable = null;
4086+
if ((ent.Parent != null) && (ent.Parent.Ymap != ymap))
4087+
{
4088+
ent.Parent.LodManagerRemoveChild(ent);
4089+
}
40864090
}
40874091
}
4088-
}
40894092
var remLodLights = ymap.LODLights?.LodLights;
40904093
if (remLodLights != null)
40914094
{
@@ -4137,18 +4140,33 @@ public void Update(Dictionary<MetaHash, YmapFile> ymaps, Camera camera, float el
41374140

41384141
VisibleLeaves.Clear();
41394142
VisibleLights.Clear();
4140-
foreach (var kvp in RootEntities)
4143+
4144+
if (HideGtavMap)
41414145
{
4142-
var ent = kvp.Key;
4143-
if (EntityVisibleAtMaxLodLevel(ent))
4146+
foreach (var kvp in CurrentYmaps)
41444147
{
4145-
ent.Distance = MapViewEnabled ? MapViewDist : (ent.Position - Position).Length();
4146-
if (ent.Distance <= (ent.LodDist * LodDistMult))
4148+
var ymap = kvp.Value;
4149+
if (ymap.HasChanged && ymap.AllEntities != null)
41474150
{
4148-
RecurseAddVisibleLeaves(ent);
4151+
if (!RenderItems) continue;
4152+
foreach (var ent in ymap.AllEntities)
4153+
{
4154+
ProcessEntitiesForVisibility(ent);
4155+
}
41494156
}
41504157
}
41514158
}
4159+
else
4160+
{
4161+
foreach (var kvp in RootEntities)
4162+
{
4163+
var ent = kvp.Key;
4164+
if (ent.Ymap.HasChanged && !RenderItems)
4165+
continue;
4166+
4167+
ProcessEntitiesForVisibility(ent);
4168+
}
4169+
}
41524170

41534171
UpdateLodLights.Clear();
41544172
foreach (var light in VisibleLights)
@@ -4179,7 +4197,17 @@ public void Update(Dictionary<MetaHash, YmapFile> ymaps, Camera camera, float el
41794197
VisibleLights = VisibleLightsPrev;
41804198
VisibleLightsPrev = vl;
41814199
}
4182-
4200+
private void ProcessEntitiesForVisibility(YmapEntityDef ent)
4201+
{
4202+
if (EntityVisibleAtMaxLodLevel(ent))
4203+
{
4204+
ent.Distance = MapViewEnabled ? MapViewDist : (ent.Position - Position).Length();
4205+
if (ent.Distance <= (ent.LodDist * LodDistMult))
4206+
{
4207+
RecurseAddVisibleLeaves(ent);
4208+
}
4209+
}
4210+
}
41834211
private void RecurseAddVisibleLeaves(YmapEntityDef ent)
41844212
{
41854213
var clist = GetEntityChildren(ent);
@@ -4196,6 +4224,9 @@ private void RecurseAddVisibleLeaves(YmapEntityDef ent)
41964224
{
41974225
if (EntityVisible(ent))
41984226
{
4227+
if (!RenderItems && ent.Ymap.HasChanged)
4228+
return;
4229+
41994230
VisibleLeaves.Add(ent);
42004231

42014232
if (HDLightsEnabled && (ent.Lights != null))

0 commit comments

Comments
 (0)