Future methods for loading/unloading sessions.

Fix reflected manager to work with instance methods on internal types.
This commit is contained in:
Westin Miller
2017-11-25 17:44:50 -08:00
parent f0adeddb66
commit 7ea982c903
2 changed files with 47 additions and 1 deletions

View File

@@ -237,8 +237,12 @@ namespace Torch.Utils
argExp[i] = Expression.Convert(paramExp[i + 1], invokeTypes[i]);
else
argExp[i] = paramExp[i + 1];
Debug.Assert(methodInstance.DeclaringType != null);
Expression instanceExp = paramExp[0].Type != methodInstance.DeclaringType
? Expression.Convert(paramExp[0], methodInstance.DeclaringType)
: (Expression) paramExp[0];
field.SetValue(null,
Expression.Lambda(Expression.Call(paramExp[0], methodInstance, argExp), paramExp)
Expression.Lambda(Expression.Call(instanceExp, methodInstance, argExp), paramExp)
.Compile());
_log.Trace($"Reflecting field {field.DeclaringType?.FullName}#{field.Name} with {methodInstance.DeclaringType?.FullName}#{methodInstance.Name}");
}

View File

@@ -10,13 +10,16 @@ using Havok;
using NLog;
using NLog.Fluent;
using Sandbox;
using Sandbox.Engine.Multiplayer;
using Sandbox.Engine.Networking;
using Sandbox.Engine.Platform.VideoMode;
using Sandbox.Game;
using Sandbox.Game.World;
using SpaceEngineers.Game;
using SpaceEngineers.Game.GUI;
using Torch.Utils;
using VRage;
using VRage.Audio;
using VRage.FileSystem;
using VRage.Game;
using VRage.Game.SessionComponents;
@@ -35,6 +38,17 @@ namespace Torch
#pragma warning disable 649
[ReflectedGetter(Name = "m_plugins", Type = typeof(MyPlugins))]
private static readonly Func<List<IPlugin>> _getVRagePluginList;
[ReflectedGetter(Name = "Static", TypeName = "Sandbox.Game.Audio.MyMusicController, Sandbox.Game")]
private static readonly Func<object> _getMusicControllerStatic;
[ReflectedSetter(Name = "Static", TypeName = "Sandbox.Game.Audio.MyMusicController, Sandbox.Game")]
private static readonly Action<object> _setMusicControllerStatic;
[ReflectedMethod(Name = "Unload", TypeName = "Sandbox.Game.Audio.MyMusicController, Sandbox.Game")]
private static readonly Action<object> _musicControllerUnload;
#pragma warning restore 649
private readonly TorchBase _torch;
@@ -210,6 +224,34 @@ namespace Torch
}
}
private void LoadSession(string sessionPath)
{
// ?
MySessionLoader.LoadSingleplayerSession(sessionPath);
}
private void UnloadSession()
{
if (MySession.Static != null)
{
MySession.Static.Unload();
MySession.Static = null;
}
{
var musicCtl = _getMusicControllerStatic();
if (musicCtl != null)
{
_musicControllerUnload(musicCtl);
_setMusicControllerStatic(null);
MyAudio.Static.MusicAllowed = true;
}
}
if (MyMultiplayer.Static != null)
{
MyMultiplayer.Static.Dispose();
}
}
private void DoStop()
{
ParallelTasks.Parallel.Scheduler.WaitForTasksToFinish(TimeSpan.FromSeconds(10.0));