Files
McSchneidar cf2fa796e2 .NET10 Migration (#946)
Runtime and build
- Move all projects to .NET 10 with SDK-style project files and a shared
  Directory.Build.props (WIN/LINUX, x86/x64 defines)
- Load managed and unmanaged dependencies from libs/managed and
  libs/unmanaged through assembly and native library resolvers
- Compile party modes with Roslyn instead of CodeDom
- Update AppVeyor to the .NET 10 SDK and dotnet test
- Download the FFmpeg and gstreamer runtimes from the dependencies
  repository during the build
- Remove the VC++ 2015-2022 runtime check, no dependency needs it anymore

Graphics and windowing
- Replace the Direct3D 9 renderer with Direct3D 11 (Vortice)
- Pace Direct3D 11 frames with a frame latency waitable swap chain
- Move window, input and message boxes to SDL3
- Replace System.Drawing with SkiaSharp and WinForms with SDL3 and a
  software renderer

Video and audio
- Replace Acinerella with FFmpeg 8.1.3 (FFmpeg.AutoGen)
- Add hardware accelerated video decoding (D3D11VA, DXVA2, VideoToolbox,
  VAAPI, VDPAU) with software fallback
- Convert YUV video frames to RGB on the GPU in Direct3D 11 and OpenGL
- Add the video options HardwareDecoding, GpuColorConversion,
  DecoderThreads and VideoDownscaleResolution
- Update OpenAL to OpenTK 4 and NAudio recording to WasapiRecorder

Fixes
- Fix the song preview start and shorten the reporter buttons
- Fix a crash when opening the highscore without a selected song
- Use the options slide highlight in the party mode screens to avoid
  brightness flicker on VRR displays
- Disable GameInput in the x86 build, SDL3 crashes in GameInputCreate
  on 32-bit systems with the GameInput runtime installed
- Fix a truncation warning in PitchTracker
2026-11-02 08:11:20 +01:00

286 lines
9.1 KiB
C#

#region license
// This file is part of Vocaluxe.
//
// Vocaluxe is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Vocaluxe is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
#endregion
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using SkiaSharp;
namespace VocaluxeLib
{
public static class CExtensions
{
/// <summary>
/// Makes sure val is between min and max
/// Asserts that min&lt;=max
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="val"></param>
/// <param name="min"></param>
/// <param name="max"></param>
/// <returns>Clamped value</returns>
public static T Clamp<T>(this T val, T min, T max) where T : IComparable<T>
{
Debug.Assert(min.CompareTo(max) <= 0);
if (val.CompareTo(min) < 0)
{
return min;
}
if (val.CompareTo(max) > 0)
{
return max;
}
return val;
}
/// <summary>
/// Makes sure val is between min and max but also handles the case where min&gt;max
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="val"></param>
/// <param name="min"></param>
/// <param name="max"></param>
/// <param name="preferMin"></param>
/// <returns>Clamped value</returns>
public static T Clamp<T>(this T val, T min, T max, bool preferMin) where T : IComparable<T>
{
if (min.CompareTo(max) > 0)
{
if (preferMin)
{
max = min;
}
else
{
min = max;
}
}
return Clamp(val, min, max);
}
/// <summary>
/// Checks if the value is in the specified range
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="val"></param>
/// <param name="min"></param>
/// <param name="max"></param>
/// <returns></returns>
public static bool IsInRange<T>(this T val, T min, T max) where T : IComparable<T>
{
Debug.Assert(min.CompareTo(max) <= 0);
return min.CompareTo(val) <= 0 && max.CompareTo(val) >= 0;
}
/// <summary>
/// Resizes the given list to the given size. Removes elements or adds default values
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="list"></param>
/// <param name="size"></param>
/// <param name="defaultValue"></param>
public static void Resize<T>(this List<T> list, int size, T defaultValue = default(T))
{
var curSize = list.Count;
if (size < curSize)
{
list.RemoveRange(size, curSize - size);
}
else if (size > curSize)
{
list.AddRange(Enumerable.Repeat(defaultValue, size - curSize));
}
}
/// <summary>
/// Makes the list at least the given size adding the given default values.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="list"></param>
/// <param name="size"></param>
/// <param name="defaultValue"></param>
public static void EnsureSize<T>(this List<T> list, int size, T defaultValue)
{
var curSize = list.Count;
if (size > curSize)
{
list.AddRange(Enumerable.Repeat(defaultValue, size - curSize));
}
}
/// <summary>
/// Makes the list at least the given size adding a new instance of T
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="list"></param>
/// <param name="size"></param>
public static void EnsureSize<T>(this List<T> list, int size) where T : new()
{
if (size > list.Count)
{
list.Add(new T());
}
}
/// <summary>
/// Gets all set bits starting from lowest (Bit 0)
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static IEnumerable<int> GetSetBits(this int value)
{
var result = new List<int>();
var curBit = 0;
//Evaluate as bitset
while (value > 0)
{
if ((value & 1) != 0)
{
result.Add(curBit);
}
value >>= 1;
curBit++;
}
return result;
}
public static bool ContainsIgnoreCase(this string value, string other)
{
return value.IndexOf(other, StringComparison.CurrentCultureIgnoreCase) >= 0;
}
private static Regex _MultipleWhiteSpaceRegEx = new Regex(@" {2,}");
public static string TrimMultipleWs(this string value)
{
if (string.IsNullOrEmpty(value))
{
return "";
}
return _MultipleWhiteSpaceRegEx.Replace(value, " ");
}
/// <summary>
/// Converts value to a string in fixed point notation using invariant formating (english style decimal point)
/// </summary>
/// <param name="value">Value to be converted</param>
/// <returns>String representation of value</returns>
public static string ToInvariantString(this float value)
{
return value.ToString("F", NumberFormatInfo.InvariantInfo);
}
public static SRectF Scale(this SRectF rect, float scale)
{
return new SRectF(
rect.X - rect.W * (scale - 1f) * 0.5f,
rect.Y - rect.H * (scale - 1f) * 0.5f,
rect.W * scale,
rect.H * scale,
rect.Z);
}
public static List<T> Shuffle<T>(this List<T> list)
{
for (var n = list.Count - 1; n >= 1; n--)
{
var k = CBase.Game.GetRandom(n);
var value = list[k];
list[k] = list[n];
list[n] = value;
}
return list;
}
public static Size GetSize(this SKBitmap bmp)
{
return new Size(bmp.Width, bmp.Height);
}
public static Rectangle GetRect(this SKBitmap bmp)
{
return new Rectangle(0, 0, bmp.Width, bmp.Height);
}
/// <summary>
/// Resizes the bitmap to the given size creating a copy of it
/// </summary>
/// <param name="bmp"></param>
/// <param name="newSize"></param>
/// <returns>Resized bitmap or null on error</returns>
public static SKBitmap Resize(this SKBitmap bmp, Size newSize)
{
SKBitmap result = null;
try
{
//Create a new Bitmap with the new sizes
result = new SKBitmap(newSize.Width, newSize.Height, SKColorType.Bgra8888, SKAlphaType.Premul);
//Scale the texture
using (var canvas = new SKCanvas(result))
using (var image = SKImage.FromBitmap(bmp))
{
canvas.Clear(SKColors.Transparent);
canvas.DrawImage(image, new SKRect(0, 0, newSize.Width, newSize.Height), new SKSamplingOptions(SKCubicResampler.Mitchell));
}
}
catch (Exception)
{
if (result != null)
{
result.Dispose();
result = null;
}
}
return result;
}
public static SKBitmap ToBgra(this SKBitmap bmp)
{
if (bmp.ColorType == SKColorType.Bgra8888 && bmp.AlphaType != SKAlphaType.Premul && bmp.RowBytes == bmp.Width * 4)
{
return bmp;
}
var result = new SKBitmap(new SKImageInfo(bmp.Width, bmp.Height, SKColorType.Bgra8888, SKAlphaType.Unpremul));
bmp.CopyPixelsTo(result);
return result;
}
public static void CopyPixelsTo(this SKBitmap bmp, SKBitmap target)
{
using (var pixmap = bmp.PeekPixels())
{
pixmap.ReadPixels(target.Info.WithSize(bmp.Width, bmp.Height), target.GetPixels(), target.RowBytes, 0, 0);
}
target.NotifyPixelsChanged();
}
}
}