scene loading fixes, still buggy
This commit is contained in:
@@ -67,7 +67,6 @@ namespace Game
|
|||||||
private float indirectLightMultiplier_ = 1.0f;
|
private float indirectLightMultiplier_ = 1.0f;
|
||||||
private List<MapEntity> lightEnts = new List<MapEntity>();
|
private List<MapEntity> lightEnts = new List<MapEntity>();
|
||||||
private Actor worldSpawnActor = null;
|
private Actor worldSpawnActor = null;
|
||||||
private bool staticBatching_ = false;
|
|
||||||
|
|
||||||
[Range(0.1f, 4f)]
|
[Range(0.1f, 4f)]
|
||||||
public float BrightnessMultiplier
|
public float BrightnessMultiplier
|
||||||
@@ -106,12 +105,12 @@ namespace Game
|
|||||||
|
|
||||||
public bool StaticBatching
|
public bool StaticBatching
|
||||||
{
|
{
|
||||||
get => staticBatching_;
|
get => staticBatching;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (staticBatching_ == value)
|
if (staticBatching == value)
|
||||||
return;
|
return;
|
||||||
staticBatching_ = value;
|
staticBatching = value;
|
||||||
dirtyLights = true;
|
dirtyLights = true;
|
||||||
dirtyMap = true;
|
dirtyMap = true;
|
||||||
}
|
}
|
||||||
@@ -255,6 +254,7 @@ namespace Game
|
|||||||
{
|
{
|
||||||
QuickHull(planePoints.ToArray(), out vertices);
|
QuickHull(planePoints.ToArray(), out vertices);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vertices = new Float3[0];
|
vertices = new Float3[0];
|
||||||
@@ -294,12 +294,25 @@ namespace Game
|
|||||||
Editor.Instance.PlayModeEnd += OnEditorPlayModeEnd;
|
Editor.Instance.PlayModeEnd += OnEditorPlayModeEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
private void OnSceneUnloading(Scene scene, Guid sceneId)
|
||||||
|
{
|
||||||
|
if (Editor.Instance == null)
|
||||||
|
return;
|
||||||
|
if (Editor.Instance.StateMachine.CurrentState is FlaxEditor.States.ChangingScenesState)
|
||||||
|
//if (!Editor.IsPlayMode)
|
||||||
|
UnloadMap();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
public override void OnDisable()
|
public override void OnDisable()
|
||||||
{
|
{
|
||||||
if (Editor.Instance == null)
|
if (Editor.Instance == null)
|
||||||
return;
|
return;
|
||||||
Editor.Instance.PlayModeBeginning -= OnEditorPlayModeStart;
|
Editor.Instance.PlayModeBeginning -= OnEditorPlayModeStart;
|
||||||
Editor.Instance.PlayModeEnd -= OnEditorPlayModeEnd;
|
Editor.Instance.PlayModeEnd -= OnEditorPlayModeEnd;
|
||||||
|
|
||||||
|
//UnloadMap();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
public override void OnStart()
|
public override void OnStart()
|
||||||
@@ -335,7 +348,7 @@ namespace Game
|
|||||||
lastSceneShadows = sceneShadows;
|
lastSceneShadows = sceneShadows;
|
||||||
dirtyLights = true;
|
dirtyLights = true;
|
||||||
}
|
}
|
||||||
staticBatching = EngineSubsystem.StaticBatch == "1";
|
var staticBatching = EngineSubsystem.StaticBatch == "1";
|
||||||
if (lastStaticBatching != staticBatching)
|
if (lastStaticBatching != staticBatching)
|
||||||
{
|
{
|
||||||
lastStaticBatching = staticBatching;
|
lastStaticBatching = staticBatching;
|
||||||
@@ -408,10 +421,44 @@ namespace Game
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UnloadMap()
|
||||||
|
{
|
||||||
|
IEnumerable<Actor> GetChildrenRecursive(Actor actor)
|
||||||
|
{
|
||||||
|
foreach (var act in actor.GetChildren<Actor>())
|
||||||
|
{
|
||||||
|
yield return act;
|
||||||
|
|
||||||
|
foreach (var child in GetChildrenRecursive(act))
|
||||||
|
yield return child;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var virtualAssets = new List<BinaryAsset>();
|
||||||
|
var allActors = GetChildrenRecursive(worldSpawnActor).ToList();
|
||||||
|
virtualAssets.AddRange(allActors.OfType<StaticModel>().Where(x => x.Model != null && x.Model.IsVirtual).Select(x => x.Model));
|
||||||
|
virtualAssets.AddRange(allActors.OfType<MeshCollider>().Where(x => x.CollisionData != null && x.CollisionData.IsVirtual).Select(x => x.CollisionData));
|
||||||
|
|
||||||
|
foreach (var asset in virtualAssets)
|
||||||
|
Content.UnloadAsset(asset);
|
||||||
|
|
||||||
|
worldSpawnActor.DestroyChildren();
|
||||||
|
FlaxEngine.Object.Destroy(worldSpawnActor);
|
||||||
|
worldSpawnActor = null;
|
||||||
|
resetLights = false;
|
||||||
|
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
Level.SceneUnloading -= OnSceneUnloading;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
private void LoadMap(bool forceLoad)
|
private void LoadMap(bool forceLoad)
|
||||||
{
|
{
|
||||||
Stopwatch sw = Stopwatch.StartNew();
|
Stopwatch sw = Stopwatch.StartNew();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
string mapPath_ = mapPath;
|
string mapPath_ = mapPath;
|
||||||
if (!File.Exists(mapPath_))
|
if (!File.Exists(mapPath_))
|
||||||
mapPath_ = Path.Combine(Directory.GetCurrentDirectory(), mapPath);
|
mapPath_ = Path.Combine(Directory.GetCurrentDirectory(), mapPath);
|
||||||
@@ -423,6 +470,8 @@ namespace Game
|
|||||||
sw.Stop();
|
sw.Stop();
|
||||||
//Console.Print("Map parsing time: " + sw.Elapsed.TotalMilliseconds + "ms");
|
//Console.Print("Map parsing time: " + sw.Elapsed.TotalMilliseconds + "ms");
|
||||||
|
|
||||||
|
dirtyMap = false;
|
||||||
|
|
||||||
worldSpawnActor = Actor.FindActor("WorldSpawn");
|
worldSpawnActor = Actor.FindActor("WorldSpawn");
|
||||||
if (worldSpawnActor != null)
|
if (worldSpawnActor != null)
|
||||||
{
|
{
|
||||||
@@ -430,9 +479,12 @@ namespace Game
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
FlaxEngine.Debug.Log($"Map dirty, reloading.");
|
FlaxEngine.Debug.Log($"Map dirty, reloading.");
|
||||||
worldSpawnActor.DestroyChildren();
|
UnloadMap();
|
||||||
resetLights = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if FLAX_EDITOR
|
||||||
|
Level.SceneUnloading += OnSceneUnloading;
|
||||||
|
#endif
|
||||||
//else
|
//else
|
||||||
// FlaxEngine.Debug.Log("No WorldSpawn, loading map");
|
// FlaxEngine.Debug.Log("No WorldSpawn, loading map");
|
||||||
|
|
||||||
@@ -787,22 +839,23 @@ namespace Game
|
|||||||
|
|
||||||
bool isClipMaterial = false;
|
bool isClipMaterial = false;
|
||||||
bool isMissingMaterial = false;
|
bool isMissingMaterial = false;
|
||||||
/*if (geom.meshes.Length == 1)
|
if (geom.meshes.Length == 1 && childModelSdf)
|
||||||
{
|
{
|
||||||
MaterialParameter info = geom.meshes[0].material.GetParameter("IsClipMaterial");
|
MaterialParameter info = geom.meshes[0].material.GetParameter("IsClipMaterial");
|
||||||
if (info != null && (bool)info.Value)
|
if (info != null && (bool)info.Value)
|
||||||
{
|
{
|
||||||
var entries = childModel.Entries;
|
var staticModel = childModel as StaticModel;
|
||||||
|
var entries = staticModel.Entries;
|
||||||
entries[0].Visible = false;
|
entries[0].Visible = false;
|
||||||
entries[0].ShadowsMode = ShadowsCastingMode.None;
|
entries[0].ShadowsMode = ShadowsCastingMode.None;
|
||||||
entries[0].ReceiveDecals = false;
|
entries[0].ReceiveDecals = false;
|
||||||
childModel.Entries = entries;
|
staticModel.Entries = entries;
|
||||||
isClipMaterial = true;
|
isClipMaterial = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (geom.meshes[0].material == missingMaterial)
|
if (geom.meshes[0].material == missingMaterial)
|
||||||
isMissingMaterial = true;
|
isMissingMaterial = true;
|
||||||
}*/
|
}
|
||||||
|
|
||||||
/*{
|
/*{
|
||||||
var entries = childModel.Entries;
|
var entries = childModel.Entries;
|
||||||
@@ -893,7 +946,7 @@ namespace Game
|
|||||||
uint indicesOffset = 0;
|
uint indicesOffset = 0;
|
||||||
foreach (BrushGeometry geom in kvp.Value)
|
foreach (BrushGeometry geom in kvp.Value)
|
||||||
{
|
{
|
||||||
for (int i=0; i<geom.meshes[0].vertices.Count; i++)
|
for (int i = 0; i < geom.meshes[0].vertices.Count; i++)
|
||||||
{
|
{
|
||||||
var v = geom.meshes[0].vertices[i];
|
var v = geom.meshes[0].vertices[i];
|
||||||
var n = geom.meshes[0].normals[i];
|
var n = geom.meshes[0].normals[i];
|
||||||
@@ -930,6 +983,7 @@ namespace Game
|
|||||||
sw.Stop();
|
sw.Stop();
|
||||||
//Console.Print("Pass 3: collision: " + sw.Elapsed.TotalMilliseconds + "ms");
|
//Console.Print("Pass 3: collision: " + sw.Elapsed.TotalMilliseconds + "ms");
|
||||||
}
|
}
|
||||||
|
#if false
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var vertices = new List<Float3>();
|
var vertices = new List<Float3>();
|
||||||
@@ -1083,6 +1137,7 @@ namespace Game
|
|||||||
sw.Stop();
|
sw.Stop();
|
||||||
Console.Print("Pass 2: model and collision: " + sw.Elapsed.TotalMilliseconds + "ms");
|
Console.Print("Pass 2: model and collision: " + sw.Elapsed.TotalMilliseconds + "ms");
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Handle entities
|
// Handle entities
|
||||||
|
|
||||||
@@ -1107,7 +1162,6 @@ namespace Game
|
|||||||
//Console.Print("entity parsing time: " + sw.Elapsed.TotalMilliseconds + "ms");
|
//Console.Print("entity parsing time: " + sw.Elapsed.TotalMilliseconds + "ms");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*for (int i=0; i<10000; i++)
|
/*for (int i=0; i<10000; i++)
|
||||||
{
|
{
|
||||||
Debug.Log($"{i} udfghjosa fuhoag guiha7 2382835yayhahn0 generate:{generateSdf}, GI:{Graphics.PostProcessSettings.GlobalIllumination.Mode != GlobalIlluminationMode.None}, {sdfModels.Count}");
|
Debug.Log($"{i} udfghjosa fuhoag guiha7 2382835yayhahn0 generate:{generateSdf}, GI:{Graphics.PostProcessSettings.GlobalIllumination.Mode != GlobalIlluminationMode.None}, {sdfModels.Count}");
|
||||||
|
|||||||
Reference in New Issue
Block a user