CurrentSession available directly from TorchBase

SteamService is now properly injected for clients, and reports errors
Obsolete tags on the manager properties in TorchBase
This commit is contained in:
Westin Miller
2017-08-21 21:38:25 -07:00
parent 91ad78e6a2
commit a4b1b9bb96
5 changed files with 48 additions and 7 deletions

View File

@@ -4,6 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Torch.API.Managers; using Torch.API.Managers;
using Torch.API.Session;
using VRage.Game.ModAPI; using VRage.Game.ModAPI;
namespace Torch.API namespace Torch.API
@@ -33,15 +34,22 @@ namespace Torch.API
/// </summary> /// </summary>
event Action SessionUnloaded; event Action SessionUnloaded;
/// <summary>
/// Gets the currently running session instance, or null if none exists.
/// </summary>
ITorchSession CurrentSession { get; }
/// <summary> /// <summary>
/// Configuration for the current instance. /// Configuration for the current instance.
/// </summary> /// </summary>
ITorchConfig Config { get; } ITorchConfig Config { get; }
/// <inheritdoc cref="IMultiplayerManager"/> /// <inheritdoc cref="IMultiplayerManager"/>
[Obsolete]
IMultiplayerManager Multiplayer { get; } IMultiplayerManager Multiplayer { get; }
/// <inheritdoc cref="IPluginManager"/> /// <inheritdoc cref="IPluginManager"/>
[Obsolete]
IPluginManager Plugins { get; } IPluginManager Plugins { get; }
/// <inheritdoc cref="IDependencyManager"/> /// <inheritdoc cref="IDependencyManager"/>

View File

@@ -12,6 +12,7 @@ using VRage.Steam;
using Torch.API; using Torch.API;
using VRage; using VRage;
using VRage.FileSystem; using VRage.FileSystem;
using VRage.GameServices;
using VRageRender; using VRageRender;
using VRageRender.ExternalApp; using VRageRender.ExternalApp;
@@ -53,7 +54,7 @@ namespace Torch.Client
_startup.DetectSharpDxLeaksBeforeRun(); _startup.DetectSharpDxLeaksBeforeRun();
var steamService = new SteamService(Game.IsDedicated, APP_ID); var steamService = new SteamService(Game.IsDedicated, APP_ID);
MyServiceManager.Instance.AddService(steamService); MyServiceManager.Instance.AddService<IMyGameService>(steamService);
_renderer = null; _renderer = null;
SpaceEngineersGame.SetupPerGameSettings(); SpaceEngineersGame.SetupPerGameSettings();
// I'm sorry, but it's what Keen does in SpaceEngineers.MyProgram // I'm sorry, but it's what Keen does in SpaceEngineers.MyProgram

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using NLog;
using Sandbox.Game.World; using Sandbox.Game.World;
using Torch.API; using Torch.API;
using Torch.API.Managers; using Torch.API.Managers;
@@ -17,6 +18,7 @@ namespace Torch.Session
/// </summary> /// </summary>
public class TorchSessionManager : Manager, ITorchSessionManager public class TorchSessionManager : Manager, ITorchSessionManager
{ {
private static readonly Logger _log = LogManager.GetCurrentClassLogger();
private TorchSession _currentSession; private TorchSession _currentSession;
/// <inheritdoc/> /// <inheritdoc/>
@@ -46,7 +48,13 @@ namespace Torch.Session
private void SessionLoaded() private void SessionLoaded()
{ {
_currentSession?.Detach(); if (_currentSession != null)
{
_log.Warn($"Override old torch session {_currentSession.KeenSession.Name}");
_currentSession.Detach();
}
_log.Info($"Starting new torch session for {MySession.Static.Name}");
_currentSession = new TorchSession(Torch, MySession.Static); _currentSession = new TorchSession(Torch, MySession.Static);
foreach (SessionManagerFactory factory in _factories) foreach (SessionManagerFactory factory in _factories)
{ {
@@ -59,7 +67,10 @@ namespace Torch.Session
private void SessionUnloaded() private void SessionUnloaded()
{ {
_currentSession?.Detach(); if (_currentSession == null)
return;
_log.Info($"Unloading torch session for {_currentSession.KeenSession.Name}");
_currentSession.Detach();
_currentSession = null; _currentSession = null;
} }

View File

@@ -3,9 +3,11 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using NLog;
using SteamSDK; using SteamSDK;
using VRage.Steam; using VRage.Steam;
using Sandbox; using Sandbox;
using Sandbox.Engine.Networking;
using Torch.Utils; using Torch.Utils;
using VRage.GameServices; using VRage.GameServices;
@@ -19,6 +21,9 @@ namespace Torch
/// </summary> /// </summary>
public class SteamService : MySteamService public class SteamService : MySteamService
{ {
private static readonly Logger _log = LogManager.GetCurrentClassLogger();
#pragma warning disable 649
[ReflectedSetter(Name = nameof(SteamServerAPI))] [ReflectedSetter(Name = nameof(SteamServerAPI))]
private static Action<MySteamService, SteamServerAPI> _steamServerAPISetter; private static Action<MySteamService, SteamServerAPI> _steamServerAPISetter;
[ReflectedSetter(Name = "m_gameServer")] [ReflectedSetter(Name = "m_gameServer")]
@@ -45,6 +50,7 @@ namespace Torch
private static Action<MySteamService> RegisterCallbacks; private static Action<MySteamService> RegisterCallbacks;
[ReflectedSetter(Name = nameof(Peer2Peer))] [ReflectedSetter(Name = nameof(Peer2Peer))]
private static Action<MySteamService, IMyPeer2Peer> _steamPeer2PeerSetter; private static Action<MySteamService, IMyPeer2Peer> _steamPeer2PeerSetter;
#pragma warning restore 649
public SteamService(bool isDedicated, uint appId) public SteamService(bool isDedicated, uint appId)
: base(true, appId) : base(true, appId)
@@ -63,7 +69,10 @@ namespace Torch
{ {
SteamAPI steamApi = SteamAPI.Instance; SteamAPI steamApi = SteamAPI.Instance;
_steamApiSetter.Invoke(this, steamApi); _steamApiSetter.Invoke(this, steamApi);
_steamIsActiveSetter.Invoke(this, steamApi.Init()); bool initResult = steamApi.Init();
if (!initResult)
_log.Warn("Failed to initialize SteamService");
_steamIsActiveSetter.Invoke(this, initResult);
if (IsActive) if (IsActive)
{ {
@@ -76,7 +85,8 @@ namespace Torch
_steamInventoryAPISetter.Invoke(this, new MySteamInventory()); _steamInventoryAPISetter.Invoke(this, new MySteamInventory());
RegisterCallbacks(this); RegisterCallbacks(this);
} } else
_log.Warn("SteamService isn't initialized; Torch Client won't start");
} }
_steamPeer2PeerSetter.Invoke(this, new MySteamPeer2Peer()); _steamPeer2PeerSetter.Invoke(this, new MySteamPeer2Peer());

View File

@@ -19,9 +19,11 @@ using SpaceEngineers.Game;
using Torch.API; using Torch.API;
using Torch.API.Managers; using Torch.API.Managers;
using Torch.API.ModAPI; using Torch.API.ModAPI;
using Torch.API.Session;
using Torch.Commands; using Torch.Commands;
using Torch.Managers; using Torch.Managers;
using Torch.Utils; using Torch.Utils;
using Torch.Session;
using VRage.Collections; using VRage.Collections;
using VRage.FileSystem; using VRage.FileSystem;
using VRage.Game.ObjectBuilder; using VRage.Game.ObjectBuilder;
@@ -57,15 +59,24 @@ namespace Torch
/// <inheritdoc /> /// <inheritdoc />
public string[] RunArgs { get; set; } public string[] RunArgs { get; set; }
/// <inheritdoc /> /// <inheritdoc />
[Obsolete]
public IPluginManager Plugins { get; protected set; } public IPluginManager Plugins { get; protected set; }
/// <inheritdoc /> /// <inheritdoc />
[Obsolete]
public IMultiplayerManager Multiplayer { get; protected set; } public IMultiplayerManager Multiplayer { get; protected set; }
/// <inheritdoc /> /// <inheritdoc />
[Obsolete]
public EntityManager Entities { get; protected set; } public EntityManager Entities { get; protected set; }
/// <inheritdoc /> /// <inheritdoc />
[Obsolete]
public INetworkManager Network { get; protected set; } public INetworkManager Network { get; protected set; }
/// <inheritdoc /> /// <inheritdoc />
[Obsolete]
public CommandManager Commands { get; protected set; } public CommandManager Commands { get; protected set; }
/// <inheritdoc />
public ITorchSession CurrentSession => Managers?.GetManager<ITorchSessionManager>()?.CurrentSession;
/// <inheritdoc /> /// <inheritdoc />
public event Action SessionLoading; public event Action SessionLoading;
/// <inheritdoc /> /// <inheritdoc />
@@ -107,6 +118,7 @@ namespace Torch
Network = new NetworkManager(this); Network = new NetworkManager(this);
Commands = new CommandManager(this); Commands = new CommandManager(this);
Managers.AddManager(new TorchSessionManager(this));
Managers.AddManager(new FilesystemManager(this)); Managers.AddManager(new FilesystemManager(this));
Managers.AddManager(new UpdateManager(this)); Managers.AddManager(new UpdateManager(this));
Managers.AddManager(Network); Managers.AddManager(Network);
@@ -116,7 +128,6 @@ namespace Torch
Managers.AddManager(Entities); Managers.AddManager(Entities);
Managers.AddManager(new ChatManager(this)); Managers.AddManager(new ChatManager(this));
TorchAPI.Instance = this; TorchAPI.Instance = this;
} }