mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Datamodel - WIP stuff, need this on a diff. PC
This commit is contained in:
1 parent
35944e064d
commit
566bdd3a89
23 files changed
+392
-161
No files matched your search
@@ -6,6 +6,7 @@ using Artemis.Core.Events;
|
||||
using Artemis.Core.Exceptions;
|
||||
using Artemis.Core.JsonConverters;
|
||||
using Artemis.Core.Ninject;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Plugins.Models;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Core.Services.Storage.Interfaces;
|
||||
@@ -24,13 +25,14 @@ namespace Artemis.Core.Services
|
||||
/// </summary>
|
||||
public class CoreService : ICoreService
|
||||
{
|
||||
private readonly Stopwatch _frameStopWatch;
|
||||
private readonly ILogger _logger;
|
||||
private readonly PluginSetting<LogEventLevel> _loggingLevel;
|
||||
private readonly IPluginService _pluginService;
|
||||
private readonly IProfileService _profileService;
|
||||
private readonly IRgbService _rgbService;
|
||||
private readonly ISurfaceService _surfaceService;
|
||||
private readonly Stopwatch _frameStopWatch;
|
||||
private List<BaseDataModelExpansion> _dataModelExpansions;
|
||||
private List<Module> _modules;
|
||||
|
||||
// ReSharper disable once UnusedParameter.Local - Storage migration service is injected early to ensure it runs before anything else
|
||||
@@ -48,9 +50,9 @@ namespace Artemis.Core.Services
|
||||
_rgbService.Surface.Updated += SurfaceOnUpdated;
|
||||
_loggingLevel.SettingChanged += (sender, args) => ApplyLoggingLevel();
|
||||
|
||||
_modules = _pluginService.GetPluginsOfType<Module>();
|
||||
_pluginService.PluginEnabled += (sender, args) => _modules = _pluginService.GetPluginsOfType<Module>();
|
||||
_pluginService.PluginDisabled += (sender, args) => _modules = _pluginService.GetPluginsOfType<Module>();
|
||||
_pluginService.PluginEnabled += (sender, args) => UpdatePluginCache();
|
||||
_pluginService.PluginDisabled += (sender, args) => UpdatePluginCache();
|
||||
UpdatePluginCache();
|
||||
|
||||
_frameStopWatch = new Stopwatch();
|
||||
|
||||
@@ -58,7 +60,7 @@ namespace Artemis.Core.Services
|
||||
}
|
||||
|
||||
public TimeSpan FrameTime { get; private set; }
|
||||
public bool ModuleUpdatingDisabled { get; set; }
|
||||
public bool PluginUpdatingDisabled { get; set; }
|
||||
public bool ModuleRenderingDisabled { get; set; }
|
||||
|
||||
public void Dispose()
|
||||
@@ -75,7 +77,7 @@ namespace Artemis.Core.Services
|
||||
throw new ArtemisCoreException("Cannot initialize the core as it is already initialized.");
|
||||
|
||||
var versionAttribute = typeof(CoreService).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
|
||||
_logger.Information("Initializing Artemis Core version {version}", versionAttribute?.InformationalVersion);
|
||||
_logger.Information("Initializing Artemis Core version {version}", versionAttribute?.InformationalVersion);
|
||||
ApplyLoggingLevel();
|
||||
|
||||
// Initialize the services
|
||||
@@ -103,6 +105,12 @@ namespace Artemis.Core.Services
|
||||
FrameRendered?.Invoke(this, e);
|
||||
}
|
||||
|
||||
private void UpdatePluginCache()
|
||||
{
|
||||
_modules = _pluginService.GetPluginsOfType<Module>();
|
||||
_dataModelExpansions = _pluginService.GetPluginsOfType<BaseDataModelExpansion>();
|
||||
}
|
||||
|
||||
private void ConfigureJsonConvert()
|
||||
{
|
||||
JsonConvert.DefaultSettings = () => new JsonSerializerSettings
|
||||
@@ -125,8 +133,15 @@ namespace Artemis.Core.Services
|
||||
try
|
||||
{
|
||||
_frameStopWatch.Restart();
|
||||
if (!ModuleUpdatingDisabled && _modules != null)
|
||||
if (!PluginUpdatingDisabled)
|
||||
{
|
||||
lock (_dataModelExpansions)
|
||||
{
|
||||
// Update all active modules
|
||||
foreach (var dataModelExpansion in _dataModelExpansions)
|
||||
dataModelExpansion.Update(args.DeltaTime);
|
||||
}
|
||||
|
||||
lock (_modules)
|
||||
{
|
||||
// Update all active modules
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.Core.Exceptions;
|
||||
using Artemis.Core.Models;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Plugins.Abstract.DataModels;
|
||||
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
|
||||
using Artemis.Core.Plugins.Exceptions;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
|
||||
namespace Artemis.Core.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides access to the main data model
|
||||
/// </summary>
|
||||
public class DataModelService : IDataModelService
|
||||
{
|
||||
private readonly IPluginService _pluginService;
|
||||
private readonly List<DataModel> _dataModelExpansions;
|
||||
|
||||
internal DataModelService(IPluginService pluginService)
|
||||
{
|
||||
_pluginService = pluginService;
|
||||
_dataModelExpansions = new List<DataModel>();
|
||||
|
||||
_pluginService.PluginEnabled += PluginServiceOnPluginEnabled;
|
||||
_pluginService.PluginDisabled += PluginServiceOnPluginDisabled;
|
||||
}
|
||||
|
||||
public ReadOnlyCollection<DataModel> DataModelExpansions
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_dataModelExpansions)
|
||||
{
|
||||
return new List<DataModel>(_dataModelExpansions).AsReadOnly();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AddExpansion(DataModel dataModelExpansion)
|
||||
{
|
||||
lock (_dataModelExpansions)
|
||||
{
|
||||
_dataModelExpansions.Add(dataModelExpansion);
|
||||
// TODO SpoinkyNL 3-3-2018: Initialize the expansion and fire an event
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveExpansion(DataModel dataModelExpansion)
|
||||
{
|
||||
lock (_dataModelExpansions)
|
||||
{
|
||||
if (!_dataModelExpansions.Contains(dataModelExpansion))
|
||||
throw new ArtemisCoreException("Cannot remove a data model expansion that wasn't previously added.");
|
||||
|
||||
// TODO SpoinkyNL 3-3-2018: Dispose the expansion and fire an event
|
||||
_dataModelExpansions.Remove(dataModelExpansion);
|
||||
}
|
||||
}
|
||||
|
||||
public DataModelDescription GetMainDataModelDescription()
|
||||
{
|
||||
var dataModelDescription = new DataModelDescription();
|
||||
|
||||
return dataModelDescription;
|
||||
}
|
||||
|
||||
private void PluginServiceOnPluginEnabled(object sender, PluginEventArgs e)
|
||||
{
|
||||
if (e.PluginInfo.Instance is Module module && module.InternalExpandsMainDataModel)
|
||||
{
|
||||
if (!module.InternalDataModel.Initialized)
|
||||
{
|
||||
module.InternalDataModel.DataModelDescription = module.InternalGetDataModelDescription();
|
||||
if (module.InternalDataModel.DataModelDescription == null)
|
||||
throw new ArtemisPluginException(module.PluginInfo, "Module overrides GetDataModelDescription but returned null");
|
||||
|
||||
module.InternalDataModel.Initialize();
|
||||
}
|
||||
|
||||
_dataModelExpansions.Add(module.InternalDataModel);
|
||||
}
|
||||
else if (e.PluginInfo.Instance is BaseDataModelExpansion dataModelExpansion)
|
||||
{
|
||||
if (!dataModelExpansion.InternalDataModel.Initialized)
|
||||
{
|
||||
dataModelExpansion.InternalDataModel.DataModelDescription = dataModelExpansion.GetDataModelDescription();
|
||||
if (dataModelExpansion.InternalDataModel.DataModelDescription == null)
|
||||
throw new ArtemisPluginException(dataModelExpansion.PluginInfo, "Data model expansion overrides GetDataModelDescription but returned null");
|
||||
|
||||
dataModelExpansion.InternalDataModel.Initialize();
|
||||
}
|
||||
|
||||
_dataModelExpansions.Add(dataModelExpansion.InternalDataModel);
|
||||
}
|
||||
}
|
||||
|
||||
private void PluginServiceOnPluginDisabled(object sender, PluginEventArgs e)
|
||||
{
|
||||
// Remove all data models related to the plugin
|
||||
lock (_dataModelExpansions)
|
||||
{
|
||||
var toRemove = _dataModelExpansions.Where(d => d.PluginInfo == e.PluginInfo).ToList();
|
||||
foreach (var dataModel in toRemove)
|
||||
_dataModelExpansions.Remove(dataModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ namespace Artemis.Core.Services.Interfaces
|
||||
/// <summary>
|
||||
/// Gets or sets whether modules are updated each frame by calling their Update method
|
||||
/// </summary>
|
||||
bool ModuleUpdatingDisabled { get; set; }
|
||||
bool PluginUpdatingDisabled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether modules are rendered each frame by calling their Render method
|
||||
|
||||
+6
-12
@@ -1,27 +1,21 @@
|
||||
using Artemis.Core.Models;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Plugins.Abstract.DataModels;
|
||||
|
||||
namespace Artemis.Core.Services.Interfaces
|
||||
{
|
||||
public interface IMainDataModelService : IArtemisService
|
||||
public interface IDataModelService : IArtemisService
|
||||
{
|
||||
/// <summary>
|
||||
/// Called each frame when the main data model must update
|
||||
/// </summary>
|
||||
/// <param name="deltaTime">Time since the last update</param>
|
||||
void Update(double deltaTime);
|
||||
|
||||
/// <summary>
|
||||
/// Add an expansion to the datamodel to be available for use after the next update
|
||||
/// </summary>
|
||||
/// <param name="dataModelExpansion"></param>
|
||||
void AddExpansion(DataModelExpansion dataModelExpansion);
|
||||
/// <param name="baseDataModelExpansion"></param>
|
||||
void AddExpansion(DataModel baseDataModelExpansion);
|
||||
|
||||
/// <summary>
|
||||
/// Remove a previously added expansion so that it is no longer available and updated
|
||||
/// </summary>
|
||||
/// <param name="dataModelExpansion"></param>
|
||||
void RemoveExpansion(DataModelExpansion dataModelExpansion);
|
||||
/// <param name="baseDataModelExpansion"></param>
|
||||
void RemoveExpansion(DataModel baseDataModelExpansion);
|
||||
|
||||
/// <summary>
|
||||
/// Generates a data model description for the main datamodel including all it's expansions
|
||||
@@ -1,71 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using Artemis.Core.Exceptions;
|
||||
using Artemis.Core.Models;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
|
||||
namespace Artemis.Core.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides access to the main data model
|
||||
/// </summary>
|
||||
public class MainDataModelService : IMainDataModelService
|
||||
{
|
||||
private readonly List<DataModelExpansion> _dataModelExpansions;
|
||||
|
||||
internal MainDataModelService()
|
||||
{
|
||||
_dataModelExpansions = new List<DataModelExpansion>();
|
||||
}
|
||||
|
||||
public ReadOnlyCollection<DataModelExpansion> DataModelExpansions
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_dataModelExpansions)
|
||||
{
|
||||
return _dataModelExpansions.AsReadOnly();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Update(double deltaTime)
|
||||
{
|
||||
lock (_dataModelExpansions)
|
||||
{
|
||||
// Update all expansions
|
||||
foreach (var expansion in _dataModelExpansions)
|
||||
expansion.Update(deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddExpansion(DataModelExpansion dataModelExpansion)
|
||||
{
|
||||
lock (_dataModelExpansions)
|
||||
{
|
||||
_dataModelExpansions.Add(dataModelExpansion);
|
||||
// TODO SpoinkyNL 3-3-2018: Initialize the expansion and fire an event
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveExpansion(DataModelExpansion dataModelExpansion)
|
||||
{
|
||||
lock (_dataModelExpansions)
|
||||
{
|
||||
if (!_dataModelExpansions.Contains(dataModelExpansion))
|
||||
throw new ArtemisCoreException("Cannot remove a data model expansion that wasn't previously added.");
|
||||
|
||||
// TODO SpoinkyNL 3-3-2018: Dispose the expansion and fire an event
|
||||
_dataModelExpansions.Remove(dataModelExpansion);
|
||||
}
|
||||
}
|
||||
|
||||
public DataModelDescription GetMainDataModelDescription()
|
||||
{
|
||||
var dataModelDescription = new DataModelDescription();
|
||||
|
||||
return dataModelDescription;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user