- Added legacy LuaCsPerformanceCounter.cs
- Added legacy redirects. - Added IConsoleCommandsService injection to plugins.
This commit is contained in:
@@ -364,10 +364,15 @@ namespace Barotrauma
|
||||
CoroutineManager.Update(paused: false, (float)Timing.Step);
|
||||
|
||||
performanceCounterTimer.Stop();
|
||||
if (LuaCsSetup.Instance.PerformanceCounterService.EnablePerformanceCounter)
|
||||
{
|
||||
LuaCsSetup.Instance.PerformanceCounterService.AddElapsedTicks(new SimplePerformanceData("Update", performanceCounterTimer.ElapsedTicks));
|
||||
}
|
||||
if (LuaCsSetup.Instance.PerformanceCounter.EnablePerformanceCounter)
|
||||
{
|
||||
LuaCsSetup.Instance.PerformanceCounter.AddElapsedTicks(new SimplePerformanceData("Update", performanceCounterTimer.ElapsedTicks));
|
||||
LuaCsSetup.Instance.PerformanceCounter.UpdateElapsedTime = (double)performanceCounterTimer.ElapsedTicks / Stopwatch.Frequency;
|
||||
}
|
||||
|
||||
performanceCounterTimer.Reset();
|
||||
|
||||
Timing.Accumulator -= Timing.Step;
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
/// <summary>
|
||||
/// <b>[Obsolete]</b> Legacy compatibility only.
|
||||
/// </summary>
|
||||
[Obsolete("Deprecated.")]
|
||||
public class LuaCsPerformanceCounter
|
||||
{
|
||||
public bool EnablePerformanceCounter = false;
|
||||
|
||||
public double UpdateElapsedTime;
|
||||
public Dictionary<string, Dictionary<string, double>> HookElapsedTime = new Dictionary<string, Dictionary<string, double>>();
|
||||
|
||||
public static float MemoryUsage
|
||||
{
|
||||
get
|
||||
{
|
||||
Process proc = Process.GetCurrentProcess();
|
||||
float memory = MathF.Round(proc.PrivateMemorySize64 / (1024 * 1024), 2);
|
||||
proc.Dispose();
|
||||
|
||||
return memory;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetHookElapsedTicks(string eventName, string hookName, long ticks)
|
||||
{
|
||||
if (!HookElapsedTime.ContainsKey(eventName))
|
||||
{
|
||||
HookElapsedTime[eventName] = new Dictionary<string, double>();
|
||||
}
|
||||
|
||||
HookElapsedTime[eventName][hookName] = (double)ticks / Stopwatch.Frequency;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,8 +68,9 @@ namespace Barotrauma
|
||||
*/
|
||||
|
||||
private readonly IServicesProvider _servicesProvider;
|
||||
|
||||
public PerformanceCounterService PerformanceCounter => _servicesProvider.GetService<PerformanceCounterService>();
|
||||
|
||||
private PerformanceCounterService _performanceCounterService;
|
||||
public PerformanceCounterService PerformanceCounterService => _performanceCounterService ??= _servicesProvider.GetService<PerformanceCounterService>();
|
||||
public ILoggerService Logger => _servicesProvider.GetService<ILoggerService>();
|
||||
public IConfigService ConfigService => _servicesProvider.GetService<IConfigService>();
|
||||
public IPackageManagementService PackageManagementService => _servicesProvider.GetService<IPackageManagementService>();
|
||||
@@ -82,8 +83,8 @@ namespace Barotrauma
|
||||
// hotpath performance ref cache
|
||||
private LuaGame _game;
|
||||
public LuaGame Game => _game ??= _servicesProvider.GetService<LuaGame>();
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Whether C# plugin code is enabled.
|
||||
/// </summary>
|
||||
@@ -381,6 +382,17 @@ namespace Barotrauma
|
||||
|
||||
#region LegacyRedirects
|
||||
|
||||
// --- Compatibility
|
||||
/// <summary>
|
||||
/// <b>[Obsolete]</b> Legacy support only.
|
||||
/// </summary>
|
||||
[Obsolete]
|
||||
public LuaCsPerformanceCounter PerformanceCounter { get; private set; } = new LuaCsPerformanceCounter();
|
||||
/// <summary>
|
||||
/// <b>[Obsolete] Use <see cref="IPluginManagementService"/> instead.</b>
|
||||
/// </summary>
|
||||
[Obsolete($"Use {nameof(PluginManagementService)} instead.")]
|
||||
public IPluginManagementService PluginPackageManager => this.PluginManagementService;
|
||||
public ILuaCsHook Hook => this.EventService;
|
||||
public INetworkingService Networking => this.NetworkingService;
|
||||
public ILuaCsTimer Timer => _servicesProvider.GetService<ILuaCsTimer>();
|
||||
@@ -413,6 +425,7 @@ namespace Barotrauma
|
||||
|
||||
_eventService = null;
|
||||
_game = null;
|
||||
PerformanceCounter = null;
|
||||
_servicesProvider.DisposeAndReset();
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
@@ -198,6 +198,7 @@ public class PluginManagementService : IAssemblyManagementService
|
||||
private Lazy<ILuaScriptManagementService> _luaScriptManagementService;
|
||||
private IEventService _pluginEventService;
|
||||
private Lazy<ILuaPatcher> _pluginLuaPatcherService;
|
||||
private Func<IConsoleCommandsService> _consoleCommandServiceFactory;
|
||||
private readonly ConcurrentDictionary<ContentPackage, IAssemblyLoaderService> _assemblyLoaders = new();
|
||||
private readonly ConcurrentDictionary<Type, ContentPackage> _pluginPackageLookup = new();
|
||||
private readonly ConcurrentDictionary<ContentPackage, ImmutableArray<IAssemblyPlugin>> _pluginInstances = new();
|
||||
@@ -213,7 +214,8 @@ public class PluginManagementService : IAssemblyManagementService
|
||||
Lazy<IEventService> eventService,
|
||||
Lazy<ILuaScriptManagementService> luaScriptManagementService,
|
||||
Lazy<IConfigService> configService,
|
||||
Lazy<ILuaPatcher> pluginLuaPatcherService)
|
||||
Lazy<ILuaPatcher> pluginLuaPatcherService,
|
||||
Func<IConsoleCommandsService> consoleCommandServiceFactory)
|
||||
{
|
||||
_assemblyLoaderFactory = assemblyLoaderFactory;
|
||||
_storageService = storageService;
|
||||
@@ -222,6 +224,7 @@ public class PluginManagementService : IAssemblyManagementService
|
||||
_luaScriptManagementService = luaScriptManagementService;
|
||||
_configService = configService;
|
||||
_pluginLuaPatcherService = pluginLuaPatcherService;
|
||||
_consoleCommandServiceFactory = consoleCommandServiceFactory;
|
||||
}
|
||||
|
||||
private ServiceContainer CreatePluginServiceContainer()
|
||||
@@ -240,6 +243,7 @@ public class PluginManagementService : IAssemblyManagementService
|
||||
container.Register<IPluginManagementService>(fac => this);
|
||||
container.Register<ILuaScriptManagementService>(fac => _luaScriptManagementService.Value);
|
||||
container.Register<IConfigService>(fac => _configService.Value);
|
||||
container.Register<IConsoleCommandsService>(fac => _consoleCommandServiceFactory?.Invoke());
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user