Clean up Tweening

Fix tweening performance
Fix overlay rendering
Fix LUA drawing scale on non-keyboard events
Added 15 sec startup delay on autorun
This commit is contained in:
SpoinkyNL committed 2017-02-03 19:32:24 +01:00
1 parent d4ca54a35a
commit 7373bad446
12 files changed
+136 -80

No files matched your search

+4 -4
View File
@@ -159,8 +159,8 @@
<HintPath>..\packages\CSCore.1.1.0\lib\net35-client\CSCore.dll</HintPath> <HintPath>..\packages\CSCore.1.1.0\lib\net35-client\CSCore.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="CUE.NET, Version=1.1.1.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="CUE.NET, Version=1.1.2.1, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\CUE.NET.1.1.1\lib\net45\CUE.NET.dll</HintPath> <HintPath>..\packages\CUE.NET.1.1.2.1\lib\net45\CUE.NET.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="DeltaCompressionDotNet, Version=1.1.0.0, Culture=neutral, PublicKeyToken=1d14d6e5194e7f4a, processorArchitecture=MSIL"> <Reference Include="DeltaCompressionDotNet, Version=1.1.0.0, Culture=neutral, PublicKeyToken=1d14d6e5194e7f4a, processorArchitecture=MSIL">
@@ -1035,12 +1035,12 @@
<Folder Include="Resources\Lua\" /> <Folder Include="Resources\Lua\" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\CUE.NET.1.1.1\build\net45\CUE.NET.targets" Condition="Exists('..\packages\CUE.NET.1.1.1\build\net45\CUE.NET.targets')" /> <Import Project="..\packages\CUE.NET.1.1.2.1\build\net45\CUE.NET.targets" Condition="Exists('..\packages\CUE.NET.1.1.2.1\build\net45\CUE.NET.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup> <PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup> </PropertyGroup>
<Error Condition="!Exists('..\packages\CUE.NET.1.1.1\build\net45\CUE.NET.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CUE.NET.1.1.1\build\net45\CUE.NET.targets'))" /> <Error Condition="!Exists('..\packages\CUE.NET.1.1.2.1\build\net45\CUE.NET.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\CUE.NET.1.1.2.1\build\net45\CUE.NET.targets'))" />
</Target> </Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.
+11
View File
@@ -1,6 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
@@ -15,6 +17,8 @@ using Artemis.ViewModels;
using Caliburn.Micro; using Caliburn.Micro;
using Newtonsoft.Json; using Newtonsoft.Json;
using Ninject; using Ninject;
using NLog;
using LogManager = NLog.LogManager;
namespace Artemis namespace Artemis
{ {
@@ -80,6 +84,13 @@ namespace Artemis
protected override void Configure() protected override void Configure()
{ {
// Sleep for a while if ran from autorun to allow full system boot
if (Environment.GetCommandLineArgs().Contains("--autorun"))
{
var logger = LogManager.GetCurrentClassLogger();
logger.Info("Artemis was run using the autorun shortcut, sleeping for 15 sec.");
Thread.Sleep(15000);
}
_kernel = new StandardKernel(new BaseModules(), new ManagerModules()); _kernel = new StandardKernel(new BaseModules(), new ManagerModules());
_kernel.Bind<IWindowManager>().To<WindowManager>().InSingletonScope(); _kernel.Bind<IWindowManager>().To<WindowManager>().InSingletonScope();
@@ -11,6 +11,7 @@ namespace Artemis.Models
{ {
private readonly int _x; private readonly int _x;
private readonly KeyboardProvider _keyboard; private readonly KeyboardProvider _keyboard;
private DrawingContext _ctx;
public DeviceVisualModel(DrawType drawType, int x) public DeviceVisualModel(DrawType drawType, int x)
{ {
@@ -59,5 +60,16 @@ namespace Artemis.Models
return bitmap; return bitmap;
} }
public DrawingContext GetDrawingContext()
{
return _ctx ?? (_ctx = RenderOpen());
}
public void CloseDrawingContext()
{
_ctx?.Close();
_ctx = null;
}
} }
} }
+13
View File
@@ -82,13 +82,26 @@ namespace Artemis.Models
c.DrawRectangle(new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)), null, _rect); c.DrawRectangle(new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)), null, _rect);
if (MouseModel != null) if (MouseModel != null)
{
MouseModel.CloseDrawingContext();
c.DrawRectangle(new VisualBrush(MouseModel), new Pen(), MouseModel.RelativeRect); c.DrawRectangle(new VisualBrush(MouseModel), new Pen(), MouseModel.RelativeRect);
}
if (HeadsetModel != null) if (HeadsetModel != null)
{
HeadsetModel.CloseDrawingContext();
c.DrawRectangle(new VisualBrush(HeadsetModel), new Pen(), HeadsetModel.RelativeRect); c.DrawRectangle(new VisualBrush(HeadsetModel), new Pen(), HeadsetModel.RelativeRect);
}
if (GenericModel != null) if (GenericModel != null)
{
GenericModel.CloseDrawingContext();
c.DrawRectangle(new VisualBrush(GenericModel), new Pen(), GenericModel.RelativeRect); c.DrawRectangle(new VisualBrush(GenericModel), new Pen(), GenericModel.RelativeRect);
}
if (MousematModel != null) if (MousematModel != null)
{
MousematModel.CloseDrawingContext();
c.DrawRectangle(new VisualBrush(MousematModel), new Pen(), MousematModel.RelativeRect); c.DrawRectangle(new VisualBrush(MousematModel), new Pen(), MousematModel.RelativeRect);
}
KeyboardModel.CloseDrawingContext();
c.DrawRectangle(new VisualBrush(KeyboardModel), new Pen(), KeyboardModel.RelativeRect); c.DrawRectangle(new VisualBrush(KeyboardModel), new Pen(), KeyboardModel.RelativeRect);
c.Pop(); c.Pop();
@@ -119,7 +119,7 @@ namespace Artemis.Modules.General.GeneralProfile
var peakValues = _playbackInfo.GetChannelsPeakValues(); var peakValues = _playbackInfo.GetChannelsPeakValues();
dataModel.Audio.Playback.OverallPeak = _playbackInfo.PeakValue; dataModel.Audio.Playback.OverallPeak = _playbackInfo.PeakValue;
dataModel.Audio.Playback.LeftPeak = peakValues[0]; dataModel.Audio.Playback.LeftPeak = peakValues[0];
dataModel.Audio.Playback.LeftPeak = peakValues[1]; dataModel.Audio.Playback.RightPeak = peakValues[1];
} }
#endregion #endregion
@@ -6,31 +6,21 @@ namespace Artemis.Profiles.Layers.Models
public class TweenModel public class TweenModel
{ {
private readonly LayerModel _layerModel; private readonly LayerModel _layerModel;
private Tweener<float> _xTweener;
private Tweener<float> _yTweener;
private float _width;
private Tweener<float> _widthTweener;
private float _height; private float _height;
private Tweener<float> _heightTweener; private Tweener<float> _heightTweener;
private float _opacity; private float _opacity;
private Tweener<float> _opacityTweener; private Tweener<float> _opacityTweener;
private float _x; private float _width;
private float _y; private Tweener<float> _widthTweener;
private Tweener<float> _xTweener;
private Tweener<float> _yTweener;
public TweenModel(LayerModel layerModel) public TweenModel(LayerModel layerModel)
{ {
_layerModel = layerModel; _layerModel = layerModel;
_xTweener = new Tweener<float>((float) layerModel.X, (float) layerModel.X, 0); _width = (float) _layerModel.Width;
_yTweener = new Tweener<float>((float) layerModel.Y, (float) layerModel.Y, 0); _height = (float) _layerModel.Height;
_widthTweener = new Tweener<float>((float) layerModel.Width, (float) layerModel.Width, 0); _opacity = (float) _layerModel.Opacity;
_heightTweener = new Tweener<float>((float) layerModel.Height, (float) layerModel.Height, 0);
_opacityTweener = new Tweener<float>((float) layerModel.Opacity, (float) layerModel.Opacity, 0);
_x = (float)_layerModel.X;
_y = (float)_layerModel.Y;
_width = (float)_layerModel.Width;
_height = (float)_layerModel.Height;
_opacity = (float)_layerModel.Opacity;
} }
public void Update() public void Update()
@@ -42,24 +32,31 @@ namespace Artemis.Profiles.Layers.Models
private void UpdateWidth() private void UpdateWidth()
{ {
if (_layerModel.Properties.WidthEaseTime < 0.001) if (_layerModel.Properties.WidthEaseTime < 0.001)
return; return;
// Width if (_widthTweener == null)
if (Math.Abs(_layerModel.Width - _width) > 0.001)
{ {
var widthFunc = GetEaseFunction(_layerModel.Properties.WidthEase); var widthFunc = GetEaseFunction(_layerModel.Properties.WidthEase);
var widthSpeed = _layerModel.Properties.WidthEaseTime; var widthSpeed = _layerModel.Properties.WidthEaseTime;
_xTweener = new Tweener<float>(_xTweener.Value, (float)_layerModel.X, widthSpeed, widthFunc); _xTweener = new Tweener<float>(0, (float) _layerModel.X, widthSpeed, widthFunc, LerpFuncFloat);
_widthTweener = new Tweener<float>(_widthTweener.Value, (float)_layerModel.Width, widthSpeed, widthFunc); _widthTweener = new Tweener<float>(0, (float) _layerModel.Width, widthSpeed, widthFunc, LerpFuncFloat);
}
// Width
if (Math.Abs(_layerModel.Width - _width) > 0.001)
{
_xTweener.Reset((float) _layerModel.X);
_xTweener.Start();
_widthTweener.Reset((float) _layerModel.Width);
_widthTweener.Start();
} }
_xTweener.Update(40); _xTweener.Update(40);
_widthTweener.Update(40); _widthTweener.Update(40);
_x = (float) _layerModel.X; _width = (float) _layerModel.Width;
_width = (float)_layerModel.Width;
_layerModel.X = _xTweener.Value; _layerModel.X = _xTweener.Value;
_layerModel.Width = _widthTweener.Value; _layerModel.Width = _widthTweener.Value;
@@ -70,20 +67,28 @@ namespace Artemis.Profiles.Layers.Models
if (_layerModel.Properties.HeightEaseTime < 0.001) if (_layerModel.Properties.HeightEaseTime < 0.001)
return; return;
// Height if (_heightTweener == null)
if (Math.Abs(_layerModel.Height - _height) > 0.001)
{ {
var heightFunc = GetEaseFunction(_layerModel.Properties.HeightEase); var heightFunc = GetEaseFunction(_layerModel.Properties.HeightEase);
var heightSpeed = _layerModel.Properties.HeightEaseTime; var heightSpeed = _layerModel.Properties.HeightEaseTime;
_yTweener = new Tweener<float>(_y, (float)_layerModel.Y, heightSpeed, heightFunc); _yTweener = new Tweener<float>(0, (float) _layerModel.Y, heightSpeed, heightFunc, LerpFuncFloat);
_heightTweener = new Tweener<float>(_height, (float)_layerModel.Height, heightSpeed, heightFunc); _heightTweener = new Tweener<float>(0, (float) _layerModel.Height, heightSpeed, heightFunc,
LerpFuncFloat);
}
// Height
if (Math.Abs(_layerModel.Height - _height) > 0.001)
{
_yTweener.Reset((float) _layerModel.Y);
_yTweener.Start();
_heightTweener.Reset((float) _layerModel.Height);
_heightTweener.Start();
} }
_yTweener.Update(40); _yTweener.Update(40);
_heightTweener.Update(40); _heightTweener.Update(40);
_y = (float)_layerModel.Y; _height = (float) _layerModel.Height;
_height = (float)_layerModel.Height;
_layerModel.Y = _yTweener.Value; _layerModel.Y = _yTweener.Value;
_layerModel.Height = _heightTweener.Value; _layerModel.Height = _heightTweener.Value;
@@ -94,16 +99,24 @@ namespace Artemis.Profiles.Layers.Models
if (_layerModel.Properties.OpacityEaseTime < 0.001) if (_layerModel.Properties.OpacityEaseTime < 0.001)
return; return;
if (_opacityTweener == null)
{
var opacityFunc = GetEaseFunction(_layerModel.Properties.OpacityEase);
var opacitySpeed = _layerModel.Properties.OpacityEaseTime;
_opacityTweener = new Tweener<float>(0, (float) _layerModel.Opacity, opacitySpeed, opacityFunc,
LerpFuncFloat);
}
// Opacity // Opacity
if (Math.Abs(_layerModel.Opacity - _opacity) > 0.001) if (Math.Abs(_layerModel.Opacity - _opacity) > 0.001)
{ {
_opacityTweener = new Tweener<float>(_opacity, (float)_layerModel.Opacity, _opacityTweener.Reset((float) _layerModel.Opacity);
_layerModel.Properties.OpacityEaseTime, GetEaseFunction(_layerModel.Properties.OpacityEase)); _opacityTweener.Start();
} }
_opacityTweener.Update(40); _opacityTweener.Update(40);
_opacity = (float)_layerModel.Opacity; _opacity = (float) _layerModel.Opacity;
_layerModel.Opacity = _opacityTweener.Value; _layerModel.Opacity = _opacityTweener.Value;
} }
@@ -122,5 +135,10 @@ namespace Artemis.Profiles.Layers.Models
return Ease.Linear; return Ease.Linear;
} }
} }
private static float LerpFuncFloat(float start, float end, float percent)
{
return start + (end - start) * percent;
}
} }
} }
@@ -63,7 +63,7 @@ namespace Artemis.Profiles.Lua.Modules
{ {
try try
{ {
var wrapper = new LuaDrawWrapper(e.DrawingContext); var wrapper = new LuaDrawWrapper(e.DrawingContext, e.UpdateType);
var args = new LuaDeviceDrawingEventArgs(e.UpdateType, e.DataModel, e.Preview, wrapper); var args = new LuaDeviceDrawingEventArgs(e.UpdateType, e.DataModel, e.Preview, wrapper);
LuaInvoke(_profileModel, () => OnDeviceDrawing(LuaManager.ProfileModule, args)); LuaInvoke(_profileModel, () => OnDeviceDrawing(LuaManager.ProfileModule, args));
} }
@@ -13,21 +13,24 @@ namespace Artemis.Profiles.Lua.Wrappers
[MoonSharpUserData] [MoonSharpUserData]
public class LuaDrawWrapper public class LuaDrawWrapper
{ {
private readonly DrawingContext _ctx; private static readonly FontFamily Font = new FontFamily(new Uri("pack://application:,,,/"),
private readonly FontFamily _font; "./resources/#Silkscreen");
public LuaDrawWrapper(DrawingContext ctx) private readonly DrawingContext _ctx;
private readonly int _scale;
public LuaDrawWrapper(DrawingContext ctx, string updateType)
{ {
_ctx = ctx; _ctx = ctx;
_font = new FontFamily(new Uri("pack://application:,,,/"), "./resources/#Silkscreen"); _scale = updateType == "keyboard" ? 4 : 2;
} }
public void DrawEllipse(LuaBrush luaBrush, double x, double y, double height, double width) public void DrawEllipse(LuaBrush luaBrush, double x, double y, double height, double width)
{ {
x *= 4; x *= _scale;
y *= 4; y *= _scale;
height *= 4; height *= _scale;
width *= 4; width *= _scale;
var center = new Point(x + width / 2, y + height / 2); var center = new Point(x + width / 2, y + height / 2);
_ctx.DrawEllipse(luaBrush.Brush, new Pen(), center, width, height); _ctx.DrawEllipse(luaBrush.Brush, new Pen(), center, width, height);
@@ -36,37 +39,37 @@ namespace Artemis.Profiles.Lua.Wrappers
public void DrawLine(LuaBrush luaBrush, double startX, double startY, double endX, double endY, public void DrawLine(LuaBrush luaBrush, double startX, double startY, double endX, double endY,
double thickness) double thickness)
{ {
startX *= 4; startX *= _scale;
startY *= 4; startY *= _scale;
endX *= 4; endX *= _scale;
endY *= 4; endY *= _scale;
thickness *= 4; thickness *= _scale;
_ctx.DrawLine(new Pen(luaBrush.Brush, thickness), new Point(startX, startY), new Point(endX, endY)); _ctx.DrawLine(new Pen(luaBrush.Brush, thickness), new Point(startX, startY), new Point(endX, endY));
} }
public void DrawRectangle(LuaBrush luaBrush, double x, double y, double height, double width) public void DrawRectangle(LuaBrush luaBrush, double x, double y, double height, double width)
{ {
x *= 4; x *= _scale;
y *= 4; y *= _scale;
height *= 4; height *= _scale;
width *= 4; width *= _scale;
_ctx.DrawRectangle(luaBrush.Brush, new Pen(), new Rect(x, y, width, height)); _ctx.DrawRectangle(luaBrush.Brush, new Pen(), new Rect(x, y, width, height));
} }
public double DrawText(LuaBrush luaBrush, double x, double y, string text, int fontSize) public double DrawText(LuaBrush luaBrush, double x, double y, string text, int fontSize)
{ {
x *= 4; x *= _scale;
y *= 4; y *= _scale;
fontSize *= 4; fontSize *= _scale;
var typeFace = new Typeface(_font, new FontStyle(), new FontWeight(), new FontStretch()); var typeFace = new Typeface(Font, new FontStyle(), new FontWeight(), new FontStretch());
var formatted = new FormattedText(text, CultureInfo.InvariantCulture, FlowDirection.LeftToRight, typeFace, var formatted = new FormattedText(text, CultureInfo.InvariantCulture, FlowDirection.LeftToRight, typeFace,
fontSize, luaBrush.Brush); fontSize, luaBrush.Brush);
_ctx.DrawText(formatted, new Point(x, y)); _ctx.DrawText(formatted, new Point(x, y));
return formatted.Width / 4; return formatted.Width / _scale;
} }
} }
} }
+14 -15
View File
@@ -111,24 +111,23 @@ namespace Artemis.Profiles
return; return;
// Setup the DrawingVisual's size // Setup the DrawingVisual's size
using (var c = deviceVisualModel.RenderOpen()) var c = deviceVisualModel.GetDrawingContext();
{
c.PushClip(new RectangleGeometry(deviceVisualModel.Rect));
c.DrawRectangle(new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)), null, deviceVisualModel.Rect);
// Update the layers c.PushClip(new RectangleGeometry(deviceVisualModel.Rect));
foreach (var layerModel in renderLayers) c.DrawRectangle(new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)), null, deviceVisualModel.Rect);
layerModel.Update(dataModel, preview, true);
RaiseDeviceUpdatedEvent(new ProfileDeviceEventsArg(deviceVisualModel.DrawType, dataModel, preview, null));
// Draw the layers // Update the layers
foreach (var layerModel in renderLayers) foreach (var layerModel in renderLayers)
layerModel.Draw(dataModel, c, preview, true); layerModel.Update(dataModel, preview, true);
RaiseDeviceDrawnEvent(new ProfileDeviceEventsArg(deviceVisualModel.DrawType, dataModel, preview, c)); RaiseDeviceUpdatedEvent(new ProfileDeviceEventsArg(deviceVisualModel.DrawType, dataModel, preview, null));
// Remove the clip // Draw the layers
c.Pop(); foreach (var layerModel in renderLayers)
} layerModel.Draw(dataModel, c, preview, true);
RaiseDeviceDrawnEvent(new ProfileDeviceEventsArg(deviceVisualModel.DrawType, dataModel, preview, c));
// Remove the clip
c.Pop();
} }
private void RaiseDeviceUpdatedEvent(ProfileDeviceEventsArg e) private void RaiseDeviceUpdatedEvent(ProfileDeviceEventsArg e)
+2 -2
View File
@@ -53,7 +53,7 @@ using System.Windows;
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.8.0.2")] [assembly: AssemblyVersion("1.8.1.0")]
[assembly: AssemblyFileVersion("1.8.0.2")] [assembly: AssemblyFileVersion("1.8.1.0")]
[assembly: InternalsVisibleTo("Artemis.Explorables")] [assembly: InternalsVisibleTo("Artemis.Explorables")]
+1 -1
View File
@@ -103,7 +103,7 @@ namespace Artemis.Settings
try try
{ {
if (Autorun) if (Autorun)
mgr.CreateShortcutsForExecutable("Artemis.exe", ShortcutLocation.Startup, false); mgr.CreateShortcutsForExecutable("Artemis.exe", ShortcutLocation.Startup, false, "--autorun");
else else
mgr.RemoveShortcutsForExecutable("Artemis.exe", ShortcutLocation.Startup); mgr.RemoveShortcutsForExecutable("Artemis.exe", ShortcutLocation.Startup);
} }
+1 -1
View File
@@ -6,7 +6,7 @@
<package id="Castle.Core" version="3.3.3" targetFramework="net452" /> <package id="Castle.Core" version="3.3.3" targetFramework="net452" />
<package id="Colore" version="5.1.0" targetFramework="net461" /> <package id="Colore" version="5.1.0" targetFramework="net461" />
<package id="CSCore" version="1.1.0" targetFramework="net461" /> <package id="CSCore" version="1.1.0" targetFramework="net461" />
<package id="CUE.NET" version="1.1.1" targetFramework="net461" /> <package id="CUE.NET" version="1.1.2.1" targetFramework="net461" />
<package id="DeltaCompressionDotNet" version="1.1.0" targetFramework="net461" /> <package id="DeltaCompressionDotNet" version="1.1.0" targetFramework="net461" />
<package id="DynamicExpresso.Core" version="1.3.3.5" targetFramework="net461" /> <package id="DynamicExpresso.Core" version="1.3.3.5" targetFramework="net461" />
<package id="gong-wpf-dragdrop" version="0.1.4.3" targetFramework="net461" /> <package id="gong-wpf-dragdrop" version="0.1.4.3" targetFramework="net461" />