mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Added a debugger, ironed out rendering pipeline
This commit is contained in:
1 parent
4add877156
commit
93cd704c6c
15 files changed
+321
-35
No files matched your search
@@ -144,6 +144,7 @@
|
||||
<Compile Include="Constants.cs" />
|
||||
<Compile Include="Events\DeviceConfigurationEventArgs.cs" />
|
||||
<Compile Include="Events\DeviceEventArgs.cs" />
|
||||
<Compile Include="Events\FrameEventArgs.cs" />
|
||||
<Compile Include="Exceptions\ArtemisCoreException.cs" />
|
||||
<Compile Include="Extensions\DirectoryInfoExtensions.cs" />
|
||||
<Compile Include="Extensions\RgbColorExtensions.cs" />
|
||||
|
||||
@@ -5,10 +5,6 @@ namespace Artemis.Core.Events
|
||||
{
|
||||
public class DeviceEventArgs : EventArgs
|
||||
{
|
||||
public DeviceEventArgs()
|
||||
{
|
||||
}
|
||||
|
||||
public DeviceEventArgs(IRGBDevice device)
|
||||
{
|
||||
Device = device;
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace Artemis.Core.Events
|
||||
{
|
||||
public class FrameEventArgs : EventArgs
|
||||
{
|
||||
public FrameEventArgs(List<Module> modules, Bitmap bitmap, double deltaTime, RGBSurface rgbSurface)
|
||||
{
|
||||
Modules = modules;
|
||||
Bitmap = bitmap;
|
||||
DeltaTime = deltaTime;
|
||||
RgbSurface = rgbSurface;
|
||||
}
|
||||
|
||||
public List<Module> Modules { get; }
|
||||
public Bitmap Bitmap { get; }
|
||||
public double DeltaTime { get; }
|
||||
public RGBSurface RgbSurface { get; }
|
||||
}
|
||||
}
|
||||
@@ -2,27 +2,24 @@
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Groups;
|
||||
using Color = RGB.NET.Core.Color;
|
||||
using Rectangle = RGB.NET.Core.Rectangle;
|
||||
|
||||
namespace Artemis.Core.RGB.NET
|
||||
{
|
||||
public class GraphicsDecorator : AbstractDecorator, IBrushDecorator
|
||||
public class GraphicsDecorator : AbstractDecorator, IBrushDecorator, IDisposable
|
||||
{
|
||||
private readonly DirectBitmap _bitmap;
|
||||
private DirectBitmap _bitmap;
|
||||
|
||||
public GraphicsDecorator(ListLedGroup ledGroup)
|
||||
public GraphicsDecorator(ILedGroup ledGroup)
|
||||
{
|
||||
var leds = ledGroup.GetLeds().ToList();
|
||||
if (!leds.Any())
|
||||
{
|
||||
_bitmap = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
var width = leds.Max(l => l.AbsoluteLedRectangle.X + l.AbsoluteLedRectangle.Width);
|
||||
var height = leds.Max(l => l.AbsoluteLedRectangle.Y + l.AbsoluteLedRectangle.Height);
|
||||
var width = Math.Min(leds.Max(l => l.AbsoluteLedRectangle.X + l.AbsoluteLedRectangle.Width), 2000);
|
||||
var height = Math.Min(leds.Max(l => l.AbsoluteLedRectangle.Y + l.AbsoluteLedRectangle.Height), 2000);
|
||||
|
||||
_bitmap = new DirectBitmap((int) width, (int) height);
|
||||
}
|
||||
@@ -40,9 +37,25 @@ namespace Artemis.Core.RGB.NET
|
||||
return new Color(0, 0, 0);
|
||||
}
|
||||
|
||||
public override void OnDetached(IDecoratable decoratable)
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_bitmap?.Dispose();
|
||||
_bitmap = null;
|
||||
}
|
||||
|
||||
public Graphics GetGraphics()
|
||||
{
|
||||
return _bitmap == null ? null : Graphics.FromImage(_bitmap.Bitmap);
|
||||
}
|
||||
|
||||
public Bitmap GetBitmap()
|
||||
{
|
||||
return _bitmap?.Bitmap;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.Core.Exceptions;
|
||||
using Artemis.Core.Models.Surface;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Core.Services.Storage;
|
||||
@@ -46,11 +47,17 @@ namespace Artemis.Core.Services
|
||||
throw new ArtemisCoreException("Cannot initialize the core as it is already initialized.");
|
||||
|
||||
_logger.Information("Initializing Artemis Core version {version}", typeof(CoreService).Assembly.GetName().Version);
|
||||
|
||||
|
||||
// Initialize the services
|
||||
await Task.Run(() => _pluginService.CopyBuiltInPlugins());
|
||||
await Task.Run(() => _pluginService.LoadPlugins());
|
||||
|
||||
var surfaceConfig = _surfaceService.ActiveSurfaceConfiguration;
|
||||
if (surfaceConfig != null)
|
||||
_logger.Information("Initialized with active surface configuration {surfaceConfig}-{guid}", surfaceConfig.Name, surfaceConfig.Guid);
|
||||
else
|
||||
_logger.Information("Initialized without an active surface configuration");
|
||||
|
||||
OnInitialized();
|
||||
}
|
||||
|
||||
@@ -79,6 +86,8 @@ namespace Artemis.Core.Services
|
||||
foreach (var module in modules)
|
||||
module.Render(args.DeltaTime, _rgbService.Surface, g);
|
||||
}
|
||||
|
||||
OnFrameRendered(new FrameEventArgs(modules, _rgbService.GraphicsDecorator.GetBitmap(), args.DeltaTime, _rgbService.Surface));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -89,6 +98,7 @@ namespace Artemis.Core.Services
|
||||
#region Events
|
||||
|
||||
public event EventHandler Initialized;
|
||||
public event EventHandler<FrameEventArgs> FrameRendered;
|
||||
|
||||
private void OnInitialized()
|
||||
{
|
||||
@@ -97,5 +107,10 @@ namespace Artemis.Core.Services
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected virtual void OnFrameRendered(FrameEventArgs e)
|
||||
{
|
||||
FrameRendered?.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Artemis.Core.Events;
|
||||
|
||||
namespace Artemis.Core.Services.Interfaces
|
||||
{
|
||||
@@ -13,5 +14,10 @@ namespace Artemis.Core.Services.Interfaces
|
||||
/// Occurs the core has finished initializing
|
||||
/// </summary>
|
||||
event EventHandler Initialized;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs whenever a frame has finished rendering
|
||||
/// </summary>
|
||||
event EventHandler<FrameEventArgs> FrameRendered;
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ namespace Artemis.Core.Services
|
||||
Surface.Exception += SurfaceOnException;
|
||||
|
||||
_loadedDevices = new List<IRGBDevice>();
|
||||
_updateTrigger = new TimerUpdateTrigger {UpdateFrequency = 1.0 / 30};
|
||||
_updateTrigger = new TimerUpdateTrigger {UpdateFrequency = 1.0 / 25};
|
||||
Surface.RegisterUpdateTrigger(_updateTrigger);
|
||||
}
|
||||
|
||||
@@ -97,10 +97,12 @@ namespace Artemis.Core.Services
|
||||
|
||||
public void UpdateGraphicsDecorator()
|
||||
{
|
||||
// TODO: Create new one first, then clean up the old one for a smoother transition
|
||||
|
||||
// Clean up the old background if present
|
||||
if (_background != null)
|
||||
{
|
||||
_background.RemoveAllDecorators();
|
||||
_background.Brush?.RemoveAllDecorators();
|
||||
_background.Detach();
|
||||
}
|
||||
|
||||
|
||||
@@ -140,8 +140,7 @@ namespace Artemis.Core.Services.Storage
|
||||
MatchDeviceConfiguration(e.Device, surfaceConfiguration);
|
||||
}
|
||||
|
||||
foreach (var deviceConfiguration in ActiveSurfaceConfiguration.DeviceConfigurations)
|
||||
deviceConfiguration.ApplyToDevice();
|
||||
UpdateSurfaceConfiguration(ActiveSurfaceConfiguration, true);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -169,7 +168,7 @@ namespace Artemis.Core.Services.Storage
|
||||
// When all surface configs are loaded, apply the active surface config
|
||||
var active = SurfaceConfigurations.FirstOrDefault(c => c.IsActive);
|
||||
if (active != null)
|
||||
ActiveSurfaceConfiguration = active;
|
||||
SetActiveSurfaceConfiguration(active);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in new issue
Block a user