1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

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 2017-02-03 19:32:24 +01:00
parent d4ca54a35a
commit 7373bad446
12 changed files with 136 additions and 80 deletions

View File

@ -159,8 +159,8 @@
<HintPath>..\packages\CSCore.1.1.0\lib\net35-client\CSCore.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="CUE.NET, Version=1.1.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\CUE.NET.1.1.1\lib\net45\CUE.NET.dll</HintPath>
<Reference Include="CUE.NET, Version=1.1.2.1, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\CUE.NET.1.1.2.1\lib\net45\CUE.NET.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="DeltaCompressionDotNet, Version=1.1.0.0, Culture=neutral, PublicKeyToken=1d14d6e5194e7f4a, processorArchitecture=MSIL">
@ -1035,12 +1035,12 @@
<Folder Include="Resources\Lua\" />
</ItemGroup>
<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">
<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>
</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>
<!-- 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.

View File

@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
@ -15,6 +17,8 @@ using Artemis.ViewModels;
using Caliburn.Micro;
using Newtonsoft.Json;
using Ninject;
using NLog;
using LogManager = NLog.LogManager;
namespace Artemis
{
@ -80,6 +84,13 @@ namespace Artemis
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.Bind<IWindowManager>().To<WindowManager>().InSingletonScope();

View File

@ -11,6 +11,7 @@ namespace Artemis.Models
{
private readonly int _x;
private readonly KeyboardProvider _keyboard;
private DrawingContext _ctx;
public DeviceVisualModel(DrawType drawType, int x)
{
@ -59,5 +60,16 @@ namespace Artemis.Models
return bitmap;
}
public DrawingContext GetDrawingContext()
{
return _ctx ?? (_ctx = RenderOpen());
}
public void CloseDrawingContext()
{
_ctx?.Close();
_ctx = null;
}
}
}

View File

@ -82,13 +82,26 @@ namespace Artemis.Models
c.DrawRectangle(new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)), null, _rect);
if (MouseModel != null)
{
MouseModel.CloseDrawingContext();
c.DrawRectangle(new VisualBrush(MouseModel), new Pen(), MouseModel.RelativeRect);
}
if (HeadsetModel != null)
{
HeadsetModel.CloseDrawingContext();
c.DrawRectangle(new VisualBrush(HeadsetModel), new Pen(), HeadsetModel.RelativeRect);
}
if (GenericModel != null)
{
GenericModel.CloseDrawingContext();
c.DrawRectangle(new VisualBrush(GenericModel), new Pen(), GenericModel.RelativeRect);
}
if (MousematModel != null)
{
MousematModel.CloseDrawingContext();
c.DrawRectangle(new VisualBrush(MousematModel), new Pen(), MousematModel.RelativeRect);
}
KeyboardModel.CloseDrawingContext();
c.DrawRectangle(new VisualBrush(KeyboardModel), new Pen(), KeyboardModel.RelativeRect);
c.Pop();

View File

@ -119,7 +119,7 @@ namespace Artemis.Modules.General.GeneralProfile
var peakValues = _playbackInfo.GetChannelsPeakValues();
dataModel.Audio.Playback.OverallPeak = _playbackInfo.PeakValue;
dataModel.Audio.Playback.LeftPeak = peakValues[0];
dataModel.Audio.Playback.LeftPeak = peakValues[1];
dataModel.Audio.Playback.RightPeak = peakValues[1];
}
#endregion

View File

@ -6,31 +6,21 @@ namespace Artemis.Profiles.Layers.Models
public class TweenModel
{
private readonly LayerModel _layerModel;
private Tweener<float> _xTweener;
private Tweener<float> _yTweener;
private float _width;
private Tweener<float> _widthTweener;
private float _height;
private Tweener<float> _heightTweener;
private float _opacity;
private Tweener<float> _opacityTweener;
private float _x;
private float _y;
private float _width;
private Tweener<float> _widthTweener;
private Tweener<float> _xTweener;
private Tweener<float> _yTweener;
public TweenModel(LayerModel layerModel)
{
_layerModel = layerModel;
_xTweener = new Tweener<float>((float) layerModel.X, (float) layerModel.X, 0);
_yTweener = new Tweener<float>((float) layerModel.Y, (float) layerModel.Y, 0);
_widthTweener = new Tweener<float>((float) layerModel.Width, (float) layerModel.Width, 0);
_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;
_width = (float) _layerModel.Width;
_height = (float) _layerModel.Height;
_opacity = (float) _layerModel.Opacity;
}
public void Update()
@ -42,24 +32,31 @@ namespace Artemis.Profiles.Layers.Models
private void UpdateWidth()
{
if (_layerModel.Properties.WidthEaseTime < 0.001)
if (_layerModel.Properties.WidthEaseTime < 0.001)
return;
// Width
if (Math.Abs(_layerModel.Width - _width) > 0.001)
if (_widthTweener == null)
{
var widthFunc = GetEaseFunction(_layerModel.Properties.WidthEase);
var widthSpeed = _layerModel.Properties.WidthEaseTime;
_xTweener = new Tweener<float>(_xTweener.Value, (float)_layerModel.X, widthSpeed, widthFunc);
_widthTweener = new Tweener<float>(_widthTweener.Value, (float)_layerModel.Width, widthSpeed, widthFunc);
_xTweener = new Tweener<float>(0, (float) _layerModel.X, widthSpeed, widthFunc, LerpFuncFloat);
_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);
_widthTweener.Update(40);
_x = (float) _layerModel.X;
_width = (float)_layerModel.Width;
_width = (float) _layerModel.Width;
_layerModel.X = _xTweener.Value;
_layerModel.Width = _widthTweener.Value;
@ -70,20 +67,28 @@ namespace Artemis.Profiles.Layers.Models
if (_layerModel.Properties.HeightEaseTime < 0.001)
return;
// Height
if (Math.Abs(_layerModel.Height - _height) > 0.001)
if (_heightTweener == null)
{
var heightFunc = GetEaseFunction(_layerModel.Properties.HeightEase);
var heightSpeed = _layerModel.Properties.HeightEaseTime;
_yTweener = new Tweener<float>(_y, (float)_layerModel.Y, heightSpeed, heightFunc);
_heightTweener = new Tweener<float>(_height, (float)_layerModel.Height, heightSpeed, heightFunc);
_yTweener = new Tweener<float>(0, (float) _layerModel.Y, heightSpeed, heightFunc, LerpFuncFloat);
_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);
_heightTweener.Update(40);
_y = (float)_layerModel.Y;
_height = (float)_layerModel.Height;
_height = (float) _layerModel.Height;
_layerModel.Y = _yTweener.Value;
_layerModel.Height = _heightTweener.Value;
@ -94,16 +99,24 @@ namespace Artemis.Profiles.Layers.Models
if (_layerModel.Properties.OpacityEaseTime < 0.001)
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
if (Math.Abs(_layerModel.Opacity - _opacity) > 0.001)
{
_opacityTweener = new Tweener<float>(_opacity, (float)_layerModel.Opacity,
_layerModel.Properties.OpacityEaseTime, GetEaseFunction(_layerModel.Properties.OpacityEase));
_opacityTweener.Reset((float) _layerModel.Opacity);
_opacityTweener.Start();
}
_opacityTweener.Update(40);
_opacity = (float)_layerModel.Opacity;
_opacity = (float) _layerModel.Opacity;
_layerModel.Opacity = _opacityTweener.Value;
}
@ -122,5 +135,10 @@ namespace Artemis.Profiles.Layers.Models
return Ease.Linear;
}
}
private static float LerpFuncFloat(float start, float end, float percent)
{
return start + (end - start) * percent;
}
}
}

View File

@ -63,7 +63,7 @@ namespace Artemis.Profiles.Lua.Modules
{
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);
LuaInvoke(_profileModel, () => OnDeviceDrawing(LuaManager.ProfileModule, args));
}

View File

@ -13,21 +13,24 @@ namespace Artemis.Profiles.Lua.Wrappers
[MoonSharpUserData]
public class LuaDrawWrapper
{
private readonly DrawingContext _ctx;
private readonly FontFamily _font;
private static readonly FontFamily Font = new FontFamily(new Uri("pack://application:,,,/"),
"./resources/#Silkscreen");
public LuaDrawWrapper(DrawingContext ctx)
private readonly DrawingContext _ctx;
private readonly int _scale;
public LuaDrawWrapper(DrawingContext ctx, string updateType)
{
_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)
{
x *= 4;
y *= 4;
height *= 4;
width *= 4;
x *= _scale;
y *= _scale;
height *= _scale;
width *= _scale;
var center = new Point(x + width / 2, y + height / 2);
_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,
double thickness)
{
startX *= 4;
startY *= 4;
endX *= 4;
endY *= 4;
thickness *= 4;
startX *= _scale;
startY *= _scale;
endX *= _scale;
endY *= _scale;
thickness *= _scale;
_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)
{
x *= 4;
y *= 4;
height *= 4;
width *= 4;
x *= _scale;
y *= _scale;
height *= _scale;
width *= _scale;
_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)
{
x *= 4;
y *= 4;
fontSize *= 4;
x *= _scale;
y *= _scale;
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,
fontSize, luaBrush.Brush);
_ctx.DrawText(formatted, new Point(x, y));
return formatted.Width / 4;
return formatted.Width / _scale;
}
}
}

View File

@ -111,24 +111,23 @@ namespace Artemis.Profiles
return;
// Setup the DrawingVisual's size
using (var c = deviceVisualModel.RenderOpen())
{
c.PushClip(new RectangleGeometry(deviceVisualModel.Rect));
c.DrawRectangle(new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)), null, deviceVisualModel.Rect);
var c = deviceVisualModel.GetDrawingContext();
// Update the layers
foreach (var layerModel in renderLayers)
layerModel.Update(dataModel, preview, true);
RaiseDeviceUpdatedEvent(new ProfileDeviceEventsArg(deviceVisualModel.DrawType, dataModel, preview, null));
c.PushClip(new RectangleGeometry(deviceVisualModel.Rect));
c.DrawRectangle(new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)), null, deviceVisualModel.Rect);
// Draw the layers
foreach (var layerModel in renderLayers)
layerModel.Draw(dataModel, c, preview, true);
RaiseDeviceDrawnEvent(new ProfileDeviceEventsArg(deviceVisualModel.DrawType, dataModel, preview, c));
// Update the layers
foreach (var layerModel in renderLayers)
layerModel.Update(dataModel, preview, true);
RaiseDeviceUpdatedEvent(new ProfileDeviceEventsArg(deviceVisualModel.DrawType, dataModel, preview, null));
// Remove the clip
c.Pop();
}
// Draw the layers
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)

View File

@ -53,7 +53,7 @@ using System.Windows;
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.8.0.2")]
[assembly: AssemblyFileVersion("1.8.0.2")]
[assembly: AssemblyVersion("1.8.1.0")]
[assembly: AssemblyFileVersion("1.8.1.0")]
[assembly: InternalsVisibleTo("Artemis.Explorables")]

View File

@ -103,7 +103,7 @@ namespace Artemis.Settings
try
{
if (Autorun)
mgr.CreateShortcutsForExecutable("Artemis.exe", ShortcutLocation.Startup, false);
mgr.CreateShortcutsForExecutable("Artemis.exe", ShortcutLocation.Startup, false, "--autorun");
else
mgr.RemoveShortcutsForExecutable("Artemis.exe", ShortcutLocation.Startup);
}

View File

@ -6,7 +6,7 @@
<package id="Castle.Core" version="3.3.3" targetFramework="net452" />
<package id="Colore" version="5.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="DynamicExpresso.Core" version="1.3.3.5" targetFramework="net461" />
<package id="gong-wpf-dragdrop" version="0.1.4.3" targetFramework="net461" />