Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
Fixes:
* ProcessorTimer works correctly after changing scene
* ProcessorScene  works correctly when no multiscene feature used

Changes:
DataGameSession removed. If you used this stuff make sure to handle it yourself
DataGameSettings removed. If you used this stuff make sure to handle it yourself

You don't need to have scene kernel anymore to run framework
  • Loading branch information
Pixeye committed Jun 24, 2019
1 parent 94875dc commit ef1b0b2
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 38 deletions.
Binary file modified Install/0 Project Template.unitypackage
Binary file not shown.
65 changes: 47 additions & 18 deletions Runtime/LibProcessors/ProcessorScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public void Setup(List<SceneReference> scenesToKeep, List<SceneReference> sceneD
this.scenesToKeep.Clear();
this.sceneDependsOn.Clear();


for (var i = 0; i < scenesToKeep.Count; i++)
{
this.scenesToKeep.Add(scenesToKeep[i].Path);
Expand Down Expand Up @@ -103,6 +104,11 @@ IEnumerator _Setup(Starter starter)
scenes.Add(name, SceneManager.GetSceneByName(name));
}

if (sceneDependsOn.Count == 0)
{
yield return 0;
}

sceneLoaded();

starter.BindScene();
Expand All @@ -114,6 +120,15 @@ IEnumerator _Load(string name)
Toolbox.changingScene = true;
Toolbox.Instance.ClearSessionData();

if (scenes.Keys.Count == 1)
{
scenes.Clear();
SceneManager.LoadScene(name);
SceneManager.SetActiveScene(SceneManager.GetSceneByName(name));
Toolbox.changingScene = false;
yield break;
}

var s = SceneManager.GetActiveScene();
var sName = s.name;

Expand Down Expand Up @@ -162,34 +177,48 @@ IEnumerator _Load(int id)
Toolbox.changingScene = true;
Toolbox.Instance.ClearSessionData();

var s = SceneManager.GetActiveScene();
var sName = s.name;

var job = SceneManager.UnloadSceneAsync(s);

while (!job.isDone)
if (scenes.Keys.Count == 1)
{
yield return 0;
scenes.Clear();
SceneManager.LoadScene(id);
SceneManager.SetActiveScene(SceneManager.GetSceneByBuildIndex(id));
Toolbox.changingScene = false;
yield break;
}

scenes.Remove(sName);
foreach (var key in scenes.Keys)
{
if (scenesToKeep.Contains(key)) continue;
var s = SceneManager.GetActiveScene();
var sName = s.name;

job = SceneManager.UnloadSceneAsync(scenes[key]);
var job = SceneManager.UnloadSceneAsync(s);

while (!job.isDone)
{
yield return 0;
}
}

job = Resources.UnloadUnusedAssets();
while (!job.isDone)
{
yield return 0;
}
scenes.Remove(sName);

if (scenes.Keys.Count != 1)
{
foreach (var key in scenes.Keys)
{
if (scenesToKeep.Contains(key)) continue;

job = SceneManager.UnloadSceneAsync(scenes[key]);

while (!job.isDone)
{
yield return 0;
}
}

job = Resources.UnloadUnusedAssets();
while (!job.isDone)
{
yield return 0;
}
}


scenes.Clear();

Expand Down
6 changes: 3 additions & 3 deletions Runtime/LibProcessors/ProcessorTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
using System.Runtime.CompilerServices;
using Pixeye.Framework;
using Unity.IL2CPP.CompilerServices;

namespace Pixeye.Source
{
[Il2CppSetOption(Option.NullChecks | Option.ArrayBoundsChecks | Option.DivideByZeroChecks, false)]
sealed class ProcessorTimer : Processor, ITick, IKernel
sealed class ProcessorTimer : ITick, IKernel
{

internal static ProcessorTimer Default = new ProcessorTimer();
Expand Down Expand Up @@ -79,7 +79,7 @@ internal int Restart(float t, Action action)
return index;
}

protected override void OnDispose()
public void Dispose()
{
for (int i = 0; i < length; i++)
{
Expand Down
2 changes: 1 addition & 1 deletion Runtime/LibProcessors/ProcessorUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void Dispose()
countTicksLate = 0;

ticks.RemoveAll(t => t is IKernel == false);

ticksFixed.Clear();
ticksLate.Clear();

Expand Down
8 changes: 5 additions & 3 deletions Runtime/LibSingleton/Toolbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,19 @@ internal void ClearSessionData()
foreach (var pair in data)
{
var isKernel = pair.Value as IKernel;
if (isKernel == null) toWipe.Add(pair.Key);
if (isKernel == null)
toWipe.Add(pair.Key);


var needToBeCleaned = pair.Value as IDisposable;
if (needToBeCleaned == null) continue;

needToBeCleaned.Dispose();
}

HandlePool.Dispose();
ProcessorGroups.Dispose();
ProcessorTimer.Default.Dispose();
ProcessorTimer.Default.Dispose();
ProcessorScene.Default.Dispose();
ProcessorUpdate.Default.Dispose();
Box.Default.Dispose();
Expand Down
26 changes: 13 additions & 13 deletions Runtime/LibStarter/StarterKernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ namespace Pixeye.Framework
public class StarterKernel : MonoBehaviour
{

[FoldoutGroup("SetupData")]
public DataSession gameSession;

[FoldoutGroup("SetupData")]
public DataSession gameSettings;
// [FoldoutGroup("SetupData")]
// public DataSession gameSession;
//
// [FoldoutGroup("SetupData")]
// public DataSession gameSettings;

[FoldoutGroup("SetupData")]
public List<Pluggable> pluggables = new List<Pluggable>();
Expand All @@ -34,14 +34,14 @@ void Awake()
pluggables[i].Plug();
}

if (gameSession != null)
{
Toolbox.Add(gameSession);
}
if (gameSettings != null)
{
Toolbox.Add(gameSettings);
}
// if (gameSession != null)
// {
// Toolbox.Add(gameSession);
// }
// if (gameSettings != null)
// {
// Toolbox.Add(gameSettings);
// }
}

IEnumerator OnApplicationFocus(bool hasFocus)
Expand Down

0 comments on commit ef1b0b2

Please sign in to comment.