Skip to content
This repository has been archived by the owner on Sep 30, 2019. It is now read-only.

Commit

Permalink
Fixed notes not getting despawned properly when changing timeline, ca…
Browse files Browse the repository at this point in the history
…using double notes. Cleaned up debug logs.
  • Loading branch information
xyonico committed Aug 22, 2018
1 parent 42f4a7a commit d453eb2
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 69 deletions.
10 changes: 1 addition & 9 deletions PracticePlugin/CustomEffectPoolsInstaller.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
using System;

namespace PracticePlugin
namespace PracticePlugin
{
public class CustomEffectPoolsInstaller : EffectPoolsInstaller
{
private void Awake()
{
Console.WriteLine("Custom Awake!");
}

public override void InstallBindings()
{
Console.WriteLine("Custom install bindings!");
Container.BindMemoryPool<FlyingTextEffect, FlyingTextEffect.Pool>().WithInitialSize(20).FromComponentInNewPrefab(_flyingTextEffectPrefab);
Container.BindMemoryPool<FlyingScoreTextEffect, FlyingScoreTextEffect.Pool>().WithInitialSize(20)
.FromComponentInNewPrefab(_flyingScoreTextEffectPrefab);
Expand Down
1 change: 0 additions & 1 deletion PracticePlugin/CustomNoteCutSoundEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public override void LateUpdate()
public override void Init(AudioClip audioClip, double noteDSPTime, float aheadTime, float missedTimeOffset,
Saber saber, NoteData noteData, bool handleWrongSaberTypeAsGood)
{
Console.WriteLine("Custom Init!");
base.Init(audioClip, noteDSPTime, aheadTime, missedTimeOffset, saber, noteData, handleWrongSaberTypeAsGood);
_audioSource.Stop();
var dspTime = AudioSettings.dspTime;
Expand Down
50 changes: 2 additions & 48 deletions PracticePlugin/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public string Name

public string Version
{
get { return "v3.0.1"; }
get { return "v3.0.2"; }
}

public const float MaxSize = 5.05f;
Expand Down Expand Up @@ -85,45 +85,7 @@ public void OnApplicationStart()
_init = true;
SceneManager.sceneLoaded += SceneManagerOnSceneLoaded;
}

private void SceneManagerOnActiveSceneChanged(Scene oldScene, Scene newScene)
{
Console.WriteLine("Active scene changed: " + newScene.name);
for (var i = 0; i < SceneManager.sceneCount; i++)
{
var scene = SceneManager.GetSceneAt(i);
Console.WriteLine("Scene loaded!!: " + scene.name);
}

var gameScene = new Scene();
if (!gameScene.isLoaded) return;

Console.WriteLine("It's loaded!");

var effectPoolsInstaller = Resources.FindObjectsOfTypeAll<EffectPoolsInstaller>().FirstOrDefault();
if (effectPoolsInstaller != null)
{
ReflectionUtil.CopyComponent(effectPoolsInstaller, typeof(EffectPoolsInstaller), typeof(CustomEffectPoolsInstaller),
effectPoolsInstaller.gameObject);
Object.DestroyImmediate(effectPoolsInstaller);

Console.WriteLine("Trying to find scene context");
SceneContext sceneContext = null;
foreach (var gameObject in gameScene.GetRootGameObjects())
{
sceneContext = gameObject.GetComponentInChildren<SceneContext>();
if (sceneContext != null)
{
break;
}
}

if (sceneContext == null) return;
Console.WriteLine("Found it");
sceneContext.enabled = false;
}
}


public void OnApplicationQuit()
{
SceneManager.sceneLoaded -= SceneManagerOnSceneLoaded;
Expand Down Expand Up @@ -189,25 +151,17 @@ private void SceneManagerOnSceneLoaded(Scene scene, LoadSceneMode mode)
if (sceneDecoratorContext == null)
{
sceneDecoratorContext = gameObject.GetComponentInChildren<SceneDecoratorContext>(true);

if (sceneDecoratorContext != null)
{
Console.WriteLine("Found one in " + gameObject.name);
}
}
}


if (sceneContext != null && sceneDecoratorContext != null)
{
Console.WriteLine("We're live!");
var prop = typeof(Context).GetField("_installers", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
var installersList = (List<MonoInstaller>) prop.GetValue(sceneDecoratorContext);
Console.WriteLine("There are " + installersList.Count + " installers!");
installersList.Remove(effectPoolsInstaller);
Object.DestroyImmediate(effectPoolsInstaller);
installersList.Add(customEffectPoolsInstaller);
Console.WriteLine("Done!");
}

if (_mainGameSceneSetupData == null)
Expand Down
4 changes: 2 additions & 2 deletions PracticePlugin/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.0.1.0")]
[assembly: AssemblyFileVersion("3.0.1.0")]
[assembly: AssemblyVersion("3.0.2.0")]
[assembly: AssemblyFileVersion("3.0.2.0")]
41 changes: 32 additions & 9 deletions PracticePlugin/SongSeekBeatmapHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,9 @@ public static void OnSongTimeChanged(float newSongTime, float aheadTime)
for (var i = 0; i < _beatmapData.beatmapLinesData.Length; i++)
{
callbackData.nextObjectIndexInLine[i] = 0;
while (callbackData.nextObjectIndexInLine[i] <
_beatmapData.beatmapLinesData[i].beatmapObjectsData.Length)
while (callbackData.nextObjectIndexInLine[i] < _beatmapData.beatmapLinesData[i].beatmapObjectsData.Length)
{
var beatmapObjectData = _beatmapData.beatmapLinesData[i]
.beatmapObjectsData[callbackData.nextObjectIndexInLine[i]];
var beatmapObjectData = _beatmapData.beatmapLinesData[i].beatmapObjectsData[callbackData.nextObjectIndexInLine[i]];
if (beatmapObjectData.time - aheadTime >= newSongTime)
{
break;
Expand All @@ -102,11 +100,36 @@ public static void OnSongTimeChanged(float newSongTime, float aheadTime)
}

_beatmapObjectCallbackController.SetPrivateField("_nextEventIndex", newNextEventIndex);

_noteAPool.DespawnAll();
_bombNotePool.DespawnAll();
_fullHeightObstaclePool.DespawnAll();
_topObstaclePool.DespawnAll();

var notesA = _noteAPool.activeItems.ToList();
foreach (var noteA in notesA)
{
_beatmapObjectSpawnController.Despawn(noteA);
}

var notesB = _noteBPool.activeItems.ToList();
foreach (var noteB in notesB)
{
_beatmapObjectSpawnController.Despawn(noteB);
}

var bombs = _bombNotePool.activeItems.ToList();
foreach (var bomb in bombs)
{
_beatmapObjectSpawnController.Despawn(bomb);
}

var fullHeights = _fullHeightObstaclePool.activeItems.ToList();
foreach (var fullHeight in fullHeights)
{
_beatmapObjectSpawnController.Despawn(fullHeight);
}

var tops = _topObstaclePool.activeItems.ToList();
foreach (var top in tops)
{
_beatmapObjectSpawnController.Despawn(top);
}

Plugin.AudioTimeSync.SetPrivateField("_prevAudioSamplePos", -1);
Plugin.AudioTimeSync.GetPrivateField<FloatSO>("_songTime").value = newSongTime;
Expand Down

0 comments on commit d453eb2

Please sign in to comment.