scene loading fixes, still buggy
This commit is contained in:
@@ -67,7 +67,6 @@ namespace Game
|
||||
private float indirectLightMultiplier_ = 1.0f;
|
||||
private List<MapEntity> lightEnts = new List<MapEntity>();
|
||||
private Actor worldSpawnActor = null;
|
||||
private bool staticBatching_ = false;
|
||||
|
||||
[Range(0.1f, 4f)]
|
||||
public float BrightnessMultiplier
|
||||
@@ -106,12 +105,12 @@ namespace Game
|
||||
|
||||
public bool StaticBatching
|
||||
{
|
||||
get => staticBatching_;
|
||||
get => staticBatching;
|
||||
set
|
||||
{
|
||||
if (staticBatching_ == value)
|
||||
if (staticBatching == value)
|
||||
return;
|
||||
staticBatching_ = value;
|
||||
staticBatching = value;
|
||||
dirtyLights = true;
|
||||
dirtyMap = true;
|
||||
}
|
||||
@@ -255,6 +254,7 @@ namespace Game
|
||||
{
|
||||
QuickHull(planePoints.ToArray(), out vertices);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
vertices = new Float3[0];
|
||||
@@ -294,12 +294,25 @@ namespace Game
|
||||
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()
|
||||
{
|
||||
if (Editor.Instance == null)
|
||||
return;
|
||||
Editor.Instance.PlayModeBeginning -= OnEditorPlayModeStart;
|
||||
Editor.Instance.PlayModeEnd -= OnEditorPlayModeEnd;
|
||||
|
||||
//UnloadMap();
|
||||
}
|
||||
#endif
|
||||
public override void OnStart()
|
||||
@@ -335,7 +348,7 @@ namespace Game
|
||||
lastSceneShadows = sceneShadows;
|
||||
dirtyLights = true;
|
||||
}
|
||||
staticBatching = EngineSubsystem.StaticBatch == "1";
|
||||
var staticBatching = EngineSubsystem.StaticBatch == "1";
|
||||
if (lastStaticBatching != staticBatching)
|
||||
{
|
||||
lastStaticBatching = staticBatching;
|
||||
@@ -408,10 +421,44 @@ namespace Game
|
||||
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)
|
||||
{
|
||||
Stopwatch sw = Stopwatch.StartNew();
|
||||
|
||||
|
||||
|
||||
|
||||
string mapPath_ = mapPath;
|
||||
if (!File.Exists(mapPath_))
|
||||
mapPath_ = Path.Combine(Directory.GetCurrentDirectory(), mapPath);
|
||||
@@ -423,6 +470,8 @@ namespace Game
|
||||
sw.Stop();
|
||||
//Console.Print("Map parsing time: " + sw.Elapsed.TotalMilliseconds + "ms");
|
||||
|
||||
dirtyMap = false;
|
||||
|
||||
worldSpawnActor = Actor.FindActor("WorldSpawn");
|
||||
if (worldSpawnActor != null)
|
||||
{
|
||||
@@ -430,9 +479,12 @@ namespace Game
|
||||
return;
|
||||
|
||||
FlaxEngine.Debug.Log($"Map dirty, reloading.");
|
||||
worldSpawnActor.DestroyChildren();
|
||||
resetLights = false;
|
||||
UnloadMap();
|
||||
}
|
||||
|
||||
#if FLAX_EDITOR
|
||||
Level.SceneUnloading += OnSceneUnloading;
|
||||
#endif
|
||||
//else
|
||||
// FlaxEngine.Debug.Log("No WorldSpawn, loading map");
|
||||
|
||||
@@ -787,22 +839,23 @@ namespace Game
|
||||
|
||||
bool isClipMaterial = false;
|
||||
bool isMissingMaterial = false;
|
||||
/*if (geom.meshes.Length == 1)
|
||||
if (geom.meshes.Length == 1 && childModelSdf)
|
||||
{
|
||||
MaterialParameter info = geom.meshes[0].material.GetParameter("IsClipMaterial");
|
||||
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].ShadowsMode = ShadowsCastingMode.None;
|
||||
entries[0].ReceiveDecals = false;
|
||||
childModel.Entries = entries;
|
||||
staticModel.Entries = entries;
|
||||
isClipMaterial = true;
|
||||
}
|
||||
|
||||
if (geom.meshes[0].material == missingMaterial)
|
||||
isMissingMaterial = true;
|
||||
}*/
|
||||
}
|
||||
|
||||
/*{
|
||||
var entries = childModel.Entries;
|
||||
@@ -893,7 +946,7 @@ namespace Game
|
||||
uint indicesOffset = 0;
|
||||
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 n = geom.meshes[0].normals[i];
|
||||
@@ -930,6 +983,7 @@ namespace Game
|
||||
sw.Stop();
|
||||
//Console.Print("Pass 3: collision: " + sw.Elapsed.TotalMilliseconds + "ms");
|
||||
}
|
||||
#if false
|
||||
else
|
||||
{
|
||||
var vertices = new List<Float3>();
|
||||
@@ -1083,6 +1137,7 @@ namespace Game
|
||||
sw.Stop();
|
||||
Console.Print("Pass 2: model and collision: " + sw.Elapsed.TotalMilliseconds + "ms");
|
||||
}
|
||||
#endif
|
||||
|
||||
// Handle entities
|
||||
|
||||
@@ -1107,7 +1162,6 @@ namespace Game
|
||||
//Console.Print("entity parsing time: " + sw.Elapsed.TotalMilliseconds + "ms");
|
||||
}
|
||||
|
||||
|
||||
/*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}");
|
||||
|
||||
Reference in New Issue
Block a user