Skip to content

Commit

Permalink
Cleaned, did SMVD changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
krypto5863 committed Aug 4, 2022
1 parent 0562bfe commit c3b87d7
Show file tree
Hide file tree
Showing 17 changed files with 105 additions and 164 deletions.
4 changes: 1 addition & 3 deletions Experiment5ParallelMenuLoading/0OldClasses/ControlClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ static IEnumerable<CodeInstruction> Transpiler1(IEnumerable<CodeInstruction> ins
new CodeInstruction(OpCodes.Ldarg_0),
Transpilers.EmitDelegate<Action>(() =>
{
Main.logger.LogDebug("Calling your control test coroutine.");
@this2.StartCoroutine(InitMenuNative());
}),
new CodeInstruction(OpCodes.Pop)
)
Expand Down Expand Up @@ -193,4 +191,4 @@ private static IEnumerator InitMenuNative()
yield break;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ namespace Experiment5ParallelMenuLoading
[BepInPlugin("Experiment5ParallelMenuLoading", "Experiment5ParallelMenuLoading", "1.0.0.0")]
public class Main : BaseUnityPlugin
{

public static Harmony harmony;
public static SceneEdit @this;
public static Main @this2;
Expand Down Expand Up @@ -84,14 +83,12 @@ static IEnumerable<CodeInstruction> Transpiler1(IEnumerable<CodeInstruction> ins
new CodeInstruction(OpCodes.Ldarg_0),
Transpilers.EmitDelegate<Action>(() =>
{
Main.logger.LogInfo("Calling your test coroutine.");
//InitMenuNativeRe();
@this2.StartCoroutine(LoadIcons());
@this2.StartCoroutine(test2());
//test2();
}),
new CodeInstruction(OpCodes.Pop)
)
Expand All @@ -102,7 +99,6 @@ static IEnumerable<CodeInstruction> Transpiler1(IEnumerable<CodeInstruction> ins
}
public static IEnumerator test2()
{

Stopwatch test = new Stopwatch();

Main.logger.LogError("Coroutine was successfully engaged!");
Expand Down Expand Up @@ -221,7 +217,7 @@ public static IEnumerator test2()

SetupDone = true;

while (IconLoadDone != true)
while (IconLoadDone != true)
{
yield return null;
}
Expand Down Expand Up @@ -319,8 +315,6 @@ public static bool GetMenuItemSetUP(SceneEdit.SMenuItem mi, string f_strMenuFile
{
NDebug.Assert(false, "メニュースクリプトが読めませんでした。" + f_strMenuFileName);
}


}
catch (Exception ex)
{
Expand All @@ -338,7 +332,6 @@ public static bool GetMenuItemSetUP(SceneEdit.SMenuItem mi, string f_strMenuFile
return true;
}


public static bool InitMenuItemScript(SceneEdit.SMenuItem mi, string f_strMenuFileName, bool f_bMan, out string IconTex)
{
var fetchedField = AccessTools.DeclaredField(typeof(SceneEdit), "m_byItemFileBuffer");
Expand Down Expand Up @@ -565,21 +558,19 @@ public static bool InitMenuItemScript(SceneEdit.SMenuItem mi, string f_strMenuFi

public static IEnumerator LoadIcons()
{
while (SetupDone == false || ListOfIconLoads.Count > 1)
while (SetupDone == false || ListOfIconLoads.Count > 1)
{
if (ListOfIconLoads.Count == 0)
{
yield return null;
}
else
{

Main.logger.LogError("Icon Coroutine is loading an icon...");

ListOfIconLoads.Keys.ElementAt(0).m_texIcon = ImportCM.CreateTexture(ListOfIconLoads[ListOfIconLoads.Keys.ElementAt(0)]);
ListOfContinues.Enqueue(ListOfIconLoads.Keys.ElementAt(0));
ListOfIconLoads.TryRemove(ListOfIconLoads.Keys.ElementAt(0), out _);

}
}

Expand All @@ -593,11 +584,11 @@ public static IEnumerator ThrowConcurrentException(string error)
yield return null;
}
/*
public static IEnumerator LoadTexture(SceneEdit.SMenuItem menu, string texture)
public static IEnumerator LoadTexture(SceneEdit.SMenuItem menu, string texture)
{
menu.m_texIcon = ImportCM.CreateTexture(texture);
yield return null;
}*/
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ namespace Experiment5ParallelMenuLoading
[BepInPlugin("Experiment5ParallelMenuLoading", "Experiment5ParallelMenuLoading", "1.0.0.0")]
public class Main : BaseUnityPlugin
{

public static Harmony harmony;
public static SceneEdit @this;
public static Main @this2;
Expand All @@ -30,7 +29,6 @@ public class Main : BaseUnityPlugin
private static bool SetupDone = false;
private static bool IconLoadDone = false;


/*
static Dictionary<int, SceneEdit.SMenuItem> menuRidDicThreadSafe;
static Dictionary<int, HashSet<int>> menuGroupMemberDic;
Expand Down Expand Up @@ -92,7 +90,6 @@ static IEnumerable<CodeInstruction> Transpiler1(IEnumerable<CodeInstruction> ins
new CodeInstruction(OpCodes.Ldarg_0),
Transpilers.EmitDelegate<Action>(() =>
{
Main.logger.LogInfo("Calling your test coroutine.");
//InitMenuNativeRe();
Expand All @@ -101,7 +98,6 @@ static IEnumerable<CodeInstruction> Transpiler1(IEnumerable<CodeInstruction> ins
@this2.StartCoroutine(InitialBackgroundWorker());
//@this2.StartCoroutine(MenuLoaderWorker());
//test2();
}),
new CodeInstruction(OpCodes.Pop)
)
Expand All @@ -112,7 +108,6 @@ static IEnumerable<CodeInstruction> Transpiler1(IEnumerable<CodeInstruction> ins
}
public static IEnumerator InitialBackgroundWorker()
{

Main.logger.LogError("Coroutine was successfully engaged!");

while (GameMain.Instance.CharacterMgr.IsBusy())
Expand Down Expand Up @@ -232,7 +227,7 @@ public static IEnumerator InitialBackgroundWorker()
{
var keyPair = ListOfIconLoads.FirstOrDefault();

if (keyPair.Key == null || keyPair.Value == null)
if (keyPair.Key == null || keyPair.Value == null)
{
ListOfIconLoads.Remove(keyPair.Key);
continue;
Expand Down Expand Up @@ -263,10 +258,9 @@ public static IEnumerator InitialBackgroundWorker()
//foreach (SceneEdit.SMenuItem mi2 in ListOfContinues)
while (ListOfContinues.Count > 0)
{

var mi2 = ListOfContinues.FirstOrDefault();

if (mi2 == null)
if (mi2 == null)
{
continue;
}
Expand Down Expand Up @@ -340,7 +334,6 @@ public static IEnumerator InitialBackgroundWorker()
test.Reset();

yield break;

}/*
public static IEnumerator MenuLoaderWorker()
{
Expand Down Expand Up @@ -606,4 +599,4 @@ public static bool InitMenuItemScript(SceneEdit.SMenuItem mi, string f_strMenuFi
return true;
}
}
}
}
28 changes: 8 additions & 20 deletions Experiment5ParallelMenuLoading/0OldClasses/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ namespace Experiment5ParallelMenuLoading
[BepInPlugin("Experiment5ParallelMenuLoading", "Experiment5ParallelMenuLoading", "1.0.0.0")]
public class Main : BaseUnityPlugin
{

public static Harmony harmony;
public static SceneEdit @this;
public static Main @this2;
Expand Down Expand Up @@ -85,7 +84,6 @@ static IEnumerable<CodeInstruction> Transpiler1(IEnumerable<CodeInstruction> ins
new CodeInstruction(OpCodes.Ldarg_0),
Transpilers.EmitDelegate<Action>(() =>
{
Main.logger.LogInfo("Calling your test coroutine.");
ListOfContinues = new Dictionary<SceneEdit.SMenuItem, string>();
Expand All @@ -98,7 +96,6 @@ static IEnumerable<CodeInstruction> Transpiler1(IEnumerable<CodeInstruction> ins
@this.StartCoroutine(SetupTexturesCoRoutine());
Task.Factory.StartNew(new Action(() => test2()));
//Task.Factory.StartNew(new Action(() => Test2Continuation()));
}),
new CodeInstruction(OpCodes.Pop)
)
Expand All @@ -109,7 +106,6 @@ static IEnumerable<CodeInstruction> Transpiler1(IEnumerable<CodeInstruction> ins
}
public static void test2()
{

Main.logger.LogError("Coroutine was successfully engaged!");

while (GameMain.Instance.CharacterMgr.IsBusy())
Expand Down Expand Up @@ -216,8 +212,6 @@ public static void test2()
Main.logger.LogError("Finished GetMenuItemSetUP: " + test2.Elapsed);
}//);



//@this2.StartCoroutine(SetupTexturesCoRoutine(menuList, menuGroupMemberDic));

SavedmenuList = menuList;
Expand All @@ -227,10 +221,9 @@ public static void test2()

public static IEnumerator SetupTexturesCoRoutine()
{

Main.logger.LogError($"Starting coroutine to set textures to menu items.");

while (Test2Done != true)
while (Test2Done != true)
{
yield return null;
}
Expand All @@ -248,7 +241,7 @@ public static IEnumerator SetupTexturesCoRoutine()

Test2Continuation();

while (Test2ContinuatonDone == false)
while (Test2ContinuatonDone == false)
{
yield return null;
}
Expand Down Expand Up @@ -278,7 +271,7 @@ public static void Test2Continuation()

int i = 0;

while (i < ListOfContinues.Keys.Count())
while (i < ListOfContinues.Keys.Count())
{
Main.logger.LogError("Relooping for.");

Expand All @@ -287,7 +280,7 @@ public static void Test2Continuation()

Main.logger.LogError("Creating task...");

while (d < 1 && i < ListOfContinues.Keys.Count())
while (d < 1 && i < ListOfContinues.Keys.Count())
{
int index = i;
taskList.Add(Task.Factory.StartNew(new Action(() => ContinueSetup(list[index]))));
Expand All @@ -302,7 +295,7 @@ public static void Test2Continuation()
//Main.logger.LogError($"Waiting for tasks to complete: {taskList.Count}");

Task.WaitAll(taskList.ToArray());

Main.logger.LogError("All tasks complete. Starting a new batch.");
}

Expand All @@ -318,7 +311,7 @@ public static void Test2Continuation()
//yield break;
}

public static void ContinueSetup(SceneEdit.SMenuItem mi2)
public static void ContinueSetup(SceneEdit.SMenuItem mi2)
{
Stopwatch test2 = new Stopwatch();

Expand Down Expand Up @@ -371,7 +364,6 @@ public static void ContinueSetup(SceneEdit.SMenuItem mi2)

public static bool GetMenuItemSetUP(SceneEdit.SMenuItem mi, string f_strMenuFileName, out string IconTex, bool f_bMan = false)
{

IconTex = null;

if (f_strMenuFileName.Contains("_zurashi"))
Expand All @@ -391,8 +383,6 @@ public static bool GetMenuItemSetUP(SceneEdit.SMenuItem mi, string f_strMenuFile
{
NDebug.Assert(false, "メニュースクリプトが読めませんでした。" + f_strMenuFileName);
}


}
catch (Exception ex)
{
Expand All @@ -410,7 +400,6 @@ public static bool GetMenuItemSetUP(SceneEdit.SMenuItem mi, string f_strMenuFile
return true;
}


public static bool InitMenuItemScript(SceneEdit.SMenuItem mi, string f_strMenuFileName, bool f_bMan, out string IconTex)
{
var fetchedField = AccessTools.DeclaredField(typeof(SceneEdit), "m_byItemFileBuffer");
Expand Down Expand Up @@ -635,19 +624,18 @@ public static bool InitMenuItemScript(SceneEdit.SMenuItem mi, string f_strMenuFi
return true;
}


public static IEnumerator ThrowConcurrentException(string error)
{
Main.logger.LogError("A concurrent thread ran into this error: " + error);

yield return null;
}
/*
public static IEnumerator LoadTexture(SceneEdit.SMenuItem menu, string texture)
public static IEnumerator LoadTexture(SceneEdit.SMenuItem menu, string texture)
{
menu.m_texIcon = ImportCM.CreateTexture(texture);
yield return null;
}*/
}
}
}
2 changes: 1 addition & 1 deletion Experiment5ParallelMenuLoading/InfinitePartitioner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ public IEnumerator<bool> GetEnumerator()
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
}
}
}
}
8 changes: 4 additions & 4 deletions Experiment5ParallelMenuLoading/LiveDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public void DirectoryChanged(object sender, EventArgs e)
if (args1.ChangeType == WatcherChangeTypes.Created)
{
FilesInDirectory.Add(args1.FullPath);
}
else if (args1.ChangeType == WatcherChangeTypes.Deleted)
}
else if (args1.ChangeType == WatcherChangeTypes.Deleted)
{
FilesInDirectory.Remove(args1.FullPath);
}
}
}
}

Expand All @@ -63,4 +63,4 @@ public void Dispose()
FilesInDirectory = null;
}
}
}
}
Loading

0 comments on commit c3b87d7

Please sign in to comment.