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:
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Torch.API.Managers;
|
||||
using Torch.API.Session;
|
||||
using VRage.Game.ModAPI;
|
||||
|
||||
namespace Torch.API
|
||||
@@ -33,15 +34,22 @@ namespace Torch.API
|
||||
/// </summary>
|
||||
event Action SessionUnloaded;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the currently running session instance, or null if none exists.
|
||||
/// </summary>
|
||||
ITorchSession CurrentSession { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Configuration for the current instance.
|
||||
/// </summary>
|
||||
ITorchConfig Config { get; }
|
||||
|
||||
/// <inheritdoc cref="IMultiplayerManager"/>
|
||||
[Obsolete]
|
||||
IMultiplayerManager Multiplayer { get; }
|
||||
|
||||
/// <inheritdoc cref="IPluginManager"/>
|
||||
[Obsolete]
|
||||
IPluginManager Plugins { get; }
|
||||
|
||||
/// <inheritdoc cref="IDependencyManager"/>
|
||||
|
@@ -12,6 +12,7 @@ using VRage.Steam;
|
||||
using Torch.API;
|
||||
using VRage;
|
||||
using VRage.FileSystem;
|
||||
using VRage.GameServices;
|
||||
using VRageRender;
|
||||
using VRageRender.ExternalApp;
|
||||
|
||||
@@ -53,7 +54,7 @@ namespace Torch.Client
|
||||
|
||||
_startup.DetectSharpDxLeaksBeforeRun();
|
||||
var steamService = new SteamService(Game.IsDedicated, APP_ID);
|
||||
MyServiceManager.Instance.AddService(steamService);
|
||||
MyServiceManager.Instance.AddService<IMyGameService>(steamService);
|
||||
_renderer = null;
|
||||
SpaceEngineersGame.SetupPerGameSettings();
|
||||
// I'm sorry, but it's what Keen does in SpaceEngineers.MyProgram
|
||||
|
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NLog;
|
||||
using Sandbox.Game.World;
|
||||
using Torch.API;
|
||||
using Torch.API.Managers;
|
||||
@@ -17,6 +18,7 @@ namespace Torch.Session
|
||||
/// </summary>
|
||||
public class TorchSessionManager : Manager, ITorchSessionManager
|
||||
{
|
||||
private static readonly Logger _log = LogManager.GetCurrentClassLogger();
|
||||
private TorchSession _currentSession;
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -46,7 +48,13 @@ namespace Torch.Session
|
||||
|
||||
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);
|
||||
foreach (SessionManagerFactory factory in _factories)
|
||||
{
|
||||
@@ -59,7 +67,10 @@ namespace Torch.Session
|
||||
|
||||
private void SessionUnloaded()
|
||||
{
|
||||
_currentSession?.Detach();
|
||||
if (_currentSession == null)
|
||||
return;
|
||||
_log.Info($"Unloading torch session for {_currentSession.KeenSession.Name}");
|
||||
_currentSession.Detach();
|
||||
_currentSession = null;
|
||||
}
|
||||
|
||||
|
@@ -3,9 +3,11 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NLog;
|
||||
using SteamSDK;
|
||||
using VRage.Steam;
|
||||
using Sandbox;
|
||||
using Sandbox.Engine.Networking;
|
||||
using Torch.Utils;
|
||||
using VRage.GameServices;
|
||||
|
||||
@@ -19,6 +21,9 @@ namespace Torch
|
||||
/// </summary>
|
||||
public class SteamService : MySteamService
|
||||
{
|
||||
private static readonly Logger _log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
#pragma warning disable 649
|
||||
[ReflectedSetter(Name = nameof(SteamServerAPI))]
|
||||
private static Action<MySteamService, SteamServerAPI> _steamServerAPISetter;
|
||||
[ReflectedSetter(Name = "m_gameServer")]
|
||||
@@ -45,6 +50,7 @@ namespace Torch
|
||||
private static Action<MySteamService> RegisterCallbacks;
|
||||
[ReflectedSetter(Name = nameof(Peer2Peer))]
|
||||
private static Action<MySteamService, IMyPeer2Peer> _steamPeer2PeerSetter;
|
||||
#pragma warning restore 649
|
||||
|
||||
public SteamService(bool isDedicated, uint appId)
|
||||
: base(true, appId)
|
||||
@@ -53,7 +59,7 @@ namespace Torch
|
||||
_steamServerAPISetter.Invoke(this, null);
|
||||
_steamGameServerSetter.Invoke(this, null);
|
||||
_steamAppIdSetter.Invoke(this, appId);
|
||||
|
||||
|
||||
if (isDedicated)
|
||||
{
|
||||
_steamServerAPISetter.Invoke(this, null);
|
||||
@@ -63,7 +69,10 @@ namespace Torch
|
||||
{
|
||||
SteamAPI steamApi = SteamAPI.Instance;
|
||||
_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)
|
||||
{
|
||||
@@ -76,7 +85,8 @@ namespace Torch
|
||||
|
||||
_steamInventoryAPISetter.Invoke(this, new MySteamInventory());
|
||||
RegisterCallbacks(this);
|
||||
}
|
||||
} else
|
||||
_log.Warn("SteamService isn't initialized; Torch Client won't start");
|
||||
}
|
||||
|
||||
_steamPeer2PeerSetter.Invoke(this, new MySteamPeer2Peer());
|
||||
|
@@ -19,9 +19,11 @@ using SpaceEngineers.Game;
|
||||
using Torch.API;
|
||||
using Torch.API.Managers;
|
||||
using Torch.API.ModAPI;
|
||||
using Torch.API.Session;
|
||||
using Torch.Commands;
|
||||
using Torch.Managers;
|
||||
using Torch.Utils;
|
||||
using Torch.Session;
|
||||
using VRage.Collections;
|
||||
using VRage.FileSystem;
|
||||
using VRage.Game.ObjectBuilder;
|
||||
@@ -57,15 +59,24 @@ namespace Torch
|
||||
/// <inheritdoc />
|
||||
public string[] RunArgs { get; set; }
|
||||
/// <inheritdoc />
|
||||
[Obsolete]
|
||||
public IPluginManager Plugins { get; protected set; }
|
||||
/// <inheritdoc />
|
||||
[Obsolete]
|
||||
public IMultiplayerManager Multiplayer { get; protected set; }
|
||||
/// <inheritdoc />
|
||||
[Obsolete]
|
||||
public EntityManager Entities { get; protected set; }
|
||||
/// <inheritdoc />
|
||||
[Obsolete]
|
||||
public INetworkManager Network { get; protected set; }
|
||||
/// <inheritdoc />
|
||||
[Obsolete]
|
||||
public CommandManager Commands { get; protected set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public ITorchSession CurrentSession => Managers?.GetManager<ITorchSessionManager>()?.CurrentSession;
|
||||
|
||||
/// <inheritdoc />
|
||||
public event Action SessionLoading;
|
||||
/// <inheritdoc />
|
||||
@@ -107,6 +118,7 @@ namespace Torch
|
||||
Network = new NetworkManager(this);
|
||||
Commands = new CommandManager(this);
|
||||
|
||||
Managers.AddManager(new TorchSessionManager(this));
|
||||
Managers.AddManager(new FilesystemManager(this));
|
||||
Managers.AddManager(new UpdateManager(this));
|
||||
Managers.AddManager(Network);
|
||||
@@ -116,7 +128,6 @@ namespace Torch
|
||||
Managers.AddManager(Entities);
|
||||
Managers.AddManager(new ChatManager(this));
|
||||
|
||||
|
||||
TorchAPI.Instance = this;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user