diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index b410fbd8b..0c5eae395 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -1,2 +1,4 @@ # Normalize all the line endings 7a598af5b92ef76e9a542170befd89ba2556a97c +# Enabled NRT globally +ba1385330cc501f34937e08257e586c84e35d772 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 36e156c2a..1059d5d52 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,10 +31,10 @@ jobs: uses: actions/cache@v3 with: path: ${{ github.workspace }}/inspectcode - key: inspectcode-${{ hashFiles('.config/dotnet-tools.json', '.github/workflows/ci.yml', 'osu-framework.sln*', '.editorconfig', '.globalconfig') }} + key: inspectcode-${{ hashFiles('.config/dotnet-tools.json', '.github/workflows/ci.yml', 'osu-framework.sln*', 'osu-framework*.slnf', '.editorconfig', '.globalconfig', 'CodeAnalysis/*', '**/*.csproj', '**/*.props') }} - name: Dotnet code style - run: dotnet build -c Debug -warnaserror build/Desktop.proj -p:EnforceCodeStyleInBuild=true + run: dotnet build -c Debug -warnaserror osu-framework.Desktop.slnf -p:EnforceCodeStyleInBuild=true - name: CodeFileSanity run: | @@ -78,20 +78,11 @@ jobs: with: dotnet-version: "6.0.x" - # FIXME: libavformat is not included in Ubuntu. Let's fix that. - # https://github.com/ppy/osu-framework/issues/4349 - # Remove this once https://github.com/actions/virtual-environments/issues/3306 has been resolved. - - name: Install libavformat-dev - if: ${{matrix.os.fullname == 'ubuntu-latest'}} - run: | - sudo apt-get update && \ - sudo apt-get -y install libavformat-dev - - name: Compile - run: dotnet build -c Debug -warnaserror build/Desktop.proj + run: dotnet build -c Debug -warnaserror osu-framework.Desktop.slnf - name: Test - run: dotnet test $pwd/*.Tests/bin/Debug/*/*.Tests.dll --settings $pwd/build/vstestconfig.runsettings --logger "trx;LogFileName=TestResults-${{matrix.os.prettyname}}-${{matrix.threadingMode}}.trx" + run: dotnet test $pwd/**/*.Tests/bin/Debug/*/*.Tests.dll --settings $pwd/build/vstestconfig.runsettings --logger "trx;LogFileName=TestResults-${{matrix.os.prettyname}}-${{matrix.threadingMode}}.trx" shell: pwsh # Attempt to upload results even if test fails. diff --git a/.gitignore b/.gitignore index 47d05197a..9e77922eb 100644 --- a/.gitignore +++ b/.gitignore @@ -335,4 +335,6 @@ fabric.properties # inspectcode inspectcodereport.xml -inspectcode \ No newline at end of file +inspectcode + +.idea/.idea.osu-framework.Desktop/.idea/misc.xml \ No newline at end of file diff --git a/.idea/.idea.osu-framework.Desktop/.idea/misc.xml b/.idea/.idea.osu-framework.Desktop/.idea/misc.xml deleted file mode 100644 index 4e1d56f4d..000000000 --- a/.idea/.idea.osu-framework.Desktop/.idea/misc.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/CodeAnalysis/BannedSymbols.txt b/CodeAnalysis/BannedSymbols.txt index d0f8b84ff..5da0fb36c 100644 --- a/CodeAnalysis/BannedSymbols.txt +++ b/CodeAnalysis/BannedSymbols.txt @@ -5,4 +5,8 @@ T:System.IComparable;Don't use non-generic IComparable. Use generic version inst M:System.Enum.HasFlag(System.Enum);Use osu.Framework.Extensions.EnumExtensions.HasFlagFast() instead. F:System.UriKind.RelativeOrAbsolute;Incompatible results when run on mono (see https://www.mono-project.com/docs/faq/known-issues/urikind-relativeorabsolute/). Use Validation.TryParseUri(string, out Uri?) instead. M:System.Threading.Tasks.Task.Wait();Don't use Task.Wait. Use Task.WaitSafely() to ensure we avoid deadlocks. +M:System.Guid.#ctor;Probably meaning to use Guid.NewGuid() instead. If actually wanting empty, use Guid.Empty. P:System.Threading.Tasks.Task`1.Result;Don't use Task.Result. Use Task.GetResultSafely() to ensure we avoid deadlocks. +M:System.Threading.ManualResetEventSlim.Wait();Specify a timeout to avoid waiting forever. +M:System.String.ToLower();string.ToLower() changes behaviour depending on CultureInfo.CurrentCulture. Use string.ToLowerInvariant() instead. If wanting culture-sensitive behaviour, explicitly provide CultureInfo.CurrentCulture or use LocalisableString. +M:System.String.ToUpper();string.ToUpper() changes behaviour depending on CultureInfo.CurrentCulture. Use string.ToUpperInvariant() instead. If wanting culture-sensitive behaviour, explicitly provide CultureInfo.CurrentCulture or use LocalisableString. diff --git a/Directory.Build.props b/Directory.Build.props index 949100ad3..c683a4edf 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,8 +1,9 @@  - 8.0 + 9.0 true + enable diff --git a/SampleGame.Android/SampleGameActivity.cs b/SampleGame.Android/SampleGameActivity.cs index 737761bbc..bdb800d5d 100644 --- a/SampleGame.Android/SampleGameActivity.cs +++ b/SampleGame.Android/SampleGameActivity.cs @@ -7,7 +7,7 @@ using osu.Framework.Android; namespace SampleGame.Android { - [Activity(ConfigurationChanges = DEFAULT_CONFIG_CHANGES, LaunchMode = DEFAULT_LAUNCH_MODE, MainLauncher = true)] + [Activity(ConfigurationChanges = DEFAULT_CONFIG_CHANGES, Exported = true, LaunchMode = DEFAULT_LAUNCH_MODE, MainLauncher = true)] public class SampleGameActivity : AndroidGameActivity { protected override Game CreateGame() => new SampleGameGame(); diff --git a/SampleGame.Desktop/Program.cs b/SampleGame.Desktop/Program.cs index 4756edbaa..4abb66826 100644 --- a/SampleGame.Desktop/Program.cs +++ b/SampleGame.Desktop/Program.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework; using osu.Framework.Platform; diff --git a/SampleGame.iOS/AppDelegate.cs b/SampleGame.iOS/AppDelegate.cs index 1a23fbd0d..b61109ea7 100644 --- a/SampleGame.iOS/AppDelegate.cs +++ b/SampleGame.iOS/AppDelegate.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using Foundation; using osu.Framework; using osu.Framework.iOS; diff --git a/SampleGame.iOS/Application.cs b/SampleGame.iOS/Application.cs index 1a7820095..5e3c85fbc 100644 --- a/SampleGame.iOS/Application.cs +++ b/SampleGame.iOS/Application.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.iOS; using UIKit; diff --git a/SampleGame/SampleGameGame.cs b/SampleGame/SampleGameGame.cs index 3b97ebaee..a090d0972 100644 --- a/SampleGame/SampleGameGame.cs +++ b/SampleGame/SampleGameGame.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework; using osu.Framework.Graphics; using osuTK; diff --git a/appveyor_deploy.yml b/appveyor_deploy.yml index 99b47b44d..90fe8769c 100644 --- a/appveyor_deploy.yml +++ b/appveyor_deploy.yml @@ -1,10 +1,50 @@ clone_depth: 1 version: '{build}' -image: Visual Studio 2022 test: off skip_non_tags: true -build_script: - - cmd: PowerShell -Version 2.0 .\build.ps1 -Target DeployFrameworkDesktop + +environment: + matrix: + - job_name: framework-desktop + job_group: framework-base + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022 + - job_name: framework-xamarin + job_group: framework-base + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 + - job_name: templates + job_depends_on: framework-base + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022 + +nuget: + project_feed: true + +for: + - + matrix: + only: + - job_name: framework-desktop + build_script: + - cmd: PowerShell -Version 2.0 .\build.ps1 -Target DeployFrameworkDesktop + - + matrix: + only: + - job_name: framework-xamarin + build_script: + - cmd: PowerShell -Version 2.0 .\build.ps1 -Target DeployFrameworkXamarin + - + matrix: + only: + - job_name: templates + build_script: + - cmd: dotnet remove osu.Framework.Templates\templates\template-empty\TemplateGame.Game\TemplateGame.Game.csproj reference osu.Framework\osu.Framework.csproj + - cmd: dotnet add osu.Framework.Templates\templates\template-empty\TemplateGame.Game\TemplateGame.Game.csproj package ppy.osu.Framework -v %APPVEYOR_REPO_TAG_NAME% + - cmd: dotnet remove osu.Framework.Templates\templates\template-flappy\FlappyDon.Game\FlappyDon.Game.csproj reference osu.Framework\osu.Framework.csproj + - cmd: dotnet add osu.Framework.Templates\templates\template-flappy\FlappyDon.Game\FlappyDon.Game.csproj package ppy.osu.Framework -v %APPVEYOR_REPO_TAG_NAME% + + # Can't use `dotnet add` for legacy Xamarin projects. String-replacement happens inside build.cake instead. + + - cmd: PowerShell -Version 2.0 .\build.ps1 -Target DeployFrameworkTemplates + deploy: - provider: Environment name: nuget diff --git a/appveyor_xamarin_deploy.yml b/appveyor_xamarin_deploy.yml deleted file mode 100644 index ceb5aa32a..000000000 --- a/appveyor_xamarin_deploy.yml +++ /dev/null @@ -1,12 +0,0 @@ -clone_depth: 1 -version: '{build}' -image: Visual Studio 2019 -test: off -skip_non_tags: true -build_script: - - cmd: PowerShell -Version 2.0 .\build.ps1 -Target DeployFrameworkXamarin -deploy: - - provider: Environment - name: nuget - - provider: Environment - name: github diff --git a/build/Desktop.proj b/build/Desktop.proj deleted file mode 100644 index c063e033d..000000000 --- a/build/Desktop.proj +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/build/build.cake b/build/build.cake index a43211210..7b8ccb7a6 100644 --- a/build/build.cake +++ b/build/build.cake @@ -1,4 +1,6 @@ using System.Threading; +using System.Text.RegularExpressions; +#addin "nuget:?package=Cake.FileHelpers&version=3.2.1" #addin "nuget:?package=CodeFileSanity&version=0.0.36" #tool "nuget:?package=Python&version=3.7.2" var pythonPath = GetFiles("./tools/python.*/tools/python.exe").First(); @@ -17,7 +19,6 @@ var tempDirectory = new DirectoryPath("temp"); var artifactsDirectory = rootDirectory.Combine("artifacts"); var sln = rootDirectory.CombineWithFilePath("osu-framework.sln"); -var desktopBuilds = rootDirectory.CombineWithFilePath("build/Desktop.proj"); var desktopSlnf = rootDirectory.CombineWithFilePath("osu-framework.Desktop.slnf"); var frameworkProject = rootDirectory.CombineWithFilePath("osu.Framework/osu.Framework.csproj"); var iosFrameworkProject = rootDirectory.CombineWithFilePath("osu.Framework.iOS/osu.Framework.iOS.csproj"); @@ -82,7 +83,7 @@ Task("RunHttpBin") Task("Compile") .Does(() => { - DotNetCoreBuild(desktopBuilds.FullPath, new DotNetCoreBuildSettings { + DotNetCoreBuild(desktopSlnf.FullPath, new DotNetCoreBuildSettings { Configuration = configuration, Verbosity = DotNetCoreVerbosity.Minimal, }); @@ -187,7 +188,21 @@ Task("PackNativeLibs") }); Task("PackTemplate") - .Does(() => { + .Does(ctx => { + ctx.ReplaceRegexInFiles( + $"{rootDirectory.FullPath}/osu.Framework.Templates/**/*.iOS.csproj", + "^.*osu.Framework.csproj.*$", + $" ", + RegexOptions.Multiline + ); + + ctx.ReplaceRegexInFiles( + $"{rootDirectory.FullPath}/osu.Framework.Templates/**/*.iOS.csproj", + "^.*osu.Framework.iOS.csproj.*$", + $" ", + RegexOptions.Multiline + ); + DotNetCorePack(templateProject.FullPath, new DotNetCorePackSettings{ OutputDirectory = artifactsDirectory, Configuration = configuration, @@ -227,6 +242,11 @@ Task("DeployFrameworkDesktop") .IsDependentOn("Clean") .IsDependentOn("DetermineAppveyorDeployProperties") .IsDependentOn("PackFramework") + .IsDependentOn("Publish"); + +Task("DeployFrameworkTemplates") + .IsDependentOn("Clean") + .IsDependentOn("DetermineAppveyorDeployProperties") .IsDependentOn("PackTemplate") .IsDependentOn("Publish"); diff --git a/osu-framework.Android.slnf b/osu-framework.Android.slnf index 4e47ddd73..d3287f7d9 100644 --- a/osu-framework.Android.slnf +++ b/osu-framework.Android.slnf @@ -7,7 +7,10 @@ "osu.Framework.Android\\osu.Framework.Android.csproj", "osu.Framework.NativeLibs\\osu.Framework.NativeLibs.csproj", "osu.Framework.Tests.Android\\osu.Framework.Tests.Android.csproj", - "osu.Framework\\osu.Framework.csproj" + "osu.Framework\\osu.Framework.csproj", + + "osu.Framework.Templates\\templates\\template-empty\\TemplateGame.Game\\TemplateGame.Game.csproj", + "osu.Framework.Templates\\templates\\template-flappy\\FlappyDon.Game\\FlappyDon.Game.csproj" ] } } \ No newline at end of file diff --git a/osu-framework.Desktop.slnf b/osu-framework.Desktop.slnf index 36bcf0064..db2006841 100644 --- a/osu-framework.Desktop.slnf +++ b/osu-framework.Desktop.slnf @@ -7,7 +7,16 @@ "osu.Framework.NativeLibs\\osu.Framework.NativeLibs.csproj", "osu.Framework.Tests\\osu.Framework.Tests.csproj", "osu.Framework\\osu.Framework.csproj", - "osu.Framework.Benchmarks\\osu.Framework.Benchmarks.csproj" + "osu.Framework.Benchmarks\\osu.Framework.Benchmarks.csproj", + + "osu.Framework.Templates\\templates\\template-empty\\TemplateGame.Game\\TemplateGame.Game.csproj", + "osu.Framework.Templates\\templates\\template-empty\\TemplateGame.Desktop\\TemplateGame.Desktop.csproj", + "osu.Framework.Templates\\templates\\template-empty\\TemplateGame.Game.Tests\\TemplateGame.Game.Tests.csproj", + "osu.Framework.Templates\\templates\\template-empty\\TemplateGame.Resources\\TemplateGame.Resources.csproj", + "osu.Framework.Templates\\templates\\template-flappy\\FlappyDon.Game\\FlappyDon.Game.csproj", + "osu.Framework.Templates\\templates\\template-flappy\\FlappyDon.Desktop\\FlappyDon.Desktop.csproj", + "osu.Framework.Templates\\templates\\template-flappy\\FlappyDon.Game.Tests\\FlappyDon.Game.Tests.csproj", + "osu.Framework.Templates\\templates\\template-flappy\\FlappyDon.Resources\\FlappyDon.Resources.csproj" ] } } \ No newline at end of file diff --git a/osu-framework.iOS.slnf b/osu-framework.iOS.slnf index b148cae00..41da6f3d5 100644 --- a/osu-framework.iOS.slnf +++ b/osu-framework.iOS.slnf @@ -7,7 +7,12 @@ "osu.Framework.iOS\\osu.Framework.iOS.csproj", "osu.Framework.NativeLibs\\osu.Framework.NativeLibs.csproj", "osu.Framework.Tests.iOS\\osu.Framework.Tests.iOS.csproj", - "osu.Framework\\osu.Framework.csproj" + "osu.Framework\\osu.Framework.csproj", + + "osu.Framework.Templates\\templates\\template-empty\\TemplateGame.Game\\TemplateGame.Game.csproj", + "osu.Framework.Templates\\templates\\template-empty\\TemplateGame.iOS\\TemplateGame.iOS.csproj", + "osu.Framework.Templates\\templates\\template-flappy\\FlappyDon.Game\\FlappyDon.Game.csproj", + "osu.Framework.Templates\\templates\\template-flappy\\FlappyDon.iOS\\FlappyDon.iOS.csproj" ] } } \ No newline at end of file diff --git a/osu-framework.sln b/osu-framework.sln index f683399b0..03c0abd8b 100644 --- a/osu-framework.sln +++ b/osu-framework.sln @@ -227,6 +227,108 @@ Global {7AA1DB5D-78DB-4693-AE50-D6078F5A0CAB}.Release|Any CPU.ActiveCfg = Release|Any CPU {7AA1DB5D-78DB-4693-AE50-D6078F5A0CAB}.Release|iPhone.ActiveCfg = Release|iPhone {7AA1DB5D-78DB-4693-AE50-D6078F5A0CAB}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator + {48783186-230D-4048-A97A-E4F1DF43BF5C}.Debug|Any CPU.ActiveCfg = Debug|iPhoneSimulator + {48783186-230D-4048-A97A-E4F1DF43BF5C}.Debug|iPhone.ActiveCfg = Debug|iPhone + {48783186-230D-4048-A97A-E4F1DF43BF5C}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator + {48783186-230D-4048-A97A-E4F1DF43BF5C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {48783186-230D-4048-A97A-E4F1DF43BF5C}.Release|iPhone.ActiveCfg = Release|iPhone + {48783186-230D-4048-A97A-E4F1DF43BF5C}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator + {6BEB95A6-0673-4AF5-892E-9146FF8B0948}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6BEB95A6-0673-4AF5-892E-9146FF8B0948}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6BEB95A6-0673-4AF5-892E-9146FF8B0948}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {6BEB95A6-0673-4AF5-892E-9146FF8B0948}.Debug|iPhone.Build.0 = Debug|Any CPU + {6BEB95A6-0673-4AF5-892E-9146FF8B0948}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {6BEB95A6-0673-4AF5-892E-9146FF8B0948}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {6BEB95A6-0673-4AF5-892E-9146FF8B0948}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6BEB95A6-0673-4AF5-892E-9146FF8B0948}.Release|Any CPU.Build.0 = Release|Any CPU + {6BEB95A6-0673-4AF5-892E-9146FF8B0948}.Release|iPhone.ActiveCfg = Release|Any CPU + {6BEB95A6-0673-4AF5-892E-9146FF8B0948}.Release|iPhone.Build.0 = Release|Any CPU + {6BEB95A6-0673-4AF5-892E-9146FF8B0948}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {6BEB95A6-0673-4AF5-892E-9146FF8B0948}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {6E3EBF71-8664-49D7-BD0D-2B21B3EEC540}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6E3EBF71-8664-49D7-BD0D-2B21B3EEC540}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6E3EBF71-8664-49D7-BD0D-2B21B3EEC540}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {6E3EBF71-8664-49D7-BD0D-2B21B3EEC540}.Debug|iPhone.Build.0 = Debug|Any CPU + {6E3EBF71-8664-49D7-BD0D-2B21B3EEC540}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {6E3EBF71-8664-49D7-BD0D-2B21B3EEC540}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {6E3EBF71-8664-49D7-BD0D-2B21B3EEC540}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6E3EBF71-8664-49D7-BD0D-2B21B3EEC540}.Release|Any CPU.Build.0 = Release|Any CPU + {6E3EBF71-8664-49D7-BD0D-2B21B3EEC540}.Release|iPhone.ActiveCfg = Release|Any CPU + {6E3EBF71-8664-49D7-BD0D-2B21B3EEC540}.Release|iPhone.Build.0 = Release|Any CPU + {6E3EBF71-8664-49D7-BD0D-2B21B3EEC540}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {6E3EBF71-8664-49D7-BD0D-2B21B3EEC540}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {55AB973D-ECA0-422B-B367-24BC47DA081B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {55AB973D-ECA0-422B-B367-24BC47DA081B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {55AB973D-ECA0-422B-B367-24BC47DA081B}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {55AB973D-ECA0-422B-B367-24BC47DA081B}.Debug|iPhone.Build.0 = Debug|Any CPU + {55AB973D-ECA0-422B-B367-24BC47DA081B}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {55AB973D-ECA0-422B-B367-24BC47DA081B}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {55AB973D-ECA0-422B-B367-24BC47DA081B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {55AB973D-ECA0-422B-B367-24BC47DA081B}.Release|Any CPU.Build.0 = Release|Any CPU + {55AB973D-ECA0-422B-B367-24BC47DA081B}.Release|iPhone.ActiveCfg = Release|Any CPU + {55AB973D-ECA0-422B-B367-24BC47DA081B}.Release|iPhone.Build.0 = Release|Any CPU + {55AB973D-ECA0-422B-B367-24BC47DA081B}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {55AB973D-ECA0-422B-B367-24BC47DA081B}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {FC0A9040-7BAF-4524-B398-8C7A1C7DDEE9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FC0A9040-7BAF-4524-B398-8C7A1C7DDEE9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FC0A9040-7BAF-4524-B398-8C7A1C7DDEE9}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {FC0A9040-7BAF-4524-B398-8C7A1C7DDEE9}.Debug|iPhone.Build.0 = Debug|Any CPU + {FC0A9040-7BAF-4524-B398-8C7A1C7DDEE9}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {FC0A9040-7BAF-4524-B398-8C7A1C7DDEE9}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {FC0A9040-7BAF-4524-B398-8C7A1C7DDEE9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FC0A9040-7BAF-4524-B398-8C7A1C7DDEE9}.Release|Any CPU.Build.0 = Release|Any CPU + {FC0A9040-7BAF-4524-B398-8C7A1C7DDEE9}.Release|iPhone.ActiveCfg = Release|Any CPU + {FC0A9040-7BAF-4524-B398-8C7A1C7DDEE9}.Release|iPhone.Build.0 = Release|Any CPU + {FC0A9040-7BAF-4524-B398-8C7A1C7DDEE9}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {FC0A9040-7BAF-4524-B398-8C7A1C7DDEE9}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {7809CB42-8FED-4BB7-8C68-7638357B94A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7809CB42-8FED-4BB7-8C68-7638357B94A6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7809CB42-8FED-4BB7-8C68-7638357B94A6}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {7809CB42-8FED-4BB7-8C68-7638357B94A6}.Debug|iPhone.Build.0 = Debug|Any CPU + {7809CB42-8FED-4BB7-8C68-7638357B94A6}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {7809CB42-8FED-4BB7-8C68-7638357B94A6}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {7809CB42-8FED-4BB7-8C68-7638357B94A6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7809CB42-8FED-4BB7-8C68-7638357B94A6}.Release|Any CPU.Build.0 = Release|Any CPU + {7809CB42-8FED-4BB7-8C68-7638357B94A6}.Release|iPhone.ActiveCfg = Release|Any CPU + {7809CB42-8FED-4BB7-8C68-7638357B94A6}.Release|iPhone.Build.0 = Release|Any CPU + {7809CB42-8FED-4BB7-8C68-7638357B94A6}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {7809CB42-8FED-4BB7-8C68-7638357B94A6}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {4C728441-4C3D-4AE4-9C0F-EA91E2C70965}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4C728441-4C3D-4AE4-9C0F-EA91E2C70965}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4C728441-4C3D-4AE4-9C0F-EA91E2C70965}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {4C728441-4C3D-4AE4-9C0F-EA91E2C70965}.Debug|iPhone.Build.0 = Debug|Any CPU + {4C728441-4C3D-4AE4-9C0F-EA91E2C70965}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {4C728441-4C3D-4AE4-9C0F-EA91E2C70965}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {4C728441-4C3D-4AE4-9C0F-EA91E2C70965}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4C728441-4C3D-4AE4-9C0F-EA91E2C70965}.Release|Any CPU.Build.0 = Release|Any CPU + {4C728441-4C3D-4AE4-9C0F-EA91E2C70965}.Release|iPhone.ActiveCfg = Release|Any CPU + {4C728441-4C3D-4AE4-9C0F-EA91E2C70965}.Release|iPhone.Build.0 = Release|Any CPU + {4C728441-4C3D-4AE4-9C0F-EA91E2C70965}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {4C728441-4C3D-4AE4-9C0F-EA91E2C70965}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {0309CF11-621A-4F23-8FBA-A583303A8531}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0309CF11-621A-4F23-8FBA-A583303A8531}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0309CF11-621A-4F23-8FBA-A583303A8531}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {0309CF11-621A-4F23-8FBA-A583303A8531}.Debug|iPhone.Build.0 = Debug|Any CPU + {0309CF11-621A-4F23-8FBA-A583303A8531}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {0309CF11-621A-4F23-8FBA-A583303A8531}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {0309CF11-621A-4F23-8FBA-A583303A8531}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0309CF11-621A-4F23-8FBA-A583303A8531}.Release|Any CPU.Build.0 = Release|Any CPU + {0309CF11-621A-4F23-8FBA-A583303A8531}.Release|iPhone.ActiveCfg = Release|Any CPU + {0309CF11-621A-4F23-8FBA-A583303A8531}.Release|iPhone.Build.0 = Release|Any CPU + {0309CF11-621A-4F23-8FBA-A583303A8531}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {0309CF11-621A-4F23-8FBA-A583303A8531}.Release|iPhoneSimulator.Build.0 = Release|Any CPU + {9E4B69EE-34E6-47CF-8346-2A66D1714FCD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9E4B69EE-34E6-47CF-8346-2A66D1714FCD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9E4B69EE-34E6-47CF-8346-2A66D1714FCD}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {9E4B69EE-34E6-47CF-8346-2A66D1714FCD}.Debug|iPhone.Build.0 = Debug|Any CPU + {9E4B69EE-34E6-47CF-8346-2A66D1714FCD}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {9E4B69EE-34E6-47CF-8346-2A66D1714FCD}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {9E4B69EE-34E6-47CF-8346-2A66D1714FCD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9E4B69EE-34E6-47CF-8346-2A66D1714FCD}.Release|Any CPU.Build.0 = Release|Any CPU + {9E4B69EE-34E6-47CF-8346-2A66D1714FCD}.Release|iPhone.ActiveCfg = Release|Any CPU + {9E4B69EE-34E6-47CF-8346-2A66D1714FCD}.Release|iPhone.Build.0 = Release|Any CPU + {9E4B69EE-34E6-47CF-8346-2A66D1714FCD}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {9E4B69EE-34E6-47CF-8346-2A66D1714FCD}.Release|iPhoneSimulator.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/osu-framework.sln.DotSettings b/osu-framework.sln.DotSettings index af8804c37..7071a978c 100644 --- a/osu-framework.sln.DotSettings +++ b/osu-framework.sln.DotSettings @@ -8,11 +8,15 @@ ExplicitlyExcluded SOLUTION WARNING + WARNING + WARNING WARNING WARNING HINT HINT WARNING + WARNING + WARNING WARNING True WARNING @@ -120,6 +124,7 @@ WARNING WARNING WARNING + HINT WARNING WARNING WARNING @@ -133,6 +138,8 @@ HINT HINT WARNING + HINT + HINT WARNING HINT WARNING @@ -143,6 +150,7 @@ DO_NOT_SHOW DO_NOT_SHOW DO_NOT_SHOW + WARNING WARNING WARNING WARNING @@ -261,6 +269,7 @@ Explicit ExpressionBody BlockBody + ExplicitlyTyped True NEXT_LINE True @@ -792,6 +801,16 @@ See the LICENCE file in the repository root for full licence text. <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + True + True + True + True + True + True + True + True + True + True True True True diff --git a/osu.Framework.Android/AndroidGameActivity.cs b/osu.Framework.Android/AndroidGameActivity.cs index dac8c61bc..35dc044d0 100644 --- a/osu.Framework.Android/AndroidGameActivity.cs +++ b/osu.Framework.Android/AndroidGameActivity.cs @@ -10,12 +10,12 @@ using Android.Runtime; using Android.Views; using ManagedBass; using osu.Framework.Bindables; -using Debug = System.Diagnostics.Debug; +using osu.Framework.Extensions.ObjectExtensions; namespace osu.Framework.Android { // since `ActivityAttribute` can't be inherited, the below is only provided as an illustrative example of how to setup an activity for best compatibility. - [Activity(ConfigurationChanges = DEFAULT_CONFIG_CHANGES, LaunchMode = DEFAULT_LAUNCH_MODE, MainLauncher = true)] + [Activity(ConfigurationChanges = DEFAULT_CONFIG_CHANGES, Exported = true, LaunchMode = DEFAULT_LAUNCH_MODE, MainLauncher = true)] public abstract class AndroidGameActivity : Activity { protected const ConfigChanges DEFAULT_CONFIG_CHANGES = ConfigChanges.Keyboard @@ -43,23 +43,18 @@ namespace osu.Framework.Android public SystemUiFlags UIVisibilityFlags { #pragma warning disable 618 // SystemUiVisibility is deprecated - get - { - Debug.Assert(Window != null); - return (SystemUiFlags)Window.DecorView.SystemUiVisibility; - } + get => (SystemUiFlags)Window.AsNonNull().DecorView.SystemUiVisibility; set { - Debug.Assert(Window != null); systemUiFlags = value; - Window.DecorView.SystemUiVisibility = (StatusBarVisibility)value; + Window.AsNonNull().DecorView.SystemUiVisibility = (StatusBarVisibility)value; #pragma warning restore 618 } } private SystemUiFlags systemUiFlags; - private AndroidGameView gameView; + private AndroidGameView gameView = null!; public override void OnTrimMemory([GeneratedEnum] TrimMemory level) { @@ -67,7 +62,7 @@ namespace osu.Framework.Android gameView.Host?.Collect(); } - protected override void OnCreate(Bundle savedInstanceState) + protected override void OnCreate(Bundle? savedInstanceState) { // The default current directory on android is '/'. // On some devices '/' maps to the app data directory. On others it maps to the root of the internal storage. @@ -80,11 +75,9 @@ namespace osu.Framework.Android UIVisibilityFlags = SystemUiFlags.LayoutFlags | SystemUiFlags.ImmersiveSticky | SystemUiFlags.HideNavigation | SystemUiFlags.Fullscreen; - Debug.Assert(Window != null); - // Firing up the on-screen keyboard (eg: interacting with textboxes) may cause the UI visibility flags to be altered thus showing the navigation bar and potentially the status bar // This sets back the UI flags to hidden once the interaction with the on-screen keyboard has finished. - Window.DecorView.SystemUiVisibilityChange += (_, e) => + Window.AsNonNull().DecorView.SystemUiVisibilityChange += (_, e) => { if ((SystemUiFlags)e.Visibility != systemUiFlags) { @@ -94,8 +87,7 @@ namespace osu.Framework.Android if (OperatingSystem.IsAndroidVersionAtLeast(28)) { - Debug.Assert(Window.Attributes != null); - Window.Attributes.LayoutInDisplayCutoutMode = LayoutInDisplayCutoutMode.ShortEdges; + Window.AsNonNull().Attributes.AsNonNull().LayoutInDisplayCutoutMode = LayoutInDisplayCutoutMode.ShortEdges; } gameView.HostStarted += host => @@ -105,9 +97,9 @@ namespace osu.Framework.Android RunOnUiThread(() => { if (!allow.NewValue) - Window.AddFlags(WindowManagerFlags.KeepScreenOn); + Window?.AddFlags(WindowManagerFlags.KeepScreenOn); else - Window.ClearFlags(WindowManagerFlags.KeepScreenOn); + Window?.ClearFlags(WindowManagerFlags.KeepScreenOn); }); }, true); }; @@ -142,17 +134,17 @@ namespace osu.Framework.Android // On some devices and keyboard combinations the OnKeyDown event does not propagate the key event to the view. // Here it is done manually to ensure that the keys actually land in the view. - public override bool OnKeyDown([GeneratedEnum] Keycode keyCode, KeyEvent e) + public override bool OnKeyDown([GeneratedEnum] Keycode keyCode, KeyEvent? e) { return gameView.OnKeyDown(keyCode, e); } - public override bool OnKeyUp([GeneratedEnum] Keycode keyCode, KeyEvent e) + public override bool OnKeyUp([GeneratedEnum] Keycode keyCode, KeyEvent? e) { return gameView.OnKeyUp(keyCode, e); } - public override bool OnKeyLongPress([GeneratedEnum] Keycode keyCode, KeyEvent e) + public override bool OnKeyLongPress([GeneratedEnum] Keycode keyCode, KeyEvent? e) { return gameView.OnKeyLongPress(keyCode, e); } diff --git a/osu.Framework.Android/AndroidGameHost.cs b/osu.Framework.Android/AndroidGameHost.cs index c4a4013f4..d69ee6277 100644 --- a/osu.Framework.Android/AndroidGameHost.cs +++ b/osu.Framework.Android/AndroidGameHost.cs @@ -9,6 +9,7 @@ using osu.Framework.Android.Graphics.Textures; using osu.Framework.Android.Graphics.Video; using osu.Framework.Android.Input; using osu.Framework.Configuration; +using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Video; using osu.Framework.Input; @@ -63,7 +64,7 @@ namespace osu.Framework.Android public override IEnumerable UserStoragePaths => new[] { // not null as internal "external storage" is always available. - Application.Context.GetExternalFilesDir(string.Empty)!.ToString(), + Application.Context.GetExternalFilesDir(string.Empty).AsNonNull().ToString(), }; public override bool OpenFileExternally(string filename) => false; diff --git a/osu.Framework.Android/AndroidGameView.cs b/osu.Framework.Android/AndroidGameView.cs index 5b56a3cff..06b4d804d 100644 --- a/osu.Framework.Android/AndroidGameView.cs +++ b/osu.Framework.Android/AndroidGameView.cs @@ -14,19 +14,19 @@ using Android.Views.InputMethods; using osu.Framework.Android.Input; using osu.Framework.Logging; using osu.Framework.Bindables; +using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Primitives; using osu.Framework.Platform; using osuTK.Graphics; -using Debug = System.Diagnostics.Debug; namespace osu.Framework.Android { public class AndroidGameView : osuTK.Android.AndroidGameView { - public AndroidGameHost Host { get; private set; } + public AndroidGameHost? Host { get; private set; } - public AndroidGameActivity Activity { get; } + public AndroidGameActivity Activity { get; } = null!; public BindableSafeArea SafeAreaPadding { get; } = new BindableSafeArea(); @@ -61,7 +61,14 @@ namespace osu.Framework.Android } } - private readonly Game game; + private readonly Game game = null!; + + private InputMethodManager? inputMethodManager; + + /// + /// Whether is active. + /// + private bool textInputActive; public AndroidGameView(AndroidGameActivity activity, Game game) : base(activity) @@ -93,6 +100,11 @@ namespace osu.Framework.Android // this needs to happen in the constructor Focusable = true; FocusableInTouchMode = true; + + // disable ugly green border when view is focused via hardware keyboard/mouse. + DefaultFocusHighlightEnabled = false; + + inputMethodManager = Activity.GetSystemService(Context.InputMethodService) as InputMethodManager; } protected override void CreateFrameBuffer() @@ -115,8 +127,10 @@ namespace osu.Framework.Android return false; } - public override bool OnKeyDown([GeneratedEnum] Keycode keyCode, KeyEvent e) + public override bool OnKeyDown([GeneratedEnum] Keycode keyCode, KeyEvent? e) { + if (e == null) return base.OnKeyDown(keyCode, e); + switch (keyCode) { // Do not consume Volume keys, so the system can handle them @@ -127,18 +141,29 @@ namespace osu.Framework.Android default: KeyDown?.Invoke(keyCode, e); + + // Releasing backspace on a physical keyboard when text input is active will not send a key up event. + // Manually send one to prevent the key from getting stuck. + // This does mean that key repeat is handled by the OS, instead of by the usual `InputManager` handling. + if (keyCode == Keycode.Del && e.IsFromSource(InputSourceType.Keyboard) && textInputActive) + KeyUp?.Invoke(Keycode.Del, new KeyEvent(e.DownTime, e.EventTime, KeyEventActions.Up, Keycode.Del, 0, e.MetaState, e.DeviceId, e.ScanCode, e.Flags, e.Source)); + return true; } } - public override bool OnKeyLongPress([GeneratedEnum] Keycode keyCode, KeyEvent e) + public override bool OnKeyLongPress([GeneratedEnum] Keycode keyCode, KeyEvent? e) { + if (e == null) return base.OnKeyLongPress(keyCode, e); + KeyLongPress?.Invoke(keyCode, e); return true; } - public override bool OnKeyUp([GeneratedEnum] Keycode keyCode, KeyEvent e) + public override bool OnKeyUp([GeneratedEnum] Keycode keyCode, KeyEvent? e) { + if (e == null) return base.OnKeyUp(keyCode, e); + KeyUp?.Invoke(keyCode, e); return true; } @@ -187,13 +212,11 @@ namespace osu.Framework.Android /// private void updateSafeArea() { - Debug.Assert(Display != null); - // compute the usable screen area. var screenSize = new Point(); #pragma warning disable 618 // GetRealSize is deprecated - Display.GetRealSize(screenSize); + Display.AsNonNull().GetRealSize(screenSize); #pragma warning restore 618 var screenArea = new RectangleI(0, 0, screenSize.X, screenSize.Y); var usableScreenArea = screenArea; @@ -239,41 +262,91 @@ namespace osu.Framework.Android }; } - public override bool OnCheckIsTextEditor() => true; + public override bool OnCheckIsTextEditor() => textInputActive; - public override IInputConnection OnCreateInputConnection(EditorInfo outAttrs) + /// null to disable input methods + public override IInputConnection? OnCreateInputConnection(EditorInfo? outAttrs) { + if (outAttrs == null) throw new ArgumentNullException(nameof(outAttrs)); + + // Properly disable native input methods so that the software keyboard doesn't unexpectedly open. + // Eg. when pressing keys on a hardware keyboard. + if (!textInputActive) + return null; + outAttrs.ImeOptions = ImeFlags.NoExtractUi | ImeFlags.NoFullscreen; outAttrs.InputType = InputTypes.TextVariationVisiblePassword | InputTypes.TextFlagNoSuggestions; return new AndroidInputConnection(this, true); } + internal void StartTextInput() + { + textInputActive = true; + Activity.RunOnUiThread(() => + { + inputMethodManager?.RestartInput(this); // this syncs the Android input method state with `OnCreateInputConnection()`. + RequestFocus(); + inputMethodManager?.ShowSoftInput(this, 0); + }); + } + + internal void StopTextInput() + { + textInputActive = false; + Activity.RunOnUiThread(() => + { + inputMethodManager?.RestartInput(this); + inputMethodManager?.HideSoftInputFromWindow(WindowToken, HideSoftInputFlags.None); + ClearFocus(); + }); + } + + public override void SwapBuffers() + { + try + { + base.SwapBuffers(); + } + catch (GraphicsContextException ex) + { + // sometimes buffers will spontaneously fail to swap with BAD_SURFACE + // just before the activity is suspended to background or just after it has been resumed, + // but will continue operating correctly after that transitionary period. + // despite some testing it is unclear which view callback can be used to tell whether it is safe to swap buffers, + // so for now just catch and suppress these errors. + if (ex.Message.Contains("BAD_SURFACE", StringComparison.Ordinal)) + Logger.Log($"BAD_SURFACE failure in {nameof(SwapBuffers)} suppressed"); + else + throw; + } + } + #region Events /// /// Invoked on a key down event. /// - public new event Action KeyDown; + public new event Action? KeyDown; /// /// Invoked on a key up event. /// - public new event Action KeyUp; + public new event Action? KeyUp; /// /// Invoked on a key long press event. /// - public event Action KeyLongPress; + public event Action? KeyLongPress; /// /// Invoked when text is committed by an . /// - public event Action CommitText; + public event Action? CommitText; /// /// Invoked when the has been started on the . /// - public event Action HostStarted; + public event Action? HostStarted; #endregion } diff --git a/osu.Framework.Android/AndroidGameWindow.cs b/osu.Framework.Android/AndroidGameWindow.cs index f0d71f4b8..8a8038704 100644 --- a/osu.Framework.Android/AndroidGameWindow.cs +++ b/osu.Framework.Android/AndroidGameWindow.cs @@ -27,7 +27,7 @@ namespace osu.Framework.Android set { } } - public event Action CursorStateChanged; + public event Action? CursorStateChanged; public override CursorState CursorState { diff --git a/osu.Framework.Android/Graphics/Video/AndroidVideoDecoder.cs b/osu.Framework.Android/Graphics/Video/AndroidVideoDecoder.cs index 241c39c20..edc81ddc3 100644 --- a/osu.Framework.Android/Graphics/Video/AndroidVideoDecoder.cs +++ b/osu.Framework.Android/Graphics/Video/AndroidVideoDecoder.cs @@ -8,6 +8,7 @@ using System.Runtime.InteropServices; using FFmpeg.AutoGen; using Java.Interop; using osu.Framework.Extensions.EnumExtensions; +using osu.Framework.Extensions.ObjectExtensions; using osu.Framework.Graphics.Video; using osu.Framework.Logging; @@ -142,7 +143,7 @@ namespace osu.Framework.Android.Graphics.Video : base(videoStream) { // Hardware decoding with MediaCodec requires that we pass a Java VM pointer - // to FFmpeg so that it can call the MediaCodec APIs through JNI (as they're Java only) + // to FFmpeg so that it can call the MediaCodec APIs through JNI (as they're Java only). int result = av_jni_set_java_vm(JniEnvironment.Runtime.InvocationPointer.ToPointer(), null); if (result < 0) diff --git a/osu.Framework.Android/Input/AndroidInputConnection.cs b/osu.Framework.Android/Input/AndroidInputConnection.cs index a0b47e093..1bcdee1fb 100644 --- a/osu.Framework.Android/Input/AndroidInputConnection.cs +++ b/osu.Framework.Android/Input/AndroidInputConnection.cs @@ -9,40 +9,43 @@ namespace osu.Framework.Android.Input { internal class AndroidInputConnection : BaseInputConnection { - public AndroidGameView TargetView { get; set; } + private readonly AndroidGameView targetView; public AndroidInputConnection(AndroidGameView targetView, bool fullEditor) : base(targetView, fullEditor) { - TargetView = targetView; + this.targetView = targetView; } - public override bool CommitText(ICharSequence text, int newCursorPosition) + public override bool CommitText(ICharSequence? text, int newCursorPosition) { - if (text.Length() != 0) + if (text?.Length() > 0) { - TargetView.OnCommitText(text.ToString()); + targetView.OnCommitText(text.ToString()); return true; } return base.CommitText(text, newCursorPosition); } - public override bool SendKeyEvent(KeyEvent e) + public override bool SendKeyEvent(KeyEvent? e) { + if (e == null) + return base.SendKeyEvent(e); + switch (e.Action) { case KeyEventActions.Down: - TargetView?.OnKeyDown(e.KeyCode, e); + targetView.OnKeyDown(e.KeyCode, e); return true; case KeyEventActions.Up: - TargetView?.OnKeyUp(e.KeyCode, e); + targetView.OnKeyUp(e.KeyCode, e); return true; case KeyEventActions.Multiple: - TargetView?.OnKeyDown(e.KeyCode, e); - TargetView?.OnKeyUp(e.KeyCode, e); + targetView.OnKeyDown(e.KeyCode, e); + targetView.OnKeyUp(e.KeyCode, e); return true; } diff --git a/osu.Framework.Android/Input/AndroidInputExtensions.cs b/osu.Framework.Android/Input/AndroidInputExtensions.cs index 19c6a31f6..dd3860029 100644 --- a/osu.Framework.Android/Input/AndroidInputExtensions.cs +++ b/osu.Framework.Android/Input/AndroidInputExtensions.cs @@ -2,7 +2,9 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Collections.Generic; using Android.Views; +using osu.Framework.Extensions.EnumExtensions; using osuTK.Input; namespace osu.Framework.Android.Input @@ -10,33 +12,27 @@ namespace osu.Framework.Android.Input public static class AndroidInputExtensions { /// - /// Returns the corresponding for a mouse button given as a . + /// Returns the corresponding s for a mouse button given as a . /// - /// The given button. Must not be a raw state or a non-mouse button. - /// The corresponding . + /// The given button state. Must not be a raw state or a non-mouse button. + /// The corresponding s. /// Thrown if the provided button is not a - public static MouseButton ToMouseButton(this MotionEventButtonState motionEventMouseButton) + public static IEnumerable ToMouseButtons(this MotionEventButtonState motionEventMouseButton) { - switch (motionEventMouseButton) - { - case MotionEventButtonState.Primary: - return MouseButton.Left; + if (motionEventMouseButton.HasFlagFast(MotionEventButtonState.Primary)) + yield return MouseButton.Left; - case MotionEventButtonState.Secondary: - return MouseButton.Right; + if (motionEventMouseButton.HasFlagFast(MotionEventButtonState.Secondary)) + yield return MouseButton.Right; - case MotionEventButtonState.Tertiary: - return MouseButton.Middle; + if (motionEventMouseButton.HasFlagFast(MotionEventButtonState.Tertiary)) + yield return MouseButton.Middle; - case MotionEventButtonState.Back: - return MouseButton.Button1; + if (motionEventMouseButton.HasFlagFast(MotionEventButtonState.Back)) + yield return MouseButton.Button1; - case MotionEventButtonState.Forward: - return MouseButton.Button2; - - default: - throw new ArgumentOutOfRangeException(nameof(motionEventMouseButton), motionEventMouseButton, "Given button is not a mouse button."); - } + if (motionEventMouseButton.HasFlagFast(MotionEventButtonState.Forward)) + yield return MouseButton.Button2; } /// diff --git a/osu.Framework.Android/Input/AndroidInputHandler.cs b/osu.Framework.Android/Input/AndroidInputHandler.cs index b3b92ae34..643740383 100644 --- a/osu.Framework.Android/Input/AndroidInputHandler.cs +++ b/osu.Framework.Android/Input/AndroidInputHandler.cs @@ -9,8 +9,6 @@ using osu.Framework.Extensions.EnumExtensions; using osu.Framework.Input.Handlers; using osu.Framework.Platform; -#nullable enable - namespace osu.Framework.Android.Input { /// diff --git a/osu.Framework.Android/Input/AndroidKeyboardHandler.cs b/osu.Framework.Android/Input/AndroidKeyboardHandler.cs index 8adbfa7d0..9b7e8b792 100644 --- a/osu.Framework.Android/Input/AndroidKeyboardHandler.cs +++ b/osu.Framework.Android/Input/AndroidKeyboardHandler.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using Android.Views; diff --git a/osu.Framework.Android/Input/AndroidMouseHandler.cs b/osu.Framework.Android/Input/AndroidMouseHandler.cs index 79a7855b5..64a66733b 100644 --- a/osu.Framework.Android/Input/AndroidMouseHandler.cs +++ b/osu.Framework.Android/Input/AndroidMouseHandler.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using Android.OS; @@ -180,11 +182,13 @@ namespace osu.Framework.Android.Input switch (genericMotionEvent.Action) { case MotionEventActions.ButtonPress: - handleMouseDown(genericMotionEvent.ActionButton.ToMouseButton()); + foreach (var button in genericMotionEvent.ActionButton.ToMouseButtons()) + handleMouseDown(button); break; case MotionEventActions.ButtonRelease: - handleMouseUp(genericMotionEvent.ActionButton.ToMouseButton()); + foreach (var button in genericMotionEvent.ActionButton.ToMouseButtons()) + handleMouseUp(button); break; case MotionEventActions.Scroll: @@ -212,17 +216,21 @@ namespace osu.Framework.Android.Input break; case MotionEventActions.ButtonPress: - handleMouseDown(capturedPointerEvent.ActionButton.ToMouseButton()); + foreach (var button in capturedPointerEvent.ActionButton.ToMouseButtons()) + handleMouseDown(button); break; case MotionEventActions.ButtonRelease: - handleMouseUp(capturedPointerEvent.ActionButton.ToMouseButton()); + foreach (var button in capturedPointerEvent.ActionButton.ToMouseButtons()) + handleMouseUp(button); break; } } } - private Vector2 getEventScroll(MotionEvent e) => new Vector2(e.GetAxisValue(Axis.Hscroll), e.GetAxisValue(Axis.Vscroll)); + private Vector2 getEventScroll(MotionEvent e) => + // Android reports horizontal scroll opposite of what framework expects. + new Vector2(-e.GetAxisValue(Axis.Hscroll), e.GetAxisValue(Axis.Vscroll)); private void handleMouseMoveEvent(MotionEvent evt) { diff --git a/osu.Framework.Android/Input/AndroidTextInput.cs b/osu.Framework.Android/Input/AndroidTextInput.cs index 524bdb40f..eab5a518d 100644 --- a/osu.Framework.Android/Input/AndroidTextInput.cs +++ b/osu.Framework.Android/Input/AndroidTextInput.cs @@ -1,22 +1,18 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using Android.Content; using Android.Views; -using Android.Views.InputMethods; using osu.Framework.Input; namespace osu.Framework.Android.Input { - public class AndroidTextInput : TextInputSource + internal class AndroidTextInput : TextInputSource { private readonly AndroidGameView view; - private readonly InputMethodManager inputMethodManager; public AndroidTextInput(AndroidGameView view) { this.view = view; - inputMethodManager = view.Activity.GetSystemService(Context.InputMethodService) as InputMethodManager; } private void commitText(string text) @@ -34,33 +30,19 @@ namespace osu.Framework.Android.Input { view.KeyDown += keyDown; view.CommitText += commitText; - - view.Activity.RunOnUiThread(() => - { - view.RequestFocus(); - inputMethodManager?.ShowSoftInput(view, 0); - }); + view.StartTextInput(); } protected override void EnsureTextInputActivated(bool allowIme) { - view.Activity.RunOnUiThread(() => - { - view.RequestFocus(); - inputMethodManager?.ShowSoftInput(view, 0); - }); + view.StartTextInput(); } protected override void DeactivateTextInput() { view.KeyDown -= keyDown; view.CommitText -= commitText; - - view.Activity.RunOnUiThread(() => - { - inputMethodManager?.HideSoftInputFromWindow(view.WindowToken, HideSoftInputFlags.None); - view.ClearFocus(); - }); + view.StopTextInput(); } } } diff --git a/osu.Framework.Android/Input/AndroidTouchHandler.cs b/osu.Framework.Android/Input/AndroidTouchHandler.cs index 8f838076a..14b6ef38c 100644 --- a/osu.Framework.Android/Input/AndroidTouchHandler.cs +++ b/osu.Framework.Android/Input/AndroidTouchHandler.cs @@ -1,12 +1,15 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using Android.Views; using osu.Framework.Input; using osu.Framework.Input.StateChanges; using osu.Framework.Input.States; +using osu.Framework.Logging; using osu.Framework.Platform; using osuTK; using osuTK.Input; @@ -48,41 +51,83 @@ namespace osu.Framework.Android.Input protected override void OnTouch(MotionEvent touchEvent) { - if (touchEvent.Action == MotionEventActions.Move) - { - for (int i = 0; i < Math.Min(touchEvent.PointerCount, TouchState.MAX_TOUCH_COUNT); i++) - { - var touch = getEventTouch(touchEvent, i); - PendingInputs.Enqueue(new TouchInput(touch, true)); - } - } - else if (touchEvent.ActionIndex < TouchState.MAX_TOUCH_COUNT) - { - var touch = getEventTouch(touchEvent, touchEvent.ActionIndex); + Touch touch; - switch (touchEvent.ActionMasked) - { - case MotionEventActions.Down: - case MotionEventActions.PointerDown: + switch (touchEvent.ActionMasked) + { + // MotionEventActions.Down arrives at the beginning of a touch event chain and implies the 0th pointer is pressed. + // ActionIndex is generally not valid here. + case MotionEventActions.Down: + if (tryGetEventTouch(touchEvent, 0, out touch)) PendingInputs.Enqueue(new TouchInput(touch, true)); - break; + break; - case MotionEventActions.Up: - case MotionEventActions.PointerUp: - case MotionEventActions.Cancel: - PendingInputs.Enqueue(new TouchInput(touch, false)); - break; - } + // events that apply only to the ActionIndex pointer (other pointers' states remain unchanged) + case MotionEventActions.PointerDown: + case MotionEventActions.PointerUp: + if (touchEvent.ActionIndex < TouchState.MAX_TOUCH_COUNT) + { + if (tryGetEventTouch(touchEvent, touchEvent.ActionIndex, out touch)) + PendingInputs.Enqueue(new TouchInput(touch, touchEvent.ActionMasked == MotionEventActions.PointerDown)); + } + + break; + + // events that apply to every pointer (up to PointerCount). + case MotionEventActions.Move: + case MotionEventActions.Up: + case MotionEventActions.Cancel: + for (int i = 0; i < Math.Min(touchEvent.PointerCount, TouchState.MAX_TOUCH_COUNT); i++) + { + if (tryGetEventTouch(touchEvent, i, out touch)) + PendingInputs.Enqueue(new TouchInput(touch, touchEvent.ActionMasked == MotionEventActions.Move)); + } + + break; + + default: + Logger.Log($"Unknown touch event action: {touchEvent.Action}, masked: {touchEvent.ActionMasked}"); + break; } } protected override void OnHover(MotionEvent hoverEvent) { - PendingInputs.Enqueue(new MousePositionAbsoluteInput { Position = getEventPosition(hoverEvent) }); + if (tryGetEventPosition(hoverEvent, 0, out var position)) + PendingInputs.Enqueue(new MousePositionAbsoluteInput { Position = position }); PendingInputs.Enqueue(new MouseButtonInput(MouseButton.Right, hoverEvent.IsButtonPressed(MotionEventButtonState.StylusPrimary))); } - private Touch getEventTouch(MotionEvent e, int index) => new Touch((TouchSource)e.GetPointerId(index), getEventPosition(e, index)); - private Vector2 getEventPosition(MotionEvent e, int index = 0) => new Vector2(e.GetX(index) * View.ScaleX, e.GetY(index) * View.ScaleY); + private bool tryGetEventTouch(MotionEvent e, int index, out Touch touch) + { + if (tryGetEventPosition(e, index, out var position)) + { + touch = new Touch((TouchSource)e.GetPointerId(index), position); + return true; + } + else + { + touch = new Touch(); + return false; + } + } + + private bool tryGetEventPosition(MotionEvent e, int index, out Vector2 position) + { + float x = e.GetX(index); + float y = e.GetY(index); + + // in empirical testing, `MotionEvent.Get{X,Y}()` methods can return NaN positions early on in the android activity's lifetime. + // these nonsensical inputs then cause issues later down the line when they are converted into framework inputs. + // as there is really nothing to recover from such inputs, drop them entirely. + if (float.IsNaN(x) || float.IsNaN(y)) + { + position = Vector2.Zero; + return false; + } + + position = new Vector2(x * View.ScaleX, y * View.ScaleY); + return true; + } } } diff --git a/osu.Framework.Benchmarks/BenchmarkBeginAbsoluteSequence.cs b/osu.Framework.Benchmarks/BenchmarkBeginAbsoluteSequence.cs index 22e95c425..dfdfc8158 100644 --- a/osu.Framework.Benchmarks/BenchmarkBeginAbsoluteSequence.cs +++ b/osu.Framework.Benchmarks/BenchmarkBeginAbsoluteSequence.cs @@ -14,7 +14,7 @@ namespace osu.Framework.Benchmarks [MemoryDiagnoser] public class BenchmarkBeginAbsoluteSequence : GameBenchmark { - private TestGame game; + private TestGame game = null!; [Test] [Benchmark] @@ -104,9 +104,9 @@ namespace osu.Framework.Benchmarks private class TestGame : Game { - public Container Flat; - public Container VeryNested; - public Container SlightlyNested; + public Container Flat = null!; + public Container VeryNested = null!; + public Container SlightlyNested = null!; protected override void LoadComplete() { diff --git a/osu.Framework.Benchmarks/BenchmarkBindableInstantiation.cs b/osu.Framework.Benchmarks/BenchmarkBindableInstantiation.cs index 6aa680782..be5c1cd98 100644 --- a/osu.Framework.Benchmarks/BenchmarkBindableInstantiation.cs +++ b/osu.Framework.Benchmarks/BenchmarkBindableInstantiation.cs @@ -4,6 +4,7 @@ using System; using BenchmarkDotNet.Attributes; using osu.Framework.Bindables; +using osu.Framework.Extensions.ObjectExtensions; namespace osu.Framework.Benchmarks { @@ -19,14 +20,14 @@ namespace osu.Framework.Benchmarks [Benchmark(Baseline = true)] public Bindable GetBoundCopyOld() => new BindableOld().GetBoundCopy(); - private class BindableOld : Bindable + private class BindableOld : Bindable where T : notnull { - public BindableOld(T defaultValue = default) + public BindableOld(T defaultValue = default!) : base(defaultValue) { } - protected override Bindable CreateInstance() => (BindableOld)Activator.CreateInstance(GetType(), Value); + protected override Bindable CreateInstance() => (BindableOld)Activator.CreateInstance(GetType(), Value).AsNonNull(); } } } diff --git a/osu.Framework.Benchmarks/BenchmarkCompositeDrawableAllocations.cs b/osu.Framework.Benchmarks/BenchmarkCompositeDrawableAllocations.cs index b3173ddde..0513c0206 100644 --- a/osu.Framework.Benchmarks/BenchmarkCompositeDrawableAllocations.cs +++ b/osu.Framework.Benchmarks/BenchmarkCompositeDrawableAllocations.cs @@ -11,7 +11,7 @@ namespace osu.Framework.Benchmarks { public class BenchmarkCompositeDrawableAllocations : GameBenchmark { - private TestGame game; + private TestGame game = null!; [Test] [Benchmark] @@ -63,7 +63,7 @@ namespace osu.Framework.Benchmarks { base.Update(); - Drawable drawable = null; + Drawable? drawable = null; switch (Mode) { diff --git a/osu.Framework.Benchmarks/BenchmarkDependencyContainer.cs b/osu.Framework.Benchmarks/BenchmarkDependencyContainer.cs index fe3f5b05a..5cab656f7 100644 --- a/osu.Framework.Benchmarks/BenchmarkDependencyContainer.cs +++ b/osu.Framework.Benchmarks/BenchmarkDependencyContainer.cs @@ -18,9 +18,9 @@ namespace osu.Framework.Benchmarks { public class BenchmarkDependencyContainer : GameBenchmark { - private Game game; - private TestBdlReceiver bdlReceiver; - private TestCachedReceiver cachedReceiver; + private Game game = null!; + private TestBdlReceiver bdlReceiver = null!; + private TestCachedReceiver cachedReceiver = null!; public override void SetUp() { @@ -63,13 +63,13 @@ namespace osu.Framework.Benchmarks private class TestCachedReceiver : Drawable { [Resolved] - private GameHost host { get; set; } + private GameHost host { get; set; } = null!; [Resolved] - private FrameworkConfigManager frameworkConfigManager { get; set; } + private FrameworkConfigManager frameworkConfigManager { get; set; } = null!; [Resolved] - private FrameworkDebugConfigManager frameworkDebugConfigManager { get; set; } + private FrameworkDebugConfigManager frameworkDebugConfigManager { get; set; } = null!; } private class TestGame : Game diff --git a/osu.Framework.Benchmarks/BenchmarkDrawableAudioWrapper.cs b/osu.Framework.Benchmarks/BenchmarkDrawableAudioWrapper.cs index c44c8b68c..bd7154974 100644 --- a/osu.Framework.Benchmarks/BenchmarkDrawableAudioWrapper.cs +++ b/osu.Framework.Benchmarks/BenchmarkDrawableAudioWrapper.cs @@ -37,7 +37,7 @@ namespace osu.Framework.Benchmarks public bool TransferBetween { get; set; } - private AudioContainer lastContainer; + private AudioContainer? lastContainer; protected override void LoadComplete() { diff --git a/osu.Framework.Benchmarks/BenchmarkDrawableLoad.cs b/osu.Framework.Benchmarks/BenchmarkDrawableLoad.cs index 7155e12f8..441dbebd8 100644 --- a/osu.Framework.Benchmarks/BenchmarkDrawableLoad.cs +++ b/osu.Framework.Benchmarks/BenchmarkDrawableLoad.cs @@ -14,7 +14,7 @@ namespace osu.Framework.Benchmarks [MemoryDiagnoser] public class BenchmarkDrawableLoad : GameBenchmark { - private TestGame game; + private TestGame game = null!; private const int nesting_level = 100; diff --git a/osu.Framework.Benchmarks/BenchmarkFillFlowContainerAllocations.cs b/osu.Framework.Benchmarks/BenchmarkFillFlowContainerAllocations.cs index 363739d03..28ce812b6 100644 --- a/osu.Framework.Benchmarks/BenchmarkFillFlowContainerAllocations.cs +++ b/osu.Framework.Benchmarks/BenchmarkFillFlowContainerAllocations.cs @@ -12,7 +12,7 @@ namespace osu.Framework.Benchmarks { public class BenchmarkFillFlowContainerAllocations : GameBenchmark { - private TestGame game; + private TestGame game = null!; [Benchmark] public void MultipleComputeLayoutPositions() diff --git a/osu.Framework.Benchmarks/BenchmarkFontLoading.cs b/osu.Framework.Benchmarks/BenchmarkFontLoading.cs index 282341b28..a98a26fbb 100644 --- a/osu.Framework.Benchmarks/BenchmarkFontLoading.cs +++ b/osu.Framework.Benchmarks/BenchmarkFontLoading.cs @@ -16,8 +16,8 @@ namespace osu.Framework.Benchmarks { public class BenchmarkFontLoading : BenchmarkTest { - private NamespacedResourceStore baseResources; - private TemporaryNativeStorage sharedTemp; + private NamespacedResourceStore baseResources = null!; + private TemporaryNativeStorage sharedTemp = null!; public override void SetUp() { @@ -30,7 +30,7 @@ namespace osu.Framework.Benchmarks [OneTimeTearDown] public void TearDown() { - sharedTemp?.Dispose(); + sharedTemp.Dispose(); } [Params(1, 10, 100, 1000, 10000)] @@ -91,7 +91,7 @@ namespace osu.Framework.Benchmarks { foreach (var p in props) { - object propValue = p.GetValue(null); + object? propValue = p.GetValue(null); Debug.Assert(propValue != null); var icon = (IconUsage)propValue; diff --git a/osu.Framework.Benchmarks/BenchmarkHashing.cs b/osu.Framework.Benchmarks/BenchmarkHashing.cs index c09a41f12..5bff2e9be 100644 --- a/osu.Framework.Benchmarks/BenchmarkHashing.cs +++ b/osu.Framework.Benchmarks/BenchmarkHashing.cs @@ -12,7 +12,7 @@ namespace osu.Framework.Benchmarks public class BenchmarkHashing { private const string test_string = @"A string with reasonable length"; - private MemoryStream memoryStream; + private MemoryStream memoryStream = null!; [Benchmark] public string StringMD5() => test_string.ComputeMD5Hash(); diff --git a/osu.Framework.Benchmarks/BenchmarkLocalisableDescription.cs b/osu.Framework.Benchmarks/BenchmarkLocalisableDescription.cs index fbd008a09..db694e29c 100644 --- a/osu.Framework.Benchmarks/BenchmarkLocalisableDescription.cs +++ b/osu.Framework.Benchmarks/BenchmarkLocalisableDescription.cs @@ -9,7 +9,7 @@ namespace osu.Framework.Benchmarks { public class BenchmarkLocalisableDescription { - private LocalisableString[] descriptions; + private LocalisableString[] descriptions = null!; [Params(1, 10, 100, 1000)] public int Times { get; set; } diff --git a/osu.Framework.Benchmarks/BenchmarkLocalisableString.cs b/osu.Framework.Benchmarks/BenchmarkLocalisableString.cs index 97f4d9ee2..d04220cc8 100644 --- a/osu.Framework.Benchmarks/BenchmarkLocalisableString.cs +++ b/osu.Framework.Benchmarks/BenchmarkLocalisableString.cs @@ -10,8 +10,8 @@ namespace osu.Framework.Benchmarks [MemoryDiagnoser] public class BenchmarkLocalisableString { - private string string1; - private string string2; + private string string1 = null!; + private string string2 = null!; private LocalisableString localisableString1; private LocalisableString localisableString2; private LocalisableString romanisableString1; diff --git a/osu.Framework.Benchmarks/BenchmarkLocalisedBindableString.cs b/osu.Framework.Benchmarks/BenchmarkLocalisedBindableString.cs index 456bd2834..5d5813704 100644 --- a/osu.Framework.Benchmarks/BenchmarkLocalisedBindableString.cs +++ b/osu.Framework.Benchmarks/BenchmarkLocalisedBindableString.cs @@ -12,13 +12,13 @@ namespace osu.Framework.Benchmarks [MemoryDiagnoser] public class BenchmarkLocalisedBindableString { - private LocalisationManager manager; - private TemporaryNativeStorage storage; + private LocalisationManager manager = null!; + private TemporaryNativeStorage storage = null!; [GlobalSetup] public void GlobalSetup() { - storage = new TemporaryNativeStorage(new Guid().ToString()); + storage = new TemporaryNativeStorage(Guid.NewGuid().ToString()); manager = new LocalisationManager(new FrameworkConfigManager(storage)); } diff --git a/osu.Framework.Benchmarks/BenchmarkManySpinningBoxes.cs b/osu.Framework.Benchmarks/BenchmarkManySpinningBoxes.cs index 0635ccf77..12e6be556 100644 --- a/osu.Framework.Benchmarks/BenchmarkManySpinningBoxes.cs +++ b/osu.Framework.Benchmarks/BenchmarkManySpinningBoxes.cs @@ -13,7 +13,7 @@ namespace osu.Framework.Benchmarks { public class BenchmarkManySpinningBoxes : GameBenchmark { - private TestGame game; + private TestGame game = null!; [Test] [Benchmark] @@ -47,7 +47,7 @@ namespace osu.Framework.Benchmarks private class TestGame : Game { - public Container MainContent; + public Container MainContent = null!; protected override void LoadComplete() { diff --git a/osu.Framework.Benchmarks/BenchmarkScheduler.cs b/osu.Framework.Benchmarks/BenchmarkScheduler.cs new file mode 100644 index 000000000..4ac44dc3c --- /dev/null +++ b/osu.Framework.Benchmarks/BenchmarkScheduler.cs @@ -0,0 +1,60 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using BenchmarkDotNet.Attributes; +using osu.Framework.Threading; + +namespace osu.Framework.Benchmarks +{ + public class BenchmarkScheduler : BenchmarkTest + { + private Scheduler scheduler = null!; + private Scheduler schedulerWithEveryUpdate = null!; + private Scheduler schedulerWithManyDelayed = null!; + + public override void SetUp() + { + base.SetUp(); + + scheduler = new Scheduler(); + + schedulerWithEveryUpdate = new Scheduler(); + schedulerWithEveryUpdate.AddDelayed(() => { }, 0, true); + + schedulerWithManyDelayed = new Scheduler(); + for (int i = 0; i < 1000; i++) + schedulerWithManyDelayed.AddDelayed(() => { }, int.MaxValue); + } + + [Benchmark] + public void UpdateEmptyScheduler() + { + for (int i = 0; i < 1000; i++) + scheduler.Update(); + } + + [Benchmark] + public void UpdateSchedulerWithManyDelayed() + { + for (int i = 0; i < 1000; i++) + schedulerWithManyDelayed.Update(); + } + + [Benchmark] + public void UpdateSchedulerWithEveryUpdate() + { + for (int i = 0; i < 1000; i++) + schedulerWithEveryUpdate.Update(); + } + + [Benchmark] + public void UpdateSchedulerWithManyAdded() + { + for (int i = 0; i < 1000; i++) + { + scheduler.Add(() => { }); + scheduler.Update(); + } + } + } +} diff --git a/osu.Framework.Benchmarks/BenchmarkScreenExtensions.cs b/osu.Framework.Benchmarks/BenchmarkScreenExtensions.cs index 0ade9fe42..f9553e7d6 100644 --- a/osu.Framework.Benchmarks/BenchmarkScreenExtensions.cs +++ b/osu.Framework.Benchmarks/BenchmarkScreenExtensions.cs @@ -9,7 +9,7 @@ namespace osu.Framework.Benchmarks { public class BenchmarkScreenExtensions : GameBenchmark { - private Screen testScreen; + private Screen testScreen = null!; [Test] [Benchmark] diff --git a/osu.Framework.Benchmarks/BenchmarkStreamExtensions.cs b/osu.Framework.Benchmarks/BenchmarkStreamExtensions.cs index 4a9fa7c4b..575109e5b 100644 --- a/osu.Framework.Benchmarks/BenchmarkStreamExtensions.cs +++ b/osu.Framework.Benchmarks/BenchmarkStreamExtensions.cs @@ -11,7 +11,7 @@ namespace osu.Framework.Benchmarks [MemoryDiagnoser] public class BenchmarkStreamExtensions { - private MemoryStream memoryStream; + private MemoryStream memoryStream = null!; [Params(100, 10000, 1000000)] public int Length { get; set; } diff --git a/osu.Framework.Benchmarks/BenchmarkTabletDriver.cs b/osu.Framework.Benchmarks/BenchmarkTabletDriver.cs index ba866956c..68218d22f 100644 --- a/osu.Framework.Benchmarks/BenchmarkTabletDriver.cs +++ b/osu.Framework.Benchmarks/BenchmarkTabletDriver.cs @@ -9,7 +9,7 @@ namespace osu.Framework.Benchmarks { public class BenchmarkTabletDriver : BenchmarkTest { - private TabletDriver driver; + private TabletDriver driver = null!; public override void SetUp() { diff --git a/osu.Framework.Benchmarks/BenchmarkTextBuilder.cs b/osu.Framework.Benchmarks/BenchmarkTextBuilder.cs index 61df335fa..4a40634bd 100644 --- a/osu.Framework.Benchmarks/BenchmarkTextBuilder.cs +++ b/osu.Framework.Benchmarks/BenchmarkTextBuilder.cs @@ -13,7 +13,7 @@ namespace osu.Framework.Benchmarks { private readonly ITexturedGlyphLookupStore store = new TestStore(); - private TextBuilder textBuilder; + private TextBuilder textBuilder = null!; [Benchmark] public void AddCharacters() => initialiseBuilder(false); diff --git a/osu.Framework.Benchmarks/BenchmarkTransform.cs b/osu.Framework.Benchmarks/BenchmarkTransform.cs index 4384db6bf..e6a62ae8d 100644 --- a/osu.Framework.Benchmarks/BenchmarkTransform.cs +++ b/osu.Framework.Benchmarks/BenchmarkTransform.cs @@ -13,7 +13,7 @@ namespace osu.Framework.Benchmarks { public class BenchmarkTransform : BenchmarkTest { - private Drawable target; + private Drawable target = null!; public override void SetUp() { diff --git a/osu.Framework.Benchmarks/BenchmarkTransformUpdate.cs b/osu.Framework.Benchmarks/BenchmarkTransformUpdate.cs index e13dd27bd..90e0d34bd 100644 --- a/osu.Framework.Benchmarks/BenchmarkTransformUpdate.cs +++ b/osu.Framework.Benchmarks/BenchmarkTransformUpdate.cs @@ -11,7 +11,8 @@ namespace osu.Framework.Benchmarks { public class BenchmarkTransformUpdate : BenchmarkTest { - private TestBox target; + private TestBox target = null!; + private TestBox targetNoTransforms = null!; public override void SetUp() { @@ -21,7 +22,8 @@ namespace osu.Framework.Benchmarks ManualClock clock; - target = new TestBox { Clock = new FramedClock(clock = new ManualClock()) }; + targetNoTransforms = new TestBox { Clock = new FramedClock(clock = new ManualClock()) }; + target = new TestBox { Clock = new FramedClock(clock) }; // transform one target member over a long period target.RotateTo(360, transforms_count * 2); @@ -34,6 +36,13 @@ namespace osu.Framework.Benchmarks target.Clock.ProcessFrame(); } + [Benchmark] + public void UpdateTransformsWithNonePresent() + { + for (int i = 0; i < 10000; i++) + targetNoTransforms.UpdateTransforms(); + } + [Benchmark] public void UpdateTransformsWithManyPresent() { diff --git a/osu.Framework.Benchmarks/BenchmarkWeakList.cs b/osu.Framework.Benchmarks/BenchmarkWeakList.cs index 6bb38b307..54ab24df7 100644 --- a/osu.Framework.Benchmarks/BenchmarkWeakList.cs +++ b/osu.Framework.Benchmarks/BenchmarkWeakList.cs @@ -14,7 +14,7 @@ namespace osu.Framework.Benchmarks public int ItemCount { get; set; } private readonly object[] objects = new object[1000]; - private WeakList weakList; + private WeakList weakList = null!; public override void SetUp() { diff --git a/osu.Framework.Benchmarks/GameBenchmark.cs b/osu.Framework.Benchmarks/GameBenchmark.cs index d14c4d406..3c90cbfe6 100644 --- a/osu.Framework.Benchmarks/GameBenchmark.cs +++ b/osu.Framework.Benchmarks/GameBenchmark.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using System.Threading; using System.Threading.Tasks; using BenchmarkDotNet.Attributes; @@ -14,9 +15,9 @@ namespace osu.Framework.Benchmarks [MemoryDiagnoser] public abstract class GameBenchmark { - private ManualGameHost gameHost; + private ManualGameHost gameHost = null!; - protected Game Game { get; private set; } + protected Game Game { get; private set; } = null!; [GlobalSetup] [OneTimeSetUp] @@ -29,8 +30,8 @@ namespace osu.Framework.Benchmarks [OneTimeTearDown] public virtual void TearDown() { - gameHost?.Exit(); - gameHost?.Dispose(); + gameHost.Exit(); + gameHost.Dispose(); } /// @@ -109,7 +110,9 @@ namespace osu.Framework.Benchmarks public override void RunMainLoop() { - RunOnce.Wait(); + if (!RunOnce.Wait(10000)) + throw new TimeoutException("Run request didn't arrive for a long time"); + RunSingleFrame(); RunOnce.Reset(); diff --git a/osu.Framework.NativeLibs/runtimes/linux-x64/native/libavcodec.so b/osu.Framework.NativeLibs/runtimes/linux-x64/native/libavcodec.so index e327c5860..160797968 100644 Binary files a/osu.Framework.NativeLibs/runtimes/linux-x64/native/libavcodec.so and b/osu.Framework.NativeLibs/runtimes/linux-x64/native/libavcodec.so differ diff --git a/osu.Framework.NativeLibs/runtimes/linux-x64/native/libavfilter.so b/osu.Framework.NativeLibs/runtimes/linux-x64/native/libavfilter.so index 35ec31e6f..b4372bba8 100644 Binary files a/osu.Framework.NativeLibs/runtimes/linux-x64/native/libavfilter.so and b/osu.Framework.NativeLibs/runtimes/linux-x64/native/libavfilter.so differ diff --git a/osu.Framework.NativeLibs/runtimes/linux-x64/native/libavformat.so b/osu.Framework.NativeLibs/runtimes/linux-x64/native/libavformat.so index 3614ba14f..df7c55893 100644 Binary files a/osu.Framework.NativeLibs/runtimes/linux-x64/native/libavformat.so and b/osu.Framework.NativeLibs/runtimes/linux-x64/native/libavformat.so differ diff --git a/osu.Framework.NativeLibs/runtimes/linux-x64/native/libavutil.so b/osu.Framework.NativeLibs/runtimes/linux-x64/native/libavutil.so index 5763fcfa1..267b124b8 100644 Binary files a/osu.Framework.NativeLibs/runtimes/linux-x64/native/libavutil.so and b/osu.Framework.NativeLibs/runtimes/linux-x64/native/libavutil.so differ diff --git a/osu.Framework.NativeLibs/runtimes/linux-x64/native/libswscale.so b/osu.Framework.NativeLibs/runtimes/linux-x64/native/libswscale.so index 7c19c179c..73b4b028e 100644 Binary files a/osu.Framework.NativeLibs/runtimes/linux-x64/native/libswscale.so and b/osu.Framework.NativeLibs/runtimes/linux-x64/native/libswscale.so differ diff --git a/osu.Framework.NativeLibs/runtimes/osx/native/libavcodec.58.dylib b/osu.Framework.NativeLibs/runtimes/osx/native/libavcodec.58.dylib index 77541405d..13971bdd5 100755 Binary files a/osu.Framework.NativeLibs/runtimes/osx/native/libavcodec.58.dylib and b/osu.Framework.NativeLibs/runtimes/osx/native/libavcodec.58.dylib differ diff --git a/osu.Framework.NativeLibs/runtimes/osx/native/libavfilter.7.dylib b/osu.Framework.NativeLibs/runtimes/osx/native/libavfilter.7.dylib index 9d5a5c5c7..6c7360f58 100755 Binary files a/osu.Framework.NativeLibs/runtimes/osx/native/libavfilter.7.dylib and b/osu.Framework.NativeLibs/runtimes/osx/native/libavfilter.7.dylib differ diff --git a/osu.Framework.NativeLibs/runtimes/osx/native/libavformat.58.dylib b/osu.Framework.NativeLibs/runtimes/osx/native/libavformat.58.dylib index 7e26e50cd..c637f3536 100755 Binary files a/osu.Framework.NativeLibs/runtimes/osx/native/libavformat.58.dylib and b/osu.Framework.NativeLibs/runtimes/osx/native/libavformat.58.dylib differ diff --git a/osu.Framework.NativeLibs/runtimes/osx/native/libavutil.56.dylib b/osu.Framework.NativeLibs/runtimes/osx/native/libavutil.56.dylib index cc6cff296..f0c9d71fc 100755 Binary files a/osu.Framework.NativeLibs/runtimes/osx/native/libavutil.56.dylib and b/osu.Framework.NativeLibs/runtimes/osx/native/libavutil.56.dylib differ diff --git a/osu.Framework.NativeLibs/runtimes/osx/native/libswscale.5.dylib b/osu.Framework.NativeLibs/runtimes/osx/native/libswscale.5.dylib index 97bf637ce..2ea2b72fe 100755 Binary files a/osu.Framework.NativeLibs/runtimes/osx/native/libswscale.5.dylib and b/osu.Framework.NativeLibs/runtimes/osx/native/libswscale.5.dylib differ diff --git a/osu.Framework.NativeLibs/runtimes/win-arm64/native/avcodec-58.dll b/osu.Framework.NativeLibs/runtimes/win-arm64/native/avcodec-58.dll index 5e3720235..5c549eb89 100644 Binary files a/osu.Framework.NativeLibs/runtimes/win-arm64/native/avcodec-58.dll and b/osu.Framework.NativeLibs/runtimes/win-arm64/native/avcodec-58.dll differ diff --git a/osu.Framework.NativeLibs/runtimes/win-arm64/native/avfilter-7.dll b/osu.Framework.NativeLibs/runtimes/win-arm64/native/avfilter-7.dll index 5872dfff0..5a061caca 100644 Binary files a/osu.Framework.NativeLibs/runtimes/win-arm64/native/avfilter-7.dll and b/osu.Framework.NativeLibs/runtimes/win-arm64/native/avfilter-7.dll differ diff --git a/osu.Framework.NativeLibs/runtimes/win-arm64/native/avformat-58.dll b/osu.Framework.NativeLibs/runtimes/win-arm64/native/avformat-58.dll index c511b18e9..263fa6cdc 100644 Binary files a/osu.Framework.NativeLibs/runtimes/win-arm64/native/avformat-58.dll and b/osu.Framework.NativeLibs/runtimes/win-arm64/native/avformat-58.dll differ diff --git a/osu.Framework.NativeLibs/runtimes/win-arm64/native/avutil-56.dll b/osu.Framework.NativeLibs/runtimes/win-arm64/native/avutil-56.dll index 8fce0d957..44eb2b8f5 100644 Binary files a/osu.Framework.NativeLibs/runtimes/win-arm64/native/avutil-56.dll and b/osu.Framework.NativeLibs/runtimes/win-arm64/native/avutil-56.dll differ diff --git a/osu.Framework.NativeLibs/runtimes/win-arm64/native/swscale-5.dll b/osu.Framework.NativeLibs/runtimes/win-arm64/native/swscale-5.dll index 28c2237e8..10f4217f5 100644 Binary files a/osu.Framework.NativeLibs/runtimes/win-arm64/native/swscale-5.dll and b/osu.Framework.NativeLibs/runtimes/win-arm64/native/swscale-5.dll differ diff --git a/osu.Framework.NativeLibs/runtimes/win-x64/native/avcodec-58.dll b/osu.Framework.NativeLibs/runtimes/win-x64/native/avcodec-58.dll index 3176fd7de..2cfe80e9e 100644 Binary files a/osu.Framework.NativeLibs/runtimes/win-x64/native/avcodec-58.dll and b/osu.Framework.NativeLibs/runtimes/win-x64/native/avcodec-58.dll differ diff --git a/osu.Framework.NativeLibs/runtimes/win-x64/native/avfilter-7.dll b/osu.Framework.NativeLibs/runtimes/win-x64/native/avfilter-7.dll index ead8af11b..dbac50102 100644 Binary files a/osu.Framework.NativeLibs/runtimes/win-x64/native/avfilter-7.dll and b/osu.Framework.NativeLibs/runtimes/win-x64/native/avfilter-7.dll differ diff --git a/osu.Framework.NativeLibs/runtimes/win-x64/native/avformat-58.dll b/osu.Framework.NativeLibs/runtimes/win-x64/native/avformat-58.dll index b1516dc34..4da1e28fa 100644 Binary files a/osu.Framework.NativeLibs/runtimes/win-x64/native/avformat-58.dll and b/osu.Framework.NativeLibs/runtimes/win-x64/native/avformat-58.dll differ diff --git a/osu.Framework.NativeLibs/runtimes/win-x64/native/avutil-56.dll b/osu.Framework.NativeLibs/runtimes/win-x64/native/avutil-56.dll index aa8fa70d7..0390cbb25 100644 Binary files a/osu.Framework.NativeLibs/runtimes/win-x64/native/avutil-56.dll and b/osu.Framework.NativeLibs/runtimes/win-x64/native/avutil-56.dll differ diff --git a/osu.Framework.NativeLibs/runtimes/win-x64/native/swscale-5.dll b/osu.Framework.NativeLibs/runtimes/win-x64/native/swscale-5.dll index f1e5e9748..2111d6903 100644 Binary files a/osu.Framework.NativeLibs/runtimes/win-x64/native/swscale-5.dll and b/osu.Framework.NativeLibs/runtimes/win-x64/native/swscale-5.dll differ diff --git a/osu.Framework.NativeLibs/runtimes/win-x86/native/avcodec-58.dll b/osu.Framework.NativeLibs/runtimes/win-x86/native/avcodec-58.dll index fcb7eccec..c74db8adf 100644 Binary files a/osu.Framework.NativeLibs/runtimes/win-x86/native/avcodec-58.dll and b/osu.Framework.NativeLibs/runtimes/win-x86/native/avcodec-58.dll differ diff --git a/osu.Framework.NativeLibs/runtimes/win-x86/native/avfilter-7.dll b/osu.Framework.NativeLibs/runtimes/win-x86/native/avfilter-7.dll index 90654500f..88d485bc5 100644 Binary files a/osu.Framework.NativeLibs/runtimes/win-x86/native/avfilter-7.dll and b/osu.Framework.NativeLibs/runtimes/win-x86/native/avfilter-7.dll differ diff --git a/osu.Framework.NativeLibs/runtimes/win-x86/native/avformat-58.dll b/osu.Framework.NativeLibs/runtimes/win-x86/native/avformat-58.dll index e9ac8863d..ddb51e11d 100644 Binary files a/osu.Framework.NativeLibs/runtimes/win-x86/native/avformat-58.dll and b/osu.Framework.NativeLibs/runtimes/win-x86/native/avformat-58.dll differ diff --git a/osu.Framework.NativeLibs/runtimes/win-x86/native/avutil-56.dll b/osu.Framework.NativeLibs/runtimes/win-x86/native/avutil-56.dll index 2cf7a160a..681ef5396 100644 Binary files a/osu.Framework.NativeLibs/runtimes/win-x86/native/avutil-56.dll and b/osu.Framework.NativeLibs/runtimes/win-x86/native/avutil-56.dll differ diff --git a/osu.Framework.NativeLibs/runtimes/win-x86/native/swscale-5.dll b/osu.Framework.NativeLibs/runtimes/win-x86/native/swscale-5.dll index 56de9082a..1e233c348 100644 Binary files a/osu.Framework.NativeLibs/runtimes/win-x86/native/swscale-5.dll and b/osu.Framework.NativeLibs/runtimes/win-x86/native/swscale-5.dll differ diff --git a/osu.Framework.NativeLibs/scripts/ffmpeg/common.sh b/osu.Framework.NativeLibs/scripts/ffmpeg/common.sh index c972e1631..36e5cf2e6 100755 --- a/osu.Framework.NativeLibs/scripts/ffmpeg/common.sh +++ b/osu.Framework.NativeLibs/scripts/ffmpeg/common.sh @@ -12,17 +12,32 @@ FFMPEG_FLAGS=( --disable-avdevice --disable-swresample --disable-librtmp + --disable-alsa + --disable-iconv + --disable-libxcb + --disable-libxcb-shm + --disable-libxcb-xfixes + --disable-libxcb-shape + --disable-sdl2 + --disable-zlib + --disable-bzlib + --disable-lzma + --disable-xlib + --disable-schannel --enable-shared ) function build_ffmpeg() { - echo "-> Downloading source..." - - curl https://ffmpeg.org/releases/ffmpeg-$FFMPEG_VERSION.tar.gz | tar zxf - - cd ffmpeg-$FFMPEG_VERSION + if [ ! -d "ffmpeg-$FFMPEG_VERSION" ]; then + echo "-> Downloading source..." + curl https://ffmpeg.org/releases/ffmpeg-$FFMPEG_VERSION.tar.gz | tar zxf - + else + echo "-> ffmpeg-$FFMPEG_VERSION already exists, not re-downloading." + fi echo "-> Configuring..." + cd ffmpeg-$FFMPEG_VERSION ./configure "${FFMPEG_FLAGS[@]}" CORES=0 diff --git a/osu.Framework.Templates/templates/template-empty/TemplateGame.Desktop/Program.cs b/osu.Framework.Templates/templates/template-empty/TemplateGame.Desktop/Program.cs index 35ee79168..ea720f4b3 100644 --- a/osu.Framework.Templates/templates/template-empty/TemplateGame.Desktop/Program.cs +++ b/osu.Framework.Templates/templates/template-empty/TemplateGame.Desktop/Program.cs @@ -8,7 +8,7 @@ namespace TemplateGame.Desktop { public static void Main() { - using (GameHost host = Host.GetSuitableHost(@"TemplateGame")) + using (GameHost host = Host.GetSuitableDesktopHost(@"TemplateGame")) using (osu.Framework.Game game = new TemplateGameGame()) host.Run(game); } diff --git a/osu.Framework.Templates/templates/template-empty/TemplateGame.Game.Tests/Program.cs b/osu.Framework.Templates/templates/template-empty/TemplateGame.Game.Tests/Program.cs index 67c4b7d6b..c07309edd 100644 --- a/osu.Framework.Templates/templates/template-empty/TemplateGame.Game.Tests/Program.cs +++ b/osu.Framework.Templates/templates/template-empty/TemplateGame.Game.Tests/Program.cs @@ -7,7 +7,7 @@ namespace TemplateGame.Game.Tests { public static void Main() { - using (GameHost host = Host.GetSuitableHost("visual-tests")) + using (GameHost host = Host.GetSuitableDesktopHost("visual-tests")) using (var game = new TemplateGameTestBrowser()) host.Run(game); } diff --git a/osu.Framework.Templates/templates/template-empty/TemplateGame.Game.Tests/Visual/TestSceneMainScreen.cs b/osu.Framework.Templates/templates/template-empty/TemplateGame.Game.Tests/Visual/TestSceneMainScreen.cs index 7f2029c35..35cced723 100644 --- a/osu.Framework.Templates/templates/template-empty/TemplateGame.Game.Tests/Visual/TestSceneMainScreen.cs +++ b/osu.Framework.Templates/templates/template-empty/TemplateGame.Game.Tests/Visual/TestSceneMainScreen.cs @@ -1,8 +1,10 @@ using osu.Framework.Graphics; using osu.Framework.Screens; +using NUnit.Framework; namespace TemplateGame.Game.Tests.Visual { + [TestFixture] public class TestSceneMainScreen : TemplateGameTestScene { // Add visual tests to ensure correct behaviour of your game: https://github.com/ppy/osu-framework/wiki/Development-and-Testing diff --git a/osu.Framework.Templates/templates/template-empty/TemplateGame.Game.Tests/Visual/TestSceneSpinningBox.cs b/osu.Framework.Templates/templates/template-empty/TemplateGame.Game.Tests/Visual/TestSceneSpinningBox.cs index d488964e6..92956d0df 100644 --- a/osu.Framework.Templates/templates/template-empty/TemplateGame.Game.Tests/Visual/TestSceneSpinningBox.cs +++ b/osu.Framework.Templates/templates/template-empty/TemplateGame.Game.Tests/Visual/TestSceneSpinningBox.cs @@ -1,7 +1,9 @@ using osu.Framework.Graphics; +using NUnit.Framework; namespace TemplateGame.Game.Tests.Visual { + [TestFixture] public class TestSceneSpinningBox : TemplateGameTestScene { // Add visual tests to ensure correct behaviour of your game: https://github.com/ppy/osu-framework/wiki/Development-and-Testing diff --git a/osu.Framework.Templates/templates/template-empty/TemplateGame.Game.Tests/Visual/TestSceneTemplateGameGame.cs b/osu.Framework.Templates/templates/template-empty/TemplateGame.Game.Tests/Visual/TestSceneTemplateGameGame.cs index 981d81f27..8d7f1adb0 100644 --- a/osu.Framework.Templates/templates/template-empty/TemplateGame.Game.Tests/Visual/TestSceneTemplateGameGame.cs +++ b/osu.Framework.Templates/templates/template-empty/TemplateGame.Game.Tests/Visual/TestSceneTemplateGameGame.cs @@ -1,8 +1,10 @@ using osu.Framework.Allocation; using osu.Framework.Platform; +using NUnit.Framework; namespace TemplateGame.Game.Tests.Visual { + [TestFixture] public class TestSceneTemplateGameGame : TemplateGameTestScene { // Add visual tests to ensure correct behaviour of your game: https://github.com/ppy/osu-framework/wiki/Development-and-Testing diff --git a/osu.Framework.Templates/templates/template-empty/TemplateGame.Game/TemplateGame.Game.csproj b/osu.Framework.Templates/templates/template-empty/TemplateGame.Game/TemplateGame.Game.csproj index 2f7d4b05e..90c01edaa 100644 --- a/osu.Framework.Templates/templates/template-empty/TemplateGame.Game/TemplateGame.Game.csproj +++ b/osu.Framework.Templates/templates/template-empty/TemplateGame.Game/TemplateGame.Game.csproj @@ -6,6 +6,6 @@ - + diff --git a/osu.Framework.Templates/templates/template-empty/TemplateGame.iOS/Application.cs b/osu.Framework.Templates/templates/template-empty/TemplateGame.iOS/Application.cs index 6007015d0..ae9254f74 100644 --- a/osu.Framework.Templates/templates/template-empty/TemplateGame.iOS/Application.cs +++ b/osu.Framework.Templates/templates/template-empty/TemplateGame.iOS/Application.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using osu.Framework.iOS; using UIKit; namespace TemplateGame.iOS diff --git a/osu.Framework.Templates/templates/template-empty/TemplateGame.iOS/Info.plist b/osu.Framework.Templates/templates/template-empty/TemplateGame.iOS/Info.plist index 6941e1b55..54c72da68 100644 --- a/osu.Framework.Templates/templates/template-empty/TemplateGame.iOS/Info.plist +++ b/osu.Framework.Templates/templates/template-empty/TemplateGame.iOS/Info.plist @@ -44,5 +44,9 @@ UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight + UIApplicationSupportsIndirectInputEvents + + CADisableMinimumFrameDurationOnPhone + diff --git a/osu.Framework.Templates/templates/template-empty/TemplateGame.iOS/TemplateGame.iOS.csproj b/osu.Framework.Templates/templates/template-empty/TemplateGame.iOS/TemplateGame.iOS.csproj index 409c83a6b..7448f3e88 100644 --- a/osu.Framework.Templates/templates/template-empty/TemplateGame.iOS/TemplateGame.iOS.csproj +++ b/osu.Framework.Templates/templates/template-empty/TemplateGame.iOS/TemplateGame.iOS.csproj @@ -19,6 +19,12 @@ TemplateGame.iOS TemplateGame + + + --nosymbolstrip=BASS_FX_BPM_BeatCallbackReset --nosymbolstrip=BASS_FX_BPM_BeatCallbackSet --nosymbolstrip=BASS_FX_BPM_BeatDecodeGet --nosymbolstrip=BASS_FX_BPM_BeatFree --nosymbolstrip=BASS_FX_BPM_BeatGetParameters --nosymbolstrip=BASS_FX_BPM_BeatSetParameters --nosymbolstrip=BASS_FX_BPM_CallbackReset --nosymbolstrip=BASS_FX_BPM_CallbackSet --nosymbolstrip=BASS_FX_BPM_DecodeGet --nosymbolstrip=BASS_FX_BPM_Free --nosymbolstrip=BASS_FX_BPM_Translate --nosymbolstrip=BASS_FX_GetVersion --nosymbolstrip=BASS_FX_ReverseCreate --nosymbolstrip=BASS_FX_ReverseGetSource --nosymbolstrip=BASS_FX_TempoCreate --nosymbolstrip=BASS_FX_TempoGetRateRatio --nosymbolstrip=BASS_FX_TempoGetSource --nosymbolstrip=BASS_Mixer_ChannelFlags --nosymbolstrip=BASS_Mixer_ChannelGetData --nosymbolstrip=BASS_Mixer_ChannelGetEnvelopePos --nosymbolstrip=BASS_Mixer_ChannelGetLevel --nosymbolstrip=BASS_Mixer_ChannelGetLevelEx --nosymbolstrip=BASS_Mixer_ChannelGetMatrix --nosymbolstrip=BASS_Mixer_ChannelGetMixer --nosymbolstrip=BASS_Mixer_ChannelGetPosition --nosymbolstrip=BASS_Mixer_ChannelGetPositionEx --nosymbolstrip=BASS_Mixer_ChannelIsActive --nosymbolstrip=BASS_Mixer_ChannelRemove --nosymbolstrip=BASS_Mixer_ChannelRemoveSync --nosymbolstrip=BASS_Mixer_ChannelSetEnvelope --nosymbolstrip=BASS_Mixer_ChannelSetEnvelopePos --nosymbolstrip=BASS_Mixer_ChannelSetMatrix --nosymbolstrip=BASS_Mixer_ChannelSetMatrixEx --nosymbolstrip=BASS_Mixer_ChannelSetPosition --nosymbolstrip=BASS_Mixer_ChannelSetSync --nosymbolstrip=BASS_Mixer_GetVersion --nosymbolstrip=BASS_Mixer_StreamAddChannel --nosymbolstrip=BASS_Mixer_StreamAddChannelEx --nosymbolstrip=BASS_Mixer_StreamCreate --nosymbolstrip=BASS_Mixer_StreamGetChannels --nosymbolstrip=BASS_Split_StreamCreate --nosymbolstrip=BASS_Split_StreamGetAvailable --nosymbolstrip=BASS_Split_StreamGetSource --nosymbolstrip=BASS_Split_StreamGetSplits --nosymbolstrip=BASS_Split_StreamReset --nosymbolstrip=BASS_Split_StreamResetEx + + --nolinkaway --nostrip $(GeneratedMtouchSymbolStripFlags) + true full @@ -54,7 +60,6 @@ prompt true None - --nolinkaway -gcc_flags "-lstdc++ -lbz2 -framework AudioToolbox -framework AVFoundation -framework CoreMedia -framework VideoToolbox -framework SystemConfiguration -framework CFNetwork -framework Accelerate" iPhone Developer @@ -80,7 +85,6 @@ true - --nolinkaway -gcc_flags "-lstdc++ -lbz2 -framework AudioToolbox -framework AVFoundation -framework CoreMedia -framework VideoToolbox -framework SystemConfiguration -framework CFNetwork -framework Accelerate" iPhone Developer @@ -98,7 +102,6 @@ 4 None x86_64 - --nolinkaway -gcc_flags "-lstdc++ -lbz2 -framework AudioToolbox -framework AVFoundation -framework CoreMedia -framework VideoToolbox -framework SystemConfiguration -framework CFNetwork -framework Accelerate" true @@ -106,7 +109,6 @@ iPhone Developer bin\iPhone\Release ARM64 - --nolinkaway -gcc_flags "-lstdc++ -lbz2 -framework AudioToolbox -framework AVFoundation -framework CoreMedia -framework VideoToolbox -framework SystemConfiguration -framework CFNetwork -framework Accelerate" @@ -128,18 +130,6 @@ {6E3EBF71-8664-49D7-BD0D-2B21B3EEC540} TemplateGame.Resources - - - - Static - False - True - - - Static - False - True - @@ -150,11 +140,11 @@ - + + - - + diff --git a/osu.Framework.Templates/templates/template-empty/TemplateGame.sln b/osu.Framework.Templates/templates/template-empty/TemplateGame.sln index c2d8c48d7..ff1127b8f 100644 --- a/osu.Framework.Templates/templates/template-empty/TemplateGame.sln +++ b/osu.Framework.Templates/templates/template-empty/TemplateGame.sln @@ -34,6 +34,7 @@ Global {AEB3FC89-DC3E-4BC9-9EC7-03B72FC5D849}.Debug|Any CPU.Build.0 = Debug|Any CPU {AEB3FC89-DC3E-4BC9-9EC7-03B72FC5D849}.Release|Any CPU.ActiveCfg = Release|Any CPU {AEB3FC89-DC3E-4BC9-9EC7-03B72FC5D849}.Release|Any CPU.Build.0 = Release|Any CPU + {7AA1DB5D-78DB-4693-AE50-D6078F5A0CAB}.Debug|Any CPU.ActiveCfg = Debug|iPhoneSimulator {7AA1DB5D-78DB-4693-AE50-D6078F5A0CAB}.Debug|iPhone.ActiveCfg = Debug|iPhone {7AA1DB5D-78DB-4693-AE50-D6078F5A0CAB}.Debug|iPhone.Build.0 = Debug|iPhone {7AA1DB5D-78DB-4693-AE50-D6078F5A0CAB}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator diff --git a/osu.Framework.Templates/templates/template-flappy/FlappyDon.Desktop/Program.cs b/osu.Framework.Templates/templates/template-flappy/FlappyDon.Desktop/Program.cs index 0e6bdc4f1..18a210664 100644 --- a/osu.Framework.Templates/templates/template-flappy/FlappyDon.Desktop/Program.cs +++ b/osu.Framework.Templates/templates/template-flappy/FlappyDon.Desktop/Program.cs @@ -8,7 +8,7 @@ namespace FlappyDon.Desktop { public static void Main() { - using (GameHost host = Host.GetSuitableHost(@"FlappyDon")) + using (GameHost host = Host.GetSuitableDesktopHost(@"FlappyDon")) using (osu.Framework.Game game = new FlappyDonGame()) { host.Run(game); diff --git a/osu.Framework.Templates/templates/template-flappy/FlappyDon.Game.Tests/Program.cs b/osu.Framework.Templates/templates/template-flappy/FlappyDon.Game.Tests/Program.cs index 59fbaf650..483bfaf1d 100644 --- a/osu.Framework.Templates/templates/template-flappy/FlappyDon.Game.Tests/Program.cs +++ b/osu.Framework.Templates/templates/template-flappy/FlappyDon.Game.Tests/Program.cs @@ -8,7 +8,7 @@ namespace FlappyDon.Game.Tests { public static void Main() { - using (GameHost host = Host.GetSuitableHost("visual-tests")) + using (GameHost host = Host.GetSuitableDesktopHost("visual-tests")) using (var game = new FlappyDonTestBrowser()) host.Run(game); } diff --git a/osu.Framework.Templates/templates/template-flappy/FlappyDon.Game.Tests/Visual/TestSceneBackdrop.cs b/osu.Framework.Templates/templates/template-flappy/FlappyDon.Game.Tests/Visual/TestSceneBackdrop.cs index e3e95a63d..442170ffa 100644 --- a/osu.Framework.Templates/templates/template-flappy/FlappyDon.Game.Tests/Visual/TestSceneBackdrop.cs +++ b/osu.Framework.Templates/templates/template-flappy/FlappyDon.Game.Tests/Visual/TestSceneBackdrop.cs @@ -1,5 +1,6 @@ using FlappyDon.Game.Elements; using osu.Framework.Allocation; +using NUnit.Framework; namespace FlappyDon.Game.Tests.Visual { @@ -7,6 +8,7 @@ namespace FlappyDon.Game.Tests.Visual /// A test scene for testing the alignment /// and placement of the sprites that make up the backdrop /// + [TestFixture] public class TestSceneBackdrop : FlappyDonTestScene { [BackgroundDependencyLoader] diff --git a/osu.Framework.Templates/templates/template-flappy/FlappyDon.Game.Tests/Visual/TestSceneFlappyDonGame.cs b/osu.Framework.Templates/templates/template-flappy/FlappyDon.Game.Tests/Visual/TestSceneFlappyDonGame.cs index c9b6c4224..a891a7d51 100644 --- a/osu.Framework.Templates/templates/template-flappy/FlappyDon.Game.Tests/Visual/TestSceneFlappyDonGame.cs +++ b/osu.Framework.Templates/templates/template-flappy/FlappyDon.Game.Tests/Visual/TestSceneFlappyDonGame.cs @@ -1,5 +1,6 @@ using osu.Framework.Allocation; using osu.Framework.Platform; +using NUnit.Framework; namespace FlappyDon.Game.Tests.Visual { @@ -7,6 +8,7 @@ namespace FlappyDon.Game.Tests.Visual /// A test scene wrapping the entire game, /// including audio. /// + [TestFixture] public class TestSceneFlappyDonGame : FlappyDonTestScene { private FlappyDonGame game; diff --git a/osu.Framework.Templates/templates/template-flappy/FlappyDon.Game.Tests/Visual/TestSceneObstacles.cs b/osu.Framework.Templates/templates/template-flappy/FlappyDon.Game.Tests/Visual/TestSceneObstacles.cs index 133af5dc5..4a7702f1d 100644 --- a/osu.Framework.Templates/templates/template-flappy/FlappyDon.Game.Tests/Visual/TestSceneObstacles.cs +++ b/osu.Framework.Templates/templates/template-flappy/FlappyDon.Game.Tests/Visual/TestSceneObstacles.cs @@ -1,12 +1,14 @@ using FlappyDon.Game.Elements; using osu.Framework.Allocation; using osu.Framework.Graphics; +using NUnit.Framework; namespace FlappyDon.Game.Tests.Visual { /// /// A scene to test the layout and positioning and rotation of two pipe sprites. /// + [TestFixture] public class TestSceneObstacles : FlappyDonTestScene { [BackgroundDependencyLoader] diff --git a/osu.Framework.Templates/templates/template-flappy/FlappyDon.Game.Tests/Visual/TestScenePipeObstacle.cs b/osu.Framework.Templates/templates/template-flappy/FlappyDon.Game.Tests/Visual/TestScenePipeObstacle.cs index 1ef9bed52..a0491b8d3 100644 --- a/osu.Framework.Templates/templates/template-flappy/FlappyDon.Game.Tests/Visual/TestScenePipeObstacle.cs +++ b/osu.Framework.Templates/templates/template-flappy/FlappyDon.Game.Tests/Visual/TestScenePipeObstacle.cs @@ -1,12 +1,14 @@ using FlappyDon.Game.Elements; using osu.Framework.Allocation; using osu.Framework.Graphics; +using NUnit.Framework; namespace FlappyDon.Game.Tests.Visual { /// /// A scene to test the layout and positioning and rotation of two pipe sprites. /// + [TestFixture] public class TestScenePipeObstacle : FlappyDonTestScene { [BackgroundDependencyLoader] diff --git a/osu.Framework.Templates/templates/template-flappy/FlappyDon.Game/FlappyDon.Game.csproj b/osu.Framework.Templates/templates/template-flappy/FlappyDon.Game/FlappyDon.Game.csproj index 157b6500b..170c58c54 100644 --- a/osu.Framework.Templates/templates/template-flappy/FlappyDon.Game/FlappyDon.Game.csproj +++ b/osu.Framework.Templates/templates/template-flappy/FlappyDon.Game/FlappyDon.Game.csproj @@ -2,10 +2,10 @@ netstandard2.1 - - - + + + diff --git a/osu.Framework.Templates/templates/template-flappy/FlappyDon.Game/FlappyDonGameBase.cs b/osu.Framework.Templates/templates/template-flappy/FlappyDon.Game/FlappyDonGameBase.cs index c0ce37846..bfbe526b8 100644 --- a/osu.Framework.Templates/templates/template-flappy/FlappyDon.Game/FlappyDonGameBase.cs +++ b/osu.Framework.Templates/templates/template-flappy/FlappyDon.Game/FlappyDonGameBase.cs @@ -2,8 +2,6 @@ using osu.Framework.Allocation; using osu.Framework.Graphics.Textures; using osu.Framework.IO.Stores; -using osu.Framework.Platform; -using osuTK.Graphics.ES30; namespace FlappyDon.Game { @@ -12,23 +10,16 @@ namespace FlappyDon.Game /// public abstract class FlappyDonGameBase : osu.Framework.Game { - private TextureStore textures; - - private DependencyContainer dependencies; + protected override TextureFilteringMode DefaultTextureFilteringMode + // To preserve the 8-bit aesthetic, disable texture filtering + // so they won't become blurry when upscaled + => TextureFilteringMode.Nearest; [BackgroundDependencyLoader] - private void load(GameHost host) + private void load() { // Load the assets from our Resources project Resources.AddStore(new DllResourceStore(FlappyDonResources.ResourceAssembly)); - - // To preserve the 8-bit aesthetic, disable texture filtering - // so they won't become blurry when upscaled - textures = new TextureStore(Textures, filteringMode: All.Nearest); - dependencies.Cache(textures); } - - protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) - => dependencies = new DependencyContainer(base.CreateChildDependencies(parent)); } } diff --git a/osu.Framework.Templates/templates/template-flappy/FlappyDon.iOS/FlappyDon.iOS.csproj b/osu.Framework.Templates/templates/template-flappy/FlappyDon.iOS/FlappyDon.iOS.csproj index 0a65e0c0e..963d8d177 100644 --- a/osu.Framework.Templates/templates/template-flappy/FlappyDon.iOS/FlappyDon.iOS.csproj +++ b/osu.Framework.Templates/templates/template-flappy/FlappyDon.iOS/FlappyDon.iOS.csproj @@ -19,6 +19,12 @@ FlappyDon.iOS FlappyDon + + + --nosymbolstrip=BASS_FX_BPM_BeatCallbackReset --nosymbolstrip=BASS_FX_BPM_BeatCallbackSet --nosymbolstrip=BASS_FX_BPM_BeatDecodeGet --nosymbolstrip=BASS_FX_BPM_BeatFree --nosymbolstrip=BASS_FX_BPM_BeatGetParameters --nosymbolstrip=BASS_FX_BPM_BeatSetParameters --nosymbolstrip=BASS_FX_BPM_CallbackReset --nosymbolstrip=BASS_FX_BPM_CallbackSet --nosymbolstrip=BASS_FX_BPM_DecodeGet --nosymbolstrip=BASS_FX_BPM_Free --nosymbolstrip=BASS_FX_BPM_Translate --nosymbolstrip=BASS_FX_GetVersion --nosymbolstrip=BASS_FX_ReverseCreate --nosymbolstrip=BASS_FX_ReverseGetSource --nosymbolstrip=BASS_FX_TempoCreate --nosymbolstrip=BASS_FX_TempoGetRateRatio --nosymbolstrip=BASS_FX_TempoGetSource --nosymbolstrip=BASS_Mixer_ChannelFlags --nosymbolstrip=BASS_Mixer_ChannelGetData --nosymbolstrip=BASS_Mixer_ChannelGetEnvelopePos --nosymbolstrip=BASS_Mixer_ChannelGetLevel --nosymbolstrip=BASS_Mixer_ChannelGetLevelEx --nosymbolstrip=BASS_Mixer_ChannelGetMatrix --nosymbolstrip=BASS_Mixer_ChannelGetMixer --nosymbolstrip=BASS_Mixer_ChannelGetPosition --nosymbolstrip=BASS_Mixer_ChannelGetPositionEx --nosymbolstrip=BASS_Mixer_ChannelIsActive --nosymbolstrip=BASS_Mixer_ChannelRemove --nosymbolstrip=BASS_Mixer_ChannelRemoveSync --nosymbolstrip=BASS_Mixer_ChannelSetEnvelope --nosymbolstrip=BASS_Mixer_ChannelSetEnvelopePos --nosymbolstrip=BASS_Mixer_ChannelSetMatrix --nosymbolstrip=BASS_Mixer_ChannelSetMatrixEx --nosymbolstrip=BASS_Mixer_ChannelSetPosition --nosymbolstrip=BASS_Mixer_ChannelSetSync --nosymbolstrip=BASS_Mixer_GetVersion --nosymbolstrip=BASS_Mixer_StreamAddChannel --nosymbolstrip=BASS_Mixer_StreamAddChannelEx --nosymbolstrip=BASS_Mixer_StreamCreate --nosymbolstrip=BASS_Mixer_StreamGetChannels --nosymbolstrip=BASS_Split_StreamCreate --nosymbolstrip=BASS_Split_StreamGetAvailable --nosymbolstrip=BASS_Split_StreamGetSource --nosymbolstrip=BASS_Split_StreamGetSplits --nosymbolstrip=BASS_Split_StreamReset --nosymbolstrip=BASS_Split_StreamResetEx + + --nolinkaway --nostrip $(GeneratedMtouchSymbolStripFlags) + true full @@ -62,7 +68,6 @@ True true None - --nolinkaway -gcc_flags "-lstdc++ -lbz2 -framework AudioToolbox -framework AVFoundation -framework CoreMedia -framework VideoToolbox -framework SystemConfiguration -framework CFNetwork -framework Accelerate" iPhone Developer @@ -91,7 +96,6 @@ true - --nolinkaway -gcc_flags "-lstdc++ -lbz2 -framework AudioToolbox -framework AVFoundation -framework CoreMedia -framework VideoToolbox -framework SystemConfiguration -framework CFNetwork -framework Accelerate" true @@ -107,14 +111,12 @@ SdkOnly true iPhone Developer - --nolinkaway -gcc_flags "-lstdc++ -lbz2 -framework AudioToolbox -framework AVFoundation -framework CoreMedia -framework VideoToolbox -framework SystemConfiguration -framework CFNetwork -framework Accelerate" x86_64 true iPhone Distribution true - --nolinkaway -gcc_flags "-lstdc++ -lbz2 -framework AudioToolbox -framework AVFoundation -framework CoreMedia -framework VideoToolbox -framework SystemConfiguration -framework CFNetwork -framework Accelerate" bin\iPhone\Release ARM64 @@ -139,19 +141,9 @@ false - - - - - Static - False - True - - - Static - False - True - + + false + @@ -162,11 +154,11 @@ - + + - - + - + \ No newline at end of file diff --git a/osu.Framework.Templates/templates/template-flappy/FlappyDon.iOS/Info.plist b/osu.Framework.Templates/templates/template-flappy/FlappyDon.iOS/Info.plist index 6cf61d564..9d594bf3b 100644 --- a/osu.Framework.Templates/templates/template-flappy/FlappyDon.iOS/Info.plist +++ b/osu.Framework.Templates/templates/template-flappy/FlappyDon.iOS/Info.plist @@ -44,5 +44,9 @@ MinimumOSVersion 11.0 + UIApplicationSupportsIndirectInputEvents + + CADisableMinimumFrameDurationOnPhone + diff --git a/osu.Framework.Templates/templates/template-flappy/FlappyDon.sln b/osu.Framework.Templates/templates/template-flappy/FlappyDon.sln index 0cdcc038a..8125e85c5 100644 --- a/osu.Framework.Templates/templates/template-flappy/FlappyDon.sln +++ b/osu.Framework.Templates/templates/template-flappy/FlappyDon.sln @@ -33,6 +33,7 @@ Global {AEB3FC89-DC3E-4BC9-9EC7-03B72FC5D849}.Debug|Any CPU.Build.0 = Debug|Any CPU {AEB3FC89-DC3E-4BC9-9EC7-03B72FC5D849}.Release|Any CPU.ActiveCfg = Release|Any CPU {AEB3FC89-DC3E-4BC9-9EC7-03B72FC5D849}.Release|Any CPU.Build.0 = Release|Any CPU + {7AA1DB5D-78DB-4693-AE50-D6078F5A0CAB}.Debug|Any CPU.ActiveCfg = Debug|iPhoneSimulator {7AA1DB5D-78DB-4693-AE50-D6078F5A0CAB}.Debug|iPhone.ActiveCfg = Debug|iPhone {7AA1DB5D-78DB-4693-AE50-D6078F5A0CAB}.Debug|iPhone.Build.0 = Debug|iPhone {7AA1DB5D-78DB-4693-AE50-D6078F5A0CAB}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator diff --git a/osu.Framework.Tests.Android/TestGameActivity.cs b/osu.Framework.Tests.Android/TestGameActivity.cs index bc48ab8bd..19851817f 100644 --- a/osu.Framework.Tests.Android/TestGameActivity.cs +++ b/osu.Framework.Tests.Android/TestGameActivity.cs @@ -6,7 +6,7 @@ using osu.Framework.Android; namespace osu.Framework.Tests.Android { - [Activity(ConfigurationChanges = DEFAULT_CONFIG_CHANGES, LaunchMode = DEFAULT_LAUNCH_MODE, MainLauncher = true)] + [Activity(ConfigurationChanges = DEFAULT_CONFIG_CHANGES, Exported = true, LaunchMode = DEFAULT_LAUNCH_MODE, MainLauncher = true)] public class TestGameActivity : AndroidGameActivity { protected override Game CreateGame() diff --git a/osu.Framework.Tests.iOS/AppDelegate.cs b/osu.Framework.Tests.iOS/AppDelegate.cs index 474d39c6d..ffe7ca39d 100644 --- a/osu.Framework.Tests.iOS/AppDelegate.cs +++ b/osu.Framework.Tests.iOS/AppDelegate.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using Foundation; using osu.Framework.iOS; diff --git a/osu.Framework.Tests.iOS/Application.cs b/osu.Framework.Tests.iOS/Application.cs index 5e4c4f780..210ad989d 100644 --- a/osu.Framework.Tests.iOS/Application.cs +++ b/osu.Framework.Tests.iOS/Application.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.iOS; using UIKit; diff --git a/osu.Framework.Tests/Audio/AudioCollectionManagerTest.cs b/osu.Framework.Tests/Audio/AudioCollectionManagerTest.cs index ca51933d8..53c39d793 100644 --- a/osu.Framework.Tests/Audio/AudioCollectionManagerTest.cs +++ b/osu.Framework.Tests/Audio/AudioCollectionManagerTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Threading; using NUnit.Framework; using osu.Framework.Audio; diff --git a/osu.Framework.Tests/Audio/AudioComponentTest.cs b/osu.Framework.Tests/Audio/AudioComponentTest.cs index 98845de4b..accb910b7 100644 --- a/osu.Framework.Tests/Audio/AudioComponentTest.cs +++ b/osu.Framework.Tests/Audio/AudioComponentTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Audio.Sample; using osu.Framework.Audio.Track; diff --git a/osu.Framework.Tests/Audio/AudioManagerWithDeviceLoss.cs b/osu.Framework.Tests/Audio/AudioManagerWithDeviceLoss.cs index d1f5977b3..924318008 100644 --- a/osu.Framework.Tests/Audio/AudioManagerWithDeviceLoss.cs +++ b/osu.Framework.Tests/Audio/AudioManagerWithDeviceLoss.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using System.Linq; using ManagedBass; diff --git a/osu.Framework.Tests/Audio/AudioThreadTest.cs b/osu.Framework.Tests/Audio/AudioThreadTest.cs index 66318ea20..dd85628fd 100644 --- a/osu.Framework.Tests/Audio/AudioThreadTest.cs +++ b/osu.Framework.Tests/Audio/AudioThreadTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Threading; using System.Threading.Tasks; diff --git a/osu.Framework.Tests/Audio/BassAudioMixerTest.cs b/osu.Framework.Tests/Audio/BassAudioMixerTest.cs index 9163cf9cc..cc9a5fdbb 100644 --- a/osu.Framework.Tests/Audio/BassAudioMixerTest.cs +++ b/osu.Framework.Tests/Audio/BassAudioMixerTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Threading; using ManagedBass; diff --git a/osu.Framework.Tests/Audio/BassTestComponents.cs b/osu.Framework.Tests/Audio/BassTestComponents.cs index 2f407b764..772bb0c6c 100644 --- a/osu.Framework.Tests/Audio/BassTestComponents.cs +++ b/osu.Framework.Tests/Audio/BassTestComponents.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Threading; diff --git a/osu.Framework.Tests/Audio/DeviceLosingAudioTest.cs b/osu.Framework.Tests/Audio/DeviceLosingAudioTest.cs index cf2a00ee2..0a92aa35e 100644 --- a/osu.Framework.Tests/Audio/DeviceLosingAudioTest.cs +++ b/osu.Framework.Tests/Audio/DeviceLosingAudioTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using NUnit.Framework; diff --git a/osu.Framework.Tests/Audio/DevicelessAudioTest.cs b/osu.Framework.Tests/Audio/DevicelessAudioTest.cs index 2ca741bd5..2d38c7d82 100644 --- a/osu.Framework.Tests/Audio/DevicelessAudioTest.cs +++ b/osu.Framework.Tests/Audio/DevicelessAudioTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; namespace osu.Framework.Tests.Audio diff --git a/osu.Framework.Tests/Audio/SampleBassInitTest.cs b/osu.Framework.Tests/Audio/SampleBassInitTest.cs index dea9f79fd..bf4df08a9 100644 --- a/osu.Framework.Tests/Audio/SampleBassInitTest.cs +++ b/osu.Framework.Tests/Audio/SampleBassInitTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Audio.Sample; diff --git a/osu.Framework.Tests/Audio/SampleBassTest.cs b/osu.Framework.Tests/Audio/SampleBassTest.cs index 399e20bf3..ed0155b18 100644 --- a/osu.Framework.Tests/Audio/SampleBassTest.cs +++ b/osu.Framework.Tests/Audio/SampleBassTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Threading; using NUnit.Framework; diff --git a/osu.Framework.Tests/Audio/SampleChannelVirtualTest.cs b/osu.Framework.Tests/Audio/SampleChannelVirtualTest.cs index 3ca56f2f7..67a4a2e07 100644 --- a/osu.Framework.Tests/Audio/SampleChannelVirtualTest.cs +++ b/osu.Framework.Tests/Audio/SampleChannelVirtualTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Threading; using NUnit.Framework; diff --git a/osu.Framework.Tests/Audio/TestAudioAdjustments.cs b/osu.Framework.Tests/Audio/TestAudioAdjustments.cs index b40dd2222..3506b811a 100644 --- a/osu.Framework.Tests/Audio/TestAudioAdjustments.cs +++ b/osu.Framework.Tests/Audio/TestAudioAdjustments.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Runtime.CompilerServices; using NUnit.Framework; diff --git a/osu.Framework.Tests/Audio/TestSceneDrawableTrack.cs b/osu.Framework.Tests/Audio/TestSceneDrawableTrack.cs index fad2adc5e..63d912105 100644 --- a/osu.Framework.Tests/Audio/TestSceneDrawableTrack.cs +++ b/osu.Framework.Tests/Audio/TestSceneDrawableTrack.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Audio; diff --git a/osu.Framework.Tests/Audio/TrackBassTest.cs b/osu.Framework.Tests/Audio/TrackBassTest.cs index 643c74730..49b711428 100644 --- a/osu.Framework.Tests/Audio/TrackBassTest.cs +++ b/osu.Framework.Tests/Audio/TrackBassTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Threading; using NUnit.Framework; diff --git a/osu.Framework.Tests/Audio/TrackVirtualTest.cs b/osu.Framework.Tests/Audio/TrackVirtualTest.cs index f3b9ffa55..9c8632d26 100644 --- a/osu.Framework.Tests/Audio/TrackVirtualTest.cs +++ b/osu.Framework.Tests/Audio/TrackVirtualTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Diagnostics; using System.Threading; diff --git a/osu.Framework.Tests/AutomatedVisualTestGame.cs b/osu.Framework.Tests/AutomatedVisualTestGame.cs index 517aa0039..a209f0836 100644 --- a/osu.Framework.Tests/AutomatedVisualTestGame.cs +++ b/osu.Framework.Tests/AutomatedVisualTestGame.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Testing; namespace osu.Framework.Tests diff --git a/osu.Framework.Tests/Bindables/AggregateBindableTest.cs b/osu.Framework.Tests/Bindables/AggregateBindableTest.cs index d74800a28..b9f7d1bdb 100644 --- a/osu.Framework.Tests/Bindables/AggregateBindableTest.cs +++ b/osu.Framework.Tests/Bindables/AggregateBindableTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Threading; using NUnit.Framework; using osu.Framework.Bindables; diff --git a/osu.Framework.Tests/Bindables/BindableBindingTest.cs b/osu.Framework.Tests/Bindables/BindableBindingTest.cs index d4bfc49ef..110ddaefa 100644 --- a/osu.Framework.Tests/Bindables/BindableBindingTest.cs +++ b/osu.Framework.Tests/Bindables/BindableBindingTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using NUnit.Framework; using osu.Framework.Allocation; @@ -109,7 +111,7 @@ namespace osu.Framework.Tests.Bindables int changed1 = 0, changed2 = 0; - bindable1.DefaultChanged += v => changed1++; + bindable1.DefaultChanged += _ => changed1++; bindable2.DefaultChanged += _ => { bindable2.Default = "won't change"; @@ -167,7 +169,7 @@ namespace osu.Framework.Tests.Bindables int changed1 = 0, changed2 = 0; - bindable1.ValueChanged += v => changed1++; + bindable1.ValueChanged += _ => changed1++; bindable2.ValueChanged += _ => { bindable2.Value = "won't change"; @@ -218,7 +220,7 @@ namespace osu.Framework.Tests.Bindables int changed1 = 0, changed2 = 0; - bindable1.DisabledChanged += v => changed1++; + bindable1.DisabledChanged += _ => changed1++; bindable2.DisabledChanged += _ => { bindable2.Disabled = false; @@ -267,7 +269,7 @@ namespace osu.Framework.Tests.Bindables int changed1 = 0, changed2 = 0; - bindable1.MinValueChanged += v => changed1++; + bindable1.MinValueChanged += _ => changed1++; bindable2.MinValueChanged += _ => { bindable2.MinValue = 1337; @@ -316,7 +318,7 @@ namespace osu.Framework.Tests.Bindables int changed1 = 0, changed2 = 0; - bindable1.MaxValueChanged += v => changed1++; + bindable1.MaxValueChanged += _ => changed1++; bindable2.MaxValueChanged += _ => { bindable2.MaxValue = 1337; diff --git a/osu.Framework.Tests/Bindables/BindableBoolTest.cs b/osu.Framework.Tests/Bindables/BindableBoolTest.cs index dc7677fd2..3114ec961 100644 --- a/osu.Framework.Tests/Bindables/BindableBoolTest.cs +++ b/osu.Framework.Tests/Bindables/BindableBoolTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Bindables; diff --git a/osu.Framework.Tests/Bindables/BindableDictionaryTest.cs b/osu.Framework.Tests/Bindables/BindableDictionaryTest.cs index 8b4a53cff..e23094190 100644 --- a/osu.Framework.Tests/Bindables/BindableDictionaryTest.cs +++ b/osu.Framework.Tests/Bindables/BindableDictionaryTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; @@ -815,7 +817,7 @@ namespace osu.Framework.Tests.Bindables [Test] public void TestDisabledWhenSetToCurrentValueDoesNotNotifySubscriber() { - bindableStringByteDictionary.DisabledChanged += b => Assert.Fail(); + bindableStringByteDictionary.DisabledChanged += _ => Assert.Fail(); bindableStringByteDictionary.Disabled = bindableStringByteDictionary.Disabled; } @@ -823,9 +825,9 @@ namespace osu.Framework.Tests.Bindables [Test] public void TestDisabledWhenSetToCurrentValueDoesNotNotifySubscribers() { - bindableStringByteDictionary.DisabledChanged += b => Assert.Fail(); - bindableStringByteDictionary.DisabledChanged += b => Assert.Fail(); - bindableStringByteDictionary.DisabledChanged += b => Assert.Fail(); + bindableStringByteDictionary.DisabledChanged += _ => Assert.Fail(); + bindableStringByteDictionary.DisabledChanged += _ => Assert.Fail(); + bindableStringByteDictionary.DisabledChanged += _ => Assert.Fail(); bindableStringByteDictionary.Disabled = bindableStringByteDictionary.Disabled; } diff --git a/osu.Framework.Tests/Bindables/BindableDoubleTest.cs b/osu.Framework.Tests/Bindables/BindableDoubleTest.cs index c6e8a8053..506d0ef51 100644 --- a/osu.Framework.Tests/Bindables/BindableDoubleTest.cs +++ b/osu.Framework.Tests/Bindables/BindableDoubleTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Bindables; diff --git a/osu.Framework.Tests/Bindables/BindableEnumTest.cs b/osu.Framework.Tests/Bindables/BindableEnumTest.cs index 7d8a6aa0f..c2df41339 100644 --- a/osu.Framework.Tests/Bindables/BindableEnumTest.cs +++ b/osu.Framework.Tests/Bindables/BindableEnumTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Linq; using NUnit.Framework; diff --git a/osu.Framework.Tests/Bindables/BindableFloatTest.cs b/osu.Framework.Tests/Bindables/BindableFloatTest.cs index f671afcfe..37c5e1421 100644 --- a/osu.Framework.Tests/Bindables/BindableFloatTest.cs +++ b/osu.Framework.Tests/Bindables/BindableFloatTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Bindables; diff --git a/osu.Framework.Tests/Bindables/BindableIntTest.cs b/osu.Framework.Tests/Bindables/BindableIntTest.cs index 7626da2ca..328a9c4ba 100644 --- a/osu.Framework.Tests/Bindables/BindableIntTest.cs +++ b/osu.Framework.Tests/Bindables/BindableIntTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Bindables; diff --git a/osu.Framework.Tests/Bindables/BindableLeasingTest.cs b/osu.Framework.Tests/Bindables/BindableLeasingTest.cs index 3fa444bed..fc2323e67 100644 --- a/osu.Framework.Tests/Bindables/BindableLeasingTest.cs +++ b/osu.Framework.Tests/Bindables/BindableLeasingTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using NUnit.Framework; using osu.Framework.Bindables; diff --git a/osu.Framework.Tests/Bindables/BindableListTest.cs b/osu.Framework.Tests/Bindables/BindableListTest.cs index e856d3c00..dc60ea921 100644 --- a/osu.Framework.Tests/Bindables/BindableListTest.cs +++ b/osu.Framework.Tests/Bindables/BindableListTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Collections.Specialized; @@ -1277,7 +1279,7 @@ namespace osu.Framework.Tests.Bindables [Test] public void TestDisabledWhenSetToCurrentValueDoesNotNotifySubscriber() { - bindableStringList.DisabledChanged += b => Assert.Fail(); + bindableStringList.DisabledChanged += _ => Assert.Fail(); bindableStringList.Disabled = bindableStringList.Disabled; } @@ -1285,9 +1287,9 @@ namespace osu.Framework.Tests.Bindables [Test] public void TestDisabledWhenSetToCurrentValueDoesNotNotifySubscribers() { - bindableStringList.DisabledChanged += b => Assert.Fail(); - bindableStringList.DisabledChanged += b => Assert.Fail(); - bindableStringList.DisabledChanged += b => Assert.Fail(); + bindableStringList.DisabledChanged += _ => Assert.Fail(); + bindableStringList.DisabledChanged += _ => Assert.Fail(); + bindableStringList.DisabledChanged += _ => Assert.Fail(); bindableStringList.Disabled = bindableStringList.Disabled; } diff --git a/osu.Framework.Tests/Bindables/BindableLongTest.cs b/osu.Framework.Tests/Bindables/BindableLongTest.cs index 5d92490a8..8da72a093 100644 --- a/osu.Framework.Tests/Bindables/BindableLongTest.cs +++ b/osu.Framework.Tests/Bindables/BindableLongTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Bindables; diff --git a/osu.Framework.Tests/Bindables/BindableMarginPaddingTest.cs b/osu.Framework.Tests/Bindables/BindableMarginPaddingTest.cs index fad7c26d6..391e6a42f 100644 --- a/osu.Framework.Tests/Bindables/BindableMarginPaddingTest.cs +++ b/osu.Framework.Tests/Bindables/BindableMarginPaddingTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Bindables; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Bindables/BindableNumberTest.cs b/osu.Framework.Tests/Bindables/BindableNumberTest.cs index d9147a780..cf17ed00e 100644 --- a/osu.Framework.Tests/Bindables/BindableNumberTest.cs +++ b/osu.Framework.Tests/Bindables/BindableNumberTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Reflection; diff --git a/osu.Framework.Tests/Bindables/BindableSerializationTest.cs b/osu.Framework.Tests/Bindables/BindableSerializationTest.cs index a54854bed..de0012fbe 100644 --- a/osu.Framework.Tests/Bindables/BindableSerializationTest.cs +++ b/osu.Framework.Tests/Bindables/BindableSerializationTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using Newtonsoft.Json; using NUnit.Framework; using osu.Framework.Bindables; diff --git a/osu.Framework.Tests/Bindables/BindableSizeTest.cs b/osu.Framework.Tests/Bindables/BindableSizeTest.cs index d5e4c9c70..8721e4846 100644 --- a/osu.Framework.Tests/Bindables/BindableSizeTest.cs +++ b/osu.Framework.Tests/Bindables/BindableSizeTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using System.Drawing; using osu.Framework.Bindables; diff --git a/osu.Framework.Tests/Bindables/BindableStringTest.cs b/osu.Framework.Tests/Bindables/BindableStringTest.cs index e2344ddae..6419651c5 100644 --- a/osu.Framework.Tests/Bindables/BindableStringTest.cs +++ b/osu.Framework.Tests/Bindables/BindableStringTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Bindables; diff --git a/osu.Framework.Tests/Bindables/BindableTest.cs b/osu.Framework.Tests/Bindables/BindableTest.cs index 93a523dc2..5cff3b295 100644 --- a/osu.Framework.Tests/Bindables/BindableTest.cs +++ b/osu.Framework.Tests/Bindables/BindableTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/osu.Framework.Tests/Bindables/BindableWithCurrentTest.cs b/osu.Framework.Tests/Bindables/BindableWithCurrentTest.cs index a5d2f56a5..78ebfcce2 100644 --- a/osu.Framework.Tests/Bindables/BindableWithCurrentTest.cs +++ b/osu.Framework.Tests/Bindables/BindableWithCurrentTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Bindables; using osu.Framework.Graphics.UserInterface; diff --git a/osu.Framework.Tests/Bindables/RangeConstrainedBindableTest.cs b/osu.Framework.Tests/Bindables/RangeConstrainedBindableTest.cs index 04ca637f7..f95976f1c 100644 --- a/osu.Framework.Tests/Bindables/RangeConstrainedBindableTest.cs +++ b/osu.Framework.Tests/Bindables/RangeConstrainedBindableTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Bindables; diff --git a/osu.Framework.Tests/Clocks/DecoupleableClockTest.cs b/osu.Framework.Tests/Clocks/DecoupleableClockTest.cs index 5941686f9..27ead2418 100644 --- a/osu.Framework.Tests/Clocks/DecoupleableClockTest.cs +++ b/osu.Framework.Tests/Clocks/DecoupleableClockTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Threading; using NUnit.Framework; diff --git a/osu.Framework.Tests/Clocks/InterpolatingClockTest.cs b/osu.Framework.Tests/Clocks/InterpolatingClockTest.cs index 0f2c1fbc3..b5e00d463 100644 --- a/osu.Framework.Tests/Clocks/InterpolatingClockTest.cs +++ b/osu.Framework.Tests/Clocks/InterpolatingClockTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Threading; using NUnit.Framework; diff --git a/osu.Framework.Tests/Clocks/StopwatchClockTest.cs b/osu.Framework.Tests/Clocks/StopwatchClockTest.cs index 3b19a9b4f..1a04ec4b6 100644 --- a/osu.Framework.Tests/Clocks/StopwatchClockTest.cs +++ b/osu.Framework.Tests/Clocks/StopwatchClockTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Threading; using NUnit.Framework; using osu.Framework.Timing; diff --git a/osu.Framework.Tests/Clocks/TestClock.cs b/osu.Framework.Tests/Clocks/TestClock.cs index a91b4de8c..ac4bf7e38 100644 --- a/osu.Framework.Tests/Clocks/TestClock.cs +++ b/osu.Framework.Tests/Clocks/TestClock.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Timing; namespace osu.Framework.Tests.Clocks diff --git a/osu.Framework.Tests/Configuration/FrameworkConfigManagerTest.cs b/osu.Framework.Tests/Configuration/FrameworkConfigManagerTest.cs index 83bce11e7..52c7bbc0a 100644 --- a/osu.Framework.Tests/Configuration/FrameworkConfigManagerTest.cs +++ b/osu.Framework.Tests/Configuration/FrameworkConfigManagerTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using NUnit.Framework; @@ -15,7 +17,7 @@ namespace osu.Framework.Tests.Configuration [Test] public void TestDefault() { - using (var storage = new TemporaryNativeStorage(new Guid().ToString())) + using (var storage = new TemporaryNativeStorage(Guid.NewGuid().ToString())) { using (var configManager = new FrameworkConfigManager(storage)) { @@ -33,7 +35,7 @@ namespace osu.Framework.Tests.Configuration { const double test_volume = 0.65; - using (var storage = new TemporaryNativeStorage(new Guid().ToString())) + using (var storage = new TemporaryNativeStorage(Guid.NewGuid().ToString())) { using (var configManager = new FrameworkConfigManager(storage)) { @@ -61,7 +63,7 @@ namespace osu.Framework.Tests.Configuration { const string test_locale = "override test"; - using (var storage = new TemporaryNativeStorage(new Guid().ToString())) + using (var storage = new TemporaryNativeStorage(Guid.NewGuid().ToString())) { using (var configManager = new FrameworkConfigManager(storage, new Dictionary { { FrameworkSetting.Locale, test_locale } })) { diff --git a/osu.Framework.Tests/Configuration/InputConfigManagerTest.cs b/osu.Framework.Tests/Configuration/InputConfigManagerTest.cs index eed00dacc..34442f3d6 100644 --- a/osu.Framework.Tests/Configuration/InputConfigManagerTest.cs +++ b/osu.Framework.Tests/Configuration/InputConfigManagerTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; @@ -42,7 +44,7 @@ namespace osu.Framework.Tests.Configuration using (var host = new TestHeadlessGameHost()) { - host.Run(new TestGame((h, config) => sensitivity = h.AvailableInputHandlers.OfType().First().Sensitivity.Value)); + host.Run(new TestGame((h, _) => sensitivity = h.AvailableInputHandlers.OfType().First().Sensitivity.Value)); } Assert.AreEqual(5, sensitivity); @@ -53,7 +55,7 @@ namespace osu.Framework.Tests.Configuration { using (var host = new TestHeadlessGameHost(bypassCleanup: true)) { - host.Run(new TestGame((h, config) => + host.Run(new TestGame((h, _) => { storage = h.Storage; h.AvailableInputHandlers.OfType().First().Sensitivity.Value = 5; @@ -67,7 +69,7 @@ namespace osu.Framework.Tests.Configuration using (var host = new TestHeadlessGameHost()) { - host.Run(new TestGame((h, config) => sensitivity = h.AvailableInputHandlers.OfType().First().Sensitivity.Value)); + host.Run(new TestGame((h, _) => sensitivity = h.AvailableInputHandlers.OfType().First().Sensitivity.Value)); } Assert.AreEqual(5, sensitivity); diff --git a/osu.Framework.Tests/Containers/ContainerEnumerableTest.cs b/osu.Framework.Tests/Containers/ContainerEnumerableTest.cs index db4071e4c..13c5e5ce3 100644 --- a/osu.Framework.Tests/Containers/ContainerEnumerableTest.cs +++ b/osu.Framework.Tests/Containers/ContainerEnumerableTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using NUnit.Framework; diff --git a/osu.Framework.Tests/Containers/TestSceneCompositeMutability.cs b/osu.Framework.Tests/Containers/TestSceneCompositeMutability.cs index bc66b8eaf..9a5c93553 100644 --- a/osu.Framework.Tests/Containers/TestSceneCompositeMutability.cs +++ b/osu.Framework.Tests/Containers/TestSceneCompositeMutability.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Threading; using NUnit.Framework; @@ -167,12 +169,14 @@ namespace osu.Framework.Tests.Containers [BackgroundDependencyLoader] private void load() { - LoadingEvent.Wait(); + if (!LoadingEvent.Wait(10000)) + throw new TimeoutException("Load took too long"); OnLoading?.Invoke(); OnLoading = null; - ReadyEvent.Wait(); + if (!ReadyEvent.Wait(10000)) + throw new TimeoutException("Ready took too long"); } public override bool UpdateSubTree() diff --git a/osu.Framework.Tests/Containers/TestSceneContainerState.cs b/osu.Framework.Tests/Containers/TestSceneContainerState.cs index 89d72397a..0bd03824f 100644 --- a/osu.Framework.Tests/Containers/TestSceneContainerState.cs +++ b/osu.Framework.Tests/Containers/TestSceneContainerState.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Linq; using System.Threading; diff --git a/osu.Framework.Tests/Containers/TestSceneLoadComponentAsync.cs b/osu.Framework.Tests/Containers/TestSceneLoadComponentAsync.cs index 580588a89..b1c77b2a9 100644 --- a/osu.Framework.Tests/Containers/TestSceneLoadComponentAsync.cs +++ b/osu.Framework.Tests/Containers/TestSceneLoadComponentAsync.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework.Tests/Containers/TestSceneLongRunningLoad.cs b/osu.Framework.Tests/Containers/TestSceneLongRunningLoad.cs index b8989da7f..19fda8a05 100644 --- a/osu.Framework.Tests/Containers/TestSceneLongRunningLoad.cs +++ b/osu.Framework.Tests/Containers/TestSceneLongRunningLoad.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Threading; diff --git a/osu.Framework.Tests/Containers/TestSceneSyncDisposal.cs b/osu.Framework.Tests/Containers/TestSceneSyncDisposal.cs index 8082efb1b..5a3742b88 100644 --- a/osu.Framework.Tests/Containers/TestSceneSyncDisposal.cs +++ b/osu.Framework.Tests/Containers/TestSceneSyncDisposal.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework.Tests/Dependencies/CachedAttributeTest.cs b/osu.Framework.Tests/Dependencies/CachedAttributeTest.cs index 3491539b2..d70384e56 100644 --- a/osu.Framework.Tests/Dependencies/CachedAttributeTest.cs +++ b/osu.Framework.Tests/Dependencies/CachedAttributeTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using NUnit.Framework; using osu.Framework.Allocation; diff --git a/osu.Framework.Tests/Dependencies/CachedModelDependenciesTest.cs b/osu.Framework.Tests/Dependencies/CachedModelDependenciesTest.cs index c8e6c324d..30f8bf4ab 100644 --- a/osu.Framework.Tests/Dependencies/CachedModelDependenciesTest.cs +++ b/osu.Framework.Tests/Dependencies/CachedModelDependenciesTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using NUnit.Framework; using osu.Framework.Allocation; diff --git a/osu.Framework.Tests/Dependencies/DependencyContainerTest.cs b/osu.Framework.Tests/Dependencies/DependencyContainerTest.cs index 489778bf9..ff9396d68 100644 --- a/osu.Framework.Tests/Dependencies/DependencyContainerTest.cs +++ b/osu.Framework.Tests/Dependencies/DependencyContainerTest.cs @@ -1,7 +1,10 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; +using System.Diagnostics.CodeAnalysis; using System.Threading; using JetBrains.Annotations; using NUnit.Framework; @@ -318,6 +321,20 @@ namespace osu.Framework.Tests.Dependencies }); } + [Test] + public void TestResolveWithNullableReferenceTypes() + { + var dependencies = new DependencyContainer(); + var receiver = new Receiver14(); + + // Throws with missing non-nullable dependency. + Assert.Throws(() => dependencies.Inject(receiver)); + + // Cache the non-nullable dependency. + dependencies.CacheAs(new BaseObject()); + Assert.DoesNotThrow(() => dependencies.Inject(receiver)); + } + private interface IBaseInterface { } @@ -435,5 +452,16 @@ namespace osu.Framework.Tests.Dependencies [BackgroundDependencyLoader(true)] private void load(int testObject) => TestObject = testObject; } + +#nullable enable + [SuppressMessage("ReSharper", "UnusedParameter.Local")] + private class Receiver14 + { + [BackgroundDependencyLoader] + private void load(BaseObject nonNullObject, DerivedObject? nullableObject) + { + } + } +#nullable disable } } diff --git a/osu.Framework.Tests/Dependencies/ResolvedAttributeTest.cs b/osu.Framework.Tests/Dependencies/ResolvedAttributeTest.cs index d58a69c95..d5407b800 100644 --- a/osu.Framework.Tests/Dependencies/ResolvedAttributeTest.cs +++ b/osu.Framework.Tests/Dependencies/ResolvedAttributeTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Bindables; @@ -189,6 +191,25 @@ namespace osu.Framework.Tests.Dependencies Assert.AreEqual(bindable.Value, receiver.Obj2.Value); } + [Test] + public void TestResolveNullableWithNullableReferenceTypes() + { + var receiver = new Receiver17(); + Assert.DoesNotThrow(() => createDependencies().Inject(receiver)); + } + + [Test] + public void TestResolveNonNullWithNullableReferenceTypes() + { + var receiver = new Receiver18(); + + // Throws with non-nullable dependency not cached. + Assert.Throws(() => createDependencies().Inject(receiver)); + + // Does not throw with the non-nullable dependency cached. + Assert.DoesNotThrow(() => createDependencies(new Bindable(10)).Inject(receiver)); + } + private DependencyContainer createDependencies(params object[] toCache) { var dependencies = new DependencyContainer(); @@ -306,5 +327,19 @@ namespace osu.Framework.Tests.Dependencies [Resolved] public IBindable Obj2 { get; private set; } } + +#nullable enable + private class Receiver17 + { + [Resolved] + public Bindable? Obj { get; private set; } + } + + private class Receiver18 + { + [Resolved] + public Bindable Obj { get; private set; } = null!; + } +#nullable disable } } diff --git a/osu.Framework.Tests/Exceptions/TestAddRemoveExceptions.cs b/osu.Framework.Tests/Exceptions/TestAddRemoveExceptions.cs index 0313afb27..526d5f966 100644 --- a/osu.Framework.Tests/Exceptions/TestAddRemoveExceptions.cs +++ b/osu.Framework.Tests/Exceptions/TestAddRemoveExceptions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using NUnit.Framework; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Exceptions/TestLoadExceptions.cs b/osu.Framework.Tests/Exceptions/TestLoadExceptions.cs index 17f63e910..434d87f60 100644 --- a/osu.Framework.Tests/Exceptions/TestLoadExceptions.cs +++ b/osu.Framework.Tests/Exceptions/TestLoadExceptions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Diagnostics.CodeAnalysis; using System.Threading; @@ -8,9 +10,11 @@ using System.Threading.Tasks; using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Extensions; +using osu.Framework.Extensions.ExceptionExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; +using osu.Framework.Logging; using osu.Framework.Platform; using osu.Framework.Testing; using osuTK; @@ -47,6 +51,47 @@ namespace osu.Framework.Tests.Exceptions }); } + [Test] + public void TestUnobservedException() + { + Exception loggedException = null; + + Logger.NewEntry += newLogEntry; + + try + { + var exception = Assert.Throws(() => + { + Task.Factory.StartNew(() => + { + runGameWithLogic(g => + { + g.Scheduler.Add(() => Task.Run(() => throw new InvalidOperationException())); + g.Scheduler.AddDelayed(() => collect(), 1, true); + + if (loggedException != null) + throw loggedException; + }); + }, TaskCreationOptions.LongRunning).Wait(TimeSpan.FromSeconds(10)); + + Assert.Fail("Game execution was not aborted"); + }); + + Assert.True(exception?.AsSingular() is InvalidOperationException); + } + finally + { + Logger.NewEntry -= newLogEntry; + } + + void newLogEntry(LogEntry entry) => loggedException = entry.Exception; + } + + private static void collect() + { + GC.Collect(); + } + [Test] public void TestSingleAsyncAdd() { @@ -59,7 +104,7 @@ namespace osu.Framework.Tests.Exceptions { g.Add(loadTarget); loadTarget.PerformAsyncLoad(); - }, g => loadable.Parent == loadTarget); + }, _ => loadable.Parent == loadTarget); }); } @@ -76,7 +121,7 @@ namespace osu.Framework.Tests.Exceptions g.Add(loadTarget); loadTarget.PerformAsyncLoad(); loadTarget.PerformAsyncLoad(false); - }, g => loadable.Parent == loadTarget); + }, _ => loadable.Parent == loadTarget); }); } @@ -164,7 +209,7 @@ namespace osu.Framework.Tests.Exceptions runGameWithLogic(g => { g.Add(loadTarget); - loadTarget.PerformAsyncLoad().ContinueWith(t => allowDispose = true); + loadTarget.PerformAsyncLoad().ContinueWith(_ => allowDispose = true); }, g => { // The following code is done here for a very specific reason, but can occur naturally in normal use diff --git a/osu.Framework.Tests/Exceptions/TestSceneDependencyInjectionExceptions.cs b/osu.Framework.Tests/Exceptions/TestSceneDependencyInjectionExceptions.cs index 2c800b39e..e8646db91 100644 --- a/osu.Framework.Tests/Exceptions/TestSceneDependencyInjectionExceptions.cs +++ b/osu.Framework.Tests/Exceptions/TestSceneDependencyInjectionExceptions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Diagnostics; using NUnit.Framework; diff --git a/osu.Framework.Tests/Extensions/TestExtensions.cs b/osu.Framework.Tests/Extensions/TestExtensions.cs index 93eb3ed87..d26059310 100644 --- a/osu.Framework.Tests/Extensions/TestExtensions.cs +++ b/osu.Framework.Tests/Extensions/TestExtensions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Extensions; diff --git a/osu.Framework.Tests/Extensions/TestIsNullableTypeExtensions.cs b/osu.Framework.Tests/Extensions/TestIsNullableTypeExtensions.cs new file mode 100644 index 000000000..8c1fdd471 --- /dev/null +++ b/osu.Framework.Tests/Extensions/TestIsNullableTypeExtensions.cs @@ -0,0 +1,142 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Diagnostics.CodeAnalysis; +using System.Reflection; +using NUnit.Framework; +using osu.Framework.Extensions.TypeExtensions; + +#pragma warning disable CS8618 +#pragma warning disable CS0649 + +namespace osu.Framework.Tests.Extensions +{ + [TestFixture] + [SuppressMessage("ReSharper", "UnassignedGetOnlyAutoProperty")] + [SuppressMessage("ReSharper", "ValueParameterNotUsed")] + [SuppressMessage("ReSharper", "UnusedParameter.Local")] + public class TestIsNullableTypeExtensions + { + private const BindingFlags binding_flags = BindingFlags.Instance | BindingFlags.NonPublic; + + private int nonNullValueField; + private int? nullableValueField; + + private int nonNullValueGetSetProperty { get; set; } + private int? nullableValueGetSetProperty { get; set; } + + private int nonNullValueGetProperty { get; } + private int? nullableValueGetProperty { get; } + + private int nonNullValueSetProperty { set { } } + private int? nullableValueSetProperty { set { } } + + private object nonNullReferenceField; + private object? nullableReferenceField; + + private object nonNullReferenceGetSetProperty { get; set; } + private object? nullableReferenceGetSetProperty { get; set; } + + private object nonNullReferenceGetProperty { get; } + private object? nullableReferenceGetProperty { get; } + + private object nonNullReferenceSetProperty { set { } } + private object? nullableReferenceSetProperty { set { } } + +#nullable disable + private object nonNullReferenceFieldWithoutNullableReferenceTypes; +#nullable enable + + private event Action nonNullEvent; + private event Action? nullableEvent; + + private void testValueParamMethod(int param1, int? param2) { } + private void testReferenceParamMethod(object param1, object? param2) { } + + [Test] + public void TestNonNullValueField() => Assert.False(GetType().GetField(nameof(nonNullValueField), binding_flags).IsNullable()); + + [Test] + public void TestNullableValueField() => Assert.True(GetType().GetField(nameof(nullableValueField), binding_flags).IsNullable()); + + [Test] + public void TestNonNullValueGetSetProperty() => Assert.False(GetType().GetProperty(nameof(nonNullValueGetSetProperty), binding_flags).IsNullable()); + + [Test] + public void TestNullableValueGetSetProperty() => Assert.True(GetType().GetProperty(nameof(nullableValueGetSetProperty), binding_flags).IsNullable()); + + [Test] + public void TestNonNullValueGetProperty() => Assert.False(GetType().GetProperty(nameof(nonNullValueGetProperty), binding_flags).IsNullable()); + + [Test] + public void TestNullableValueGetProperty() => Assert.True(GetType().GetProperty(nameof(nullableValueGetProperty), binding_flags).IsNullable()); + + [Test] + public void TestNonNullValueSetProperty() => Assert.False(GetType().GetProperty(nameof(nonNullValueSetProperty), binding_flags).IsNullable()); + + [Test] + public void TestNullableValueSetProperty() => Assert.True(GetType().GetProperty(nameof(nullableValueSetProperty), binding_flags).IsNullable()); + + [Test] + public void TestNonNullReferenceField() => Assert.False(GetType().GetField(nameof(nonNullReferenceField), binding_flags).IsNullable()); + + [Test] + public void TestNullableReferenceField() => Assert.True(GetType().GetField(nameof(nullableReferenceField), binding_flags).IsNullable()); + + [Test] + public void TestNonNullReferenceGetSetProperty() => Assert.False(GetType().GetProperty(nameof(nonNullReferenceGetSetProperty), binding_flags).IsNullable()); + + [Test] + public void TestNullableReferenceGetSetProperty() => Assert.True(GetType().GetProperty(nameof(nullableReferenceGetSetProperty), binding_flags).IsNullable()); + + [Test] + public void TestNonNullReferenceGetProperty() => Assert.False(GetType().GetProperty(nameof(nonNullReferenceGetProperty), binding_flags).IsNullable()); + + [Test] + public void TestNullableReferenceGetProperty() => Assert.True(GetType().GetProperty(nameof(nullableReferenceGetProperty), binding_flags).IsNullable()); + + [Test] + public void TestNonNullReferenceSetProperty() => Assert.False(GetType().GetProperty(nameof(nonNullReferenceSetProperty), binding_flags).IsNullable()); + + [Test] + public void TestNullableReferenceSetProperty() => Assert.True(GetType().GetProperty(nameof(nullableReferenceSetProperty), binding_flags).IsNullable()); + + [Test] + public void TestNonNullReferenceFieldWithoutNullableReferenceTypes() + => Assert.False(GetType().GetField(nameof(nonNullReferenceFieldWithoutNullableReferenceTypes), binding_flags).IsNullable()); + + [Test] + public void TestNonNullEvent() => Assert.False(GetType().GetEvent(nameof(nonNullEvent), binding_flags).IsNullable()); + + [Test] + public void TestNullableEvent() => Assert.True(GetType().GetEvent(nameof(nullableEvent), binding_flags).IsNullable()); + + [Test] + public void TestValueParameters() + { + var parameters = GetType().GetMethod(nameof(testValueParamMethod), binding_flags)!.GetParameters(); + Assert.False(parameters[0].IsNullable()); + Assert.True(parameters[1].IsNullable()); + } + + [Test] + public void TestReferenceParameters() + { + var parameters = GetType().GetMethod(nameof(testReferenceParamMethod), binding_flags)!.GetParameters(); + Assert.False(parameters[0].IsNullable()); + Assert.True(parameters[1].IsNullable()); + } + + [Test] + public void TestNonNullValueType() => Assert.False(typeof(int).IsNullable()); + + [Test] + public void TestNullableValueType() => Assert.True(typeof(int?).IsNullable()); + + [Test] + public void TestNonNullReferenceType() => Assert.False(typeof(object).IsNullable()); + + // typeof cannot be used on "object?". + } +} diff --git a/osu.Framework.Tests/Extensions/TestStreamExtensions.cs b/osu.Framework.Tests/Extensions/TestStreamExtensions.cs index 8f713c254..d7b3aa189 100644 --- a/osu.Framework.Tests/Extensions/TestStreamExtensions.cs +++ b/osu.Framework.Tests/Extensions/TestStreamExtensions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.IO; using System.Linq; using System.Threading.Tasks; diff --git a/osu.Framework.Tests/Graphics/ColourTest.cs b/osu.Framework.Tests/Graphics/ColourTest.cs index d5ae5539e..a061871b5 100644 --- a/osu.Framework.Tests/Graphics/ColourTest.cs +++ b/osu.Framework.Tests/Graphics/ColourTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Numerics; using NUnit.Framework; diff --git a/osu.Framework.Tests/Graphics/LifetimeEntryManagerTest.cs b/osu.Framework.Tests/Graphics/LifetimeEntryManagerTest.cs index 51caeebf9..2e7a3e4ca 100644 --- a/osu.Framework.Tests/Graphics/LifetimeEntryManagerTest.cs +++ b/osu.Framework.Tests/Graphics/LifetimeEntryManagerTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; @@ -207,7 +209,7 @@ namespace osu.Framework.Tests.Graphics addEntry(); - manager.EntryCrossedBoundary += (entry, kind, direction) => changeLifetime(); + manager.EntryCrossedBoundary += (_, _, _) => changeLifetime(); manager.Update(0); int count = 1; diff --git a/osu.Framework.Tests/Graphics/ShaderRegexTest.cs b/osu.Framework.Tests/Graphics/ShaderRegexTest.cs index 20b28ed37..7bf9a84f1 100644 --- a/osu.Framework.Tests/Graphics/ShaderRegexTest.cs +++ b/osu.Framework.Tests/Graphics/ShaderRegexTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Text.RegularExpressions; using NUnit.Framework; using osu.Framework.Graphics.Shaders; diff --git a/osu.Framework.Tests/Graphics/TestSceneDrawableScheduling.cs b/osu.Framework.Tests/Graphics/TestSceneDrawableScheduling.cs index cb2fb7275..10da54b86 100644 --- a/osu.Framework.Tests/Graphics/TestSceneDrawableScheduling.cs +++ b/osu.Framework.Tests/Graphics/TestSceneDrawableScheduling.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using NUnit.Framework; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Graphics/TextureAtlasTest.cs b/osu.Framework.Tests/Graphics/TextureAtlasTest.cs index 7f63e9208..bf4e1ea76 100644 --- a/osu.Framework.Tests/Graphics/TextureAtlasTest.cs +++ b/osu.Framework.Tests/Graphics/TextureAtlasTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Graphics.OpenGL.Textures; using osu.Framework.Graphics.Primitives; diff --git a/osu.Framework.Tests/Graphics/TripleBufferTest.cs b/osu.Framework.Tests/Graphics/TripleBufferTest.cs new file mode 100644 index 000000000..705bbf0d4 --- /dev/null +++ b/osu.Framework.Tests/Graphics/TripleBufferTest.cs @@ -0,0 +1,102 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Threading; +using System.Threading.Tasks; +using NUnit.Framework; +using osu.Framework.Allocation; +using osu.Framework.Extensions; + +namespace osu.Framework.Tests.Graphics +{ + [TestFixture] + public class TripleBufferTest + { + [Test] + public void TestWriteOnly() + { + var tripleBuffer = new TripleBuffer(); + + for (int i = 0; i < 1000; i++) + { + using (tripleBuffer.GetForWrite()) + { + } + } + } + + [Test] + public void TestReadOnly() + { + var tripleBuffer = new TripleBuffer(); + + using (var buffer = tripleBuffer.GetForRead()) + Assert.That(buffer, Is.Null); + } + + [Test] + public void TestWriteThenRead() + { + var tripleBuffer = new TripleBuffer(); + + for (int i = 0; i < 1000; i++) + { + var obj = new TestObject(i); + + using (var buffer = tripleBuffer.GetForWrite()) + buffer.Object = obj; + + using (var buffer = tripleBuffer.GetForRead()) + Assert.That(buffer?.Object, Is.EqualTo(obj)); + } + + using (var buffer = tripleBuffer.GetForRead()) + Assert.That(buffer, Is.Null); + } + + [Test] + public void TestReadSaturated() + { + var tripleBuffer = new TripleBuffer(); + + for (int i = 0; i < 10; i++) + { + var obj = new TestObject(i); + ManualResetEventSlim resetEventSlim = new ManualResetEventSlim(); + + var readTask = Task.Factory.StartNew(() => + { + resetEventSlim.Set(); + using (var buffer = tripleBuffer.GetForRead()) + Assert.That(buffer?.Object, Is.EqualTo(obj)); + }, TaskCreationOptions.LongRunning); + + Task.Factory.StartNew(() => + { + resetEventSlim.Wait(1000); + Thread.Sleep(10); + + using (var buffer = tripleBuffer.GetForWrite()) + buffer.Object = obj; + }, TaskCreationOptions.LongRunning); + + readTask.WaitSafely(); + } + } + + private class TestObject + { + private readonly int i; + + public TestObject(int i) + { + this.i = i; + } + + public override string ToString() + { + return $"{base.ToString()} {i}"; + } + } + } +} diff --git a/osu.Framework.Tests/IO/BackgroundGameHeadlessGameHost.cs b/osu.Framework.Tests/IO/BackgroundGameHeadlessGameHost.cs index c923180b1..6f7b14c27 100644 --- a/osu.Framework.Tests/IO/BackgroundGameHeadlessGameHost.cs +++ b/osu.Framework.Tests/IO/BackgroundGameHeadlessGameHost.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Threading; using System.Threading.Tasks; @@ -31,7 +33,8 @@ namespace osu.Framework.Tests.IO Task.Factory.StartNew(() => Run(testGame), TaskCreationOptions.LongRunning); - testGame.HasProcessed.Wait(); + if (!testGame.HasProcessed.Wait(10000)) + throw new TimeoutException("Game took too long to process a frame"); } private class TestGame : Game diff --git a/osu.Framework.Tests/IO/FontStoreTest.cs b/osu.Framework.Tests/IO/FontStoreTest.cs index 54674d28a..cab61144f 100644 --- a/osu.Framework.Tests/IO/FontStoreTest.cs +++ b/osu.Framework.Tests/IO/FontStoreTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.IO.Stores; diff --git a/osu.Framework.Tests/IO/TestDesktopStorage.cs b/osu.Framework.Tests/IO/TestDesktopStorage.cs index a067d40ca..195236b1d 100644 --- a/osu.Framework.Tests/IO/TestDesktopStorage.cs +++ b/osu.Framework.Tests/IO/TestDesktopStorage.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.IO; using NUnit.Framework; @@ -14,7 +16,7 @@ namespace osu.Framework.Tests.IO [Test] public void TestRelativePaths() { - string guid = new Guid().ToString(); + string guid = Guid.NewGuid().ToString(); using (var storage = new TemporaryNativeStorage(guid)) { @@ -34,11 +36,15 @@ namespace osu.Framework.Tests.IO [Test] public void TestAttemptEscapeRoot() { - string guid = new Guid().ToString(); + string guid = Guid.NewGuid().ToString(); using (var storage = new TemporaryNativeStorage(guid)) { - Assert.Throws(() => storage.GetStream("../test")); + Assert.Throws(() => + { + using var x = storage.GetStream("../test"); + }); + Assert.Throws(() => storage.GetStorageForDirectory("../")); } } @@ -46,7 +52,7 @@ namespace osu.Framework.Tests.IO [Test] public void TestGetSubDirectoryStorage() { - string guid = new Guid().ToString(); + string guid = Guid.NewGuid().ToString(); using (var storage = new TemporaryNativeStorage(guid)) { @@ -57,7 +63,7 @@ namespace osu.Framework.Tests.IO [Test] public void TestGetEmptySubDirectoryStorage() { - string guid = new Guid().ToString(); + string guid = Guid.NewGuid().ToString(); using (var storage = new TemporaryNativeStorage(guid)) { diff --git a/osu.Framework.Tests/IO/TestLogging.cs b/osu.Framework.Tests/IO/TestLogging.cs index 02358bce0..2759ecd32 100644 --- a/osu.Framework.Tests/IO/TestLogging.cs +++ b/osu.Framework.Tests/IO/TestLogging.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Threading; using System.Threading.Tasks; @@ -98,7 +100,7 @@ namespace osu.Framework.Tests.IO { using (var host = new TestRunHeadlessGameHost()) { - host.ExceptionThrown += ex => ignoreCount-- > 0; + host.ExceptionThrown += _ => ignoreCount-- > 0; var game = new TestGame(); @@ -129,32 +131,6 @@ namespace osu.Framework.Tests.IO } } - [Test] - public void TestGameUnobservedExceptionDoesntCrashGame() - { - using (var host = new TestRunHeadlessGameHost()) - { - TaskCrashTestGame game = new TaskCrashTestGame(); - host.Run(game); - } - } - - private class TaskCrashTestGame : Game - { - private int frameCount; - - protected override void Update() - { - base.Update(); - - Task.Run(() => throw new TestException()); - - // only start counting frames once the task has completed, to allow some time for the unobserved exception to be handled. - if (frameCount++ > 10) - Exit(); - } - } - [Test] public void TestTaskExceptionLogging() { @@ -162,7 +138,7 @@ namespace osu.Framework.Tests.IO void logTest(LogEntry entry) { - if (entry.Exception is AggregateException ex) + if (entry.Exception is TestException ex) { Assert.IsNull(resolvedException, "exception was forwarded more than once"); resolvedException = ex; @@ -177,8 +153,7 @@ namespace osu.Framework.Tests.IO // needs to be in a separate method so the Task gets GC'd. performTaskException(); - GC.Collect(); - GC.WaitForPendingFinalizers(); + collectAndFireUnobserved(); } Assert.IsNotNull(resolvedException, "exception wasn't forwarded by logger"); @@ -237,5 +212,21 @@ namespace osu.Framework.Tests.IO private class TestInnerException : Exception { } + + [TearDown] + public void TearDown() + { + // Safety against any unobserved exceptions being left in the pipe. + collectAndFireUnobserved(); + } + + /// + /// Forcefully collect so the unobserved exception isn't handled by a future test execution. + /// + private static void collectAndFireUnobserved() + { + GC.Collect(); + GC.WaitForPendingFinalizers(); + } } } diff --git a/osu.Framework.Tests/IO/TestSortedListSerialization.cs b/osu.Framework.Tests/IO/TestSortedListSerialization.cs index c8585caca..98d5f8941 100644 --- a/osu.Framework.Tests/IO/TestSortedListSerialization.cs +++ b/osu.Framework.Tests/IO/TestSortedListSerialization.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using Newtonsoft.Json; using NUnit.Framework; using osu.Framework.Lists; diff --git a/osu.Framework.Tests/IO/TestWebRequest.cs b/osu.Framework.Tests/IO/TestWebRequest.cs index 917ba8966..417ab837c 100644 --- a/osu.Framework.Tests/IO/TestWebRequest.cs +++ b/osu.Framework.Tests/IO/TestWebRequest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Diagnostics; @@ -295,9 +297,7 @@ namespace osu.Framework.Tests.IO bool hasThrown = false; request.Failed += exception => hasThrown = exception != null; -#pragma warning disable 4014 - request.PerformAsync(); -#pragma warning restore 4014 + Task.Run(() => request.PerformAsync()); Assert.DoesNotThrow(request.Abort); @@ -310,7 +310,38 @@ namespace osu.Framework.Tests.IO } /// - /// Tests being able to abort + restart a request. + /// Tests not being able to perform a request after an abort (before any perform). + /// + [Test, Retry(5)] + public void TestStartAfterAbort([Values(true, false)] bool async) + { + var request = new JsonWebRequest($"{default_protocol}://{host}/get") + { + Method = HttpMethod.Get, + AllowInsecureRequests = true, + }; + + bool hasThrown = false; + request.Failed += exception => hasThrown = exception != null; + + Assert.DoesNotThrow(request.Abort); + + if (async) + Assert.ThrowsAsync(() => request.PerformAsync()); + else + Assert.Throws(request.Perform); + + Assert.IsTrue(request.Completed); + Assert.IsTrue(request.Aborted); + + var responseObject = request.ResponseObject; + + Assert.IsTrue(responseObject == null); + Assert.IsFalse(hasThrown); + } + + /// + /// Tests not being able to perform a request after an initial perform-abort sequence. /// [Test, Retry(5)] public void TestRestartAfterAbort([Values(true, false)] bool async) @@ -324,16 +355,14 @@ namespace osu.Framework.Tests.IO bool hasThrown = false; request.Failed += exception => hasThrown = exception != null; -#pragma warning disable 4014 - request.PerformAsync(); -#pragma warning restore 4014 + Task.Run(() => request.PerformAsync()); Assert.DoesNotThrow(request.Abort); if (async) - Assert.ThrowsAsync(() => request.PerformAsync()); + Assert.ThrowsAsync(() => request.PerformAsync()); else - Assert.Throws(request.Perform); + Assert.Throws(request.Perform); Assert.IsTrue(request.Completed); Assert.IsTrue(request.Aborted); @@ -402,7 +431,7 @@ namespace osu.Framework.Tests.IO /// Tests being able to cancel + restart a request. /// [Test, Retry(5)] - public void TestRestartAfterAbort() + public void TestRestartAfterAbortViaCancellationToken() { var cancellationSource = new CancellationTokenSource(); var request = new JsonWebRequest($"{default_protocol}://{host}/get") @@ -417,7 +446,7 @@ namespace osu.Framework.Tests.IO cancellationSource.Cancel(); request.PerformAsync(cancellationSource.Token).WaitSafely(); - Assert.ThrowsAsync(() => request.PerformAsync(cancellationSource.Token)); + Assert.ThrowsAsync(() => request.PerformAsync(cancellationSource.Token)); Assert.IsTrue(request.Completed); Assert.IsTrue(request.Aborted); @@ -494,9 +523,9 @@ namespace osu.Framework.Tests.IO }; request.Started += () => { }; - request.Failed += e => { }; - request.DownloadProgress += (l1, l2) => { }; - request.UploadProgress += (l1, l2) => { }; + request.Failed += _ => { }; + request.DownloadProgress += (_, _) => { }; + request.UploadProgress += (_, _) => { }; Assert.DoesNotThrow(request.Perform); @@ -524,9 +553,9 @@ namespace osu.Framework.Tests.IO using (request) { request.Started += () => { }; - request.Failed += e => { }; - request.DownloadProgress += (l1, l2) => { }; - request.UploadProgress += (l1, l2) => { }; + request.Failed += _ => { }; + request.DownloadProgress += (_, _) => { }; + request.UploadProgress += (_, _) => { }; Assert.DoesNotThrow(request.Perform); } diff --git a/osu.Framework.Tests/IO/TextureStoreTest.cs b/osu.Framework.Tests/IO/TextureStoreTest.cs new file mode 100644 index 000000000..780d6859a --- /dev/null +++ b/osu.Framework.Tests/IO/TextureStoreTest.cs @@ -0,0 +1,73 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Linq; +using NUnit.Framework; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Textures; +using osu.Framework.IO.Stores; + +namespace osu.Framework.Tests.IO +{ + [TestFixture] + public class TextureStoreTest + { + private TextureLoaderStore fontResourceStore = null!; + + [OneTimeSetUp] + public void OneTimeSetUp() + { + fontResourceStore = new TextureLoaderStore(new NamespacedResourceStore(new DllResourceStore(typeof(Drawable).Assembly), "Resources/Fonts")); + } + + [Test] + public void TestLookupStores() + { + using (var lookupStore1 = new NamespacedResourceStore(fontResourceStore, "Roboto")) + using (var lookupStore2 = new NamespacedResourceStore(fontResourceStore, "RobotoCondensed")) + using (var textureStore = new TextureStore(scaleAdjust: 100)) + { + textureStore.AddTextureSource(lookupStore1); + textureStore.AddTextureSource(lookupStore2); + + Assert.That(textureStore.GetAvailableResources().Contains("Roboto-Regular_0.png")); + Assert.That(textureStore.GetStream("Roboto-Regular_0"), Is.Not.Null); + + var normalSheet = textureStore.Get("Roboto-Regular_0"); + Assert.That(normalSheet, Is.Not.Null); + Assert.That(normalSheet.ScaleAdjust, Is.EqualTo(100)); + + Assert.That(textureStore.GetAvailableResources().Contains("RobotoCondensed-Regular_0.png")); + Assert.That(textureStore.GetStream("RobotoCondensed-Regular_0"), Is.Not.Null); + + var condensedSheet = textureStore.Get("RobotoCondensed-Regular_0"); + Assert.That(condensedSheet, Is.Not.Null); + Assert.That(condensedSheet.ScaleAdjust, Is.EqualTo(100)); + } + } + + [Test] + public void TestNestedTextureStores() + { + using (var textureStore = new TextureStore(new NamespacedResourceStore(fontResourceStore, "Roboto"), scaleAdjust: 100)) + using (var nestedTextureStore = new TextureStore(new NamespacedResourceStore(fontResourceStore, "RobotoCondensed"), scaleAdjust: 200)) + { + textureStore.AddStore(nestedTextureStore); + + Assert.That(textureStore.GetAvailableResources().Contains("Roboto-Regular_0.png")); + Assert.That(textureStore.GetStream("Roboto-Regular_0"), Is.Not.Null); + + var normalSheet = textureStore.Get("Roboto-Regular_0"); + Assert.That(normalSheet, Is.Not.Null); + Assert.That(normalSheet.ScaleAdjust, Is.EqualTo(100)); + + Assert.That(textureStore.GetAvailableResources().Contains("RobotoCondensed-Regular_0.png")); + Assert.That(textureStore.GetStream("RobotoCondensed-Regular_0"), Is.Not.Null); + + var condensedSheet = textureStore.Get("RobotoCondensed-Regular_0"); + Assert.That(condensedSheet, Is.Not.Null); + Assert.That(condensedSheet.ScaleAdjust, Is.EqualTo(200)); + } + } + } +} diff --git a/osu.Framework.Tests/Input/JoystickInputTest.cs b/osu.Framework.Tests/Input/JoystickInputTest.cs index 30cc8d41a..520b2113e 100644 --- a/osu.Framework.Tests/Input/JoystickInputTest.cs +++ b/osu.Framework.Tests/Input/JoystickInputTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using NUnit.Framework; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Input/KeyBindingInputTest.cs b/osu.Framework.Tests/Input/KeyBindingInputTest.cs index 19dd49fe0..f211cb916 100644 --- a/osu.Framework.Tests/Input/KeyBindingInputTest.cs +++ b/osu.Framework.Tests/Input/KeyBindingInputTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using NUnit.Framework; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Input/KeyCombinationModifierTest.cs b/osu.Framework.Tests/Input/KeyCombinationModifierTest.cs index b74e09260..6ae0e5e31 100644 --- a/osu.Framework.Tests/Input/KeyCombinationModifierTest.cs +++ b/osu.Framework.Tests/Input/KeyCombinationModifierTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Input.Bindings; diff --git a/osu.Framework.Tests/Input/KeyboardInputTest.cs b/osu.Framework.Tests/Input/KeyboardInputTest.cs index 00d3987f4..fbe9a3b45 100644 --- a/osu.Framework.Tests/Input/KeyboardInputTest.cs +++ b/osu.Framework.Tests/Input/KeyboardInputTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using NUnit.Framework; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Input/MouseInputTest.cs b/osu.Framework.Tests/Input/MouseInputTest.cs index b97ae8b3c..bbfedceb3 100644 --- a/osu.Framework.Tests/Input/MouseInputTest.cs +++ b/osu.Framework.Tests/Input/MouseInputTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using NUnit.Framework; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Input/ReadableKeyCombinationTest.cs b/osu.Framework.Tests/Input/ReadableKeyCombinationTest.cs index 01d9eb8dd..a273b074d 100644 --- a/osu.Framework.Tests/Input/ReadableKeyCombinationTest.cs +++ b/osu.Framework.Tests/Input/ReadableKeyCombinationTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Input; using osu.Framework.Input.Bindings; diff --git a/osu.Framework.Tests/Layout/TestSceneContainerLayout.cs b/osu.Framework.Tests/Layout/TestSceneContainerLayout.cs index 376998632..3c4b661b5 100644 --- a/osu.Framework.Tests/Layout/TestSceneContainerLayout.cs +++ b/osu.Framework.Tests/Layout/TestSceneContainerLayout.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using NUnit.Framework; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Layout/TestSceneDrawableLayout.cs b/osu.Framework.Tests/Layout/TestSceneDrawableLayout.cs index 8f324b325..0a730d87b 100644 --- a/osu.Framework.Tests/Layout/TestSceneDrawableLayout.cs +++ b/osu.Framework.Tests/Layout/TestSceneDrawableLayout.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework.Tests/Layout/TestSceneGridContainerLayout.cs b/osu.Framework.Tests/Layout/TestSceneGridContainerLayout.cs index c073d24af..550b6dcd4 100644 --- a/osu.Framework.Tests/Layout/TestSceneGridContainerLayout.cs +++ b/osu.Framework.Tests/Layout/TestSceneGridContainerLayout.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework.Tests/Layout/TestSceneSpriteLayout.cs b/osu.Framework.Tests/Layout/TestSceneSpriteLayout.cs index 08fbbd69d..99b9fb194 100644 --- a/osu.Framework.Tests/Layout/TestSceneSpriteLayout.cs +++ b/osu.Framework.Tests/Layout/TestSceneSpriteLayout.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework.Tests/Lists/TestArrayExtensions.cs b/osu.Framework.Tests/Lists/TestArrayExtensions.cs index 576f3d692..b894ca294 100644 --- a/osu.Framework.Tests/Lists/TestArrayExtensions.cs +++ b/osu.Framework.Tests/Lists/TestArrayExtensions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Linq; using NUnit.Framework; diff --git a/osu.Framework.Tests/Lists/TestEnumerableExtensions.cs b/osu.Framework.Tests/Lists/TestEnumerableExtensions.cs index 83b0b437e..4bd2ce0c6 100644 --- a/osu.Framework.Tests/Lists/TestEnumerableExtensions.cs +++ b/osu.Framework.Tests/Lists/TestEnumerableExtensions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Linq; using NUnit.Framework; using osu.Framework.Extensions.IEnumerableExtensions; diff --git a/osu.Framework.Tests/Lists/TestSortedList.cs b/osu.Framework.Tests/Lists/TestSortedList.cs index b19f4bc3d..6ca89e31f 100644 --- a/osu.Framework.Tests/Lists/TestSortedList.cs +++ b/osu.Framework.Tests/Lists/TestSortedList.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using osu.Framework.Lists; diff --git a/osu.Framework.Tests/Lists/TestWeakList.cs b/osu.Framework.Tests/Lists/TestWeakList.cs index 08e491804..4777dee7a 100644 --- a/osu.Framework.Tests/Lists/TestWeakList.cs +++ b/osu.Framework.Tests/Lists/TestWeakList.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework.Tests/Localisation/LocalisableDescriptionAttributeTest.cs b/osu.Framework.Tests/Localisation/LocalisableDescriptionAttributeTest.cs index 676dadab5..495a079c9 100644 --- a/osu.Framework.Tests/Localisation/LocalisableDescriptionAttributeTest.cs +++ b/osu.Framework.Tests/Localisation/LocalisableDescriptionAttributeTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using NUnit.Framework; using osu.Framework.Extensions; @@ -49,6 +51,13 @@ namespace osu.Framework.Tests.Localisation Assert.Throws(() => EnumD.Item1.GetLocalisableDescription()); } + [Test] + public void TestLocalisableStringDescription() + { + object description = TestStrings.Romanisable; + Assert.AreEqual(description, description.GetLocalisableDescription()); + } + public enum EnumA { Item1, @@ -63,7 +72,7 @@ namespace osu.Framework.Tests.Localisation Item1, [LocalisableDescription(typeof(TestStrings), nameof(TestStrings.B))] - Item2 + Item2, } public enum EnumC @@ -89,6 +98,8 @@ namespace osu.Framework.Tests.Localisation public static readonly LocalisableString B = "Localised B"; + public static LocalisableString Romanisable => new RomanisableString("Original", "Romanised"); + public LocalisableString Instance => string.Empty; } } diff --git a/osu.Framework.Tests/Localisation/LocalisableStringTest.cs b/osu.Framework.Tests/Localisation/LocalisableStringTest.cs index f49c3e739..3ebf89e7c 100644 --- a/osu.Framework.Tests/Localisation/LocalisableStringTest.cs +++ b/osu.Framework.Tests/Localisation/LocalisableStringTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using NUnit.Framework; using osu.Framework.Localisation; diff --git a/osu.Framework.Tests/Localisation/LocalisationTest.cs b/osu.Framework.Tests/Localisation/LocalisationTest.cs index 3ba5d094c..f689e926e 100644 --- a/osu.Framework.Tests/Localisation/LocalisationTest.cs +++ b/osu.Framework.Tests/Localisation/LocalisationTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Globalization; @@ -56,6 +58,32 @@ namespace osu.Framework.Tests.Localisation Assert.AreEqual(FakeStorage.LOCALISABLE_STRING_JA_JP, localisedText.Value); } + [Test] + public void TestConfigSettingRetainedWhenAddingLocaleMappings() + { + config.SetValue(FrameworkSetting.Locale, "ja-JP"); + + // ensure that adding a new language which doesn't match the user's choice doesn't cause the configuration value to get reset. + manager.AddLocaleMappings(new[] + { + new LocaleMapping("po", new FakeStorage("po-OP")), + new LocaleMapping("wa", new FakeStorage("wa-NG")) + }); + + Assert.AreEqual("ja-JP", config.Get(FrameworkSetting.Locale)); + + var localisedText = manager.GetLocalisedBindableString(new TranslatableString(FakeStorage.LOCALISABLE_STRING_EN, FakeStorage.LOCALISABLE_STRING_EN)); + Assert.AreEqual(FakeStorage.LOCALISABLE_STRING_EN, localisedText.Value); + + // ensure that if the user's selection is added in a further AddLanguage call, the manager correctly translates strings. + manager.AddLocaleMappings(new[] + { + new LocaleMapping("ja-JP", new FakeStorage("ja-JP")) + }); + + Assert.AreEqual(FakeStorage.LOCALISABLE_STRING_JA_JP, localisedText.Value); + } + [Test] public void TestNotLocalised() { @@ -120,7 +148,8 @@ namespace osu.Framework.Tests.Localisation string expectedResult = string.Format(FakeStorage.LOCALISABLE_FORMAT_STRING_JA, arg_0); - var formattedText = manager.GetLocalisedBindableString(new TranslatableString(FakeStorage.LOCALISABLE_FORMAT_STRING_EN, interpolation: $"The {arg_0} fallback should only matches argument count")); + var formattedText = manager.GetLocalisedBindableString(new TranslatableString(FakeStorage.LOCALISABLE_FORMAT_STRING_EN, + interpolation: $"The {arg_0} fallback should only matches argument count")); Assert.AreEqual(expectedResult, formattedText.Value); } diff --git a/osu.Framework.Tests/Localisation/ThreadCultureTest.cs b/osu.Framework.Tests/Localisation/ThreadCultureTest.cs index 0ba342532..5a663f876 100644 --- a/osu.Framework.Tests/Localisation/ThreadCultureTest.cs +++ b/osu.Framework.Tests/Localisation/ThreadCultureTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Concurrent; using System.Globalization; using System.Linq; diff --git a/osu.Framework.Tests/MathUtils/TestInterpolation.cs b/osu.Framework.Tests/MathUtils/TestInterpolation.cs index 054f1caaa..6f427293e 100644 --- a/osu.Framework.Tests/MathUtils/TestInterpolation.cs +++ b/osu.Framework.Tests/MathUtils/TestInterpolation.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework.Tests/MathUtils/TestPathApproximator.cs b/osu.Framework.Tests/MathUtils/TestPathApproximator.cs index 2a58c2edb..b421d9dfc 100644 --- a/osu.Framework.Tests/MathUtils/TestPathApproximator.cs +++ b/osu.Framework.Tests/MathUtils/TestPathApproximator.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using NUnit.Framework; using osu.Framework.Utils; diff --git a/osu.Framework.Tests/Platform/ComponentAsyncDisposalTest.cs b/osu.Framework.Tests/Platform/ComponentAsyncDisposalTest.cs index 30cd87374..7d654c628 100644 --- a/osu.Framework.Tests/Platform/ComponentAsyncDisposalTest.cs +++ b/osu.Framework.Tests/Platform/ComponentAsyncDisposalTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Threading; using System.Threading.Tasks; using NUnit.Framework; diff --git a/osu.Framework.Tests/Platform/GameExitTest.cs b/osu.Framework.Tests/Platform/GameExitTest.cs index ce538fcaf..62ec625a8 100644 --- a/osu.Framework.Tests/Platform/GameExitTest.cs +++ b/osu.Framework.Tests/Platform/GameExitTest.cs @@ -1,10 +1,11 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Threading; using System.Threading.Tasks; using NUnit.Framework; -using osu.Framework.Extensions; using osu.Framework.Platform; using osu.Framework.Testing; @@ -40,9 +41,7 @@ namespace osu.Framework.Tests.Platform // block game from exiting. game.BlockExit.Value = true; - // `RequestExit()` should return true. - Assert.That(host.RequestExit(), Is.True); - // game's last exit result should match. + requestExit(); Assert.That(game.LastExitResult, Is.True); // exit should be blocked. @@ -51,9 +50,7 @@ namespace osu.Framework.Tests.Platform // unblock game from exiting. game.BlockExit.Value = false; - // `RequestExit()` should not be blocked and return false. - Assert.That(host.RequestExit(), Is.False); - // game's last exit result should match. + requestExit(); Assert.That(game.LastExitResult, Is.False); // finally, the game should exit. @@ -61,23 +58,24 @@ namespace osu.Framework.Tests.Platform Assert.That(host.ExecutionState, Is.EqualTo(ExecutionState.Stopped)); } + private void requestExit() + { + host.RequestExit(); + + // wait for the event to be handled by the game (on the update thread) + Assert.That(game.ExitRequested.Wait(timeout), Is.True); + game.ExitRequested.Reset(); + } + private class ManualExitHeadlessGameHost : TestRunHeadlessGameHost { - public bool RequestExit() - { - // The exit request has to come from the thread that is also running the game host - // to avoid corrupting the host's internal state. - // Therefore, use a task completion source as an intermediary that can be used - // to request the exit on the correct thread and wait for the result of the exit operation. - var exitRequestTask = new TaskCompletionSource(); - InputThread.Scheduler.Add(() => exitRequestTask.SetResult(OnExitRequested())); - return exitRequestTask.Task.GetResultSafely(); - } + public void RequestExit() => OnExitRequested(); } private class TestTestGame : TestGame { public readonly ManualResetEventSlim BecameAlive = new ManualResetEventSlim(); + public readonly ManualResetEventSlim ExitRequested = new ManualResetEventSlim(); public bool? LastExitResult { get; private set; } @@ -90,6 +88,7 @@ namespace osu.Framework.Tests.Platform { bool result = base.OnExiting(); LastExitResult = result; + ExitRequested.Set(); return result; } } diff --git a/osu.Framework.Tests/Platform/GameHostSuspendTest.cs b/osu.Framework.Tests/Platform/GameHostSuspendTest.cs index 3304ea624..f537d3240 100644 --- a/osu.Framework.Tests/Platform/GameHostSuspendTest.cs +++ b/osu.Framework.Tests/Platform/GameHostSuspendTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; diff --git a/osu.Framework.Tests/Platform/HeadlessGameHostTest.cs b/osu.Framework.Tests/Platform/HeadlessGameHostTest.cs index 5a31b7f1c..ab8ca8ed6 100644 --- a/osu.Framework.Tests/Platform/HeadlessGameHostTest.cs +++ b/osu.Framework.Tests/Platform/HeadlessGameHostTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Diagnostics.CodeAnalysis; using System.Threading; @@ -110,7 +112,8 @@ namespace osu.Framework.Tests.Platform await clientChannel.SendMessageAsync(new Foobar { Bar = "example" }).ConfigureAwait(false); - received.Wait(); + if (!received.Wait(10000)) + throw new TimeoutException("Message was not received in a timely fashion"); } } diff --git a/osu.Framework.Tests/Platform/PortableInstallationTest.cs b/osu.Framework.Tests/Platform/PortableInstallationTest.cs index d686e4b35..8ee2c2304 100644 --- a/osu.Framework.Tests/Platform/PortableInstallationTest.cs +++ b/osu.Framework.Tests/Platform/PortableInstallationTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Configuration; using osu.Framework.Platform; diff --git a/osu.Framework.Tests/Platform/UserInputManagerTest.cs b/osu.Framework.Tests/Platform/UserInputManagerTest.cs index a3f6e91b7..d35758dc7 100644 --- a/osu.Framework.Tests/Platform/UserInputManagerTest.cs +++ b/osu.Framework.Tests/Platform/UserInputManagerTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Testing; diff --git a/osu.Framework.Tests/Platform/UserStorageLookupTest.cs b/osu.Framework.Tests/Platform/UserStorageLookupTest.cs index ad85d3838..0ecf20ce2 100644 --- a/osu.Framework.Tests/Platform/UserStorageLookupTest.cs +++ b/osu.Framework.Tests/Platform/UserStorageLookupTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.IO; diff --git a/osu.Framework.Tests/Polygons/ConvexPolygonClipperFuzzingTest.cs b/osu.Framework.Tests/Polygons/ConvexPolygonClipperFuzzingTest.cs new file mode 100644 index 000000000..b0f09b335 --- /dev/null +++ b/osu.Framework.Tests/Polygons/ConvexPolygonClipperFuzzingTest.cs @@ -0,0 +1,118 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using NUnit.Framework; +using osu.Framework.Graphics.Primitives; +using osu.Framework.Utils; +using osuTK; + +namespace osu.Framework.Tests.Polygons +{ + [TestFixture] + [Ignore("This test will never complete if working correctly. Test manually if required.")] + public class ConvexPolygonClipperFuzzingTest + { + private const int parallelism = 4; + + private static readonly float[] possible_values = + { + float.NegativeInfinity, + float.MinValue, + float.MinValue / 2, + -10.0f, + -2.0f, + -1.0f, + -0.5f, + -0.1f, + 0.0f, + float.Epsilon, + 0.1f, + 0.5f, + 1.0f, + 2.0f, + 10.0f, + float.MaxValue / 2, + float.MaxValue, + float.PositiveInfinity, + float.NaN, + }; + + private static readonly int[] possible_sizes = + { + 3, + 4, + 5, + 8, + 16 + }; + + [Test] + public void RunTest() + { + Task[] tasks = new Task[parallelism]; + + for (int i = 0; i < tasks.Length; i++) + { + tasks[i] = Task.Factory.StartNew(() => + { + while (true) + { + int count1 = getRand(possible_sizes); + int count2 = getRand(possible_sizes); + + HashSet vertices1 = new HashSet(); + HashSet vertices2 = new HashSet(); + + while (vertices1.Count < count1) + vertices1.Add(new Vector2(getRand(possible_values), getRand(possible_values))); + + while (vertices2.Count < count2) + vertices2.Add(new Vector2(getRand(possible_values), getRand(possible_values))); + + SimpleConvexPolygon poly1 = new SimpleConvexPolygon(vertices1.ToArray()); + SimpleConvexPolygon poly2 = new SimpleConvexPolygon(vertices2.ToArray()); + + try + { + clip(poly1, poly2); + } + catch (Exception ex) + { + Assert.Fail($"Failed.\nPoly1: {poly1}\nPoly2: {poly2}\n\nException: {ex}"); + return; + } + + try + { + clip(poly2, poly1); + } + catch (Exception ex) + { + Assert.Fail($"Failed.\nPoly1: {poly2}\nPoly2: {poly1}\n\nException: {ex}"); + return; + } + } + }, TaskCreationOptions.LongRunning); + } + + Task.WaitAny(tasks); + } + + private static Vector2[] clip(SimpleConvexPolygon poly1, SimpleConvexPolygon poly2) + { + var clipper = new ConvexPolygonClipper(ref poly1, ref poly2); + + Span buffer = stackalloc Vector2[clipper.GetClipBufferSize()]; + + return clipper.Clip(buffer).ToArray(); + } + + private static T getRand(T[] arr) => arr[RNG.Next(0, arr.Length)]; + } +} diff --git a/osu.Framework.Tests/Polygons/ConvexPolygonClippingTest.cs b/osu.Framework.Tests/Polygons/ConvexPolygonClippingTest.cs index dc002e89d..8ad7b8d3e 100644 --- a/osu.Framework.Tests/Polygons/ConvexPolygonClippingTest.cs +++ b/osu.Framework.Tests/Polygons/ConvexPolygonClippingTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using NUnit.Framework; using osu.Framework.Graphics; @@ -241,6 +243,64 @@ namespace osu.Framework.Tests.Polygons false); } + private static object[] fuzzedEdgeCases => new object[] + { + new object[] + { + new[] { new Vector2(0, 0.5f), new Vector2(100, 1), new Vector2(2, 2), new Vector2(1, 2) }, + new[] { new Vector2(0, 0.5f), new Vector2(100, 0), new Vector2(0.5f, 100) }, + }, + new object[] + { + new[] { new Vector2(0, 1), new Vector2(100, 0), new Vector2(100, 2), new Vector2(2, 2) }, + new[] { new Vector2(1, 100), new Vector2(2, 0.5f), new Vector2(100, 2) }, + }, + new object[] + { + new[] { new Vector2(0, 1), new Vector2(2, 0.5f), new Vector2(100, 0), new Vector2(1, 2) }, + new[] { new Vector2(1, 0.5f), new Vector2(100, 0), new Vector2(1, 100) }, + }, + new object[] + { + new[] { new Vector2(0, 1), new Vector2(0, 0), new Vector2(2, 1), new Vector2(1, 2) }, + new[] { new Vector2(0.5f, 2), new Vector2(100, 0.5f), new Vector2(1, 0.5f), new Vector2(100, 2) }, + }, + new object[] + { + new[] { new Vector2(2, float.MinValue), new Vector2(float.MaxValue, 0.5f), new Vector2(float.MaxValue, float.NegativeInfinity), new Vector2(1, float.MaxValue) }, + new[] { new Vector2(0, 1), new Vector2(0, float.NegativeInfinity), new Vector2(float.Epsilon, 1), new Vector2(1, 0.5f) }, + }, + new object[] + { + new[] { new Vector2(float.Epsilon, 0.5f), new Vector2(float.Epsilon, 100), new Vector2(float.MaxValue, float.NegativeInfinity), new Vector2(1, float.MaxValue) }, + new[] { new Vector2(0, 1), new Vector2(0, float.NegativeInfinity), new Vector2(float.Epsilon, 1), new Vector2(1, 0.5f) }, + }, + new object[] + { + new[] { new Vector2(-0.1f, 2), new Vector2(0, 0), new Vector2(0.5f, -0.1f) }, + new[] { new Vector2(-10, 2), new Vector2(-0.5f, 0.1f), new Vector2(0.5f, 0.5f) } + }, + new object[] + { + new[] { new Vector2(-10, 1), new Vector2(0.1f, 0), new Vector2(-0.5f, 2) }, + new[] { new Vector2(-1, 2), new Vector2(-0.1f, -0.5f), new Vector2(0.1f, 0) } + }, + new object[] + { + new[] { new Vector2(-1, 0.5f), new Vector2(0.1f, 0.1f), new Vector2(0, 1) }, + new[] { new Vector2(-2, -0.5f), new Vector2(0.1f, 0.1f), new Vector2(-0.1f, 1) } + } + }; + + [TestCaseSource(nameof(fuzzedEdgeCases))] + public void TestFuzzedEdgeCases(Vector2[] clipVertices, Vector2[] subjectVertices) + { + var clipPolygon = new SimpleConvexPolygon(clipVertices); + var subjectPolygon = new SimpleConvexPolygon(subjectVertices); + + clip(clipPolygon, subjectPolygon); + } + private Span clip(SimpleConvexPolygon clipPolygon, SimpleConvexPolygon subjectPolygon) => new ConvexPolygonClipper(ref clipPolygon, ref subjectPolygon).Clip(); diff --git a/osu.Framework.Tests/Polygons/LineIntersections.cs b/osu.Framework.Tests/Polygons/LineIntersections.cs index d19007d58..025043fe2 100644 --- a/osu.Framework.Tests/Polygons/LineIntersections.cs +++ b/osu.Framework.Tests/Polygons/LineIntersections.cs @@ -1,7 +1,10 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; +using osu.Framework.Graphics; using osu.Framework.Graphics.Primitives; using osuTK; @@ -56,7 +59,7 @@ namespace osu.Framework.Tests.Polygons new object[] { new Line(up_1, origin), new Line(origin, up_1), false, 0f }, new object[] { new Line(origin, up_1), new Line(up_1, origin), false, 0f }, new object[] { new Line(up_1, origin), new Line(up_1, origin), false, 0f }, - // Colinear touching + // Collinear touching new object[] { new Line(origin, up_1), new Line(origin, down_1), false, 0f }, new object[] { new Line(origin, up_1), new Line(down_1, origin), false, 0f }, }; @@ -69,5 +72,12 @@ namespace osu.Framework.Tests.Polygons Assert.That(success, Is.EqualTo(expectedResult)); Assert.That(t, Is.EqualTo(expectedT)); } + + [Test] + public void TestCollinearPointNotInRightHalfPlane() + { + Line line = new Line(new Vector2(-0.5f, 0.1f), new Vector2(-10, 2)); + Assert.That(new Vector2(0.5f, -0.1f).InRightHalfPlaneOf(line), Is.False); + } } } diff --git a/osu.Framework.Tests/Primitives/QuadTest.cs b/osu.Framework.Tests/Primitives/QuadTest.cs index d69a2a9f0..6a31e455c 100644 --- a/osu.Framework.Tests/Primitives/QuadTest.cs +++ b/osu.Framework.Tests/Primitives/QuadTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections; using NUnit.Framework; using osu.Framework.Extensions.MatrixExtensions; diff --git a/osu.Framework.Tests/Primitives/TriangleTest.cs b/osu.Framework.Tests/Primitives/TriangleTest.cs index 91d66cfab..1ac187efd 100644 --- a/osu.Framework.Tests/Primitives/TriangleTest.cs +++ b/osu.Framework.Tests/Primitives/TriangleTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Graphics.Primitives; using osuTK; diff --git a/osu.Framework.Tests/Primitives/Vector2ExtensionsTest.cs b/osu.Framework.Tests/Primitives/Vector2ExtensionsTest.cs index 719d479d7..81a473792 100644 --- a/osu.Framework.Tests/Primitives/Vector2ExtensionsTest.cs +++ b/osu.Framework.Tests/Primitives/Vector2ExtensionsTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using NUnit.Framework; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Program.cs b/osu.Framework.Tests/Program.cs index 8fb25e4db..1743924e2 100644 --- a/osu.Framework.Tests/Program.cs +++ b/osu.Framework.Tests/Program.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Linq; using osu.Framework.Platform; diff --git a/osu.Framework.Tests/Shaders/TestSceneShaderDisposal.cs b/osu.Framework.Tests/Shaders/TestSceneShaderDisposal.cs index a43db97fc..15d48ad28 100644 --- a/osu.Framework.Tests/Shaders/TestSceneShaderDisposal.cs +++ b/osu.Framework.Tests/Shaders/TestSceneShaderDisposal.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using NUnit.Framework; diff --git a/osu.Framework.Tests/Sprites/TestSceneSpriteTextPresence.cs b/osu.Framework.Tests/Sprites/TestSceneSpriteTextPresence.cs index 2e1bee049..c675db517 100644 --- a/osu.Framework.Tests/Sprites/TestSceneSpriteTextPresence.cs +++ b/osu.Framework.Tests/Sprites/TestSceneSpriteTextPresence.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/TestGame.cs b/osu.Framework.Tests/TestGame.cs index 8183f4e45..b2a09a141 100644 --- a/osu.Framework.Tests/TestGame.cs +++ b/osu.Framework.Tests/TestGame.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.IO.Stores; diff --git a/osu.Framework.Tests/Text/TextBuilderTest.cs b/osu.Framework.Tests/Text/TextBuilderTest.cs index 1c1e37d1d..c8d2c6e74 100644 --- a/osu.Framework.Tests/Text/TextBuilderTest.cs +++ b/osu.Framework.Tests/Text/TextBuilderTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Linq; using System.Threading.Tasks; diff --git a/osu.Framework.Tests/Threading/AsyncDisposalQueueTest.cs b/osu.Framework.Tests/Threading/AsyncDisposalQueueTest.cs index d554767d5..b092fe6a1 100644 --- a/osu.Framework.Tests/Threading/AsyncDisposalQueueTest.cs +++ b/osu.Framework.Tests/Threading/AsyncDisposalQueueTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework.Tests/Threading/SchedulerTest.cs b/osu.Framework.Tests/Threading/SchedulerTest.cs index bb4641bf5..b2b25d6dd 100644 --- a/osu.Framework.Tests/Threading/SchedulerTest.cs +++ b/osu.Framework.Tests/Threading/SchedulerTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using NUnit.Framework; using osu.Framework.Logging; diff --git a/osu.Framework.Tests/Threading/ThreadedTaskSchedulerTest.cs b/osu.Framework.Tests/Threading/ThreadedTaskSchedulerTest.cs index 4e8733e3e..380b0871d 100644 --- a/osu.Framework.Tests/Threading/ThreadedTaskSchedulerTest.cs +++ b/osu.Framework.Tests/Threading/ThreadedTaskSchedulerTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Threading; using System.Threading.Tasks; using NUnit.Framework; diff --git a/osu.Framework.Tests/Transforms/TestSceneTransformEventBindings.cs b/osu.Framework.Tests/Transforms/TestSceneTransformEventBindings.cs index 6fea2a255..b92482358 100644 --- a/osu.Framework.Tests/Transforms/TestSceneTransformEventBindings.cs +++ b/osu.Framework.Tests/Transforms/TestSceneTransformEventBindings.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -41,7 +43,7 @@ namespace osu.Framework.Tests.Transforms Child = container = new Container(); completedFired = 0; - container.FadeIn(500).Then().FadeOut().OnComplete(a => { completedFired++; }); + container.FadeIn(500).Then().FadeOut().OnComplete(_ => { completedFired++; }); }); AddAssert("not immediately fired", () => completedFired == 0); diff --git a/osu.Framework.Tests/Visual/Audio/TestSceneAudioMixer.cs b/osu.Framework.Tests/Visual/Audio/TestSceneAudioMixer.cs index 065f366e7..147b57dc7 100644 --- a/osu.Framework.Tests/Visual/Audio/TestSceneAudioMixer.cs +++ b/osu.Framework.Tests/Visual/Audio/TestSceneAudioMixer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Linq; using ManagedBass; using ManagedBass.Fx; diff --git a/osu.Framework.Tests/Visual/Audio/TestSceneSampleAmplitudes.cs b/osu.Framework.Tests/Visual/Audio/TestSceneSampleAmplitudes.cs index bf5925edf..3b4aed7a0 100644 --- a/osu.Framework.Tests/Visual/Audio/TestSceneSampleAmplitudes.cs +++ b/osu.Framework.Tests/Visual/Audio/TestSceneSampleAmplitudes.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Linq; using osu.Framework.Allocation; using osu.Framework.Audio.Sample; diff --git a/osu.Framework.Tests/Visual/Audio/TestSceneSampleChannels.cs b/osu.Framework.Tests/Visual/Audio/TestSceneSampleChannels.cs index 9e46c5c6c..be046822f 100644 --- a/osu.Framework.Tests/Visual/Audio/TestSceneSampleChannels.cs +++ b/osu.Framework.Tests/Visual/Audio/TestSceneSampleChannels.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using NUnit.Framework; using osu.Framework.Allocation; diff --git a/osu.Framework.Tests/Visual/Audio/TestSceneSampleLooping.cs b/osu.Framework.Tests/Visual/Audio/TestSceneSampleLooping.cs index 380419039..bcc2b5dca 100644 --- a/osu.Framework.Tests/Visual/Audio/TestSceneSampleLooping.cs +++ b/osu.Framework.Tests/Visual/Audio/TestSceneSampleLooping.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Audio; diff --git a/osu.Framework.Tests/Visual/Audio/TestSceneSamples.cs b/osu.Framework.Tests/Visual/Audio/TestSceneSamples.cs index dfa294c10..165f07e1d 100644 --- a/osu.Framework.Tests/Visual/Audio/TestSceneSamples.cs +++ b/osu.Framework.Tests/Visual/Audio/TestSceneSamples.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Linq; using osu.Framework.Allocation; using osu.Framework.Audio; diff --git a/osu.Framework.Tests/Visual/Audio/TestSceneTrackAdjustments.cs b/osu.Framework.Tests/Visual/Audio/TestSceneTrackAdjustments.cs index 10554b353..271ec1f41 100644 --- a/osu.Framework.Tests/Visual/Audio/TestSceneTrackAdjustments.cs +++ b/osu.Framework.Tests/Visual/Audio/TestSceneTrackAdjustments.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Allocation; using osu.Framework.Audio.Track; using osu.Framework.Bindables; diff --git a/osu.Framework.Tests/Visual/Audio/TestSceneTrackAmplitudes.cs b/osu.Framework.Tests/Visual/Audio/TestSceneTrackAmplitudes.cs index 888de7048..6a545105f 100644 --- a/osu.Framework.Tests/Visual/Audio/TestSceneTrackAmplitudes.cs +++ b/osu.Framework.Tests/Visual/Audio/TestSceneTrackAmplitudes.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Linq; using osu.Framework.Allocation; using osu.Framework.Audio.Track; diff --git a/osu.Framework.Tests/Visual/Bindables/TestSceneBindableAutoUnbinding.cs b/osu.Framework.Tests/Visual/Bindables/TestSceneBindableAutoUnbinding.cs index 18687c386..6f59fff87 100644 --- a/osu.Framework.Tests/Visual/Bindables/TestSceneBindableAutoUnbinding.cs +++ b/osu.Framework.Tests/Visual/Bindables/TestSceneBindableAutoUnbinding.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Bindables; diff --git a/osu.Framework.Tests/Visual/Bindables/TestSceneBindableNumbers.cs b/osu.Framework.Tests/Visual/Bindables/TestSceneBindableNumbers.cs index b0cc82d27..7c568b99e 100644 --- a/osu.Framework.Tests/Visual/Bindables/TestSceneBindableNumbers.cs +++ b/osu.Framework.Tests/Visual/Bindables/TestSceneBindableNumbers.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Globalization; using osu.Framework.Bindables; diff --git a/osu.Framework.Tests/Visual/Clocks/LaggyFramedClock.cs b/osu.Framework.Tests/Visual/Clocks/LaggyFramedClock.cs index 139129660..ce97d6bf2 100644 --- a/osu.Framework.Tests/Visual/Clocks/LaggyFramedClock.cs +++ b/osu.Framework.Tests/Visual/Clocks/LaggyFramedClock.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Timing; namespace osu.Framework.Tests.Visual.Clocks diff --git a/osu.Framework.Tests/Visual/Clocks/TestSceneClock.cs b/osu.Framework.Tests/Visual/Clocks/TestSceneClock.cs index 68e540cce..66f8bcf41 100644 --- a/osu.Framework.Tests/Visual/Clocks/TestSceneClock.cs +++ b/osu.Framework.Tests/Visual/Clocks/TestSceneClock.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework.Tests/Visual/Clocks/TestSceneClocks.cs b/osu.Framework.Tests/Visual/Clocks/TestSceneClocks.cs index 719e39d7e..ccde6c823 100644 --- a/osu.Framework.Tests/Visual/Clocks/TestSceneClocks.cs +++ b/osu.Framework.Tests/Visual/Clocks/TestSceneClocks.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Timing; namespace osu.Framework.Tests.Visual.Clocks diff --git a/osu.Framework.Tests/Visual/Containers/TestSceneBufferedContainer.cs b/osu.Framework.Tests/Visual/Containers/TestSceneBufferedContainer.cs index eee36160c..f4626bd9c 100644 --- a/osu.Framework.Tests/Visual/Containers/TestSceneBufferedContainer.cs +++ b/osu.Framework.Tests/Visual/Containers/TestSceneBufferedContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osuTK; diff --git a/osu.Framework.Tests/Visual/Containers/TestSceneCachedBufferedContainer.cs b/osu.Framework.Tests/Visual/Containers/TestSceneCachedBufferedContainer.cs index 6a6ec4417..3ce61c0f0 100644 --- a/osu.Framework.Tests/Visual/Containers/TestSceneCachedBufferedContainer.cs +++ b/osu.Framework.Tests/Visual/Containers/TestSceneCachedBufferedContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework.Tests/Visual/Containers/TestSceneCircularContainer.cs b/osu.Framework.Tests/Visual/Containers/TestSceneCircularContainer.cs index ddc522dc4..9a02ddff3 100644 --- a/osu.Framework.Tests/Visual/Containers/TestSceneCircularContainer.cs +++ b/osu.Framework.Tests/Visual/Containers/TestSceneCircularContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; diff --git a/osu.Framework.Tests/Visual/Containers/TestSceneCircularContainerSizing.cs b/osu.Framework.Tests/Visual/Containers/TestSceneCircularContainerSizing.cs index 120a587bd..c8e5ec960 100644 --- a/osu.Framework.Tests/Visual/Containers/TestSceneCircularContainerSizing.cs +++ b/osu.Framework.Tests/Visual/Containers/TestSceneCircularContainerSizing.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using NUnit.Framework; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Visual/Containers/TestSceneCompositeDrawable.cs b/osu.Framework.Tests/Visual/Containers/TestSceneCompositeDrawable.cs index 2e2b22d62..42fa0329a 100644 --- a/osu.Framework.Tests/Visual/Containers/TestSceneCompositeDrawable.cs +++ b/osu.Framework.Tests/Visual/Containers/TestSceneCompositeDrawable.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using NUnit.Framework; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Visual/Containers/TestSceneCoordinateSpaces.cs b/osu.Framework.Tests/Visual/Containers/TestSceneCoordinateSpaces.cs index f30e59c26..0a6c5dd18 100644 --- a/osu.Framework.Tests/Visual/Containers/TestSceneCoordinateSpaces.cs +++ b/osu.Framework.Tests/Visual/Containers/TestSceneCoordinateSpaces.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Globalization; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework.Tests/Visual/Containers/TestSceneCursorContainer.cs b/osu.Framework.Tests/Visual/Containers/TestSceneCursorContainer.cs index ae3b1314d..232468500 100644 --- a/osu.Framework.Tests/Visual/Containers/TestSceneCursorContainer.cs +++ b/osu.Framework.Tests/Visual/Containers/TestSceneCursorContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework.Tests/Visual/Containers/TestSceneCustomizableTextContainer.cs b/osu.Framework.Tests/Visual/Containers/TestSceneCustomizableTextContainer.cs index d840ce46e..046f3ba6e 100644 --- a/osu.Framework.Tests/Visual/Containers/TestSceneCustomizableTextContainer.cs +++ b/osu.Framework.Tests/Visual/Containers/TestSceneCustomizableTextContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Configuration; diff --git a/osu.Framework.Tests/Visual/Containers/TestSceneDrawSizePreservingFillContainer.cs b/osu.Framework.Tests/Visual/Containers/TestSceneDrawSizePreservingFillContainer.cs index 7a9afa775..5a487f7f8 100644 --- a/osu.Framework.Tests/Visual/Containers/TestSceneDrawSizePreservingFillContainer.cs +++ b/osu.Framework.Tests/Visual/Containers/TestSceneDrawSizePreservingFillContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework.Tests/Visual/Containers/TestSceneDynamicDepth.cs b/osu.Framework.Tests/Visual/Containers/TestSceneDynamicDepth.cs index 7b6ecdf47..7ebdcb42c 100644 --- a/osu.Framework.Tests/Visual/Containers/TestSceneDynamicDepth.cs +++ b/osu.Framework.Tests/Visual/Containers/TestSceneDynamicDepth.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; diff --git a/osu.Framework.Tests/Visual/Containers/TestSceneFrontToBack.cs b/osu.Framework.Tests/Visual/Containers/TestSceneFrontToBack.cs index bb7a19761..4b063cb02 100644 --- a/osu.Framework.Tests/Visual/Containers/TestSceneFrontToBack.cs +++ b/osu.Framework.Tests/Visual/Containers/TestSceneFrontToBack.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Allocation; using osu.Framework.Configuration; diff --git a/osu.Framework.Tests/Visual/Containers/TestSceneFrontToBackBox.cs b/osu.Framework.Tests/Visual/Containers/TestSceneFrontToBackBox.cs index 8f29609cb..bb3c11bfd 100644 --- a/osu.Framework.Tests/Visual/Containers/TestSceneFrontToBackBox.cs +++ b/osu.Framework.Tests/Visual/Containers/TestSceneFrontToBackBox.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using NUnit.Framework; using osu.Framework.Allocation; diff --git a/osu.Framework.Tests/Visual/Containers/TestSceneFrontToBackBufferedContainer.cs b/osu.Framework.Tests/Visual/Containers/TestSceneFrontToBackBufferedContainer.cs index 4dac0f217..b01008cb9 100644 --- a/osu.Framework.Tests/Visual/Containers/TestSceneFrontToBackBufferedContainer.cs +++ b/osu.Framework.Tests/Visual/Containers/TestSceneFrontToBackBufferedContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework.Tests/Visual/Containers/TestSceneFrontToBackTriangle.cs b/osu.Framework.Tests/Visual/Containers/TestSceneFrontToBackTriangle.cs index d87fef535..3aa327882 100644 --- a/osu.Framework.Tests/Visual/Containers/TestSceneFrontToBackTriangle.cs +++ b/osu.Framework.Tests/Visual/Containers/TestSceneFrontToBackTriangle.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics; using osu.Framework.Graphics.Shapes; using osuTK; diff --git a/osu.Framework.Tests/Visual/Containers/TestSceneLifetimeManagementContainer.cs b/osu.Framework.Tests/Visual/Containers/TestSceneLifetimeManagementContainer.cs index 3677452ae..12d241000 100644 --- a/osu.Framework.Tests/Visual/Containers/TestSceneLifetimeManagementContainer.cs +++ b/osu.Framework.Tests/Visual/Containers/TestSceneLifetimeManagementContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework.Tests/Visual/Containers/TestSceneMasking.cs b/osu.Framework.Tests/Visual/Containers/TestSceneMasking.cs index 0eaabbbae..2ca117832 100644 --- a/osu.Framework.Tests/Visual/Containers/TestSceneMasking.cs +++ b/osu.Framework.Tests/Visual/Containers/TestSceneMasking.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework.Tests/Visual/Containers/TestScenePadding.cs b/osu.Framework.Tests/Visual/Containers/TestScenePadding.cs index e4387ad8c..9e87fac85 100644 --- a/osu.Framework.Tests/Visual/Containers/TestScenePadding.cs +++ b/osu.Framework.Tests/Visual/Containers/TestScenePadding.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; diff --git a/osu.Framework.Tests/Visual/Containers/TestSceneSafeAreaContainer.cs b/osu.Framework.Tests/Visual/Containers/TestSceneSafeAreaContainer.cs index 475fa20ef..b8f87bb24 100644 --- a/osu.Framework.Tests/Visual/Containers/TestSceneSafeAreaContainer.cs +++ b/osu.Framework.Tests/Visual/Containers/TestSceneSafeAreaContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Linq; using osu.Framework.Bindables; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Visual/Containers/TestSceneSafeAreaOverrides.cs b/osu.Framework.Tests/Visual/Containers/TestSceneSafeAreaOverrides.cs index 88c2339a7..852313188 100644 --- a/osu.Framework.Tests/Visual/Containers/TestSceneSafeAreaOverrides.cs +++ b/osu.Framework.Tests/Visual/Containers/TestSceneSafeAreaOverrides.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Extensions.EnumExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework.Tests/Visual/Containers/TestSceneScrollContainer.cs b/osu.Framework.Tests/Visual/Containers/TestSceneScrollContainer.cs index 09660da23..0089c4e20 100644 --- a/osu.Framework.Tests/Visual/Containers/TestSceneScrollContainer.cs +++ b/osu.Framework.Tests/Visual/Containers/TestSceneScrollContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Diagnostics; using System.Linq; @@ -140,9 +142,9 @@ namespace osu.Framework.Tests.Visual.Containers InputManager.MoveMouseTo(scrollContainer.ToScreenSpace(scrollContainer.LayoutRectangle.Centre + new Vector2(10f))); }); - AddStep("Move mouse up", () => InputManager.MoveMouseTo(scrollContainer.ScreenSpaceDrawQuad.Centre - new Vector2(0, 400))); + AddStep("Move mouse up", () => InputManager.MoveMouseTo(scrollContainer.ScreenSpaceDrawQuad.Centre - new Vector2(0, 1000))); checkPosition(withClampExtension ? 200 : 100); - AddStep("Move mouse down", () => InputManager.MoveMouseTo(scrollContainer.ScreenSpaceDrawQuad.Centre + new Vector2(0, 400))); + AddStep("Move mouse down", () => InputManager.MoveMouseTo(scrollContainer.ScreenSpaceDrawQuad.Centre + new Vector2(0, 1000))); checkPosition(withClampExtension ? -100 : 0); AddStep("Release mouse button", () => InputManager.ReleaseButton(MouseButton.Left)); checkPosition(0); @@ -451,6 +453,135 @@ namespace osu.Framework.Tests.Visual.Containers static bool checkScrollCurrent(BasicScrollContainer scrolled, BasicScrollContainer notScrolled) => notScrolled.Current == 0 && Precision.DefinitelyBigger(scrolled.Current, 0f); } + /// + /// Ensures that initiating a drag with horizontal delta on a singular vertical doesn't prevent from continuing with vertical drags. + /// + /// + /// If the vertical scroll container is nested inside of a horizontal one, then it should prevent it, as covered in . + /// + [TestCase(false)] + [TestCase(true)] + public void TestSingularVerticalScrollWithHorizontalDelta(bool withClampExtension) + { + AddStep("Create scroll container", () => + { + Add(scrollContainer = new BasicScrollContainer + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Size = new Vector2(200), + ClampExtension = withClampExtension ? 100 : 0, + Child = new Box { Size = new Vector2(200, 300) } + }); + }); + + AddStep("Click and drag horizontally", () => + { + InputManager.MoveMouseTo(scrollContainer); + InputManager.PressButton(MouseButton.Left); + + // Required for the dragging state to be set correctly. + InputManager.MoveMouseTo(scrollContainer.ToScreenSpace(scrollContainer.LayoutRectangle.Centre + new Vector2(20f, 0f))); + }); + + AddStep("Move mouse up", () => InputManager.MoveMouseTo(scrollContainer.ScreenSpaceDrawQuad.Centre - new Vector2(0, 1000))); + checkPosition(withClampExtension ? 200 : 100); + AddStep("Move mouse down", () => InputManager.MoveMouseTo(scrollContainer.ScreenSpaceDrawQuad.Centre + new Vector2(0, 1000))); + checkPosition(withClampExtension ? -100 : 0); + + AddStep("Move mouse diagonally up", () => InputManager.MoveMouseTo(scrollContainer.ScreenSpaceDrawQuad.Centre - new Vector2(2000, 1000))); + checkPosition(withClampExtension ? 200 : 100); + AddStep("Move mouse diagonally down", () => InputManager.MoveMouseTo(scrollContainer.ScreenSpaceDrawQuad.Centre + new Vector2(2000, 1000))); + checkPosition(withClampExtension ? -100 : 0); + + AddStep("Release mouse button", () => InputManager.ReleaseButton(MouseButton.Left)); + checkPosition(0); + + AddStep("Hover over scroll container", () => InputManager.MoveMouseTo(scrollContainer)); + AddStep("Scroll diagonally down", () => InputManager.ScrollBy(new Vector2(-20, -10))); + checkPosition(100); + AddStep("Scroll diagonally up", () => InputManager.ScrollBy(new Vector2(20, 10))); + checkPosition(0); + } + + [Test] + public void TestDragHandlingUpdatesOnParentChanges() + { + BasicScrollContainer horizontalScrollContainer = null; + + AddStep("Create scroll container", () => + { + Add(scrollContainer = new BasicScrollContainer + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Size = new Vector2(200), + ClampExtension = 0, + Child = new Box { Size = new Vector2(200, 300) } + }); + }); + + AddStep("Click and drag horizontally", () => + { + InputManager.MoveMouseTo(scrollContainer); + InputManager.PressButton(MouseButton.Left); + + // Required for the dragging state to be set correctly. + InputManager.MoveMouseTo(scrollContainer.ToScreenSpace(scrollContainer.LayoutRectangle.Centre + new Vector2(20f, 0f))); + }); + + AddStep("Move mouse diagonally up", () => InputManager.MoveMouseTo(scrollContainer.ScreenSpaceDrawQuad.Centre - new Vector2(1000, 1000))); + checkPosition(100); + AddStep("Move mouse diagonally down", () => InputManager.MoveMouseTo(scrollContainer.ScreenSpaceDrawQuad.Centre + new Vector2(1000, 1000))); + checkPosition(0); + + AddStep("Release mouse button", () => InputManager.ReleaseButton(MouseButton.Left)); + checkPosition(0); + + AddStep("Nest vertical scroll inside of horizontal", () => + { + Remove(scrollContainer); + + Add(horizontalScrollContainer = new BasicScrollContainer(Direction.Horizontal) + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Size = new Vector2(400), + ClampExtension = 0, + Children = new Drawable[] + { + new Box + { + Size = new Vector2(500, 400), + Colour = FrameworkColour.Yellow, + }, + scrollContainer + }, + }); + }); + + AddStep("Click and drag horizontally", () => + { + InputManager.MoveMouseTo(scrollContainer); + InputManager.PressButton(MouseButton.Left); + + // Required for the dragging state to be set correctly. + InputManager.MoveMouseTo(scrollContainer.ToScreenSpace(scrollContainer.LayoutRectangle.Centre + new Vector2(20f, 0f))); + }); + + AddStep("Move mouse diagonally up", () => InputManager.MoveMouseTo(scrollContainer.ScreenSpaceDrawQuad.Centre - new Vector2(1000, 1000))); + AddUntilStep("horizontal position at 100", () => Precision.AlmostEquals(100, horizontalScrollContainer.Current, 1)); + AddUntilStep("vertical position at 0", () => Precision.AlmostEquals(0, scrollContainer.Current, 1)); + + AddStep("Move mouse diagonally down", () => InputManager.MoveMouseTo(scrollContainer.ScreenSpaceDrawQuad.Centre + new Vector2(1000, 1000))); + AddUntilStep("horizontal position at 0", () => Precision.AlmostEquals(0, horizontalScrollContainer.Current, 1)); + AddUntilStep("vertical position at 0", () => Precision.AlmostEquals(0, scrollContainer.Current, 1)); + + AddStep("Release mouse button", () => InputManager.ReleaseButton(MouseButton.Left)); + AddUntilStep("horizontal position at 0", () => Precision.AlmostEquals(0, horizontalScrollContainer.Current, 1)); + AddUntilStep("vertical position at 0", () => Precision.AlmostEquals(0, scrollContainer.Current, 1)); + } + private void scrollIntoView(int index, float expectedPosition, float? heightAdjust = null, float? expectedPostAdjustPosition = null) { if (heightAdjust != null) @@ -484,7 +615,7 @@ namespace osu.Framework.Tests.Visual.Containers AddAssert($"immediately scrolled to {clampedTarget}", () => Precision.AlmostEquals(clampedTarget, immediateScrollPosition, 1)); } - private void checkPosition(float expected) => AddUntilStep($"position at {expected}", () => Precision.AlmostEquals(expected, scrollContainer.Current, 1)); + private void checkPosition(float expected, ScrollContainer scroll = null) => AddUntilStep($"position at {expected}", () => Precision.AlmostEquals(expected, (scroll ?? scrollContainer).Current, 1)); private void checkScrollbarPosition(float expected) => AddUntilStep($"scrollbar position at {expected}", () => Precision.AlmostEquals(expected, scrollContainer.InternalChildren[1].DrawPosition.Y, 1)); diff --git a/osu.Framework.Tests/Visual/Containers/TestSceneSizing.cs b/osu.Framework.Tests/Visual/Containers/TestSceneSizing.cs index 529af6b21..c9865ff6b 100644 --- a/osu.Framework.Tests/Visual/Containers/TestSceneSizing.cs +++ b/osu.Framework.Tests/Visual/Containers/TestSceneSizing.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Visual/Containers/TestSceneTextFlowContainer.cs b/osu.Framework.Tests/Visual/Containers/TestSceneTextFlowContainer.cs index 4f595111d..c217c0eae 100644 --- a/osu.Framework.Tests/Visual/Containers/TestSceneTextFlowContainer.cs +++ b/osu.Framework.Tests/Visual/Containers/TestSceneTextFlowContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Linq; using NUnit.Framework; using osu.Framework.Extensions.Color4Extensions; diff --git a/osu.Framework.Tests/Visual/Containers/TestSceneVisibilityContainer.cs b/osu.Framework.Tests/Visual/Containers/TestSceneVisibilityContainer.cs index 92b87ef41..9ecb0f8db 100644 --- a/osu.Framework.Tests/Visual/Containers/TestSceneVisibilityContainer.cs +++ b/osu.Framework.Tests/Visual/Containers/TestSceneVisibilityContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Linq; using NUnit.Framework; using osu.Framework.Graphics; @@ -186,7 +188,7 @@ namespace osu.Framework.Tests.Visual.Containers }, }; - State.ValueChanged += e => FireCount++; + State.ValueChanged += _ => FireCount++; } public int FireCount { get; private set; } diff --git a/osu.Framework.Tests/Visual/Drawables/TestSceneBlending.cs b/osu.Framework.Tests/Visual/Drawables/TestSceneBlending.cs index 07148212e..db011ab06 100644 --- a/osu.Framework.Tests/Visual/Drawables/TestSceneBlending.cs +++ b/osu.Framework.Tests/Visual/Drawables/TestSceneBlending.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework.Tests/Visual/Drawables/TestSceneBorderColour.cs b/osu.Framework.Tests/Visual/Drawables/TestSceneBorderColour.cs index 92498e6ff..8fc6df02f 100644 --- a/osu.Framework.Tests/Visual/Drawables/TestSceneBorderColour.cs +++ b/osu.Framework.Tests/Visual/Drawables/TestSceneBorderColour.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.Colour; diff --git a/osu.Framework.Tests/Visual/Drawables/TestSceneBorderSmoothing.cs b/osu.Framework.Tests/Visual/Drawables/TestSceneBorderSmoothing.cs index ef3386524..cbc0fa553 100644 --- a/osu.Framework.Tests/Visual/Drawables/TestSceneBorderSmoothing.cs +++ b/osu.Framework.Tests/Visual/Drawables/TestSceneBorderSmoothing.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Allocation; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Visual/Drawables/TestSceneCircularArcBoundingBox.cs b/osu.Framework.Tests/Visual/Drawables/TestSceneCircularArcBoundingBox.cs index bb215330d..35f04d547 100644 --- a/osu.Framework.Tests/Visual/Drawables/TestSceneCircularArcBoundingBox.cs +++ b/osu.Framework.Tests/Visual/Drawables/TestSceneCircularArcBoundingBox.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Linq; using osu.Framework.Allocation; @@ -66,7 +68,7 @@ namespace osu.Framework.Tests.Visual.Drawables protected override void LoadComplete() { - controlPoints.BindCollectionChanged((_, __) => + controlPoints.BindCollectionChanged((_, _) => { var copy = controlPoints.ToArray(); if (copy.Length != 3) diff --git a/osu.Framework.Tests/Visual/Drawables/TestSceneColourGradient.cs b/osu.Framework.Tests/Visual/Drawables/TestSceneColourGradient.cs index 957411e6e..e38567e07 100644 --- a/osu.Framework.Tests/Visual/Drawables/TestSceneColourGradient.cs +++ b/osu.Framework.Tests/Visual/Drawables/TestSceneColourGradient.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Colour; diff --git a/osu.Framework.Tests/Visual/Drawables/TestSceneColourInterpolation.cs b/osu.Framework.Tests/Visual/Drawables/TestSceneColourInterpolation.cs index 7838f7474..86d8c8aaa 100644 --- a/osu.Framework.Tests/Visual/Drawables/TestSceneColourInterpolation.cs +++ b/osu.Framework.Tests/Visual/Drawables/TestSceneColourInterpolation.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Linq; using NUnit.Framework; using osu.Framework.Allocation; diff --git a/osu.Framework.Tests/Visual/Drawables/TestSceneComplexBlending.cs b/osu.Framework.Tests/Visual/Drawables/TestSceneComplexBlending.cs index f6da815ec..484cec3d2 100644 --- a/osu.Framework.Tests/Visual/Drawables/TestSceneComplexBlending.cs +++ b/osu.Framework.Tests/Visual/Drawables/TestSceneComplexBlending.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using osu.Framework.Graphics; @@ -225,13 +227,13 @@ namespace osu.Framework.Tests.Visual.Drawables blendingAlphaSrcDropdown.Current.Value = BlendingType.One; blendingAlphaDestDropdown.Current.Value = BlendingType.One; - colourModeDropdown.Current.ValueChanged += v => updateBlending(); - colourEquation.Current.ValueChanged += v => updateBlending(); - alphaEquation.Current.ValueChanged += v => updateBlending(); - blendingSrcDropdown.Current.ValueChanged += v => updateBlending(); - blendingDestDropdown.Current.ValueChanged += v => updateBlending(); - blendingAlphaSrcDropdown.Current.ValueChanged += v => updateBlending(); - blendingAlphaDestDropdown.Current.ValueChanged += v => updateBlending(); + colourModeDropdown.Current.ValueChanged += _ => updateBlending(); + colourEquation.Current.ValueChanged += _ => updateBlending(); + alphaEquation.Current.ValueChanged += _ => updateBlending(); + blendingSrcDropdown.Current.ValueChanged += _ => updateBlending(); + blendingDestDropdown.Current.ValueChanged += _ => updateBlending(); + blendingAlphaSrcDropdown.Current.ValueChanged += _ => updateBlending(); + blendingAlphaDestDropdown.Current.ValueChanged += _ => updateBlending(); } private void switchToCustomBlending() diff --git a/osu.Framework.Tests/Visual/Drawables/TestSceneConcurrentLoad.cs b/osu.Framework.Tests/Visual/Drawables/TestSceneConcurrentLoad.cs index 346369407..eb2c36dba 100644 --- a/osu.Framework.Tests/Visual/Drawables/TestSceneConcurrentLoad.cs +++ b/osu.Framework.Tests/Visual/Drawables/TestSceneConcurrentLoad.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Linq; using System.Threading; using System.Threading.Tasks; diff --git a/osu.Framework.Tests/Visual/Drawables/TestSceneCustomEasingCurve.cs b/osu.Framework.Tests/Visual/Drawables/TestSceneCustomEasingCurve.cs index bf5b1a46c..760e3e8aa 100644 --- a/osu.Framework.Tests/Visual/Drawables/TestSceneCustomEasingCurve.cs +++ b/osu.Framework.Tests/Visual/Drawables/TestSceneCustomEasingCurve.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using System.Linq; using osu.Framework.Bindables; diff --git a/osu.Framework.Tests/Visual/Drawables/TestSceneDelayedLoadUnloadWrapper.cs b/osu.Framework.Tests/Visual/Drawables/TestSceneDelayedLoadUnloadWrapper.cs index dd8f7e316..15fb5bf5f 100644 --- a/osu.Framework.Tests/Visual/Drawables/TestSceneDelayedLoadUnloadWrapper.cs +++ b/osu.Framework.Tests/Visual/Drawables/TestSceneDelayedLoadUnloadWrapper.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework.Tests/Visual/Drawables/TestSceneDelayedLoadWrapper.cs b/osu.Framework.Tests/Visual/Drawables/TestSceneDelayedLoadWrapper.cs index 6dbf9fa6c..e213cb5a1 100644 --- a/osu.Framework.Tests/Visual/Drawables/TestSceneDelayedLoadWrapper.cs +++ b/osu.Framework.Tests/Visual/Drawables/TestSceneDelayedLoadWrapper.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework.Tests/Visual/Drawables/TestSceneDrawNodeDisposal.cs b/osu.Framework.Tests/Visual/Drawables/TestSceneDrawNodeDisposal.cs index 51f929c80..c54a05a73 100644 --- a/osu.Framework.Tests/Visual/Drawables/TestSceneDrawNodeDisposal.cs +++ b/osu.Framework.Tests/Visual/Drawables/TestSceneDrawNodeDisposal.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework.Tests/Visual/Drawables/TestSceneDrawableLoadCancellation.cs b/osu.Framework.Tests/Visual/Drawables/TestSceneDrawableLoadCancellation.cs index 27b885be1..0325a8a51 100644 --- a/osu.Framework.Tests/Visual/Drawables/TestSceneDrawableLoadCancellation.cs +++ b/osu.Framework.Tests/Visual/Drawables/TestSceneDrawableLoadCancellation.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework.Tests/Visual/Drawables/TestSceneDrawablePool.cs b/osu.Framework.Tests/Visual/Drawables/TestSceneDrawablePool.cs index 2b40224cf..6de869777 100644 --- a/osu.Framework.Tests/Visual/Drawables/TestSceneDrawablePool.cs +++ b/osu.Framework.Tests/Visual/Drawables/TestSceneDrawablePool.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework.Tests/Visual/Drawables/TestSceneEasingCurves.cs b/osu.Framework.Tests/Visual/Drawables/TestSceneEasingCurves.cs index aba316c18..e63d1e00f 100644 --- a/osu.Framework.Tests/Visual/Drawables/TestSceneEasingCurves.cs +++ b/osu.Framework.Tests/Visual/Drawables/TestSceneEasingCurves.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Linq; using NUnit.Framework; diff --git a/osu.Framework.Tests/Visual/Drawables/TestSceneEffects.cs b/osu.Framework.Tests/Visual/Drawables/TestSceneEffects.cs index 5171b7b10..aeabe8d6e 100644 --- a/osu.Framework.Tests/Visual/Drawables/TestSceneEffects.cs +++ b/osu.Framework.Tests/Visual/Drawables/TestSceneEffects.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics; using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework.Tests/Visual/Drawables/TestSceneFillModes.cs b/osu.Framework.Tests/Visual/Drawables/TestSceneFillModes.cs index eade96962..319b6946a 100644 --- a/osu.Framework.Tests/Visual/Drawables/TestSceneFillModes.cs +++ b/osu.Framework.Tests/Visual/Drawables/TestSceneFillModes.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework.Tests/Visual/Drawables/TestSceneFocus.cs b/osu.Framework.Tests/Visual/Drawables/TestSceneFocus.cs index e9ea2706c..e52a9203b 100644 --- a/osu.Framework.Tests/Visual/Drawables/TestSceneFocus.cs +++ b/osu.Framework.Tests/Visual/Drawables/TestSceneFocus.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using NUnit.Framework; using osu.Framework.Extensions.Color4Extensions; diff --git a/osu.Framework.Tests/Visual/Drawables/TestSceneHollowEdgeEffect.cs b/osu.Framework.Tests/Visual/Drawables/TestSceneHollowEdgeEffect.cs index 11c26a510..22ff6a214 100644 --- a/osu.Framework.Tests/Visual/Drawables/TestSceneHollowEdgeEffect.cs +++ b/osu.Framework.Tests/Visual/Drawables/TestSceneHollowEdgeEffect.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Effects; diff --git a/osu.Framework.Tests/Visual/Drawables/TestSceneIsMaskedAway.cs b/osu.Framework.Tests/Visual/Drawables/TestSceneIsMaskedAway.cs index 19c5714d4..be4b0abe5 100644 --- a/osu.Framework.Tests/Visual/Drawables/TestSceneIsMaskedAway.cs +++ b/osu.Framework.Tests/Visual/Drawables/TestSceneIsMaskedAway.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Extensions.EnumExtensions; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Visual/Drawables/TestSceneModelBackedDrawable.cs b/osu.Framework.Tests/Visual/Drawables/TestSceneModelBackedDrawable.cs index b67a5a885..8d3e4c300 100644 --- a/osu.Framework.Tests/Visual/Drawables/TestSceneModelBackedDrawable.cs +++ b/osu.Framework.Tests/Visual/Drawables/TestSceneModelBackedDrawable.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Threading; using NUnit.Framework; diff --git a/osu.Framework.Tests/Visual/Drawables/TestSceneModelBackedDrawableWithLoading.cs b/osu.Framework.Tests/Visual/Drawables/TestSceneModelBackedDrawableWithLoading.cs index 3d248ee17..e19c0b6d5 100644 --- a/osu.Framework.Tests/Visual/Drawables/TestSceneModelBackedDrawableWithLoading.cs +++ b/osu.Framework.Tests/Visual/Drawables/TestSceneModelBackedDrawableWithLoading.cs @@ -1,6 +1,9 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + +using System; using System.Threading; using NUnit.Framework; using osu.Framework.Allocation; @@ -175,7 +178,8 @@ namespace osu.Framework.Tests.Visual.Drawables [BackgroundDependencyLoader] private void load() { - AllowLoad.Wait(); + if (!AllowLoad.Wait(10000)) + throw new TimeoutException("Load was not allowed in a timely fashion"); } } diff --git a/osu.Framework.Tests/Visual/Drawables/TestSceneModelBackedDrawableWithUnloading.cs b/osu.Framework.Tests/Visual/Drawables/TestSceneModelBackedDrawableWithUnloading.cs index 578c1857a..c244d96dc 100644 --- a/osu.Framework.Tests/Visual/Drawables/TestSceneModelBackedDrawableWithUnloading.cs +++ b/osu.Framework.Tests/Visual/Drawables/TestSceneModelBackedDrawableWithUnloading.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using NUnit.Framework; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Visual/Drawables/TestScenePathApproximator.cs b/osu.Framework.Tests/Visual/Drawables/TestScenePathApproximator.cs index 73a8d25d2..51e7b93dd 100644 --- a/osu.Framework.Tests/Visual/Drawables/TestScenePathApproximator.cs +++ b/osu.Framework.Tests/Visual/Drawables/TestScenePathApproximator.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Visual/Drawables/TestScenePropertyBoundaries.cs b/osu.Framework.Tests/Visual/Drawables/TestScenePropertyBoundaries.cs index d7443454f..32e13f0d9 100644 --- a/osu.Framework.Tests/Visual/Drawables/TestScenePropertyBoundaries.cs +++ b/osu.Framework.Tests/Visual/Drawables/TestScenePropertyBoundaries.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Shapes; diff --git a/osu.Framework.Tests/Visual/Drawables/TestSceneProxyDrawableLifetime.cs b/osu.Framework.Tests/Visual/Drawables/TestSceneProxyDrawableLifetime.cs index ddd1174cf..7027e8b2d 100644 --- a/osu.Framework.Tests/Visual/Drawables/TestSceneProxyDrawableLifetime.cs +++ b/osu.Framework.Tests/Visual/Drawables/TestSceneProxyDrawableLifetime.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework.Tests/Visual/Drawables/TestSceneProxyDrawables.cs b/osu.Framework.Tests/Visual/Drawables/TestSceneProxyDrawables.cs index 7782629c1..56b76113b 100644 --- a/osu.Framework.Tests/Visual/Drawables/TestSceneProxyDrawables.cs +++ b/osu.Framework.Tests/Visual/Drawables/TestSceneProxyDrawables.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework.Tests/Visual/Drawables/TestSceneStressGLDisposal.cs b/osu.Framework.Tests/Visual/Drawables/TestSceneStressGLDisposal.cs index 8aff35ed1..a2d845c3a 100644 --- a/osu.Framework.Tests/Visual/Drawables/TestSceneStressGLDisposal.cs +++ b/osu.Framework.Tests/Visual/Drawables/TestSceneStressGLDisposal.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Linq; using NUnit.Framework; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Visual/Drawables/TestSceneSynchronizationContext.cs b/osu.Framework.Tests/Visual/Drawables/TestSceneSynchronizationContext.cs index c3ea4b06f..cf6642118 100644 --- a/osu.Framework.Tests/Visual/Drawables/TestSceneSynchronizationContext.cs +++ b/osu.Framework.Tests/Visual/Drawables/TestSceneSynchronizationContext.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Diagnostics; @@ -8,6 +10,7 @@ using System.Threading; using System.Threading.Tasks; using NUnit.Framework; using osu.Framework.Allocation; +using osu.Framework.Configuration; using osu.Framework.Development; using osu.Framework.Graphics; using osu.Framework.Graphics.Shapes; @@ -22,6 +25,9 @@ namespace osu.Framework.Tests.Visual.Drawables [Resolved] private GameHost host { get; set; } + [Resolved] + private FrameworkConfigManager config { get; set; } + private AsyncPerformingBox box; [Test] @@ -194,6 +200,29 @@ namespace osu.Framework.Tests.Visual.Drawables AddUntilStep("has spun", () => box.Rotation == 0); } + [Test] + public void TestExecutionMode() + { + AddStep("add box", () => Child = box = new AsyncPerformingBox(true)); + AddAssert("not spun", () => box.Rotation == 0); + + AddStep("toggle execution mode", () => toggleExecutionMode()); + + AddStep("trigger", () => box.ReleaseAsyncLoadCompleteLock()); + AddUntilStep("has spun", () => box.Rotation == 180); + + AddStep("revert execution mode", () => toggleExecutionMode()); + + void toggleExecutionMode() + { + var executionMode = config.GetBindable(FrameworkSetting.ExecutionMode); + + executionMode.Value = executionMode.Value == ExecutionMode.MultiThreaded + ? ExecutionMode.SingleThread + : ExecutionMode.MultiThreaded; + } + } + public class AsyncPerformingBox : Box { private readonly bool performAsyncLoadComplete; diff --git a/osu.Framework.Tests/Visual/Drawables/TestSceneTransformRewinding.cs b/osu.Framework.Tests/Visual/Drawables/TestSceneTransformRewinding.cs index 7b7d20d53..954178eb1 100644 --- a/osu.Framework.Tests/Visual/Drawables/TestSceneTransformRewinding.cs +++ b/osu.Framework.Tests/Visual/Drawables/TestSceneTransformRewinding.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework.Tests/Visual/Drawables/TestSceneTransformSequence.cs b/osu.Framework.Tests/Visual/Drawables/TestSceneTransformSequence.cs index 79e77ea27..af06eca17 100644 --- a/osu.Framework.Tests/Visual/Drawables/TestSceneTransformSequence.cs +++ b/osu.Framework.Tests/Visual/Drawables/TestSceneTransformSequence.cs @@ -1,6 +1,10 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + +using System; +using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Effects; @@ -65,6 +69,20 @@ namespace osu.Framework.Tests.Visual.Drawables AddAssert("finalize triggered", () => finalizeTriggered); } + [Test] + public void TestValidation() + { + AddStep("Animate", () => + { + setup(); + animate(); + }); + + AddStep("nan width", () => Assert.Throws(() => boxes[0].ResizeWidthTo(float.NaN))); + AddStep("nan width sequence", () => Assert.Throws(() => boxes[0].FadeIn(200).ResizeWidthTo(float.NaN))); + AddStep("zero child size", () => Assert.Throws(() => boxes[0].TransformRelativeChildSizeTo(Vector2.Zero))); + } + private void setup() { finalizeTriggered = false; diff --git a/osu.Framework.Tests/Visual/Drawables/TestSceneUpdateBeforeDraw.cs b/osu.Framework.Tests/Visual/Drawables/TestSceneUpdateBeforeDraw.cs index 45ba533ee..c77f8bfe5 100644 --- a/osu.Framework.Tests/Visual/Drawables/TestSceneUpdateBeforeDraw.cs +++ b/osu.Framework.Tests/Visual/Drawables/TestSceneUpdateBeforeDraw.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using NUnit.Framework; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Visual/Drawables/TestSceneWaveform.cs b/osu.Framework.Tests/Visual/Drawables/TestSceneWaveform.cs index c5943fc24..2e4ec1eb3 100644 --- a/osu.Framework.Tests/Visual/Drawables/TestSceneWaveform.cs +++ b/osu.Framework.Tests/Visual/Drawables/TestSceneWaveform.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Audio; diff --git a/osu.Framework.Tests/Visual/FrameworkGridTestScene.cs b/osu.Framework.Tests/Visual/FrameworkGridTestScene.cs index 9d29c7512..5b87824f4 100644 --- a/osu.Framework.Tests/Visual/FrameworkGridTestScene.cs +++ b/osu.Framework.Tests/Visual/FrameworkGridTestScene.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Testing; namespace osu.Framework.Tests.Visual diff --git a/osu.Framework.Tests/Visual/FrameworkTestScene.cs b/osu.Framework.Tests/Visual/FrameworkTestScene.cs index c277a2f2d..c26b485bc 100644 --- a/osu.Framework.Tests/Visual/FrameworkTestScene.cs +++ b/osu.Framework.Tests/Visual/FrameworkTestScene.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Testing; namespace osu.Framework.Tests.Visual diff --git a/osu.Framework.Tests/Visual/FrameworkTestSceneTestRunner.cs b/osu.Framework.Tests/Visual/FrameworkTestSceneTestRunner.cs index 4c0499ee7..3b579126b 100644 --- a/osu.Framework.Tests/Visual/FrameworkTestSceneTestRunner.cs +++ b/osu.Framework.Tests/Visual/FrameworkTestSceneTestRunner.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Allocation; using osu.Framework.IO.Stores; using osu.Framework.Testing; diff --git a/osu.Framework.Tests/Visual/Input/TestSceneClickLenience.cs b/osu.Framework.Tests/Visual/Input/TestSceneClickLenience.cs index 4463408f7..a865c831c 100644 --- a/osu.Framework.Tests/Visual/Input/TestSceneClickLenience.cs +++ b/osu.Framework.Tests/Visual/Input/TestSceneClickLenience.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework.Tests/Visual/Input/TestSceneHandleInput.cs b/osu.Framework.Tests/Visual/Input/TestSceneHandleInput.cs index 03a472780..3116b6627 100644 --- a/osu.Framework.Tests/Visual/Input/TestSceneHandleInput.cs +++ b/osu.Framework.Tests/Visual/Input/TestSceneHandleInput.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework.Tests/Visual/Input/TestSceneInputManager.cs b/osu.Framework.Tests/Visual/Input/TestSceneInputManager.cs index c65dfc5e0..d1b1db764 100644 --- a/osu.Framework.Tests/Visual/Input/TestSceneInputManager.cs +++ b/osu.Framework.Tests/Visual/Input/TestSceneInputManager.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Linq; using osu.Framework.Allocation; using osu.Framework.Configuration; @@ -184,12 +186,14 @@ namespace osu.Framework.Tests.Visual.Input AddSliderStep("Cursor sensitivity", 0.5, 5, 1, setCursorSensitivityConfig); setCursorSensitivityConfig(1); AddToggleStep("Toggle relative mode", setRelativeMode); - AddToggleStep("Toggle ConfineMouseMode", setConfineMouseModeConfig); + AddStep("Set confine to Never", () => setConfineMouseModeConfig(ConfineMouseMode.Never)); + AddStep("Set confine to Fullscreen", () => setConfineMouseModeConfig(ConfineMouseMode.Fullscreen)); + AddStep("Set confine to Always", () => setConfineMouseModeConfig(ConfineMouseMode.Always)); AddToggleStep("Toggle cursor visibility", setCursorVisibility); AddToggleStep("Toggle cursor confine rect", setCursorConfineRect); setRelativeMode(false); - setConfineMouseModeConfig(false); + setConfineMouseModeConfig(ConfineMouseMode.Never); setCursorConfineRect(false); AddStep("Reset handlers", () => host.ResetInputHandlers()); @@ -231,9 +235,9 @@ namespace osu.Framework.Tests.Visual.Input host.Window.CursorState |= CursorState.Hidden; } - private void setConfineMouseModeConfig(bool enabled) + private void setConfineMouseModeConfig(ConfineMouseMode mode) { - config.SetValue(FrameworkSetting.ConfineMouseMode, enabled ? ConfineMouseMode.Always : ConfineMouseMode.Fullscreen); + config.SetValue(FrameworkSetting.ConfineMouseMode, mode); } private void setCursorConfineRect(bool enabled) @@ -249,7 +253,7 @@ namespace osu.Framework.Tests.Visual.Input Width = host.Window.ClientSize.Width * 2 / 3f, Height = host.Window.ClientSize.Height * 2 / 3f, } - : (RectangleF?)null; + : null; } } } diff --git a/osu.Framework.Tests/Visual/Input/TestSceneInputPropagationForLoadStates.cs b/osu.Framework.Tests/Visual/Input/TestSceneInputPropagationForLoadStates.cs index 13e680ba9..181026676 100644 --- a/osu.Framework.Tests/Visual/Input/TestSceneInputPropagationForLoadStates.cs +++ b/osu.Framework.Tests/Visual/Input/TestSceneInputPropagationForLoadStates.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Input.Events; diff --git a/osu.Framework.Tests/Visual/Input/TestSceneInputQueueChange.cs b/osu.Framework.Tests/Visual/Input/TestSceneInputQueueChange.cs index 682e7ccf9..dfb1c4276 100644 --- a/osu.Framework.Tests/Visual/Input/TestSceneInputQueueChange.cs +++ b/osu.Framework.Tests/Visual/Input/TestSceneInputQueueChange.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Linq; using NUnit.Framework; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Visual/Input/TestSceneInputResampler.cs b/osu.Framework.Tests/Visual/Input/TestSceneInputResampler.cs index 16a4822bc..ae270ad0e 100644 --- a/osu.Framework.Tests/Visual/Input/TestSceneInputResampler.cs +++ b/osu.Framework.Tests/Visual/Input/TestSceneInputResampler.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Graphics; using osu.Framework.Graphics.Lines; diff --git a/osu.Framework.Tests/Visual/Input/TestSceneJoystick.cs b/osu.Framework.Tests/Visual/Input/TestSceneJoystick.cs index 94eba9ded..606bf80f1 100644 --- a/osu.Framework.Tests/Visual/Input/TestSceneJoystick.cs +++ b/osu.Framework.Tests/Visual/Input/TestSceneJoystick.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework.Tests/Visual/Input/TestSceneKeyBindingContainer.cs b/osu.Framework.Tests/Visual/Input/TestSceneKeyBindingContainer.cs index 8f234729d..3ed25fe04 100644 --- a/osu.Framework.Tests/Visual/Input/TestSceneKeyBindingContainer.cs +++ b/osu.Framework.Tests/Visual/Input/TestSceneKeyBindingContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using NUnit.Framework; diff --git a/osu.Framework.Tests/Visual/Input/TestSceneKeyBindingInputQueueChange.cs b/osu.Framework.Tests/Visual/Input/TestSceneKeyBindingInputQueueChange.cs index 0851b4370..c2955cd5e 100644 --- a/osu.Framework.Tests/Visual/Input/TestSceneKeyBindingInputQueueChange.cs +++ b/osu.Framework.Tests/Visual/Input/TestSceneKeyBindingInputQueueChange.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using NUnit.Framework; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Visual/Input/TestSceneKeyBindingsGrid.cs b/osu.Framework.Tests/Visual/Input/TestSceneKeyBindingsGrid.cs index 86ee6f813..e9a5eb872 100644 --- a/osu.Framework.Tests/Visual/Input/TestSceneKeyBindingsGrid.cs +++ b/osu.Framework.Tests/Visual/Input/TestSceneKeyBindingsGrid.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Diagnostics; @@ -281,9 +283,9 @@ namespace osu.Framework.Tests.Visual.Input scrollMouseWheel(0, -1); check(TestAction.WheelDown, allPressAndReleased); - scrollMouseWheel(-1, 0); - check(TestAction.WheelLeft, allPressAndReleased); scrollMouseWheel(1, 0); + check(TestAction.WheelLeft, allPressAndReleased); + scrollMouseWheel(-1, 0); check(TestAction.WheelRight, allPressAndReleased); toggleKey(Key.ControlLeft); diff --git a/osu.Framework.Tests/Visual/Input/TestSceneMidi.cs b/osu.Framework.Tests/Visual/Input/TestSceneMidi.cs index 0a31ad3c3..0e75b85d9 100644 --- a/osu.Framework.Tests/Visual/Input/TestSceneMidi.cs +++ b/osu.Framework.Tests/Visual/Input/TestSceneMidi.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Linq; using osu.Framework.Allocation; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Visual/Input/TestSceneMouseStates.cs b/osu.Framework.Tests/Visual/Input/TestSceneMouseStates.cs index abac5dd7d..8d4b0a95d 100644 --- a/osu.Framework.Tests/Visual/Input/TestSceneMouseStates.cs +++ b/osu.Framework.Tests/Visual/Input/TestSceneMouseStates.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework.Tests/Visual/Input/TestSceneNestedHover.cs b/osu.Framework.Tests/Visual/Input/TestSceneNestedHover.cs index 6cfab935e..ec6685dab 100644 --- a/osu.Framework.Tests/Visual/Input/TestSceneNestedHover.cs +++ b/osu.Framework.Tests/Visual/Input/TestSceneNestedHover.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; diff --git a/osu.Framework.Tests/Visual/Input/TestScenePassThroughInputManager.cs b/osu.Framework.Tests/Visual/Input/TestScenePassThroughInputManager.cs index bcc3c0222..6d2ff089b 100644 --- a/osu.Framework.Tests/Visual/Input/TestScenePassThroughInputManager.cs +++ b/osu.Framework.Tests/Visual/Input/TestScenePassThroughInputManager.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Linq; using NUnit.Framework; diff --git a/osu.Framework.Tests/Visual/Input/TestScenePathInput.cs b/osu.Framework.Tests/Visual/Input/TestScenePathInput.cs index 3ee4b9ea8..b3e10d786 100644 --- a/osu.Framework.Tests/Visual/Input/TestScenePathInput.cs +++ b/osu.Framework.Tests/Visual/Input/TestScenePathInput.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Linq; using NUnit.Framework; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Visual/Input/TestScenePlatformActionContainer.cs b/osu.Framework.Tests/Visual/Input/TestScenePlatformActionContainer.cs index 372014694..422c591e9 100644 --- a/osu.Framework.Tests/Visual/Input/TestScenePlatformActionContainer.cs +++ b/osu.Framework.Tests/Visual/Input/TestScenePlatformActionContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Linq; using osu.Framework.Allocation; diff --git a/osu.Framework.Tests/Visual/Input/TestSceneReadableKeyCombinationProvider.cs b/osu.Framework.Tests/Visual/Input/TestSceneReadableKeyCombinationProvider.cs index 66ee9a06a..124f1f08d 100644 --- a/osu.Framework.Tests/Visual/Input/TestSceneReadableKeyCombinationProvider.cs +++ b/osu.Framework.Tests/Visual/Input/TestSceneReadableKeyCombinationProvider.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework.Tests/Visual/Input/TestSceneTabletInput.cs b/osu.Framework.Tests/Visual/Input/TestSceneTabletInput.cs index 5d5158b57..d00b33a6a 100644 --- a/osu.Framework.Tests/Visual/Input/TestSceneTabletInput.cs +++ b/osu.Framework.Tests/Visual/Input/TestSceneTabletInput.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + #if NET6_0_OR_GREATER using System.Linq; using osu.Framework.Allocation; diff --git a/osu.Framework.Tests/Visual/Input/TestSceneTouchInput.cs b/osu.Framework.Tests/Visual/Input/TestSceneTouchInput.cs index 88cddb896..73db4192b 100644 --- a/osu.Framework.Tests/Visual/Input/TestSceneTouchInput.cs +++ b/osu.Framework.Tests/Visual/Input/TestSceneTouchInput.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; @@ -463,10 +465,10 @@ namespace osu.Framework.Tests.Visual.Input break; - case MouseDownEvent _: - case MouseMoveEvent _: - case DragEvent _: - case MouseUpEvent _: + case MouseDownEvent: + case MouseMoveEvent: + case DragEvent: + case MouseUpEvent: if (HandleMouse?.Invoke((MouseEvent)e) != false) { MouseEvents.Enqueue((MouseEvent)e); diff --git a/osu.Framework.Tests/Visual/Input/TestSceneTouchVisualiser.cs b/osu.Framework.Tests/Visual/Input/TestSceneTouchVisualiser.cs index f55b8d084..7d2879934 100644 --- a/osu.Framework.Tests/Visual/Input/TestSceneTouchVisualiser.cs +++ b/osu.Framework.Tests/Visual/Input/TestSceneTouchVisualiser.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; diff --git a/osu.Framework.Tests/Visual/Layout/TestSceneFillFlowContainer.cs b/osu.Framework.Tests/Visual/Layout/TestSceneFillFlowContainer.cs index c6c9a2abc..cddc8e57d 100644 --- a/osu.Framework.Tests/Visual/Layout/TestSceneFillFlowContainer.cs +++ b/osu.Framework.Tests/Visual/Layout/TestSceneFillFlowContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Linq; using System.Reflection; diff --git a/osu.Framework.Tests/Visual/Layout/TestSceneFitInsideFlow.cs b/osu.Framework.Tests/Visual/Layout/TestSceneFitInsideFlow.cs index 4c16b8ec7..54d40a91c 100644 --- a/osu.Framework.Tests/Visual/Layout/TestSceneFitInsideFlow.cs +++ b/osu.Framework.Tests/Visual/Layout/TestSceneFitInsideFlow.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework.Tests/Visual/Layout/TestSceneGridContainer.cs b/osu.Framework.Tests/Visual/Layout/TestSceneGridContainer.cs index e2a89bc4a..4396b4d77 100644 --- a/osu.Framework.Tests/Visual/Layout/TestSceneGridContainer.cs +++ b/osu.Framework.Tests/Visual/Layout/TestSceneGridContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Linq; using NUnit.Framework; diff --git a/osu.Framework.Tests/Visual/Layout/TestSceneLayoutDurations.cs b/osu.Framework.Tests/Visual/Layout/TestSceneLayoutDurations.cs index 94466c7e4..7406a7ab4 100644 --- a/osu.Framework.Tests/Visual/Layout/TestSceneLayoutDurations.cs +++ b/osu.Framework.Tests/Visual/Layout/TestSceneLayoutDurations.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework.Tests/Visual/Layout/TestSceneLayoutTransformRewinding.cs b/osu.Framework.Tests/Visual/Layout/TestSceneLayoutTransformRewinding.cs index 4ecec93c7..b8d582aef 100644 --- a/osu.Framework.Tests/Visual/Layout/TestSceneLayoutTransformRewinding.cs +++ b/osu.Framework.Tests/Visual/Layout/TestSceneLayoutTransformRewinding.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework.Tests/Visual/Layout/TestSceneScrollableFlow.cs b/osu.Framework.Tests/Visual/Layout/TestSceneScrollableFlow.cs index 8e07e4336..741464290 100644 --- a/osu.Framework.Tests/Visual/Layout/TestSceneScrollableFlow.cs +++ b/osu.Framework.Tests/Visual/Layout/TestSceneScrollableFlow.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; diff --git a/osu.Framework.Tests/Visual/Layout/TestSceneTableContainer.cs b/osu.Framework.Tests/Visual/Layout/TestSceneTableContainer.cs index f56b7282b..cb563d742 100644 --- a/osu.Framework.Tests/Visual/Layout/TestSceneTableContainer.cs +++ b/osu.Framework.Tests/Visual/Layout/TestSceneTableContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Linq; using NUnit.Framework; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Visual/Localisation/TestSceneTextFlowContainerLocalisation.cs b/osu.Framework.Tests/Visual/Localisation/TestSceneTextFlowContainerLocalisation.cs index db0abf36f..977d16827 100644 --- a/osu.Framework.Tests/Visual/Localisation/TestSceneTextFlowContainerLocalisation.cs +++ b/osu.Framework.Tests/Visual/Localisation/TestSceneTextFlowContainerLocalisation.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Globalization; diff --git a/osu.Framework.Tests/Visual/Platform/TestSceneActiveState.cs b/osu.Framework.Tests/Visual/Platform/TestSceneActiveState.cs index f3eda4e27..2759e275e 100644 --- a/osu.Framework.Tests/Visual/Platform/TestSceneActiveState.cs +++ b/osu.Framework.Tests/Visual/Platform/TestSceneActiveState.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Visual/Platform/TestSceneAllowSuspension.cs b/osu.Framework.Tests/Visual/Platform/TestSceneAllowSuspension.cs index 9116e0cac..25cab7ebe 100644 --- a/osu.Framework.Tests/Visual/Platform/TestSceneAllowSuspension.cs +++ b/osu.Framework.Tests/Visual/Platform/TestSceneAllowSuspension.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Bindables; diff --git a/osu.Framework.Tests/Visual/Platform/TestSceneBlockExiting.cs b/osu.Framework.Tests/Visual/Platform/TestSceneBlockExiting.cs index 08730e00d..40f502c37 100644 --- a/osu.Framework.Tests/Visual/Platform/TestSceneBlockExiting.cs +++ b/osu.Framework.Tests/Visual/Platform/TestSceneBlockExiting.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Bindables; diff --git a/osu.Framework.Tests/Visual/Platform/TestSceneBorderless.cs b/osu.Framework.Tests/Visual/Platform/TestSceneBorderless.cs index 51d95d96e..eef9e0b84 100644 --- a/osu.Framework.Tests/Visual/Platform/TestSceneBorderless.cs +++ b/osu.Framework.Tests/Visual/Platform/TestSceneBorderless.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Drawing; using System.Linq; diff --git a/osu.Framework.Tests/Visual/Platform/TestSceneClipboard.cs b/osu.Framework.Tests/Visual/Platform/TestSceneClipboard.cs index 4fa1bce62..761bfd704 100644 --- a/osu.Framework.Tests/Visual/Platform/TestSceneClipboard.cs +++ b/osu.Framework.Tests/Visual/Platform/TestSceneClipboard.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Extensions; diff --git a/osu.Framework.Tests/Visual/Platform/TestSceneDisplayMode.cs b/osu.Framework.Tests/Visual/Platform/TestSceneDisplayMode.cs index 78bfab4ff..57ee4b709 100644 --- a/osu.Framework.Tests/Visual/Platform/TestSceneDisplayMode.cs +++ b/osu.Framework.Tests/Visual/Platform/TestSceneDisplayMode.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Drawing; using System.Linq; using NUnit.Framework; diff --git a/osu.Framework.Tests/Visual/Platform/TestSceneExecutionModes.cs b/osu.Framework.Tests/Visual/Platform/TestSceneExecutionModes.cs index fb741144d..e55355eed 100644 --- a/osu.Framework.Tests/Visual/Platform/TestSceneExecutionModes.cs +++ b/osu.Framework.Tests/Visual/Platform/TestSceneExecutionModes.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Bindables; diff --git a/osu.Framework.Tests/Visual/Platform/TestSceneExternalLinks.cs b/osu.Framework.Tests/Visual/Platform/TestSceneExternalLinks.cs index 4706a8160..c46d71c1f 100644 --- a/osu.Framework.Tests/Visual/Platform/TestSceneExternalLinks.cs +++ b/osu.Framework.Tests/Visual/Platform/TestSceneExternalLinks.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework.Tests/Visual/Platform/TestSceneFullscreen.cs b/osu.Framework.Tests/Visual/Platform/TestSceneFullscreen.cs index 591f79db4..6ef350a63 100644 --- a/osu.Framework.Tests/Visual/Platform/TestSceneFullscreen.cs +++ b/osu.Framework.Tests/Visual/Platform/TestSceneFullscreen.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Drawing; using System.Linq; using NUnit.Framework; diff --git a/osu.Framework.Tests/Visual/Platform/TestScenePresentFileExternally.cs b/osu.Framework.Tests/Visual/Platform/TestScenePresentFileExternally.cs index 07c004dc7..c341dcdda 100644 --- a/osu.Framework.Tests/Visual/Platform/TestScenePresentFileExternally.cs +++ b/osu.Framework.Tests/Visual/Platform/TestScenePresentFileExternally.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Allocation; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Visual/Platform/TestSceneResourceStores.cs b/osu.Framework.Tests/Visual/Platform/TestSceneResourceStores.cs index 80f68f29b..080754d75 100644 --- a/osu.Framework.Tests/Visual/Platform/TestSceneResourceStores.cs +++ b/osu.Framework.Tests/Visual/Platform/TestSceneResourceStores.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework.Tests/Visual/Platform/TestSceneWindowed.cs b/osu.Framework.Tests/Visual/Platform/TestSceneWindowed.cs index 95b5f226e..cb4e86009 100644 --- a/osu.Framework.Tests/Visual/Platform/TestSceneWindowed.cs +++ b/osu.Framework.Tests/Visual/Platform/TestSceneWindowed.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Drawing; using NUnit.Framework; diff --git a/osu.Framework.Tests/Visual/Sprites/TestSceneAnimation.cs b/osu.Framework.Tests/Visual/Sprites/TestSceneAnimation.cs index 3bdaf1761..b5c0d8dc0 100644 --- a/osu.Framework.Tests/Visual/Sprites/TestSceneAnimation.cs +++ b/osu.Framework.Tests/Visual/Sprites/TestSceneAnimation.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Linq; using NUnit.Framework; diff --git a/osu.Framework.Tests/Visual/Sprites/TestSceneAnimationLayout.cs b/osu.Framework.Tests/Visual/Sprites/TestSceneAnimationLayout.cs index df8611866..8a07800f0 100644 --- a/osu.Framework.Tests/Visual/Sprites/TestSceneAnimationLayout.cs +++ b/osu.Framework.Tests/Visual/Sprites/TestSceneAnimationLayout.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Allocation; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Visual/Sprites/TestSceneBufferedContainerView.cs b/osu.Framework.Tests/Visual/Sprites/TestSceneBufferedContainerView.cs index d8431a607..23974a59c 100644 --- a/osu.Framework.Tests/Visual/Sprites/TestSceneBufferedContainerView.cs +++ b/osu.Framework.Tests/Visual/Sprites/TestSceneBufferedContainerView.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework.Tests/Visual/Sprites/TestSceneRomanisableSpriteText.cs b/osu.Framework.Tests/Visual/Sprites/TestSceneRomanisableSpriteText.cs index 5deb069be..9d92424cf 100644 --- a/osu.Framework.Tests/Visual/Sprites/TestSceneRomanisableSpriteText.cs +++ b/osu.Framework.Tests/Visual/Sprites/TestSceneRomanisableSpriteText.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Linq; using NUnit.Framework; using osu.Framework.Allocation; diff --git a/osu.Framework.Tests/Visual/Sprites/TestSceneScreenshot.cs b/osu.Framework.Tests/Visual/Sprites/TestSceneScreenshot.cs index 832754f19..6c755a1ac 100644 --- a/osu.Framework.Tests/Visual/Sprites/TestSceneScreenshot.cs +++ b/osu.Framework.Tests/Visual/Sprites/TestSceneScreenshot.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Allocation; using osu.Framework.Extensions; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Visual/Sprites/TestSceneSmoothedEdges.cs b/osu.Framework.Tests/Visual/Sprites/TestSceneSmoothedEdges.cs index 262c6b6e5..59f94e176 100644 --- a/osu.Framework.Tests/Visual/Sprites/TestSceneSmoothedEdges.cs +++ b/osu.Framework.Tests/Visual/Sprites/TestSceneSmoothedEdges.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics; using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Sprites; diff --git a/osu.Framework.Tests/Visual/Sprites/TestSceneSpriteIcon.cs b/osu.Framework.Tests/Visual/Sprites/TestSceneSpriteIcon.cs index 3ee68ace5..962d161c6 100644 --- a/osu.Framework.Tests/Visual/Sprites/TestSceneSpriteIcon.cs +++ b/osu.Framework.Tests/Visual/Sprites/TestSceneSpriteIcon.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Diagnostics; using System.Linq; using System.Reflection; diff --git a/osu.Framework.Tests/Visual/Sprites/TestSceneSpriteText.cs b/osu.Framework.Tests/Visual/Sprites/TestSceneSpriteText.cs index 3889ec286..dd8bff61d 100644 --- a/osu.Framework.Tests/Visual/Sprites/TestSceneSpriteText.cs +++ b/osu.Framework.Tests/Visual/Sprites/TestSceneSpriteText.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; diff --git a/osu.Framework.Tests/Visual/Sprites/TestSceneSpriteTextMaxWidth.cs b/osu.Framework.Tests/Visual/Sprites/TestSceneSpriteTextMaxWidth.cs index 920d3358b..0eb0d534a 100644 --- a/osu.Framework.Tests/Visual/Sprites/TestSceneSpriteTextMaxWidth.cs +++ b/osu.Framework.Tests/Visual/Sprites/TestSceneSpriteTextMaxWidth.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using NUnit.Framework; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Visual/Sprites/TestSceneSpriteTextScenarios.cs b/osu.Framework.Tests/Visual/Sprites/TestSceneSpriteTextScenarios.cs index d882b13cd..b79d98cb4 100644 --- a/osu.Framework.Tests/Visual/Sprites/TestSceneSpriteTextScenarios.cs +++ b/osu.Framework.Tests/Visual/Sprites/TestSceneSpriteTextScenarios.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Globalization; diff --git a/osu.Framework.Tests/Visual/Sprites/TestSceneSpriteTextTruncate.cs b/osu.Framework.Tests/Visual/Sprites/TestSceneSpriteTextTruncate.cs index 6637de74f..70df8cdee 100644 --- a/osu.Framework.Tests/Visual/Sprites/TestSceneSpriteTextTruncate.cs +++ b/osu.Framework.Tests/Visual/Sprites/TestSceneSpriteTextTruncate.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; diff --git a/osu.Framework.Tests/Visual/Sprites/TestSceneTextFlow.cs b/osu.Framework.Tests/Visual/Sprites/TestSceneTextFlow.cs index 25bda94c9..46395b8f7 100644 --- a/osu.Framework.Tests/Visual/Sprites/TestSceneTextFlow.cs +++ b/osu.Framework.Tests/Visual/Sprites/TestSceneTextFlow.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Linq; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework.Tests/Visual/Sprites/TestSceneTextureCropping.cs b/osu.Framework.Tests/Visual/Sprites/TestSceneTextureCropping.cs index de3811fea..54089712b 100644 --- a/osu.Framework.Tests/Visual/Sprites/TestSceneTextureCropping.cs +++ b/osu.Framework.Tests/Visual/Sprites/TestSceneTextureCropping.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework.Tests/Visual/Sprites/TestSceneTextureUnit.cs b/osu.Framework.Tests/Visual/Sprites/TestSceneTextureUnit.cs index 01300aa2e..380e37164 100644 --- a/osu.Framework.Tests/Visual/Sprites/TestSceneTextureUnit.cs +++ b/osu.Framework.Tests/Visual/Sprites/TestSceneTextureUnit.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Allocation; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Visual/Sprites/TestSceneTexturedTriangle.cs b/osu.Framework.Tests/Visual/Sprites/TestSceneTexturedTriangle.cs index bbe7c4b96..d22c85690 100644 --- a/osu.Framework.Tests/Visual/Sprites/TestSceneTexturedTriangle.cs +++ b/osu.Framework.Tests/Visual/Sprites/TestSceneTexturedTriangle.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Allocation; using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Visual/Sprites/TestSceneTextures.cs b/osu.Framework.Tests/Visual/Sprites/TestSceneTextures.cs index 3815cfa9c..40bd5e8ab 100644 --- a/osu.Framework.Tests/Visual/Sprites/TestSceneTextures.cs +++ b/osu.Framework.Tests/Visual/Sprites/TestSceneTextures.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.IO; @@ -221,10 +223,13 @@ namespace osu.Framework.Tests.Visual.Sprites TotalInitiatedLookups++; if (blocking && name == blockingName) - resetEvent.Wait(); + { + if (!resetEvent.Wait(10000)) + throw new TimeoutException("Load was not allowed in a timely fashion."); + } TotalCompletedLookups++; - return getFunc("sample-texture"); + return getFunc("sample-texture.png"); } public void Reset() diff --git a/osu.Framework.Tests/Visual/Sprites/TestSceneTriangles.cs b/osu.Framework.Tests/Visual/Sprites/TestSceneTriangles.cs index 4e21988e9..2731b03ba 100644 --- a/osu.Framework.Tests/Visual/Sprites/TestSceneTriangles.cs +++ b/osu.Framework.Tests/Visual/Sprites/TestSceneTriangles.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; diff --git a/osu.Framework.Tests/Visual/Sprites/TestSceneVideo.cs b/osu.Framework.Tests/Visual/Sprites/TestSceneVideo.cs index 5aa88f676..30e5f80dc 100644 --- a/osu.Framework.Tests/Visual/Sprites/TestSceneVideo.cs +++ b/osu.Framework.Tests/Visual/Sprites/TestSceneVideo.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Configuration; @@ -103,7 +105,6 @@ namespace osu.Framework.Tests.Visual.Sprites AddStep("make video hidden", () => video.Hide()); AddWaitStep("wait a bit", 10); - AddUntilStep("decoding stopped", () => video.State == VideoDecoder.DecoderState.Ready); AddStep("reset decode state", () => didDecode = false); @@ -125,6 +126,7 @@ namespace osu.Framework.Tests.Visual.Sprites AddStep("Jump back to before start time", () => clock.CurrentTime = -30000); + AddWaitStep("wait a bit", 10); AddUntilStep("decoding stopped", () => video.State == VideoDecoder.DecoderState.Ready); AddStep("reset decode state", () => didDecode = false); diff --git a/osu.Framework.Tests/Visual/Sprites/TestSceneVideoLayout.cs b/osu.Framework.Tests/Visual/Sprites/TestSceneVideoLayout.cs index 309253cc1..18ef00f58 100644 --- a/osu.Framework.Tests/Visual/Sprites/TestSceneVideoLayout.cs +++ b/osu.Framework.Tests/Visual/Sprites/TestSceneVideoLayout.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Allocation; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Visual/Sprites/TestSceneWrapModes.cs b/osu.Framework.Tests/Visual/Sprites/TestSceneWrapModes.cs index 5653ac875..ae9a66646 100644 --- a/osu.Framework.Tests/Visual/Sprites/TestSceneWrapModes.cs +++ b/osu.Framework.Tests/Visual/Sprites/TestSceneWrapModes.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.IO; using NUnit.Framework; diff --git a/osu.Framework.Tests/Visual/Sprites/TestVideo.cs b/osu.Framework.Tests/Visual/Sprites/TestVideo.cs index 12236bab9..4c7082791 100644 --- a/osu.Framework.Tests/Visual/Sprites/TestVideo.cs +++ b/osu.Framework.Tests/Visual/Sprites/TestVideo.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.IO; using osu.Framework.Graphics; using osu.Framework.Graphics.Video; diff --git a/osu.Framework.Tests/Visual/Testing/TestSceneAudioMixerVisualiser.cs b/osu.Framework.Tests/Visual/Testing/TestSceneAudioMixerVisualiser.cs index db68c099e..edf58d678 100644 --- a/osu.Framework.Tests/Visual/Testing/TestSceneAudioMixerVisualiser.cs +++ b/osu.Framework.Tests/Visual/Testing/TestSceneAudioMixerVisualiser.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Allocation; using osu.Framework.Audio.Sample; using osu.Framework.Audio.Track; diff --git a/osu.Framework.Tests/Visual/Testing/TestSceneDerivedTestWithDerivedMethods.cs b/osu.Framework.Tests/Visual/Testing/TestSceneDerivedTestWithDerivedMethods.cs index 1dd4c77bc..88e4326d4 100644 --- a/osu.Framework.Tests/Visual/Testing/TestSceneDerivedTestWithDerivedMethods.cs +++ b/osu.Framework.Tests/Visual/Testing/TestSceneDerivedTestWithDerivedMethods.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Tests.Visual.Testing { public class TestSceneDerivedTestWithDerivedMethods : TestSceneTest diff --git a/osu.Framework.Tests/Visual/Testing/TestSceneDerivedTestWithDerivedMethodsWithAttributes.cs b/osu.Framework.Tests/Visual/Testing/TestSceneDerivedTestWithDerivedMethodsWithAttributes.cs index 933f6519b..69cc5f8da 100644 --- a/osu.Framework.Tests/Visual/Testing/TestSceneDerivedTestWithDerivedMethodsWithAttributes.cs +++ b/osu.Framework.Tests/Visual/Testing/TestSceneDerivedTestWithDerivedMethodsWithAttributes.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Testing; diff --git a/osu.Framework.Tests/Visual/Testing/TestSceneDerivedTestWithDerivedSource.cs b/osu.Framework.Tests/Visual/Testing/TestSceneDerivedTestWithDerivedSource.cs index c0db40648..9cf5e1781 100644 --- a/osu.Framework.Tests/Visual/Testing/TestSceneDerivedTestWithDerivedSource.cs +++ b/osu.Framework.Tests/Visual/Testing/TestSceneDerivedTestWithDerivedSource.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; namespace osu.Framework.Tests.Visual.Testing diff --git a/osu.Framework.Tests/Visual/Testing/TestSceneDrawVisualiser.cs b/osu.Framework.Tests/Visual/Testing/TestSceneDrawVisualiser.cs index 76e3f869e..6b3bccc31 100644 --- a/osu.Framework.Tests/Visual/Testing/TestSceneDrawVisualiser.cs +++ b/osu.Framework.Tests/Visual/Testing/TestSceneDrawVisualiser.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Visualisation; diff --git a/osu.Framework.Tests/Visual/Testing/TestSceneGlobalStatisticsDisplay.cs b/osu.Framework.Tests/Visual/Testing/TestSceneGlobalStatisticsDisplay.cs index 30f7b9d1a..b1b8fa503 100644 --- a/osu.Framework.Tests/Visual/Testing/TestSceneGlobalStatisticsDisplay.cs +++ b/osu.Framework.Tests/Visual/Testing/TestSceneGlobalStatisticsDisplay.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework.Tests/Visual/Testing/TestSceneIgnore.cs b/osu.Framework.Tests/Visual/Testing/TestSceneIgnore.cs index 2da3100af..73fc7c7b7 100644 --- a/osu.Framework.Tests/Visual/Testing/TestSceneIgnore.cs +++ b/osu.Framework.Tests/Visual/Testing/TestSceneIgnore.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; namespace osu.Framework.Tests.Visual.Testing diff --git a/osu.Framework.Tests/Visual/Testing/TestSceneManualInputManagerTestScene.cs b/osu.Framework.Tests/Visual/Testing/TestSceneManualInputManagerTestScene.cs index d78477856..3f4bafc40 100644 --- a/osu.Framework.Tests/Visual/Testing/TestSceneManualInputManagerTestScene.cs +++ b/osu.Framework.Tests/Visual/Testing/TestSceneManualInputManagerTestScene.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Linq; using NUnit.Framework; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Visual/Testing/TestSceneNestedGame.cs b/osu.Framework.Tests/Visual/Testing/TestSceneNestedGame.cs index 08a1abf80..d64bcae31 100644 --- a/osu.Framework.Tests/Visual/Testing/TestSceneNestedGame.cs +++ b/osu.Framework.Tests/Visual/Testing/TestSceneNestedGame.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using NUnit.Framework; using osu.Framework.Allocation; diff --git a/osu.Framework.Tests/Visual/Testing/TestSceneStepButton.cs b/osu.Framework.Tests/Visual/Testing/TestSceneStepButton.cs index 5ff9e99d9..439d3226a 100644 --- a/osu.Framework.Tests/Visual/Testing/TestSceneStepButton.cs +++ b/osu.Framework.Tests/Visual/Testing/TestSceneStepButton.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Testing.Drawables.Steps; diff --git a/osu.Framework.Tests/Visual/Testing/TestSceneTest.cs b/osu.Framework.Tests/Visual/Testing/TestSceneTest.cs index bdc2ab40f..8b221316b 100644 --- a/osu.Framework.Tests/Visual/Testing/TestSceneTest.cs +++ b/osu.Framework.Tests/Visual/Testing/TestSceneTest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Linq; using NUnit.Framework; using osu.Framework.Development; diff --git a/osu.Framework.Tests/Visual/Testing/TestSceneTestWithExternalSource.cs b/osu.Framework.Tests/Visual/Testing/TestSceneTestWithExternalSource.cs index 2858e39a8..3403b3dbf 100644 --- a/osu.Framework.Tests/Visual/Testing/TestSceneTestWithExternalSource.cs +++ b/osu.Framework.Tests/Visual/Testing/TestSceneTestWithExternalSource.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; namespace osu.Framework.Tests.Visual.Testing diff --git a/osu.Framework.Tests/Visual/Testing/TestSceneTestWithSource.cs b/osu.Framework.Tests/Visual/Testing/TestSceneTestWithSource.cs index d6f7f4986..d2b158312 100644 --- a/osu.Framework.Tests/Visual/Testing/TestSceneTestWithSource.cs +++ b/osu.Framework.Tests/Visual/Testing/TestSceneTestWithSource.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections; using NUnit.Framework; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework.Tests/Visual/Testing/TestSceneTestWithValues.cs b/osu.Framework.Tests/Visual/Testing/TestSceneTestWithValues.cs index 207710ce2..90f677d0a 100644 --- a/osu.Framework.Tests/Visual/Testing/TestSceneTestWithValues.cs +++ b/osu.Framework.Tests/Visual/Testing/TestSceneTestWithValues.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Tests.Bindables; diff --git a/osu.Framework.Tests/Visual/Testing/TestSceneTestingExtensions.cs b/osu.Framework.Tests/Visual/Testing/TestSceneTestingExtensions.cs index 7fdc72007..c78b4de84 100644 --- a/osu.Framework.Tests/Visual/Testing/TestSceneTestingExtensions.cs +++ b/osu.Framework.Tests/Visual/Testing/TestSceneTestingExtensions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Linq; using NUnit.Framework; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Visual/UserInterface/TestSceneButton.cs b/osu.Framework.Tests/Visual/UserInterface/TestSceneButton.cs index 6605b2347..cc83fa7e7 100644 --- a/osu.Framework.Tests/Visual/UserInterface/TestSceneButton.cs +++ b/osu.Framework.Tests/Visual/UserInterface/TestSceneButton.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.UserInterface; diff --git a/osu.Framework.Tests/Visual/UserInterface/TestSceneCheckboxes.cs b/osu.Framework.Tests/Visual/UserInterface/TestSceneCheckboxes.cs index f676c3c9d..1d2df64f7 100644 --- a/osu.Framework.Tests/Visual/UserInterface/TestSceneCheckboxes.cs +++ b/osu.Framework.Tests/Visual/UserInterface/TestSceneCheckboxes.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Bindables; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Visual/UserInterface/TestSceneCircularProgress.cs b/osu.Framework.Tests/Visual/UserInterface/TestSceneCircularProgress.cs index 2c7fe6ef2..b28aaad5a 100644 --- a/osu.Framework.Tests/Visual/UserInterface/TestSceneCircularProgress.cs +++ b/osu.Framework.Tests/Visual/UserInterface/TestSceneCircularProgress.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics; using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Textures; diff --git a/osu.Framework.Tests/Visual/UserInterface/TestSceneClosableMenu.cs b/osu.Framework.Tests/Visual/UserInterface/TestSceneClosableMenu.cs index 7331408bd..a529ea096 100644 --- a/osu.Framework.Tests/Visual/UserInterface/TestSceneClosableMenu.cs +++ b/osu.Framework.Tests/Visual/UserInterface/TestSceneClosableMenu.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using NUnit.Framework; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Visual/UserInterface/TestSceneColourPicker.cs b/osu.Framework.Tests/Visual/UserInterface/TestSceneColourPicker.cs index fb506a103..35068efef 100644 --- a/osu.Framework.Tests/Visual/UserInterface/TestSceneColourPicker.cs +++ b/osu.Framework.Tests/Visual/UserInterface/TestSceneColourPicker.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Linq; using NUnit.Framework; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Visual/UserInterface/TestSceneContextMenu.cs b/osu.Framework.Tests/Visual/UserInterface/TestSceneContextMenu.cs index 216b7f587..29e56058a 100644 --- a/osu.Framework.Tests/Visual/UserInterface/TestSceneContextMenu.cs +++ b/osu.Framework.Tests/Visual/UserInterface/TestSceneContextMenu.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Linq; using NUnit.Framework; @@ -281,7 +283,8 @@ namespace osu.Framework.Tests.Visual.UserInterface }); } - private void addBoxStep(Action boxFunc, int actionCount) => addBoxStep(boxFunc, Enumerable.Repeat(new Action(() => { }), actionCount).ToArray()); + // ReSharper disable once RedundantTypeArgumentsOfMethod (can be removed with c# language version 10). + private void addBoxStep(Action boxFunc, int actionCount) => addBoxStep(boxFunc, Enumerable.Repeat(() => { }, actionCount).ToArray()); private void addBoxStep(Action boxFunc, params Action[] actions) { diff --git a/osu.Framework.Tests/Visual/UserInterface/TestSceneCountingText.cs b/osu.Framework.Tests/Visual/UserInterface/TestSceneCountingText.cs index aa0e23796..f89b835a6 100644 --- a/osu.Framework.Tests/Visual/UserInterface/TestSceneCountingText.cs +++ b/osu.Framework.Tests/Visual/UserInterface/TestSceneCountingText.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Globalization; using osu.Framework.Bindables; @@ -35,7 +37,7 @@ namespace osu.Framework.Tests.Visual.UserInterface typeDropdown.Items = (CountType[])Enum.GetValues(typeof(CountType)); countType.BindTo(typeDropdown.Current); - countType.ValueChanged += v => beginStep(lastStep)(); + countType.ValueChanged += _ => beginStep(lastStep)(); AddStep("1 -> 4 | 1 sec", beginStep(() => counter.CountTo(1).CountTo(4, 1000))); AddStep("1 -> 4 | 3 sec", beginStep(() => counter.CountTo(1).CountTo(4, 3000))); diff --git a/osu.Framework.Tests/Visual/UserInterface/TestSceneDirectorySelector.cs b/osu.Framework.Tests/Visual/UserInterface/TestSceneDirectorySelector.cs index 6b139e94d..955198dac 100644 --- a/osu.Framework.Tests/Visual/UserInterface/TestSceneDirectorySelector.cs +++ b/osu.Framework.Tests/Visual/UserInterface/TestSceneDirectorySelector.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.UserInterface; diff --git a/osu.Framework.Tests/Visual/UserInterface/TestSceneDrawablePath.cs b/osu.Framework.Tests/Visual/UserInterface/TestSceneDrawablePath.cs index e56329fe2..78beb2031 100644 --- a/osu.Framework.Tests/Visual/UserInterface/TestSceneDrawablePath.cs +++ b/osu.Framework.Tests/Visual/UserInterface/TestSceneDrawablePath.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using NUnit.Framework; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Visual/UserInterface/TestSceneDropdown.cs b/osu.Framework.Tests/Visual/UserInterface/TestSceneDropdown.cs index 5e28878d2..1fea4f263 100644 --- a/osu.Framework.Tests/Visual/UserInterface/TestSceneDropdown.cs +++ b/osu.Framework.Tests/Visual/UserInterface/TestSceneDropdown.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Linq; using NUnit.Framework; diff --git a/osu.Framework.Tests/Visual/UserInterface/TestSceneFileSelector.cs b/osu.Framework.Tests/Visual/UserInterface/TestSceneFileSelector.cs index c00d47613..4eebc406f 100644 --- a/osu.Framework.Tests/Visual/UserInterface/TestSceneFileSelector.cs +++ b/osu.Framework.Tests/Visual/UserInterface/TestSceneFileSelector.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.UserInterface; diff --git a/osu.Framework.Tests/Visual/UserInterface/TestSceneFocusedOverlayContainer.cs b/osu.Framework.Tests/Visual/UserInterface/TestSceneFocusedOverlayContainer.cs index 49e424766..9ecd60570 100644 --- a/osu.Framework.Tests/Visual/UserInterface/TestSceneFocusedOverlayContainer.cs +++ b/osu.Framework.Tests/Visual/UserInterface/TestSceneFocusedOverlayContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -121,7 +123,7 @@ namespace osu.Framework.Tests.Visual.UserInterface }, }; - State.ValueChanged += e => FireCount++; + State.ValueChanged += _ => FireCount++; } public int FireCount { get; private set; } @@ -136,13 +138,7 @@ namespace osu.Framework.Tests.Visual.UserInterface return true; } - return true; - } - - protected override bool OnMouseDown(MouseDownEvent e) - { - base.OnMouseDown(e); - return true; + return false; } protected override void PopIn() diff --git a/osu.Framework.Tests/Visual/UserInterface/TestSceneHSVColourPicker.cs b/osu.Framework.Tests/Visual/UserInterface/TestSceneHSVColourPicker.cs index f0c26dc71..3b24e25c3 100644 --- a/osu.Framework.Tests/Visual/UserInterface/TestSceneHSVColourPicker.cs +++ b/osu.Framework.Tests/Visual/UserInterface/TestSceneHSVColourPicker.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Linq; using NUnit.Framework; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Visual/UserInterface/TestSceneHexColourPicker.cs b/osu.Framework.Tests/Visual/UserInterface/TestSceneHexColourPicker.cs index 47c6f4f41..b989ffeeb 100644 --- a/osu.Framework.Tests/Visual/UserInterface/TestSceneHexColourPicker.cs +++ b/osu.Framework.Tests/Visual/UserInterface/TestSceneHexColourPicker.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Linq; using NUnit.Framework; using osu.Framework.Graphics; diff --git a/osu.Framework.Tests/Visual/UserInterface/TestSceneMarkdownContainer.cs b/osu.Framework.Tests/Visual/UserInterface/TestSceneMarkdownContainer.cs index c1799c302..64d3828c1 100644 --- a/osu.Framework.Tests/Visual/UserInterface/TestSceneMarkdownContainer.cs +++ b/osu.Framework.Tests/Visual/UserInterface/TestSceneMarkdownContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Threading.Tasks; diff --git a/osu.Framework.Tests/Visual/UserInterface/TestSceneNestedMenus.cs b/osu.Framework.Tests/Visual/UserInterface/TestSceneNestedMenus.cs index d9c9157d9..63eaefcec 100644 --- a/osu.Framework.Tests/Visual/UserInterface/TestSceneNestedMenus.cs +++ b/osu.Framework.Tests/Visual/UserInterface/TestSceneNestedMenus.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework.Tests/Visual/UserInterface/TestScenePopover.cs b/osu.Framework.Tests/Visual/UserInterface/TestScenePopover.cs index 48a2b001b..dc72e5b31 100644 --- a/osu.Framework.Tests/Visual/UserInterface/TestScenePopover.cs +++ b/osu.Framework.Tests/Visual/UserInterface/TestScenePopover.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using NUnit.Framework; using osu.Framework.Graphics; @@ -29,7 +31,7 @@ namespace osu.Framework.Tests.Visual.UserInterface }); [Test] - public void TestSizingDirectly() => createContent((anchor, popover) => + public void TestSizingDirectly() => createContent((_, popover) => { popover.Size = new Vector2(200, 100); diff --git a/osu.Framework.Tests/Visual/UserInterface/TestScenePopoverContainer.cs b/osu.Framework.Tests/Visual/UserInterface/TestScenePopoverContainer.cs index 60279d4a2..696048d68 100644 --- a/osu.Framework.Tests/Visual/UserInterface/TestScenePopoverContainer.cs +++ b/osu.Framework.Tests/Visual/UserInterface/TestScenePopoverContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Linq; using NUnit.Framework; diff --git a/osu.Framework.Tests/Visual/UserInterface/TestSceneRearrangeableListContainer.cs b/osu.Framework.Tests/Visual/UserInterface/TestSceneRearrangeableListContainer.cs index db446cc16..e959ed08c 100644 --- a/osu.Framework.Tests/Visual/UserInterface/TestSceneRearrangeableListContainer.cs +++ b/osu.Framework.Tests/Visual/UserInterface/TestSceneRearrangeableListContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework.Tests/Visual/UserInterface/TestSceneRigidBody.cs b/osu.Framework.Tests/Visual/UserInterface/TestSceneRigidBody.cs index 4611633ef..9b7b7cda8 100644 --- a/osu.Framework.Tests/Visual/UserInterface/TestSceneRigidBody.cs +++ b/osu.Framework.Tests/Visual/UserInterface/TestSceneRigidBody.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Graphics; using osu.Framework.Graphics.Shapes; diff --git a/osu.Framework.Tests/Visual/UserInterface/TestSceneScreenStack.cs b/osu.Framework.Tests/Visual/UserInterface/TestSceneScreenStack.cs index 5c9e4928c..f99a53e95 100644 --- a/osu.Framework.Tests/Visual/UserInterface/TestSceneScreenStack.cs +++ b/osu.Framework.Tests/Visual/UserInterface/TestSceneScreenStack.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; @@ -40,7 +42,7 @@ namespace osu.Framework.Tests.Visual.UserInterface RelativeSizeAxes = Axes.Both }); - stack.ScreenPushed += (last, current) => + stack.ScreenPushed += (_, current) => { if (current is TestScreenSlow slow) slowLoaders.Add(slow); diff --git a/osu.Framework.Tests/Visual/UserInterface/TestSceneSearchContainer.cs b/osu.Framework.Tests/Visual/UserInterface/TestSceneSearchContainer.cs index 8036df4ba..9595d4a69 100644 --- a/osu.Framework.Tests/Visual/UserInterface/TestSceneSearchContainer.cs +++ b/osu.Framework.Tests/Visual/UserInterface/TestSceneSearchContainer.cs @@ -1,9 +1,19 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + +using System; using System.Collections.Generic; +using System.Globalization; +using System.IO; using System.Linq; +using System.Threading; +using System.Threading.Tasks; using NUnit.Framework; +using osu.Framework.Allocation; +using osu.Framework.Configuration; +using osu.Framework.Localisation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; @@ -17,6 +27,37 @@ namespace osu.Framework.Tests.Visual.UserInterface private SearchContainer search; private BasicTextBox textBox; + [Resolved] + private FrameworkConfigManager configManager { get; set; } + + [Cached] + private LocalisationManager manager; + + [BackgroundDependencyLoader] + private void load() + { + manager.AddLanguage("en", new TestLocalisationStore("en", new Dictionary + { + [goodbye] = "Goodbye", + })); + manager.AddLanguage("es", new TestLocalisationStore("es", new Dictionary + { + [goodbye] = "Adiós", + })); + } + + protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) + { + var dependencies = new DependencyContainer(parent); + + configManager = parent.Get(); + dependencies.Cache(manager = new LocalisationManager(configManager)); + + return dependencies; + } + + private const string goodbye = "goodbye"; + [SetUp] public void SetUp() => Schedule(() => { @@ -67,6 +108,7 @@ namespace osu.Framework.Tests.Visual.UserInterface { new SearchableText { Text = "?!()[]{}" }, new SearchableText { Text = "@€$" }, + new SearchableText { Text = new LocalisableString(new TranslatableString(goodbye, "Goodbye")) }, }, }, }, @@ -84,7 +126,7 @@ namespace osu.Framework.Tests.Visual.UserInterface [TestCase("èê", 1)] [TestCase("321", 0)] [TestCase("mul pi", 1)] - [TestCase("header", 8)] + [TestCase("header", 9)] public void TestFiltering(string term, int count) { setTerm(term); @@ -94,7 +136,7 @@ namespace osu.Framework.Tests.Visual.UserInterface [TestCase("tst", 2)] [TestCase("ssn 1", 6)] [TestCase("sns 1", 0)] - [TestCase("hdr", 8)] + [TestCase("hdr", 9)] [TestCase("tt", 2)] [TestCase("ttt", 0)] public void TestEagerFilteringEnabled(string term, int count) @@ -128,6 +170,19 @@ namespace osu.Framework.Tests.Visual.UserInterface checkCount(2); } + [TestCase] + public void TestFilterLocalisedStrings() + { + AddStep("Change locale to en", () => configManager.SetValue(FrameworkSetting.Locale, "en")); + setTerm("Goodbye"); + checkCount(1); + AddStep("Change locale to es", () => configManager.SetValue(FrameworkSetting.Locale, "es")); + setTerm("Adiós"); + checkCount(1); + setTerm("Goodbye"); + checkCount(1); + } + private void checkCount(int count) { AddAssert("Visible children: " + count, () => count == countSearchableText(search)); @@ -146,7 +201,7 @@ namespace osu.Framework.Tests.Visual.UserInterface private class HeaderContainer : Container, IHasFilterableChildren { - public IEnumerable FilterTerms => header.FilterTerms; + public IEnumerable FilterTerms => header.FilterTerms; public bool MatchingFilter { @@ -188,7 +243,7 @@ namespace osu.Framework.Tests.Visual.UserInterface private class FilterableFlowContainer : FillFlowContainer, IFilterable { - public IEnumerable FilterTerms => Children.OfType().SelectMany(d => d.FilterTerms); + public IEnumerable FilterTerms => Children.OfType().SelectMany(d => d.FilterTerms); public bool MatchingFilter { @@ -244,5 +299,31 @@ namespace osu.Framework.Tests.Visual.UserInterface set { } } } + + private class TestLocalisationStore : ILocalisationStore + { + public CultureInfo EffectiveCulture { get; } + + private readonly IDictionary translations; + + public TestLocalisationStore(string locale, IDictionary translations) + { + EffectiveCulture = new CultureInfo(locale); + + this.translations = translations; + } + + public string Get(string key) => translations.TryGetValue(key, out string value) ? value : null; + + public Task GetAsync(string key, CancellationToken cancellationToken = default) => Task.FromResult(Get(key)); + + public Stream GetStream(string name) => throw new NotSupportedException(); + + public IEnumerable GetAvailableResources() => Array.Empty(); + + public void Dispose() + { + } + } } } diff --git a/osu.Framework.Tests/Visual/UserInterface/TestSceneSliderBar.cs b/osu.Framework.Tests/Visual/UserInterface/TestSceneSliderBar.cs index ea5c3d03e..108436f68 100644 --- a/osu.Framework.Tests/Visual/UserInterface/TestSceneSliderBar.cs +++ b/osu.Framework.Tests/Visual/UserInterface/TestSceneSliderBar.cs @@ -1,12 +1,17 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; +using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.UserInterface; +using osu.Framework.Input.Events; using osu.Framework.Testing; using osu.Framework.Utils; using osuTK; @@ -22,6 +27,7 @@ namespace osu.Framework.Tests.Visual.UserInterface private readonly SpriteText sliderBarText; private readonly TestSliderBar sliderBar; private readonly SliderBar transferOnCommitSliderBar; + private readonly TestSliderBarWithNub sliderBarWithNub; public TestSceneSliderBar() { @@ -82,6 +88,18 @@ namespace osu.Framework.Tests.Visual.UserInterface KeyboardStep = 1, Current = sliderBarValue }, + new SpriteText + { + Text = "w/ Nub:", + }, + sliderBarWithNub = new TestSliderBarWithNub + { + Size = new Vector2(200, 10), + BackgroundColour = Color4.White, + SelectionColour = Color4.Pink, + KeyboardStep = 1, + Current = sliderBarValue + }, } }); } @@ -200,6 +218,43 @@ namespace osu.Framework.Tests.Visual.UserInterface checkValue(-5, disabled); } + [Test] + public void TestAbsoluteDrag() + { + checkValue(0, false); + AddStep("Move Cursor", + () => { InputManager.MoveMouseTo(sliderBarWithNub.ToScreenSpace(sliderBarWithNub.DrawSize * new Vector2(0.1f, 0.5f))); }); + AddStep("Click", () => { InputManager.PressButton(MouseButton.Left); }); + AddStep("Drag", + () => { InputManager.MoveMouseTo(sliderBarWithNub.ToScreenSpace(sliderBarWithNub.DrawSize * new Vector2(0.4f, 1f))); }); + AddStep("Release Click", () => { InputManager.ReleaseButton(MouseButton.Left); }); + checkValue(-2, false); + } + + [Test] + public void TestRelativeDrag() + { + checkValue(0, false); + AddStep("Move Cursor", + () => { InputManager.MoveMouseTo(sliderBarWithNub.ToScreenSpace(sliderBarWithNub.DrawSize * new Vector2(0.6f, 0.5f))); }); + AddStep("Click", () => { InputManager.PressButton(MouseButton.Left); }); + AddStep("Drag", + () => { InputManager.MoveMouseTo(sliderBarWithNub.ToScreenSpace(sliderBarWithNub.DrawSize * new Vector2(0.75f, 1f))); }); + AddStep("Release Click", () => { InputManager.ReleaseButton(MouseButton.Left); }); + checkValue(3, false); + } + + [Test] + public void TestRelativeClick() + { + checkValue(0, false); + AddStep("Move Cursor", + () => { InputManager.MoveMouseTo(sliderBarWithNub.ToScreenSpace(sliderBarWithNub.DrawSize * new Vector2(0.6f, 0.5f))); }); + AddStep("Click", () => { InputManager.PressButton(MouseButton.Left); }); + AddStep("Release Click", () => { InputManager.ReleaseButton(MouseButton.Left); }); + checkValue(0, false); + } + private void checkValue(int expected, bool disabled) { if (disabled) @@ -216,5 +271,32 @@ namespace osu.Framework.Tests.Visual.UserInterface public class TestSliderBar : BasicSliderBar { } + + public class TestSliderBarWithNub : BasicSliderBar + { + private Box nub; + + [BackgroundDependencyLoader] + private void load() + { + Add(nub = new Box + { + Colour = Color4.Blue, + Origin = Anchor.Centre, + Anchor = Anchor.CentreLeft, + RelativeSizeAxes = Axes.Y, + RelativePositionAxes = Axes.X, + Width = 80, + }); + } + + protected override bool ShouldHandleAsRelativeDrag(MouseDownEvent e) => nub.ReceivePositionalInputAt(e.ScreenSpaceMouseDownPosition); + + protected override void UpdateValue(float value) + { + base.UpdateValue(value); + nub.X = value; + } + } } } diff --git a/osu.Framework.Tests/Visual/UserInterface/TestSceneTabControl.cs b/osu.Framework.Tests/Visual/UserInterface/TestSceneTabControl.cs index 2d2de0399..6518019aa 100644 --- a/osu.Framework.Tests/Visual/UserInterface/TestSceneTabControl.cs +++ b/osu.Framework.Tests/Visual/UserInterface/TestSceneTabControl.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework.Tests/Visual/UserInterface/TestSceneTextBox.cs b/osu.Framework.Tests/Visual/UserInterface/TestSceneTextBox.cs index 09362b1e4..2cf6df50c 100644 --- a/osu.Framework.Tests/Visual/UserInterface/TestSceneTextBox.cs +++ b/osu.Framework.Tests/Visual/UserInterface/TestSceneTextBox.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Linq; using NUnit.Framework; using osu.Framework.Extensions; @@ -766,6 +768,35 @@ namespace osu.Framework.Tests.Visual.UserInterface AddAssert("text container moved back", () => textBox.TextContainerBounds.TopLeft.X < PaddedTextBox.LEFT_RIGHT_PADDING); } + [Test] + public void TestSetTextSelection() + { + TextBox textBox = null; + + AddStep("add textbox", () => + { + textBoxes.Add(textBox = new BasicTextBox + { + Size = new Vector2(300, 40), + Text = "initial text", + }); + }); + + AddStep("click on textbox", () => + { + InputManager.MoveMouseTo(textBox); + InputManager.Click(MouseButton.Left); + }); + + AddStep("set text", () => textBox.Text = "a longer string of text"); + // ideally, this should check the caret/selection position, but that is not exposed in TextBox. + AddAssert("nothing selected", () => textBox.SelectedText == string.Empty); + + AddStep("select all", () => InputManager.Keys(PlatformAction.SelectAll)); + AddStep("set text via current", () => textBox.Text = "short text"); + AddAssert("nothing selected", () => textBox.SelectedText == string.Empty); + } + private void prependString(InsertableTextBox textBox, string text) { InputManager.Keys(PlatformAction.MoveBackwardLine); diff --git a/osu.Framework.Tests/Visual/UserInterface/TestSceneTextBoxEvents.cs b/osu.Framework.Tests/Visual/UserInterface/TestSceneTextBoxEvents.cs index fe650b767..8c91e03fa 100644 --- a/osu.Framework.Tests/Visual/UserInterface/TestSceneTextBoxEvents.cs +++ b/osu.Framework.Tests/Visual/UserInterface/TestSceneTextBoxEvents.cs @@ -1,11 +1,15 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using System.Linq; using NUnit.Framework; using osu.Framework.Allocation; +using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.UserInterface; using osu.Framework.Input; using osu.Framework.Testing; using osuTK; @@ -16,8 +20,8 @@ namespace osu.Framework.Tests.Visual.UserInterface public class TestSceneTextBoxEvents : ManualInputManagerTestScene { private EventQueuesTextBox textBox; - private ManualTextInput textInput; + private ManualTextInputContainer textInputContainer; private const string default_text = "some default text"; private const string composition_text = "test"; @@ -25,27 +29,26 @@ namespace osu.Framework.Tests.Visual.UserInterface [SetUpSteps] public void SetUpSteps() { - ManualTextInputContainer textInputContainer = null; - AddStep("add manual text input container", () => { Child = textInputContainer = new ManualTextInputContainer(); textInput = textInputContainer.TextInput; }); - AddStep("add textbox", () => textInputContainer.Child = textBox = new EventQueuesTextBox + AddStep("add textbox", () => textInputContainer.Add(textBox = new EventQueuesTextBox { CommitOnFocusLost = true, ReleaseFocusOnCommit = false, Size = new Vector2(200, 40), Text = default_text, - }); + })); AddStep("focus textbox", () => { InputManager.MoveMouseTo(textBox); InputManager.Click(MouseButton.Left); }); + AddStep("dequeue text input activated event", () => textInput.ActivationQueue.Dequeue()); AddStep("move caret to end", () => InputManager.Keys(PlatformAction.MoveForwardLine)); AddStep("dequeue caret event", () => textBox.CaretMovedQueue.Dequeue()); @@ -54,7 +57,7 @@ namespace osu.Framework.Tests.Visual.UserInterface [Test] public void TestCommitIsNewTextSecondTime() { - AddStep("add handler to reset on commit", () => textBox.OnCommit += (sender, isNew) => + AddStep("add handler to reset on commit", () => textBox.OnCommit += (_, isNew) => { if (!isNew) return; @@ -125,6 +128,8 @@ namespace osu.Framework.Tests.Visual.UserInterface AddAssert("text committed event raised", () => // Ensure dequeued text commit event has textChanged = false. textBox.CommittedTextQueue.Dequeue() == false && textBox.CommittedTextQueue.Count == 0); + + AddAssert("input deactivated", () => textInput.DeactivationQueue.Dequeue() && textInput.DeactivationQueue.Count == 0); } [Test] @@ -278,6 +283,7 @@ namespace osu.Framework.Tests.Visual.UserInterface AddStep("press escape again to kill focus", () => InputManager.Key(Key.Escape)); AddAssert("text box not focused", () => textBox.HasFocus == false); AddAssert("text committed event raised", () => textBox.CommittedTextQueue.Dequeue() && textBox.CommittedTextQueue.Count == 0); + AddAssert("input deactivated", () => textInput.DeactivationQueue.Dequeue() && textInput.DeactivationQueue.Count == 0); } [Test] @@ -359,6 +365,7 @@ namespace osu.Framework.Tests.Visual.UserInterface AddStep("set read only", () => textBox.ReadOnly = true); AddAssert("text committed event raised", () => textBox.CommittedTextQueue.Dequeue() && textBox.CommittedTextQueue.Count == 0); + AddAssert("input deactivated", () => textInput.DeactivationQueue.Dequeue() && textInput.DeactivationQueue.Count == 0); assertCompositionNotActive(); AddStep("trigger composition", () => textInput.TriggerImeComposition(composition_text, composition_text.Length, 0)); @@ -381,6 +388,41 @@ namespace osu.Framework.Tests.Visual.UserInterface AddAssert("text matches expected", () => textBox.Text == composition_text); } + /// + /// Tests that changing focus directly between two es doesn't deactivate and reactivate text input, + /// as that creates bad UX with mobile virtual keyboards. + /// + [TestCase(false)] + [TestCase(true)] + public void TestChangingFocusDoesNotReactivate(bool allowIme) + { + EventQueuesTextBox secondTextBox = null; + + AddStep("add second textbox", () => textInputContainer.Add(secondTextBox = new EventQueuesTextBox + { + ImeAllowed = allowIme, + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + CommitOnFocusLost = true, + Size = new Vector2(200, 40), + Text = default_text, + })); + + AddStep("focus second textbox", () => + { + InputManager.MoveMouseTo(secondTextBox); + InputManager.Click(MouseButton.Left); + }); + AddStep("dequeue commit event", () => textBox.CommittedTextQueue.Dequeue()); + + AddAssert("text input not deactivated", () => textInput.DeactivationQueue.Count == 0); + AddAssert("text input not activated again", () => textInput.ActivationQueue.Count == 0); + AddAssert($"text input ensure activated {(allowIme ? "with" : "without")} IME", () => textInput.EnsureActivatedQueue.Dequeue() == allowIme && textInput.EnsureActivatedQueue.Count == 0); + + AddStep("commit text", () => InputManager.Key(Key.Enter)); + AddAssert("text input deactivated", () => textInput.DeactivationQueue.Dequeue()); + } + [TearDownSteps] public void TearDownSteps() { @@ -390,7 +432,10 @@ namespace osu.Framework.Tests.Visual.UserInterface textBox.CommittedTextQueue.Count == 0 && textBox.CaretMovedQueue.Count == 0 && textBox.ImeCompositionQueue.Count == 0 && - textBox.ImeResultQueue.Count == 0); + textBox.ImeResultQueue.Count == 0 && + textInput.ActivationQueue.Count == 0 && + textInput.DeactivationQueue.Count == 0 && + textInput.EnsureActivatedQueue.Count == 0); } private void assertCompositionNotActive() @@ -427,6 +472,10 @@ namespace osu.Framework.Tests.Visual.UserInterface public class EventQueuesTextBox : TestSceneTextBox.InsertableTextBox { + public bool ImeAllowed { get; set; } = true; + + protected override bool AllowIme => ImeAllowed; + public readonly Queue InputErrorQueue = new Queue(); public readonly Queue UserConsumedTextQueue = new Queue(); public readonly Queue UserRemovedTextQueue = new Queue(); @@ -467,6 +516,7 @@ namespace osu.Framework.Tests.Visual.UserInterface public ManualTextInputContainer() { + RelativeSizeAxes = Axes.Both; TextInput = new ManualTextInput(); } } @@ -492,6 +542,28 @@ namespace osu.Framework.Tests.Visual.UserInterface // this call will be somewhat delayed in a real world scenario, but let's run it immediately for simplicity. base.TriggerImeComposition(string.Empty, 0, 0); } + + public readonly Queue ActivationQueue = new Queue(); + public readonly Queue EnsureActivatedQueue = new Queue(); + public readonly Queue DeactivationQueue = new Queue(); + + protected override void ActivateTextInput(bool allowIme) + { + base.ActivateTextInput(allowIme); + ActivationQueue.Enqueue(allowIme); + } + + protected override void EnsureTextInputActivated(bool allowIme) + { + base.EnsureTextInputActivated(allowIme); + EnsureActivatedQueue.Enqueue(allowIme); + } + + protected override void DeactivateTextInput() + { + base.DeactivateTextInput(); + DeactivationQueue.Enqueue(true); + } } public struct ImeCompositionEvent diff --git a/osu.Framework.Tests/Visual/UserInterface/TestSceneTextBoxKeyEvents.cs b/osu.Framework.Tests/Visual/UserInterface/TestSceneTextBoxKeyEvents.cs index 5f5035771..bb1c3e7ff 100644 --- a/osu.Framework.Tests/Visual/UserInterface/TestSceneTextBoxKeyEvents.cs +++ b/osu.Framework.Tests/Visual/UserInterface/TestSceneTextBoxKeyEvents.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using System.Linq; using NUnit.Framework; diff --git a/osu.Framework.Tests/Visual/UserInterface/TestSceneTooltip.cs b/osu.Framework.Tests/Visual/UserInterface/TestSceneTooltip.cs index f963b2f47..fcb20f850 100644 --- a/osu.Framework.Tests/Visual/UserInterface/TestSceneTooltip.cs +++ b/osu.Framework.Tests/Visual/UserInterface/TestSceneTooltip.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Linq; using NUnit.Framework; diff --git a/osu.Framework.Tests/Visual/UserInterface/TestSceneUnclosableMenu.cs b/osu.Framework.Tests/Visual/UserInterface/TestSceneUnclosableMenu.cs index 3a1320e00..97144428d 100644 --- a/osu.Framework.Tests/Visual/UserInterface/TestSceneUnclosableMenu.cs +++ b/osu.Framework.Tests/Visual/UserInterface/TestSceneUnclosableMenu.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.UserInterface; diff --git a/osu.Framework.Tests/Visual/UserInterface/TestUIComponentsWithCurrent.cs b/osu.Framework.Tests/Visual/UserInterface/TestUIComponentsWithCurrent.cs index 1616675c5..9ba947139 100644 --- a/osu.Framework.Tests/Visual/UserInterface/TestUIComponentsWithCurrent.cs +++ b/osu.Framework.Tests/Visual/UserInterface/TestUIComponentsWithCurrent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Bindables; using osu.Framework.Graphics.UserInterface; diff --git a/osu.Framework.Tests/VisualTestGame.cs b/osu.Framework.Tests/VisualTestGame.cs index fa1ebae48..c7d873943 100644 --- a/osu.Framework.Tests/VisualTestGame.cs +++ b/osu.Framework.Tests/VisualTestGame.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Cursor; diff --git a/osu.Framework.iOS.props b/osu.Framework.iOS.props index b8324b048..2c6284987 100644 --- a/osu.Framework.iOS.props +++ b/osu.Framework.iOS.props @@ -61,7 +61,7 @@ - + diff --git a/osu.Framework.iOS/GameAppDelegate.cs b/osu.Framework.iOS/GameAppDelegate.cs index 22544c090..0ca2e550c 100644 --- a/osu.Framework.iOS/GameAppDelegate.cs +++ b/osu.Framework.iOS/GameAppDelegate.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Drawing; using System.Runtime.CompilerServices; diff --git a/osu.Framework.iOS/GameUIApplication.cs b/osu.Framework.iOS/GameUIApplication.cs index 69d90e01d..1de979a6c 100644 --- a/osu.Framework.iOS/GameUIApplication.cs +++ b/osu.Framework.iOS/GameUIApplication.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Runtime.InteropServices; using Foundation; diff --git a/osu.Framework.iOS/GameViewController.cs b/osu.Framework.iOS/GameViewController.cs index 84cafb723..12e4c7399 100644 --- a/osu.Framework.iOS/GameViewController.cs +++ b/osu.Framework.iOS/GameViewController.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using CoreGraphics; using osu.Framework.Platform; using UIKit; diff --git a/osu.Framework.iOS/Graphics/Textures/IOSTextureLoaderStore.cs b/osu.Framework.iOS/Graphics/Textures/IOSTextureLoaderStore.cs index d5dc40ea2..23846eeed 100644 --- a/osu.Framework.iOS/Graphics/Textures/IOSTextureLoaderStore.cs +++ b/osu.Framework.iOS/Graphics/Textures/IOSTextureLoaderStore.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.IO; using CoreGraphics; diff --git a/osu.Framework.iOS/Graphics/Video/IOSVideoDecoder.cs b/osu.Framework.iOS/Graphics/Video/IOSVideoDecoder.cs index 804ae77ad..037566deb 100644 --- a/osu.Framework.iOS/Graphics/Video/IOSVideoDecoder.cs +++ b/osu.Framework.iOS/Graphics/Video/IOSVideoDecoder.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.IO; using System.Runtime.InteropServices; using FFmpeg.AutoGen; diff --git a/osu.Framework.iOS/IOSClipboard.cs b/osu.Framework.iOS/IOSClipboard.cs index 6e8c8bc8c..0aa737072 100644 --- a/osu.Framework.iOS/IOSClipboard.cs +++ b/osu.Framework.iOS/IOSClipboard.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Platform; using SixLabors.ImageSharp; using UIKit; diff --git a/osu.Framework.iOS/IOSGameHost.cs b/osu.Framework.iOS/IOSGameHost.cs index 60204af35..39c3fd10d 100644 --- a/osu.Framework.iOS/IOSGameHost.cs +++ b/osu.Framework.iOS/IOSGameHost.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using System.IO; using Foundation; diff --git a/osu.Framework.iOS/IOSGameView.cs b/osu.Framework.iOS/IOSGameView.cs index b41581928..14c0bf85a 100644 --- a/osu.Framework.iOS/IOSGameView.cs +++ b/osu.Framework.iOS/IOSGameView.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Drawing; diff --git a/osu.Framework.iOS/IOSGameWindow.cs b/osu.Framework.iOS/IOSGameWindow.cs index c8e8547eb..154d532d3 100644 --- a/osu.Framework.iOS/IOSGameWindow.cs +++ b/osu.Framework.iOS/IOSGameWindow.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using JetBrains.Annotations; diff --git a/osu.Framework.iOS/IOSStorage.cs b/osu.Framework.iOS/IOSStorage.cs index a25665b7f..350b99281 100644 --- a/osu.Framework.iOS/IOSStorage.cs +++ b/osu.Framework.iOS/IOSStorage.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Platform; namespace osu.Framework.iOS diff --git a/osu.Framework.iOS/Input/IOSHardwareKeyboardHandler.cs b/osu.Framework.iOS/Input/IOSHardwareKeyboardHandler.cs index 81d511b08..83f85ca17 100644 --- a/osu.Framework.iOS/Input/IOSHardwareKeyboardHandler.cs +++ b/osu.Framework.iOS/Input/IOSHardwareKeyboardHandler.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Linq; using Foundation; using osu.Framework.Input.Handlers; diff --git a/osu.Framework.iOS/Input/IOSMouseHandler.cs b/osu.Framework.iOS/Input/IOSMouseHandler.cs index dc313f31e..21f78f04b 100644 --- a/osu.Framework.iOS/Input/IOSMouseHandler.cs +++ b/osu.Framework.iOS/Input/IOSMouseHandler.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using CoreGraphics; using Foundation; diff --git a/osu.Framework.iOS/Input/IOSTextFieldKeyboardHandler.cs b/osu.Framework.iOS/Input/IOSTextFieldKeyboardHandler.cs index d770280fd..0ec9445e7 100644 --- a/osu.Framework.iOS/Input/IOSTextFieldKeyboardHandler.cs +++ b/osu.Framework.iOS/Input/IOSTextFieldKeyboardHandler.cs @@ -1,7 +1,10 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; +using System.Globalization; using System.Linq; using Foundation; using osu.Framework.Input.Handlers; @@ -202,7 +205,7 @@ namespace osu.Framework.iOS.Input default: if (char.IsLetter(c)) { - string keyName = c.ToString().ToUpper(); + string keyName = c.ToString().ToUpper(CultureInfo.CurrentCulture); if (Enum.TryParse(keyName, out Key result)) return result; } diff --git a/osu.Framework.iOS/Input/IOSTextInput.cs b/osu.Framework.iOS/Input/IOSTextInput.cs index 3a9b4d2a1..18f44e9b1 100644 --- a/osu.Framework.iOS/Input/IOSTextInput.cs +++ b/osu.Framework.iOS/Input/IOSTextInput.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using Foundation; using osu.Framework.Input; diff --git a/osu.Framework.iOS/Input/IOSTouchHandler.cs b/osu.Framework.iOS/Input/IOSTouchHandler.cs index 2515c495c..40c4d7b01 100644 --- a/osu.Framework.iOS/Input/IOSTouchHandler.cs +++ b/osu.Framework.iOS/Input/IOSTouchHandler.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Diagnostics; using Foundation; using osu.Framework.Input; diff --git a/osu.Framework.iOS/Properties/AssemblyInfo.cs b/osu.Framework.iOS/Properties/AssemblyInfo.cs index 7f5291bb7..cc26bf377 100644 --- a/osu.Framework.iOS/Properties/AssemblyInfo.cs +++ b/osu.Framework.iOS/Properties/AssemblyInfo.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Runtime.CompilerServices; using ObjCRuntime; diff --git a/osu.Framework.iOS/global.json b/osu.Framework.iOS/global.json index ca155216f..e032ebd53 100644 --- a/osu.Framework.iOS/global.json +++ b/osu.Framework.iOS/global.json @@ -3,9 +3,5 @@ "allowPrerelease": false, "rollForward": "minor", "version": "3.1.100" - }, - "msbuild-sdks": { - "MSBuild.Sdk.Extras": "3.0.22", - "Microsoft.Build.Traversal": "3.0.2" } } \ No newline at end of file diff --git a/osu.Framework.iOS/osu.Framework.iOS.csproj b/osu.Framework.iOS/osu.Framework.iOS.csproj index fac36bc1a..ca5e41c60 100644 --- a/osu.Framework.iOS/osu.Framework.iOS.csproj +++ b/osu.Framework.iOS/osu.Framework.iOS.csproj @@ -1,4 +1,4 @@ - + xamarinios10 Library @@ -24,7 +24,7 @@ - + diff --git a/osu.Framework/Allocation/AsyncDisposalQueue.cs b/osu.Framework/Allocation/AsyncDisposalQueue.cs index 5a1438093..1f969f014 100644 --- a/osu.Framework/Allocation/AsyncDisposalQueue.cs +++ b/osu.Framework/Allocation/AsyncDisposalQueue.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Threading; diff --git a/osu.Framework/Allocation/BackgroundDependencyLoaderAttribute.cs b/osu.Framework/Allocation/BackgroundDependencyLoaderAttribute.cs index ecc2605f2..dc4396e18 100644 --- a/osu.Framework/Allocation/BackgroundDependencyLoaderAttribute.cs +++ b/osu.Framework/Allocation/BackgroundDependencyLoaderAttribute.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Diagnostics; using System.Linq; @@ -45,7 +47,7 @@ namespace osu.Framework.Allocation switch (loaderMethods.Length) { case 0: - return (_, __) => { }; + return (_, _) => { }; case 1: var method = loaderMethods[0]; @@ -58,8 +60,8 @@ namespace osu.Framework.Allocation Debug.Assert(attribute != null); bool permitNulls = attribute.permitNulls; - var parameterGetters = method.GetParameters().Select(p => p.ParameterType) - .Select(t => getDependency(t, type, permitNulls || t.IsNullable())).ToArray(); + var parameterGetters = method.GetParameters() + .Select(parameter => getDependency(parameter.ParameterType, type, permitNulls || parameter.IsNullable())).ToArray(); return (target, dc) => { diff --git a/osu.Framework/Allocation/CacheInfo.cs b/osu.Framework/Allocation/CacheInfo.cs index 124828003..d19fcb0b9 100644 --- a/osu.Framework/Allocation/CacheInfo.cs +++ b/osu.Framework/Allocation/CacheInfo.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Extensions.TypeExtensions; diff --git a/osu.Framework/Allocation/CachedAttribute.cs b/osu.Framework/Allocation/CachedAttribute.cs index c0dcc729f..6d627222d 100644 --- a/osu.Framework/Allocation/CachedAttribute.cs +++ b/osu.Framework/Allocation/CachedAttribute.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; @@ -139,7 +141,7 @@ namespace osu.Framework.Allocation additionActivators.AddRange(createMemberActivator(field, type, allowValueTypes)); if (additionActivators.Count == 0) - return (_, existing, info) => existing; + return (_, existing, _) => existing; return (target, existing, info) => { diff --git a/osu.Framework/Allocation/CachedModelDependencyContainer.cs b/osu.Framework/Allocation/CachedModelDependencyContainer.cs index 581ebbf9d..86bce3b2b 100644 --- a/osu.Framework/Allocation/CachedModelDependencyContainer.cs +++ b/osu.Framework/Allocation/CachedModelDependencyContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Reflection; using osu.Framework.Bindables; diff --git a/osu.Framework/Allocation/DependencyActivator.cs b/osu.Framework/Allocation/DependencyActivator.cs index c4dbf183e..3562e353e 100644 --- a/osu.Framework/Allocation/DependencyActivator.cs +++ b/osu.Framework/Allocation/DependencyActivator.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Concurrent; using System.Collections.Generic; diff --git a/osu.Framework/Allocation/DependencyContainer.cs b/osu.Framework/Allocation/DependencyContainer.cs index a8022bf78..72e9ac77e 100644 --- a/osu.Framework/Allocation/DependencyContainer.cs +++ b/osu.Framework/Allocation/DependencyContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Threading; diff --git a/osu.Framework/Allocation/IReadOnlyDependencyContainer.cs b/osu.Framework/Allocation/IReadOnlyDependencyContainer.cs index 7ed141373..8b2524ad8 100644 --- a/osu.Framework/Allocation/IReadOnlyDependencyContainer.cs +++ b/osu.Framework/Allocation/IReadOnlyDependencyContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; namespace osu.Framework.Allocation diff --git a/osu.Framework/Allocation/InvokeOnDisposal.cs b/osu.Framework/Allocation/InvokeOnDisposal.cs index ef61bb2cd..0f6c5dcef 100644 --- a/osu.Framework/Allocation/InvokeOnDisposal.cs +++ b/osu.Framework/Allocation/InvokeOnDisposal.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; namespace osu.Framework.Allocation diff --git a/osu.Framework/Allocation/LongRunningLoadAttribute.cs b/osu.Framework/Allocation/LongRunningLoadAttribute.cs index 684696948..e84d0a977 100644 --- a/osu.Framework/Allocation/LongRunningLoadAttribute.cs +++ b/osu.Framework/Allocation/LongRunningLoadAttribute.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework/Allocation/ObjectHandle.cs b/osu.Framework/Allocation/ObjectHandle.cs index 4c6d55121..26b6758c2 100644 --- a/osu.Framework/Allocation/ObjectHandle.cs +++ b/osu.Framework/Allocation/ObjectHandle.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Runtime.InteropServices; diff --git a/osu.Framework/Allocation/ObjectUsage.cs b/osu.Framework/Allocation/ObjectUsage.cs index ae2dcaee2..54b6ecbc1 100644 --- a/osu.Framework/Allocation/ObjectUsage.cs +++ b/osu.Framework/Allocation/ObjectUsage.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; namespace osu.Framework.Allocation @@ -9,17 +11,22 @@ namespace osu.Framework.Allocation where T : class { public T Object; - public int Index; - - public long FrameId; - - internal Action, UsageType> Finish; public UsageType Usage; + public readonly int Index; + + private readonly Action> finish; + + public ObjectUsage(int index, Action> finish) + { + Index = index; + this.finish = finish; + } + public void Dispose() { - Finish?.Invoke(this, Usage); + finish?.Invoke(this); } } diff --git a/osu.Framework/Allocation/ResolvedAttribute.cs b/osu.Framework/Allocation/ResolvedAttribute.cs index db2907402..5b29a20a1 100644 --- a/osu.Framework/Allocation/ResolvedAttribute.cs +++ b/osu.Framework/Allocation/ResolvedAttribute.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Diagnostics; @@ -95,7 +97,7 @@ namespace osu.Framework.Allocation cacheInfo = new CacheInfo(cacheInfo.Name ?? property.Name, attribute.Parent); } - var fieldGetter = getDependency(property.PropertyType, type, attribute.CanBeNull || property.PropertyType.IsNullable(), cacheInfo); + var fieldGetter = getDependency(property.PropertyType, type, attribute.CanBeNull || property.IsNullable(), cacheInfo); activators.Add((target, dc) => property.SetValue(target, fieldGetter(dc))); } diff --git a/osu.Framework/Allocation/TimedExpiryCache.cs b/osu.Framework/Allocation/TimedExpiryCache.cs index 3433d37ee..f851524ec 100644 --- a/osu.Framework/Allocation/TimedExpiryCache.cs +++ b/osu.Framework/Allocation/TimedExpiryCache.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Concurrent; using System.Threading; diff --git a/osu.Framework/Allocation/TripleBuffer.cs b/osu.Framework/Allocation/TripleBuffer.cs index 7ba62d211..f2cf4f52d 100644 --- a/osu.Framework/Allocation/TripleBuffer.cs +++ b/osu.Framework/Allocation/TripleBuffer.cs @@ -1,7 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System; +using System.Diagnostics; using System.Threading; namespace osu.Framework.Allocation @@ -15,80 +15,94 @@ namespace osu.Framework.Allocation { private readonly ObjectUsage[] buffers = new ObjectUsage[3]; - private int read; - private int write; - private int lastWrite = -1; + private int? lastCompletedWriteIndex; - private long currentFrame; + private int? activeReadIndex; - private readonly Action, UsageType> finishDelegate; + private readonly ManualResetEventSlim writeCompletedEvent = new ManualResetEventSlim(); + + private const int buffer_count = 3; public TripleBuffer() { - //caching the delegate means we only have to allocate it once, rather than once per created buffer. - finishDelegate = finish; + for (int i = 0; i < buffer_count; i++) + buffers[i] = new ObjectUsage(i, finishUsage); } - public ObjectUsage Get(UsageType usage) + public ObjectUsage GetForWrite() { - switch (usage) + ObjectUsage buffer; + + lock (buffers) { - case UsageType.Write: - lock (buffers) - { - while (buffers[write]?.Usage == UsageType.Read || write == lastWrite) - write = (write + 1) % 3; - } + buffer = getNextWriteBuffer(); - if (buffers[write] == null) - { - buffers[write] = new ObjectUsage - { - Finish = finishDelegate, - Usage = UsageType.Write, - Index = write, - }; - } - else - { - buffers[write].Usage = UsageType.Write; - } - - buffers[write].FrameId = Interlocked.Increment(ref currentFrame); - return buffers[write]; - - case UsageType.Read: - if (lastWrite < 0) return null; - - lock (buffers) - { - read = lastWrite; - buffers[read].Usage = UsageType.Read; - } - - return buffers[read]; + Debug.Assert(buffer.Usage == UsageType.None); + buffer.Usage = UsageType.Write; } - return null; + return buffer; } - private void finish(ObjectUsage obj, UsageType type) + public ObjectUsage? GetForRead() { - switch (type) + writeCompletedEvent.Reset(); + + lock (buffers) { - case UsageType.Read: - lock (buffers) - buffers[read].Usage = UsageType.None; - break; + if (lastCompletedWriteIndex != null) + { + var buffer = buffers[lastCompletedWriteIndex.Value]; + lastCompletedWriteIndex = null; + buffer.Usage = UsageType.Read; - case UsageType.Write: - lock (buffers) - { - buffers[write].Usage = UsageType.None; - lastWrite = write; - } + Debug.Assert(activeReadIndex == null); + activeReadIndex = buffer.Index; + return buffer; + } + } - break; + // A completed write wasn't available, so wait for the next to complete. + if (!writeCompletedEvent.Wait(100)) + // Generally shouldn't happen, but this avoids spinning forever. + return null; + + return GetForRead(); + } + + private ObjectUsage getNextWriteBuffer() + { + for (int i = 0; i < buffer_count - 1; i++) + { + if (i == activeReadIndex) continue; + if (i == lastCompletedWriteIndex) continue; + + return buffers[i]; + } + + return buffers[buffer_count - 1]; + } + + private void finishUsage(ObjectUsage obj) + { + lock (buffers) + { + switch (obj.Usage) + { + case UsageType.Read: + Debug.Assert(activeReadIndex != null); + activeReadIndex = null; + break; + + case UsageType.Write: + Debug.Assert(lastCompletedWriteIndex != obj.Index); + lastCompletedWriteIndex = obj.Index; + + writeCompletedEvent.Set(); + break; + } + + obj.Usage = UsageType.None; } } } diff --git a/osu.Framework/Allocation/ValueInvokeOnDisposal.cs b/osu.Framework/Allocation/ValueInvokeOnDisposal.cs index f61a2e600..429863189 100644 --- a/osu.Framework/Allocation/ValueInvokeOnDisposal.cs +++ b/osu.Framework/Allocation/ValueInvokeOnDisposal.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; namespace osu.Framework.Allocation diff --git a/osu.Framework/Audio/AdjustableAudioComponent.cs b/osu.Framework/Audio/AdjustableAudioComponent.cs index 7d0ee441d..d6fd3fbe2 100644 --- a/osu.Framework/Audio/AdjustableAudioComponent.cs +++ b/osu.Framework/Audio/AdjustableAudioComponent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Bindables; namespace osu.Framework.Audio diff --git a/osu.Framework/Audio/AggregateAdjustmentExtensions.cs b/osu.Framework/Audio/AggregateAdjustmentExtensions.cs index 3dda8ef66..e36dac049 100644 --- a/osu.Framework/Audio/AggregateAdjustmentExtensions.cs +++ b/osu.Framework/Audio/AggregateAdjustmentExtensions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Bindables; diff --git a/osu.Framework/Audio/AudioAdjustments.cs b/osu.Framework/Audio/AudioAdjustments.cs index eceb288d2..e311e1c82 100644 --- a/osu.Framework/Audio/AudioAdjustments.cs +++ b/osu.Framework/Audio/AudioAdjustments.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Bindables; diff --git a/osu.Framework/Audio/AudioCollectionManager.cs b/osu.Framework/Audio/AudioCollectionManager.cs index 8917280ee..53d2ae96e 100644 --- a/osu.Framework/Audio/AudioCollectionManager.cs +++ b/osu.Framework/Audio/AudioCollectionManager.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework/Audio/AudioComponent.cs b/osu.Framework/Audio/AudioComponent.cs index 348a723bb..778a513cc 100644 --- a/osu.Framework/Audio/AudioComponent.cs +++ b/osu.Framework/Audio/AudioComponent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Concurrent; using System.Threading.Tasks; diff --git a/osu.Framework/Audio/AudioManager.cs b/osu.Framework/Audio/AudioManager.cs index 180bef8eb..d7a2de4f4 100644 --- a/osu.Framework/Audio/AudioManager.cs +++ b/osu.Framework/Audio/AudioManager.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Collections.Immutable; diff --git a/osu.Framework/Audio/BassAmplitudeProcessor.cs b/osu.Framework/Audio/BassAmplitudeProcessor.cs index 4b6c32651..3d0aef7fd 100644 --- a/osu.Framework/Audio/BassAmplitudeProcessor.cs +++ b/osu.Framework/Audio/BassAmplitudeProcessor.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using ManagedBass; using osu.Framework.Audio.Mixing.Bass; using osu.Framework.Audio.Track; diff --git a/osu.Framework/Audio/BassRelativeFrequencyHandler.cs b/osu.Framework/Audio/BassRelativeFrequencyHandler.cs index 57e78f78f..631bd4ef5 100644 --- a/osu.Framework/Audio/BassRelativeFrequencyHandler.cs +++ b/osu.Framework/Audio/BassRelativeFrequencyHandler.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using ManagedBass; diff --git a/osu.Framework/Audio/BassUtils.cs b/osu.Framework/Audio/BassUtils.cs index d7de470c8..d89f84239 100644 --- a/osu.Framework/Audio/BassUtils.cs +++ b/osu.Framework/Audio/BassUtils.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using ManagedBass; using osu.Framework.Logging; diff --git a/osu.Framework/Audio/Callbacks/BassCallback.cs b/osu.Framework/Audio/Callbacks/BassCallback.cs index 61ec9ce66..779d220f2 100644 --- a/osu.Framework/Audio/Callbacks/BassCallback.cs +++ b/osu.Framework/Audio/Callbacks/BassCallback.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Runtime.InteropServices; using osu.Framework.Allocation; diff --git a/osu.Framework/Audio/Callbacks/DataStreamFileProcedures.cs b/osu.Framework/Audio/Callbacks/DataStreamFileProcedures.cs index 2b1076acc..8d8284108 100644 --- a/osu.Framework/Audio/Callbacks/DataStreamFileProcedures.cs +++ b/osu.Framework/Audio/Callbacks/DataStreamFileProcedures.cs @@ -4,8 +4,6 @@ using System; using System.IO; -#nullable enable - namespace osu.Framework.Audio.Callbacks { /// diff --git a/osu.Framework/Audio/Callbacks/FileCallbacks.cs b/osu.Framework/Audio/Callbacks/FileCallbacks.cs index bf981f868..81bfae8e8 100644 --- a/osu.Framework/Audio/Callbacks/FileCallbacks.cs +++ b/osu.Framework/Audio/Callbacks/FileCallbacks.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using ManagedBass; using osu.Framework.Allocation; diff --git a/osu.Framework/Audio/Callbacks/IFileProcedures.cs b/osu.Framework/Audio/Callbacks/IFileProcedures.cs index 11a5c4710..2249c26b2 100644 --- a/osu.Framework/Audio/Callbacks/IFileProcedures.cs +++ b/osu.Framework/Audio/Callbacks/IFileProcedures.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using ManagedBass; diff --git a/osu.Framework/Audio/Callbacks/SyncCallback.cs b/osu.Framework/Audio/Callbacks/SyncCallback.cs index 61454aa4c..18977fd0a 100644 --- a/osu.Framework/Audio/Callbacks/SyncCallback.cs +++ b/osu.Framework/Audio/Callbacks/SyncCallback.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using ManagedBass; using osu.Framework.Allocation; diff --git a/osu.Framework/Audio/IAdjustableAudioComponent.cs b/osu.Framework/Audio/IAdjustableAudioComponent.cs index 743950627..42e1f4a5e 100644 --- a/osu.Framework/Audio/IAdjustableAudioComponent.cs +++ b/osu.Framework/Audio/IAdjustableAudioComponent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Audio; diff --git a/osu.Framework/Audio/IAdjustableResourceStore.cs b/osu.Framework/Audio/IAdjustableResourceStore.cs index e35d5066f..904e5ba4e 100644 --- a/osu.Framework/Audio/IAdjustableResourceStore.cs +++ b/osu.Framework/Audio/IAdjustableResourceStore.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.IO.Stores; namespace osu.Framework.Audio diff --git a/osu.Framework/Audio/IAggregateAudioAdjustment.cs b/osu.Framework/Audio/IAggregateAudioAdjustment.cs index 50b79a5de..90b0487fa 100644 --- a/osu.Framework/Audio/IAggregateAudioAdjustment.cs +++ b/osu.Framework/Audio/IAggregateAudioAdjustment.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Bindables; namespace osu.Framework.Audio diff --git a/osu.Framework/Audio/IBassAudio.cs b/osu.Framework/Audio/IBassAudio.cs index c24d41cbc..4c0286bf4 100644 --- a/osu.Framework/Audio/IBassAudio.cs +++ b/osu.Framework/Audio/IBassAudio.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Audio { internal interface IBassAudio diff --git a/osu.Framework/Audio/IHasAmplitudes.cs b/osu.Framework/Audio/IHasAmplitudes.cs index ec06fd80f..507f2d578 100644 --- a/osu.Framework/Audio/IHasAmplitudes.cs +++ b/osu.Framework/Audio/IHasAmplitudes.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Audio.Track; namespace osu.Framework.Audio diff --git a/osu.Framework/Audio/Mixing/AudioMixer.cs b/osu.Framework/Audio/Mixing/AudioMixer.cs index f93650e2b..581aef8f4 100644 --- a/osu.Framework/Audio/Mixing/AudioMixer.cs +++ b/osu.Framework/Audio/Mixing/AudioMixer.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using ManagedBass; using osu.Framework.Bindables; using osu.Framework.Extensions.ObjectExtensions; diff --git a/osu.Framework/Audio/Mixing/Bass/BassAudioMixer.cs b/osu.Framework/Audio/Mixing/Bass/BassAudioMixer.cs index f4b5d5feb..37ed04d6d 100644 --- a/osu.Framework/Audio/Mixing/Bass/BassAudioMixer.cs +++ b/osu.Framework/Audio/Mixing/Bass/BassAudioMixer.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using System; using System.Collections.Generic; using System.Collections.Specialized; @@ -302,8 +300,10 @@ namespace osu.Framework.Audio.Mixing.Bass /// public void AddChannelToBassMix(IBassAudioChannel channel) { - Debug.Assert(Handle != 0); - Debug.Assert(channel.Handle != 0); + // TODO: This fails and throws unobserved exceptions in github CI runs on macOS. + // Needs further investigation at some point as something is definitely not right. + // Debug.Assert(Handle != 0); + // Debug.Assert(channel.Handle != 0); BassFlags flags = BassFlags.MixerChanBuffer | BassFlags.MixerChanNoRampin; if (channel.MixerChannelPaused) @@ -318,8 +318,10 @@ namespace osu.Framework.Audio.Mixing.Bass /// private void removeChannelFromBassMix(IBassAudioChannel channel) { - Debug.Assert(Handle != 0); - Debug.Assert(channel.Handle != 0); + // TODO: This fails and throws unobserved exceptions in github CI runs on macOS. + // Needs further investigation at some point as something is definitely not right. + // Debug.Assert(Handle != 0); + // Debug.Assert(channel.Handle != 0); channel.MixerChannelPaused = BassMix.ChannelHasFlag(channel.Handle, BassFlags.MixerChanPause); BassMix.MixerRemoveChannel(channel.Handle); diff --git a/osu.Framework/Audio/Mixing/Bass/IBassAudioChannel.cs b/osu.Framework/Audio/Mixing/Bass/IBassAudioChannel.cs index a2ae556be..4e6905b18 100644 --- a/osu.Framework/Audio/Mixing/Bass/IBassAudioChannel.cs +++ b/osu.Framework/Audio/Mixing/Bass/IBassAudioChannel.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using osu.Framework.Audio.Sample; using osu.Framework.Audio.Track; diff --git a/osu.Framework/Audio/Mixing/IAudioChannel.cs b/osu.Framework/Audio/Mixing/IAudioChannel.cs index 528688cd9..868d93c04 100644 --- a/osu.Framework/Audio/Mixing/IAudioChannel.cs +++ b/osu.Framework/Audio/Mixing/IAudioChannel.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using System; using System.Threading.Tasks; diff --git a/osu.Framework/Audio/Mixing/IAudioMixer.cs b/osu.Framework/Audio/Mixing/IAudioMixer.cs index 208d946b1..8b4f4bcd4 100644 --- a/osu.Framework/Audio/Mixing/IAudioMixer.cs +++ b/osu.Framework/Audio/Mixing/IAudioMixer.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using ManagedBass; using osu.Framework.Bindables; diff --git a/osu.Framework/Audio/Sample/ISample.cs b/osu.Framework/Audio/Sample/ISample.cs index cbd7b1d58..fdf83fbdd 100644 --- a/osu.Framework/Audio/Sample/ISample.cs +++ b/osu.Framework/Audio/Sample/ISample.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Bindables; namespace osu.Framework.Audio.Sample diff --git a/osu.Framework/Audio/Sample/ISampleChannel.cs b/osu.Framework/Audio/Sample/ISampleChannel.cs index 6c6326752..22133a1ad 100644 --- a/osu.Framework/Audio/Sample/ISampleChannel.cs +++ b/osu.Framework/Audio/Sample/ISampleChannel.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Audio.Sample { /// diff --git a/osu.Framework/Audio/Sample/ISampleStore.cs b/osu.Framework/Audio/Sample/ISampleStore.cs index 409a2b78a..e43ee81d8 100644 --- a/osu.Framework/Audio/Sample/ISampleStore.cs +++ b/osu.Framework/Audio/Sample/ISampleStore.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Audio.Sample { public interface ISampleStore : IAdjustableResourceStore diff --git a/osu.Framework/Audio/Sample/Sample.cs b/osu.Framework/Audio/Sample/Sample.cs index e7cee15ac..566c2ce98 100644 --- a/osu.Framework/Audio/Sample/Sample.cs +++ b/osu.Framework/Audio/Sample/Sample.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Bindables; diff --git a/osu.Framework/Audio/Sample/SampleBass.cs b/osu.Framework/Audio/Sample/SampleBass.cs index bb825110c..554b32c59 100644 --- a/osu.Framework/Audio/Sample/SampleBass.cs +++ b/osu.Framework/Audio/Sample/SampleBass.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using osu.Framework.Audio.Mixing.Bass; namespace osu.Framework.Audio.Sample diff --git a/osu.Framework/Audio/Sample/SampleBassFactory.cs b/osu.Framework/Audio/Sample/SampleBassFactory.cs index b4f7db122..088eb0d4f 100644 --- a/osu.Framework/Audio/Sample/SampleBassFactory.cs +++ b/osu.Framework/Audio/Sample/SampleBassFactory.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using System.Diagnostics; using System.Runtime.InteropServices; using ManagedBass; diff --git a/osu.Framework/Audio/Sample/SampleChannel.cs b/osu.Framework/Audio/Sample/SampleChannel.cs index 29e4f0f05..c0a5b47d5 100644 --- a/osu.Framework/Audio/Sample/SampleChannel.cs +++ b/osu.Framework/Audio/Sample/SampleChannel.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using System; using System.Threading.Tasks; using osu.Framework.Audio.Mixing; diff --git a/osu.Framework/Audio/Sample/SampleChannelBass.cs b/osu.Framework/Audio/Sample/SampleChannelBass.cs index a2a5ecd1d..cbe9fdb13 100644 --- a/osu.Framework/Audio/Sample/SampleChannelBass.cs +++ b/osu.Framework/Audio/Sample/SampleChannelBass.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using ManagedBass; using osu.Framework.Audio.Mixing.Bass; using osu.Framework.Audio.Track; @@ -189,7 +187,15 @@ namespace osu.Framework.Audio.Sample if (hasChannel) return; - channel = Bass.SampleGetChannel(sample.SampleId, BassFlags.SampleChannelStream | BassFlags.Decode); + BassFlags flags = BassFlags.SampleChannelStream | BassFlags.Decode; + + // While this shouldn't cause issues, we've had a small subset of users reporting issues on windows. + // To keep things working let's only apply to other platforms until we know more. + // See https://github.com/ppy/osu/issues/18652. + if (RuntimeInfo.OS != RuntimeInfo.Platform.Windows) + flags |= BassFlags.AsyncFile; + + channel = Bass.SampleGetChannel(sample.SampleId, flags); if (!hasChannel) return; diff --git a/osu.Framework/Audio/Sample/SampleChannelVirtual.cs b/osu.Framework/Audio/Sample/SampleChannelVirtual.cs index 601f7fda2..e6c01bf1f 100644 --- a/osu.Framework/Audio/Sample/SampleChannelVirtual.cs +++ b/osu.Framework/Audio/Sample/SampleChannelVirtual.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Audio.Sample { /// diff --git a/osu.Framework/Audio/Sample/SampleStore.cs b/osu.Framework/Audio/Sample/SampleStore.cs index f2d060abe..68448d413 100644 --- a/osu.Framework/Audio/Sample/SampleStore.cs +++ b/osu.Framework/Audio/Sample/SampleStore.cs @@ -1,8 +1,9 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; -using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; using System.Threading; @@ -20,7 +21,7 @@ namespace osu.Framework.Audio.Sample private readonly IResourceStore store; private readonly AudioMixer mixer; - private readonly ConcurrentDictionary factories = new ConcurrentDictionary(); + private readonly Dictionary factories = new Dictionary(); public int PlaybackConcurrency { get; set; } = Sample.DEFAULT_CONCURRENCY; diff --git a/osu.Framework/Audio/Sample/SampleVirtual.cs b/osu.Framework/Audio/Sample/SampleVirtual.cs index d025d02af..930610698 100644 --- a/osu.Framework/Audio/Sample/SampleVirtual.cs +++ b/osu.Framework/Audio/Sample/SampleVirtual.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Audio.Sample { /// diff --git a/osu.Framework/Audio/Track/ChannelAmplitudes.cs b/osu.Framework/Audio/Track/ChannelAmplitudes.cs index c9308fb1e..7217f00ba 100644 --- a/osu.Framework/Audio/Track/ChannelAmplitudes.cs +++ b/osu.Framework/Audio/Track/ChannelAmplitudes.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; namespace osu.Framework.Audio.Track diff --git a/osu.Framework/Audio/Track/ITrack.cs b/osu.Framework/Audio/Track/ITrack.cs index 35ff84bdf..173ff4174 100644 --- a/osu.Framework/Audio/Track/ITrack.cs +++ b/osu.Framework/Audio/Track/ITrack.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Timing; diff --git a/osu.Framework/Audio/Track/ITrackStore.cs b/osu.Framework/Audio/Track/ITrackStore.cs index 53c771a64..86ced96c7 100644 --- a/osu.Framework/Audio/Track/ITrackStore.cs +++ b/osu.Framework/Audio/Track/ITrackStore.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Audio.Track { public interface ITrackStore : IAdjustableResourceStore diff --git a/osu.Framework/Audio/Track/Track.cs b/osu.Framework/Audio/Track/Track.cs index d05c632ec..304b305af 100644 --- a/osu.Framework/Audio/Track/Track.cs +++ b/osu.Framework/Audio/Track/Track.cs @@ -1,12 +1,11 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using osu.Framework.Statistics; using System; using System.Threading.Tasks; using osu.Framework.Audio.Mixing; +using osu.Framework.Extensions; namespace osu.Framework.Audio.Track { @@ -15,8 +14,8 @@ namespace osu.Framework.Audio.Track public event Action? Completed; public event Action? Failed; - protected virtual void RaiseCompleted() => Completed?.Invoke(); - protected virtual void RaiseFailed() => Failed?.Invoke(); + protected void RaiseCompleted() => Completed?.Invoke(); + protected void RaiseFailed() => Failed?.Invoke(); public virtual bool IsDummyDevice => true; @@ -40,12 +39,14 @@ namespace osu.Framework.Audio.Track /// /// Restarts this track from the while retaining adjustments. /// - public virtual void Restart() + public void Restart() => RestartAsync().WaitSafely(); + + public Task RestartAsync() => EnqueueAction(() => { Stop(); Seek(RestartPoint); Start(); - } + }); public virtual void ResetSpeedAdjustments() { @@ -84,15 +85,15 @@ namespace osu.Framework.Audio.Track /// Whether the seek was successful. public abstract bool Seek(double seek); - public virtual void Start() - { - if (IsDisposed) - throw new ObjectDisposedException(ToString(), "Can not start disposed tracks."); - } + public abstract Task SeekAsync(double seek); - public virtual void Stop() - { - } + public abstract Task StartAsync(); + + public abstract void Start(); + + public abstract Task StopAsync(); + + public abstract void Stop(); public abstract bool IsRunning { get; } diff --git a/osu.Framework/Audio/Track/TrackBass.cs b/osu.Framework/Audio/Track/TrackBass.cs index ac4774649..6300889a3 100644 --- a/osu.Framework/Audio/Track/TrackBass.cs +++ b/osu.Framework/Audio/Track/TrackBass.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using System; using System.Diagnostics; using System.IO; @@ -135,9 +133,9 @@ namespace osu.Framework.Audio.Track { switch (data) { - case MemoryStream _: - case UnmanagedMemoryStream _: - case AsyncBufferStream _: + case MemoryStream: + case UnmanagedMemoryStream: + case AsyncBufferStream: // Buffering memory stream is definitely unworthy. dataStream = data; break; @@ -151,7 +149,14 @@ namespace osu.Framework.Audio.Track fileCallbacks = new FileCallbacks(new DataStreamFileProcedures(dataStream)); - BassFlags flags = Preview ? 0 : BassFlags.Decode | BassFlags.Prescan; + BassFlags flags = (Preview ? 0 : BassFlags.Decode | BassFlags.Prescan); + + // While this shouldn't cause issues, we've had a small subset of users reporting issues on windows. + // To keep things working let's only apply to other platforms until we know more. + // See https://github.com/ppy/osu/issues/18652. + if (RuntimeInfo.OS != RuntimeInfo.Platform.Windows) + flags |= BassFlags.AsyncFile; + int stream = Bass.CreateStream(StreamSystem.NoBuffer, flags, fileCallbacks.Callbacks, fileCallbacks.Handle); bitrate = (int)Math.Round(Bass.ChannelGetAttribute(stream, ChannelAttribute.Bitrate)); @@ -215,19 +220,17 @@ namespace osu.Framework.Audio.Track public override bool IsDummyDevice => false; - public override void Stop() - { - base.Stop(); + public override void Stop() => StopAsync().WaitSafely(); - StopAsync().WaitSafely(); + public override Task StopAsync() + { + return EnqueueAction(() => + { + stopInternal(); + isRunning = isPlayed = false; + }); } - public Task StopAsync() => EnqueueAction(() => - { - stopInternal(); - isRunning = isPlayed = false; - }); - private void stopInternal() { if (!isRunningState(bassMixer.ChannelIsActive(this))) @@ -246,12 +249,13 @@ namespace osu.Framework.Audio.Track public override void Start() { - base.Start(); + if (IsDisposed) + throw new ObjectDisposedException(ToString(), "Can not start disposed tracks."); StartAsync().WaitSafely(); } - public Task StartAsync() => EnqueueAction(() => + public override Task StartAsync() => EnqueueAction(() => { if (startInternal()) isRunning = isPlayed = true; @@ -286,7 +290,7 @@ namespace osu.Framework.Audio.Track public override bool Seek(double seek) => SeekAsync(seek).GetResultSafely(); - public async Task SeekAsync(double seek) + public override async Task SeekAsync(double seek) { // At this point the track may not yet be loaded which is indicated by a 0 length. // In that case we still want to return true, hence the conservative length. @@ -366,8 +370,8 @@ namespace osu.Framework.Audio.Track && endCallback == null && endSync == null); - stopCallback = new SyncCallback((a, b, c, d) => RaiseFailed()); - endCallback = new SyncCallback((a, b, c, d) => + stopCallback = new SyncCallback((_, _, _, _) => RaiseFailed()); + endCallback = new SyncCallback((_, _, _, _) => { if (Looping) { @@ -391,21 +395,16 @@ namespace osu.Framework.Audio.Track private void cleanUpSyncs() { - Debug.Assert(stopCallback != null - && stopSync != null - && endCallback != null - && endSync != null); - - bassMixer.ChannelRemoveSync(this, stopSync.Value); - bassMixer.ChannelRemoveSync(this, endSync.Value); + if (stopSync != null) bassMixer.ChannelRemoveSync(this, stopSync.Value); + if (endSync != null) bassMixer.ChannelRemoveSync(this, endSync.Value); stopSync = null; endSync = null; - stopCallback.Dispose(); + stopCallback?.Dispose(); stopCallback = null; - endCallback.Dispose(); + endCallback?.Dispose(); endCallback = null; } diff --git a/osu.Framework/Audio/Track/TrackStore.cs b/osu.Framework/Audio/Track/TrackStore.cs index eaca9c9df..3d3325003 100644 --- a/osu.Framework/Audio/Track/TrackStore.cs +++ b/osu.Framework/Audio/Track/TrackStore.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.IO; diff --git a/osu.Framework/Audio/Track/TrackVirtual.cs b/osu.Framework/Audio/Track/TrackVirtual.cs index aa535970f..a03b47bd6 100644 --- a/osu.Framework/Audio/Track/TrackVirtual.cs +++ b/osu.Framework/Audio/Track/TrackVirtual.cs @@ -1,7 +1,10 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; +using System.Threading.Tasks; using osu.Framework.Timing; namespace osu.Framework.Audio.Track @@ -32,6 +35,23 @@ namespace osu.Framework.Audio.Track return seekOffset == seek; } + public override Task SeekAsync(double seek) + { + return Task.FromResult(Seek(seek)); + } + + public override Task StartAsync() + { + Start(); + return Task.CompletedTask; + } + + public override Task StopAsync() + { + Stop(); + return Task.CompletedTask; + } + public override void Start() { if (Length == 0) diff --git a/osu.Framework/Audio/Track/Waveform.cs b/osu.Framework/Audio/Track/Waveform.cs index f7b5bdaaf..607843804 100644 --- a/osu.Framework/Audio/Track/Waveform.cs +++ b/osu.Framework/Audio/Track/Waveform.cs @@ -1,11 +1,14 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.IO; using System.Threading; using System.Threading.Tasks; +using JetBrains.Annotations; using ManagedBass; using osu.Framework.Utils; using osu.Framework.Audio.Callbacks; @@ -179,6 +182,7 @@ namespace osu.Framework.Audio.Track /// The number of points the resulting should contain. /// The token to cancel the task. /// An async task for the generation of the . + [ItemNotNull] public async Task GenerateResampledAsync(int pointCount, CancellationToken cancellationToken = default) { if (pointCount < 0) throw new ArgumentOutOfRangeException(nameof(pointCount)); @@ -205,6 +209,9 @@ namespace osu.Framework.Audio.Track for (int i = 0; i < filter.Length; ++i) { + if (cancellationToken.IsCancellationRequested) + return new Waveform(null); + filter[i] = (float)Blur.EvalGaussian(i, pointsPerGeneratedPoint); } @@ -217,7 +224,8 @@ namespace osu.Framework.Audio.Track while (originalPointIndex < points.Count) { - if (cancellationToken.IsCancellationRequested) break; + if (cancellationToken.IsCancellationRequested) + return new Waveform(null); int startIndex = (int)originalPointIndex - kernelWidth; int endIndex = (int)originalPointIndex + kernelWidth; @@ -239,12 +247,15 @@ namespace osu.Framework.Audio.Track point.HighIntensity += weight * points[j].HighIntensity; } - // Means - for (int c = 0; c < channels; c++) - point.Amplitude[c] /= totalWeight; - point.LowIntensity /= totalWeight; - point.MidIntensity /= totalWeight; - point.HighIntensity /= totalWeight; + if (totalWeight > 0) + { + // Means + for (int c = 0; c < channels; c++) + point.Amplitude[c] /= totalWeight; + point.LowIntensity /= totalWeight; + point.MidIntensity /= totalWeight; + point.HighIntensity /= totalWeight; + } generatedPoints.Add(point); diff --git a/osu.Framework/Bindables/AggregateBindable.cs b/osu.Framework/Bindables/AggregateBindable.cs index 1432bad46..9e327752d 100644 --- a/osu.Framework/Bindables/AggregateBindable.cs +++ b/osu.Framework/Bindables/AggregateBindable.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework/Bindables/Bindable.cs b/osu.Framework/Bindables/Bindable.cs index 8afa5e469..d621af599 100644 --- a/osu.Framework/Bindables/Bindable.cs +++ b/osu.Framework/Bindables/Bindable.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Globalization; @@ -243,7 +245,7 @@ namespace osu.Framework.Bindables Value = t; break; - case IBindable _: + case IBindable: if (!(input is IBindable bindable)) throw new ArgumentException($"Expected bindable of type {nameof(IBindable)}<{typeof(T)}>, got {input.GetType()}", nameof(input)); diff --git a/osu.Framework/Bindables/BindableBool.cs b/osu.Framework/Bindables/BindableBool.cs index 90e19345f..add13c38d 100644 --- a/osu.Framework/Bindables/BindableBool.cs +++ b/osu.Framework/Bindables/BindableBool.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Bindables { public class BindableBool : Bindable diff --git a/osu.Framework/Bindables/BindableDictionary.cs b/osu.Framework/Bindables/BindableDictionary.cs index 527c441f6..4d392987d 100644 --- a/osu.Framework/Bindables/BindableDictionary.cs +++ b/osu.Framework/Bindables/BindableDictionary.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using System; using System.Collections; using System.Collections.Generic; @@ -138,8 +136,7 @@ namespace osu.Framework.Bindables { ensureMutationAllowed(); -#nullable disable // Todo: Remove after upgrading Resharper version on CI. - bool hasPreviousValue = TryGetValue(key, out TValue lastValue); + bool hasPreviousValue = TryGetValue(key, out TValue? lastValue); collection[key] = value; @@ -153,7 +150,6 @@ namespace osu.Framework.Bindables b.setKey(key, value, this); } } -#nullable enable notifyDictionaryChanged(hasPreviousValue ? new NotifyDictionaryChangedEventArgs(new KeyValuePair(key, value), new KeyValuePair(key, lastValue!)) @@ -236,13 +232,11 @@ namespace osu.Framework.Bindables bool ICollection>.Remove(KeyValuePair item) { -#nullable disable // Todo: Remove after upgrading Resharper version on CI. - if (TryGetValue(item.Key, out TValue value) && EqualityComparer.Default.Equals(value, item.Value)) + if (TryGetValue(item.Key, out TValue? value) && EqualityComparer.Default.Equals(value, item.Value)) { Remove(item.Key); return true; } -#nullable enable return false; } diff --git a/osu.Framework/Bindables/BindableDouble.cs b/osu.Framework/Bindables/BindableDouble.cs index bbac0f8b3..0c84ce1a9 100644 --- a/osu.Framework/Bindables/BindableDouble.cs +++ b/osu.Framework/Bindables/BindableDouble.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Globalization; namespace osu.Framework.Bindables diff --git a/osu.Framework/Bindables/BindableFloat.cs b/osu.Framework/Bindables/BindableFloat.cs index 8e960f8a5..70f77b302 100644 --- a/osu.Framework/Bindables/BindableFloat.cs +++ b/osu.Framework/Bindables/BindableFloat.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Globalization; namespace osu.Framework.Bindables diff --git a/osu.Framework/Bindables/BindableInt.cs b/osu.Framework/Bindables/BindableInt.cs index 67d2056f5..096045f61 100644 --- a/osu.Framework/Bindables/BindableInt.cs +++ b/osu.Framework/Bindables/BindableInt.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Globalization; namespace osu.Framework.Bindables diff --git a/osu.Framework/Bindables/BindableList.cs b/osu.Framework/Bindables/BindableList.cs index 1399b64ca..353c24c53 100644 --- a/osu.Framework/Bindables/BindableList.cs +++ b/osu.Framework/Bindables/BindableList.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections; using System.Collections.Generic; diff --git a/osu.Framework/Bindables/BindableLong.cs b/osu.Framework/Bindables/BindableLong.cs index 63f2b5416..e7236f937 100644 --- a/osu.Framework/Bindables/BindableLong.cs +++ b/osu.Framework/Bindables/BindableLong.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Bindables { public class BindableLong : BindableNumber diff --git a/osu.Framework/Bindables/BindableMarginPadding.cs b/osu.Framework/Bindables/BindableMarginPadding.cs index 2378e2826..91169db69 100644 --- a/osu.Framework/Bindables/BindableMarginPadding.cs +++ b/osu.Framework/Bindables/BindableMarginPadding.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Globalization; using osu.Framework.Graphics; diff --git a/osu.Framework/Bindables/BindableNumber.cs b/osu.Framework/Bindables/BindableNumber.cs index babedfd3a..a94f638ad 100644 --- a/osu.Framework/Bindables/BindableNumber.cs +++ b/osu.Framework/Bindables/BindableNumber.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Diagnostics; using System.Globalization; diff --git a/osu.Framework/Bindables/BindableNumberWithCurrent.cs b/osu.Framework/Bindables/BindableNumberWithCurrent.cs index 2082ec4a4..97ccf0ab1 100644 --- a/osu.Framework/Bindables/BindableNumberWithCurrent.cs +++ b/osu.Framework/Bindables/BindableNumberWithCurrent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; namespace osu.Framework.Bindables diff --git a/osu.Framework/Bindables/BindableSafeArea.cs b/osu.Framework/Bindables/BindableSafeArea.cs index 9489e5ff9..e69a9d009 100644 --- a/osu.Framework/Bindables/BindableSafeArea.cs +++ b/osu.Framework/Bindables/BindableSafeArea.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics; namespace osu.Framework.Bindables diff --git a/osu.Framework/Bindables/BindableSize.cs b/osu.Framework/Bindables/BindableSize.cs index f2f3157fe..15952e9f2 100644 --- a/osu.Framework/Bindables/BindableSize.cs +++ b/osu.Framework/Bindables/BindableSize.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Drawing; diff --git a/osu.Framework/Bindables/BindableWithCurrent.cs b/osu.Framework/Bindables/BindableWithCurrent.cs index 1f7e05ec0..20a12987b 100644 --- a/osu.Framework/Bindables/BindableWithCurrent.cs +++ b/osu.Framework/Bindables/BindableWithCurrent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; namespace osu.Framework.Bindables diff --git a/osu.Framework/Bindables/IBindable.cs b/osu.Framework/Bindables/IBindable.cs index 80bd1ee0c..023261cf0 100644 --- a/osu.Framework/Bindables/IBindable.cs +++ b/osu.Framework/Bindables/IBindable.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Extensions.TypeExtensions; using osu.Framework.Utils; diff --git a/osu.Framework/Bindables/IBindableDictionary.cs b/osu.Framework/Bindables/IBindableDictionary.cs index bf4e1c122..7b9fe7b79 100644 --- a/osu.Framework/Bindables/IBindableDictionary.cs +++ b/osu.Framework/Bindables/IBindableDictionary.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using System.Collections.Generic; namespace osu.Framework.Bindables diff --git a/osu.Framework/Bindables/IBindableList.cs b/osu.Framework/Bindables/IBindableList.cs index 92d951834..aeeabceb2 100644 --- a/osu.Framework/Bindables/IBindableList.cs +++ b/osu.Framework/Bindables/IBindableList.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using System.Collections.Specialized; diff --git a/osu.Framework/Bindables/IBindableNumber.cs b/osu.Framework/Bindables/IBindableNumber.cs index da4ecd735..1d2679078 100644 --- a/osu.Framework/Bindables/IBindableNumber.cs +++ b/osu.Framework/Bindables/IBindableNumber.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; namespace osu.Framework.Bindables diff --git a/osu.Framework/Bindables/IBindableWithCurrent.cs b/osu.Framework/Bindables/IBindableWithCurrent.cs index 498324cb5..5c5987f7e 100644 --- a/osu.Framework/Bindables/IBindableWithCurrent.cs +++ b/osu.Framework/Bindables/IBindableWithCurrent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Graphics.UserInterface; using osu.Framework.Utils; diff --git a/osu.Framework/Bindables/ICanBeDisabled.cs b/osu.Framework/Bindables/ICanBeDisabled.cs index d6a8e55ff..ae196f905 100644 --- a/osu.Framework/Bindables/ICanBeDisabled.cs +++ b/osu.Framework/Bindables/ICanBeDisabled.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; namespace osu.Framework.Bindables diff --git a/osu.Framework/Bindables/IHasDefaultValue.cs b/osu.Framework/Bindables/IHasDefaultValue.cs index e3eee44a2..b9387d567 100644 --- a/osu.Framework/Bindables/IHasDefaultValue.cs +++ b/osu.Framework/Bindables/IHasDefaultValue.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Bindables { /// diff --git a/osu.Framework/Bindables/IHasDescription.cs b/osu.Framework/Bindables/IHasDescription.cs index a5660e15b..4865b7f7f 100644 --- a/osu.Framework/Bindables/IHasDescription.cs +++ b/osu.Framework/Bindables/IHasDescription.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Bindables { /// diff --git a/osu.Framework/Bindables/ILeasedBindable.cs b/osu.Framework/Bindables/ILeasedBindable.cs index b5f04f94f..2b21cb454 100644 --- a/osu.Framework/Bindables/ILeasedBindable.cs +++ b/osu.Framework/Bindables/ILeasedBindable.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Bindables { /// diff --git a/osu.Framework/Bindables/IParseable.cs b/osu.Framework/Bindables/IParseable.cs index c45202bb0..f6dc2455f 100644 --- a/osu.Framework/Bindables/IParseable.cs +++ b/osu.Framework/Bindables/IParseable.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Bindables { /// diff --git a/osu.Framework/Bindables/IUnbindable.cs b/osu.Framework/Bindables/IUnbindable.cs index 963b1333b..39bafa1af 100644 --- a/osu.Framework/Bindables/IUnbindable.cs +++ b/osu.Framework/Bindables/IUnbindable.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Bindables { /// diff --git a/osu.Framework/Bindables/LeasedBindable.cs b/osu.Framework/Bindables/LeasedBindable.cs index 97ca32c64..d3b965496 100644 --- a/osu.Framework/Bindables/LeasedBindable.cs +++ b/osu.Framework/Bindables/LeasedBindable.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using JetBrains.Annotations; diff --git a/osu.Framework/Bindables/NonNullableBindable.cs b/osu.Framework/Bindables/NonNullableBindable.cs index 4d376b6fa..4d0f9ac26 100644 --- a/osu.Framework/Bindables/NonNullableBindable.cs +++ b/osu.Framework/Bindables/NonNullableBindable.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; namespace osu.Framework.Bindables diff --git a/osu.Framework/Bindables/NotifyDictionaryChangedEventArgs.cs b/osu.Framework/Bindables/NotifyDictionaryChangedEventArgs.cs index ce54e67ec..7ab366883 100644 --- a/osu.Framework/Bindables/NotifyDictionaryChangedEventArgs.cs +++ b/osu.Framework/Bindables/NotifyDictionaryChangedEventArgs.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using System; using System.Collections.Generic; diff --git a/osu.Framework/Bindables/RangeConstrainedBindable.cs b/osu.Framework/Bindables/RangeConstrainedBindable.cs index 2ae5f5b77..cef619065 100644 --- a/osu.Framework/Bindables/RangeConstrainedBindable.cs +++ b/osu.Framework/Bindables/RangeConstrainedBindable.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; diff --git a/osu.Framework/Bindables/ValueChangedEvent.cs b/osu.Framework/Bindables/ValueChangedEvent.cs index 9809faf05..2f236f8f9 100644 --- a/osu.Framework/Bindables/ValueChangedEvent.cs +++ b/osu.Framework/Bindables/ValueChangedEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Bindables { /// diff --git a/osu.Framework/Caching/Cached.cs b/osu.Framework/Caching/Cached.cs index 1fccf5c2e..807175666 100644 --- a/osu.Framework/Caching/Cached.cs +++ b/osu.Framework/Caching/Cached.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Statistics; using System; diff --git a/osu.Framework/Configuration/ConfigManager.cs b/osu.Framework/Configuration/ConfigManager.cs index 4c8c1267e..b09610022 100644 --- a/osu.Framework/Configuration/ConfigManager.cs +++ b/osu.Framework/Configuration/ConfigManager.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Drawing; @@ -309,7 +311,7 @@ namespace osu.Framework.Configuration { int current = Interlocked.Increment(ref lastSave); - Task.Delay(100).ContinueWith(task => + Task.Delay(100).ContinueWith(_ => { if (current == lastSave) Save(); }); diff --git a/osu.Framework/Configuration/FrameSync.cs b/osu.Framework/Configuration/FrameSync.cs index b1418600a..a16c6d01f 100644 --- a/osu.Framework/Configuration/FrameSync.cs +++ b/osu.Framework/Configuration/FrameSync.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.ComponentModel; namespace osu.Framework.Configuration @@ -18,7 +20,7 @@ namespace osu.Framework.Configuration [Description("8x refresh rate")] Limit8x, - [Description("Unlimited")] + [Description("Basically unlimited")] Unlimited, } } diff --git a/osu.Framework/Configuration/FrameworkConfigManager.cs b/osu.Framework/Configuration/FrameworkConfigManager.cs index 63be1346a..1935204e0 100644 --- a/osu.Framework/Configuration/FrameworkConfigManager.cs +++ b/osu.Framework/Configuration/FrameworkConfigManager.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Drawing; diff --git a/osu.Framework/Configuration/FrameworkDebugConfig.cs b/osu.Framework/Configuration/FrameworkDebugConfig.cs index 87011b1d7..d0a4046cf 100644 --- a/osu.Framework/Configuration/FrameworkDebugConfig.cs +++ b/osu.Framework/Configuration/FrameworkDebugConfig.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Configuration { public class FrameworkDebugConfigManager : IniConfigManager diff --git a/osu.Framework/Configuration/IConfigManager.cs b/osu.Framework/Configuration/IConfigManager.cs index 899b63024..eb91ebeeb 100644 --- a/osu.Framework/Configuration/IConfigManager.cs +++ b/osu.Framework/Configuration/IConfigManager.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Configuration { public interface IConfigManager diff --git a/osu.Framework/Configuration/IniConfigManager.cs b/osu.Framework/Configuration/IniConfigManager.cs index ee8a9280c..9fae132a1 100644 --- a/osu.Framework/Configuration/IniConfigManager.cs +++ b/osu.Framework/Configuration/IniConfigManager.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.IO; @@ -83,7 +85,7 @@ namespace osu.Framework.Configuration try { - using (var stream = storage.GetStream(Filename, FileAccess.Write, FileMode.Create)) + using (var stream = storage.CreateFileSafely(Filename)) using (var w = new StreamWriter(stream)) { foreach (var p in ConfigStore) diff --git a/osu.Framework/Configuration/InputConfigManager.cs b/osu.Framework/Configuration/InputConfigManager.cs index 3c0d2a513..577baa931 100644 --- a/osu.Framework/Configuration/InputConfigManager.cs +++ b/osu.Framework/Configuration/InputConfigManager.cs @@ -14,8 +14,6 @@ using osu.Framework.Input.Handlers; using osu.Framework.Logging; using osu.Framework.Platform; -#nullable enable - namespace osu.Framework.Configuration { /// @@ -50,7 +48,7 @@ namespace osu.Framework.Configuration { try { - using (var stream = storage.GetStream(FILENAME, FileAccess.Write, FileMode.Create)) + using (var stream = storage.CreateFileSafely(FILENAME)) using (var sw = new StreamWriter(stream)) { sw.Write(JsonConvert.SerializeObject(this)); diff --git a/osu.Framework/Configuration/Tracking/ITrackableConfigManager.cs b/osu.Framework/Configuration/Tracking/ITrackableConfigManager.cs index aa09d40c0..40887438c 100644 --- a/osu.Framework/Configuration/Tracking/ITrackableConfigManager.cs +++ b/osu.Framework/Configuration/Tracking/ITrackableConfigManager.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Bindables; namespace osu.Framework.Configuration.Tracking diff --git a/osu.Framework/Configuration/Tracking/ITrackedSetting.cs b/osu.Framework/Configuration/Tracking/ITrackedSetting.cs index 75478b6de..7cbb84d3c 100644 --- a/osu.Framework/Configuration/Tracking/ITrackedSetting.cs +++ b/osu.Framework/Configuration/Tracking/ITrackedSetting.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Bindables; diff --git a/osu.Framework/Configuration/Tracking/SettingDescription.cs b/osu.Framework/Configuration/Tracking/SettingDescription.cs index 5c34e4dfa..610ae356d 100644 --- a/osu.Framework/Configuration/Tracking/SettingDescription.cs +++ b/osu.Framework/Configuration/Tracking/SettingDescription.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Localisation; namespace osu.Framework.Configuration.Tracking diff --git a/osu.Framework/Configuration/Tracking/TrackedSetting.cs b/osu.Framework/Configuration/Tracking/TrackedSetting.cs index d1dc61cb9..92a0afe0c 100644 --- a/osu.Framework/Configuration/Tracking/TrackedSetting.cs +++ b/osu.Framework/Configuration/Tracking/TrackedSetting.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Bindables; diff --git a/osu.Framework/Configuration/Tracking/TrackedSettings.cs b/osu.Framework/Configuration/Tracking/TrackedSettings.cs index 14b5ee2e6..95c51da45 100644 --- a/osu.Framework/Configuration/Tracking/TrackedSettings.cs +++ b/osu.Framework/Configuration/Tracking/TrackedSettings.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; diff --git a/osu.Framework/Configuration/TypedRepopulatingConverter.cs b/osu.Framework/Configuration/TypedRepopulatingConverter.cs index 9783421b6..826c74ee0 100644 --- a/osu.Framework/Configuration/TypedRepopulatingConverter.cs +++ b/osu.Framework/Configuration/TypedRepopulatingConverter.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework/Configuration/WindowMode.cs b/osu.Framework/Configuration/WindowMode.cs index 54db68723..d0a1713fa 100644 --- a/osu.Framework/Configuration/WindowMode.cs +++ b/osu.Framework/Configuration/WindowMode.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Configuration { public enum WindowMode diff --git a/osu.Framework/Development/DebugUtils.cs b/osu.Framework/Development/DebugUtils.cs index 84bb9e01d..6f97903dd 100644 --- a/osu.Framework/Development/DebugUtils.cs +++ b/osu.Framework/Development/DebugUtils.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Diagnostics; using System.Linq; diff --git a/osu.Framework/Development/ReflectionUtils.cs b/osu.Framework/Development/ReflectionUtils.cs index 4cc44a9c6..29b9d7b8f 100644 --- a/osu.Framework/Development/ReflectionUtils.cs +++ b/osu.Framework/Development/ReflectionUtils.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Linq; using System.Reflection; diff --git a/osu.Framework/Development/ThreadSafety.cs b/osu.Framework/Development/ThreadSafety.cs index 4e3f99c7b..f90e311b7 100644 --- a/osu.Framework/Development/ThreadSafety.cs +++ b/osu.Framework/Development/ThreadSafety.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Diagnostics; using osu.Framework.Platform; diff --git a/osu.Framework/Extensions/AnchorExtensions.cs b/osu.Framework/Extensions/AnchorExtensions.cs index 08aee6e90..28a9ac802 100644 --- a/osu.Framework/Extensions/AnchorExtensions.cs +++ b/osu.Framework/Extensions/AnchorExtensions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Extensions.EnumExtensions; using osu.Framework.Graphics; diff --git a/osu.Framework/Extensions/BridgingExtensions.cs b/osu.Framework/Extensions/BridgingExtensions.cs index 802de679a..2b6f8f556 100644 --- a/osu.Framework/Extensions/BridgingExtensions.cs +++ b/osu.Framework/Extensions/BridgingExtensions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Platform; using TKVector2 = osuTK.Vector2; using SNVector2 = System.Numerics.Vector2; diff --git a/osu.Framework/Extensions/Color4Extensions/Color4Extensions.cs b/osu.Framework/Extensions/Color4Extensions/Color4Extensions.cs index 7e663b642..2e1bb8fda 100644 --- a/osu.Framework/Extensions/Color4Extensions/Color4Extensions.cs +++ b/osu.Framework/Extensions/Color4Extensions/Color4Extensions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osuTK.Graphics; using System; using System.Globalization; diff --git a/osu.Framework/Extensions/EnumExtensions/EnumExtensions.cs b/osu.Framework/Extensions/EnumExtensions/EnumExtensions.cs index bbd5eff65..a40b2b578 100644 --- a/osu.Framework/Extensions/EnumExtensions/EnumExtensions.cs +++ b/osu.Framework/Extensions/EnumExtensions/EnumExtensions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework/Extensions/ExceptionExtensions/ExceptionExtensions.cs b/osu.Framework/Extensions/ExceptionExtensions/ExceptionExtensions.cs index 20bf842b2..ee3a315aa 100644 --- a/osu.Framework/Extensions/ExceptionExtensions/ExceptionExtensions.cs +++ b/osu.Framework/Extensions/ExceptionExtensions/ExceptionExtensions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Reflection; using System.Runtime.ExceptionServices; diff --git a/osu.Framework/Extensions/ExtensionMethods.cs b/osu.Framework/Extensions/ExtensionMethods.cs index c31e23c51..e1048d86a 100644 --- a/osu.Framework/Extensions/ExtensionMethods.cs +++ b/osu.Framework/Extensions/ExtensionMethods.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.ComponentModel; @@ -179,12 +181,21 @@ namespace osu.Framework.Extensions /// /// /// + /// + /// If the passed value is already of type , it will be returned. + /// /// /// When the specified in the /// does not match any of the existing members in . /// public static LocalisableString GetLocalisableDescription(this T value) { + if (value is LocalisableString localisable) + return localisable; + + if (value is string description) + return description; + MemberInfo type; if (value is Enum) @@ -222,8 +233,14 @@ namespace osu.Framework.Extensions /// /// /// + /// + /// If the passed value is already of type , it will be returned. + /// public static string GetDescription(this object value) { + if (value is string description) + return description; + Type type = value as Type ?? value.GetType(); return type.GetField(value.ToString())?.GetCustomAttribute()?.Description ?? value.ToString(); } @@ -265,8 +282,12 @@ namespace osu.Framework.Extensions /// A lower-case hex string representation of the hash (64 characters). public static string ComputeSHA2Hash(this string str) { +#if NET6_0_OR_GREATER + return SHA256.HashData(Encoding.UTF8.GetBytes(str)).toLowercaseHex(); +#else using (var alg = SHA256.Create()) return alg.ComputeHash(Encoding.UTF8.GetBytes(str)).toLowercaseHex(); +#endif } public static string ComputeMD5Hash(this Stream stream) @@ -283,8 +304,12 @@ namespace osu.Framework.Extensions public static string ComputeMD5Hash(this string input) { +#if NET6_0_OR_GREATER + return MD5.HashData(Encoding.UTF8.GetBytes(input)).toLowercaseHex(); +#else using (var md5 = MD5.Create()) return md5.ComputeHash(Encoding.UTF8.GetBytes(input)).toLowercaseHex(); +#endif } public static DisplayIndex GetIndex(this DisplayDevice display) diff --git a/osu.Framework/Extensions/IEnumerableExtensions/EnumerableExtensions.cs b/osu.Framework/Extensions/IEnumerableExtensions/EnumerableExtensions.cs index 64c5b753b..843241343 100644 --- a/osu.Framework/Extensions/IEnumerableExtensions/EnumerableExtensions.cs +++ b/osu.Framework/Extensions/IEnumerableExtensions/EnumerableExtensions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework/Extensions/ImageExtensions/ImageExtensions.cs b/osu.Framework/Extensions/ImageExtensions/ImageExtensions.cs index 2675e7e37..17e0c86f0 100644 --- a/osu.Framework/Extensions/ImageExtensions/ImageExtensions.cs +++ b/osu.Framework/Extensions/ImageExtensions/ImageExtensions.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using System.Buffers; using SixLabors.ImageSharp; using SixLabors.ImageSharp.Advanced; diff --git a/osu.Framework/Extensions/ImageExtensions/ReadOnlyPixelMemory.cs b/osu.Framework/Extensions/ImageExtensions/ReadOnlyPixelMemory.cs index f05a612bb..20b27955a 100644 --- a/osu.Framework/Extensions/ImageExtensions/ReadOnlyPixelMemory.cs +++ b/osu.Framework/Extensions/ImageExtensions/ReadOnlyPixelMemory.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using System; using System.Buffers; using System.Diagnostics; diff --git a/osu.Framework/Extensions/ImageExtensions/ReadOnlyPixelSpan.cs b/osu.Framework/Extensions/ImageExtensions/ReadOnlyPixelSpan.cs index 7afd70b00..38e45d3e8 100644 --- a/osu.Framework/Extensions/ImageExtensions/ReadOnlyPixelSpan.cs +++ b/osu.Framework/Extensions/ImageExtensions/ReadOnlyPixelSpan.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using System; using System.Buffers; using SixLabors.ImageSharp; diff --git a/osu.Framework/Extensions/ListExtensions/ListExtensions.cs b/osu.Framework/Extensions/ListExtensions/ListExtensions.cs index c80a8143a..4476ba2d6 100644 --- a/osu.Framework/Extensions/ListExtensions/ListExtensions.cs +++ b/osu.Framework/Extensions/ListExtensions/ListExtensions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using osu.Framework.Lists; diff --git a/osu.Framework/Extensions/LocalisationExtensions/LocalisableStringExtensions.cs b/osu.Framework/Extensions/LocalisationExtensions/LocalisableStringExtensions.cs index 1a7677c60..012097af0 100644 --- a/osu.Framework/Extensions/LocalisationExtensions/LocalisableStringExtensions.cs +++ b/osu.Framework/Extensions/LocalisationExtensions/LocalisableStringExtensions.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using System; using osu.Framework.Localisation; diff --git a/osu.Framework/Extensions/MatrixExtensions/MatrixExtensions.cs b/osu.Framework/Extensions/MatrixExtensions/MatrixExtensions.cs index 7a1a16fce..0e9fd8d1b 100644 --- a/osu.Framework/Extensions/MatrixExtensions/MatrixExtensions.cs +++ b/osu.Framework/Extensions/MatrixExtensions/MatrixExtensions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osuTK; diff --git a/osu.Framework/Extensions/ObjectExtensions/ObjectExtensions.cs b/osu.Framework/Extensions/ObjectExtensions/ObjectExtensions.cs index cc3437c31..2f584119e 100644 --- a/osu.Framework/Extensions/ObjectExtensions/ObjectExtensions.cs +++ b/osu.Framework/Extensions/ObjectExtensions/ObjectExtensions.cs @@ -1,9 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Diagnostics; - -#nullable enable +using System.Diagnostics.CodeAnalysis; namespace osu.Framework.Extensions.ObjectExtensions { @@ -21,11 +19,17 @@ namespace osu.Framework.Extensions.ObjectExtensions /// The nullable object. /// The type of the object. /// The non-nullable object corresponding to . - public static T AsNonNull(this T? obj) - where T : class - { - Debug.Assert(obj != null); - return obj; - } + [return: NotNull] + public static T AsNonNull(this T? obj) => obj!; + + /// + /// If the given object is null. + /// + public static bool IsNull([NotNullWhen(false)] this T obj) => ReferenceEquals(obj, null); + + /// + /// true if the given object is not null, false otherwise. + /// + public static bool IsNotNull([NotNullWhen(true)] this T obj) => !ReferenceEquals(obj, null); } } diff --git a/osu.Framework/Extensions/PlatformActionExtensions/PlatformActionExtensions.cs b/osu.Framework/Extensions/PlatformActionExtensions/PlatformActionExtensions.cs index d351a1a03..301f56ffd 100644 --- a/osu.Framework/Extensions/PlatformActionExtensions/PlatformActionExtensions.cs +++ b/osu.Framework/Extensions/PlatformActionExtensions/PlatformActionExtensions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input; namespace osu.Framework.Extensions.PlatformActionExtensions diff --git a/osu.Framework/Extensions/PolygonExtensions/ConvexPolygonExtensions.cs b/osu.Framework/Extensions/PolygonExtensions/ConvexPolygonExtensions.cs index 30334eb59..984aa022d 100644 --- a/osu.Framework/Extensions/PolygonExtensions/ConvexPolygonExtensions.cs +++ b/osu.Framework/Extensions/PolygonExtensions/ConvexPolygonExtensions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Graphics.Primitives; using osuTK; diff --git a/osu.Framework/Extensions/PolygonExtensions/PolygonExtensions.cs b/osu.Framework/Extensions/PolygonExtensions/PolygonExtensions.cs index fd6c4bfd4..7811eff40 100644 --- a/osu.Framework/Extensions/PolygonExtensions/PolygonExtensions.cs +++ b/osu.Framework/Extensions/PolygonExtensions/PolygonExtensions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Graphics.Primitives; using osuTK; diff --git a/osu.Framework/Extensions/PopoverExtensions.cs b/osu.Framework/Extensions/PopoverExtensions.cs index dcb1b6175..fa7097b4d 100644 --- a/osu.Framework/Extensions/PopoverExtensions.cs +++ b/osu.Framework/Extensions/PopoverExtensions.cs @@ -5,8 +5,6 @@ using System; using osu.Framework.Graphics; using osu.Framework.Graphics.Cursor; -#nullable enable - namespace osu.Framework.Extensions { public static class PopoverExtensions diff --git a/osu.Framework/Extensions/StreamExtensions.cs b/osu.Framework/Extensions/StreamExtensions.cs index b76676db8..846bc3b3a 100644 --- a/osu.Framework/Extensions/StreamExtensions.cs +++ b/osu.Framework/Extensions/StreamExtensions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.IO; using System.Threading; @@ -113,7 +115,13 @@ namespace osu.Framework.Extensions } } - internal static void ReadToFill(this Stream stream, Span buffer) + /// + /// Reads bytes from a stream until the provided buffer is full. + /// + /// The stream to read. + /// The buffer to read into. + /// Throws if the stream didn't have enough content to fill the buffer. + public static void ReadToFill(this Stream stream, Span buffer) { Span remainingBuffer = buffer; @@ -127,7 +135,14 @@ namespace osu.Framework.Extensions } } - internal static async Task ReadToFillAsync(this Stream stream, Memory buffer, CancellationToken cancellationToken = default) + /// + /// Reads bytes from a stream until the provided buffer is full. + /// + /// The stream to read. + /// The buffer to read into. + /// A cancellation token. + /// Throws if the stream didn't have enough content to fill the buffer. + public static async Task ReadToFillAsync(this Stream stream, Memory buffer, CancellationToken cancellationToken = default) { Memory remainingBuffer = buffer; diff --git a/osu.Framework/Extensions/TaskExtensions.cs b/osu.Framework/Extensions/TaskExtensions.cs index 7f27bb375..9536f40c7 100644 --- a/osu.Framework/Extensions/TaskExtensions.cs +++ b/osu.Framework/Extensions/TaskExtensions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Threading; using System.Threading.Tasks; diff --git a/osu.Framework/Extensions/TypeExtensions/TypeExtensions.cs b/osu.Framework/Extensions/TypeExtensions/TypeExtensions.cs index a64c4bbd7..325c34f07 100644 --- a/osu.Framework/Extensions/TypeExtensions/TypeExtensions.cs +++ b/osu.Framework/Extensions/TypeExtensions/TypeExtensions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -92,8 +94,15 @@ namespace osu.Framework.Extensions.TypeExtensions /// /// Determines whether the specified type is a type. + /// + /// https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/nullable-types/how-to-identify-a-nullable-type + /// /// - /// See: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/nullable-types/how-to-identify-a-nullable-type + /// + /// When nullable reference types are enabled, prefer to use one of: + /// , , , or , + /// in order to properly handle events/properties/fields/parameters. + /// public static bool IsNullable(this Type type) => type.GetUnderlyingNullableType() != null; /// @@ -110,6 +119,90 @@ namespace osu.Framework.Extensions.TypeExtensions // ReSharper disable once ConvertClosureToMethodGroup (see: https://github.com/dotnet/runtime/issues/33747) return underlying_type_cache.GetOrAdd(type, t => Nullable.GetUnderlyingType(t)); } + + /// + /// Determines whether the type of an event is nullable. + /// + /// + /// Will be false for reference types if nullable reference types are not enabled. + /// + /// The event. + /// Whether the event type is nullable. + public static bool IsNullable(this EventInfo eventInfo) + { + if (IsNullable(eventInfo.EventHandlerType)) + return true; + +#if NET6_0_OR_GREATER + return isNullableInfo(new NullabilityInfoContext().Create(eventInfo)); +#else + return false; +#endif + } + + /// + /// Determines whether the type of a parameter is nullable. + /// + /// + /// Will be false for reference types if nullable reference types are not enabled. + /// + /// The parameter. + /// Whether the parameter type is nullable. + public static bool IsNullable(this ParameterInfo parameterInfo) + { + if (IsNullable(parameterInfo.ParameterType)) + return true; + +#if NET6_0_OR_GREATER + return isNullableInfo(new NullabilityInfoContext().Create(parameterInfo)); +#else + return false; +#endif + } + + /// + /// Determines whether the type of a field is nullable. + /// + /// + /// Will be false for reference types if nullable reference types are not enabled. + /// + /// The field. + /// Whether the field type is nullable. + public static bool IsNullable(this FieldInfo fieldInfo) + { + if (IsNullable(fieldInfo.FieldType)) + return true; + +#if NET6_0_OR_GREATER + return isNullableInfo(new NullabilityInfoContext().Create(fieldInfo)); +#else + return false; +#endif + } + + /// + /// Determines whether the type of a property is nullable. + /// + /// + /// Will be false for reference types if nullable reference types are not enabled. + /// + /// The property. + /// Whether the property type is nullable. + public static bool IsNullable(this PropertyInfo propertyInfo) + { + if (IsNullable(propertyInfo.PropertyType)) + return true; + +#if NET6_0_OR_GREATER + return isNullableInfo(new NullabilityInfoContext().Create(propertyInfo)); +#else + return false; +#endif + } + +#if NET6_0_OR_GREATER + private static bool isNullableInfo(NullabilityInfo info) => info.WriteState == NullabilityState.Nullable || info.ReadState == NullabilityState.Nullable; +#endif } [Flags] diff --git a/osu.Framework/Game.cs b/osu.Framework/Game.cs index efe2dab27..712ad82b1 100644 --- a/osu.Framework/Game.cs +++ b/osu.Framework/Game.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using osu.Framework.Allocation; @@ -21,6 +23,7 @@ using osu.Framework.IO.Stores; using osu.Framework.Localisation; using osu.Framework.Platform; using osuTK; +using osuTK.Graphics.ES30; namespace osu.Framework { @@ -32,6 +35,11 @@ namespace osu.Framework public TextureStore Textures { get; private set; } + /// + /// The filtering mode to use for all textures fetched from . + /// + protected virtual TextureFilteringMode DefaultTextureFilteringMode => TextureFilteringMode.Linear; + protected GameHost Host { get; private set; } private readonly Bindable isActive = new Bindable(true); @@ -115,7 +123,7 @@ namespace osu.Framework public virtual void SetHost(GameHost host) { Host = host; - host.Exiting += OnExiting; + host.ExitRequested += RequestExit; host.Activated += () => isActive.Value = true; host.Deactivated += () => isActive.Value = false; } @@ -131,8 +139,10 @@ namespace osu.Framework Resources = new ResourceStore(); Resources.AddStore(new NamespacedResourceStore(new DllResourceStore(typeof(Game).Assembly), @"Resources")); - Textures = new TextureStore(Host.CreateTextureLoaderStore(new NamespacedResourceStore(Resources, @"Textures"))); - Textures.AddStore(Host.CreateTextureLoaderStore(new OnlineStore())); + Textures = new TextureStore(Host.CreateTextureLoaderStore(new NamespacedResourceStore(Resources, @"Textures")), + filteringMode: DefaultTextureFilteringMode == TextureFilteringMode.Linear ? All.Linear : All.Nearest); + + Textures.AddTextureSource(Host.CreateTextureLoaderStore(new OnlineStore())); dependencies.Cache(Textures); var tracks = new ResourceStore(); @@ -222,7 +232,7 @@ namespace osu.Framework => addFont(target ?? Fonts, store, assetName); private void addFont(FontStore target, ResourceStore store, string assetName = null) - => target.AddStore(new RawCachingGlyphStore(store, assetName, Host.CreateTextureLoaderStore(store))); + => target.AddTextureSource(new RawCachingGlyphStore(store, assetName, Host.CreateTextureLoaderStore(store))); protected override void LoadComplete() { @@ -381,7 +391,7 @@ namespace osu.Framework switch (e.Action) { case PlatformAction.Exit: - Host.Window?.RequestClose(); + RequestExit(); return true; } @@ -392,6 +402,18 @@ namespace osu.Framework { } + /// + /// Requests the game to exit. This exit can be blocked by . + /// + public void RequestExit() + { + if (!OnExiting()) + Exit(); + } + + /// + /// Force-closes the game, ignoring return value. + /// public void Exit() { if (Host == null) @@ -401,8 +423,9 @@ namespace osu.Framework } /// - /// Fired when the game host signals that an exit has been requested. + /// Fired when an exit has been requested. /// + /// Usually fired because or the window close (X) button was pressed. /// Return true to block the exit process. protected virtual bool OnExiting() => false; diff --git a/osu.Framework/Graphics/Animations/Animation.cs b/osu.Framework/Graphics/Animations/Animation.cs index 7df6dee86..1831c0677 100644 --- a/osu.Framework/Graphics/Animations/Animation.cs +++ b/osu.Framework/Graphics/Animations/Animation.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework/Graphics/Animations/AnimationClockComposite.cs b/osu.Framework/Graphics/Animations/AnimationClockComposite.cs index e62a43ade..e4bc7d79b 100644 --- a/osu.Framework/Graphics/Animations/AnimationClockComposite.cs +++ b/osu.Framework/Graphics/Animations/AnimationClockComposite.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Allocation; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework/Graphics/Animations/CustomisableSizeCompositeDrawable.cs b/osu.Framework/Graphics/Animations/CustomisableSizeCompositeDrawable.cs index a2062e514..8bc20c1d3 100644 --- a/osu.Framework/Graphics/Animations/CustomisableSizeCompositeDrawable.cs +++ b/osu.Framework/Graphics/Animations/CustomisableSizeCompositeDrawable.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.Containers; using osuTK; diff --git a/osu.Framework/Graphics/Animations/DrawableAnimation.cs b/osu.Framework/Graphics/Animations/DrawableAnimation.cs index 17065c7d6..135f97d00 100644 --- a/osu.Framework/Graphics/Animations/DrawableAnimation.cs +++ b/osu.Framework/Graphics/Animations/DrawableAnimation.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Linq; using osu.Framework.Graphics.Containers; using osuTK; diff --git a/osu.Framework/Graphics/Animations/FrameData.cs b/osu.Framework/Graphics/Animations/FrameData.cs index dce57242d..08ecf11aa 100644 --- a/osu.Framework/Graphics/Animations/FrameData.cs +++ b/osu.Framework/Graphics/Animations/FrameData.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Graphics.Animations { /// diff --git a/osu.Framework/Graphics/Animations/FramedAnimationExtensions.cs b/osu.Framework/Graphics/Animations/FramedAnimationExtensions.cs index 4198fe579..7228ff1a4 100644 --- a/osu.Framework/Graphics/Animations/FramedAnimationExtensions.cs +++ b/osu.Framework/Graphics/Animations/FramedAnimationExtensions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Graphics.Animations { /// diff --git a/osu.Framework/Graphics/Animations/IAnimation.cs b/osu.Framework/Graphics/Animations/IAnimation.cs index d51577842..ad2b39f83 100644 --- a/osu.Framework/Graphics/Animations/IAnimation.cs +++ b/osu.Framework/Graphics/Animations/IAnimation.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Graphics.Animations { /// diff --git a/osu.Framework/Graphics/Animations/IFramedAnimation.cs b/osu.Framework/Graphics/Animations/IFramedAnimation.cs index 47f591383..defb6d64c 100644 --- a/osu.Framework/Graphics/Animations/IFramedAnimation.cs +++ b/osu.Framework/Graphics/Animations/IFramedAnimation.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Graphics.Animations { /// diff --git a/osu.Framework/Graphics/Animations/TextureAnimation.cs b/osu.Framework/Graphics/Animations/TextureAnimation.cs index b514100ad..6c2c2bc50 100644 --- a/osu.Framework/Graphics/Animations/TextureAnimation.cs +++ b/osu.Framework/Graphics/Animations/TextureAnimation.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osuTK; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Textures; diff --git a/osu.Framework/Graphics/Audio/DrawableAudioMixer.cs b/osu.Framework/Graphics/Audio/DrawableAudioMixer.cs index 8e6cd3ee0..23c038216 100644 --- a/osu.Framework/Graphics/Audio/DrawableAudioMixer.cs +++ b/osu.Framework/Graphics/Audio/DrawableAudioMixer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Diagnostics; using ManagedBass; using osu.Framework.Allocation; diff --git a/osu.Framework/Graphics/Audio/DrawableAudioWrapper.cs b/osu.Framework/Graphics/Audio/DrawableAudioWrapper.cs index 11306fd56..924a79ffb 100644 --- a/osu.Framework/Graphics/Audio/DrawableAudioWrapper.cs +++ b/osu.Framework/Graphics/Audio/DrawableAudioWrapper.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using JetBrains.Annotations; using osu.Framework.Allocation; diff --git a/osu.Framework/Graphics/Audio/DrawableSample.cs b/osu.Framework/Graphics/Audio/DrawableSample.cs index ba739864a..c6e0e9666 100644 --- a/osu.Framework/Graphics/Audio/DrawableSample.cs +++ b/osu.Framework/Graphics/Audio/DrawableSample.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using osu.Framework.Audio.Mixing; using osu.Framework.Audio.Sample; using osu.Framework.Bindables; diff --git a/osu.Framework/Graphics/Audio/DrawableTrack.cs b/osu.Framework/Graphics/Audio/DrawableTrack.cs index a0b4545ac..b02eb0028 100644 --- a/osu.Framework/Graphics/Audio/DrawableTrack.cs +++ b/osu.Framework/Graphics/Audio/DrawableTrack.cs @@ -1,9 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using System; +using System.Threading.Tasks; using osu.Framework.Audio; using osu.Framework.Audio.Mixing; using osu.Framework.Audio.Track; @@ -95,6 +94,14 @@ namespace osu.Framework.Graphics.Audio RemoveAllAdjustments(AdjustableProperty.Tempo); } + public Task RestartAsync() => track.RestartAsync(); + + public Task SeekAsync(double seek) => track.SeekAsync(seek); + + public Task StartAsync() => track.StartAsync(); + + public Task StopAsync() => track.StopAsync(); + public bool Seek(double seek) => track.Seek(seek); public void Start() => track.Start(); diff --git a/osu.Framework/Graphics/Audio/WaveformGraph.cs b/osu.Framework/Graphics/Audio/WaveformGraph.cs index 7dfe5f6a8..4a6b7a34c 100644 --- a/osu.Framework/Graphics/Audio/WaveformGraph.cs +++ b/osu.Framework/Graphics/Audio/WaveformGraph.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; @@ -10,17 +12,16 @@ using osu.Framework.Audio.Track; using osu.Framework.Extensions; using osu.Framework.Graphics.Batches; using osu.Framework.Graphics.Colour; +using osu.Framework.Graphics.OpenGL; using osu.Framework.Graphics.OpenGL.Vertices; using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Shaders; using osu.Framework.Graphics.Textures; -using osuTK; -using osu.Framework.Graphics.OpenGL; using osu.Framework.Layout; +using osu.Framework.Logging; using osu.Framework.Utils; -using osu.Framework.Threading; +using osuTK; using osuTK.Graphics; -using RectangleF = osu.Framework.Graphics.Primitives.RectangleF; namespace osu.Framework.Graphics.Audio { @@ -60,7 +61,8 @@ namespace osu.Framework.Graphics.Audio return; resolution = value; - generate(); + resampledPointCount = null; + queueRegeneration(); } } @@ -78,7 +80,8 @@ namespace osu.Framework.Graphics.Audio return; waveform = value; - generate(); + resampledPointCount = null; + queueRegeneration(); } } @@ -168,60 +171,74 @@ namespace osu.Framework.Graphics.Audio if ((invalidation & Invalidation.RequiredParentSizeToFit) > 0) { - generate(); - result = true; + // We should regenerate when `Scale` changed, but not `Position`. + // Unfortunately both of these are grouped together in `MiscGeometry`. + queueRegeneration(); } return result; } private CancellationTokenSource cancelSource = new CancellationTokenSource(); - private ScheduledDelegate scheduledGenerate; + private long resampledVersion; private List resampledPoints; + private int? resampledPointCount; private int resampledChannels; private double resampledMaxHighIntensity; private double resampledMaxMidIntensity; private double resampledMaxLowIntensity; - private void generate() + private void queueRegeneration() => Scheduler.AddOnce(() => { - scheduledGenerate?.Cancel(); + int requiredPointCount = (int)Math.Max(0, Math.Ceiling(DrawWidth * Scale.X) * Resolution); + if (requiredPointCount == resampledPointCount) + return; + cancelGeneration(); if (Waveform == null) return; - scheduledGenerate = Schedule(() => - { - cancelSource = new CancellationTokenSource(); - var token = cancelSource.Token; + // This should be set before the operation is run. + // It will stop unnecessary task churn if invalidation is occuring often. + resampledPointCount = requiredPointCount; - Waveform.GenerateResampledAsync((int)Math.Max(0, Math.Ceiling(DrawWidth * Scale.X) * Resolution), token).ContinueWith(task => - { - var resampled = task.GetResultSafely(); + Logger.Log($"Waveform resampling with {requiredPointCount} points..."); - var points = resampled.GetPoints(); - int channels = resampled.GetChannels(); - double maxHighIntensity = points.Count > 0 ? points.Max(p => p.HighIntensity) : 0; - double maxMidIntensity = points.Count > 0 ? points.Max(p => p.MidIntensity) : 0; - double maxLowIntensity = points.Count > 0 ? points.Max(p => p.LowIntensity) : 0; + cancelSource = new CancellationTokenSource(); + var token = cancelSource.Token; - Schedule(() => + Waveform.GenerateResampledAsync(resampledPointCount.Value, token) + .ContinueWith(task => { - resampledPoints = points; - resampledChannels = channels; - resampledMaxHighIntensity = maxHighIntensity; - resampledMaxMidIntensity = maxMidIntensity; - resampledMaxLowIntensity = maxLowIntensity; + var resampled = task.GetResultSafely(); - OnWaveformRegenerated(resampled); + var points = resampled.GetPoints(); + int channels = resampled.GetChannels(); + double maxHighIntensity = points.Count > 0 ? points.Max(p => p.HighIntensity) : 0; + double maxMidIntensity = points.Count > 0 ? points.Max(p => p.MidIntensity) : 0; + double maxLowIntensity = points.Count > 0 ? points.Max(p => p.LowIntensity) : 0; - Invalidate(Invalidation.DrawNode); - }); - }, token); - }); - } + Logger.Log($"Waveform resample complete with {points.Count} points."); + + Schedule(() => + { + if (token.IsCancellationRequested) + return; + + resampledPoints = points; + resampledChannels = channels; + resampledMaxHighIntensity = maxHighIntensity; + resampledMaxMidIntensity = maxMidIntensity; + resampledMaxLowIntensity = maxLowIntensity; + resampledVersion = InvalidationID; + + OnWaveformRegenerated(resampled); + Invalidate(Invalidation.DrawNode); + }); + }, token); + }); private void cancelGeneration() { @@ -256,6 +273,8 @@ namespace osu.Framework.Graphics.Audio private Vector2 drawSize; private int channels; + private long version; + private Color4 baseColour; private Color4 lowColour; private Color4 midColour; @@ -280,20 +299,27 @@ namespace osu.Framework.Graphics.Audio texture = Source.texture; drawSize = Source.DrawSize; - points.Clear(); - - if (Source.resampledPoints != null) - points.AddRange(Source.resampledPoints); - - channels = Source.resampledChannels; - highMax = Source.resampledMaxHighIntensity; - midMax = Source.resampledMaxMidIntensity; - lowMax = Source.resampledMaxLowIntensity; - baseColour = Source.baseColour; + lowColour = Source.lowColour ?? baseColour; midColour = Source.midColour ?? baseColour; highColour = Source.highColour ?? baseColour; + + if (Source.resampledVersion != version) + { + points.Clear(); + + if (Source.resampledPoints != null) + points.AddRange(Source.resampledPoints); + + channels = Source.resampledChannels; + + highMax = Source.resampledMaxHighIntensity; + midMax = Source.resampledMaxMidIntensity; + lowMax = Source.resampledMaxLowIntensity; + + version = Source.resampledVersion; + } } private readonly QuadBatch vertexBatch = new QuadBatch(1000, 10); diff --git a/osu.Framework/Graphics/Batches/IVertexBatch.cs b/osu.Framework/Graphics/Batches/IVertexBatch.cs index c06a41fc2..b1990c4c9 100644 --- a/osu.Framework/Graphics/Batches/IVertexBatch.cs +++ b/osu.Framework/Graphics/Batches/IVertexBatch.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Graphics.Batches { public interface IVertexBatch diff --git a/osu.Framework/Graphics/Batches/LinearBatch.cs b/osu.Framework/Graphics/Batches/LinearBatch.cs index 67a8ee211..d08fae781 100644 --- a/osu.Framework/Graphics/Batches/LinearBatch.cs +++ b/osu.Framework/Graphics/Batches/LinearBatch.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Graphics.OpenGL.Buffers; using osuTK.Graphics.ES30; diff --git a/osu.Framework/Graphics/Batches/QuadBatch.cs b/osu.Framework/Graphics/Batches/QuadBatch.cs index 10f1bbb9a..11bd67e24 100644 --- a/osu.Framework/Graphics/Batches/QuadBatch.cs +++ b/osu.Framework/Graphics/Batches/QuadBatch.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Graphics.OpenGL.Buffers; using osu.Framework.Graphics.OpenGL.Vertices; diff --git a/osu.Framework/Graphics/Batches/VertexBatch.cs b/osu.Framework/Graphics/Batches/VertexBatch.cs index 08fb190f6..cfae17b1c 100644 --- a/osu.Framework/Graphics/Batches/VertexBatch.cs +++ b/osu.Framework/Graphics/Batches/VertexBatch.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/osu.Framework/Graphics/BlendingEquation.cs b/osu.Framework/Graphics/BlendingEquation.cs index eb2f8c9ba..2c962d8a3 100644 --- a/osu.Framework/Graphics/BlendingEquation.cs +++ b/osu.Framework/Graphics/BlendingEquation.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Graphics { public enum BlendingEquation diff --git a/osu.Framework/Graphics/BlendingParameters.cs b/osu.Framework/Graphics/BlendingParameters.cs index 5b0d48fd1..1721dab3a 100644 --- a/osu.Framework/Graphics/BlendingParameters.cs +++ b/osu.Framework/Graphics/BlendingParameters.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Diagnostics.CodeAnalysis; using osuTK.Graphics.ES30; diff --git a/osu.Framework/Graphics/BlendingType.cs b/osu.Framework/Graphics/BlendingType.cs index 7df192149..f9ea3c5f9 100644 --- a/osu.Framework/Graphics/BlendingType.cs +++ b/osu.Framework/Graphics/BlendingType.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Graphics { public enum BlendingType diff --git a/osu.Framework/Graphics/BufferedDrawNode.cs b/osu.Framework/Graphics/BufferedDrawNode.cs index 5d24818ab..96aa65e24 100644 --- a/osu.Framework/Graphics/BufferedDrawNode.cs +++ b/osu.Framework/Graphics/BufferedDrawNode.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Allocation; using osu.Framework.Graphics.OpenGL; diff --git a/osu.Framework/Graphics/BufferedDrawNodeSharedData.cs b/osu.Framework/Graphics/BufferedDrawNodeSharedData.cs index 308d76d20..9256ce908 100644 --- a/osu.Framework/Graphics/BufferedDrawNodeSharedData.cs +++ b/osu.Framework/Graphics/BufferedDrawNodeSharedData.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Graphics.OpenGL; using osu.Framework.Graphics.OpenGL.Buffers; diff --git a/osu.Framework/Graphics/Colour/ColourInfo.cs b/osu.Framework/Graphics/Colour/ColourInfo.cs index eeafe6a60..a65f2f3cd 100644 --- a/osu.Framework/Graphics/Colour/ColourInfo.cs +++ b/osu.Framework/Graphics/Colour/ColourInfo.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osuTK; using osu.Framework.Graphics.Primitives; diff --git a/osu.Framework/Graphics/Colour/SRGBColour.cs b/osu.Framework/Graphics/Colour/SRGBColour.cs index e988c13e0..88ec2f0be 100644 --- a/osu.Framework/Graphics/Colour/SRGBColour.cs +++ b/osu.Framework/Graphics/Colour/SRGBColour.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osuTK; using osuTK.Graphics; using osu.Framework.Extensions.Color4Extensions; diff --git a/osu.Framework/Graphics/Colour4.cs b/osu.Framework/Graphics/Colour4.cs index e83972c31..9421d8b3c 100644 --- a/osu.Framework/Graphics/Colour4.cs +++ b/osu.Framework/Graphics/Colour4.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Globalization; using System.Numerics; diff --git a/osu.Framework/Graphics/Component.cs b/osu.Framework/Graphics/Component.cs index 3752ecb92..05506d318 100644 --- a/osu.Framework/Graphics/Component.cs +++ b/osu.Framework/Graphics/Component.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Graphics { /// diff --git a/osu.Framework/Graphics/Containers/AudioContainer.cs b/osu.Framework/Graphics/Containers/AudioContainer.cs index 52acecf31..bcb19bb9d 100644 --- a/osu.Framework/Graphics/Containers/AudioContainer.cs +++ b/osu.Framework/Graphics/Containers/AudioContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections; using System.Collections.Generic; diff --git a/osu.Framework/Graphics/Containers/BasicScrollContainer.cs b/osu.Framework/Graphics/Containers/BasicScrollContainer.cs index 01b76abcf..1e3457ac1 100644 --- a/osu.Framework/Graphics/Containers/BasicScrollContainer.cs +++ b/osu.Framework/Graphics/Containers/BasicScrollContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.Shapes; using osuTK; diff --git a/osu.Framework/Graphics/Containers/BufferedContainer.cs b/osu.Framework/Graphics/Containers/BufferedContainer.cs index cb3f08441..36d74fef3 100644 --- a/osu.Framework/Graphics/Containers/BufferedContainer.cs +++ b/osu.Framework/Graphics/Containers/BufferedContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osuTK; using osuTK.Graphics; using osuTK.Graphics.ES30; diff --git a/osu.Framework/Graphics/Containers/BufferedContainer_DrawNode.cs b/osu.Framework/Graphics/Containers/BufferedContainer_DrawNode.cs index 13514236c..69714456a 100644 --- a/osu.Framework/Graphics/Containers/BufferedContainer_DrawNode.cs +++ b/osu.Framework/Graphics/Containers/BufferedContainer_DrawNode.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using osu.Framework.Graphics.OpenGL; using osu.Framework.Graphics.OpenGL.Buffers; diff --git a/osu.Framework/Graphics/Containers/CircularContainer.cs b/osu.Framework/Graphics/Containers/CircularContainer.cs index ed2a14e85..558a39f32 100644 --- a/osu.Framework/Graphics/Containers/CircularContainer.cs +++ b/osu.Framework/Graphics/Containers/CircularContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; namespace osu.Framework.Graphics.Containers diff --git a/osu.Framework/Graphics/Containers/ClickableContainer.cs b/osu.Framework/Graphics/Containers/ClickableContainer.cs index 8d5e15a9e..c5aa07d1c 100644 --- a/osu.Framework/Graphics/Containers/ClickableContainer.cs +++ b/osu.Framework/Graphics/Containers/ClickableContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Bindables; using osu.Framework.Input.Events; diff --git a/osu.Framework/Graphics/Containers/CompositeDrawable.cs b/osu.Framework/Graphics/Containers/CompositeDrawable.cs index 3e1b951dc..df1db1eaf 100644 --- a/osu.Framework/Graphics/Containers/CompositeDrawable.cs +++ b/osu.Framework/Graphics/Containers/CompositeDrawable.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Lists; using System.Collections.Generic; using System; @@ -358,7 +360,10 @@ namespace osu.Framework.Graphics.Containers get { if (InternalChildren.Count != 1) - throw new InvalidOperationException($"Cannot call {nameof(InternalChild)} unless there's exactly one {nameof(Drawable)} in {nameof(InternalChildren)} (currently {InternalChildren.Count})!"); + { + throw new InvalidOperationException( + $"Cannot call {nameof(InternalChild)} unless there's exactly one {nameof(Drawable)} in {nameof(InternalChildren)} (currently {InternalChildren.Count})!"); + } return InternalChildren[0]; } @@ -1331,8 +1336,11 @@ namespace osu.Framework.Graphics.Containers if (propagateChildren) { - foreach (var c in internalChildren) - c.FinishTransforms(true, targetMember); + // Use for over foreach as collection may grow due to abort / completion events. + // Note that this may mean that in the addition of elements being removed, + // `FinishTransforms` may not be called on all items. + for (int i = 0; i < internalChildren.Count; i++) + internalChildren[i].FinishTransforms(true, targetMember); } } @@ -1715,8 +1723,13 @@ namespace osu.Framework.Graphics.Containers /// The coordinate space to tween to. /// The tween duration. /// The tween easing. - protected TransformSequence TransformRelativeChildSizeTo(Vector2 newSize, double duration = 0, Easing easing = Easing.None) => - this.TransformTo(nameof(RelativeChildSize), newSize, duration, easing); + protected TransformSequence TransformRelativeChildSizeTo(Vector2 newSize, double duration = 0, Easing easing = Easing.None) + { + if (newSize.X == 0 || newSize.Y == 0) + throw new ArgumentException($@"{nameof(newSize)} must be non-zero, but is {newSize}.", nameof(newSize)); + + return this.TransformTo(nameof(RelativeChildSize), newSize, duration, easing); + } /// /// Tweens the of this . diff --git a/osu.Framework/Graphics/Containers/CompositeDrawable_DrawNode.cs b/osu.Framework/Graphics/Containers/CompositeDrawable_DrawNode.cs index 6d71dfc12..b6311b55d 100644 --- a/osu.Framework/Graphics/Containers/CompositeDrawable_DrawNode.cs +++ b/osu.Framework/Graphics/Containers/CompositeDrawable_DrawNode.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using osu.Framework.Graphics.OpenGL; using osu.Framework.Graphics.Primitives; @@ -89,7 +91,7 @@ namespace osu.Framework.Graphics.Containers shrunkDrawRectangle = shrunkDrawRectangle.Shrink(new Vector2(Math.Min(shrunkDrawRectangle.Width / 2, shrinkage), Math.Min(shrunkDrawRectangle.Height / 2, shrinkage))); maskingInfo = !Source.Masking - ? (MaskingInfo?)null + ? null : new MaskingInfo { ScreenSpaceAABB = Source.ScreenSpaceDrawQuad.AABB, diff --git a/osu.Framework/Graphics/Containers/Container.cs b/osu.Framework/Graphics/Containers/Container.cs index f212eeaa1..1e768caeb 100644 --- a/osu.Framework/Graphics/Containers/Container.cs +++ b/osu.Framework/Graphics/Containers/Container.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Lists; using System.Collections.Generic; using System; diff --git a/osu.Framework/Graphics/Containers/ContainerExtensions.cs b/osu.Framework/Graphics/Containers/ContainerExtensions.cs index 72730b190..9a45afa68 100644 --- a/osu.Framework/Graphics/Containers/ContainerExtensions.cs +++ b/osu.Framework/Graphics/Containers/ContainerExtensions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osuTK; using System; using System.Collections.Generic; diff --git a/osu.Framework/Graphics/Containers/CustomizableTextChunk.cs b/osu.Framework/Graphics/Containers/CustomizableTextChunk.cs index b7c3acee8..52ec443aa 100644 --- a/osu.Framework/Graphics/Containers/CustomizableTextChunk.cs +++ b/osu.Framework/Graphics/Containers/CustomizableTextChunk.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework/Graphics/Containers/CustomizableTextContainer.cs b/osu.Framework/Graphics/Containers/CustomizableTextContainer.cs index 7dc80ee67..840d7275b 100644 --- a/osu.Framework/Graphics/Containers/CustomizableTextContainer.cs +++ b/osu.Framework/Graphics/Containers/CustomizableTextContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using osu.Framework.Localisation; diff --git a/osu.Framework/Graphics/Containers/DelayedLoadUnloadWrapper.cs b/osu.Framework/Graphics/Containers/DelayedLoadUnloadWrapper.cs index e6c57998b..53bc8f505 100644 --- a/osu.Framework/Graphics/Containers/DelayedLoadUnloadWrapper.cs +++ b/osu.Framework/Graphics/Containers/DelayedLoadUnloadWrapper.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Statistics; using System.Diagnostics; diff --git a/osu.Framework/Graphics/Containers/DelayedLoadWrapper.cs b/osu.Framework/Graphics/Containers/DelayedLoadWrapper.cs index 8f3f4ed9f..92b9d89ae 100644 --- a/osu.Framework/Graphics/Containers/DelayedLoadWrapper.cs +++ b/osu.Framework/Graphics/Containers/DelayedLoadWrapper.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Threading; using osu.Framework.Allocation; diff --git a/osu.Framework/Graphics/Containers/DrawSizePreservingFillContainer.cs b/osu.Framework/Graphics/Containers/DrawSizePreservingFillContainer.cs index 8c3613d6c..730b3d168 100644 --- a/osu.Framework/Graphics/Containers/DrawSizePreservingFillContainer.cs +++ b/osu.Framework/Graphics/Containers/DrawSizePreservingFillContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osuTK; diff --git a/osu.Framework/Graphics/Containers/FillFlowContainer.cs b/osu.Framework/Graphics/Containers/FillFlowContainer.cs index 706891de1..113e428af 100644 --- a/osu.Framework/Graphics/Containers/FillFlowContainer.cs +++ b/osu.Framework/Graphics/Containers/FillFlowContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Buffers; using System.Collections.Generic; diff --git a/osu.Framework/Graphics/Containers/FlowContainer.cs b/osu.Framework/Graphics/Containers/FlowContainer.cs index 930e00980..7bfa358e3 100644 --- a/osu.Framework/Graphics/Containers/FlowContainer.cs +++ b/osu.Framework/Graphics/Containers/FlowContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/osu.Framework/Graphics/Containers/FocusedOverlayContainer.cs b/osu.Framework/Graphics/Containers/FocusedOverlayContainer.cs index 6515ff9e6..a17ceed87 100644 --- a/osu.Framework/Graphics/Containers/FocusedOverlayContainer.cs +++ b/osu.Framework/Graphics/Containers/FocusedOverlayContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Graphics.Containers { /// diff --git a/osu.Framework/Graphics/Containers/GridContainer.cs b/osu.Framework/Graphics/Containers/GridContainer.cs index 7fcc9cbdb..64752f0c8 100644 --- a/osu.Framework/Graphics/Containers/GridContainer.cs +++ b/osu.Framework/Graphics/Containers/GridContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework/Graphics/Containers/GridContainerContent.cs b/osu.Framework/Graphics/Containers/GridContainerContent.cs index a487db437..26f96223a 100644 --- a/osu.Framework/Graphics/Containers/GridContainerContent.cs +++ b/osu.Framework/Graphics/Containers/GridContainerContent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using JetBrains.Annotations; using osu.Framework.Lists; diff --git a/osu.Framework/Graphics/Containers/IBufferedContainer.cs b/osu.Framework/Graphics/Containers/IBufferedContainer.cs index 8fba37ff0..8809959d1 100644 --- a/osu.Framework/Graphics/Containers/IBufferedContainer.cs +++ b/osu.Framework/Graphics/Containers/IBufferedContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osuTK; namespace osu.Framework.Graphics.Containers diff --git a/osu.Framework/Graphics/Containers/IContainer.cs b/osu.Framework/Graphics/Containers/IContainer.cs index e84375451..415821f23 100644 --- a/osu.Framework/Graphics/Containers/IContainer.cs +++ b/osu.Framework/Graphics/Containers/IContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osuTK; using System; using System.Collections.Generic; diff --git a/osu.Framework/Graphics/Containers/IFillFlowContainer.cs b/osu.Framework/Graphics/Containers/IFillFlowContainer.cs index 84160cd13..13bbf0b7f 100644 --- a/osu.Framework/Graphics/Containers/IFillFlowContainer.cs +++ b/osu.Framework/Graphics/Containers/IFillFlowContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.Transforms; using osuTK; diff --git a/osu.Framework/Graphics/Containers/IFilterable.cs b/osu.Framework/Graphics/Containers/IFilterable.cs index 51447c819..bd0a8851c 100644 --- a/osu.Framework/Graphics/Containers/IFilterable.cs +++ b/osu.Framework/Graphics/Containers/IFilterable.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Graphics.Containers { public interface IFilterable : IHasFilterTerms diff --git a/osu.Framework/Graphics/Containers/IHasFilterTerms.cs b/osu.Framework/Graphics/Containers/IHasFilterTerms.cs index 5c72edc1a..6983177bb 100644 --- a/osu.Framework/Graphics/Containers/IHasFilterTerms.cs +++ b/osu.Framework/Graphics/Containers/IHasFilterTerms.cs @@ -1,7 +1,10 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; +using osu.Framework.Localisation; namespace osu.Framework.Graphics.Containers { @@ -14,6 +17,6 @@ namespace osu.Framework.Graphics.Containers /// /// An enumerator of relevant terms which match the current object in a filtered scenario. /// - IEnumerable FilterTerms { get; } + IEnumerable FilterTerms { get; } } } diff --git a/osu.Framework/Graphics/Containers/IHasFilterableChildren.cs b/osu.Framework/Graphics/Containers/IHasFilterableChildren.cs index 98d583dd0..102eed326 100644 --- a/osu.Framework/Graphics/Containers/IHasFilterableChildren.cs +++ b/osu.Framework/Graphics/Containers/IHasFilterableChildren.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; namespace osu.Framework.Graphics.Containers diff --git a/osu.Framework/Graphics/Containers/ISafeArea.cs b/osu.Framework/Graphics/Containers/ISafeArea.cs index cb325f3b6..6d29f1bca 100644 --- a/osu.Framework/Graphics/Containers/ISafeArea.cs +++ b/osu.Framework/Graphics/Containers/ISafeArea.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Bindables; using osu.Framework.Graphics.Primitives; diff --git a/osu.Framework/Graphics/Containers/IScrollContainer.cs b/osu.Framework/Graphics/Containers/IScrollContainer.cs new file mode 100644 index 000000000..fd02dc3ef --- /dev/null +++ b/osu.Framework/Graphics/Containers/IScrollContainer.cs @@ -0,0 +1,15 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +#nullable disable + +namespace osu.Framework.Graphics.Containers +{ + public interface IScrollContainer : IContainer + { + /// + /// The direction in which scrolling is supported. + /// + Direction ScrollDirection { get; } + } +} diff --git a/osu.Framework/Graphics/Containers/ITextPart.cs b/osu.Framework/Graphics/Containers/ITextPart.cs index 76014d219..10e0048b0 100644 --- a/osu.Framework/Graphics/Containers/ITextPart.cs +++ b/osu.Framework/Graphics/Containers/ITextPart.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; diff --git a/osu.Framework/Graphics/Containers/LifetimeManagementContainer.cs b/osu.Framework/Graphics/Containers/LifetimeManagementContainer.cs index 7480edaec..a2b604424 100644 --- a/osu.Framework/Graphics/Containers/LifetimeManagementContainer.cs +++ b/osu.Framework/Graphics/Containers/LifetimeManagementContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/osu.Framework/Graphics/Containers/Markdown/IMarkdownTextComponent.cs b/osu.Framework/Graphics/Containers/Markdown/IMarkdownTextComponent.cs index 9b1772eac..55b8a2433 100644 --- a/osu.Framework/Graphics/Containers/Markdown/IMarkdownTextComponent.cs +++ b/osu.Framework/Graphics/Containers/Markdown/IMarkdownTextComponent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Allocation; using osu.Framework.Graphics.Sprites; diff --git a/osu.Framework/Graphics/Containers/Markdown/IMarkdownTextFlowComponent.cs b/osu.Framework/Graphics/Containers/Markdown/IMarkdownTextFlowComponent.cs index bc7c8a255..54cb2a649 100644 --- a/osu.Framework/Graphics/Containers/Markdown/IMarkdownTextFlowComponent.cs +++ b/osu.Framework/Graphics/Containers/Markdown/IMarkdownTextFlowComponent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Allocation; namespace osu.Framework.Graphics.Containers.Markdown diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownContainer.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownContainer.cs index de93fe525..e7bf478ce 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownContainer.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Linq; using Markdig; @@ -257,11 +259,11 @@ namespace osu.Framework.Graphics.Containers.Markdown AddMarkdownComponent(single, container, level); break; - case HtmlBlock _: + case HtmlBlock: // HTML is not supported break; - case LinkReferenceDefinitionGroup _: + case LinkReferenceDefinitionGroup: // Link reference doesn't need to be displayed. break; diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs index f148769c1..c19ff6063 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownFencedCodeBlock.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using Markdig.Syntax; using osu.Framework.Allocation; using osu.Framework.Graphics.Shapes; diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownHeading.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownHeading.cs index 9242378d5..c5ef3f540 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownHeading.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownHeading.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using Markdig.Syntax; using osu.Framework.Allocation; using osu.Framework.Graphics.Sprites; diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownImage.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownImage.cs index 1fa21cf9f..2fc890782 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownImage.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownImage.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Allocation; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Textures; diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownLinkText.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownLinkText.cs index 6f416edb3..9f3759087 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownLinkText.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownLinkText.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using Markdig.Syntax.Inlines; using osu.Framework.Allocation; using osu.Framework.Graphics.Cursor; diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownList.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownList.cs index 4c903087e..69efdd9ae 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownList.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownList.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osuTK; namespace osu.Framework.Graphics.Containers.Markdown diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownParagraph.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownParagraph.cs index b8dafd2e6..3aeeaac1b 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownParagraph.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownParagraph.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using Markdig.Syntax; using osu.Framework.Allocation; diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownQuoteBlock.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownQuoteBlock.cs index b4bdde46d..e0572c311 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownQuoteBlock.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownQuoteBlock.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using Markdig.Syntax; using osu.Framework.Allocation; using osu.Framework.Graphics.Shapes; diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownSeparator.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownSeparator.cs index d8f082f3d..9267d2b9b 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownSeparator.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownSeparator.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Allocation; using osu.Framework.Graphics.Shapes; using osuTK.Graphics; diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownTable.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownTable.cs index 3bc86b223..1c1cb6c5c 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownTable.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownTable.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownTableCell.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownTableCell.cs index ea4279423..943fb47a5 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownTableCell.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownTableCell.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using Markdig.Extensions.Tables; using Markdig.Syntax; using osu.Framework.Allocation; diff --git a/osu.Framework/Graphics/Containers/Markdown/MarkdownTextFlowContainer.cs b/osu.Framework/Graphics/Containers/Markdown/MarkdownTextFlowContainer.cs index 203af530a..aac91de8c 100644 --- a/osu.Framework/Graphics/Containers/Markdown/MarkdownTextFlowContainer.cs +++ b/osu.Framework/Graphics/Containers/Markdown/MarkdownTextFlowContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; @@ -54,7 +56,7 @@ namespace osu.Framework.Graphics.Containers.Markdown { switch (literal.Parent) { - case EmphasisInline _: + case EmphasisInline: var parent = literal.Parent; var emphases = new List(); @@ -92,8 +94,8 @@ namespace osu.Framework.Graphics.Containers.Markdown AddImage(linkInline); break; - case HtmlInline _: - case HtmlEntityInline _: + case HtmlInline: + case HtmlEntityInline: // Handled by the next literal break; diff --git a/osu.Framework/Graphics/Containers/Markdown/NotImplementedMarkdown.cs b/osu.Framework/Graphics/Containers/Markdown/NotImplementedMarkdown.cs index a16a48168..ea08bc4d6 100644 --- a/osu.Framework/Graphics/Containers/Markdown/NotImplementedMarkdown.cs +++ b/osu.Framework/Graphics/Containers/Markdown/NotImplementedMarkdown.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using Markdig.Syntax; using osu.Framework.Allocation; using osu.Framework.Graphics.Sprites; diff --git a/osu.Framework/Graphics/Containers/ModelBackedDrawable.cs b/osu.Framework/Graphics/Containers/ModelBackedDrawable.cs index 80c732d12..9cd925b5a 100644 --- a/osu.Framework/Graphics/Containers/ModelBackedDrawable.cs +++ b/osu.Framework/Graphics/Containers/ModelBackedDrawable.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using JetBrains.Annotations; diff --git a/osu.Framework/Graphics/Containers/OverlayContainer.cs b/osu.Framework/Graphics/Containers/OverlayContainer.cs index 7bcb4ba09..6c969acc3 100644 --- a/osu.Framework/Graphics/Containers/OverlayContainer.cs +++ b/osu.Framework/Graphics/Containers/OverlayContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using osu.Framework.Input; using osu.Framework.Input.Events; @@ -43,24 +45,8 @@ namespace osu.Framework.Graphics.Containers public override bool DragBlocksClick => false; - protected override bool Handle(UIEvent e) - { - switch (e) - { - case ScrollEvent _: - if (BlockScrollInput && base.ReceivePositionalInputAt(e.ScreenSpaceMousePosition)) - return true; - - break; - - case MouseEvent _: - if (BlockPositionalInput) - return true; - - break; - } - - return base.Handle(e); - } + protected override bool OnHover(HoverEvent e) => BlockPositionalInput; + protected override bool OnMouseDown(MouseDownEvent e) => BlockPositionalInput; + protected override bool OnScroll(ScrollEvent e) => BlockScrollInput && base.ReceivePositionalInputAt(e.ScreenSpaceMousePosition); } } diff --git a/osu.Framework/Graphics/Containers/RearrangeableListContainer.cs b/osu.Framework/Graphics/Containers/RearrangeableListContainer.cs index fb0f6f57a..b243f5050 100644 --- a/osu.Framework/Graphics/Containers/RearrangeableListContainer.cs +++ b/osu.Framework/Graphics/Containers/RearrangeableListContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections; using System.Collections.Generic; diff --git a/osu.Framework/Graphics/Containers/RearrangeableListItem.cs b/osu.Framework/Graphics/Containers/RearrangeableListItem.cs index 30f888a62..f7a0907cb 100644 --- a/osu.Framework/Graphics/Containers/RearrangeableListItem.cs +++ b/osu.Framework/Graphics/Containers/RearrangeableListItem.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Input.Events; using osuTK; diff --git a/osu.Framework/Graphics/Containers/SafeAreaContainer.cs b/osu.Framework/Graphics/Containers/SafeAreaContainer.cs index 693696ef6..52ac9b69b 100644 --- a/osu.Framework/Graphics/Containers/SafeAreaContainer.cs +++ b/osu.Framework/Graphics/Containers/SafeAreaContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Allocation; using osu.Framework.Bindables; diff --git a/osu.Framework/Graphics/Containers/SafeAreaDefiningContainer.cs b/osu.Framework/Graphics/Containers/SafeAreaDefiningContainer.cs index 08962e371..484a9a14a 100644 --- a/osu.Framework/Graphics/Containers/SafeAreaDefiningContainer.cs +++ b/osu.Framework/Graphics/Containers/SafeAreaDefiningContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics.Primitives; diff --git a/osu.Framework/Graphics/Containers/ScrollContainer.cs b/osu.Framework/Graphics/Containers/ScrollContainer.cs index ad77282d6..8040c4cee 100644 --- a/osu.Framework/Graphics/Containers/ScrollContainer.cs +++ b/osu.Framework/Graphics/Containers/ScrollContainer.cs @@ -1,19 +1,22 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Diagnostics; using osu.Framework.Caching; using osu.Framework.Input; using osu.Framework.Input.Bindings; using osu.Framework.Input.Events; +using osu.Framework.Layout; using osu.Framework.Utils; using osuTK; using osuTK.Input; namespace osu.Framework.Graphics.Containers { - public abstract class ScrollContainer : Container, DelayedLoadWrapper.IOnScreenOptimisingContainer, IKeyBindingHandler + public abstract class ScrollContainer : Container, IScrollContainer, DelayedLoadWrapper.IOnScreenOptimisingContainer, IKeyBindingHandler where T : Drawable { /// @@ -164,16 +167,19 @@ namespace osu.Framework.Graphics.Containers } } - /// - /// The direction in which scrolling is supported. - /// - protected readonly Direction ScrollDirection; + public Direction ScrollDirection { get; } /// /// The direction in which scrolling is supported, converted to an int for array index lookups. /// protected int ScrollDim => ScrollDirection == Direction.Horizontal ? 0 : 1; + private readonly LayoutValue parentScrollContainerCache = new LayoutValue(Invalidation.Parent); + + private IScrollContainer parentScrollContainer => parentScrollContainerCache.IsValid + ? parentScrollContainerCache.Value + : parentScrollContainerCache.Value = this.FindClosestParent(); + /// /// Creates a scroll container. /// @@ -198,6 +204,8 @@ namespace osu.Framework.Graphics.Containers Scrollbar.Hide(); Scrollbar.Dragged = onScrollbarMovement; ScrollbarAnchor = scrollDirection == Direction.Vertical ? Anchor.TopRight : Anchor.BottomLeft; + + AddLayout(parentScrollContainerCache); } private float lastUpdateDisplayableContent = -1; @@ -243,10 +251,12 @@ namespace osu.Framework.Graphics.Containers if (IsDragging || e.Button != MouseButton.Left || Content.AliveInternalChildren.Count == 0) return false; - bool dragWasMostlyHorizontal = Math.Abs(e.Delta.X) > Math.Abs(e.Delta.Y); - - if (dragWasMostlyHorizontal != (ScrollDirection == Direction.Horizontal)) - return false; + if (parentScrollContainer != null && parentScrollContainer.ScrollDirection != ScrollDirection) + { + bool dragWasMostlyHorizontal = Math.Abs(e.Delta.X) > Math.Abs(e.Delta.Y); + if (dragWasMostlyHorizontal != (ScrollDirection == Direction.Horizontal)) + return false; + } lastDragTime = Time.Current; averageDragDelta = averageDragTime = 0; @@ -368,12 +378,15 @@ namespace osu.Framework.Graphics.Containers if (Content.AliveInternalChildren.Count == 0) return false; - bool scrollWasMostlyHorizontal = Math.Abs(e.ScrollDelta.X) > Math.Abs(e.ScrollDelta.Y); + if (parentScrollContainer != null && parentScrollContainer.ScrollDirection != ScrollDirection) + { + bool scrollWasMostlyHorizontal = Math.Abs(e.ScrollDelta.X) > Math.Abs(e.ScrollDelta.Y); - // For horizontal scrolling containers, vertical scroll is also used to perform horizontal traversal. - // Due to this, we only block horizontal scroll in vertical containers, but not vice-versa. - if (scrollWasMostlyHorizontal && ScrollDirection == Direction.Vertical) - return false; + // For horizontal scrolling containers, vertical scroll is also used to perform horizontal traversal. + // Due to this, we only block horizontal scroll in vertical containers, but not vice-versa. + if (scrollWasMostlyHorizontal && ScrollDirection == Direction.Vertical) + return false; + } bool isPrecise = e.IsPrecise; @@ -382,7 +395,7 @@ namespace osu.Framework.Graphics.Containers if (ScrollDirection == Direction.Horizontal && scrollDelta.X != 0) scrollDeltaFloat = scrollDelta.X; - scrollByOffset((isPrecise ? 10 : ScrollDistance) * -scrollDeltaFloat, true, isPrecise ? 0.05 : DistanceDecayScroll); + scrollByOffset(ScrollDistance * -scrollDeltaFloat, true, isPrecise ? 0.05 : DistanceDecayScroll); return true; } diff --git a/osu.Framework/Graphics/Containers/SearchContainer.cs b/osu.Framework/Graphics/Containers/SearchContainer.cs index 789d92e88..90ff22f0c 100644 --- a/osu.Framework/Graphics/Containers/SearchContainer.cs +++ b/osu.Framework/Graphics/Containers/SearchContainer.cs @@ -1,11 +1,15 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Globalization; using System.Linq; +using osu.Framework.Allocation; using osu.Framework.Caching; +using osu.Framework.Localisation; using osu.Framework.Extensions.IEnumerableExtensions; namespace osu.Framework.Graphics.Containers @@ -64,6 +68,9 @@ namespace osu.Framework.Graphics.Containers } } + [Resolved] + private LocalisationManager localisation { get; set; } + protected internal override void AddInternal(Drawable drawable) { base.AddInternal(drawable); @@ -90,11 +97,14 @@ namespace osu.Framework.Graphics.Containers Children.OfType().ForEach(child => match(child, terms, terms.Length > 0, allowNonContiguousMatching)); } - private static bool match(IFilterable filterable, IEnumerable searchTerms, bool searchActive, bool nonContiguousMatching) + private bool match(IFilterable filterable, IEnumerable searchTerms, bool searchActive, bool nonContiguousMatching) { + IEnumerable filterTerms = filterable.FilterTerms.SelectMany(localisedStr => + new[] { localisedStr.ToString(), localisation.GetLocalisedString(localisedStr) }); + //Words matched by parent is not needed to match children string[] childTerms = searchTerms.Where(term => - !filterable.FilterTerms.Any(filterTerm => + !filterTerms.Any(filterTerm => checkTerm(filterTerm, term, nonContiguousMatching))).ToArray(); bool matching = childTerms.Length == 0; diff --git a/osu.Framework/Graphics/Containers/TabbableContainer.cs b/osu.Framework/Graphics/Containers/TabbableContainer.cs index adaf8f122..0c33dc9af 100644 --- a/osu.Framework/Graphics/Containers/TabbableContainer.cs +++ b/osu.Framework/Graphics/Containers/TabbableContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using System.Linq; using osu.Framework.Input.Events; diff --git a/osu.Framework/Graphics/Containers/TableContainer.cs b/osu.Framework/Graphics/Containers/TableContainer.cs index 9d3c7142e..9d12d9e27 100644 --- a/osu.Framework/Graphics/Containers/TableContainer.cs +++ b/osu.Framework/Graphics/Containers/TableContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Linq; using JetBrains.Annotations; diff --git a/osu.Framework/Graphics/Containers/TextChunk.cs b/osu.Framework/Graphics/Containers/TextChunk.cs index d03ed28b8..ecc681536 100644 --- a/osu.Framework/Graphics/Containers/TextChunk.cs +++ b/osu.Framework/Graphics/Containers/TextChunk.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework/Graphics/Containers/TextFlowContainer.cs b/osu.Framework/Graphics/Containers/TextFlowContainer.cs index c2a55db14..e3200a6d3 100644 --- a/osu.Framework/Graphics/Containers/TextFlowContainer.cs +++ b/osu.Framework/Graphics/Containers/TextFlowContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Caching; using osu.Framework.Graphics.Sprites; using System; diff --git a/osu.Framework/Graphics/Containers/TextNewLine.cs b/osu.Framework/Graphics/Containers/TextNewLine.cs index b29f8a871..50f773a35 100644 --- a/osu.Framework/Graphics/Containers/TextNewLine.cs +++ b/osu.Framework/Graphics/Containers/TextNewLine.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using osu.Framework.Extensions.IEnumerableExtensions; diff --git a/osu.Framework/Graphics/Containers/TextPart.cs b/osu.Framework/Graphics/Containers/TextPart.cs index ffd13edaa..bb6450714 100644 --- a/osu.Framework/Graphics/Containers/TextPart.cs +++ b/osu.Framework/Graphics/Containers/TextPart.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; diff --git a/osu.Framework/Graphics/Containers/TextPartManual.cs b/osu.Framework/Graphics/Containers/TextPartManual.cs index bd588e8fd..56d67246f 100644 --- a/osu.Framework/Graphics/Containers/TextPartManual.cs +++ b/osu.Framework/Graphics/Containers/TextPartManual.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Collections.Immutable; diff --git a/osu.Framework/Graphics/Containers/VisibilityContainer.cs b/osu.Framework/Graphics/Containers/VisibilityContainer.cs index 06d9457ee..d80de638a 100644 --- a/osu.Framework/Graphics/Containers/VisibilityContainer.cs +++ b/osu.Framework/Graphics/Containers/VisibilityContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Bindables; namespace osu.Framework.Graphics.Containers diff --git a/osu.Framework/Graphics/Cursor/BasicContextMenuContainer.cs b/osu.Framework/Graphics/Cursor/BasicContextMenuContainer.cs index d2f2ba805..41bac78ef 100644 --- a/osu.Framework/Graphics/Cursor/BasicContextMenuContainer.cs +++ b/osu.Framework/Graphics/Cursor/BasicContextMenuContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.UserInterface; namespace osu.Framework.Graphics.Cursor diff --git a/osu.Framework/Graphics/Cursor/ContextMenuContainer.cs b/osu.Framework/Graphics/Cursor/ContextMenuContainer.cs index bb8d0f95d..bbcc3c88e 100644 --- a/osu.Framework/Graphics/Cursor/ContextMenuContainer.cs +++ b/osu.Framework/Graphics/Cursor/ContextMenuContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Diagnostics; using System.Linq; diff --git a/osu.Framework/Graphics/Cursor/CursorContainer.cs b/osu.Framework/Graphics/Cursor/CursorContainer.cs index b6be07757..75fb182e2 100644 --- a/osu.Framework/Graphics/Cursor/CursorContainer.cs +++ b/osu.Framework/Graphics/Cursor/CursorContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Allocation; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Effects; diff --git a/osu.Framework/Graphics/Cursor/CursorEffectContainer.cs b/osu.Framework/Graphics/Cursor/CursorEffectContainer.cs index 769336e69..1c5571fef 100644 --- a/osu.Framework/Graphics/Cursor/CursorEffectContainer.cs +++ b/osu.Framework/Graphics/Cursor/CursorEffectContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using System.Diagnostics; using System.Linq; diff --git a/osu.Framework/Graphics/Cursor/IHasAppearDelay.cs b/osu.Framework/Graphics/Cursor/IHasAppearDelay.cs index 6e7400719..36a756fd1 100644 --- a/osu.Framework/Graphics/Cursor/IHasAppearDelay.cs +++ b/osu.Framework/Graphics/Cursor/IHasAppearDelay.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Graphics.Cursor { /// diff --git a/osu.Framework/Graphics/Cursor/IHasContextMenu.cs b/osu.Framework/Graphics/Cursor/IHasContextMenu.cs index 2536e9cdc..28bc07c91 100644 --- a/osu.Framework/Graphics/Cursor/IHasContextMenu.cs +++ b/osu.Framework/Graphics/Cursor/IHasContextMenu.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.UserInterface; namespace osu.Framework.Graphics.Cursor diff --git a/osu.Framework/Graphics/Cursor/IHasCustomTooltip.cs b/osu.Framework/Graphics/Cursor/IHasCustomTooltip.cs index 9810334cc..6e6f159c1 100644 --- a/osu.Framework/Graphics/Cursor/IHasCustomTooltip.cs +++ b/osu.Framework/Graphics/Cursor/IHasCustomTooltip.cs @@ -22,7 +22,7 @@ namespace osu.Framework.Graphics.Cursor /// /// Tooltip text that shows when hovering the drawable. /// - object TooltipContent { get; } + object? TooltipContent { get; } } /// @@ -33,9 +33,9 @@ namespace osu.Framework.Graphics.Cursor /// new ITooltip GetCustomTooltip(); - object IHasCustomTooltip.TooltipContent => TooltipContent; + object? IHasCustomTooltip.TooltipContent => TooltipContent; /// - new TContent TooltipContent { get; } + new TContent? TooltipContent { get; } } } diff --git a/osu.Framework/Graphics/Cursor/IHasPopover.cs b/osu.Framework/Graphics/Cursor/IHasPopover.cs index f4a923016..6c074018f 100644 --- a/osu.Framework/Graphics/Cursor/IHasPopover.cs +++ b/osu.Framework/Graphics/Cursor/IHasPopover.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using osu.Framework.Graphics.UserInterface; namespace osu.Framework.Graphics.Cursor diff --git a/osu.Framework/Graphics/Cursor/IHasTooltip.cs b/osu.Framework/Graphics/Cursor/IHasTooltip.cs index 5bc6a1761..28531a453 100644 --- a/osu.Framework/Graphics/Cursor/IHasTooltip.cs +++ b/osu.Framework/Graphics/Cursor/IHasTooltip.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Localisation; namespace osu.Framework.Graphics.Cursor diff --git a/osu.Framework/Graphics/Cursor/ITooltip.cs b/osu.Framework/Graphics/Cursor/ITooltip.cs index 2cec948cf..ba7c5e614 100644 --- a/osu.Framework/Graphics/Cursor/ITooltip.cs +++ b/osu.Framework/Graphics/Cursor/ITooltip.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osuTK; namespace osu.Framework.Graphics.Cursor diff --git a/osu.Framework/Graphics/Cursor/ITooltipContentProvider.cs b/osu.Framework/Graphics/Cursor/ITooltipContentProvider.cs index 658a391ca..83d9d5e4a 100644 --- a/osu.Framework/Graphics/Cursor/ITooltipContentProvider.cs +++ b/osu.Framework/Graphics/Cursor/ITooltipContentProvider.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Graphics.Cursor { /// diff --git a/osu.Framework/Graphics/Cursor/PopoverContainer.cs b/osu.Framework/Graphics/Cursor/PopoverContainer.cs index a789db508..66268c8f0 100644 --- a/osu.Framework/Graphics/Cursor/PopoverContainer.cs +++ b/osu.Framework/Graphics/Cursor/PopoverContainer.cs @@ -11,8 +11,6 @@ using osu.Framework.Input.Events; using osu.Framework.Utils; using osuTK; -#nullable enable - namespace osu.Framework.Graphics.Cursor { public class PopoverContainer : Container diff --git a/osu.Framework/Graphics/Cursor/TooltipContainer.cs b/osu.Framework/Graphics/Cursor/TooltipContainer.cs index d6dab4fcf..122bf4e39 100644 --- a/osu.Framework/Graphics/Cursor/TooltipContainer.cs +++ b/osu.Framework/Graphics/Cursor/TooltipContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework/Graphics/DrawColourInfo.cs b/osu.Framework/Graphics/DrawColourInfo.cs index 1aaadd69d..75000e2b8 100644 --- a/osu.Framework/Graphics/DrawColourInfo.cs +++ b/osu.Framework/Graphics/DrawColourInfo.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Graphics.Colour; using osuTK.Graphics; diff --git a/osu.Framework/Graphics/DrawInfo.cs b/osu.Framework/Graphics/DrawInfo.cs index 1e7c73037..c95057e53 100644 --- a/osu.Framework/Graphics/DrawInfo.cs +++ b/osu.Framework/Graphics/DrawInfo.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Extensions.MatrixExtensions; using osuTK; diff --git a/osu.Framework/Graphics/DrawNode.cs b/osu.Framework/Graphics/DrawNode.cs index 235a9b25f..0d5a6862e 100644 --- a/osu.Framework/Graphics/DrawNode.cs +++ b/osu.Framework/Graphics/DrawNode.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Runtime.CompilerServices; using System.Threading; diff --git a/osu.Framework/Graphics/Drawable.cs b/osu.Framework/Graphics/Drawable.cs index 2af05ae5a..f9fef7d21 100644 --- a/osu.Framework/Graphics/Drawable.cs +++ b/osu.Framework/Graphics/Drawable.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osuTK; using osuTK.Graphics; using osu.Framework.Allocation; diff --git a/osu.Framework/Graphics/DrawableExtensions.cs b/osu.Framework/Graphics/DrawableExtensions.cs index 1aad4df6c..15a5e389d 100644 --- a/osu.Framework/Graphics/DrawableExtensions.cs +++ b/osu.Framework/Graphics/DrawableExtensions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Development; diff --git a/osu.Framework/Graphics/Drawable_ProxyDrawable.cs b/osu.Framework/Graphics/Drawable_ProxyDrawable.cs index 917ab5fac..c08b4e898 100644 --- a/osu.Framework/Graphics/Drawable_ProxyDrawable.cs +++ b/osu.Framework/Graphics/Drawable_ProxyDrawable.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Graphics.OpenGL; using osu.Framework.Graphics.OpenGL.Vertices; diff --git a/osu.Framework/Graphics/Easing.cs b/osu.Framework/Graphics/Easing.cs index 73bc18e67..beca0f803 100644 --- a/osu.Framework/Graphics/Easing.cs +++ b/osu.Framework/Graphics/Easing.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Graphics { /// diff --git a/osu.Framework/Graphics/Effects/BlurEffect.cs b/osu.Framework/Graphics/Effects/BlurEffect.cs index 7babbf47a..319d37ab4 100644 --- a/osu.Framework/Graphics/Effects/BlurEffect.cs +++ b/osu.Framework/Graphics/Effects/BlurEffect.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osuTK; using osuTK.Graphics; using osu.Framework.Graphics.Colour; diff --git a/osu.Framework/Graphics/Effects/EdgeEffect.cs b/osu.Framework/Graphics/Effects/EdgeEffect.cs index 8a113b9ab..c14c9fd6c 100644 --- a/osu.Framework/Graphics/Effects/EdgeEffect.cs +++ b/osu.Framework/Graphics/Effects/EdgeEffect.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.Containers; namespace osu.Framework.Graphics.Effects diff --git a/osu.Framework/Graphics/Effects/EdgeEffectParameters.cs b/osu.Framework/Graphics/Effects/EdgeEffectParameters.cs index 47e12572f..610c8ddd7 100644 --- a/osu.Framework/Graphics/Effects/EdgeEffectParameters.cs +++ b/osu.Framework/Graphics/Effects/EdgeEffectParameters.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework/Graphics/Effects/EdgeEffectType.cs b/osu.Framework/Graphics/Effects/EdgeEffectType.cs index 8ddcd7fe4..5542cbdd4 100644 --- a/osu.Framework/Graphics/Effects/EdgeEffectType.cs +++ b/osu.Framework/Graphics/Effects/EdgeEffectType.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.Containers; namespace osu.Framework.Graphics.Effects diff --git a/osu.Framework/Graphics/Effects/EffectExtensions.cs b/osu.Framework/Graphics/Effects/EffectExtensions.cs index 29e2bb800..4e2c901dd 100644 --- a/osu.Framework/Graphics/Effects/EffectExtensions.cs +++ b/osu.Framework/Graphics/Effects/EffectExtensions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; namespace osu.Framework.Graphics.Effects diff --git a/osu.Framework/Graphics/Effects/GlowEffect.cs b/osu.Framework/Graphics/Effects/GlowEffect.cs index f491c5a05..981126f3b 100644 --- a/osu.Framework/Graphics/Effects/GlowEffect.cs +++ b/osu.Framework/Graphics/Effects/GlowEffect.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osuTK; using osuTK.Graphics; using osu.Framework.Graphics.Colour; diff --git a/osu.Framework/Graphics/Effects/IEffect.cs b/osu.Framework/Graphics/Effects/IEffect.cs index c86a478d1..748c44dcc 100644 --- a/osu.Framework/Graphics/Effects/IEffect.cs +++ b/osu.Framework/Graphics/Effects/IEffect.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Graphics.Effects { /// diff --git a/osu.Framework/Graphics/Effects/OutlineEffect.cs b/osu.Framework/Graphics/Effects/OutlineEffect.cs index 18eff20b3..4a32fc1af 100644 --- a/osu.Framework/Graphics/Effects/OutlineEffect.cs +++ b/osu.Framework/Graphics/Effects/OutlineEffect.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osuTK; using osuTK.Graphics; using osu.Framework.Graphics.Colour; diff --git a/osu.Framework/Graphics/FrameworkColour.cs b/osu.Framework/Graphics/FrameworkColour.cs index 0be28fde5..0b2053fa8 100644 --- a/osu.Framework/Graphics/FrameworkColour.cs +++ b/osu.Framework/Graphics/FrameworkColour.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osuTK.Graphics; namespace osu.Framework.Graphics diff --git a/osu.Framework/Graphics/FrameworkFont.cs b/osu.Framework/Graphics/FrameworkFont.cs index cd3937ebb..a216de425 100644 --- a/osu.Framework/Graphics/FrameworkFont.cs +++ b/osu.Framework/Graphics/FrameworkFont.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.Sprites; namespace osu.Framework.Graphics diff --git a/osu.Framework/Graphics/IBufferedDrawable.cs b/osu.Framework/Graphics/IBufferedDrawable.cs index 1db3051b9..c7b713d6c 100644 --- a/osu.Framework/Graphics/IBufferedDrawable.cs +++ b/osu.Framework/Graphics/IBufferedDrawable.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.OpenGL.Buffers; using osuTK; using osuTK.Graphics; diff --git a/osu.Framework/Graphics/ICompositeDrawNode.cs b/osu.Framework/Graphics/ICompositeDrawNode.cs index 2987f468a..be16d8dbb 100644 --- a/osu.Framework/Graphics/ICompositeDrawNode.cs +++ b/osu.Framework/Graphics/ICompositeDrawNode.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework/Graphics/IDrawable.cs b/osu.Framework/Graphics/IDrawable.cs index 040308dd6..e4eeba50d 100644 --- a/osu.Framework/Graphics/IDrawable.cs +++ b/osu.Framework/Graphics/IDrawable.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osuTK; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Primitives; diff --git a/osu.Framework/Graphics/ITexturedShaderDrawable.cs b/osu.Framework/Graphics/ITexturedShaderDrawable.cs index 4a0eac6b3..f5b2c970b 100644 --- a/osu.Framework/Graphics/ITexturedShaderDrawable.cs +++ b/osu.Framework/Graphics/ITexturedShaderDrawable.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.Shaders; namespace osu.Framework.Graphics diff --git a/osu.Framework/Graphics/InvalidationList.cs b/osu.Framework/Graphics/InvalidationList.cs index 013a65e91..f40f34f39 100644 --- a/osu.Framework/Graphics/InvalidationList.cs +++ b/osu.Framework/Graphics/InvalidationList.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Runtime.CompilerServices; using osu.Framework.Layout; diff --git a/osu.Framework/Graphics/Lines/Path.cs b/osu.Framework/Graphics/Lines/Path.cs index f504909ab..4717f8f88 100644 --- a/osu.Framework/Graphics/Lines/Path.cs +++ b/osu.Framework/Graphics/Lines/Path.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Textures; diff --git a/osu.Framework/Graphics/Lines/Path_DrawNode.cs b/osu.Framework/Graphics/Lines/Path_DrawNode.cs index fcbdbce0b..74245b919 100644 --- a/osu.Framework/Graphics/Lines/Path_DrawNode.cs +++ b/osu.Framework/Graphics/Lines/Path_DrawNode.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Textures; using osuTK.Graphics.ES30; diff --git a/osu.Framework/Graphics/Lines/SmoothPath.cs b/osu.Framework/Graphics/Lines/SmoothPath.cs index f0b868c27..9f8fa0ef6 100644 --- a/osu.Framework/Graphics/Lines/SmoothPath.cs +++ b/osu.Framework/Graphics/Lines/SmoothPath.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Allocation; using osu.Framework.Caching; diff --git a/osu.Framework/Graphics/Lines/TexturedPath.cs b/osu.Framework/Graphics/Lines/TexturedPath.cs index 46bbed7b8..a59ad9fb4 100644 --- a/osu.Framework/Graphics/Lines/TexturedPath.cs +++ b/osu.Framework/Graphics/Lines/TexturedPath.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.Textures; namespace osu.Framework.Graphics.Lines diff --git a/osu.Framework/Graphics/MarginPadding.cs b/osu.Framework/Graphics/MarginPadding.cs index 65df10cfa..b77e4a8dd 100644 --- a/osu.Framework/Graphics/MarginPadding.cs +++ b/osu.Framework/Graphics/MarginPadding.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osuTK; using System; using osu.Framework.Graphics.Transforms; diff --git a/osu.Framework/Graphics/OpenGL/Buffers/BufferFormatExtensions.cs b/osu.Framework/Graphics/OpenGL/Buffers/BufferFormatExtensions.cs index af9eb31fa..28cc449dc 100644 --- a/osu.Framework/Graphics/OpenGL/Buffers/BufferFormatExtensions.cs +++ b/osu.Framework/Graphics/OpenGL/Buffers/BufferFormatExtensions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osuTK.Graphics.ES30; diff --git a/osu.Framework/Graphics/OpenGL/Buffers/FrameBuffer.cs b/osu.Framework/Graphics/OpenGL/Buffers/FrameBuffer.cs index f66e6948e..c2be6b8c0 100644 --- a/osu.Framework/Graphics/OpenGL/Buffers/FrameBuffer.cs +++ b/osu.Framework/Graphics/OpenGL/Buffers/FrameBuffer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using osu.Framework.Graphics.OpenGL.Textures; diff --git a/osu.Framework/Graphics/OpenGL/Buffers/IVertexBuffer.cs b/osu.Framework/Graphics/OpenGL/Buffers/IVertexBuffer.cs index a66318cf0..2c0986540 100644 --- a/osu.Framework/Graphics/OpenGL/Buffers/IVertexBuffer.cs +++ b/osu.Framework/Graphics/OpenGL/Buffers/IVertexBuffer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Graphics.OpenGL.Buffers { /// diff --git a/osu.Framework/Graphics/OpenGL/Buffers/LinearVertexBuffer.cs b/osu.Framework/Graphics/OpenGL/Buffers/LinearVertexBuffer.cs index a43de18a9..814b1c20d 100644 --- a/osu.Framework/Graphics/OpenGL/Buffers/LinearVertexBuffer.cs +++ b/osu.Framework/Graphics/OpenGL/Buffers/LinearVertexBuffer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Graphics.OpenGL.Vertices; using osuTK.Graphics.ES30; diff --git a/osu.Framework/Graphics/OpenGL/Buffers/QuadVertexBuffer.cs b/osu.Framework/Graphics/OpenGL/Buffers/QuadVertexBuffer.cs index bf4866376..ee96cccb0 100644 --- a/osu.Framework/Graphics/OpenGL/Buffers/QuadVertexBuffer.cs +++ b/osu.Framework/Graphics/OpenGL/Buffers/QuadVertexBuffer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Diagnostics; using osu.Framework.Graphics.OpenGL.Textures; diff --git a/osu.Framework/Graphics/OpenGL/Buffers/RenderBuffer.cs b/osu.Framework/Graphics/OpenGL/Buffers/RenderBuffer.cs index a0a25fa99..846ad32d4 100644 --- a/osu.Framework/Graphics/OpenGL/Buffers/RenderBuffer.cs +++ b/osu.Framework/Graphics/OpenGL/Buffers/RenderBuffer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Platform; using osuTK; diff --git a/osu.Framework/Graphics/OpenGL/Buffers/VertexBuffer.cs b/osu.Framework/Graphics/OpenGL/Buffers/VertexBuffer.cs index 4cd9b45a2..0a3e73340 100644 --- a/osu.Framework/Graphics/OpenGL/Buffers/VertexBuffer.cs +++ b/osu.Framework/Graphics/OpenGL/Buffers/VertexBuffer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Buffers; using osu.Framework.Graphics.OpenGL.Vertices; diff --git a/osu.Framework/Graphics/OpenGL/ClearInfo.cs b/osu.Framework/Graphics/OpenGL/ClearInfo.cs index 1ddd0c8a4..d403fb192 100644 --- a/osu.Framework/Graphics/OpenGL/ClearInfo.cs +++ b/osu.Framework/Graphics/OpenGL/ClearInfo.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osuTK.Graphics; namespace osu.Framework.Graphics.OpenGL diff --git a/osu.Framework/Graphics/OpenGL/DepthInfo.cs b/osu.Framework/Graphics/OpenGL/DepthInfo.cs index a4b7b8d3c..852dcbc1d 100644 --- a/osu.Framework/Graphics/OpenGL/DepthInfo.cs +++ b/osu.Framework/Graphics/OpenGL/DepthInfo.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osuTK.Graphics.ES30; diff --git a/osu.Framework/Graphics/OpenGL/DepthValue.cs b/osu.Framework/Graphics/OpenGL/DepthValue.cs index 3fb48213d..9abbb5b34 100644 --- a/osu.Framework/Graphics/OpenGL/DepthValue.cs +++ b/osu.Framework/Graphics/OpenGL/DepthValue.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Runtime.CompilerServices; namespace osu.Framework.Graphics.OpenGL diff --git a/osu.Framework/Graphics/OpenGL/GLDisposalQueue.cs b/osu.Framework/Graphics/OpenGL/GLDisposalQueue.cs index a8386f1d7..d4f13f176 100644 --- a/osu.Framework/Graphics/OpenGL/GLDisposalQueue.cs +++ b/osu.Framework/Graphics/OpenGL/GLDisposalQueue.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/osu.Framework/Graphics/OpenGL/GLWrapper.cs b/osu.Framework/Graphics/OpenGL/GLWrapper.cs index af3eb9a93..317811eb4 100644 --- a/osu.Framework/Graphics/OpenGL/GLWrapper.cs +++ b/osu.Framework/Graphics/OpenGL/GLWrapper.cs @@ -1,10 +1,13 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; +using JetBrains.Annotations; using osu.Framework.Development; using osu.Framework.Graphics.Batches; using osu.Framework.Graphics.OpenGL.Textures; @@ -141,8 +144,6 @@ namespace osu.Framework.Graphics.OpenGL { ResetId++; - Trace.Assert(shader_stack.Count == 0); - reset_scheduler.Update(); stat_expensive_operations_queued.Value = expensive_operation_queue.Count; @@ -164,6 +165,11 @@ namespace osu.Framework.Graphics.OpenGL b.ResetCounters(); batch_reset_list.Clear(); + currentShader?.Unbind(); + currentShader = null; + shader_stack.Clear(); + GL.UseProgram(0); + viewport_stack.Clear(); ortho_stack.Clear(); masking_stack.Clear(); @@ -903,18 +909,15 @@ namespace osu.Framework.Graphics.OpenGL ScheduleDisposal(GL.DeleteFramebuffer, frameBuffer); } - private static int currentShader; + private static readonly Stack shader_stack = new Stack(); + private static Shader currentShader; - private static readonly Stack shader_stack = new Stack(); - - public static void UseProgram(int? shader) + public static void UseProgram([CanBeNull] Shader shader) { ThreadSafety.EnsureDrawThread(); if (shader != null) - { - shader_stack.Push(shader.Value); - } + shader_stack.Push(shader); else { shader_stack.Pop(); @@ -924,16 +927,17 @@ namespace osu.Framework.Graphics.OpenGL return; } - int s = shader ?? shader_stack.Peek(); + shader ??= shader_stack.Peek(); - if (currentShader == s) return; + if (currentShader == shader) + return; FrameStatistics.Increment(StatisticsCounterType.ShaderBinds); FlushCurrentBatch(); - GL.UseProgram(s); - currentShader = s; + GL.UseProgram(shader); + currentShader = shader; } internal static void SetUniform(IUniformWithValue uniform) diff --git a/osu.Framework/Graphics/OpenGL/Textures/TextureGL.cs b/osu.Framework/Graphics/OpenGL/Textures/TextureGL.cs index 10694eb10..78e8173ad 100644 --- a/osu.Framework/Graphics/OpenGL/Textures/TextureGL.cs +++ b/osu.Framework/Graphics/OpenGL/Textures/TextureGL.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Graphics.Batches; using osu.Framework.Graphics.Primitives; diff --git a/osu.Framework/Graphics/OpenGL/Textures/TextureGLAtlas.cs b/osu.Framework/Graphics/OpenGL/Textures/TextureGLAtlas.cs index 29f185a99..b58cc1bca 100644 --- a/osu.Framework/Graphics/OpenGL/Textures/TextureGLAtlas.cs +++ b/osu.Framework/Graphics/OpenGL/Textures/TextureGLAtlas.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Runtime.CompilerServices; using osu.Framework.Graphics.Primitives; diff --git a/osu.Framework/Graphics/OpenGL/Textures/TextureGLAtlasWhite.cs b/osu.Framework/Graphics/OpenGL/Textures/TextureGLAtlasWhite.cs index 7a66fea93..19f28afc1 100644 --- a/osu.Framework/Graphics/OpenGL/Textures/TextureGLAtlasWhite.cs +++ b/osu.Framework/Graphics/OpenGL/Textures/TextureGLAtlasWhite.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.Primitives; using osuTK.Graphics.ES30; diff --git a/osu.Framework/Graphics/OpenGL/Textures/TextureGLSingle.cs b/osu.Framework/Graphics/OpenGL/Textures/TextureGLSingle.cs index 3acdc1ec0..ba17e3c0b 100644 --- a/osu.Framework/Graphics/OpenGL/Textures/TextureGLSingle.cs +++ b/osu.Framework/Graphics/OpenGL/Textures/TextureGLSingle.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework/Graphics/OpenGL/Textures/TextureGLSub.cs b/osu.Framework/Graphics/OpenGL/Textures/TextureGLSub.cs index 98e940c0b..0fc7bd8e4 100644 --- a/osu.Framework/Graphics/OpenGL/Textures/TextureGLSub.cs +++ b/osu.Framework/Graphics/OpenGL/Textures/TextureGLSub.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Graphics.Primitives; using osuTK; diff --git a/osu.Framework/Graphics/OpenGL/Vertices/DepthWrappingVertex.cs b/osu.Framework/Graphics/OpenGL/Vertices/DepthWrappingVertex.cs index 67673af78..836221bb3 100644 --- a/osu.Framework/Graphics/OpenGL/Vertices/DepthWrappingVertex.cs +++ b/osu.Framework/Graphics/OpenGL/Vertices/DepthWrappingVertex.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Runtime.InteropServices; using osuTK.Graphics.ES30; diff --git a/osu.Framework/Graphics/OpenGL/Vertices/IVertex.cs b/osu.Framework/Graphics/OpenGL/Vertices/IVertex.cs index 32ee3531f..198d3c27f 100644 --- a/osu.Framework/Graphics/OpenGL/Vertices/IVertex.cs +++ b/osu.Framework/Graphics/OpenGL/Vertices/IVertex.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Graphics.OpenGL.Vertices { public interface IVertex diff --git a/osu.Framework/Graphics/OpenGL/Vertices/ParticleVertex2D.cs b/osu.Framework/Graphics/OpenGL/Vertices/ParticleVertex2D.cs index 5a7e8164e..e6ef21e17 100644 --- a/osu.Framework/Graphics/OpenGL/Vertices/ParticleVertex2D.cs +++ b/osu.Framework/Graphics/OpenGL/Vertices/ParticleVertex2D.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Runtime.InteropServices; using osuTK; diff --git a/osu.Framework/Graphics/OpenGL/Vertices/TexturedVertex2D.cs b/osu.Framework/Graphics/OpenGL/Vertices/TexturedVertex2D.cs index 884508bc7..75b58b557 100644 --- a/osu.Framework/Graphics/OpenGL/Vertices/TexturedVertex2D.cs +++ b/osu.Framework/Graphics/OpenGL/Vertices/TexturedVertex2D.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Runtime.InteropServices; using osuTK; diff --git a/osu.Framework/Graphics/OpenGL/Vertices/TexturedVertex3D.cs b/osu.Framework/Graphics/OpenGL/Vertices/TexturedVertex3D.cs index dfa931959..29da1cb87 100644 --- a/osu.Framework/Graphics/OpenGL/Vertices/TexturedVertex3D.cs +++ b/osu.Framework/Graphics/OpenGL/Vertices/TexturedVertex3D.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Runtime.InteropServices; using osuTK; diff --git a/osu.Framework/Graphics/OpenGL/Vertices/TimedTexturedVertex2D.cs b/osu.Framework/Graphics/OpenGL/Vertices/TimedTexturedVertex2D.cs index 6fd96ac97..89a84eb81 100644 --- a/osu.Framework/Graphics/OpenGL/Vertices/TimedTexturedVertex2D.cs +++ b/osu.Framework/Graphics/OpenGL/Vertices/TimedTexturedVertex2D.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Runtime.InteropServices; using osuTK; diff --git a/osu.Framework/Graphics/OpenGL/Vertices/UncolouredVertex2D.cs b/osu.Framework/Graphics/OpenGL/Vertices/UncolouredVertex2D.cs index d41dc77b0..92b1034ad 100644 --- a/osu.Framework/Graphics/OpenGL/Vertices/UncolouredVertex2D.cs +++ b/osu.Framework/Graphics/OpenGL/Vertices/UncolouredVertex2D.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Runtime.InteropServices; using osuTK; diff --git a/osu.Framework/Graphics/OpenGL/Vertices/Vertex2D.cs b/osu.Framework/Graphics/OpenGL/Vertices/Vertex2D.cs index 5f745a047..16a6252da 100644 --- a/osu.Framework/Graphics/OpenGL/Vertices/Vertex2D.cs +++ b/osu.Framework/Graphics/OpenGL/Vertices/Vertex2D.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Runtime.InteropServices; using osuTK; diff --git a/osu.Framework/Graphics/OpenGL/Vertices/VertexMemberAttribute.cs b/osu.Framework/Graphics/OpenGL/Vertices/VertexMemberAttribute.cs index 575751109..5cd81f7cd 100644 --- a/osu.Framework/Graphics/OpenGL/Vertices/VertexMemberAttribute.cs +++ b/osu.Framework/Graphics/OpenGL/Vertices/VertexMemberAttribute.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osuTK.Graphics.ES30; diff --git a/osu.Framework/Graphics/OpenGL/Vertices/VertexUtils.cs b/osu.Framework/Graphics/OpenGL/Vertices/VertexUtils.cs index 74219317e..de61069ad 100644 --- a/osu.Framework/Graphics/OpenGL/Vertices/VertexUtils.cs +++ b/osu.Framework/Graphics/OpenGL/Vertices/VertexUtils.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + // ReSharper disable StaticMemberInGenericType using System; diff --git a/osu.Framework/Graphics/Performance/FrameStatisticsDisplay.cs b/osu.Framework/Graphics/Performance/FrameStatisticsDisplay.cs index ca5d7b488..ba4f481db 100644 --- a/osu.Framework/Graphics/Performance/FrameStatisticsDisplay.cs +++ b/osu.Framework/Graphics/Performance/FrameStatisticsDisplay.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osuTK.Graphics; using osuTK.Input; using osu.Framework.Allocation; @@ -15,6 +17,7 @@ using osu.Framework.Threading; using System; using System.Buffers; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using osu.Framework.Input.Events; using osuTK; @@ -346,6 +349,21 @@ namespace osu.Framework.Graphics.Performance base.OnKeyUp(e); } + protected override void Update() + { + base.Update(); + + if (running) + { + while (monitor.PendingFrames.TryDequeue(out FrameStatistics frame)) + { + applyFrame(frame); + frameTimeDisplay.NewFrame(frame); + monitor.FramesPool.Return(frame); + } + } + } + private void applyFrameGC(FrameStatistics frame) { foreach (int gcLevel in frame.GarbageCollections) @@ -379,12 +397,6 @@ namespace osu.Framework.Graphics.Performance } } - private void applyFrameCounts(FrameStatistics frame) - { - foreach (var pair in frame.Counts) - counterBars[pair.Key].Value = pair.Value; - } - private void applyFrame(FrameStatistics frame) { if (state == FrameStatisticsMode.Full) @@ -393,22 +405,8 @@ namespace osu.Framework.Graphics.Performance applyFrameTime(frame); } - applyFrameCounts(frame); - } - - protected override void Update() - { - base.Update(); - - if (running) - { - while (monitor.PendingFrames.TryDequeue(out FrameStatistics frame)) - { - applyFrame(frame); - frameTimeDisplay.NewFrame(frame); - monitor.FramesPool.Return(frame); - } - } + foreach (var pair in frame.Counts) + counterBars[pair.Key].Value = pair.Value; } private Color4 getColour(PerformanceCollectionType type) @@ -553,7 +551,6 @@ namespace osu.Framework.Graphics.Performance private double height; private double velocity; - private const double acceleration = 0.000001; private const float bar_width = 6; private long value; @@ -562,6 +559,8 @@ namespace osu.Framework.Graphics.Performance { set { + Debug.Assert(value >= 0); // Log10 will NaN for negative values. + this.value = value; height = Math.Log10(value + 1) / amount_count_steps; } @@ -596,15 +595,19 @@ namespace osu.Framework.Graphics.Performance { base.Update(); + const double acceleration = 0.000001; + double elapsedTime = Time.Elapsed; - double movement = velocity * Time.Elapsed + 0.5 * acceleration * elapsedTime * elapsedTime; - double newHeight = Math.Max(height, box.Height - movement); + + double change = velocity * elapsedTime + 0.5 * acceleration * elapsedTime * elapsedTime; + double newHeight = Math.Max(height, box.Height - change); + box.Height = (float)newHeight; if (newHeight <= height) velocity = 0; else - velocity += Time.Elapsed * acceleration; + velocity += elapsedTime * acceleration; if (expanded) text.Text = $@"{Label}: {NumberFormatter.PrintWithSiSuffix(value)}"; diff --git a/osu.Framework/Graphics/Performance/FrameTimeDisplay.cs b/osu.Framework/Graphics/Performance/FrameTimeDisplay.cs index 40fda2bb1..c9d60560a 100644 --- a/osu.Framework/Graphics/Performance/FrameTimeDisplay.cs +++ b/osu.Framework/Graphics/Performance/FrameTimeDisplay.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; diff --git a/osu.Framework/Graphics/Performance/GlobalStatisticsDisplay.cs b/osu.Framework/Graphics/Performance/GlobalStatisticsDisplay.cs index 1a09c397a..4528fdb92 100644 --- a/osu.Framework/Graphics/Performance/GlobalStatisticsDisplay.cs +++ b/osu.Framework/Graphics/Performance/GlobalStatisticsDisplay.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; diff --git a/osu.Framework/Graphics/Performance/LifetimeBoundaryCrossingDirection.cs b/osu.Framework/Graphics/Performance/LifetimeBoundaryCrossingDirection.cs index 052d9d469..dc6e3c58a 100644 --- a/osu.Framework/Graphics/Performance/LifetimeBoundaryCrossingDirection.cs +++ b/osu.Framework/Graphics/Performance/LifetimeBoundaryCrossingDirection.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Graphics.Performance { /// diff --git a/osu.Framework/Graphics/Performance/LifetimeBoundaryKind.cs b/osu.Framework/Graphics/Performance/LifetimeBoundaryKind.cs index 74e5c1dcf..c05d64fc3 100644 --- a/osu.Framework/Graphics/Performance/LifetimeBoundaryKind.cs +++ b/osu.Framework/Graphics/Performance/LifetimeBoundaryKind.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Graphics.Performance { /// diff --git a/osu.Framework/Graphics/Performance/LifetimeEntry.cs b/osu.Framework/Graphics/Performance/LifetimeEntry.cs index 180dc0321..f67bdfc5d 100644 --- a/osu.Framework/Graphics/Performance/LifetimeEntry.cs +++ b/osu.Framework/Graphics/Performance/LifetimeEntry.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; namespace osu.Framework.Graphics.Performance diff --git a/osu.Framework/Graphics/Performance/LifetimeEntryManager.cs b/osu.Framework/Graphics/Performance/LifetimeEntryManager.cs index ac30eb24e..90765a156 100644 --- a/osu.Framework/Graphics/Performance/LifetimeEntryManager.cs +++ b/osu.Framework/Graphics/Performance/LifetimeEntryManager.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/osu.Framework/Graphics/Performance/LifetimeEntryState.cs b/osu.Framework/Graphics/Performance/LifetimeEntryState.cs index d7a094a6e..ee6bda0a2 100644 --- a/osu.Framework/Graphics/Performance/LifetimeEntryState.cs +++ b/osu.Framework/Graphics/Performance/LifetimeEntryState.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Graphics.Performance { /// diff --git a/osu.Framework/Graphics/Performance/PerformanceOverlay.cs b/osu.Framework/Graphics/Performance/PerformanceOverlay.cs index b90e0c472..7e9b3f290 100644 --- a/osu.Framework/Graphics/Performance/PerformanceOverlay.cs +++ b/osu.Framework/Graphics/Performance/PerformanceOverlay.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Buffers; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework/Graphics/Pooling/DrawablePool.cs b/osu.Framework/Graphics/Pooling/DrawablePool.cs index 6d1160930..ec74d6303 100644 --- a/osu.Framework/Graphics/Pooling/DrawablePool.cs +++ b/osu.Framework/Graphics/Pooling/DrawablePool.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/osu.Framework/Graphics/Pooling/IDrawablePool.cs b/osu.Framework/Graphics/Pooling/IDrawablePool.cs index 1a02960b7..249ca9e20 100644 --- a/osu.Framework/Graphics/Pooling/IDrawablePool.cs +++ b/osu.Framework/Graphics/Pooling/IDrawablePool.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; namespace osu.Framework.Graphics.Pooling diff --git a/osu.Framework/Graphics/Pooling/PoolableDrawable.cs b/osu.Framework/Graphics/Pooling/PoolableDrawable.cs index fd387540d..12cb6cd91 100644 --- a/osu.Framework/Graphics/Pooling/PoolableDrawable.cs +++ b/osu.Framework/Graphics/Pooling/PoolableDrawable.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Extensions.EnumExtensions; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework/Graphics/Primitives/IConvexPolygon.cs b/osu.Framework/Graphics/Primitives/IConvexPolygon.cs index 446611763..ab12fb881 100644 --- a/osu.Framework/Graphics/Primitives/IConvexPolygon.cs +++ b/osu.Framework/Graphics/Primitives/IConvexPolygon.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Graphics.Primitives { public interface IConvexPolygon : IPolygon diff --git a/osu.Framework/Graphics/Primitives/IPolygon.cs b/osu.Framework/Graphics/Primitives/IPolygon.cs index b637ebada..7b43573a8 100644 --- a/osu.Framework/Graphics/Primitives/IPolygon.cs +++ b/osu.Framework/Graphics/Primitives/IPolygon.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osuTK; diff --git a/osu.Framework/Graphics/Primitives/Line.cs b/osu.Framework/Graphics/Primitives/Line.cs index 5c6ee570e..4464de8e3 100644 --- a/osu.Framework/Graphics/Primitives/Line.cs +++ b/osu.Framework/Graphics/Primitives/Line.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Runtime.CompilerServices; using osu.Framework.Utils; diff --git a/osu.Framework/Graphics/Primitives/ProjectionRange.cs b/osu.Framework/Graphics/Primitives/ProjectionRange.cs index 97b134b76..2632fc9cd 100644 --- a/osu.Framework/Graphics/Primitives/ProjectionRange.cs +++ b/osu.Framework/Graphics/Primitives/ProjectionRange.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osuTK; diff --git a/osu.Framework/Graphics/Primitives/Quad.cs b/osu.Framework/Graphics/Primitives/Quad.cs index 2683db60b..05ac1cf65 100644 --- a/osu.Framework/Graphics/Primitives/Quad.cs +++ b/osu.Framework/Graphics/Primitives/Quad.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; diff --git a/osu.Framework/Graphics/Primitives/RectangleF.cs b/osu.Framework/Graphics/Primitives/RectangleF.cs index 54e48d374..d1dad4258 100644 --- a/osu.Framework/Graphics/Primitives/RectangleF.cs +++ b/osu.Framework/Graphics/Primitives/RectangleF.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.ComponentModel; using System.Diagnostics.CodeAnalysis; diff --git a/osu.Framework/Graphics/Primitives/RectangleI.cs b/osu.Framework/Graphics/Primitives/RectangleI.cs index 0ecb9099b..64ac87a99 100644 --- a/osu.Framework/Graphics/Primitives/RectangleI.cs +++ b/osu.Framework/Graphics/Primitives/RectangleI.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.ComponentModel; using System.Diagnostics.CodeAnalysis; diff --git a/osu.Framework/Graphics/Primitives/SimpleConvexPolygon.cs b/osu.Framework/Graphics/Primitives/SimpleConvexPolygon.cs index bb562e464..cee04fbeb 100644 --- a/osu.Framework/Graphics/Primitives/SimpleConvexPolygon.cs +++ b/osu.Framework/Graphics/Primitives/SimpleConvexPolygon.cs @@ -1,7 +1,10 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; +using System.Linq; using osuTK; namespace osu.Framework.Graphics.Primitives @@ -20,5 +23,7 @@ namespace osu.Framework.Graphics.Primitives public ReadOnlySpan GetVertices() => vertices; public int MaxClipVertices => vertices.Length * 2; + + public override string ToString() => $"{{ {string.Join(", ", vertices.Select(v => $"({v.X}, {v.Y})"))} }}"; } } diff --git a/osu.Framework/Graphics/Primitives/Triangle.cs b/osu.Framework/Graphics/Primitives/Triangle.cs index fd9559524..dce2984ec 100644 --- a/osu.Framework/Graphics/Primitives/Triangle.cs +++ b/osu.Framework/Graphics/Primitives/Triangle.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osuTK; using System; using System.Runtime.CompilerServices; diff --git a/osu.Framework/Graphics/Primitives/Vector2I.cs b/osu.Framework/Graphics/Primitives/Vector2I.cs index 59fbea973..76b445998 100644 --- a/osu.Framework/Graphics/Primitives/Vector2I.cs +++ b/osu.Framework/Graphics/Primitives/Vector2I.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osuTK; using System; using System.Diagnostics.CodeAnalysis; diff --git a/osu.Framework/Graphics/Shaders/GlobalProperty.cs b/osu.Framework/Graphics/Shaders/GlobalProperty.cs index 75efc36d5..c299dc622 100644 --- a/osu.Framework/Graphics/Shaders/GlobalProperty.cs +++ b/osu.Framework/Graphics/Shaders/GlobalProperty.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Graphics.Shaders { /// diff --git a/osu.Framework/Graphics/Shaders/GlobalPropertyManager.cs b/osu.Framework/Graphics/Shaders/GlobalPropertyManager.cs index d3a5829b4..6a189cabd 100644 --- a/osu.Framework/Graphics/Shaders/GlobalPropertyManager.cs +++ b/osu.Framework/Graphics/Shaders/GlobalPropertyManager.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework/Graphics/Shaders/GlobalUniform.cs b/osu.Framework/Graphics/Shaders/GlobalUniform.cs index 3d52ab901..628bb3cf2 100644 --- a/osu.Framework/Graphics/Shaders/GlobalUniform.cs +++ b/osu.Framework/Graphics/Shaders/GlobalUniform.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.OpenGL; using System; diff --git a/osu.Framework/Graphics/Shaders/IShader.cs b/osu.Framework/Graphics/Shaders/IShader.cs index a95a0bde0..7d11a6e24 100644 --- a/osu.Framework/Graphics/Shaders/IShader.cs +++ b/osu.Framework/Graphics/Shaders/IShader.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; namespace osu.Framework.Graphics.Shaders diff --git a/osu.Framework/Graphics/Shaders/IUniform.cs b/osu.Framework/Graphics/Shaders/IUniform.cs index 093d3c445..3493001b9 100644 --- a/osu.Framework/Graphics/Shaders/IUniform.cs +++ b/osu.Framework/Graphics/Shaders/IUniform.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Graphics.Shaders { /// diff --git a/osu.Framework/Graphics/Shaders/IUniformMapping.cs b/osu.Framework/Graphics/Shaders/IUniformMapping.cs index 946be766c..acb26ad2e 100644 --- a/osu.Framework/Graphics/Shaders/IUniformMapping.cs +++ b/osu.Framework/Graphics/Shaders/IUniformMapping.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Graphics.Shaders { internal interface IUniformMapping diff --git a/osu.Framework/Graphics/Shaders/IUniformWithValue.cs b/osu.Framework/Graphics/Shaders/IUniformWithValue.cs index ef97f9c67..a506b2c65 100644 --- a/osu.Framework/Graphics/Shaders/IUniformWithValue.cs +++ b/osu.Framework/Graphics/Shaders/IUniformWithValue.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; namespace osu.Framework.Graphics.Shaders diff --git a/osu.Framework/Graphics/Shaders/Shader.cs b/osu.Framework/Graphics/Shaders/Shader.cs index 39e7451a8..49dadd5cf 100644 --- a/osu.Framework/Graphics/Shaders/Shader.cs +++ b/osu.Framework/Graphics/Shaders/Shader.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using osu.Framework.Graphics.OpenGL; diff --git a/osu.Framework/Graphics/Shaders/ShaderInputInfo.cs b/osu.Framework/Graphics/Shaders/ShaderInputInfo.cs index 3b408642f..83f186feb 100644 --- a/osu.Framework/Graphics/Shaders/ShaderInputInfo.cs +++ b/osu.Framework/Graphics/Shaders/ShaderInputInfo.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Graphics.Shaders { /// diff --git a/osu.Framework/Graphics/Shaders/ShaderManager.cs b/osu.Framework/Graphics/Shaders/ShaderManager.cs index 4cd456043..7bf9a89fb 100644 --- a/osu.Framework/Graphics/Shaders/ShaderManager.cs +++ b/osu.Framework/Graphics/Shaders/ShaderManager.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using System; using System.Collections.Concurrent; using System.Collections.Generic; diff --git a/osu.Framework/Graphics/Shaders/ShaderPart.cs b/osu.Framework/Graphics/Shaders/ShaderPart.cs index 3deab8dbc..c3e47a9ac 100644 --- a/osu.Framework/Graphics/Shaders/ShaderPart.cs +++ b/osu.Framework/Graphics/Shaders/ShaderPart.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.IO; diff --git a/osu.Framework/Graphics/Shaders/Uniform.cs b/osu.Framework/Graphics/Shaders/Uniform.cs index 8a70ba368..dfb374f2b 100644 --- a/osu.Framework/Graphics/Shaders/Uniform.cs +++ b/osu.Framework/Graphics/Shaders/Uniform.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.OpenGL; using System; diff --git a/osu.Framework/Graphics/Shaders/UniformMapping.cs b/osu.Framework/Graphics/Shaders/UniformMapping.cs index a3f438544..f827a9375 100644 --- a/osu.Framework/Graphics/Shaders/UniformMapping.cs +++ b/osu.Framework/Graphics/Shaders/UniformMapping.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; diff --git a/osu.Framework/Graphics/Shapes/Box.cs b/osu.Framework/Graphics/Shapes/Box.cs index 037207447..b53cf723e 100644 --- a/osu.Framework/Graphics/Shapes/Box.cs +++ b/osu.Framework/Graphics/Shapes/Box.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Textures; diff --git a/osu.Framework/Graphics/Shapes/Circle.cs b/osu.Framework/Graphics/Shapes/Circle.cs index d599da37a..303ba3b45 100644 --- a/osu.Framework/Graphics/Shapes/Circle.cs +++ b/osu.Framework/Graphics/Shapes/Circle.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.Containers; namespace osu.Framework.Graphics.Shapes diff --git a/osu.Framework/Graphics/Shapes/EquilateralTriangle.cs b/osu.Framework/Graphics/Shapes/EquilateralTriangle.cs index fe65f4a2f..9f7bab834 100644 --- a/osu.Framework/Graphics/Shapes/EquilateralTriangle.cs +++ b/osu.Framework/Graphics/Shapes/EquilateralTriangle.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osuTK; namespace osu.Framework.Graphics.Shapes diff --git a/osu.Framework/Graphics/Shapes/Triangle.cs b/osu.Framework/Graphics/Shapes/Triangle.cs index 41de4142b..55631c854 100644 --- a/osu.Framework/Graphics/Shapes/Triangle.cs +++ b/osu.Framework/Graphics/Shapes/Triangle.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Graphics.OpenGL.Vertices; using osu.Framework.Graphics.Textures; diff --git a/osu.Framework/Graphics/Sprites/BufferedContainerView.cs b/osu.Framework/Graphics/Sprites/BufferedContainerView.cs index 7e86b5436..e52dda792 100644 --- a/osu.Framework/Graphics/Sprites/BufferedContainerView.cs +++ b/osu.Framework/Graphics/Sprites/BufferedContainerView.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Allocation; using osu.Framework.Graphics.Colour; diff --git a/osu.Framework/Graphics/Sprites/FontAwesome.cs b/osu.Framework/Graphics/Sprites/FontAwesome.cs index 106176ed9..c1be93f80 100644 --- a/osu.Framework/Graphics/Sprites/FontAwesome.cs +++ b/osu.Framework/Graphics/Sprites/FontAwesome.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + // Auto-generated by https://gist.github.com/peppy/6f49ac3d204ea3595ee65875944046d4 // ReSharper disable CommentTypo diff --git a/osu.Framework/Graphics/Sprites/FontUsage.cs b/osu.Framework/Graphics/Sprites/FontUsage.cs index 402a3b512..06525ea69 100644 --- a/osu.Framework/Graphics/Sprites/FontUsage.cs +++ b/osu.Framework/Graphics/Sprites/FontUsage.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using JetBrains.Annotations; diff --git a/osu.Framework/Graphics/Sprites/IHasLineBaseHeight.cs b/osu.Framework/Graphics/Sprites/IHasLineBaseHeight.cs index 48ecc5df6..888417810 100644 --- a/osu.Framework/Graphics/Sprites/IHasLineBaseHeight.cs +++ b/osu.Framework/Graphics/Sprites/IHasLineBaseHeight.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Graphics.Sprites { /// diff --git a/osu.Framework/Graphics/Sprites/IHasText.cs b/osu.Framework/Graphics/Sprites/IHasText.cs index f5a82b4f5..b78aeb4c2 100644 --- a/osu.Framework/Graphics/Sprites/IHasText.cs +++ b/osu.Framework/Graphics/Sprites/IHasText.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Localisation; namespace osu.Framework.Graphics.Sprites diff --git a/osu.Framework/Graphics/Sprites/IconUsage.cs b/osu.Framework/Graphics/Sprites/IconUsage.cs index e2da2b56c..b9f7e35d9 100644 --- a/osu.Framework/Graphics/Sprites/IconUsage.cs +++ b/osu.Framework/Graphics/Sprites/IconUsage.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using JetBrains.Annotations; diff --git a/osu.Framework/Graphics/Sprites/Sprite.cs b/osu.Framework/Graphics/Sprites/Sprite.cs index f3b3b1464..4e58e4411 100644 --- a/osu.Framework/Graphics/Sprites/Sprite.cs +++ b/osu.Framework/Graphics/Sprites/Sprite.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Textures; diff --git a/osu.Framework/Graphics/Sprites/SpriteDrawNode.cs b/osu.Framework/Graphics/Sprites/SpriteDrawNode.cs index 6dc2a31cb..f22c9a286 100644 --- a/osu.Framework/Graphics/Sprites/SpriteDrawNode.cs +++ b/osu.Framework/Graphics/Sprites/SpriteDrawNode.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osuTK; using System; using osu.Framework.Graphics.OpenGL.Vertices; diff --git a/osu.Framework/Graphics/Sprites/SpriteIcon.cs b/osu.Framework/Graphics/Sprites/SpriteIcon.cs index 3cb989ae5..5903adda6 100644 --- a/osu.Framework/Graphics/Sprites/SpriteIcon.cs +++ b/osu.Framework/Graphics/Sprites/SpriteIcon.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Allocation; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework/Graphics/Sprites/SpriteText.cs b/osu.Framework/Graphics/Sprites/SpriteText.cs index 4981f4ced..88e4bf2bd 100644 --- a/osu.Framework/Graphics/Sprites/SpriteText.cs +++ b/osu.Framework/Graphics/Sprites/SpriteText.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using osu.Framework.Allocation; @@ -636,6 +638,6 @@ namespace osu.Framework.Graphics.Sprites } } - public IEnumerable FilterTerms => displayedText.Yield(); + public IEnumerable FilterTerms => Text.Yield(); } } diff --git a/osu.Framework/Graphics/Sprites/SpriteText_DrawNode.cs b/osu.Framework/Graphics/Sprites/SpriteText_DrawNode.cs index 0596c1eb4..5bf1c0ec4 100644 --- a/osu.Framework/Graphics/Sprites/SpriteText_DrawNode.cs +++ b/osu.Framework/Graphics/Sprites/SpriteText_DrawNode.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using osu.Framework.Graphics.Colour; diff --git a/osu.Framework/Graphics/TexturedShaderDrawNode.cs b/osu.Framework/Graphics/TexturedShaderDrawNode.cs index 987d2c16f..9e7af9441 100644 --- a/osu.Framework/Graphics/TexturedShaderDrawNode.cs +++ b/osu.Framework/Graphics/TexturedShaderDrawNode.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.OpenGL; using osu.Framework.Graphics.Shaders; diff --git a/osu.Framework/Graphics/Textures/ArrayPoolTextureUpload.cs b/osu.Framework/Graphics/Textures/ArrayPoolTextureUpload.cs index dcd4ff04c..683cbfc25 100644 --- a/osu.Framework/Graphics/Textures/ArrayPoolTextureUpload.cs +++ b/osu.Framework/Graphics/Textures/ArrayPoolTextureUpload.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Buffers; using osu.Framework.Graphics.Primitives; diff --git a/osu.Framework/Graphics/Textures/DisposableTexture.cs b/osu.Framework/Graphics/Textures/DisposableTexture.cs index 77d12e976..45abd60ed 100644 --- a/osu.Framework/Graphics/Textures/DisposableTexture.cs +++ b/osu.Framework/Graphics/Textures/DisposableTexture.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.OpenGL.Textures; using osuTK.Graphics.ES30; diff --git a/osu.Framework/Graphics/Textures/ITextureStore.cs b/osu.Framework/Graphics/Textures/ITextureStore.cs new file mode 100644 index 000000000..4fb2ef391 --- /dev/null +++ b/osu.Framework/Graphics/Textures/ITextureStore.cs @@ -0,0 +1,35 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Threading; +using System.Threading.Tasks; +using osu.Framework.Graphics.OpenGL.Textures; +using osu.Framework.IO.Stores; + +namespace osu.Framework.Graphics.Textures +{ + /// + /// Provides drawable-ready s. + /// + public interface ITextureStore : IResourceStore + { + /// + /// Retrieves a texture from the store. + /// + /// The name of the texture. + /// The texture wrap mode in horizontal direction. + /// The texture wrap mode in vertical direction. + /// The texture. + Texture? Get(string name, WrapMode wrapModeS, WrapMode wrapModeT); + + /// + /// Retrieves a texture from the store asynchronously. + /// + /// The name of the texture. + /// The texture wrap mode in horizontal direction. + /// The texture wrap mode in vertical direction. + /// A cancellation token. + /// The texture. + Task GetAsync(string name, WrapMode wrapModeS, WrapMode wrapModeT, CancellationToken cancellationToken = default); + } +} diff --git a/osu.Framework/Graphics/Textures/ITextureUpload.cs b/osu.Framework/Graphics/Textures/ITextureUpload.cs index 2f7828471..01dba8abf 100644 --- a/osu.Framework/Graphics/Textures/ITextureUpload.cs +++ b/osu.Framework/Graphics/Textures/ITextureUpload.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Graphics.Primitives; using osuTK.Graphics.ES30; diff --git a/osu.Framework/Graphics/Textures/LargeTextureStore.cs b/osu.Framework/Graphics/Textures/LargeTextureStore.cs index cd93b792a..9407ae52f 100644 --- a/osu.Framework/Graphics/Textures/LargeTextureStore.cs +++ b/osu.Framework/Graphics/Textures/LargeTextureStore.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using System.Diagnostics; using System.Threading; diff --git a/osu.Framework/Graphics/Textures/MemoryAllocatorTextureUpload.cs b/osu.Framework/Graphics/Textures/MemoryAllocatorTextureUpload.cs index 4416c5b41..f0a9560c5 100644 --- a/osu.Framework/Graphics/Textures/MemoryAllocatorTextureUpload.cs +++ b/osu.Framework/Graphics/Textures/MemoryAllocatorTextureUpload.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Buffers; using osu.Framework.Graphics.Primitives; diff --git a/osu.Framework/Graphics/Textures/Texture.cs b/osu.Framework/Graphics/Textures/Texture.cs index def259e80..a161df949 100644 --- a/osu.Framework/Graphics/Textures/Texture.cs +++ b/osu.Framework/Graphics/Textures/Texture.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.IO; using osu.Framework.Extensions.EnumExtensions; diff --git a/osu.Framework/Graphics/Textures/TextureAtlas.cs b/osu.Framework/Graphics/Textures/TextureAtlas.cs index 9cab0a265..f0abbb429 100644 --- a/osu.Framework/Graphics/Textures/TextureAtlas.cs +++ b/osu.Framework/Graphics/Textures/TextureAtlas.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Numerics; diff --git a/osu.Framework/Graphics/Textures/TextureFilteringMode.cs b/osu.Framework/Graphics/Textures/TextureFilteringMode.cs new file mode 100644 index 000000000..17007e12a --- /dev/null +++ b/osu.Framework/Graphics/Textures/TextureFilteringMode.cs @@ -0,0 +1,11 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +namespace osu.Framework.Graphics.Textures +{ + public enum TextureFilteringMode + { + Linear, + Nearest, + } +} diff --git a/osu.Framework/Graphics/Textures/TextureLoaderStore.cs b/osu.Framework/Graphics/Textures/TextureLoaderStore.cs index c2802d7ab..d719402d5 100644 --- a/osu.Framework/Graphics/Textures/TextureLoaderStore.cs +++ b/osu.Framework/Graphics/Textures/TextureLoaderStore.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.IO; @@ -12,15 +14,18 @@ using SixLabors.ImageSharp.PixelFormats; namespace osu.Framework.Graphics.Textures { + /// + /// Handles the parsing of image data from standard image formats into s ready for GPU consumption. + /// public class TextureLoaderStore : IResourceStore { - private IResourceStore store { get; } + private readonly ResourceStore store; public TextureLoaderStore(IResourceStore store) { - this.store = store; - (store as ResourceStore)?.AddExtension(@"png"); - (store as ResourceStore)?.AddExtension(@"jpg"); + this.store = new ResourceStore(store); + this.store.AddExtension(@"png"); + this.store.AddExtension(@"jpg"); } public Task GetAsync(string name, CancellationToken cancellationToken = default) => diff --git a/osu.Framework/Graphics/Textures/TextureStore.cs b/osu.Framework/Graphics/Textures/TextureStore.cs index 87a050df9..a97b853c5 100644 --- a/osu.Framework/Graphics/Textures/TextureStore.cs +++ b/osu.Framework/Graphics/Textures/TextureStore.cs @@ -1,12 +1,16 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Graphics.OpenGL; using osu.Framework.Graphics.OpenGL.Textures; using osu.Framework.IO.Stores; using System.Collections.Generic; using System.Diagnostics; +using System.IO; +using System.Linq; using System.Threading; using System.Threading.Tasks; using JetBrains.Annotations; @@ -16,10 +20,16 @@ using osuTK.Graphics.ES30; namespace osu.Framework.Graphics.Textures { - public class TextureStore : ResourceStore + /// + /// Provides drawable-ready s sourced from any number of provided sources (via constructor parameter or ). + /// + public class TextureStore : ITextureStore { private readonly Dictionary textureCache = new Dictionary(); + private readonly ResourceStore uploadStore = new ResourceStore(); + private readonly List nestedStores = new List(); + private readonly All filteringMode; private readonly bool manualMipmaps; @@ -34,16 +44,15 @@ namespace osu.Framework.Graphics.Textures public readonly float ScaleAdjust; public TextureStore(IResourceStore store = null, bool useAtlas = true, All filteringMode = All.Linear, bool manualMipmaps = false, float scaleAdjust = 2) - : base(store) { + if (store != null) + AddTextureSource(store); + this.filteringMode = filteringMode; this.manualMipmaps = manualMipmaps; ScaleAdjust = scaleAdjust; - AddExtension(@"png"); - AddExtension(@"jpg"); - if (useAtlas) { int size = Math.Min(max_atlas_size, GLWrapper.MaxTextureSize); @@ -51,7 +60,43 @@ namespace osu.Framework.Graphics.Textures } } - private Texture getTexture(string name, WrapMode wrapModeS = WrapMode.None, WrapMode wrapModeT = WrapMode.None) => loadRaw(base.Get(name), wrapModeS, wrapModeT); + /// + /// Adds a texture data lookup source to load s with. + /// + /// + /// Lookup sources can be implemented easily using a to provide the final . + /// + /// The store to add. + public virtual void AddTextureSource(IResourceStore store) => uploadStore.AddStore(store); + + /// + /// Removes a texture data lookup source. + /// + /// The store to remove. + public virtual void RemoveTextureStore(IResourceStore store) => uploadStore.RemoveStore(store); + + /// + /// Adds a nested texture store to use during lookup if not found in this store. + /// + /// + /// Of note, nested stores will use their own sources and not include any sources added via . + /// + /// The store to add. + public virtual void AddStore(ITextureStore store) + { + lock (nestedStores) + nestedStores.Add(store); + } + + /// + /// Removes a nested texture store. + /// + /// The store to remove. + public virtual void RemoveStore(ITextureStore store) + { + lock (nestedStores) + nestedStores.Remove(store); + } private Texture loadRaw(TextureUpload upload, WrapMode wrapModeS = WrapMode.None, WrapMode wrapModeT = WrapMode.None) { @@ -83,7 +128,7 @@ namespace osu.Framework.Graphics.Textures /// The name of the texture. /// A cancellation token. /// The texture. - public new Task GetAsync(string name, CancellationToken cancellationToken) => GetAsync(name, default, default, cancellationToken); + public Task GetAsync(string name, CancellationToken cancellationToken) => GetAsync(name, default, default, cancellationToken); /// /// Retrieves a texture from the store and adds it to the atlas. @@ -101,7 +146,7 @@ namespace osu.Framework.Graphics.Textures /// /// The name of the texture. /// The texture. - public new Texture Get(string name) => Get(name, default, default); + public Texture Get(string name) => Get(name, default, default); private readonly Dictionary retrievalCompletionSources = new Dictionary(); @@ -113,6 +158,50 @@ namespace osu.Framework.Graphics.Textures /// The texture wrap mode in vertical direction. /// The texture. public virtual Texture Get(string name, WrapMode wrapModeS, WrapMode wrapModeT) + { + var texture = get(name, wrapModeS, wrapModeT); + + if (texture == null) + { + lock (nestedStores) + { + foreach (var nested in nestedStores) + { + if ((texture = nested.Get(name, wrapModeS, wrapModeT)) != null) + break; + } + } + } + + return texture; + } + + public Stream GetStream(string name) + { + var stream = uploadStore.GetStream(name); + + if (stream == null) + { + lock (nestedStores) + { + foreach (var nested in nestedStores) + { + if ((stream = nested.GetStream(name)) != null) + break; + } + } + } + + return stream; + } + + public IEnumerable GetAvailableResources() + { + lock (nestedStores) + return uploadStore.GetAvailableResources().Concat(nestedStores.SelectMany(s => s.GetAvailableResources()).ExcludeSystemFileNames()).ToArray(); + } + + private Texture get(string name, WrapMode wrapModeS, WrapMode wrapModeT) { if (string.IsNullOrEmpty(name)) return null; @@ -151,7 +240,7 @@ namespace osu.Framework.Graphics.Textures try { - tex = getTexture(name, wrapModeS, wrapModeT); + tex = loadRaw(uploadStore.Get(name), wrapModeS, wrapModeT); if (tex != null) tex.LookupKey = key; @@ -220,5 +309,28 @@ namespace osu.Framework.Graphics.Textures textureCache.Remove(texture.LookupKey); } } + + #region IDisposable Support + + private bool isDisposed; + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (!isDisposed) + { + isDisposed = true; + + uploadStore.Dispose(); + lock (nestedStores) nestedStores.ForEach(s => s.Dispose()); + } + } + + #endregion } } diff --git a/osu.Framework/Graphics/Textures/TextureTooLargeForGLException.cs b/osu.Framework/Graphics/Textures/TextureTooLargeForGLException.cs index cf41a93a5..3ef4eae29 100644 --- a/osu.Framework/Graphics/Textures/TextureTooLargeForGLException.cs +++ b/osu.Framework/Graphics/Textures/TextureTooLargeForGLException.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; namespace osu.Framework.Graphics.Textures diff --git a/osu.Framework/Graphics/Textures/TextureUpload.cs b/osu.Framework/Graphics/Textures/TextureUpload.cs index 080650e67..419f9f557 100644 --- a/osu.Framework/Graphics/Textures/TextureUpload.cs +++ b/osu.Framework/Graphics/Textures/TextureUpload.cs @@ -1,9 +1,12 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.IO; using System.Runtime.InteropServices; +using osu.Framework.Extensions; using osu.Framework.Extensions.ImageExtensions; using osu.Framework.Graphics.OpenGL; using osu.Framework.Graphics.OpenGL.Buffers; @@ -86,10 +89,11 @@ namespace osu.Framework.Graphics.Textures try { - using (var m = new MemoryStream()) + using (var buffer = SixLabors.ImageSharp.Configuration.Default.MemoryAllocator.Allocate((int)stream.Length)) { - stream.CopyTo(m); - using (var stbiImage = Stbi.LoadFromMemory(m, 4)) + stream.ReadToFill(buffer.Memory.Span); + + using (var stbiImage = Stbi.LoadFromMemory(buffer.Memory.Span, 4)) return Image.LoadPixelData(MemoryMarshal.Cast(stbiImage.Data), stbiImage.Width, stbiImage.Height); } } diff --git a/osu.Framework/Graphics/Textures/TextureWhitePixel.cs b/osu.Framework/Graphics/Textures/TextureWhitePixel.cs index 9b8f97df4..c02d60298 100644 --- a/osu.Framework/Graphics/Textures/TextureWhitePixel.cs +++ b/osu.Framework/Graphics/Textures/TextureWhitePixel.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.OpenGL; using osu.Framework.Graphics.OpenGL.Textures; using osu.Framework.Graphics.Primitives; diff --git a/osu.Framework/Graphics/Textures/TextureWithRefCount.cs b/osu.Framework/Graphics/Textures/TextureWithRefCount.cs index 8502c2db8..5a0b96805 100644 --- a/osu.Framework/Graphics/Textures/TextureWithRefCount.cs +++ b/osu.Framework/Graphics/Textures/TextureWithRefCount.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Threading; using osu.Framework.Graphics.OpenGL.Textures; diff --git a/osu.Framework/Graphics/TransformSequenceExtensions.cs b/osu.Framework/Graphics/TransformSequenceExtensions.cs index 84fffead9..e6ac365c6 100644 --- a/osu.Framework/Graphics/TransformSequenceExtensions.cs +++ b/osu.Framework/Graphics/TransformSequenceExtensions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osuTK; using osuTK.Graphics; using osu.Framework.Graphics.Colour; diff --git a/osu.Framework/Graphics/TransformableExtensions.cs b/osu.Framework/Graphics/TransformableExtensions.cs index b4a109fe1..4f327b514 100644 --- a/osu.Framework/Graphics/TransformableExtensions.cs +++ b/osu.Framework/Graphics/TransformableExtensions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osuTK; using osuTK.Graphics; using osu.Framework.Graphics.Colour; @@ -141,6 +143,9 @@ namespace osu.Framework.Graphics where TThis : class, ITransformable where TEasing : IEasingFunction { + if (!isFinite(newValue)) + throw new ArgumentException($"{nameof(newValue)} must be finite, but is {newValue}.", nameof(newValue)); + if (duration < 0) throw new ArgumentOutOfRangeException(nameof(duration), $"{nameof(duration)} must be positive."); @@ -157,6 +162,20 @@ namespace osu.Framework.Graphics transform.Easing = easing; return transform; + + static bool isFinite(TValue value) + { + if (typeof(TValue) == typeof(float)) + return float.IsFinite((float)(object)value); + if (typeof(TValue) == typeof(double)) + return double.IsFinite((double)(object)value); + if (typeof(TValue) == typeof(Vector2)) + return Validation.IsFinite((Vector2)(object)value); + if (typeof(TValue) == typeof(MarginPadding)) + return Validation.IsFinite((MarginPadding)(object)value); + + return true; + } } /// @@ -676,7 +695,12 @@ namespace osu.Framework.Graphics public static TransformSequence TransformRelativeChildSizeTo(this T container, Vector2 newSize, double duration, in TEasing easing) where T : class, IContainer where TEasing : IEasingFunction - => container.TransformTo(nameof(container.RelativeChildSize), newSize, duration, easing); + { + if (newSize.X == 0 || newSize.Y == 0) + throw new ArgumentException($@"{nameof(newSize)} must be non-zero, but is {newSize}.", nameof(newSize)); + + return container.TransformTo(nameof(container.RelativeChildSize), newSize, duration, easing); + } /// /// Smoothly adjusts over time. diff --git a/osu.Framework/Graphics/Transforms/DefaultEasingFunction.cs b/osu.Framework/Graphics/Transforms/DefaultEasingFunction.cs index 2a8be8f90..f48785fb8 100644 --- a/osu.Framework/Graphics/Transforms/DefaultEasingFunction.cs +++ b/osu.Framework/Graphics/Transforms/DefaultEasingFunction.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; namespace osu.Framework.Graphics.Transforms diff --git a/osu.Framework/Graphics/Transforms/IEasingFunction.cs b/osu.Framework/Graphics/Transforms/IEasingFunction.cs index 22ff66f29..1cd645936 100644 --- a/osu.Framework/Graphics/Transforms/IEasingFunction.cs +++ b/osu.Framework/Graphics/Transforms/IEasingFunction.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Graphics.Transforms { /// diff --git a/osu.Framework/Graphics/Transforms/ITransformSequence.cs b/osu.Framework/Graphics/Transforms/ITransformSequence.cs index 43ef8f45f..942a78f5d 100644 --- a/osu.Framework/Graphics/Transforms/ITransformSequence.cs +++ b/osu.Framework/Graphics/Transforms/ITransformSequence.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Graphics.Transforms { public interface ITransformSequence diff --git a/osu.Framework/Graphics/Transforms/ITransformable.cs b/osu.Framework/Graphics/Transforms/ITransformable.cs index 54550edff..0a84ab890 100644 --- a/osu.Framework/Graphics/Transforms/ITransformable.cs +++ b/osu.Framework/Graphics/Transforms/ITransformable.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Allocation; using osu.Framework.Timing; diff --git a/osu.Framework/Graphics/Transforms/TargetGroupingTransformTracker.cs b/osu.Framework/Graphics/Transforms/TargetGroupingTransformTracker.cs index 174627115..49be26fb0 100644 --- a/osu.Framework/Graphics/Transforms/TargetGroupingTransformTracker.cs +++ b/osu.Framework/Graphics/Transforms/TargetGroupingTransformTracker.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/osu.Framework/Graphics/Transforms/Transform.cs b/osu.Framework/Graphics/Transforms/Transform.cs index 77faa4dfc..689aa8af0 100644 --- a/osu.Framework/Graphics/Transforms/Transform.cs +++ b/osu.Framework/Graphics/Transforms/Transform.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; diff --git a/osu.Framework/Graphics/Transforms/TransformBindable.cs b/osu.Framework/Graphics/Transforms/TransformBindable.cs index f6552d6d5..a0200b60e 100644 --- a/osu.Framework/Graphics/Transforms/TransformBindable.cs +++ b/osu.Framework/Graphics/Transforms/TransformBindable.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Bindables; using osu.Framework.Utils; diff --git a/osu.Framework/Graphics/Transforms/TransformCustom.cs b/osu.Framework/Graphics/Transforms/TransformCustom.cs index 5140167d8..4ad2ee80c 100644 --- a/osu.Framework/Graphics/Transforms/TransformCustom.cs +++ b/osu.Framework/Graphics/Transforms/TransformCustom.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Utils; using System; using System.Collections.Concurrent; diff --git a/osu.Framework/Graphics/Transforms/TransformSequence.cs b/osu.Framework/Graphics/Transforms/TransformSequence.cs index b2b8e6d32..f20a2e8c1 100644 --- a/osu.Framework/Graphics/Transforms/TransformSequence.cs +++ b/osu.Framework/Graphics/Transforms/TransformSequence.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; diff --git a/osu.Framework/Graphics/Transforms/Transformable.cs b/osu.Framework/Graphics/Transforms/Transformable.cs index a6cf35ca4..ca62a1f8c 100644 --- a/osu.Framework/Graphics/Transforms/Transformable.cs +++ b/osu.Framework/Graphics/Transforms/Transformable.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; @@ -40,7 +42,7 @@ namespace osu.Framework.Graphics.Transforms /// /// A lazily-initialized list of s applied to this object. /// - public IEnumerable Transforms => targetGroupingTrackers.SelectMany(t => t.Transforms); + public IEnumerable Transforms => targetGroupingTrackers?.SelectMany(t => t.Transforms) ?? Array.Empty(); /// /// Retrieves the s for a given target member. @@ -61,13 +63,16 @@ namespace osu.Framework.Graphics.Transforms //expiry should happen either at the end of the last transform or using the current sequence delay (whichever is highest). double max = TransformStartTime; - foreach (var tracker in targetGroupingTrackers) + if (targetGroupingTrackers != null) { - for (int i = 0; i < tracker.Transforms.Count; i++) + foreach (var tracker in targetGroupingTrackers) { - var t = tracker.Transforms[i]; - if (t.EndTime > max) - max = t.EndTime + 1; //adding 1ms here ensures we can expire on the current frame without issue. + for (int i = 0; i < tracker.Transforms.Count; i++) + { + var t = tracker.Transforms[i]; + if (t.EndTime > max) + max = t.EndTime + 1; //adding 1ms here ensures we can expire on the current frame without issue. + } } } @@ -86,19 +91,26 @@ namespace osu.Framework.Graphics.Transforms protected void UpdateTransforms() { TransformDelay = 0; + + if (targetGroupingTrackers == null) + return; + updateTransforms(Time.Current); } private double lastUpdateTransformsTime; - private readonly List targetGroupingTrackers = new List(); + private List targetGroupingTrackers; private TargetGroupingTransformTracker getTrackerFor(string targetMember) { - foreach (var t in targetGroupingTrackers) + if (targetGroupingTrackers != null) { - if (t.TargetMembers.Contains(targetMember)) - return t; + foreach (var t in targetGroupingTrackers) + { + if (t.TargetMembers.Contains(targetMember)) + return t; + } } return null; @@ -106,17 +118,23 @@ namespace osu.Framework.Graphics.Transforms private TargetGroupingTransformTracker getTrackerForGrouping(string targetGrouping, bool createIfNotExisting) { - foreach (var t in targetGroupingTrackers) + if (targetGroupingTrackers != null) { - if (t.TargetGrouping == targetGrouping) - return t; + foreach (var t in targetGroupingTrackers) + { + if (t.TargetGrouping == targetGrouping) + return t; + } } if (!createIfNotExisting) return null; var tracker = new TargetGroupingTransformTracker(this, targetGrouping); + + targetGroupingTrackers ??= new List(); targetGroupingTrackers.Add(tracker); + return tracker; } @@ -128,6 +146,9 @@ namespace osu.Framework.Graphics.Transforms /// Whether prior transforms should be reprocessed even if a rewind was not detected. private void updateTransforms(double time, bool forceRewindReprocess = false) { + if (targetGroupingTrackers == null) + return; + bool rewinding = lastUpdateTransformsTime > time || forceRewindReprocess; lastUpdateTransformsTime = time; @@ -175,6 +196,9 @@ namespace osu.Framework.Graphics.Transforms /// public virtual void ClearTransformsAfter(double time, bool propagateChildren = false, string targetMember = null) { + if (targetGroupingTrackers == null) + return; + EnsureTransformMutationAllowed(); if (targetMember != null) @@ -216,6 +240,9 @@ namespace osu.Framework.Graphics.Transforms /// public virtual void FinishTransforms(bool propagateChildren = false, string targetMember = null) { + if (targetGroupingTrackers == null) + return; + EnsureTransformMutationAllowed(); if (targetMember != null) @@ -224,7 +251,9 @@ namespace osu.Framework.Graphics.Transforms } else { - // collection may grow due to abort / completion events. + // Use for over foreach as collection may grow due to abort / completion events. + // Note that this may mean that in the addition of elements being removed, + // `FinishTransforms` may not be called on all items. for (int i = 0; i < targetGroupingTrackers.Count; i++) targetGroupingTrackers[i].FinishTransforms(); } diff --git a/osu.Framework/Graphics/UserInterface/BasicButton.cs b/osu.Framework/Graphics/UserInterface/BasicButton.cs index cbcd95c8f..bc49198f4 100644 --- a/osu.Framework/Graphics/UserInterface/BasicButton.cs +++ b/osu.Framework/Graphics/UserInterface/BasicButton.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Bindables; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics.Sprites; diff --git a/osu.Framework/Graphics/UserInterface/BasicCheckbox.cs b/osu.Framework/Graphics/UserInterface/BasicCheckbox.cs index b77e3828c..ee1ca7e7d 100644 --- a/osu.Framework/Graphics/UserInterface/BasicCheckbox.cs +++ b/osu.Framework/Graphics/UserInterface/BasicCheckbox.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osuTK; using osuTK.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework/Graphics/UserInterface/BasicColourPicker.cs b/osu.Framework/Graphics/UserInterface/BasicColourPicker.cs index 8461eae81..e2e44cc34 100644 --- a/osu.Framework/Graphics/UserInterface/BasicColourPicker.cs +++ b/osu.Framework/Graphics/UserInterface/BasicColourPicker.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Graphics.UserInterface { public class BasicColourPicker : ColourPicker diff --git a/osu.Framework/Graphics/UserInterface/BasicDirectorySelector.cs b/osu.Framework/Graphics/UserInterface/BasicDirectorySelector.cs index e5a6f2212..8df34c005 100644 --- a/osu.Framework/Graphics/UserInterface/BasicDirectorySelector.cs +++ b/osu.Framework/Graphics/UserInterface/BasicDirectorySelector.cs @@ -1,8 +1,11 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.IO; using osu.Framework.Graphics.Containers; +using osuTK; namespace osu.Framework.Graphics.UserInterface { @@ -10,6 +13,13 @@ namespace osu.Framework.Graphics.UserInterface { protected override DirectorySelectorBreadcrumbDisplay CreateBreadcrumb() => new BasicDirectorySelectorBreadcrumbDisplay(); + protected override Drawable CreateHiddenToggleButton() => new BasicButton + { + Size = new Vector2(200, 25), + Text = "Toggle hidden items", + Action = ShowHiddenItems.Toggle, + }; + protected override DirectorySelectorDirectory CreateDirectoryItem(DirectoryInfo directory, string displayName = null) => new BasicDirectorySelectorDirectory(directory, displayName); protected override DirectorySelectorDirectory CreateParentDirectoryItem(DirectoryInfo directory) => new BasicDirectorySelectorParentDirectory(directory); diff --git a/osu.Framework/Graphics/UserInterface/BasicDirectorySelectorBreadcrumbDisplay.cs b/osu.Framework/Graphics/UserInterface/BasicDirectorySelectorBreadcrumbDisplay.cs index fe9394e30..e4abb0f8b 100644 --- a/osu.Framework/Graphics/UserInterface/BasicDirectorySelectorBreadcrumbDisplay.cs +++ b/osu.Framework/Graphics/UserInterface/BasicDirectorySelectorBreadcrumbDisplay.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.IO; using osu.Framework.Allocation; using osu.Framework.Graphics.Sprites; @@ -47,6 +49,11 @@ namespace osu.Framework.Graphics.UserInterface { } + // this method is suppressed to ensure the breadcrumbs of hidden directories are presented the same way as non-hidden directories + protected sealed override void ApplyHiddenState() + { + } + [BackgroundDependencyLoader] private void load() { diff --git a/osu.Framework/Graphics/UserInterface/BasicDirectorySelectorDirectory.cs b/osu.Framework/Graphics/UserInterface/BasicDirectorySelectorDirectory.cs index 78983cec4..980dc46f9 100644 --- a/osu.Framework/Graphics/UserInterface/BasicDirectorySelectorDirectory.cs +++ b/osu.Framework/Graphics/UserInterface/BasicDirectorySelectorDirectory.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.IO; using osu.Framework.Graphics.Sprites; diff --git a/osu.Framework/Graphics/UserInterface/BasicDirectorySelectorParentDirectory.cs b/osu.Framework/Graphics/UserInterface/BasicDirectorySelectorParentDirectory.cs index 456539bef..6a8f743c4 100644 --- a/osu.Framework/Graphics/UserInterface/BasicDirectorySelectorParentDirectory.cs +++ b/osu.Framework/Graphics/UserInterface/BasicDirectorySelectorParentDirectory.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.IO; using osu.Framework.Graphics.Sprites; @@ -14,5 +16,10 @@ namespace osu.Framework.Graphics.UserInterface : base(directory, "..") { } + + // this method is suppressed to ensure that parent directories that are also hidden directories are presented the same way as non-hidden parent directories + protected sealed override void ApplyHiddenState() + { + } } } diff --git a/osu.Framework/Graphics/UserInterface/BasicDropdown.cs b/osu.Framework/Graphics/UserInterface/BasicDropdown.cs index e04bff02b..178fb0fcb 100644 --- a/osu.Framework/Graphics/UserInterface/BasicDropdown.cs +++ b/osu.Framework/Graphics/UserInterface/BasicDropdown.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; using osu.Framework.Localisation; diff --git a/osu.Framework/Graphics/UserInterface/BasicFileSelector.cs b/osu.Framework/Graphics/UserInterface/BasicFileSelector.cs index 6449d58cf..d11727b38 100644 --- a/osu.Framework/Graphics/UserInterface/BasicFileSelector.cs +++ b/osu.Framework/Graphics/UserInterface/BasicFileSelector.cs @@ -1,9 +1,12 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.IO; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; +using osuTK; namespace osu.Framework.Graphics.UserInterface { @@ -11,6 +14,13 @@ namespace osu.Framework.Graphics.UserInterface { protected override DirectorySelectorBreadcrumbDisplay CreateBreadcrumb() => new BasicDirectorySelectorBreadcrumbDisplay(); + protected override Drawable CreateHiddenToggleButton() => new BasicButton + { + Size = new Vector2(200, 25), + Text = "Toggle hidden items", + Action = ShowHiddenItems.Toggle, + }; + protected override DirectorySelectorDirectory CreateDirectoryItem(DirectoryInfo directory, string displayName = null) => new BasicDirectorySelectorDirectory(directory, displayName); protected override DirectorySelectorDirectory CreateParentDirectoryItem(DirectoryInfo directory) => new BasicDirectorySelectorParentDirectory(directory); diff --git a/osu.Framework/Graphics/UserInterface/BasicHSVColourPicker.cs b/osu.Framework/Graphics/UserInterface/BasicHSVColourPicker.cs index 775b126c5..1126ad1bb 100644 --- a/osu.Framework/Graphics/UserInterface/BasicHSVColourPicker.cs +++ b/osu.Framework/Graphics/UserInterface/BasicHSVColourPicker.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osuTK; diff --git a/osu.Framework/Graphics/UserInterface/BasicHexColourPicker.cs b/osu.Framework/Graphics/UserInterface/BasicHexColourPicker.cs index 4769900c6..e41b13df4 100644 --- a/osu.Framework/Graphics/UserInterface/BasicHexColourPicker.cs +++ b/osu.Framework/Graphics/UserInterface/BasicHexColourPicker.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.Shapes; namespace osu.Framework.Graphics.UserInterface diff --git a/osu.Framework/Graphics/UserInterface/BasicMenu.cs b/osu.Framework/Graphics/UserInterface/BasicMenu.cs index fe9be2c3b..4193d1378 100644 --- a/osu.Framework/Graphics/UserInterface/BasicMenu.cs +++ b/osu.Framework/Graphics/UserInterface/BasicMenu.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; diff --git a/osu.Framework/Graphics/UserInterface/BasicPasswordTextBox.cs b/osu.Framework/Graphics/UserInterface/BasicPasswordTextBox.cs index 42fc9602d..ebaf1001f 100644 --- a/osu.Framework/Graphics/UserInterface/BasicPasswordTextBox.cs +++ b/osu.Framework/Graphics/UserInterface/BasicPasswordTextBox.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input; namespace osu.Framework.Graphics.UserInterface diff --git a/osu.Framework/Graphics/UserInterface/BasicPopover.cs b/osu.Framework/Graphics/UserInterface/BasicPopover.cs index 34d91ad1e..46036590d 100644 --- a/osu.Framework/Graphics/UserInterface/BasicPopover.cs +++ b/osu.Framework/Graphics/UserInterface/BasicPopover.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using osu.Framework.Extensions.EnumExtensions; using osu.Framework.Graphics.Shapes; using osuTK; diff --git a/osu.Framework/Graphics/UserInterface/BasicRearrangeableListContainer.cs b/osu.Framework/Graphics/UserInterface/BasicRearrangeableListContainer.cs index bf6c57926..e33037f20 100644 --- a/osu.Framework/Graphics/UserInterface/BasicRearrangeableListContainer.cs +++ b/osu.Framework/Graphics/UserInterface/BasicRearrangeableListContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Allocation; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework/Graphics/UserInterface/BasicSliderBar.cs b/osu.Framework/Graphics/UserInterface/BasicSliderBar.cs index 40ec19472..be6a49e71 100644 --- a/osu.Framework/Graphics/UserInterface/BasicSliderBar.cs +++ b/osu.Framework/Graphics/UserInterface/BasicSliderBar.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osuTK; using osuTK.Graphics; diff --git a/osu.Framework/Graphics/UserInterface/BasicTabControl.cs b/osu.Framework/Graphics/UserInterface/BasicTabControl.cs index 7365ea752..ddc7ec340 100644 --- a/osu.Framework/Graphics/UserInterface/BasicTabControl.cs +++ b/osu.Framework/Graphics/UserInterface/BasicTabControl.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.Sprites; using osuTK.Graphics; diff --git a/osu.Framework/Graphics/UserInterface/BasicTextBox.cs b/osu.Framework/Graphics/UserInterface/BasicTextBox.cs index e53dc56b9..56f9c64ad 100644 --- a/osu.Framework/Graphics/UserInterface/BasicTextBox.cs +++ b/osu.Framework/Graphics/UserInterface/BasicTextBox.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; diff --git a/osu.Framework/Graphics/UserInterface/Button.cs b/osu.Framework/Graphics/UserInterface/Button.cs index 72ecde85b..fa5014dbe 100644 --- a/osu.Framework/Graphics/UserInterface/Button.cs +++ b/osu.Framework/Graphics/UserInterface/Button.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.Containers; namespace osu.Framework.Graphics.UserInterface diff --git a/osu.Framework/Graphics/UserInterface/Caret.cs b/osu.Framework/Graphics/UserInterface/Caret.cs index 02fd276d9..3928c8107 100644 --- a/osu.Framework/Graphics/UserInterface/Caret.cs +++ b/osu.Framework/Graphics/UserInterface/Caret.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.Containers; using osuTK; diff --git a/osu.Framework/Graphics/UserInterface/Checkbox.cs b/osu.Framework/Graphics/UserInterface/Checkbox.cs index 967837be4..eb887e654 100644 --- a/osu.Framework/Graphics/UserInterface/Checkbox.cs +++ b/osu.Framework/Graphics/UserInterface/Checkbox.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Bindables; using osu.Framework.Graphics.Containers; using osu.Framework.Input.Events; diff --git a/osu.Framework/Graphics/UserInterface/CircularProgress.cs b/osu.Framework/Graphics/UserInterface/CircularProgress.cs index 0402441ef..69bdefdfb 100644 --- a/osu.Framework/Graphics/UserInterface/CircularProgress.cs +++ b/osu.Framework/Graphics/UserInterface/CircularProgress.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Allocation; using osu.Framework.Bindables; @@ -22,7 +24,7 @@ namespace osu.Framework.Graphics.UserInterface public CircularProgress() { - Current.ValueChanged += newValue => Invalidate(Invalidation.DrawNode); + Current.ValueChanged += _ => Invalidate(Invalidation.DrawNode); } public IShader RoundedTextureShader { get; private set; } diff --git a/osu.Framework/Graphics/UserInterface/CircularProgressDrawNode.cs b/osu.Framework/Graphics/UserInterface/CircularProgressDrawNode.cs index 082d957ad..46379635a 100644 --- a/osu.Framework/Graphics/UserInterface/CircularProgressDrawNode.cs +++ b/osu.Framework/Graphics/UserInterface/CircularProgressDrawNode.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.Textures; using osuTK.Graphics.ES30; using osuTK; diff --git a/osu.Framework/Graphics/UserInterface/ColourPicker.cs b/osu.Framework/Graphics/UserInterface/ColourPicker.cs index 159c10aff..bfbe1e21b 100644 --- a/osu.Framework/Graphics/UserInterface/ColourPicker.cs +++ b/osu.Framework/Graphics/UserInterface/ColourPicker.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Bindables; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework/Graphics/UserInterface/Counter.cs b/osu.Framework/Graphics/UserInterface/Counter.cs index 1c82ab6ce..a2d364d58 100644 --- a/osu.Framework/Graphics/UserInterface/Counter.cs +++ b/osu.Framework/Graphics/UserInterface/Counter.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Transforms; diff --git a/osu.Framework/Graphics/UserInterface/DirectorySelector.cs b/osu.Framework/Graphics/UserInterface/DirectorySelector.cs index 5c421e347..9397b15ed 100644 --- a/osu.Framework/Graphics/UserInterface/DirectorySelector.cs +++ b/osu.Framework/Graphics/UserInterface/DirectorySelector.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.IO; @@ -21,6 +23,8 @@ namespace osu.Framework.Graphics.UserInterface { private FillFlowContainer directoryFlow; + protected readonly BindableBool ShowHiddenItems = new BindableBool(); + protected abstract ScrollContainer CreateScrollContainer(); /// @@ -28,6 +32,14 @@ namespace osu.Framework.Graphics.UserInterface /// protected abstract DirectorySelectorBreadcrumbDisplay CreateBreadcrumb(); + /// + /// Create a button that toggles the display of hidden items. + /// + /// + /// Unless overridden, a toggle button will not be added. + /// + protected virtual Drawable CreateHiddenToggleButton() => Empty(); + protected abstract DirectorySelectorDirectory CreateDirectoryItem(DirectoryInfo directory, string displayName = null); /// @@ -69,7 +81,25 @@ namespace osu.Framework.Graphics.UserInterface { new Drawable[] { - CreateBreadcrumb() + new GridContainer + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + ColumnDimensions = new[] + { + new Dimension(), + new Dimension(GridSizeMode.AutoSize), + }, + RowDimensions = new[] { new Dimension(GridSizeMode.AutoSize) }, + Content = new[] + { + new[] + { + CreateBreadcrumb(), + CreateHiddenToggleButton() + } + } + } }, new Drawable[] { @@ -88,7 +118,8 @@ namespace osu.Framework.Graphics.UserInterface } }; - CurrentPath.BindValueChanged(updateDisplay, true); + ShowHiddenItems.ValueChanged += _ => updateDisplay(); + CurrentPath.BindValueChanged(_ => updateDisplay(), true); } /// @@ -98,7 +129,7 @@ namespace osu.Framework.Graphics.UserInterface /// private bool directoryChanging; - private void updateDisplay(ValueChangedEvent directory) + private void updateDisplay() { if (directoryChanging) return; @@ -109,7 +140,7 @@ namespace osu.Framework.Graphics.UserInterface directoryFlow.Clear(); - var newDirectory = directory.NewValue; + var newDirectory = CurrentPath.Value; bool notifyError = false; ICollection items = Array.Empty(); @@ -166,7 +197,7 @@ namespace osu.Framework.Graphics.UserInterface { foreach (var dir in path.GetDirectories().OrderBy(d => d.Name)) { - if (!dir.Attributes.HasFlagFast(FileAttributes.Hidden)) + if (ShowHiddenItems.Value || !dir.Attributes.HasFlagFast(FileAttributes.Hidden)) items.Add(CreateDirectoryItem(dir)); } diff --git a/osu.Framework/Graphics/UserInterface/DirectorySelectorBreadcrumbDisplay.cs b/osu.Framework/Graphics/UserInterface/DirectorySelectorBreadcrumbDisplay.cs index a29a72c68..4ea6bc2a4 100644 --- a/osu.Framework/Graphics/UserInterface/DirectorySelectorBreadcrumbDisplay.cs +++ b/osu.Framework/Graphics/UserInterface/DirectorySelectorBreadcrumbDisplay.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using System.IO; using System.Linq; diff --git a/osu.Framework/Graphics/UserInterface/DirectorySelectorDirectory.cs b/osu.Framework/Graphics/UserInterface/DirectorySelectorDirectory.cs index a27e62293..b89a40ff8 100644 --- a/osu.Framework/Graphics/UserInterface/DirectorySelectorDirectory.cs +++ b/osu.Framework/Graphics/UserInterface/DirectorySelectorDirectory.cs @@ -1,10 +1,14 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + +using System; using System.IO; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Input.Events; +using osu.Framework.Extensions.EnumExtensions; namespace osu.Framework.Graphics.UserInterface { @@ -20,6 +24,16 @@ namespace osu.Framework.Graphics.UserInterface : base(displayName) { Directory = directory; + + try + { + if (directory?.Attributes.HasFlagFast(FileAttributes.Hidden) == true) + ApplyHiddenState(); + } + catch (UnauthorizedAccessException) + { + // checking attributes on access-controlled directories will throw an error so we handle it here to prevent a crash + } } protected override bool OnClick(ClickEvent e) diff --git a/osu.Framework/Graphics/UserInterface/DirectorySelectorItem.cs b/osu.Framework/Graphics/UserInterface/DirectorySelectorItem.cs index abab8c06e..e204faf5e 100644 --- a/osu.Framework/Graphics/UserInterface/DirectorySelectorItem.cs +++ b/osu.Framework/Graphics/UserInterface/DirectorySelectorItem.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Allocation; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; @@ -39,6 +41,12 @@ namespace osu.Framework.Graphics.UserInterface /// protected virtual SpriteText CreateSpriteText() => new SpriteText(); + /// + /// Called when this is a representation of a hidden item. + /// Used to customize the appearance of hidden items. + /// + protected virtual void ApplyHiddenState() => Alpha = 0.5f; + [BackgroundDependencyLoader] private void load() { diff --git a/osu.Framework/Graphics/UserInterface/Dropdown.cs b/osu.Framework/Graphics/UserInterface/Dropdown.cs index dcbe48352..2fc54316c 100644 --- a/osu.Framework/Graphics/UserInterface/Dropdown.cs +++ b/osu.Framework/Graphics/UserInterface/Dropdown.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; @@ -223,7 +225,7 @@ namespace osu.Framework.Graphics.UserInterface Menu.State = MenuState.Closed; }; - ItemSource.CollectionChanged += (_, __) => setItems(ItemSource); + ItemSource.CollectionChanged += (_, _) => setItems(ItemSource); } private void preselectionConfirmed(int selectedIndex) diff --git a/osu.Framework/Graphics/UserInterface/DropdownHeader.cs b/osu.Framework/Graphics/UserInterface/DropdownHeader.cs index 16c70ca11..02dc785ea 100644 --- a/osu.Framework/Graphics/UserInterface/DropdownHeader.cs +++ b/osu.Framework/Graphics/UserInterface/DropdownHeader.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osuTK.Graphics; using System; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework/Graphics/UserInterface/DropdownMenuItem.cs b/osu.Framework/Graphics/UserInterface/DropdownMenuItem.cs index 2719ae913..df7372a53 100644 --- a/osu.Framework/Graphics/UserInterface/DropdownMenuItem.cs +++ b/osu.Framework/Graphics/UserInterface/DropdownMenuItem.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Localisation; diff --git a/osu.Framework/Graphics/UserInterface/FileSelector.cs b/osu.Framework/Graphics/UserInterface/FileSelector.cs index 46cf04e3a..57bccd5aa 100644 --- a/osu.Framework/Graphics/UserInterface/FileSelector.cs +++ b/osu.Framework/Graphics/UserInterface/FileSelector.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.IO; @@ -47,7 +49,7 @@ namespace osu.Framework.Graphics.UserInterface foreach (var file in files.OrderBy(d => d.Name)) { - if (!file.Attributes.HasFlagFast(FileAttributes.Hidden)) + if (ShowHiddenItems.Value || !file.Attributes.HasFlagFast(FileAttributes.Hidden)) items.Add(CreateFileItem(file)); } @@ -69,6 +71,16 @@ namespace osu.Framework.Graphics.UserInterface protected DirectoryListingFile(FileInfo file) { File = file; + + try + { + if (File?.Attributes.HasFlagFast(FileAttributes.Hidden) == true) + ApplyHiddenState(); + } + catch (UnauthorizedAccessException) + { + // checking attributes on access-controlled files will throw an error so we handle it here to prevent a crash + } } protected override bool OnClick(ClickEvent e) diff --git a/osu.Framework/Graphics/UserInterface/HSVColourPicker.cs b/osu.Framework/Graphics/UserInterface/HSVColourPicker.cs index dc9453412..950403977 100644 --- a/osu.Framework/Graphics/UserInterface/HSVColourPicker.cs +++ b/osu.Framework/Graphics/UserInterface/HSVColourPicker.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Bindables; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; diff --git a/osu.Framework/Graphics/UserInterface/HSVColourPicker_HueSelector.cs b/osu.Framework/Graphics/UserInterface/HSVColourPicker_HueSelector.cs index e57f45fa2..72a7c94bf 100644 --- a/osu.Framework/Graphics/UserInterface/HSVColourPicker_HueSelector.cs +++ b/osu.Framework/Graphics/UserInterface/HSVColourPicker_HueSelector.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework/Graphics/UserInterface/HSVColourPicker_SaturationValueSelector.cs b/osu.Framework/Graphics/UserInterface/HSVColourPicker_SaturationValueSelector.cs index 9d5dca757..aa3e9572d 100644 --- a/osu.Framework/Graphics/UserInterface/HSVColourPicker_SaturationValueSelector.cs +++ b/osu.Framework/Graphics/UserInterface/HSVColourPicker_SaturationValueSelector.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Allocation; using osu.Framework.Bindables; diff --git a/osu.Framework/Graphics/UserInterface/HexColourPicker.cs b/osu.Framework/Graphics/UserInterface/HexColourPicker.cs index 7a8fc8bbb..272d0f4d1 100644 --- a/osu.Framework/Graphics/UserInterface/HexColourPicker.cs +++ b/osu.Framework/Graphics/UserInterface/HexColourPicker.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Bindables; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; diff --git a/osu.Framework/Graphics/UserInterface/IHasCurrentValue.cs b/osu.Framework/Graphics/UserInterface/IHasCurrentValue.cs index 506ffcdf4..57f2775c5 100644 --- a/osu.Framework/Graphics/UserInterface/IHasCurrentValue.cs +++ b/osu.Framework/Graphics/UserInterface/IHasCurrentValue.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Bindables; namespace osu.Framework.Graphics.UserInterface diff --git a/osu.Framework/Graphics/UserInterface/Menu.cs b/osu.Framework/Graphics/UserInterface/Menu.cs index 81c52ea55..85bf6fbad 100644 --- a/osu.Framework/Graphics/UserInterface/Menu.cs +++ b/osu.Framework/Graphics/UserInterface/Menu.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework/Graphics/UserInterface/MenuItem.cs b/osu.Framework/Graphics/UserInterface/MenuItem.cs index cd007e998..e8f45fa22 100644 --- a/osu.Framework/Graphics/UserInterface/MenuItem.cs +++ b/osu.Framework/Graphics/UserInterface/MenuItem.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using osu.Framework.Bindables; diff --git a/osu.Framework/Graphics/UserInterface/Popover.cs b/osu.Framework/Graphics/UserInterface/Popover.cs index 7495ffc23..99ccee985 100644 --- a/osu.Framework/Graphics/UserInterface/Popover.cs +++ b/osu.Framework/Graphics/UserInterface/Popover.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Extensions; using osu.Framework.Extensions.EnumExtensions; diff --git a/osu.Framework/Graphics/UserInterface/SliderBar.cs b/osu.Framework/Graphics/UserInterface/SliderBar.cs index c69a56919..e0a4b93cf 100644 --- a/osu.Framework/Graphics/UserInterface/SliderBar.cs +++ b/osu.Framework/Graphics/UserInterface/SliderBar.cs @@ -1,7 +1,10 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; +using System.Globalization; using osu.Framework.Bindables; using osu.Framework.Graphics.Containers; using osuTK.Input; @@ -112,10 +115,28 @@ namespace osu.Framework.Graphics.UserInterface private void updateValue() => UpdateValue(NormalizedValue); private bool handleClick; + private float? relativeValueAtMouseDown; protected override bool OnMouseDown(MouseDownEvent e) { - handleClick = true; + if (ShouldHandleAsRelativeDrag(e)) + { + float min = currentNumberInstantaneous.MinValue.ToSingle(NumberFormatInfo.InvariantInfo); + float max = currentNumberInstantaneous.MaxValue.ToSingle(NumberFormatInfo.InvariantInfo); + float val = currentNumberInstantaneous.Value.ToSingle(NumberFormatInfo.InvariantInfo); + + relativeValueAtMouseDown = (val - min) / (max - min); + + // Click shouldn't be handled if relative dragging is happening (i.e. while holding a nub). + // This is generally an expectation by most OSes and UIs. + handleClick = false; + } + else + { + handleClick = true; + relativeValueAtMouseDown = null; + } + return base.OnMouseDown(e); } @@ -149,11 +170,7 @@ namespace osu.Framework.Graphics.UserInterface return true; } - protected override void OnDragEnd(DragEndEvent e) - { - handleMouseInput(e); - commit(); - } + protected override void OnDragEnd(DragEndEvent e) => commit(); protected override bool OnKeyDown(KeyDownEvent e) { @@ -201,14 +218,36 @@ namespace osu.Framework.Graphics.UserInterface return true; } - private void handleMouseInput(UIEvent e) - { - float xPosition = ToLocalSpace(e.ScreenSpaceMousePosition).X - RangePadding; + /// + /// Whether mouse handling should be relative to the distance travelled, or absolute in line with the exact position of the cursor. + /// + /// + /// Generally, this should be overridden and return true when the cursor is hovering a "nub" or "thumb" portion at the point of mouse down + /// to give the user more correct control. + /// + /// The mouse down event. + /// Whether to perform a relative drag. + protected virtual bool ShouldHandleAsRelativeDrag(MouseDownEvent e) => false; + private void handleMouseInput(MouseButtonEvent e) + { if (currentNumberInstantaneous.Disabled) return; - currentNumberInstantaneous.SetProportional(xPosition / UsableWidth, e.ShiftPressed ? KeyboardStep : 0); + float localX = ToLocalSpace(e.ScreenSpaceMousePosition).X; + + float newValue; + + if (relativeValueAtMouseDown != null && e is DragEvent drag) + { + newValue = relativeValueAtMouseDown.Value + (localX - ToLocalSpace(drag.ScreenSpaceMouseDownPosition).X) / UsableWidth; + } + else + { + newValue = (localX - RangePadding) / UsableWidth; + } + + currentNumberInstantaneous.SetProportional(newValue, e.ShiftPressed ? KeyboardStep : 0); onUserChange(currentNumberInstantaneous.Value); } diff --git a/osu.Framework/Graphics/UserInterface/TabControl.cs b/osu.Framework/Graphics/UserInterface/TabControl.cs index 5dad62fe0..62a6107e2 100644 --- a/osu.Framework/Graphics/UserInterface/TabControl.cs +++ b/osu.Framework/Graphics/UserInterface/TabControl.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/osu.Framework/Graphics/UserInterface/TabItem.cs b/osu.Framework/Graphics/UserInterface/TabItem.cs index 39f404c07..a7422ce65 100644 --- a/osu.Framework/Graphics/UserInterface/TabItem.cs +++ b/osu.Framework/Graphics/UserInterface/TabItem.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Bindables; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework/Graphics/UserInterface/TextBox.cs b/osu.Framework/Graphics/UserInterface/TextBox.cs index f74595d31..ad4142618 100644 --- a/osu.Framework/Graphics/UserInterface/TextBox.cs +++ b/osu.Framework/Graphics/UserInterface/TextBox.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Diagnostics; @@ -465,7 +467,7 @@ namespace osu.Framework.Graphics.UserInterface { OnCommit = null; - unbindInput(); + unbindInput(false); base.Dispose(isDisposing); } @@ -935,7 +937,6 @@ namespace osu.Framework.Graphics.UserInterface // `FinalizeImeComposition()` crashes if textbox isn't fully loaded. if (IsLoaded) FinalizeImeComposition(false); - int startBefore = selectionStart; selectionStart = selectionEnd = 0; TextFlow?.Clear(); @@ -944,8 +945,6 @@ namespace osu.Framework.Graphics.UserInterface // insert string and fast forward any transforms (generally when replacing the full content of a textbox we don't want any kind of fade etc.). insertString(value, d => d.FinishTransforms()); - selectionStart = Math.Clamp(startBefore, 0, text.Length); - endTextChange(beganChange); cursorAndLayout.Invalidate(); } @@ -1190,7 +1189,7 @@ namespace osu.Framework.Graphics.UserInterface // let's say that a focus loss is not a user event as focus is commonly indirectly lost. FinalizeImeComposition(false); - unbindInput(); + unbindInput(e.NextFocused is TextBox); updateCaretVisibility(); @@ -1210,7 +1209,7 @@ namespace osu.Framework.Graphics.UserInterface protected override void OnFocus(FocusEvent e) { - bindInput(); + bindInput(e.PreviouslyFocused is TextBox); updateCaretVisibility(); } @@ -1224,7 +1223,7 @@ namespace osu.Framework.Graphics.UserInterface /// private bool textInputBound; - private void bindInput() + private void bindInput(bool previousFocusWasTextBox) { if (textInputBound) { @@ -1232,7 +1231,14 @@ namespace osu.Framework.Graphics.UserInterface return; } - textInput.Activate(AllowIme); + // TextBox has special handling of text input activation when focus is changed directly from one TextBox to another. + // We don't deactivate and activate, but instead keep text input active during the focus handoff, so that virtual keyboards on phones don't flicker. + + if (previousFocusWasTextBox) + textInput.EnsureActivated(AllowIme); + else + textInput.Activate(AllowIme); + textInput.OnTextInput += handleTextInput; textInput.OnImeComposition += handleImeComposition; textInput.OnImeResult += handleImeResult; @@ -1240,14 +1246,17 @@ namespace osu.Framework.Graphics.UserInterface textInputBound = true; } - private void unbindInput() + private void unbindInput(bool nextFocusIsTextBox) { if (!textInputBound) return; textInputBound = false; - textInput.Deactivate(); + // see the comment above, in `bindInput(bool)`. + if (!nextFocusIsTextBox) + textInput.Deactivate(); + textInput.OnTextInput -= handleTextInput; textInput.OnImeComposition -= handleImeComposition; textInput.OnImeResult -= handleImeResult; diff --git a/osu.Framework/Graphics/Vector2Extensions.cs b/osu.Framework/Graphics/Vector2Extensions.cs index e2eb63649..072f0d517 100644 --- a/osu.Framework/Graphics/Vector2Extensions.cs +++ b/osu.Framework/Graphics/Vector2Extensions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Runtime.CompilerServices; using osu.Framework.Graphics.Primitives; @@ -99,16 +101,14 @@ namespace osu.Framework.Graphics } /// - /// Determines whether a point is within the right half-plane of a line. + /// Determines whether a point is within the right half-plane of a line in the traditional cartesian coordinate system. /// /// The line. /// The point. - /// Whether is in the right half-plane of . - /// If the point is colinear to the line, it is said to be in the right half-plane of the line. - /// + /// Whether is in the right half-plane of . Collinear points are never in the right half-plane of the line. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool InRightHalfPlaneOf(this Vector2 point, in Line line) => (line.EndPoint.X - line.StartPoint.X) * (point.Y - line.StartPoint.Y) - - (line.EndPoint.Y - line.StartPoint.Y) * (point.X - line.StartPoint.X) <= 0; + - (line.EndPoint.Y - line.StartPoint.Y) * (point.X - line.StartPoint.X) < 0; } } diff --git a/osu.Framework/Graphics/Video/AVHWDeviceTypePerformanceComparer.cs b/osu.Framework/Graphics/Video/AVHWDeviceTypePerformanceComparer.cs index f2daffb1e..44e367752 100644 --- a/osu.Framework/Graphics/Video/AVHWDeviceTypePerformanceComparer.cs +++ b/osu.Framework/Graphics/Video/AVHWDeviceTypePerformanceComparer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using FFmpeg.AutoGen; diff --git a/osu.Framework/Graphics/Video/DecodedFrame.cs b/osu.Framework/Graphics/Video/DecodedFrame.cs index dd3c10d0a..8bb0c03de 100644 --- a/osu.Framework/Graphics/Video/DecodedFrame.cs +++ b/osu.Framework/Graphics/Video/DecodedFrame.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.Textures; namespace osu.Framework.Graphics.Video diff --git a/osu.Framework/Graphics/Video/FFmpegCodec.cs b/osu.Framework/Graphics/Video/FFmpegCodec.cs index ecff16493..67f0ab4d8 100644 --- a/osu.Framework/Graphics/Video/FFmpegCodec.cs +++ b/osu.Framework/Graphics/Video/FFmpegCodec.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Runtime.InteropServices; diff --git a/osu.Framework/Graphics/Video/FFmpegExtensions.cs b/osu.Framework/Graphics/Video/FFmpegExtensions.cs index be6142ca9..ef639affa 100644 --- a/osu.Framework/Graphics/Video/FFmpegExtensions.cs +++ b/osu.Framework/Graphics/Video/FFmpegExtensions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using FFmpeg.AutoGen; namespace osu.Framework.Graphics.Video diff --git a/osu.Framework/Graphics/Video/FFmpegFrame.cs b/osu.Framework/Graphics/Video/FFmpegFrame.cs index 4e2f11331..1daa9b7a2 100644 --- a/osu.Framework/Graphics/Video/FFmpegFrame.cs +++ b/osu.Framework/Graphics/Video/FFmpegFrame.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Diagnostics; using FFmpeg.AutoGen; diff --git a/osu.Framework/Graphics/Video/FFmpegFuncs.cs b/osu.Framework/Graphics/Video/FFmpegFuncs.cs index a346e83b6..6e2b18fc5 100644 --- a/osu.Framework/Graphics/Video/FFmpegFuncs.cs +++ b/osu.Framework/Graphics/Video/FFmpegFuncs.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Runtime.InteropServices; using FFmpeg.AutoGen; diff --git a/osu.Framework/Graphics/Video/HardwareVideoDecoder.cs b/osu.Framework/Graphics/Video/HardwareVideoDecoder.cs index d1b892f5c..df73677b1 100644 --- a/osu.Framework/Graphics/Video/HardwareVideoDecoder.cs +++ b/osu.Framework/Graphics/Video/HardwareVideoDecoder.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.ComponentModel; diff --git a/osu.Framework/Graphics/Video/StdIo.cs b/osu.Framework/Graphics/Video/StdIo.cs index 63a84b410..102e3395f 100644 --- a/osu.Framework/Graphics/Video/StdIo.cs +++ b/osu.Framework/Graphics/Video/StdIo.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Graphics.Video { internal static class StdIo diff --git a/osu.Framework/Graphics/Video/Video.cs b/osu.Framework/Graphics/Video/Video.cs index 8565c700b..1c371fa7d 100644 --- a/osu.Framework/Graphics/Video/Video.cs +++ b/osu.Framework/Graphics/Video/Video.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Allocation; using System; using System.Collections.Generic; diff --git a/osu.Framework/Graphics/Video/VideoDecoder.cs b/osu.Framework/Graphics/Video/VideoDecoder.cs index 9a380c1cf..a01179a4f 100644 --- a/osu.Framework/Graphics/Video/VideoDecoder.cs +++ b/osu.Framework/Graphics/Video/VideoDecoder.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using FFmpeg.AutoGen; using osuTK; using osu.Framework.Graphics.Textures; @@ -146,7 +148,7 @@ namespace osu.Framework.Graphics.Video availableTextures = new ConcurrentQueue(); // TODO: use "real" object pool when there's some public pool supporting disposables handle = new ObjectHandle(this, GCHandleType.Normal); - TargetHardwareVideoDecoders.BindValueChanged(e => + TargetHardwareVideoDecoders.BindValueChanged(_ => { // ignore if decoding wasn't initialized yet. if (formatContext == null) diff --git a/osu.Framework/Graphics/Video/VideoSprite.cs b/osu.Framework/Graphics/Video/VideoSprite.cs index 448d16709..0f02200fe 100644 --- a/osu.Framework/Graphics/Video/VideoSprite.cs +++ b/osu.Framework/Graphics/Video/VideoSprite.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Allocation; using osu.Framework.Graphics.Shaders; using osu.Framework.Graphics.Sprites; diff --git a/osu.Framework/Graphics/Video/VideoSpriteDrawNode.cs b/osu.Framework/Graphics/Video/VideoSpriteDrawNode.cs index 6651230fd..50e0d02e9 100644 --- a/osu.Framework/Graphics/Video/VideoSpriteDrawNode.cs +++ b/osu.Framework/Graphics/Video/VideoSpriteDrawNode.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osuTK; using osu.Framework.Graphics.Sprites; diff --git a/osu.Framework/Graphics/Video/VideoTexture.cs b/osu.Framework/Graphics/Video/VideoTexture.cs index d5f97060a..2b0de9327 100644 --- a/osu.Framework/Graphics/Video/VideoTexture.cs +++ b/osu.Framework/Graphics/Video/VideoTexture.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Diagnostics; using osuTK.Graphics.ES30; diff --git a/osu.Framework/Graphics/Video/VideoTextureUpload.cs b/osu.Framework/Graphics/Video/VideoTextureUpload.cs index ee6442cca..31f6168c7 100644 --- a/osu.Framework/Graphics/Video/VideoTextureUpload.cs +++ b/osu.Framework/Graphics/Video/VideoTextureUpload.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Graphics.Textures; using osuTK.Graphics.ES30; diff --git a/osu.Framework/Graphics/Visualisation/Audio/AudioChannelDisplay.cs b/osu.Framework/Graphics/Visualisation/Audio/AudioChannelDisplay.cs index 014e4dbd0..ea8c50cd5 100644 --- a/osu.Framework/Graphics/Visualisation/Audio/AudioChannelDisplay.cs +++ b/osu.Framework/Graphics/Visualisation/Audio/AudioChannelDisplay.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using ManagedBass; using ManagedBass.Mix; diff --git a/osu.Framework/Graphics/Visualisation/Audio/AudioMixerVisualiser.cs b/osu.Framework/Graphics/Visualisation/Audio/AudioMixerVisualiser.cs index 755453dab..5f0ace442 100644 --- a/osu.Framework/Graphics/Visualisation/Audio/AudioMixerVisualiser.cs +++ b/osu.Framework/Graphics/Visualisation/Audio/AudioMixerVisualiser.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Specialized; using System.Diagnostics; using System.Linq; diff --git a/osu.Framework/Graphics/Visualisation/Audio/MixerDisplay.cs b/osu.Framework/Graphics/Visualisation/Audio/MixerDisplay.cs index 0751bf15c..023be5dc8 100644 --- a/osu.Framework/Graphics/Visualisation/Audio/MixerDisplay.cs +++ b/osu.Framework/Graphics/Visualisation/Audio/MixerDisplay.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Linq; using ManagedBass.Mix; using osu.Framework.Audio.Mixing; diff --git a/osu.Framework/Graphics/Visualisation/DrawVisualiser.cs b/osu.Framework/Graphics/Visualisation/DrawVisualiser.cs index 566ba8b26..17e50aa87 100644 --- a/osu.Framework/Graphics/Visualisation/DrawVisualiser.cs +++ b/osu.Framework/Graphics/Visualisation/DrawVisualiser.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; @@ -35,6 +37,8 @@ namespace osu.Framework.Graphics.Visualisation private readonly InfoOverlay overlay; private InputManager inputManager; + protected override bool BlockPositionalInput => Searching; + public DrawVisualiser() { RelativeSizeAxes = Axes.Both; @@ -317,8 +321,6 @@ namespace osu.Framework.Graphics.Visualisation } } - protected override bool OnMouseDown(MouseDownEvent e) => Searching; - protected override bool OnClick(ClickEvent e) { if (Searching) diff --git a/osu.Framework/Graphics/Visualisation/DrawableInspector.cs b/osu.Framework/Graphics/Visualisation/DrawableInspector.cs index 881d497f9..cb6c0adff 100644 --- a/osu.Framework/Graphics/Visualisation/DrawableInspector.cs +++ b/osu.Framework/Graphics/Visualisation/DrawableInspector.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Linq; using osu.Framework.Allocation; diff --git a/osu.Framework/Graphics/Visualisation/DrawableTransform.cs b/osu.Framework/Graphics/Visualisation/DrawableTransform.cs index 5805ce041..e7b9fab34 100644 --- a/osu.Framework/Graphics/Visualisation/DrawableTransform.cs +++ b/osu.Framework/Graphics/Visualisation/DrawableTransform.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Sprites; diff --git a/osu.Framework/Graphics/Visualisation/FlashyBox.cs b/osu.Framework/Graphics/Visualisation/FlashyBox.cs index 31591be0e..45fbfd556 100644 --- a/osu.Framework/Graphics/Visualisation/FlashyBox.cs +++ b/osu.Framework/Graphics/Visualisation/FlashyBox.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Shapes; using System; diff --git a/osu.Framework/Graphics/Visualisation/IContainVisualisedDrawables.cs b/osu.Framework/Graphics/Visualisation/IContainVisualisedDrawables.cs index 5426cb9f0..72711e088 100644 --- a/osu.Framework/Graphics/Visualisation/IContainVisualisedDrawables.cs +++ b/osu.Framework/Graphics/Visualisation/IContainVisualisedDrawables.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Graphics.Visualisation { /// diff --git a/osu.Framework/Graphics/Visualisation/InfoOverlay.cs b/osu.Framework/Graphics/Visualisation/InfoOverlay.cs index cc1de75c6..c4cb03e4c 100644 --- a/osu.Framework/Graphics/Visualisation/InfoOverlay.cs +++ b/osu.Framework/Graphics/Visualisation/InfoOverlay.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osuTK; using osuTK.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework/Graphics/Visualisation/LogOverlay.cs b/osu.Framework/Graphics/Visualisation/LogOverlay.cs index d817e84ea..8e6ba979f 100644 --- a/osu.Framework/Graphics/Visualisation/LogOverlay.cs +++ b/osu.Framework/Graphics/Visualisation/LogOverlay.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Threading; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; diff --git a/osu.Framework/Graphics/Visualisation/PropertyDisplay.cs b/osu.Framework/Graphics/Visualisation/PropertyDisplay.cs index d74697bb6..6fc09b9b2 100644 --- a/osu.Framework/Graphics/Visualisation/PropertyDisplay.cs +++ b/osu.Framework/Graphics/Visualisation/PropertyDisplay.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/osu.Framework/Graphics/Visualisation/TextureVisualiser.cs b/osu.Framework/Graphics/Visualisation/TextureVisualiser.cs index 92a81111b..c37db2508 100644 --- a/osu.Framework/Graphics/Visualisation/TextureVisualiser.cs +++ b/osu.Framework/Graphics/Visualisation/TextureVisualiser.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Linq; using osu.Framework.Graphics.Colour; diff --git a/osu.Framework/Graphics/Visualisation/TitleBar.cs b/osu.Framework/Graphics/Visualisation/TitleBar.cs index edd81874e..0d000f26c 100644 --- a/osu.Framework/Graphics/Visualisation/TitleBar.cs +++ b/osu.Framework/Graphics/Visualisation/TitleBar.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Sprites; diff --git a/osu.Framework/Graphics/Visualisation/ToolWindow.cs b/osu.Framework/Graphics/Visualisation/ToolWindow.cs index 3f3e8ae37..5413ea0d9 100644 --- a/osu.Framework/Graphics/Visualisation/ToolWindow.cs +++ b/osu.Framework/Graphics/Visualisation/ToolWindow.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Cursor; @@ -20,17 +22,21 @@ namespace osu.Framework.Graphics.Visualisation protected readonly FillFlowContainer ToolbarContent; - protected readonly ScrollContainer ScrollContent; - protected readonly FillFlowContainer MainHorizontalContent; - protected ToolWindow(string title, string keyHelpText) + protected ScrollContainer ScrollContent; + + protected readonly SearchContainer SearchContainer; + + protected ToolWindow(string title, string keyHelpText, bool supportsSearch = false) { AutoSizeAxes = Axes.X; Height = HEIGHT; Masking = true; // for cursor masking + BasicTextBox queryTextBox; + AddRangeInternal(new Drawable[] { new Box @@ -98,12 +104,39 @@ namespace osu.Framework.Graphics.Visualisation RelativeSizeAxes = Axes.Y, AutoSizeAxes = Axes.X, Direction = FillDirection.Horizontal, - Children = new Drawable[] + Child = new GridContainer { - ScrollContent = new BasicScrollContainer + RelativeSizeAxes = Axes.Y, + Width = WIDTH, + RowDimensions = new[] { - RelativeSizeAxes = Axes.Y, - Width = WIDTH + new Dimension(GridSizeMode.AutoSize), + new Dimension(GridSizeMode.Distributed) + }, + Content = new[] + { + new Drawable[] + { + queryTextBox = new BasicTextBox + { + Width = WIDTH, + Height = 30, + PlaceholderText = "Search...", + Alpha = supportsSearch ? 1 : 0, + } + }, + new Drawable[] + { + ScrollContent = new BasicScrollContainer + { + RelativeSizeAxes = Axes.Both, + Child = SearchContainer = new SearchContainer + { + AutoSizeAxes = Axes.Y, + RelativeSizeAxes = Axes.X, + } + } + } } } } @@ -113,6 +146,8 @@ namespace osu.Framework.Graphics.Visualisation }, new CursorContainer() }); + + queryTextBox.Current.BindValueChanged(term => SearchContainer.SearchTerm = term.NewValue, true); } protected void AddButton(string text, Action action) diff --git a/osu.Framework/Graphics/Visualisation/TransformDisplay.cs b/osu.Framework/Graphics/Visualisation/TransformDisplay.cs index c0703e9a9..ad5f48b37 100644 --- a/osu.Framework/Graphics/Visualisation/TransformDisplay.cs +++ b/osu.Framework/Graphics/Visualisation/TransformDisplay.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework/Graphics/Visualisation/TreeContainer.cs b/osu.Framework/Graphics/Visualisation/TreeContainer.cs index c3725e33d..0ba3e1206 100644 --- a/osu.Framework/Graphics/Visualisation/TreeContainer.cs +++ b/osu.Framework/Graphics/Visualisation/TreeContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Allocation; using osu.Framework.Graphics.Sprites; @@ -26,14 +28,14 @@ namespace osu.Framework.Graphics.Visualisation set { if (value == null) - ScrollContent.Clear(false); + SearchContainer.Clear(false); else - ScrollContent.Child = value; + SearchContainer.Child = value; } } public TreeContainer() - : base("Draw Visualiser", "(Ctrl+F1 to toggle)") + : base("Draw Visualiser", "(Ctrl+F1 to toggle)", true) { AddInternal(waitingText = new SpriteText { diff --git a/osu.Framework/Graphics/Visualisation/TreeContainerStatus.cs b/osu.Framework/Graphics/Visualisation/TreeContainerStatus.cs index a946c04ca..519192cdd 100644 --- a/osu.Framework/Graphics/Visualisation/TreeContainerStatus.cs +++ b/osu.Framework/Graphics/Visualisation/TreeContainerStatus.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Graphics.Visualisation { internal enum TreeContainerStatus diff --git a/osu.Framework/Graphics/Visualisation/VisualisedDrawable.cs b/osu.Framework/Graphics/Visualisation/VisualisedDrawable.cs index 0948d98c0..8828a50d5 100644 --- a/osu.Framework/Graphics/Visualisation/VisualisedDrawable.cs +++ b/osu.Framework/Graphics/Visualisation/VisualisedDrawable.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; @@ -14,10 +16,11 @@ using osu.Framework.Allocation; using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Graphics.Textures; using osu.Framework.Input.Events; +using osu.Framework.Localisation; namespace osu.Framework.Graphics.Visualisation { - internal class VisualisedDrawable : Container, IContainVisualisedDrawables + internal class VisualisedDrawable : Container, IContainVisualisedDrawables, IHasFilterableChildren { private const int line_height = 12; @@ -38,6 +41,33 @@ namespace osu.Framework.Graphics.Visualisation } } + public IEnumerable FilterTerms => new LocalisableString[] + { + Target.ToString() + }; + + public IEnumerable FilterableChildren => flow.Children; + + public bool FilteringActive { get; set; } + + private bool matchingFilter = true; + + public bool MatchingFilter + { + get => matchingFilter; + set + { + bool wasPresent = IsPresent; + + matchingFilter = value; + + if (IsPresent != wasPresent) + Invalidate(Invalidation.Presence); + } + } + + public override bool IsPresent => base.IsPresent && MatchingFilter; + public Action RequestTarget; public Action HighlightTarget; diff --git a/osu.Framework/Host.cs b/osu.Framework/Host.cs index 949670cbb..c4cf1e4eb 100644 --- a/osu.Framework/Host.cs +++ b/osu.Framework/Host.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Platform; using osu.Framework.Platform.Linux; diff --git a/osu.Framework/HostOptions.cs b/osu.Framework/HostOptions.cs index b6913c4f6..b31824f0a 100644 --- a/osu.Framework/HostOptions.cs +++ b/osu.Framework/HostOptions.cs @@ -3,8 +3,6 @@ using osu.Framework.Platform; -#nullable enable - namespace osu.Framework { /// diff --git a/osu.Framework/IO/AsyncBufferStream.cs b/osu.Framework/IO/AsyncBufferStream.cs index d0da4f770..fe36d65cf 100644 --- a/osu.Framework/IO/AsyncBufferStream.cs +++ b/osu.Framework/IO/AsyncBufferStream.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Diagnostics; using System.IO; diff --git a/osu.Framework/IO/Network/FileWebRequest.cs b/osu.Framework/IO/Network/FileWebRequest.cs index 566413cb6..fbe00fcb1 100644 --- a/osu.Framework/IO/Network/FileWebRequest.cs +++ b/osu.Framework/IO/Network/FileWebRequest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.IO; using System.Threading.Tasks; diff --git a/osu.Framework/IO/Network/JsonWebRequest.cs b/osu.Framework/IO/Network/JsonWebRequest.cs index 1e1e8faa0..90bdb5009 100644 --- a/osu.Framework/IO/Network/JsonWebRequest.cs +++ b/osu.Framework/IO/Network/JsonWebRequest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using Newtonsoft.Json; namespace osu.Framework.IO.Network diff --git a/osu.Framework/IO/Network/RequestParameterType.cs b/osu.Framework/IO/Network/RequestParameterType.cs index 63eb76ecb..ab0ecae61 100644 --- a/osu.Framework/IO/Network/RequestParameterType.cs +++ b/osu.Framework/IO/Network/RequestParameterType.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.IO.Network { /// diff --git a/osu.Framework/IO/Network/UrlEncoding.cs b/osu.Framework/IO/Network/UrlEncoding.cs index a18c5d170..95582cf89 100644 --- a/osu.Framework/IO/Network/UrlEncoding.cs +++ b/osu.Framework/IO/Network/UrlEncoding.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Text; namespace osu.Framework.IO.Network diff --git a/osu.Framework/IO/Network/WebRequest.cs b/osu.Framework/IO/Network/WebRequest.cs index 325795c62..1f711ea9e 100644 --- a/osu.Framework/IO/Network/WebRequest.cs +++ b/osu.Framework/IO/Network/WebRequest.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + #if NET6_0_OR_GREATER using System.Net.Sockets; #endif @@ -246,7 +248,12 @@ namespace osu.Framework.IO.Network public async Task PerformAsync(CancellationToken cancellationToken = default) { if (Completed) + { + if (Aborted) + throw new OperationCanceledException($"The {nameof(WebRequest)} has been aborted."); + throw new InvalidOperationException($"The {nameof(WebRequest)} has already been run."); + } try { diff --git a/osu.Framework/IO/Serialization/BindableJsonConverter.cs b/osu.Framework/IO/Serialization/BindableJsonConverter.cs index e7a1d584f..efb539433 100644 --- a/osu.Framework/IO/Serialization/BindableJsonConverter.cs +++ b/osu.Framework/IO/Serialization/BindableJsonConverter.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Diagnostics; using Newtonsoft.Json; diff --git a/osu.Framework/IO/Serialization/ISerializableBindable.cs b/osu.Framework/IO/Serialization/ISerializableBindable.cs index 7805823c8..3686027a5 100644 --- a/osu.Framework/IO/Serialization/ISerializableBindable.cs +++ b/osu.Framework/IO/Serialization/ISerializableBindable.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using Newtonsoft.Json; using osu.Framework.Bindables; diff --git a/osu.Framework/IO/Serialization/ISerializableSortedList.cs b/osu.Framework/IO/Serialization/ISerializableSortedList.cs index abbb5bf81..40a56278b 100644 --- a/osu.Framework/IO/Serialization/ISerializableSortedList.cs +++ b/osu.Framework/IO/Serialization/ISerializableSortedList.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using Newtonsoft.Json; using osu.Framework.Lists; diff --git a/osu.Framework/IO/Serialization/SortedListJsonConverter.cs b/osu.Framework/IO/Serialization/SortedListJsonConverter.cs index d15bf6fde..7e4137e65 100644 --- a/osu.Framework/IO/Serialization/SortedListJsonConverter.cs +++ b/osu.Framework/IO/Serialization/SortedListJsonConverter.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Diagnostics; using Newtonsoft.Json; diff --git a/osu.Framework/IO/Serialization/Vector2Converter.cs b/osu.Framework/IO/Serialization/Vector2Converter.cs index 5d9be33a9..d6ebee313 100644 --- a/osu.Framework/IO/Serialization/Vector2Converter.cs +++ b/osu.Framework/IO/Serialization/Vector2Converter.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using Newtonsoft.Json; using Newtonsoft.Json.Linq; diff --git a/osu.Framework/IO/Stores/DllResourceStore.cs b/osu.Framework/IO/Stores/DllResourceStore.cs index 2b57dd5dc..75c3784ae 100644 --- a/osu.Framework/IO/Stores/DllResourceStore.cs +++ b/osu.Framework/IO/Stores/DllResourceStore.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.IO; diff --git a/osu.Framework/IO/Stores/FontStore.cs b/osu.Framework/IO/Stores/FontStore.cs index baeda61c5..60d4a7bdc 100644 --- a/osu.Framework/IO/Stores/FontStore.cs +++ b/osu.Framework/IO/Stores/FontStore.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.Textures; using System.Collections.Generic; using System.Threading.Tasks; @@ -9,8 +11,6 @@ using System.Collections.Concurrent; using JetBrains.Annotations; using osu.Framework.Platform; using osu.Framework.Text; -using osu.Framework.Extensions.IEnumerableExtensions; -using osu.Framework.Graphics.OpenGL.Textures; using osuTK.Graphics.ES30; namespace osu.Framework.IO.Stores @@ -57,30 +57,28 @@ namespace osu.Framework.IO.Stores this.cacheStorage = cacheStorage; } - protected override IEnumerable GetFilenames(string name) => - // extensions should not be used as they interfere with character lookup. - name.Yield(); - - public override void AddStore(IResourceStore store) + public override void AddTextureSource(IResourceStore store) { - switch (store) + if (store is IGlyphStore gs) { - case FontStore fs: - // if null, share the main store's atlas. - fs.Atlas ??= Atlas; - fs.cacheStorage ??= cacheStorage; + if (gs is RawCachingGlyphStore raw && raw.CacheStorage == null) + raw.CacheStorage = cacheStorage; - nestedFontStores.Add(fs); - return; + glyphStores.Add(gs); + queueLoad(gs); + } - case IGlyphStore gs: + base.AddTextureSource(store); + } - if (gs is RawCachingGlyphStore raw && raw.CacheStorage == null) - raw.CacheStorage = cacheStorage; - - glyphStores.Add(gs); - queueLoad(gs); - break; + public override void AddStore(ITextureStore store) + { + if (store is FontStore fs) + { + // if null, share the main store's atlas. + fs.Atlas ??= Atlas; + fs.cacheStorage ??= cacheStorage; + nestedFontStores.Add(fs); } base.AddStore(store); @@ -114,36 +112,20 @@ namespace osu.Framework.IO.Stores }); } - public override void RemoveStore(IResourceStore store) + public override void RemoveTextureStore(IResourceStore store) { - switch (store) - { - case FontStore fs: - nestedFontStores.Remove(fs); - return; + if (store is GlyphStore gs) + glyphStores.Remove(gs); - case GlyphStore gs: - glyphStores.Remove(gs); - break; - } - - base.RemoveStore(store); + base.RemoveTextureStore(store); } - public new Texture Get(string name) + public override void RemoveStore(ITextureStore store) { - var found = base.Get(name, WrapMode.None, WrapMode.None); + if (store is FontStore fs) + nestedFontStores.Remove(fs); - if (found == null) - { - foreach (var store in nestedFontStores) - { - if ((found = store.Get(name)) != null) - break; - } - } - - return found; + base.RemoveStore(store); } [CanBeNull] @@ -173,13 +155,5 @@ namespace osu.Framework.IO.Stores } public Task GetAsync(string fontName, char character) => Task.Run(() => Get(fontName, character)); - - protected override void Dispose(bool disposing) - { - base.Dispose(disposing); - - nestedFontStores.ForEach(f => f.Dispose()); - glyphStores.ForEach(g => g.Dispose()); - } } } diff --git a/osu.Framework/IO/Stores/GlyphStore.cs b/osu.Framework/IO/Stores/GlyphStore.cs index a3be41ca2..ce6b67467 100644 --- a/osu.Framework/IO/Stores/GlyphStore.cs +++ b/osu.Framework/IO/Stores/GlyphStore.cs @@ -1,7 +1,10 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -40,6 +43,13 @@ namespace osu.Framework.IO.Stores private readonly TaskCompletionSource completionSource = new TaskCompletionSource(); + /// + /// This is a rare usage of a static framework-wide cache. + /// In normal execution font instances are held locally by font stores and this will add no overhead or improvement. + /// It exists specifically to avoid overheads of parsing fonts repeatedly in unit tests. + /// + private static readonly ConcurrentDictionary font_cache = new ConcurrentDictionary(); + /// /// Create a new glyph store. /// @@ -66,8 +76,20 @@ namespace osu.Framework.IO.Stores try { BitmapFont font; + using (var s = Store.GetStream($@"{AssetName}")) - font = BitmapFont.FromStream(s, FormatHint.Binary, false); + { + string hash = s.ComputeMD5Hash(); + + if (font_cache.TryGetValue(hash, out font)) + { + Logger.Log($"Cached font load for {AssetName}"); + } + else + { + font_cache.TryAdd(hash, font = BitmapFont.FromStream(s, FormatHint.Binary, false)); + } + } completionSource.SetResult(font); } diff --git a/osu.Framework/IO/Stores/IGlyphStore.cs b/osu.Framework/IO/Stores/IGlyphStore.cs index 18d20cf20..797e7dc69 100644 --- a/osu.Framework/IO/Stores/IGlyphStore.cs +++ b/osu.Framework/IO/Stores/IGlyphStore.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Threading.Tasks; using osu.Framework.Text; diff --git a/osu.Framework/IO/Stores/IResourceStore.cs b/osu.Framework/IO/Stores/IResourceStore.cs index 36c0ac362..6160f4b0b 100644 --- a/osu.Framework/IO/Stores/IResourceStore.cs +++ b/osu.Framework/IO/Stores/IResourceStore.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/osu.Framework/IO/Stores/NamespacedResourceStore.cs b/osu.Framework/IO/Stores/NamespacedResourceStore.cs index fd46d3ba1..f01d8cbd1 100644 --- a/osu.Framework/IO/Stores/NamespacedResourceStore.cs +++ b/osu.Framework/IO/Stores/NamespacedResourceStore.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework/IO/Stores/OnlineStore.cs b/osu.Framework/IO/Stores/OnlineStore.cs index 5572bd707..b1421acef 100644 --- a/osu.Framework/IO/Stores/OnlineStore.cs +++ b/osu.Framework/IO/Stores/OnlineStore.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.IO; diff --git a/osu.Framework/IO/Stores/RawCachingGlyphStore.cs b/osu.Framework/IO/Stores/RawCachingGlyphStore.cs index a7fe93b4e..bbc56e6f3 100644 --- a/osu.Framework/IO/Stores/RawCachingGlyphStore.cs +++ b/osu.Framework/IO/Stores/RawCachingGlyphStore.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Buffers; using System.Collections.Generic; @@ -25,7 +27,10 @@ namespace osu.Framework.IO.Stores /// public class RawCachingGlyphStore : GlyphStore { - public Storage CacheStorage; + /// + /// A storage backing to be used for storing decompressed glyph sheets. + /// + internal Storage CacheStorage { get; set; } public RawCachingGlyphStore(ResourceStore store, string assetName = null, IResourceStore textureLoader = null) : base(store, assetName, textureLoader) @@ -53,21 +58,38 @@ namespace osu.Framework.IO.Stores using (var stream = Store.GetStream(filename)) { + // The md5 of the original (compressed png) content. string streamMd5 = stream.ComputeMD5Hash(); + + // The md5 of the access filename, including font name and page number. string filenameMd5 = filename.ComputeMD5Hash(); string accessFilename = $"{filenameMd5}#{streamMd5}"; + // Finding an existing file validates that the file both exists on disk, and was generated for the correct font. + // It doesn't guarantee that the generated cache file is in a good state. string existing = CacheStorage.GetFiles(string.Empty, $"{accessFilename}*").FirstOrDefault(); if (existing != null) { string[] split = existing.Split('#'); - return pageLookup[page] = new PageInfo + + int width = int.Parse(split[2]); + int height = int.Parse(split[3]); + + // Sanity check that the length of the file is expected, based on the width and height. + // If we ever see corrupt files in the wild, this should be changed to a full md5 check. Hopefully it will never happen. + using (var testStream = CacheStorage.GetStream(existing)) { - Size = new Size(int.Parse(split[2]), int.Parse(split[3])), - Filename = existing - }; + if (testStream.Length == width * height) + { + return pageLookup[page] = new PageInfo + { + Size = new Size(width, height), + Filename = existing + }; + } + } } using (var convert = GetPageImage(page)) @@ -85,7 +107,7 @@ namespace osu.Framework.IO.Stores accessFilename += $"#{convert.Width}#{convert.Height}"; - using (var outStream = CacheStorage.GetStream(accessFilename, FileAccess.Write, FileMode.Create)) + using (var outStream = CacheStorage.CreateFileSafely(accessFilename)) outStream.Write(buffer.Memory.Span); return pageLookup[page] = new PageInfo diff --git a/osu.Framework/IO/Stores/ResourceStore.cs b/osu.Framework/IO/Stores/ResourceStore.cs index 2e29c2272..c7d634657 100644 --- a/osu.Framework/IO/Stores/ResourceStore.cs +++ b/osu.Framework/IO/Stores/ResourceStore.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.IO; @@ -59,7 +61,7 @@ namespace osu.Framework.IO.Stores } /// - /// Adds a resource store to this store. + /// Adds a nested resource store to this store. /// /// The store to add. public virtual void AddStore(IResourceStore store) diff --git a/osu.Framework/IO/Stores/StorageBackedResourceStore.cs b/osu.Framework/IO/Stores/StorageBackedResourceStore.cs index 2847c03f3..19bbdb674 100644 --- a/osu.Framework/IO/Stores/StorageBackedResourceStore.cs +++ b/osu.Framework/IO/Stores/StorageBackedResourceStore.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using System.IO; using System.Linq; diff --git a/osu.Framework/IO/Stores/TimedExpiryGlyphStore.cs b/osu.Framework/IO/Stores/TimedExpiryGlyphStore.cs index 377042356..ba317b819 100644 --- a/osu.Framework/IO/Stores/TimedExpiryGlyphStore.cs +++ b/osu.Framework/IO/Stores/TimedExpiryGlyphStore.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. diff --git a/osu.Framework/IStateful.cs b/osu.Framework/IStateful.cs index c453a8dbf..231704b32 100644 --- a/osu.Framework/IStateful.cs +++ b/osu.Framework/IStateful.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; namespace osu.Framework diff --git a/osu.Framework/IUpdateable.cs b/osu.Framework/IUpdateable.cs index 37fa1fc29..4afa4a319 100644 --- a/osu.Framework/IUpdateable.cs +++ b/osu.Framework/IUpdateable.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework { public interface IUpdateable diff --git a/osu.Framework/Input/Bindings/IKeyBinding.cs b/osu.Framework/Input/Bindings/IKeyBinding.cs index 0ae856ba2..a140a461f 100644 --- a/osu.Framework/Input/Bindings/IKeyBinding.cs +++ b/osu.Framework/Input/Bindings/IKeyBinding.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Input.Bindings { /// diff --git a/osu.Framework/Input/Bindings/IKeyBindingHandler.cs b/osu.Framework/Input/Bindings/IKeyBindingHandler.cs index f8167b016..8db87d2fa 100644 --- a/osu.Framework/Input/Bindings/IKeyBindingHandler.cs +++ b/osu.Framework/Input/Bindings/IKeyBindingHandler.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics; using osu.Framework.Input.Events; diff --git a/osu.Framework/Input/Bindings/IScrollBindingHandler.cs b/osu.Framework/Input/Bindings/IScrollBindingHandler.cs index c3a12efdf..2d9aca200 100644 --- a/osu.Framework/Input/Bindings/IScrollBindingHandler.cs +++ b/osu.Framework/Input/Bindings/IScrollBindingHandler.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.Events; namespace osu.Framework.Input.Bindings diff --git a/osu.Framework/Input/Bindings/InputKey.cs b/osu.Framework/Input/Bindings/InputKey.cs index cada41e7e..e6e71447f 100644 --- a/osu.Framework/Input/Bindings/InputKey.cs +++ b/osu.Framework/Input/Bindings/InputKey.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Utils; namespace osu.Framework.Input.Bindings diff --git a/osu.Framework/Input/Bindings/KeyBinding.cs b/osu.Framework/Input/Bindings/KeyBinding.cs index 156321d08..288524039 100644 --- a/osu.Framework/Input/Bindings/KeyBinding.cs +++ b/osu.Framework/Input/Bindings/KeyBinding.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Input.Bindings { public class KeyBinding : IKeyBinding diff --git a/osu.Framework/Input/Bindings/KeyBindingContainer.cs b/osu.Framework/Input/Bindings/KeyBindingContainer.cs index 015c76db6..c4cdf6dd8 100644 --- a/osu.Framework/Input/Bindings/KeyBindingContainer.cs +++ b/osu.Framework/Input/Bindings/KeyBindingContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework/Input/Bindings/KeyBindingExtensions.cs b/osu.Framework/Input/Bindings/KeyBindingExtensions.cs index 2c5db9fc0..18a3b056f 100644 --- a/osu.Framework/Input/Bindings/KeyBindingExtensions.cs +++ b/osu.Framework/Input/Bindings/KeyBindingExtensions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Input.Bindings { public static class KeyBindingExtensions diff --git a/osu.Framework/Input/Bindings/KeyCombination.cs b/osu.Framework/Input/Bindings/KeyCombination.cs index f38454517..9d369ba59 100644 --- a/osu.Framework/Input/Bindings/KeyCombination.cs +++ b/osu.Framework/Input/Bindings/KeyCombination.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Collections.Immutable; @@ -623,10 +625,10 @@ namespace osu.Framework.Input.Bindings yield return InputKey.MouseWheelDown; if (scrollDelta.X > 0) - yield return InputKey.MouseWheelRight; + yield return InputKey.MouseWheelLeft; if (scrollDelta.X < 0) - yield return InputKey.MouseWheelLeft; + yield return InputKey.MouseWheelRight; } public static InputKey FromMidiKey(MidiKey key) => (InputKey)((int)InputKey.MidiA0 + key - MidiKey.A0); diff --git a/osu.Framework/Input/ButtonEventManager.cs b/osu.Framework/Input/ButtonEventManager.cs index 7d6a2bfa2..0627dcdb8 100644 --- a/osu.Framework/Input/ButtonEventManager.cs +++ b/osu.Framework/Input/ButtonEventManager.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework/Input/ConfineMouseMode.cs b/osu.Framework/Input/ConfineMouseMode.cs index 95e32e2ed..b73d7795c 100644 --- a/osu.Framework/Input/ConfineMouseMode.cs +++ b/osu.Framework/Input/ConfineMouseMode.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Input { public enum ConfineMouseMode diff --git a/osu.Framework/Input/CustomInputManager.cs b/osu.Framework/Input/CustomInputManager.cs index 39f457a9a..7a0212401 100644 --- a/osu.Framework/Input/CustomInputManager.cs +++ b/osu.Framework/Input/CustomInputManager.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Immutable; using System.Linq; using osu.Framework.Input.Handlers; diff --git a/osu.Framework/Input/Events/ClickEvent.cs b/osu.Framework/Input/Events/ClickEvent.cs index 60e76d156..5904d3e6d 100644 --- a/osu.Framework/Input/Events/ClickEvent.cs +++ b/osu.Framework/Input/Events/ClickEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.States; using osuTK; using osuTK.Input; diff --git a/osu.Framework/Input/Events/DoubleClickEvent.cs b/osu.Framework/Input/Events/DoubleClickEvent.cs index 17ce9a8fa..1640776d6 100644 --- a/osu.Framework/Input/Events/DoubleClickEvent.cs +++ b/osu.Framework/Input/Events/DoubleClickEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.States; using osuTK; using osuTK.Input; diff --git a/osu.Framework/Input/Events/DragEndEvent.cs b/osu.Framework/Input/Events/DragEndEvent.cs index 9ea803d7d..d2f4a7c91 100644 --- a/osu.Framework/Input/Events/DragEndEvent.cs +++ b/osu.Framework/Input/Events/DragEndEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.States; using osuTK; using osuTK.Input; diff --git a/osu.Framework/Input/Events/DragEvent.cs b/osu.Framework/Input/Events/DragEvent.cs index 1b451a382..e0809a0e3 100644 --- a/osu.Framework/Input/Events/DragEvent.cs +++ b/osu.Framework/Input/Events/DragEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.States; using osuTK; using osuTK.Input; diff --git a/osu.Framework/Input/Events/DragStartEvent.cs b/osu.Framework/Input/Events/DragStartEvent.cs index 8362acd30..ba6eb1e17 100644 --- a/osu.Framework/Input/Events/DragStartEvent.cs +++ b/osu.Framework/Input/Events/DragStartEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.States; using osuTK; using osuTK.Input; diff --git a/osu.Framework/Input/Events/FocusEvent.cs b/osu.Framework/Input/Events/FocusEvent.cs index 0042678e7..4f80ebfd2 100644 --- a/osu.Framework/Input/Events/FocusEvent.cs +++ b/osu.Framework/Input/Events/FocusEvent.cs @@ -1,18 +1,29 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + +using JetBrains.Annotations; +using osu.Framework.Graphics; using osu.Framework.Input.States; namespace osu.Framework.Input.Events { /// - /// An event represeting that a drawable gained the focus. + /// An event representing that a drawable gained the focus. /// public class FocusEvent : UIEvent { - public FocusEvent(InputState state) + /// + /// The that has lost focus, or null if nothing was previously focused. + /// + [CanBeNull] + public readonly Drawable PreviouslyFocused; + + public FocusEvent(InputState state, Drawable previouslyFocused) : base(state) { + PreviouslyFocused = previouslyFocused; } } } diff --git a/osu.Framework/Input/Events/FocusLostEvent.cs b/osu.Framework/Input/Events/FocusLostEvent.cs index b4ffe8f4e..70b15ae35 100644 --- a/osu.Framework/Input/Events/FocusLostEvent.cs +++ b/osu.Framework/Input/Events/FocusLostEvent.cs @@ -1,18 +1,29 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + +using JetBrains.Annotations; +using osu.Framework.Graphics; using osu.Framework.Input.States; namespace osu.Framework.Input.Events { /// - /// An event represeting that a drawable lost the focus. + /// An event representing that a drawable lost the focus. /// public class FocusLostEvent : UIEvent { - public FocusLostEvent(InputState state) + /// + /// The that will gain focus, or null if nothing will gain focus. + /// + [CanBeNull] + public readonly Drawable NextFocused; + + public FocusLostEvent(InputState state, Drawable nextFocused) : base(state) { + NextFocused = nextFocused; } } } diff --git a/osu.Framework/Input/Events/HoverEvent.cs b/osu.Framework/Input/Events/HoverEvent.cs index df5e7f5f3..f904ecfa2 100644 --- a/osu.Framework/Input/Events/HoverEvent.cs +++ b/osu.Framework/Input/Events/HoverEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.States; namespace osu.Framework.Input.Events diff --git a/osu.Framework/Input/Events/HoverLostEvent.cs b/osu.Framework/Input/Events/HoverLostEvent.cs index 8be4aed28..f33671891 100644 --- a/osu.Framework/Input/Events/HoverLostEvent.cs +++ b/osu.Framework/Input/Events/HoverLostEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.States; namespace osu.Framework.Input.Events diff --git a/osu.Framework/Input/Events/JoystickAxisMoveEvent.cs b/osu.Framework/Input/Events/JoystickAxisMoveEvent.cs index d0139744d..91c018e31 100644 --- a/osu.Framework/Input/Events/JoystickAxisMoveEvent.cs +++ b/osu.Framework/Input/Events/JoystickAxisMoveEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using JetBrains.Annotations; using osu.Framework.Extensions.TypeExtensions; using osu.Framework.Input.States; diff --git a/osu.Framework/Input/Events/JoystickButtonEvent.cs b/osu.Framework/Input/Events/JoystickButtonEvent.cs index 8218909c6..bb703d46d 100644 --- a/osu.Framework/Input/Events/JoystickButtonEvent.cs +++ b/osu.Framework/Input/Events/JoystickButtonEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Extensions.TypeExtensions; using osu.Framework.Input.States; diff --git a/osu.Framework/Input/Events/JoystickEvent.cs b/osu.Framework/Input/Events/JoystickEvent.cs index 64f713a12..db6d7c108 100644 --- a/osu.Framework/Input/Events/JoystickEvent.cs +++ b/osu.Framework/Input/Events/JoystickEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using System.Linq; using JetBrains.Annotations; diff --git a/osu.Framework/Input/Events/JoystickPressEvent.cs b/osu.Framework/Input/Events/JoystickPressEvent.cs index 927dc120c..97e7806d5 100644 --- a/osu.Framework/Input/Events/JoystickPressEvent.cs +++ b/osu.Framework/Input/Events/JoystickPressEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.States; namespace osu.Framework.Input.Events diff --git a/osu.Framework/Input/Events/JoystickReleaseEvent.cs b/osu.Framework/Input/Events/JoystickReleaseEvent.cs index 8e857624e..1b1abdf16 100644 --- a/osu.Framework/Input/Events/JoystickReleaseEvent.cs +++ b/osu.Framework/Input/Events/JoystickReleaseEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.States; namespace osu.Framework.Input.Events diff --git a/osu.Framework/Input/Events/KeyBindingEvent.cs b/osu.Framework/Input/Events/KeyBindingEvent.cs index 1ecb8ec27..9070d6777 100644 --- a/osu.Framework/Input/Events/KeyBindingEvent.cs +++ b/osu.Framework/Input/Events/KeyBindingEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.States; namespace osu.Framework.Input.Events diff --git a/osu.Framework/Input/Events/KeyBindingPressEvent.cs b/osu.Framework/Input/Events/KeyBindingPressEvent.cs index 942f024cc..6f8ac1d29 100644 --- a/osu.Framework/Input/Events/KeyBindingPressEvent.cs +++ b/osu.Framework/Input/Events/KeyBindingPressEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.States; namespace osu.Framework.Input.Events diff --git a/osu.Framework/Input/Events/KeyBindingReleaseEvent.cs b/osu.Framework/Input/Events/KeyBindingReleaseEvent.cs index 7424860c0..f2d7ed95b 100644 --- a/osu.Framework/Input/Events/KeyBindingReleaseEvent.cs +++ b/osu.Framework/Input/Events/KeyBindingReleaseEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.States; namespace osu.Framework.Input.Events diff --git a/osu.Framework/Input/Events/KeyBindingScrollEvent.cs b/osu.Framework/Input/Events/KeyBindingScrollEvent.cs index dcd64442b..b7e3288a4 100644 --- a/osu.Framework/Input/Events/KeyBindingScrollEvent.cs +++ b/osu.Framework/Input/Events/KeyBindingScrollEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.States; namespace osu.Framework.Input.Events diff --git a/osu.Framework/Input/Events/KeyDownEvent.cs b/osu.Framework/Input/Events/KeyDownEvent.cs index 8071e75a8..d00ad2325 100644 --- a/osu.Framework/Input/Events/KeyDownEvent.cs +++ b/osu.Framework/Input/Events/KeyDownEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Extensions.TypeExtensions; using osu.Framework.Input.States; using osuTK.Input; diff --git a/osu.Framework/Input/Events/KeyUpEvent.cs b/osu.Framework/Input/Events/KeyUpEvent.cs index cf0b6402b..eef98649d 100644 --- a/osu.Framework/Input/Events/KeyUpEvent.cs +++ b/osu.Framework/Input/Events/KeyUpEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.States; using osuTK.Input; diff --git a/osu.Framework/Input/Events/KeyboardEvent.cs b/osu.Framework/Input/Events/KeyboardEvent.cs index a3cfdb5c3..995e759ef 100644 --- a/osu.Framework/Input/Events/KeyboardEvent.cs +++ b/osu.Framework/Input/Events/KeyboardEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using osu.Framework.Extensions.TypeExtensions; using osu.Framework.Input.States; diff --git a/osu.Framework/Input/Events/MidiDownEvent.cs b/osu.Framework/Input/Events/MidiDownEvent.cs index ca909522b..dab24495e 100644 --- a/osu.Framework/Input/Events/MidiDownEvent.cs +++ b/osu.Framework/Input/Events/MidiDownEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using JetBrains.Annotations; using osu.Framework.Input.States; diff --git a/osu.Framework/Input/Events/MidiEvent.cs b/osu.Framework/Input/Events/MidiEvent.cs index be1d7ca0c..f94825ecc 100644 --- a/osu.Framework/Input/Events/MidiEvent.cs +++ b/osu.Framework/Input/Events/MidiEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using JetBrains.Annotations; using osu.Framework.Extensions.TypeExtensions; diff --git a/osu.Framework/Input/Events/MidiUpEvent.cs b/osu.Framework/Input/Events/MidiUpEvent.cs index eceeac34a..8b36d2365 100644 --- a/osu.Framework/Input/Events/MidiUpEvent.cs +++ b/osu.Framework/Input/Events/MidiUpEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using JetBrains.Annotations; using osu.Framework.Input.States; diff --git a/osu.Framework/Input/Events/MouseButtonEvent.cs b/osu.Framework/Input/Events/MouseButtonEvent.cs index 201bacd1d..d4b6181a7 100644 --- a/osu.Framework/Input/Events/MouseButtonEvent.cs +++ b/osu.Framework/Input/Events/MouseButtonEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Extensions.TypeExtensions; using osu.Framework.Input.States; using osuTK; diff --git a/osu.Framework/Input/Events/MouseDownEvent.cs b/osu.Framework/Input/Events/MouseDownEvent.cs index 01b4f340a..506a33019 100644 --- a/osu.Framework/Input/Events/MouseDownEvent.cs +++ b/osu.Framework/Input/Events/MouseDownEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.States; using osuTK; using osuTK.Input; diff --git a/osu.Framework/Input/Events/MouseEvent.cs b/osu.Framework/Input/Events/MouseEvent.cs index a209005b0..f2878b5ec 100644 --- a/osu.Framework/Input/Events/MouseEvent.cs +++ b/osu.Framework/Input/Events/MouseEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using osu.Framework.Input.States; using osuTK.Input; diff --git a/osu.Framework/Input/Events/MouseMoveEvent.cs b/osu.Framework/Input/Events/MouseMoveEvent.cs index bab7e9934..85c718d99 100644 --- a/osu.Framework/Input/Events/MouseMoveEvent.cs +++ b/osu.Framework/Input/Events/MouseMoveEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.States; using osuTK; diff --git a/osu.Framework/Input/Events/MouseUpEvent.cs b/osu.Framework/Input/Events/MouseUpEvent.cs index f0e9acea7..7d169eaa5 100644 --- a/osu.Framework/Input/Events/MouseUpEvent.cs +++ b/osu.Framework/Input/Events/MouseUpEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.States; using osuTK; using osuTK.Input; diff --git a/osu.Framework/Input/Events/ScrollEvent.cs b/osu.Framework/Input/Events/ScrollEvent.cs index b3250f4e3..b4f4c2d04 100644 --- a/osu.Framework/Input/Events/ScrollEvent.cs +++ b/osu.Framework/Input/Events/ScrollEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Extensions.TypeExtensions; using osu.Framework.Input.States; using osuTK; @@ -15,6 +17,9 @@ namespace osu.Framework.Input.Events /// /// The relative change in scroll associated with this event. /// + /// + /// Delta is positive when mouse wheel scrolled to the up or left, in non-"natural" scroll mode (ie. the classic way). + /// public readonly Vector2 ScrollDelta; /// diff --git a/osu.Framework/Input/Events/TabletAuxiliaryButtonEvent.cs b/osu.Framework/Input/Events/TabletAuxiliaryButtonEvent.cs index b21261fe0..d181416d1 100644 --- a/osu.Framework/Input/Events/TabletAuxiliaryButtonEvent.cs +++ b/osu.Framework/Input/Events/TabletAuxiliaryButtonEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Extensions.TypeExtensions; using osu.Framework.Input.States; diff --git a/osu.Framework/Input/Events/TabletAuxiliaryButtonPressEvent.cs b/osu.Framework/Input/Events/TabletAuxiliaryButtonPressEvent.cs index 9f3e3fdd0..46d5c290d 100644 --- a/osu.Framework/Input/Events/TabletAuxiliaryButtonPressEvent.cs +++ b/osu.Framework/Input/Events/TabletAuxiliaryButtonPressEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.States; namespace osu.Framework.Input.Events diff --git a/osu.Framework/Input/Events/TabletAuxiliaryButtonReleaseEvent.cs b/osu.Framework/Input/Events/TabletAuxiliaryButtonReleaseEvent.cs index 7fa2f1725..e85e64deb 100644 --- a/osu.Framework/Input/Events/TabletAuxiliaryButtonReleaseEvent.cs +++ b/osu.Framework/Input/Events/TabletAuxiliaryButtonReleaseEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.States; namespace osu.Framework.Input.Events diff --git a/osu.Framework/Input/Events/TabletEvent.cs b/osu.Framework/Input/Events/TabletEvent.cs index 7607b344f..fe7e485b3 100644 --- a/osu.Framework/Input/Events/TabletEvent.cs +++ b/osu.Framework/Input/Events/TabletEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using JetBrains.Annotations; using osu.Framework.Input.States; diff --git a/osu.Framework/Input/Events/TabletPenButtonEvent.cs b/osu.Framework/Input/Events/TabletPenButtonEvent.cs index 2dfd096cc..06fdfb887 100644 --- a/osu.Framework/Input/Events/TabletPenButtonEvent.cs +++ b/osu.Framework/Input/Events/TabletPenButtonEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Extensions.TypeExtensions; using osu.Framework.Input.States; diff --git a/osu.Framework/Input/Events/TabletPenButtonPressEvent.cs b/osu.Framework/Input/Events/TabletPenButtonPressEvent.cs index ea5723c13..97d5532b9 100644 --- a/osu.Framework/Input/Events/TabletPenButtonPressEvent.cs +++ b/osu.Framework/Input/Events/TabletPenButtonPressEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.States; namespace osu.Framework.Input.Events diff --git a/osu.Framework/Input/Events/TabletPenButtonReleaseEvent.cs b/osu.Framework/Input/Events/TabletPenButtonReleaseEvent.cs index da946b480..0ce5c47a3 100644 --- a/osu.Framework/Input/Events/TabletPenButtonReleaseEvent.cs +++ b/osu.Framework/Input/Events/TabletPenButtonReleaseEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.States; namespace osu.Framework.Input.Events diff --git a/osu.Framework/Input/Events/TouchDownEvent.cs b/osu.Framework/Input/Events/TouchDownEvent.cs index 598c0d64a..5cb8ba4d1 100644 --- a/osu.Framework/Input/Events/TouchDownEvent.cs +++ b/osu.Framework/Input/Events/TouchDownEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.States; namespace osu.Framework.Input.Events diff --git a/osu.Framework/Input/Events/TouchEvent.cs b/osu.Framework/Input/Events/TouchEvent.cs index 524846f81..787c22120 100644 --- a/osu.Framework/Input/Events/TouchEvent.cs +++ b/osu.Framework/Input/Events/TouchEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Extensions.TypeExtensions; using osu.Framework.Input.States; using osuTK; diff --git a/osu.Framework/Input/Events/TouchMoveEvent.cs b/osu.Framework/Input/Events/TouchMoveEvent.cs index 552df4bf5..1d030d515 100644 --- a/osu.Framework/Input/Events/TouchMoveEvent.cs +++ b/osu.Framework/Input/Events/TouchMoveEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.States; using osuTK; diff --git a/osu.Framework/Input/Events/TouchUpEvent.cs b/osu.Framework/Input/Events/TouchUpEvent.cs index f80c0a9ee..344917283 100644 --- a/osu.Framework/Input/Events/TouchUpEvent.cs +++ b/osu.Framework/Input/Events/TouchUpEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.States; using osuTK; diff --git a/osu.Framework/Input/Events/UIEvent.cs b/osu.Framework/Input/Events/UIEvent.cs index 3a1754013..03a14a406 100644 --- a/osu.Framework/Input/Events/UIEvent.cs +++ b/osu.Framework/Input/Events/UIEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using JetBrains.Annotations; using osu.Framework.Extensions.TypeExtensions; diff --git a/osu.Framework/Input/FrameworkActionContainer.cs b/osu.Framework/Input/FrameworkActionContainer.cs index 17fdca0b2..111f274d8 100644 --- a/osu.Framework/Input/FrameworkActionContainer.cs +++ b/osu.Framework/Input/FrameworkActionContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using osu.Framework.Input.Bindings; diff --git a/osu.Framework/Input/Handlers/IHasCursorSensitivity.cs b/osu.Framework/Input/Handlers/IHasCursorSensitivity.cs index 23c22cefc..4a36dcc77 100644 --- a/osu.Framework/Input/Handlers/IHasCursorSensitivity.cs +++ b/osu.Framework/Input/Handlers/IHasCursorSensitivity.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Bindables; namespace osu.Framework.Input.Handlers diff --git a/osu.Framework/Input/Handlers/INeedsMousePositionFeedback.cs b/osu.Framework/Input/Handlers/INeedsMousePositionFeedback.cs index d98eaf1be..99be6571c 100644 --- a/osu.Framework/Input/Handlers/INeedsMousePositionFeedback.cs +++ b/osu.Framework/Input/Handlers/INeedsMousePositionFeedback.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osuTK; namespace osu.Framework.Input.Handlers diff --git a/osu.Framework/Input/Handlers/InputHandler.cs b/osu.Framework/Input/Handlers/InputHandler.cs index 09f4a14e3..8da4c84b3 100644 --- a/osu.Framework/Input/Handlers/InputHandler.cs +++ b/osu.Framework/Input/Handlers/InputHandler.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Concurrent; using System.Collections.Generic; diff --git a/osu.Framework/Input/Handlers/Joystick/JoystickHandler.cs b/osu.Framework/Input/Handlers/Joystick/JoystickHandler.cs index fa9449661..ae5a7cc76 100644 --- a/osu.Framework/Input/Handlers/Joystick/JoystickHandler.cs +++ b/osu.Framework/Input/Handlers/Joystick/JoystickHandler.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Bindables; using osu.Framework.Input.StateChanges; @@ -18,8 +20,6 @@ namespace osu.Framework.Input.Handlers.Joystick Precision = 0.005f, }; - private readonly JoystickButton[] axisDirectionButtons = new JoystickButton[(int)JoystickAxisSource.AxisCount]; - public override string Description => "Joystick / Gamepad"; public override bool IsActive => true; @@ -63,32 +63,9 @@ namespace osu.Framework.Input.Handlers.Joystick /// /// Enqueues a taking into account the axis deadzone. - /// Also enqueues events depending on whether the axis has changed direction. /// - private void enqueueJoystickAxisChanged(JoystickAxis axis) - { - float value = rescaleByDeadzone(axis.Value); - - int index = (int)axis.Source; - var currentButton = axisDirectionButtons[index]; - var expectedButton = getAxisButtonForInput(index, value); - - // if a directional button is pressed and does not match that for the new axis direction, release it - if (currentButton != 0 && expectedButton != currentButton) - { - enqueueJoystickButtonUp(currentButton); - axisDirectionButtons[index] = currentButton = 0; - } - - // if we expect a directional button to be pressed, and it is not, press it - if (expectedButton != 0 && expectedButton != currentButton) - { - enqueueJoystickButtonDown(expectedButton); - axisDirectionButtons[index] = expectedButton; - } - - enqueueJoystickEvent(new JoystickAxisInput(new JoystickAxis(axis.Source, value))); - } + private void enqueueJoystickAxisChanged(JoystickAxisSource source, float value) => + enqueueJoystickEvent(new JoystickAxisInput(new JoystickAxis(source, rescaleByDeadzone(value)))); private float rescaleByDeadzone(float axisValue) { @@ -101,16 +78,5 @@ namespace osu.Framework.Input.Handlers.Joystick float absoluteRescaled = (absoluteValue - DeadzoneThreshold.Value) / (1f - DeadzoneThreshold.Value); return Math.Sign(axisValue) * absoluteRescaled; } - - private static JoystickButton getAxisButtonForInput(int axisIndex, float axisValue) - { - if (axisValue > 0) - return JoystickButton.FirstAxisPositive + axisIndex; - - if (axisValue < 0) - return JoystickButton.FirstAxisNegative + axisIndex; - - return 0; - } } } diff --git a/osu.Framework/Input/Handlers/Keyboard/KeyboardHandler.cs b/osu.Framework/Input/Handlers/Keyboard/KeyboardHandler.cs index bc74853f8..6c0d204fc 100644 --- a/osu.Framework/Input/Handlers/Keyboard/KeyboardHandler.cs +++ b/osu.Framework/Input/Handlers/Keyboard/KeyboardHandler.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.StateChanges; using osu.Framework.Platform; using osu.Framework.Statistics; diff --git a/osu.Framework/Input/Handlers/Midi/MidiHandler.cs b/osu.Framework/Input/Handlers/Midi/MidiHandler.cs index 52c62d095..3b9bb5294 100644 --- a/osu.Framework/Input/Handlers/Midi/MidiHandler.cs +++ b/osu.Framework/Input/Handlers/Midi/MidiHandler.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Diagnostics; @@ -20,8 +22,9 @@ namespace osu.Framework.Input.Handlers.Midi public class MidiHandler : InputHandler { public override string Description => "MIDI"; - public override bool IsActive => active; - private bool active = true; + public override bool IsActive => inGoodState; + + private bool inGoodState = true; private ScheduledDelegate scheduledRefreshDevices; @@ -42,6 +45,7 @@ namespace osu.Framework.Input.Handlers.Midi { if (e.NewValue) { + inGoodState = true; host.InputThread.Scheduler.Add(scheduledRefreshDevices = new ScheduledDelegate(() => refreshDevices(), 0, 500)); } else @@ -101,11 +105,15 @@ namespace osu.Framework.Input.Handlers.Midi } catch (Exception e) { - Logger.Error(e, RuntimeInfo.OS == RuntimeInfo.Platform.Linux - ? "Couldn't list input devices. Is libasound2-dev installed?" - : "Couldn't list input devices. There may be another application already using MIDI."); + string message = RuntimeInfo.OS == RuntimeInfo.Platform.Linux + ? "Is libasound2-dev installed?" + : "There may be another application already using MIDI."; - active = false; + Logger.Log($"MIDI devices could not be enumerated. {message} ({e.Message})"); + + // stop attempting to refresh devices until next startup. + inGoodState = false; + scheduledRefreshDevices?.Cancel(); return false; } } @@ -208,8 +216,6 @@ namespace osu.Framework.Input.Handlers.Midi private void dispatchEvent(byte eventType, byte key, byte velocity) { - Logger.Log($"Handling MIDI event {eventType:X2}:{key:X2}:{velocity:X2}"); - // Low nibble only contains channel data in note on/off messages // Ignore to receive messages from all channels switch (eventType & 0xF0) @@ -226,17 +232,15 @@ namespace osu.Framework.Input.Handlers.Midi break; } - void noteOff() + void noteOn() { - Logger.Log($"NoteOff: {(MidiKey)key}/{velocity / 128f:P}"); - PendingInputs.Enqueue(new MidiKeyInput((MidiKey)key, 0, false)); + PendingInputs.Enqueue(new MidiKeyInput((MidiKey)key, velocity, true)); FrameStatistics.Increment(StatisticsCounterType.MidiEvents); } - void noteOn() + void noteOff() { - Logger.Log($"NoteOn: {(MidiKey)key}/{velocity / 128f:P}"); - PendingInputs.Enqueue(new MidiKeyInput((MidiKey)key, velocity, true)); + PendingInputs.Enqueue(new MidiKeyInput((MidiKey)key, 0, false)); FrameStatistics.Increment(StatisticsCounterType.MidiEvents); } } diff --git a/osu.Framework/Input/Handlers/Mouse/MouseHandler.cs b/osu.Framework/Input/Handlers/Mouse/MouseHandler.cs index 5700f3c30..cf0803080 100644 --- a/osu.Framework/Input/Handlers/Mouse/MouseHandler.cs +++ b/osu.Framework/Input/Handlers/Mouse/MouseHandler.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Diagnostics; using osu.Framework.Bindables; using osu.Framework.Extensions.EnumExtensions; diff --git a/osu.Framework/Input/Handlers/Tablet/AbsoluteTabletMode.cs b/osu.Framework/Input/Handlers/Tablet/AbsoluteTabletMode.cs index 606a4460a..1b9db72c7 100644 --- a/osu.Framework/Input/Handlers/Tablet/AbsoluteTabletMode.cs +++ b/osu.Framework/Input/Handlers/Tablet/AbsoluteTabletMode.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + #if NET6_0_OR_GREATER using OpenTabletDriver.Plugin.Output; using OpenTabletDriver.Plugin.Platform.Pointer; diff --git a/osu.Framework/Input/Handlers/Tablet/ITabletHandler.cs b/osu.Framework/Input/Handlers/Tablet/ITabletHandler.cs index 7be1fcdd1..3aaee1b3e 100644 --- a/osu.Framework/Input/Handlers/Tablet/ITabletHandler.cs +++ b/osu.Framework/Input/Handlers/Tablet/ITabletHandler.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Bindables; using osuTK; diff --git a/osu.Framework/Input/Handlers/Tablet/OpenTabletDriverHandler.cs b/osu.Framework/Input/Handlers/Tablet/OpenTabletDriverHandler.cs index c03ce4122..61bd2246b 100644 --- a/osu.Framework/Input/Handlers/Tablet/OpenTabletDriverHandler.cs +++ b/osu.Framework/Input/Handlers/Tablet/OpenTabletDriverHandler.cs @@ -1,8 +1,11 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + #if NET6_0_OR_GREATER using System.Linq; +using System.Threading.Tasks; using JetBrains.Annotations; using OpenTabletDriver; using OpenTabletDriver.Plugin; @@ -10,6 +13,7 @@ using OpenTabletDriver.Plugin.Output; using OpenTabletDriver.Plugin.Platform.Pointer; using OpenTabletDriver.Plugin.Tablet; using osu.Framework.Bindables; +using osu.Framework.Extensions; using osu.Framework.Input.StateChanges; using osu.Framework.Platform; using osu.Framework.Statistics; @@ -38,6 +42,8 @@ namespace osu.Framework.Input.Handlers.Tablet private readonly Bindable tablet = new Bindable(); + private Task lastInitTask; + public override bool Initialize(GameHost host) { outputMode = new AbsoluteTabletMode(this); @@ -48,30 +54,34 @@ namespace osu.Framework.Input.Handlers.Tablet AreaSize.BindValueChanged(_ => updateInputArea(device), true); Rotation.BindValueChanged(_ => updateInputArea(device), true); - Enabled.BindValueChanged(d => + Enabled.BindValueChanged(enabled => { - if (d.NewValue && tabletDriver == null) + if (enabled.NewValue) { - tabletDriver = TabletDriver.Create(); - tabletDriver.TabletsChanged += (s, e) => + lastInitTask = Task.Run(() => { - device = e.Any() ? tabletDriver.InputDevices.First() : null; - - if (device != null) + tabletDriver = TabletDriver.Create(); + tabletDriver.TabletsChanged += (_, e) => { - device.OutputMode = outputMode; - outputMode.Tablet = device.CreateReference(); + device = e.Any() ? tabletDriver.InputDevices.First() : null; - updateInputArea(device); - updateOutputArea(host.Window); - } - }; - tabletDriver.DeviceReported += handleDeviceReported; - tabletDriver.Detect(); + if (device != null) + { + device.OutputMode = outputMode; + outputMode.Tablet = device.CreateReference(); + + updateInputArea(device); + updateOutputArea(host.Window); + } + }; + tabletDriver.DeviceReported += handleDeviceReported; + tabletDriver.Detect(); + }); } - else if (!d.NewValue && tabletDriver != null) + else { - tabletDriver.Dispose(); + lastInitTask?.WaitSafely(); + tabletDriver?.Dispose(); tabletDriver = null; } }, true); diff --git a/osu.Framework/Input/Handlers/Tablet/TabletDriver.cs b/osu.Framework/Input/Handlers/Tablet/TabletDriver.cs index f47334205..ccfe92cd7 100644 --- a/osu.Framework/Input/Handlers/Tablet/TabletDriver.cs +++ b/osu.Framework/Input/Handlers/Tablet/TabletDriver.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + #if NET6_0_OR_GREATER using System; using System.Collections.Generic; @@ -29,9 +31,9 @@ namespace osu.Framework.Input.Handlers.Tablet public TabletDriver([NotNull] ICompositeDeviceHub deviceHub, [NotNull] IReportParserProvider reportParserProvider, [NotNull] IDeviceConfigurationProvider configurationProvider) : base(deviceHub, reportParserProvider, configurationProvider) { - Log.Output += (sender, logMessage) => Logger.Log($"{logMessage.Group}: {logMessage.Message}", level: (LogLevel)logMessage.Level); + Log.Output += (_, logMessage) => Logger.Log($"{logMessage.Group}: {logMessage.Message}", level: (LogLevel)logMessage.Level); - deviceHub.DevicesChanged += (sender, args) => + deviceHub.DevicesChanged += (_, args) => { // it's worth noting that this event fires on *any* device change system-wide, including non-tablet devices. if (!Tablets.Any() && args.Additions.Any()) @@ -62,7 +64,7 @@ namespace osu.Framework.Input.Handlers.Tablet foreach (var endpoint in device.InputDevices) { endpoint.Report += DeviceReported; - endpoint.ConnectionStateChanged += (sender, connected) => + endpoint.ConnectionStateChanged += (_, connected) => { if (!connected) endpoint.Report -= DeviceReported; diff --git a/osu.Framework/Input/Handlers/Tablet/TabletInfo.cs b/osu.Framework/Input/Handlers/Tablet/TabletInfo.cs index 759ceaec9..b2dd9c4c4 100644 --- a/osu.Framework/Input/Handlers/Tablet/TabletInfo.cs +++ b/osu.Framework/Input/Handlers/Tablet/TabletInfo.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osuTK; namespace osu.Framework.Input.Handlers.Tablet diff --git a/osu.Framework/Input/IHandleGlobalKeyboardInput.cs b/osu.Framework/Input/IHandleGlobalKeyboardInput.cs index 8eb217ccf..d3a5af458 100644 --- a/osu.Framework/Input/IHandleGlobalKeyboardInput.cs +++ b/osu.Framework/Input/IHandleGlobalKeyboardInput.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Input { /// diff --git a/osu.Framework/Input/IRequireHighFrequencyMousePosition.cs b/osu.Framework/Input/IRequireHighFrequencyMousePosition.cs index 5eb88c4b1..b73c2d285 100644 --- a/osu.Framework/Input/IRequireHighFrequencyMousePosition.cs +++ b/osu.Framework/Input/IRequireHighFrequencyMousePosition.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics; namespace osu.Framework.Input diff --git a/osu.Framework/Input/ISuppressKeyEventLogging.cs b/osu.Framework/Input/ISuppressKeyEventLogging.cs index 686ab71a9..08bc77555 100644 --- a/osu.Framework/Input/ISuppressKeyEventLogging.cs +++ b/osu.Framework/Input/ISuppressKeyEventLogging.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Input { /// diff --git a/osu.Framework/Input/InputManager.cs b/osu.Framework/Input/InputManager.cs index 5f821ff3e..8b5974bd1 100644 --- a/osu.Framework/Input/InputManager.cs +++ b/osu.Framework/Input/InputManager.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Collections.Immutable; @@ -394,7 +396,7 @@ namespace osu.Framework.Input if (previousFocus != null) { previousFocus.HasFocus = false; - previousFocus.TriggerEvent(new FocusLostEvent(state)); + previousFocus.TriggerEvent(new FocusLostEvent(state, potentialFocusTarget)); if (FocusedDrawable != null) throw new InvalidOperationException($"Focus cannot be changed inside {nameof(OnFocusLost)}"); } @@ -406,7 +408,7 @@ namespace osu.Framework.Input if (FocusedDrawable != null) { FocusedDrawable.HasFocus = true; - FocusedDrawable.TriggerEvent(new FocusEvent(state)); + FocusedDrawable.TriggerEvent(new FocusEvent(state, previousFocus)); } return true; @@ -888,9 +890,9 @@ namespace osu.Framework.Input case KeyDownEvent k: return !k.Repeat; - case DragEvent _: - case ScrollEvent _: - case MouseMoveEvent _: + case DragEvent: + case ScrollEvent: + case MouseMoveEvent: return false; default: diff --git a/osu.Framework/Input/InputResampler.cs b/osu.Framework/Input/InputResampler.cs index 69326e7bc..e1c018dab 100644 --- a/osu.Framework/Input/InputResampler.cs +++ b/osu.Framework/Input/InputResampler.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using osuTK; diff --git a/osu.Framework/Input/JoystickAxis.cs b/osu.Framework/Input/JoystickAxis.cs index ee451029f..3020c83d2 100644 --- a/osu.Framework/Input/JoystickAxis.cs +++ b/osu.Framework/Input/JoystickAxis.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Input { public readonly struct JoystickAxis diff --git a/osu.Framework/Input/JoystickAxisEventManager.cs b/osu.Framework/Input/JoystickAxisEventManager.cs index 7fc936fa5..9b04750f4 100644 --- a/osu.Framework/Input/JoystickAxisEventManager.cs +++ b/osu.Framework/Input/JoystickAxisEventManager.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework/Input/JoystickAxisSource.cs b/osu.Framework/Input/JoystickAxisSource.cs index eeff692c0..1d99462b7 100644 --- a/osu.Framework/Input/JoystickAxisSource.cs +++ b/osu.Framework/Input/JoystickAxisSource.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Input { public enum JoystickAxisSource diff --git a/osu.Framework/Input/JoystickButton.cs b/osu.Framework/Input/JoystickButton.cs index f839b1def..7ba89305d 100644 --- a/osu.Framework/Input/JoystickButton.cs +++ b/osu.Framework/Input/JoystickButton.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Input { public enum JoystickButton diff --git a/osu.Framework/Input/JoystickButtonEventManager.cs b/osu.Framework/Input/JoystickButtonEventManager.cs index 95c323305..7378a5220 100644 --- a/osu.Framework/Input/JoystickButtonEventManager.cs +++ b/osu.Framework/Input/JoystickButtonEventManager.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using osu.Framework.Graphics; using osu.Framework.Input.Events; diff --git a/osu.Framework/Input/KeyEventManager.cs b/osu.Framework/Input/KeyEventManager.cs index a606ac8a9..097a61695 100644 --- a/osu.Framework/Input/KeyEventManager.cs +++ b/osu.Framework/Input/KeyEventManager.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using System.Linq; using osu.Framework.Graphics; diff --git a/osu.Framework/Input/MidiKey.cs b/osu.Framework/Input/MidiKey.cs index 2cfe9be94..9ec977f7f 100644 --- a/osu.Framework/Input/MidiKey.cs +++ b/osu.Framework/Input/MidiKey.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Input { public enum MidiKey diff --git a/osu.Framework/Input/MidiKeyEventManager.cs b/osu.Framework/Input/MidiKeyEventManager.cs index e0b7b93a5..8b0151ea5 100644 --- a/osu.Framework/Input/MidiKeyEventManager.cs +++ b/osu.Framework/Input/MidiKeyEventManager.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using osu.Framework.Graphics; using osu.Framework.Input.Events; diff --git a/osu.Framework/Input/MouseButtonEventManager.cs b/osu.Framework/Input/MouseButtonEventManager.cs index f9a389473..b0fab0995 100644 --- a/osu.Framework/Input/MouseButtonEventManager.cs +++ b/osu.Framework/Input/MouseButtonEventManager.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/osu.Framework/Input/PassThroughInputManager.cs b/osu.Framework/Input/PassThroughInputManager.cs index 5b67e6654..37bdb6ed6 100644 --- a/osu.Framework/Input/PassThroughInputManager.cs +++ b/osu.Framework/Input/PassThroughInputManager.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using System.Linq; using osu.Framework.Graphics; @@ -118,11 +120,11 @@ namespace osu.Framework.Input new MidiKeyInput(midi.Key, midi.Velocity, midi.IsPressed(midi.Key)).Apply(CurrentState, this); break; - case KeyboardEvent _: - case JoystickButtonEvent _: - case JoystickAxisMoveEvent _: - case TabletPenButtonEvent _: - case TabletAuxiliaryButtonEvent _: + case KeyboardEvent: + case JoystickButtonEvent: + case JoystickAxisMoveEvent: + case TabletPenButtonEvent: + case TabletAuxiliaryButtonEvent: SyncInputState(e.CurrentState); break; } diff --git a/osu.Framework/Input/PlatformAction.cs b/osu.Framework/Input/PlatformAction.cs index 2be94aa5b..19fe812bc 100644 --- a/osu.Framework/Input/PlatformAction.cs +++ b/osu.Framework/Input/PlatformAction.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Input { public enum PlatformAction diff --git a/osu.Framework/Input/PlatformActionContainer.cs b/osu.Framework/Input/PlatformActionContainer.cs index 66e2ac928..ab07e4e8d 100644 --- a/osu.Framework/Input/PlatformActionContainer.cs +++ b/osu.Framework/Input/PlatformActionContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using osu.Framework.Allocation; using osu.Framework.Input.Bindings; diff --git a/osu.Framework/Input/ReadableKeyCombinationProvider.cs b/osu.Framework/Input/ReadableKeyCombinationProvider.cs index b55790899..741494994 100644 --- a/osu.Framework/Input/ReadableKeyCombinationProvider.cs +++ b/osu.Framework/Input/ReadableKeyCombinationProvider.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Linq; using osu.Framework.Extensions.EnumExtensions; diff --git a/osu.Framework/Input/SDL2DesktopWindowTextInput.cs b/osu.Framework/Input/SDL2DesktopWindowTextInput.cs index ac0fb7fdd..4888ee4c8 100644 --- a/osu.Framework/Input/SDL2DesktopWindowTextInput.cs +++ b/osu.Framework/Input/SDL2DesktopWindowTextInput.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.Primitives; using osu.Framework.Platform; diff --git a/osu.Framework/Input/StateChanges/ButtonInput.cs b/osu.Framework/Input/StateChanges/ButtonInput.cs index 87d394c43..1eb83a51a 100644 --- a/osu.Framework/Input/StateChanges/ButtonInput.cs +++ b/osu.Framework/Input/StateChanges/ButtonInput.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using System.Collections.Immutable; using osu.Framework.Input.StateChanges.Events; diff --git a/osu.Framework/Input/StateChanges/ButtonInputEntry.cs b/osu.Framework/Input/StateChanges/ButtonInputEntry.cs index 546c144c9..a7bf6c845 100644 --- a/osu.Framework/Input/StateChanges/ButtonInputEntry.cs +++ b/osu.Framework/Input/StateChanges/ButtonInputEntry.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Input.StateChanges { /// diff --git a/osu.Framework/Input/StateChanges/ButtonStateChangeKind.cs b/osu.Framework/Input/StateChanges/ButtonStateChangeKind.cs index 7f75de258..417a0aa68 100644 --- a/osu.Framework/Input/StateChanges/ButtonStateChangeKind.cs +++ b/osu.Framework/Input/StateChanges/ButtonStateChangeKind.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Input.StateChanges { /// diff --git a/osu.Framework/Input/StateChanges/Events/ButtonStateChangeEvent.cs b/osu.Framework/Input/StateChanges/Events/ButtonStateChangeEvent.cs index 05300b7ff..4e204a29a 100644 --- a/osu.Framework/Input/StateChanges/Events/ButtonStateChangeEvent.cs +++ b/osu.Framework/Input/StateChanges/Events/ButtonStateChangeEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.States; namespace osu.Framework.Input.StateChanges.Events diff --git a/osu.Framework/Input/StateChanges/Events/InputStateChangeEvent.cs b/osu.Framework/Input/StateChanges/Events/InputStateChangeEvent.cs index e5092ac1c..a06d3a7ff 100644 --- a/osu.Framework/Input/StateChanges/Events/InputStateChangeEvent.cs +++ b/osu.Framework/Input/StateChanges/Events/InputStateChangeEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using JetBrains.Annotations; using osu.Framework.Input.States; diff --git a/osu.Framework/Input/StateChanges/Events/JoystickAxisChangeEvent.cs b/osu.Framework/Input/StateChanges/Events/JoystickAxisChangeEvent.cs index 6ed5b96fb..c3a4aa46b 100644 --- a/osu.Framework/Input/StateChanges/Events/JoystickAxisChangeEvent.cs +++ b/osu.Framework/Input/StateChanges/Events/JoystickAxisChangeEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.States; namespace osu.Framework.Input.StateChanges.Events diff --git a/osu.Framework/Input/StateChanges/Events/MousePositionChangeEvent.cs b/osu.Framework/Input/StateChanges/Events/MousePositionChangeEvent.cs index 3fa12b9dd..7c8d43331 100644 --- a/osu.Framework/Input/StateChanges/Events/MousePositionChangeEvent.cs +++ b/osu.Framework/Input/StateChanges/Events/MousePositionChangeEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.States; using osuTK; diff --git a/osu.Framework/Input/StateChanges/Events/MouseScrollChangeEvent.cs b/osu.Framework/Input/StateChanges/Events/MouseScrollChangeEvent.cs index 606db99a2..15295b1ae 100644 --- a/osu.Framework/Input/StateChanges/Events/MouseScrollChangeEvent.cs +++ b/osu.Framework/Input/StateChanges/Events/MouseScrollChangeEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.States; using osuTK; diff --git a/osu.Framework/Input/StateChanges/Events/TouchStateChangeEvent.cs b/osu.Framework/Input/StateChanges/Events/TouchStateChangeEvent.cs index caf1c3d02..850bc840b 100644 --- a/osu.Framework/Input/StateChanges/Events/TouchStateChangeEvent.cs +++ b/osu.Framework/Input/StateChanges/Events/TouchStateChangeEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.States; using osuTK; diff --git a/osu.Framework/Input/StateChanges/IInput.cs b/osu.Framework/Input/StateChanges/IInput.cs index c07b8c78a..3f647d143 100644 --- a/osu.Framework/Input/StateChanges/IInput.cs +++ b/osu.Framework/Input/StateChanges/IInput.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.States; namespace osu.Framework.Input.StateChanges diff --git a/osu.Framework/Input/StateChanges/IInputStateChangeHandler.cs b/osu.Framework/Input/StateChanges/IInputStateChangeHandler.cs index 46e368458..7033dff7c 100644 --- a/osu.Framework/Input/StateChanges/IInputStateChangeHandler.cs +++ b/osu.Framework/Input/StateChanges/IInputStateChangeHandler.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.StateChanges.Events; using osu.Framework.Input.States; diff --git a/osu.Framework/Input/StateChanges/ISourcedFromTouch.cs b/osu.Framework/Input/StateChanges/ISourcedFromTouch.cs index 5e52e6f52..86f3a9fee 100644 --- a/osu.Framework/Input/StateChanges/ISourcedFromTouch.cs +++ b/osu.Framework/Input/StateChanges/ISourcedFromTouch.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.StateChanges.Events; namespace osu.Framework.Input.StateChanges diff --git a/osu.Framework/Input/StateChanges/JoystickAxisInput.cs b/osu.Framework/Input/StateChanges/JoystickAxisInput.cs index d9cca9df9..ea62274c6 100644 --- a/osu.Framework/Input/StateChanges/JoystickAxisInput.cs +++ b/osu.Framework/Input/StateChanges/JoystickAxisInput.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; @@ -41,9 +43,46 @@ namespace osu.Framework.Input.StateChanges if (oldValue == a.Value || (a.Value != 0 && Precision.AlmostEquals(oldValue, a.Value))) continue; + applyButtonInputsIfNeeded(state, handler, a); + state.Joystick.AxesValues[(int)a.Source] = a.Value; handler.HandleInputStateChange(new JoystickAxisChangeEvent(state, this, a, oldValue)); } } + + /// + /// Applies events depending on whether the axis has changed direction. + /// + private void applyButtonInputsIfNeeded(InputState state, IInputStateChangeHandler handler, JoystickAxis axis) + { + int index = (int)axis.Source; + var currentButton = state.Joystick.AxisDirectionButtons[index]; + var expectedButton = getAxisButtonForInput(index, axis.Value); + + // if a directional button is pressed and does not match that for the new axis direction, release it + if (currentButton != 0 && expectedButton != currentButton) + { + new JoystickButtonInput(currentButton, false).Apply(state, handler); + state.Joystick.AxisDirectionButtons[index] = currentButton = 0; + } + + // if we expect a directional button to be pressed, and it is not, press it + if (expectedButton != 0 && expectedButton != currentButton) + { + new JoystickButtonInput(expectedButton, true).Apply(state, handler); + state.Joystick.AxisDirectionButtons[index] = expectedButton; + } + } + + private static JoystickButton getAxisButtonForInput(int axisIndex, float axisValue) + { + if (axisValue > 0) + return JoystickButton.FirstAxisPositive + axisIndex; + + if (axisValue < 0) + return JoystickButton.FirstAxisNegative + axisIndex; + + return 0; + } } } diff --git a/osu.Framework/Input/StateChanges/JoystickButtonInput.cs b/osu.Framework/Input/StateChanges/JoystickButtonInput.cs index 61538ef5c..a13013f22 100644 --- a/osu.Framework/Input/StateChanges/JoystickButtonInput.cs +++ b/osu.Framework/Input/StateChanges/JoystickButtonInput.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using osu.Framework.Input.States; diff --git a/osu.Framework/Input/StateChanges/KeyboardKeyInput.cs b/osu.Framework/Input/StateChanges/KeyboardKeyInput.cs index 2f84c462a..1bd4bcdcb 100644 --- a/osu.Framework/Input/StateChanges/KeyboardKeyInput.cs +++ b/osu.Framework/Input/StateChanges/KeyboardKeyInput.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using osu.Framework.Input.States; using osuTK.Input; diff --git a/osu.Framework/Input/StateChanges/MidiKeyInput.cs b/osu.Framework/Input/StateChanges/MidiKeyInput.cs index 808b6ddd2..389eedf99 100644 --- a/osu.Framework/Input/StateChanges/MidiKeyInput.cs +++ b/osu.Framework/Input/StateChanges/MidiKeyInput.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using System.Linq; using osu.Framework.Input.States; diff --git a/osu.Framework/Input/StateChanges/MouseButtonInput.cs b/osu.Framework/Input/StateChanges/MouseButtonInput.cs index 2debe2d76..949e1d2c7 100644 --- a/osu.Framework/Input/StateChanges/MouseButtonInput.cs +++ b/osu.Framework/Input/StateChanges/MouseButtonInput.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using osu.Framework.Input.States; using osuTK.Input; diff --git a/osu.Framework/Input/StateChanges/MouseButtonInputFromTouch.cs b/osu.Framework/Input/StateChanges/MouseButtonInputFromTouch.cs index 0aef05c4c..63e69ddb2 100644 --- a/osu.Framework/Input/StateChanges/MouseButtonInputFromTouch.cs +++ b/osu.Framework/Input/StateChanges/MouseButtonInputFromTouch.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.StateChanges.Events; using osuTK.Input; diff --git a/osu.Framework/Input/StateChanges/MousePositionAbsoluteInput.cs b/osu.Framework/Input/StateChanges/MousePositionAbsoluteInput.cs index 4bef388c4..becaa224b 100644 --- a/osu.Framework/Input/StateChanges/MousePositionAbsoluteInput.cs +++ b/osu.Framework/Input/StateChanges/MousePositionAbsoluteInput.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.StateChanges.Events; using osu.Framework.Input.States; using osuTK; diff --git a/osu.Framework/Input/StateChanges/MousePositionAbsoluteInputFromTouch.cs b/osu.Framework/Input/StateChanges/MousePositionAbsoluteInputFromTouch.cs index 43e46036f..27c4915ce 100644 --- a/osu.Framework/Input/StateChanges/MousePositionAbsoluteInputFromTouch.cs +++ b/osu.Framework/Input/StateChanges/MousePositionAbsoluteInputFromTouch.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.StateChanges.Events; namespace osu.Framework.Input.StateChanges diff --git a/osu.Framework/Input/StateChanges/MousePositionRelativeInput.cs b/osu.Framework/Input/StateChanges/MousePositionRelativeInput.cs index 19f384794..a7da88b3b 100644 --- a/osu.Framework/Input/StateChanges/MousePositionRelativeInput.cs +++ b/osu.Framework/Input/StateChanges/MousePositionRelativeInput.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.StateChanges.Events; using osu.Framework.Input.States; using osuTK; diff --git a/osu.Framework/Input/StateChanges/MouseScrollRelativeInput.cs b/osu.Framework/Input/StateChanges/MouseScrollRelativeInput.cs index 5880f166b..5b337de68 100644 --- a/osu.Framework/Input/StateChanges/MouseScrollRelativeInput.cs +++ b/osu.Framework/Input/StateChanges/MouseScrollRelativeInput.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.StateChanges.Events; using osu.Framework.Input.States; using osuTK; @@ -32,6 +34,9 @@ namespace osu.Framework.Input.StateChanges if (Delta != Vector2.Zero) { + if (!IsPrecise && Delta.X == 0 && state.Keyboard.ShiftPressed) + Delta = new Vector2(Delta.Y, 0); + var lastScroll = mouse.Scroll; mouse.Scroll += Delta; mouse.LastSource = this; diff --git a/osu.Framework/Input/StateChanges/TabletAuxiliaryButtonInput.cs b/osu.Framework/Input/StateChanges/TabletAuxiliaryButtonInput.cs index 5ecf4375c..ebedc45f8 100644 --- a/osu.Framework/Input/StateChanges/TabletAuxiliaryButtonInput.cs +++ b/osu.Framework/Input/StateChanges/TabletAuxiliaryButtonInput.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using osu.Framework.Input.States; diff --git a/osu.Framework/Input/StateChanges/TabletPenButtonInput.cs b/osu.Framework/Input/StateChanges/TabletPenButtonInput.cs index 5ca068c79..d6f14ea22 100644 --- a/osu.Framework/Input/StateChanges/TabletPenButtonInput.cs +++ b/osu.Framework/Input/StateChanges/TabletPenButtonInput.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using osu.Framework.Input.States; diff --git a/osu.Framework/Input/StateChanges/TouchInput.cs b/osu.Framework/Input/StateChanges/TouchInput.cs index 5663cbb50..99ca1a987 100644 --- a/osu.Framework/Input/StateChanges/TouchInput.cs +++ b/osu.Framework/Input/StateChanges/TouchInput.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Input.StateChanges.Events; @@ -59,7 +61,7 @@ namespace osu.Framework.Input.StateChanges if (activityChanged || positionChanged) { handler.HandleInputStateChange(new TouchStateChangeEvent(state, this, touch, - !activityChanged ? (bool?)null : Activate, + !activityChanged ? null : Activate, !positionChanged ? null : lastPosition )); } diff --git a/osu.Framework/Input/States/ButtonStates.cs b/osu.Framework/Input/States/ButtonStates.cs index 07bbe0882..e4926d5a1 100644 --- a/osu.Framework/Input/States/ButtonStates.cs +++ b/osu.Framework/Input/States/ButtonStates.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections; using System.Collections.Generic; diff --git a/osu.Framework/Input/States/InputState.cs b/osu.Framework/Input/States/InputState.cs index 3ede34fcf..0ddc32722 100644 --- a/osu.Framework/Input/States/InputState.cs +++ b/osu.Framework/Input/States/InputState.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Input.States { /// diff --git a/osu.Framework/Input/States/JoystickState.cs b/osu.Framework/Input/States/JoystickState.cs index abd4ad0f4..6c3c35665 100644 --- a/osu.Framework/Input/States/JoystickState.cs +++ b/osu.Framework/Input/States/JoystickState.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using System.Linq; @@ -17,6 +19,11 @@ namespace osu.Framework.Input.States /// public readonly float[] AxesValues = new float[MAX_AXES]; + /// + /// Currently simulated for each . 0 if no button press is simulated. + /// + internal readonly JoystickButton[] AxisDirectionButtons = new JoystickButton[MAX_AXES]; + /// /// Retrieves all with their current value (regardless of inactive ones). /// diff --git a/osu.Framework/Input/States/KeyboardState.cs b/osu.Framework/Input/States/KeyboardState.cs index 19a344fc1..e11b13f36 100644 --- a/osu.Framework/Input/States/KeyboardState.cs +++ b/osu.Framework/Input/States/KeyboardState.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osuTK.Input; namespace osu.Framework.Input.States diff --git a/osu.Framework/Input/States/MidiState.cs b/osu.Framework/Input/States/MidiState.cs index a97870f8e..df0e9ca28 100644 --- a/osu.Framework/Input/States/MidiState.cs +++ b/osu.Framework/Input/States/MidiState.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; namespace osu.Framework.Input.States diff --git a/osu.Framework/Input/States/MouseState.cs b/osu.Framework/Input/States/MouseState.cs index fec7834e7..d2761e259 100644 --- a/osu.Framework/Input/States/MouseState.cs +++ b/osu.Framework/Input/States/MouseState.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Extensions.TypeExtensions; using osu.Framework.Input.StateChanges; using osuTK; diff --git a/osu.Framework/Input/States/TabletState.cs b/osu.Framework/Input/States/TabletState.cs index 14a5565fc..405c46606 100644 --- a/osu.Framework/Input/States/TabletState.cs +++ b/osu.Framework/Input/States/TabletState.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Extensions.TypeExtensions; using osuTK; diff --git a/osu.Framework/Input/States/TouchState.cs b/osu.Framework/Input/States/TouchState.cs index 5f0949ba9..6a53437d0 100644 --- a/osu.Framework/Input/States/TouchState.cs +++ b/osu.Framework/Input/States/TouchState.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; @@ -34,7 +36,7 @@ namespace osu.Framework.Input.States /// /// The touch source. /// The touch position, or null if provided is not currently active. - public Vector2? GetTouchPosition(TouchSource source) => IsActive(source) ? TouchPositions[(int)source] : (Vector2?)null; + public Vector2? GetTouchPosition(TouchSource source) => IsActive(source) ? TouchPositions[(int)source] : null; /// /// Whether the provided touch is active. diff --git a/osu.Framework/Input/TabletAuxiliaryButton.cs b/osu.Framework/Input/TabletAuxiliaryButton.cs index c88f2499e..14e689b71 100644 --- a/osu.Framework/Input/TabletAuxiliaryButton.cs +++ b/osu.Framework/Input/TabletAuxiliaryButton.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Input { public enum TabletAuxiliaryButton diff --git a/osu.Framework/Input/TabletAuxiliaryButtonEventManager.cs b/osu.Framework/Input/TabletAuxiliaryButtonEventManager.cs index ce3195b7f..a1538fe2b 100644 --- a/osu.Framework/Input/TabletAuxiliaryButtonEventManager.cs +++ b/osu.Framework/Input/TabletAuxiliaryButtonEventManager.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using osu.Framework.Graphics; using osu.Framework.Input.Events; diff --git a/osu.Framework/Input/TabletPenButton.cs b/osu.Framework/Input/TabletPenButton.cs index f49b4353b..9f81a3a9e 100644 --- a/osu.Framework/Input/TabletPenButton.cs +++ b/osu.Framework/Input/TabletPenButton.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Input { public enum TabletPenButton diff --git a/osu.Framework/Input/TabletPenButtonEventManager.cs b/osu.Framework/Input/TabletPenButtonEventManager.cs index 064d42bc2..0bcba8a5f 100644 --- a/osu.Framework/Input/TabletPenButtonEventManager.cs +++ b/osu.Framework/Input/TabletPenButtonEventManager.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using osu.Framework.Graphics; using osu.Framework.Input.Events; diff --git a/osu.Framework/Input/TextInputSource.cs b/osu.Framework/Input/TextInputSource.cs index 897fcb535..96a8db740 100644 --- a/osu.Framework/Input/TextInputSource.cs +++ b/osu.Framework/Input/TextInputSource.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Threading; using osu.Framework.Graphics.Primitives; diff --git a/osu.Framework/Input/Touch.cs b/osu.Framework/Input/Touch.cs index 91237eded..0744cbdaa 100644 --- a/osu.Framework/Input/Touch.cs +++ b/osu.Framework/Input/Touch.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osuTK; diff --git a/osu.Framework/Input/TouchEventManager.cs b/osu.Framework/Input/TouchEventManager.cs index c1b0cbcf1..4e00f696e 100644 --- a/osu.Framework/Input/TouchEventManager.cs +++ b/osu.Framework/Input/TouchEventManager.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using System.Diagnostics; using osu.Framework.Graphics; diff --git a/osu.Framework/Input/TouchSource.cs b/osu.Framework/Input/TouchSource.cs index f44942138..eb0e7cfa6 100644 --- a/osu.Framework/Input/TouchSource.cs +++ b/osu.Framework/Input/TouchSource.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Input { /// diff --git a/osu.Framework/Input/UserInputManager.cs b/osu.Framework/Input/UserInputManager.cs index 704059c98..854ef21f6 100644 --- a/osu.Framework/Input/UserInputManager.cs +++ b/osu.Framework/Input/UserInputManager.cs @@ -1,15 +1,21 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + +using System; using System.Collections.Immutable; +using System.Drawing; +using System.Linq; +using osu.Framework.Configuration; using osu.Framework.Extensions.EnumExtensions; -using osu.Framework.Graphics.Primitives; using osu.Framework.Input.Handlers; using osu.Framework.Input.StateChanges; using osu.Framework.Input.StateChanges.Events; using osu.Framework.Platform; using osuTK; using osuTK.Input; +using RectangleF = osu.Framework.Graphics.Primitives.RectangleF; namespace osu.Framework.Input { @@ -36,11 +42,27 @@ namespace osu.Framework.Input var mouse = mousePositionChange.State.Mouse; // confine cursor - if (Host.Window != null && Host.Window.CursorState.HasFlagFast(CursorState.Confined)) + if (Host.Window != null) { + RectangleF? cursorConfineRect = null; var clientSize = Host.Window.ClientSize; - var cursorConfineRect = Host.Window.CursorConfineRect ?? new RectangleF(0, 0, clientSize.Width, clientSize.Height); - mouse.Position = Vector2.Clamp(mouse.Position, cursorConfineRect.Location, cursorConfineRect.Location + cursorConfineRect.Size - Vector2.One); + var windowRect = new RectangleF(0, 0, clientSize.Width, clientSize.Height); + + if (Host.Window.CursorState.HasFlagFast(CursorState.Confined)) + { + cursorConfineRect = Host.Window.CursorConfineRect ?? windowRect; + } + else if (mouseOutsideAllDisplays(mouse.Position)) + { + // Implicitly confine the cursor to prevent a feedback loop of MouseHandler warping the cursor to an invalid position + // and the OS immediately warping it back inside a display. + + // Window.CursorConfineRect is not used here as that should only be used when confining is explicitly enabled. + cursorConfineRect = windowRect; + } + + if (cursorConfineRect.HasValue) + mouse.Position = Vector2.Clamp(mouse.Position, cursorConfineRect.Value.Location, cursorConfineRect.Value.Location + cursorConfineRect.Value.Size - Vector2.One); } break; @@ -51,7 +73,7 @@ namespace osu.Framework.Input break; - case MouseScrollChangeEvent _: + case MouseScrollChangeEvent: if (Host.Window?.CursorInWindow.Value == false) return; @@ -60,5 +82,26 @@ namespace osu.Framework.Input base.HandleInputStateChange(inputStateChange); } + + private bool mouseOutsideAllDisplays(Vector2 mousePosition) + { + Point windowLocation; + + switch (Host.Window.WindowMode.Value) + { + case WindowMode.Windowed: + windowLocation = Host.Window is SDL2DesktopWindow sdlWindow ? sdlWindow.Position : Point.Empty; + break; + + default: + windowLocation = Host.Window.CurrentDisplayBindable.Value.Bounds.Location; + break; + } + + int x = (int)MathF.Floor(windowLocation.X + mousePosition.X); + int y = (int)MathF.Floor(windowLocation.Y + mousePosition.Y); + + return !Host.Window.Displays.Any(d => d.Bounds.Contains(x, y)); + } } } diff --git a/osu.Framework/Layout/InvalidationSource.cs b/osu.Framework/Layout/InvalidationSource.cs index 8e9b73f3b..97abfcbf3 100644 --- a/osu.Framework/Layout/InvalidationSource.cs +++ b/osu.Framework/Layout/InvalidationSource.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Graphics; diff --git a/osu.Framework/Layout/LayoutMember.cs b/osu.Framework/Layout/LayoutMember.cs index 97c43eb2c..9999ac760 100644 --- a/osu.Framework/Layout/LayoutMember.cs +++ b/osu.Framework/Layout/LayoutMember.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics; using osu.Framework.Statistics; diff --git a/osu.Framework/Layout/LayoutValue.cs b/osu.Framework/Layout/LayoutValue.cs index 1e5a91fd6..f42e46e4a 100644 --- a/osu.Framework/Layout/LayoutValue.cs +++ b/osu.Framework/Layout/LayoutValue.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Graphics; diff --git a/osu.Framework/Lists/FuncEqualityComparer.cs b/osu.Framework/Lists/FuncEqualityComparer.cs index bd4fbb7d5..b404225d1 100644 --- a/osu.Framework/Lists/FuncEqualityComparer.cs +++ b/osu.Framework/Lists/FuncEqualityComparer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; diff --git a/osu.Framework/Lists/INotifyArrayChanged.cs b/osu.Framework/Lists/INotifyArrayChanged.cs index 073c912b1..4468b6d04 100644 --- a/osu.Framework/Lists/INotifyArrayChanged.cs +++ b/osu.Framework/Lists/INotifyArrayChanged.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; namespace osu.Framework.Lists diff --git a/osu.Framework/Lists/IWeakList.cs b/osu.Framework/Lists/IWeakList.cs index 0d6249958..79a37d7e6 100644 --- a/osu.Framework/Lists/IWeakList.cs +++ b/osu.Framework/Lists/IWeakList.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; namespace osu.Framework.Lists diff --git a/osu.Framework/Lists/LazyList.cs b/osu.Framework/Lists/LazyList.cs index 3090639c4..aebc35193 100644 --- a/osu.Framework/Lists/LazyList.cs +++ b/osu.Framework/Lists/LazyList.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections; using System.Collections.Generic; diff --git a/osu.Framework/Lists/LockedWeakList.cs b/osu.Framework/Lists/LockedWeakList.cs index 0191cb2eb..7bebe3655 100644 --- a/osu.Framework/Lists/LockedWeakList.cs +++ b/osu.Framework/Lists/LockedWeakList.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using System; using System.Collections; using System.Collections.Generic; diff --git a/osu.Framework/Lists/ObservableArray.cs b/osu.Framework/Lists/ObservableArray.cs index 7ccec4550..5450f1840 100644 --- a/osu.Framework/Lists/ObservableArray.cs +++ b/osu.Framework/Lists/ObservableArray.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections; using System.Collections.Generic; diff --git a/osu.Framework/Lists/SlimReadOnlyListWrapper.cs b/osu.Framework/Lists/SlimReadOnlyListWrapper.cs index 053eb35b0..346f8afe2 100644 --- a/osu.Framework/Lists/SlimReadOnlyListWrapper.cs +++ b/osu.Framework/Lists/SlimReadOnlyListWrapper.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using System; using System.Collections; using System.Collections.Generic; diff --git a/osu.Framework/Lists/SortedList.cs b/osu.Framework/Lists/SortedList.cs index cfa4b6706..2e157d6e9 100644 --- a/osu.Framework/Lists/SortedList.cs +++ b/osu.Framework/Lists/SortedList.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Extensions.TypeExtensions; using System; using System.Collections; diff --git a/osu.Framework/Lists/WeakList.cs b/osu.Framework/Lists/WeakList.cs index 8db166c11..c3254b94a 100644 --- a/osu.Framework/Lists/WeakList.cs +++ b/osu.Framework/Lists/WeakList.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using System; using System.Collections; using System.Collections.Generic; diff --git a/osu.Framework/Lists/WeakList_ValidItemsEnumerator.cs b/osu.Framework/Lists/WeakList_ValidItemsEnumerator.cs index f7da327ce..f65b112eb 100644 --- a/osu.Framework/Lists/WeakList_ValidItemsEnumerator.cs +++ b/osu.Framework/Lists/WeakList_ValidItemsEnumerator.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using System.Collections; using System.Collections.Generic; diff --git a/osu.Framework/Localisation/CaseTransformableString.cs b/osu.Framework/Localisation/CaseTransformableString.cs index 18bbc90f8..edfc382c9 100644 --- a/osu.Framework/Localisation/CaseTransformableString.cs +++ b/osu.Framework/Localisation/CaseTransformableString.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using System; using System.Globalization; diff --git a/osu.Framework/Localisation/ILocalisableStringData.cs b/osu.Framework/Localisation/ILocalisableStringData.cs index 7cc687a55..7bb08260c 100644 --- a/osu.Framework/Localisation/ILocalisableStringData.cs +++ b/osu.Framework/Localisation/ILocalisableStringData.cs @@ -3,8 +3,6 @@ using System; -#nullable enable - namespace osu.Framework.Localisation { /// diff --git a/osu.Framework/Localisation/ILocalisationStore.cs b/osu.Framework/Localisation/ILocalisationStore.cs index f9244a2e2..65c34c2fc 100644 --- a/osu.Framework/Localisation/ILocalisationStore.cs +++ b/osu.Framework/Localisation/ILocalisationStore.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Globalization; using osu.Framework.IO.Stores; diff --git a/osu.Framework/Localisation/ILocalisedBindableString.cs b/osu.Framework/Localisation/ILocalisedBindableString.cs index f0756ffcb..9539a61a8 100644 --- a/osu.Framework/Localisation/ILocalisedBindableString.cs +++ b/osu.Framework/Localisation/ILocalisedBindableString.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Bindables; namespace osu.Framework.Localisation diff --git a/osu.Framework/Localisation/LocaleMapping.cs b/osu.Framework/Localisation/LocaleMapping.cs new file mode 100644 index 000000000..6827480c7 --- /dev/null +++ b/osu.Framework/Localisation/LocaleMapping.cs @@ -0,0 +1,36 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +namespace osu.Framework.Localisation +{ + /// + /// Maps a localisation store to a lookup string. + /// Used by . + /// + public class LocaleMapping + { + public readonly string Name; + public readonly ILocalisationStore Storage; + + /// + /// Create a locale mapping from a localisation store. + /// + /// The store to be used. + public LocaleMapping(ILocalisationStore store) + { + Name = store.EffectiveCulture.Name; + Storage = store; + } + + /// + /// Create a locale mapping with a custom lookup name. + /// + /// + /// The store to be used. + public LocaleMapping(string name, ILocalisationStore store) + { + Name = name; + Storage = store; + } + } +} diff --git a/osu.Framework/Localisation/LocalisableDescriptionAttribute.cs b/osu.Framework/Localisation/LocalisableDescriptionAttribute.cs index 670ae07aa..96d526d7b 100644 --- a/osu.Framework/Localisation/LocalisableDescriptionAttribute.cs +++ b/osu.Framework/Localisation/LocalisableDescriptionAttribute.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Extensions; diff --git a/osu.Framework/Localisation/LocalisableFormattableString.cs b/osu.Framework/Localisation/LocalisableFormattableString.cs index 71b5c7629..009c3d930 100644 --- a/osu.Framework/Localisation/LocalisableFormattableString.cs +++ b/osu.Framework/Localisation/LocalisableFormattableString.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using System; using System.Globalization; using System.Linq; diff --git a/osu.Framework/Localisation/LocalisableString.cs b/osu.Framework/Localisation/LocalisableString.cs index d95d8381b..101d266e4 100644 --- a/osu.Framework/Localisation/LocalisableString.cs +++ b/osu.Framework/Localisation/LocalisableString.cs @@ -3,8 +3,6 @@ using System; -#nullable enable - namespace osu.Framework.Localisation { /// diff --git a/osu.Framework/Localisation/LocalisableStringEqualityComparer.cs b/osu.Framework/Localisation/LocalisableStringEqualityComparer.cs index 74c540427..ba0888514 100644 --- a/osu.Framework/Localisation/LocalisableStringEqualityComparer.cs +++ b/osu.Framework/Localisation/LocalisableStringEqualityComparer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; diff --git a/osu.Framework/Localisation/LocalisationManager.cs b/osu.Framework/Localisation/LocalisationManager.cs index 228efe82c..262614a50 100644 --- a/osu.Framework/Localisation/LocalisationManager.cs +++ b/osu.Framework/Localisation/LocalisationManager.cs @@ -6,8 +6,6 @@ using System.Globalization; using osu.Framework.Bindables; using osu.Framework.Configuration; -#nullable enable - namespace osu.Framework.Localisation { public partial class LocalisationManager @@ -30,6 +28,23 @@ namespace osu.Framework.Localisation configPreferUnicode.BindValueChanged(_ => UpdateLocalisationParameters(), true); } + /// + /// Add multiple locale mappings. Should be used to add all available languages at initialisation. + /// + /// All available locale mappings. + public void AddLocaleMappings(IEnumerable mappings) + { + locales.AddRange(mappings); + configLocale.TriggerChange(); + } + + /// + /// Add a single language to this manager. + /// + /// + /// Use as a more efficient way of bootstrapping all available locales. + /// The culture name to be added. Generally should match . + /// A storage providing localisations for the specified language. public void AddLanguage(string language, ILocalisationStore storage) { locales.Add(new LocaleMapping(language, storage)); @@ -104,17 +119,5 @@ namespace osu.Framework.Localisation /// /// The resultant . protected virtual LocalisationParameters CreateLocalisationParameters() => new LocalisationParameters(currentLocale?.Storage, configPreferUnicode.Value); - - private class LocaleMapping - { - public readonly string Name; - public readonly ILocalisationStore Storage; - - public LocaleMapping(string name, ILocalisationStore storage) - { - Name = name; - Storage = storage; - } - } } } diff --git a/osu.Framework/Localisation/LocalisationManager_LocalisedBindableString.cs b/osu.Framework/Localisation/LocalisationManager_LocalisedBindableString.cs index c9a6011c7..88f7bcd1a 100644 --- a/osu.Framework/Localisation/LocalisationManager_LocalisedBindableString.cs +++ b/osu.Framework/Localisation/LocalisationManager_LocalisedBindableString.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + #pragma warning disable 8632 // TODO: can be #nullable enable when Bindables are updated to also be. using osu.Framework.Bindables; diff --git a/osu.Framework/Localisation/LocalisationParameters.cs b/osu.Framework/Localisation/LocalisationParameters.cs index f2ba9c6a4..bb6126a78 100644 --- a/osu.Framework/Localisation/LocalisationParameters.cs +++ b/osu.Framework/Localisation/LocalisationParameters.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - namespace osu.Framework.Localisation { /// diff --git a/osu.Framework/Localisation/RomanisableString.cs b/osu.Framework/Localisation/RomanisableString.cs index a2a47d265..cb19b8f63 100644 --- a/osu.Framework/Localisation/RomanisableString.cs +++ b/osu.Framework/Localisation/RomanisableString.cs @@ -4,8 +4,6 @@ using System; using osu.Framework.Configuration; -#nullable enable - namespace osu.Framework.Localisation { /// diff --git a/osu.Framework/Localisation/TranslatableString.cs b/osu.Framework/Localisation/TranslatableString.cs index 3278ee30f..aa00af885 100644 --- a/osu.Framework/Localisation/TranslatableString.cs +++ b/osu.Framework/Localisation/TranslatableString.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using System; namespace osu.Framework.Localisation diff --git a/osu.Framework/Logging/LoadingComponentsLogger.cs b/osu.Framework/Logging/LoadingComponentsLogger.cs index 313c3bac5..28e05b405 100644 --- a/osu.Framework/Logging/LoadingComponentsLogger.cs +++ b/osu.Framework/Logging/LoadingComponentsLogger.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Linq; using System.Threading; using osu.Framework.Development; diff --git a/osu.Framework/Logging/Logger.cs b/osu.Framework/Logging/Logger.cs index 89758e7b5..02eeecdac 100644 --- a/osu.Framework/Logging/Logger.cs +++ b/osu.Framework/Logging/Logger.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Globalization; @@ -87,7 +89,7 @@ namespace osu.Framework.Logging private readonly GlobalStatistic logCount; - private static readonly HashSet reserved_names = new HashSet(Enum.GetNames(typeof(LoggingTarget)).Select(n => n.ToLower())); + private static readonly HashSet reserved_names = new HashSet(Enum.GetNames(typeof(LoggingTarget)).Select(n => n.ToLowerInvariant())); private Logger(LoggingTarget target = LoggingTarget.Runtime) : this(target.ToString(), false) @@ -97,7 +99,7 @@ namespace osu.Framework.Logging private Logger(string name, bool checkedReserved) { - name = name.ToLower(); + name = name.ToLowerInvariant(); if (string.IsNullOrWhiteSpace(name)) throw new ArgumentException("The name of a logger must be non-null and may not contain only white space.", nameof(name)); @@ -252,7 +254,7 @@ namespace osu.Framework.Logging { lock (static_sync_lock) { - string nameLower = name.ToLower(); + string nameLower = name.ToLowerInvariant(); if (!static_loggers.TryGetValue(nameLower, out Logger l)) { @@ -310,7 +312,7 @@ namespace osu.Framework.Logging IEnumerable lines = logOutput .Replace(@"\r\n", @"\n") .Split('\n') - .Select(s => $@"{DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture)} [{level.ToString().ToLower()}]: {s.Trim()}"); + .Select(s => $@"{DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture)} [{level.ToString().ToLowerInvariant()}]: {s.Trim()}"); if (outputToListeners) { @@ -339,7 +341,7 @@ namespace osu.Framework.Logging { if (bypassRateLimit || debugOutputRollingTime.RequestEntry()) { - consoleLog($"[{Name.ToLower()}] {line}"); + consoleLog($"[{Name.ToLowerInvariant()}] {line}"); if (!bypassRateLimit && debugOutputRollingTime.IsAtLimit) consoleLog($"Console output is being limited. Please check {Filename} for full logs."); diff --git a/osu.Framework/Logging/RollingTime.cs b/osu.Framework/Logging/RollingTime.cs index 8ec0ef546..9cb43e51f 100644 --- a/osu.Framework/Logging/RollingTime.cs +++ b/osu.Framework/Logging/RollingTime.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; namespace osu.Framework.Logging diff --git a/osu.Framework/Logging/ThrowingTraceListener.cs b/osu.Framework/Logging/ThrowingTraceListener.cs index 8caf3bb81..111714d62 100644 --- a/osu.Framework/Logging/ThrowingTraceListener.cs +++ b/osu.Framework/Logging/ThrowingTraceListener.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Diagnostics; using NUnit.Framework; diff --git a/osu.Framework/Physics/IRigidBody.cs b/osu.Framework/Physics/IRigidBody.cs index ba7075c9f..fd1ab34a1 100644 --- a/osu.Framework/Physics/IRigidBody.cs +++ b/osu.Framework/Physics/IRigidBody.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osuTK; using osu.Framework.Graphics; diff --git a/osu.Framework/Physics/RigidBodyContainer.cs b/osu.Framework/Physics/RigidBodyContainer.cs index ffdff95c6..a7c804f95 100644 --- a/osu.Framework/Physics/RigidBodyContainer.cs +++ b/osu.Framework/Physics/RigidBodyContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osuTK; using System; using System.Collections.Generic; diff --git a/osu.Framework/Physics/RigidBodySimulation.cs b/osu.Framework/Physics/RigidBodySimulation.cs index c0212eeaa..a09feff0d 100644 --- a/osu.Framework/Physics/RigidBodySimulation.cs +++ b/osu.Framework/Physics/RigidBodySimulation.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osuTK; using osu.Framework.Graphics; using System.Collections.Generic; diff --git a/osu.Framework/Platform/Clipboard.cs b/osu.Framework/Platform/Clipboard.cs index 96b3433a1..8e2bde6ae 100644 --- a/osu.Framework/Platform/Clipboard.cs +++ b/osu.Framework/Platform/Clipboard.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using SixLabors.ImageSharp; using SixLabors.ImageSharp.PixelFormats; diff --git a/osu.Framework/Platform/DesktopGameHost.cs b/osu.Framework/Platform/DesktopGameHost.cs index 1578f82bd..caa7a28a6 100644 --- a/osu.Framework/Platform/DesktopGameHost.cs +++ b/osu.Framework/Platform/DesktopGameHost.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using System.Diagnostics; using System.IO; diff --git a/osu.Framework/Platform/DesktopStorage.cs b/osu.Framework/Platform/DesktopStorage.cs index f82e1b96f..3665994dd 100644 --- a/osu.Framework/Platform/DesktopStorage.cs +++ b/osu.Framework/Platform/DesktopStorage.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Platform { public class DesktopStorage : NativeStorage diff --git a/osu.Framework/Platform/Display.cs b/osu.Framework/Platform/Display.cs index 66171bdea..97784159a 100644 --- a/osu.Framework/Platform/Display.cs +++ b/osu.Framework/Platform/Display.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Drawing; using System.Linq; diff --git a/osu.Framework/Platform/DisplayMode.cs b/osu.Framework/Platform/DisplayMode.cs index d662fd9cf..6a45dcaca 100644 --- a/osu.Framework/Platform/DisplayMode.cs +++ b/osu.Framework/Platform/DisplayMode.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Drawing; diff --git a/osu.Framework/Platform/ExecutionMode.cs b/osu.Framework/Platform/ExecutionMode.cs index 79d93513d..d87b6442d 100644 --- a/osu.Framework/Platform/ExecutionMode.cs +++ b/osu.Framework/Platform/ExecutionMode.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.ComponentModel; namespace osu.Framework.Platform diff --git a/osu.Framework/Platform/FlushingStream.cs b/osu.Framework/Platform/FlushingStream.cs index 17f9f12c4..ea399527b 100644 --- a/osu.Framework/Platform/FlushingStream.cs +++ b/osu.Framework/Platform/FlushingStream.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.IO; namespace osu.Framework.Platform diff --git a/osu.Framework/Platform/GameHost.cs b/osu.Framework/Platform/GameHost.cs index ebb1dce2e..6edf2c843 100644 --- a/osu.Framework/Platform/GameHost.cs +++ b/osu.Framework/Platform/GameHost.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Collections.Immutable; @@ -22,6 +24,7 @@ using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Configuration; using osu.Framework.Development; +using osu.Framework.Extensions.ExceptionExtensions; using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -50,6 +53,12 @@ namespace osu.Framework.Platform { public IWindow Window { get; private set; } + /// + /// Whether "unlimited" frame limiter should be allowed to exceed sane limits. + /// Only use this for benchmarking purposes (see for further reasoning). + /// + public bool AllowBenchmarkUnlimitedFrames { get; set; } + protected FrameworkDebugConfigManager DebugConfig { get; private set; } protected FrameworkConfigManager Config { get; private set; } @@ -85,9 +94,12 @@ namespace osu.Framework.Platform public event Action Deactivated; /// - /// Called when the host is requesting to exit. Return true to block the exit process. + /// Invoked when an exit was requested. Always invoked from the update thread. /// - public event Func Exiting; + /// + /// Usually invoked when the window close (X) button or another platform-native exit action has been pressed. + /// + public event Action ExitRequested; public event Action Exited; @@ -327,8 +339,13 @@ namespace osu.Framework.Platform private void unobservedExceptionHandler(object sender, UnobservedTaskExceptionEventArgs args) { + var actualException = args.Exception.AsSingular(); + // unobserved exceptions are logged but left unhandled (most of the time they are not intended to be critical). - logException(args.Exception, "unobserved"); + logException(actualException, "unobserved"); + + if (DebugUtils.IsNUnitRunning) + abortExecutionFromException(sender, actualException, false); } private void logException(Exception exception, string type) @@ -395,30 +412,7 @@ namespace osu.Framework.Platform protected virtual void OnDeactivated() => UpdateThread.Scheduler.Add(() => Deactivated?.Invoke()); - /// true to cancel - protected virtual bool OnExitRequested() - { - if (ExecutionState <= ExecutionState.Stopping) return false; - - bool? response = null; - - UpdateThread.Scheduler.Add(delegate { response = Exiting?.Invoke() == true; }); - - //wait for a potentially blocking response - while (!response.HasValue) - { - if (ThreadSafety.ExecutionMode == ExecutionMode.SingleThread) - threadRunner.RunMainLoop(); - else - Thread.Sleep(1); - } - - if (response.Value) - return true; - - Exit(); - return false; - } + protected void OnExitRequested() => UpdateThread.Scheduler.Add(() => ExitRequested?.Invoke()); protected virtual void OnExited() { @@ -453,12 +447,10 @@ namespace osu.Framework.Platform Root.UpdateSubTree(); Root.UpdateSubTreeMasking(Root, Root.ScreenSpaceDrawQuad.AABBFloat); - using (var buffer = DrawRoots.Get(UsageType.Write)) + using (var buffer = DrawRoots.GetForWrite()) buffer.Object = Root.GenerateDrawNodeSubtree(frameCount, buffer.Index, false); } - private long lastDrawFrameId; - private readonly DepthValue depthValue = new DepthValue(); protected virtual void DrawFrame() @@ -466,64 +458,60 @@ namespace osu.Framework.Platform if (Root == null) return; - while (ExecutionState == ExecutionState.Running) + if (ExecutionState != ExecutionState.Running) + return; + + ObjectUsage buffer; + + using (drawMonitor.BeginCollecting(PerformanceCollectionType.Sleep)) + buffer = DrawRoots.GetForRead(); + + if (buffer == null) + return; + + try { - using (var buffer = DrawRoots.Get(UsageType.Read)) + using (drawMonitor.BeginCollecting(PerformanceCollectionType.GLReset)) + GLWrapper.Reset(new Vector2(Window.ClientSize.Width, Window.ClientSize.Height)); + + if (!bypassFrontToBackPass.Value) { - if (buffer?.Object == null || buffer.FrameId == lastDrawFrameId) - { - // if a buffer is not available in single threaded mode there's no point in looping. - // in the general case this should never happen, but may occur during exception handling. - if (executionMode.Value == ExecutionMode.SingleThread) - break; + depthValue.Reset(); - using (drawMonitor.BeginCollecting(PerformanceCollectionType.Sleep)) - Thread.Sleep(1); + GL.ColorMask(false, false, false, false); + GLWrapper.SetBlend(BlendingParameters.None); + GLWrapper.PushDepthInfo(DepthInfo.Default); - continue; - } - - using (drawMonitor.BeginCollecting(PerformanceCollectionType.GLReset)) - GLWrapper.Reset(new Vector2(Window.ClientSize.Width, Window.ClientSize.Height)); - - if (!bypassFrontToBackPass.Value) - { - depthValue.Reset(); - - GL.ColorMask(false, false, false, false); - GLWrapper.SetBlend(BlendingParameters.None); - GLWrapper.PushDepthInfo(DepthInfo.Default); - - // Front pass - buffer.Object.DrawOpaqueInteriorSubTree(depthValue, null); - - GLWrapper.PopDepthInfo(); - GL.ColorMask(true, true, true, true); - - // The back pass doesn't write depth, but needs to depth test properly - GLWrapper.PushDepthInfo(new DepthInfo(true, false)); - } - else - { - // Disable depth testing - GLWrapper.PushDepthInfo(new DepthInfo()); - } - - // Back pass - buffer.Object.Draw(null); + // Front pass + buffer.Object.DrawOpaqueInteriorSubTree(depthValue, null); GLWrapper.PopDepthInfo(); + GL.ColorMask(true, true, true, true); - lastDrawFrameId = buffer.FrameId; - break; + // The back pass doesn't write depth, but needs to depth test properly + GLWrapper.PushDepthInfo(new DepthInfo(true, false)); + } + else + { + // Disable depth testing + GLWrapper.PushDepthInfo(new DepthInfo()); + } + + // Back pass + buffer.Object.Draw(null); + + GLWrapper.PopDepthInfo(); + + GLWrapper.FlushCurrentBatch(); + + using (drawMonitor.BeginCollecting(PerformanceCollectionType.SwapBuffer)) + { + Swap(); } } - - GLWrapper.FlushCurrentBatch(); - - using (drawMonitor.BeginCollecting(PerformanceCollectionType.SwapBuffer)) + finally { - Swap(); + buffer.Dispose(); } } @@ -568,7 +556,9 @@ namespace osu.Framework.Platform }); // this is required as attempting to use a TaskCompletionSource blocks the thread calling SetResult on some configurations. - await Task.Run(completionEvent.Wait).ConfigureAwait(false); + // ReSharper disable once AccessToDisposedClosure + if (!await Task.Run(() => completionEvent.Wait(5000)).ConfigureAwait(false)) + throw new TimeoutException("Screenshot data did not arrive in a timely fashion"); var image = Image.LoadPixelData(pixelData.Memory.Span, width, height); image.Mutate(c => c.Flip(FlipMode.Vertical)); @@ -758,7 +748,7 @@ namespace osu.Framework.Platform break; case OsuTKWindow tkWindow: - tkWindow.UpdateFrame += (o, e) => windowUpdate(); + tkWindow.UpdateFrame += (_, _) => windowUpdate(); break; } @@ -1015,7 +1005,24 @@ namespace osu.Framework.Platform threadLocale = Config.GetBindable(FrameworkSetting.Locale); threadLocale.BindValueChanged(locale => { - var culture = CultureInfo.GetCultures(CultureTypes.AllCultures).FirstOrDefault(c => c.Name.Equals(locale.NewValue, StringComparison.OrdinalIgnoreCase)) ?? CultureInfo.InvariantCulture; + CultureInfo culture; + + try + { + // After dropping netstandard we can use `predefinedOnly` override. + // See https://github.com/dotnet/runtime/pull/1261/files + culture = CultureInfo.GetCultureInfo(locale.NewValue); + + // This is best-effort for now to catch cases where dotnet is creating cultures. + // See https://github.com/dotnet/runtime/blob/5877e8b713742b6d80bd1aa9819094be029e3e1f/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.Icu.cs#L341-L345 + if (culture.ThreeLetterWindowsLanguageName == "ZZZ") + culture = CultureInfo.InvariantCulture; + } + catch (Exception e) + { + Logger.Log($"Culture for {locale.NewValue} could not be found ({e})"); + culture = CultureInfo.InvariantCulture; + } CultureInfo.DefaultThreadCurrentCulture = culture; CultureInfo.DefaultThreadCurrentUICulture = culture; @@ -1026,19 +1033,34 @@ namespace osu.Framework.Platform inputConfig = new InputConfigManager(Storage, AvailableInputHandlers); } + /// + /// Games using osu!framework can generally run at *very* high frame rates when not much is going on. + /// + /// This can be counter-productive due to the induced allocation and GPU overhead. + /// - Allocation overhead can lead to excess garbage collection + /// - GPU overhead can lead to unexpected pipeline blocking (and stutters as a result). + /// Also, in general graphics card manufacturers do not test their hardware at insane frame rates and + /// therefore drivers are not optimised to handle this kind of throughput. + /// - We only harvest input at 1000hz, so running any higher has zero benefits. + /// + /// We limit things to the same rate we poll input at, to keep both gamers and their systems happy + /// and (more) stutter-free. + /// + private const int maximum_sane_fps = GameThread.DEFAULT_ACTIVE_HZ; + private void updateFrameSyncMode() { if (Window == null) return; - float refreshRate = Window.CurrentDisplayMode.Value.RefreshRate; + int refreshRate = Window.CurrentDisplayMode.Value.RefreshRate; // For invalid refresh rates let's assume 60 Hz as it is most common. if (refreshRate <= 0) refreshRate = 60; - float drawLimiter = refreshRate; - float updateLimiter = drawLimiter * 2; + int drawLimiter = refreshRate; + int updateLimiter = drawLimiter * 2; setVSyncMode(); @@ -1065,10 +1087,17 @@ namespace osu.Framework.Platform break; case FrameSync.Unlimited: - drawLimiter = updateLimiter = int.MaxValue; + drawLimiter = int.MaxValue; + updateLimiter = int.MaxValue; break; } + if (!AllowBenchmarkUnlimitedFrames) + { + drawLimiter = Math.Min(maximum_sane_fps, drawLimiter); + updateLimiter = Math.Min(maximum_sane_fps, updateLimiter); + } + MaximumDrawHz = drawLimiter; MaximumUpdateHz = updateLimiter; } @@ -1110,7 +1139,9 @@ namespace osu.Framework.Platform case ExecutionState.Stopping: case ExecutionState.Stopped: // Delay disposal until the game has exited - stoppedEvent.Wait(); + if (!stoppedEvent.Wait(60000)) + throw new InvalidOperationException("Game stuck in runnning state."); + break; } diff --git a/osu.Framework/Platform/HeadlessGameHost.cs b/osu.Framework/Platform/HeadlessGameHost.cs index 67739168f..d90851a30 100644 --- a/osu.Framework/Platform/HeadlessGameHost.cs +++ b/osu.Framework/Platform/HeadlessGameHost.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using osu.Framework.Configuration; diff --git a/osu.Framework/Platform/IGraphicsBackend.cs b/osu.Framework/Platform/IGraphicsBackend.cs index c6fbc8ef9..8fc246ae5 100644 --- a/osu.Framework/Platform/IGraphicsBackend.cs +++ b/osu.Framework/Platform/IGraphicsBackend.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Platform { /// diff --git a/osu.Framework/Platform/IIpcHost.cs b/osu.Framework/Platform/IIpcHost.cs index dc27d8e4b..5d9aaa55b 100644 --- a/osu.Framework/Platform/IIpcHost.cs +++ b/osu.Framework/Platform/IIpcHost.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Threading.Tasks; diff --git a/osu.Framework/Platform/IWindow.cs b/osu.Framework/Platform/IWindow.cs index 32f85e17c..9b4ece1ec 100644 --- a/osu.Framework/Platform/IWindow.cs +++ b/osu.Framework/Platform/IWindow.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Drawing; @@ -33,10 +35,10 @@ namespace osu.Framework.Platform void Create(); /// - /// Return value decides whether we should intercept and cancel this exit (if possible). + /// Invoked when the window close (X) button or another platform-native exit action has been pressed. /// [CanBeNull] - event Func ExitRequested; + event Action ExitRequested; /// /// Invoked when the has closed. @@ -148,11 +150,6 @@ namespace osu.Framework.Platform /// void Close(); - /// - /// Attempts to close the window. - /// - void RequestClose(); - /// /// Start the window's run loop. /// Is a blocking call on desktop platforms, and a non-blocking call on mobile platforms. diff --git a/osu.Framework/Platform/IpcChannel.cs b/osu.Framework/Platform/IpcChannel.cs index 243d68d8d..ec28ba1ee 100644 --- a/osu.Framework/Platform/IpcChannel.cs +++ b/osu.Framework/Platform/IpcChannel.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Threading.Tasks; diff --git a/osu.Framework/Platform/IpcMessage.cs b/osu.Framework/Platform/IpcMessage.cs index 6a5904689..159d4dc83 100644 --- a/osu.Framework/Platform/IpcMessage.cs +++ b/osu.Framework/Platform/IpcMessage.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Platform { public class IpcMessage diff --git a/osu.Framework/Platform/Linux/LinuxGameHost.cs b/osu.Framework/Platform/Linux/LinuxGameHost.cs index 4ff97f230..8d90d4b95 100644 --- a/osu.Framework/Platform/Linux/LinuxGameHost.cs +++ b/osu.Framework/Platform/Linux/LinuxGameHost.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.IO; diff --git a/osu.Framework/Platform/Linux/LinuxReadableKeyCombinationProvider.cs b/osu.Framework/Platform/Linux/LinuxReadableKeyCombinationProvider.cs index 89c010dbe..5f400e1d7 100644 --- a/osu.Framework/Platform/Linux/LinuxReadableKeyCombinationProvider.cs +++ b/osu.Framework/Platform/Linux/LinuxReadableKeyCombinationProvider.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.Bindings; using osu.Framework.Platform.SDL2; using SDL2; diff --git a/osu.Framework/Platform/Linux/Native/Library.cs b/osu.Framework/Platform/Linux/Native/Library.cs index c35617cda..169125fd0 100644 --- a/osu.Framework/Platform/Linux/Native/Library.cs +++ b/osu.Framework/Platform/Linux/Native/Library.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Diagnostics; using System.IO; diff --git a/osu.Framework/Platform/Linux/SDL2/SDL2Clipboard.cs b/osu.Framework/Platform/Linux/SDL2/SDL2Clipboard.cs index 6e05833af..9d4fb2f3a 100644 --- a/osu.Framework/Platform/Linux/SDL2/SDL2Clipboard.cs +++ b/osu.Framework/Platform/Linux/SDL2/SDL2Clipboard.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using SDL2; using SixLabors.ImageSharp; diff --git a/osu.Framework/Platform/MacOS/MacOSClipboard.cs b/osu.Framework/Platform/MacOS/MacOSClipboard.cs index 07d08d927..aeaf575eb 100644 --- a/osu.Framework/Platform/MacOS/MacOSClipboard.cs +++ b/osu.Framework/Platform/MacOS/MacOSClipboard.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Platform.MacOS.Native; using SixLabors.ImageSharp; diff --git a/osu.Framework/Platform/MacOS/MacOSGameHost.cs b/osu.Framework/Platform/MacOS/MacOSGameHost.cs index 1a5808b78..ac5ac2d29 100644 --- a/osu.Framework/Platform/MacOS/MacOSGameHost.cs +++ b/osu.Framework/Platform/MacOS/MacOSGameHost.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.IO; diff --git a/osu.Framework/Platform/MacOS/MacOSReadableKeyCombinationProvider.cs b/osu.Framework/Platform/MacOS/MacOSReadableKeyCombinationProvider.cs index 8dd85efed..20362c33e 100644 --- a/osu.Framework/Platform/MacOS/MacOSReadableKeyCombinationProvider.cs +++ b/osu.Framework/Platform/MacOS/MacOSReadableKeyCombinationProvider.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.Bindings; using osu.Framework.Platform.SDL2; using SDL2; diff --git a/osu.Framework/Platform/MacOS/MacOSWindow.cs b/osu.Framework/Platform/MacOS/MacOSWindow.cs index b9aeea5a9..da86bd60c 100644 --- a/osu.Framework/Platform/MacOS/MacOSWindow.cs +++ b/osu.Framework/Platform/MacOS/MacOSWindow.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Platform.MacOS.Native; using osuTK; @@ -51,7 +53,8 @@ namespace osu.Framework.Platform.MacOS } // according to osuTK, 0.1f is the scaling factor expected to be returned by CGEventSourceGetPixelsPerLine - const float scale_factor = 0.1f; + // this is additionally scaled down by a factor of 8 so that a precise scroll of 1.0 is roughly equivalent to one notch on a traditional scroll wheel. + const float scale_factor = 0.1f / 8; float scrollingDeltaX = Cocoa.SendFloat(theEvent, sel_scrollingdeltax); float scrollingDeltaY = Cocoa.SendFloat(theEvent, sel_scrollingdeltay); diff --git a/osu.Framework/Platform/MacOS/Native/Class.cs b/osu.Framework/Platform/MacOS/Native/Class.cs index 4cd0784ab..2d6ce3e4f 100644 --- a/osu.Framework/Platform/MacOS/Native/Class.cs +++ b/osu.Framework/Platform/MacOS/Native/Class.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Runtime.InteropServices; diff --git a/osu.Framework/Platform/MacOS/Native/Cocoa.cs b/osu.Framework/Platform/MacOS/Native/Cocoa.cs index 750408b00..adf6b5940 100644 --- a/osu.Framework/Platform/MacOS/Native/Cocoa.cs +++ b/osu.Framework/Platform/MacOS/Native/Cocoa.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.IO; using System.Runtime.InteropServices; diff --git a/osu.Framework/Platform/MacOS/Native/NSArray.cs b/osu.Framework/Platform/MacOS/Native/NSArray.cs index 6e7c62f83..db3d9ca41 100644 --- a/osu.Framework/Platform/MacOS/Native/NSArray.cs +++ b/osu.Framework/Platform/MacOS/Native/NSArray.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; namespace osu.Framework.Platform.MacOS.Native diff --git a/osu.Framework/Platform/MacOS/Native/NSData.cs b/osu.Framework/Platform/MacOS/Native/NSData.cs index 4ad24b8fe..3e1a3b4e4 100644 --- a/osu.Framework/Platform/MacOS/Native/NSData.cs +++ b/osu.Framework/Platform/MacOS/Native/NSData.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Runtime.InteropServices; diff --git a/osu.Framework/Platform/MacOS/Native/NSDictionary.cs b/osu.Framework/Platform/MacOS/Native/NSDictionary.cs index 095761c95..5e819602b 100644 --- a/osu.Framework/Platform/MacOS/Native/NSDictionary.cs +++ b/osu.Framework/Platform/MacOS/Native/NSDictionary.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; namespace osu.Framework.Platform.MacOS.Native diff --git a/osu.Framework/Platform/MacOS/Native/NSNotificationCenter.cs b/osu.Framework/Platform/MacOS/Native/NSNotificationCenter.cs index e7e6206b3..6a517c6f8 100644 --- a/osu.Framework/Platform/MacOS/Native/NSNotificationCenter.cs +++ b/osu.Framework/Platform/MacOS/Native/NSNotificationCenter.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; namespace osu.Framework.Platform.MacOS.Native diff --git a/osu.Framework/Platform/MacOS/Native/NSPasteboard.cs b/osu.Framework/Platform/MacOS/Native/NSPasteboard.cs index c24d203e8..c16c07275 100644 --- a/osu.Framework/Platform/MacOS/Native/NSPasteboard.cs +++ b/osu.Framework/Platform/MacOS/Native/NSPasteboard.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; namespace osu.Framework.Platform.MacOS.Native @@ -31,7 +33,7 @@ namespace osu.Framework.Platform.MacOS.Native internal NSArray? ReadObjectsForClasses(NSArray classArray, NSDictionary? optionDict) { var result = Cocoa.SendIntPtr(Handle, sel_read_objects_for_classes, classArray.Handle, optionDict?.Handle ?? IntPtr.Zero); - return result == IntPtr.Zero ? (NSArray?)null : new NSArray(result); + return result == IntPtr.Zero ? null : new NSArray(result); } internal bool WriteObjects(NSArray objects) => Cocoa.SendBool(Handle, sel_write_objects, objects.Handle); diff --git a/osu.Framework/Platform/MacOS/Native/NSStringEncoding.cs b/osu.Framework/Platform/MacOS/Native/NSStringEncoding.cs index 3fe8a98fa..82faffc2e 100644 --- a/osu.Framework/Platform/MacOS/Native/NSStringEncoding.cs +++ b/osu.Framework/Platform/MacOS/Native/NSStringEncoding.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Platform.MacOS.Native { public enum NSStringEncoding : uint diff --git a/osu.Framework/Platform/MacOS/Native/Selector.cs b/osu.Framework/Platform/MacOS/Native/Selector.cs index 286a1171d..4be2f2114 100644 --- a/osu.Framework/Platform/MacOS/Native/Selector.cs +++ b/osu.Framework/Platform/MacOS/Native/Selector.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Runtime.InteropServices; diff --git a/osu.Framework/Platform/MonoPInvokeCallbackAttribute.cs b/osu.Framework/Platform/MonoPInvokeCallbackAttribute.cs index 060075a8b..6269d2211 100644 --- a/osu.Framework/Platform/MonoPInvokeCallbackAttribute.cs +++ b/osu.Framework/Platform/MonoPInvokeCallbackAttribute.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Runtime.CompilerServices; diff --git a/osu.Framework/Platform/NativeMemoryTracker.cs b/osu.Framework/Platform/NativeMemoryTracker.cs index 077ae2fa4..4b91d6523 100644 --- a/osu.Framework/Platform/NativeMemoryTracker.cs +++ b/osu.Framework/Platform/NativeMemoryTracker.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Allocation; using osu.Framework.Statistics; diff --git a/osu.Framework/Platform/NativeStorage.cs b/osu.Framework/Platform/NativeStorage.cs index fbe5aa020..70f86f7d1 100644 --- a/osu.Framework/Platform/NativeStorage.cs +++ b/osu.Framework/Platform/NativeStorage.cs @@ -1,11 +1,14 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.IO; using System.Linq; using JetBrains.Annotations; +using osu.Framework.Utils; namespace osu.Framework.Platform { @@ -40,6 +43,13 @@ namespace osu.Framework.Platform File.Delete(path); } + public override void Move(string from, string to) + { + // Retry move operations as it can fail on windows intermittently with IOExceptions: + // The process cannot access the file because it is being used by another process. + General.AttemptWithRetryOnException(() => File.Move(GetFullPath(from), GetFullPath(to))); + } + public override IEnumerable GetDirectories(string path) => getRelativePaths(Directory.GetDirectories(GetFullPath(path))); public override IEnumerable GetFiles(string path, string pattern = "*") => getRelativePaths(Directory.GetFiles(GetFullPath(path), pattern)); diff --git a/osu.Framework/Platform/OsuTKGameHost.cs b/osu.Framework/Platform/OsuTKGameHost.cs index bc3953655..86e01bdbf 100644 --- a/osu.Framework/Platform/OsuTKGameHost.cs +++ b/osu.Framework/Platform/OsuTKGameHost.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osuTK; namespace osu.Framework.Platform diff --git a/osu.Framework/Platform/OsuTKWindow.cs b/osu.Framework/Platform/OsuTKWindow.cs index ea575ee17..cf32216b7 100644 --- a/osu.Framework/Platform/OsuTKWindow.cs +++ b/osu.Framework/Platform/OsuTKWindow.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; @@ -31,10 +33,9 @@ namespace osu.Framework.Platform public abstract IGraphicsContext Context { get; } /// - /// Return value decides whether we should intercept and cancel this exit (if possible). + /// Invoked when the window close (X) button or another platform-native exit action has been pressed. /// - [CanBeNull] - public event Func ExitRequested; + public event Action ExitRequested; /// /// Invoked when the has closed. @@ -112,22 +113,28 @@ namespace osu.Framework.Platform // Moving or resizing the window needs to check to see if we've moved to a different display. // This will update the CurrentDisplay bindable. - Move += (sender, e) => checkCurrentDisplay(); - Resize += (sender, e) => + Move += (_, _) => checkCurrentDisplay(); + Resize += (_, _) => { checkCurrentDisplay(); Resized?.Invoke(); }; - Closing += (sender, e) => e.Cancel = ExitRequested?.Invoke() ?? false; - Closed += (sender, e) => Exited?.Invoke(); + Closing += (_, e) => + { + // always block a graceful exit as it's treated as a regular window event. + // the host will force-close the window if the game decides not to block the exit. + ExitRequested?.Invoke(); + e.Cancel = true; + }; + Closed += (_, _) => Exited?.Invoke(); - MouseEnter += (sender, args) => cursorInWindow.Value = true; - MouseLeave += (sender, args) => cursorInWindow.Value = false; + MouseEnter += (_, _) => cursorInWindow.Value = true; + MouseLeave += (_, _) => cursorInWindow.Value = false; supportedWindowModes.AddRange(DefaultSupportedWindowModes); - UpdateFrame += (o, e) => UpdateFrameScheduler.Update(); + UpdateFrame += (_, _) => UpdateFrameScheduler.Update(); MakeCurrent(); @@ -428,12 +435,6 @@ namespace osu.Framework.Platform public void Close() => OsuTKGameWindow.Close(); - public void RequestClose() - { - if (ExitRequested?.Invoke() != true) - Close(); - } - public void ProcessEvents() => OsuTKGameWindow.ProcessEvents(); public Point PointToClient(Point point) => OsuTKGameWindow.PointToClient(point); public Point PointToScreen(Point point) => OsuTKGameWindow.PointToScreen(point); diff --git a/osu.Framework/Platform/PassthroughGraphicsBackend.cs b/osu.Framework/Platform/PassthroughGraphicsBackend.cs index ffcc65ebe..c3df322c2 100644 --- a/osu.Framework/Platform/PassthroughGraphicsBackend.cs +++ b/osu.Framework/Platform/PassthroughGraphicsBackend.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Diagnostics; using System.Linq; diff --git a/osu.Framework/Platform/SDL2/SDL2ControllerBindings.cs b/osu.Framework/Platform/SDL2/SDL2ControllerBindings.cs index f5c483692..5690229cc 100644 --- a/osu.Framework/Platform/SDL2/SDL2ControllerBindings.cs +++ b/osu.Framework/Platform/SDL2/SDL2ControllerBindings.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Linq; using SDL2; diff --git a/osu.Framework/Platform/SDL2/SDL2Extensions.cs b/osu.Framework/Platform/SDL2/SDL2Extensions.cs index 47f66b006..727fe44ca 100644 --- a/osu.Framework/Platform/SDL2/SDL2Extensions.cs +++ b/osu.Framework/Platform/SDL2/SDL2Extensions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Drawing; using System.Runtime.InteropServices; @@ -1019,5 +1021,68 @@ namespace osu.Framework.Platform.SDL2 SDL.SDL_PixelFormatEnumToMasks(mode.format, out int bpp, out _, out _, out _, out _); return new DisplayMode(SDL.SDL_GetPixelFormatName(mode.format), new Size(mode.w, mode.h), bpp, mode.refresh_rate, displayIndex); } + + public static string ReadableName(this SDL.SDL_LogCategory category) + { + switch (category) + { + case SDL.SDL_LogCategory.SDL_LOG_CATEGORY_APPLICATION: + return "application"; + + case SDL.SDL_LogCategory.SDL_LOG_CATEGORY_ERROR: + return "error"; + + case SDL.SDL_LogCategory.SDL_LOG_CATEGORY_ASSERT: + return "assert"; + + case SDL.SDL_LogCategory.SDL_LOG_CATEGORY_SYSTEM: + return "system"; + + case SDL.SDL_LogCategory.SDL_LOG_CATEGORY_AUDIO: + return "audio"; + + case SDL.SDL_LogCategory.SDL_LOG_CATEGORY_VIDEO: + return "video"; + + case SDL.SDL_LogCategory.SDL_LOG_CATEGORY_RENDER: + return "render"; + + case SDL.SDL_LogCategory.SDL_LOG_CATEGORY_INPUT: + return "input"; + + case SDL.SDL_LogCategory.SDL_LOG_CATEGORY_TEST: + return "test"; + + default: + return "unknown"; + } + } + + public static string ReadableName(this SDL.SDL_LogPriority priority) + { + switch (priority) + { + case SDL.SDL_LogPriority.SDL_LOG_PRIORITY_VERBOSE: + return "verbose"; + + case SDL.SDL_LogPriority.SDL_LOG_PRIORITY_DEBUG: + return "debug"; + + case SDL.SDL_LogPriority.SDL_LOG_PRIORITY_INFO: + return "info"; + + case SDL.SDL_LogPriority.SDL_LOG_PRIORITY_WARN: + return "warn"; + + case SDL.SDL_LogPriority.SDL_LOG_PRIORITY_ERROR: + return "error"; + + case SDL.SDL_LogPriority.SDL_LOG_PRIORITY_CRITICAL: + return "critical"; + + default: + return "unknown"; + } + } } } diff --git a/osu.Framework/Platform/SDL2/SDL2GraphicsBackend.cs b/osu.Framework/Platform/SDL2/SDL2GraphicsBackend.cs index 9eee8692d..b2fb5a10d 100644 --- a/osu.Framework/Platform/SDL2/SDL2GraphicsBackend.cs +++ b/osu.Framework/Platform/SDL2/SDL2GraphicsBackend.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using SDL2; @@ -39,7 +41,21 @@ namespace osu.Framework.Platform.SDL2 public override void SwapBuffers() => SDL.SDL_GL_SwapWindow(sdlWindowHandle); - protected override IntPtr GetProcAddress(string symbol) => SDL.SDL_GL_GetProcAddress(symbol); + protected override IntPtr GetProcAddress(string symbol) + { + const int error_category = (int)SDL.SDL_LogCategory.SDL_LOG_CATEGORY_ERROR; + SDL.SDL_LogPriority oldPriority = SDL.SDL_LogGetPriority(error_category); + + // Prevent logging calls to SDL_GL_GetProcAddress() that fail on systems which don't have the requested symbol (typically macOS). + SDL.SDL_LogSetPriority(error_category, SDL.SDL_LogPriority.SDL_LOG_PRIORITY_INFO); + + IntPtr ret = SDL.SDL_GL_GetProcAddress(symbol); + + // Reset the logging behaviour. + SDL.SDL_LogSetPriority(error_category, oldPriority); + + return ret; + } public override void Initialise(IWindow window) { diff --git a/osu.Framework/Platform/SDL2/SDL2ReadableKeyCombinationProvider.cs b/osu.Framework/Platform/SDL2/SDL2ReadableKeyCombinationProvider.cs index 5038d07f8..855688f4a 100644 --- a/osu.Framework/Platform/SDL2/SDL2ReadableKeyCombinationProvider.cs +++ b/osu.Framework/Platform/SDL2/SDL2ReadableKeyCombinationProvider.cs @@ -1,6 +1,9 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + +using System.Globalization; using osu.Framework.Input; using osu.Framework.Input.Bindings; using SDL2; @@ -36,7 +39,10 @@ namespace osu.Framework.Platform.SDL2 // SDL_GetKeyName() returned a unicode character that would be produced if that key was pressed. // consumers expect an uppercase letter. - return name.ToUpper(); + // `.ToUpper()` with current culture may be slightly inaccurate if the framework locale + // is different from the locale of the keyboard layout being used, + // but we have no means to detect this anyway, as SDL doesn't provide the name of the layout. + return name.ToUpper(CultureInfo.CurrentCulture); } /// diff --git a/osu.Framework/Platform/SDL2/SDL2Structs.cs b/osu.Framework/Platform/SDL2/SDL2Structs.cs index 5cb09608d..4950ee822 100644 --- a/osu.Framework/Platform/SDL2/SDL2Structs.cs +++ b/osu.Framework/Platform/SDL2/SDL2Structs.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Runtime.InteropServices; using SDL2; diff --git a/osu.Framework/Platform/SDL2DesktopWindow.cs b/osu.Framework/Platform/SDL2DesktopWindow.cs index 197c64ec1..589acabec 100644 --- a/osu.Framework/Platform/SDL2DesktopWindow.cs +++ b/osu.Framework/Platform/SDL2DesktopWindow.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.IO; @@ -435,9 +437,29 @@ namespace osu.Framework.Platform private readonly BindableDouble windowPositionY = new BindableDouble(); private readonly Bindable windowDisplayIndexBindable = new Bindable(); + // references must be kept to avoid GC, see https://stackoverflow.com/a/6193914 + + [UsedImplicitly] + private SDL.SDL_LogOutputFunction logOutputDelegate; + + [UsedImplicitly] + private SDL.SDL_EventFilter eventFilterDelegate; + public SDL2DesktopWindow() { - SDL.SDL_Init(SDL.SDL_INIT_VIDEO | SDL.SDL_INIT_GAMECONTROLLER); + if (SDL.SDL_Init(SDL.SDL_INIT_VIDEO | SDL.SDL_INIT_GAMECONTROLLER) < 0) + { + throw new InvalidOperationException($"Failed to initialise SDL: {SDL.SDL_GetError()}"); + } + + SDL.SDL_LogSetPriority((int)SDL.SDL_LogCategory.SDL_LOG_CATEGORY_ERROR, SDL.SDL_LogPriority.SDL_LOG_PRIORITY_DEBUG); + SDL.SDL_LogSetOutputFunction(logOutputDelegate = (_, categoryInt, priority, messagePtr) => + { + var category = (SDL.SDL_LogCategory)categoryInt; + string message = Marshal.PtrToStringUTF8(messagePtr); + + Logger.Log($@"SDL {category.ReadableName()} log [{priority.ReadableName()}]: {message}"); + }, IntPtr.Zero); graphicsBackend = CreateGraphicsBackend(); @@ -509,10 +531,6 @@ namespace osu.Framework.Platform WindowMode.TriggerChange(); } - // reference must be kept to avoid GC, see https://stackoverflow.com/a/6193914 - [UsedImplicitly] - private SDL.SDL_EventFilter eventFilterDelegate; - /// /// Starts the window's run loop. /// @@ -585,15 +603,6 @@ namespace osu.Framework.Platform /// public void Close() => ScheduleCommand(() => Exists = false); - /// - /// Attempts to close the window. - /// - public void RequestClose() => ScheduleEvent(() => - { - if (ExitRequested?.Invoke() != true) - Close(); - }); - public void SwapBuffers() { graphicsBackend.SwapBuffers(); @@ -620,7 +629,7 @@ namespace osu.Framework.Platform { // SDL reports axis values in the range short.MinValue to short.MaxValue, so we scale and clamp it to the range of -1f to 1f float clamped = Math.Clamp((float)axisValue / short.MaxValue, -1f, 1f); - JoystickAxisChanged?.Invoke(new JoystickAxis(axisSource, clamped)); + JoystickAxisChanged?.Invoke(axisSource, clamped); } private void enqueueJoystickButtonInput(JoystickButton button, bool isPressed) @@ -815,7 +824,7 @@ namespace osu.Framework.Platform } } - private void handleQuitEvent(SDL.SDL_QuitEvent evtQuit) => RequestClose(); + private void handleQuitEvent(SDL.SDL_QuitEvent evtQuit) => ExitRequested?.Invoke(); private void handleDropEvent(SDL.SDL_DropEvent evtDrop) { @@ -958,8 +967,22 @@ namespace osu.Framework.Platform enqueueJoystickAxisInput(JoystickAxisSource.Axis1 + evtJaxis.axis, evtJaxis.axisValue); } - private void handleMouseWheelEvent(SDL.SDL_MouseWheelEvent evtWheel) => - TriggerMouseWheel(new Vector2(evtWheel.x, evtWheel.y), false); + private uint lastPreciseScroll; + + private const uint precise_scroll_debounce = 100; + + private void handleMouseWheelEvent(SDL.SDL_MouseWheelEvent evtWheel) + { + bool isPrecise(float f) => f % 1 != 0; + + if (isPrecise(evtWheel.preciseX) || isPrecise(evtWheel.preciseY)) + lastPreciseScroll = evtWheel.timestamp; + + bool precise = evtWheel.timestamp < lastPreciseScroll + precise_scroll_debounce; + + // SDL reports horizontal scroll opposite of what framework expects (in non-"natural" mode, scrolling to the right gives positive deltas while we want negative). + TriggerMouseWheel(new Vector2(-evtWheel.preciseX, evtWheel.preciseY), precise); + } private void handleMouseButtonEvent(SDL.SDL_MouseButtonEvent evtButton) { @@ -1512,9 +1535,9 @@ namespace osu.Framework.Platform public event Action WindowStateChanged; /// - /// Invoked when the user attempts to close the window. Return value of true will cancel exit. + /// Invoked when the window close (X) button or another platform-native exit action has been pressed. /// - public event Func ExitRequested; + public event Action ExitRequested; /// /// Invoked when the window is about to close. @@ -1539,6 +1562,9 @@ namespace osu.Framework.Platform /// /// Invoked when the user scrolls the mouse wheel over the window. /// + /// + /// Delta is positive when mouse wheel scrolled to the up or left, in non-"natural" scroll mode (ie. the classic way). + /// public event Action MouseWheel; protected void TriggerMouseWheel(Vector2 delta, bool precise) => MouseWheel?.Invoke(delta, precise); @@ -1593,7 +1619,7 @@ namespace osu.Framework.Platform /// /// Invoked when a joystick axis changes. /// - public event Action JoystickAxisChanged; + public event Action JoystickAxisChanged; /// /// Invoked when the user presses a button on a joystick. diff --git a/osu.Framework/Platform/Storage.cs b/osu.Framework/Platform/Storage.cs index 0866982b3..34308ba7b 100644 --- a/osu.Framework/Platform/Storage.cs +++ b/osu.Framework/Platform/Storage.cs @@ -1,8 +1,11 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; +using System.Diagnostics.Contracts; using System.IO; namespace osu.Framework.Platform @@ -98,6 +101,29 @@ namespace osu.Framework.Platform return (Storage)Activator.CreateInstance(GetType(), fullPath); } + /// + /// Move a file from one location to another. File must exist. Destination must not exist. + /// + /// The file path to move. + /// The destination path. + public abstract void Move(string from, string to); + + /// + /// Create a new file on disk, using a temporary file to write to before moving to the final location to ensure a half-written file cannot exist at the specified location. + /// + /// + /// If the target file path already exists, it will be deleted before attempting to write a new version. + /// + /// The path of the file to create or overwrite. + /// A stream associated with the requested path. Will only exist at the specified location after the stream is disposed. + [Pure] + public Stream CreateFileSafely(string path) + { + string temporaryPath = Path.Combine(Path.GetDirectoryName(path), $"_{Path.GetFileName(path)}_{Guid.NewGuid()}"); + + return new SafeWriteStream(temporaryPath, path, this); + } + /// /// Retrieve a stream from an underlying file inside this storage. /// @@ -105,6 +131,7 @@ namespace osu.Framework.Platform /// The access requirements. /// The mode in which the file should be opened. /// A stream associated with the requested path. + [Pure] public abstract Stream GetStream(string path, FileAccess access = FileAccess.Read, FileMode mode = FileMode.OpenOrCreate); /// @@ -129,5 +156,38 @@ namespace osu.Framework.Platform /// Relative path to the file. /// Whether the file was successfully presented. public abstract bool PresentFileExternally(string filename); + + /// + /// Uses a temporary file to ensure a file is written to completion before existing at its specified location. + /// + private class SafeWriteStream : FlushingStream + { + private readonly string temporaryPath; + private readonly string finalPath; + private readonly Storage storage; + + public SafeWriteStream(string temporaryPath, string finalPath, Storage storage) + : base(storage.GetFullPath(temporaryPath, true), FileMode.Create, FileAccess.Write) + { + this.temporaryPath = temporaryPath; + this.finalPath = finalPath; + this.storage = storage; + } + + private bool isDisposed; + + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + + if (!isDisposed) + { + storage.Delete(finalPath); + storage.Move(temporaryPath, finalPath); + + isDisposed = true; + } + } + } } } diff --git a/osu.Framework/Platform/TcpIpcProvider.cs b/osu.Framework/Platform/TcpIpcProvider.cs index 365eb8cdb..1d392193f 100644 --- a/osu.Framework/Platform/TcpIpcProvider.cs +++ b/osu.Framework/Platform/TcpIpcProvider.cs @@ -13,8 +13,6 @@ using Newtonsoft.Json.Linq; using osu.Framework.Extensions; using osu.Framework.Logging; -#nullable enable - namespace osu.Framework.Platform { /// diff --git a/osu.Framework/Platform/ThreadRunner.cs b/osu.Framework/Platform/ThreadRunner.cs index aa14c96e6..15c4eb722 100644 --- a/osu.Framework/Platform/ThreadRunner.cs +++ b/osu.Framework/Platform/ThreadRunner.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. @@ -139,24 +141,28 @@ namespace osu.Framework.Platform { const int thread_join_timeout = 30000; - Threads.ForEach(t => t.Exit()); - Threads.Where(t => t.Running).ForEach(t => + // exit in reverse order so AudioThread is exited last (UpdateThread depends on AudioThread) + Threads.Reverse().ForEach(t => { + // save the native thread to a local variable as Thread gets set to null when exiting. + // WaitForState(Exited) appears to be unsafe in multithreaded. var thread = t.Thread; - if (thread == null) + t.Exit(); + + if (thread != null) { - // has already been cleaned up (or never started) - return; + if (!thread.Join(thread_join_timeout)) + throw new TimeoutException($"Thread {t.Name} failed to exit in allocated time ({thread_join_timeout}ms)."); + } + else + { + t.WaitForState(GameThreadState.Exited); } - if (!thread.Join(thread_join_timeout)) - Logger.Log($"Thread {t.Name} failed to exit in allocated time ({thread_join_timeout}ms).", LoggingTarget.Runtime, LogLevel.Important); + Debug.Assert(t.Exited); }); - // as the input thread isn't actually handled by a thread, the above join does not necessarily mean it has been completed to an exiting state. - mainThread.WaitForState(GameThreadState.Exited); - ThreadSafety.ResetAllForCurrentThread(); } diff --git a/osu.Framework/Platform/WindowState.cs b/osu.Framework/Platform/WindowState.cs index ac06bc64c..923594c68 100644 --- a/osu.Framework/Platform/WindowState.cs +++ b/osu.Framework/Platform/WindowState.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Platform { /// diff --git a/osu.Framework/Platform/Windows/FullscreenCapability.cs b/osu.Framework/Platform/Windows/FullscreenCapability.cs new file mode 100644 index 000000000..076a685fc --- /dev/null +++ b/osu.Framework/Platform/Windows/FullscreenCapability.cs @@ -0,0 +1,25 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +#nullable disable + +namespace osu.Framework.Platform.Windows +{ + public enum FullscreenCapability + { + /// + /// Fullscreen capability is unknown. + /// + Unknown, + + /// + /// Unable to enter exclusive fullscreen. + /// + Incapable, + + /// + /// Able to enter exclusive fullscreen. + /// + Capable + } +} diff --git a/osu.Framework/Platform/Windows/Native/Execution.cs b/osu.Framework/Platform/Windows/Native/Execution.cs index 71dbd3ba0..db65b3707 100644 --- a/osu.Framework/Platform/Windows/Native/Execution.cs +++ b/osu.Framework/Platform/Windows/Native/Execution.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Runtime.InteropServices; diff --git a/osu.Framework/Platform/Windows/Native/Explorer.cs b/osu.Framework/Platform/Windows/Native/Explorer.cs index 593795dac..8b0c6eb6a 100644 --- a/osu.Framework/Platform/Windows/Native/Explorer.cs +++ b/osu.Framework/Platform/Windows/Native/Explorer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.IO; using System.Runtime.InteropServices; diff --git a/osu.Framework/Platform/Windows/Native/Icon.cs b/osu.Framework/Platform/Windows/Native/Icon.cs index 21fd98b71..b5bfba21c 100644 --- a/osu.Framework/Platform/Windows/Native/Icon.cs +++ b/osu.Framework/Platform/Windows/Native/Icon.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Runtime.InteropServices; diff --git a/osu.Framework/Platform/Windows/Native/IconGroup.cs b/osu.Framework/Platform/Windows/Native/IconGroup.cs index 067cb2101..896b13008 100644 --- a/osu.Framework/Platform/Windows/Native/IconGroup.cs +++ b/osu.Framework/Platform/Windows/Native/IconGroup.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.IO; using System.Runtime.InteropServices; using System; diff --git a/osu.Framework/Platform/Windows/Native/Imm.cs b/osu.Framework/Platform/Windows/Native/Imm.cs index 7b9dbf734..cfc72fce9 100644 --- a/osu.Framework/Platform/Windows/Native/Imm.cs +++ b/osu.Framework/Platform/Windows/Native/Imm.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Runtime.InteropServices; using System.Text; diff --git a/osu.Framework/Platform/Windows/Native/Input.cs b/osu.Framework/Platform/Windows/Native/Input.cs index c90ad09c4..4f8569fa7 100644 --- a/osu.Framework/Platform/Windows/Native/Input.cs +++ b/osu.Framework/Platform/Windows/Native/Input.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Drawing; using System.Runtime.InteropServices; diff --git a/osu.Framework/Platform/Windows/TimePeriod.cs b/osu.Framework/Platform/Windows/TimePeriod.cs index c4932409e..51ee3172c 100644 --- a/osu.Framework/Platform/Windows/TimePeriod.cs +++ b/osu.Framework/Platform/Windows/TimePeriod.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Runtime.InteropServices; diff --git a/osu.Framework/Platform/Windows/WindowsClipboard.cs b/osu.Framework/Platform/Windows/WindowsClipboard.cs index 37a6ebef4..f7b0ab7a6 100644 --- a/osu.Framework/Platform/Windows/WindowsClipboard.cs +++ b/osu.Framework/Platform/Windows/WindowsClipboard.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.IO; using System.Linq; diff --git a/osu.Framework/Platform/Windows/WindowsGameHost.cs b/osu.Framework/Platform/Windows/WindowsGameHost.cs index 3790d3f14..81c76fb62 100644 --- a/osu.Framework/Platform/Windows/WindowsGameHost.cs +++ b/osu.Framework/Platform/Windows/WindowsGameHost.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.IO; diff --git a/osu.Framework/Platform/Windows/WindowsMouseHandler.cs b/osu.Framework/Platform/Windows/WindowsMouseHandler.cs index fdfe8f6a9..8d14bbf8b 100644 --- a/osu.Framework/Platform/Windows/WindowsMouseHandler.cs +++ b/osu.Framework/Platform/Windows/WindowsMouseHandler.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Drawing; using osu.Framework.Extensions.EnumExtensions; diff --git a/osu.Framework/Platform/Windows/WindowsReadableKeyCombinationProvider.cs b/osu.Framework/Platform/Windows/WindowsReadableKeyCombinationProvider.cs index a97a06e4d..d3744d3f8 100644 --- a/osu.Framework/Platform/Windows/WindowsReadableKeyCombinationProvider.cs +++ b/osu.Framework/Platform/Windows/WindowsReadableKeyCombinationProvider.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Input.Bindings; using osu.Framework.Platform.SDL2; using SDL2; diff --git a/osu.Framework/Platform/Windows/WindowsWindow.cs b/osu.Framework/Platform/Windows/WindowsWindow.cs index 814ba14a0..96ae4d350 100644 --- a/osu.Framework/Platform/Windows/WindowsWindow.cs +++ b/osu.Framework/Platform/Windows/WindowsWindow.cs @@ -1,11 +1,17 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Drawing; using System.Runtime.InteropServices; +using System.Threading; +using System.Threading.Tasks; using JetBrains.Annotations; +using osu.Framework.Bindables; using osu.Framework.Input.Handlers.Mouse; +using osu.Framework.Logging; using osu.Framework.Platform.SDL2; using osu.Framework.Platform.Windows.Native; using osuTK; @@ -23,6 +29,9 @@ namespace osu.Framework.Platform.Windows private const int large_icon_size = 256; private const int small_icon_size = 16; + public IBindable FullscreenCapability => fullscreenCapability; + private readonly Bindable fullscreenCapability = new Bindable(); + private Icon smallIcon; private Icon largeIcon; @@ -39,6 +48,62 @@ namespace osu.Framework.Platform.Windows { // API doesn't exist on Windows 7 so it needs to be allowed to fail silently. } + + IsActive.BindValueChanged(_ => detectFullscreenCapability(WindowState)); + WindowStateChanged += detectFullscreenCapability; + detectFullscreenCapability(WindowState); + } + + private CancellationTokenSource fullscreenCapabilityDetectionCancellationSource; + + private void detectFullscreenCapability(WindowState state) + { + fullscreenCapabilityDetectionCancellationSource?.Cancel(); + fullscreenCapabilityDetectionCancellationSource?.Dispose(); + fullscreenCapabilityDetectionCancellationSource = null; + + if (state != WindowState.Fullscreen || !IsActive.Value || fullscreenCapability.Value != Windows.FullscreenCapability.Unknown) + return; + + var cancellationSource = fullscreenCapabilityDetectionCancellationSource = new CancellationTokenSource(); + + // 50 attempts, 100ms apart = run the detection for a total of 5 seconds before yielding an incapable state. + const int max_attempts = 50; + const int time_per_attempt = 100; + int attempts = 0; + + queueNextAttempt(); + + void queueNextAttempt() => Task.Delay(time_per_attempt, cancellationSource.Token).ContinueWith(_ => ScheduleEvent(() => + { + if (cancellationSource.IsCancellationRequested || WindowState != WindowState.Fullscreen || !IsActive.Value) + return; + + attempts++; + + try + { + SHQueryUserNotificationState(out var notificationState); + + var capability = notificationState == QueryUserNotificationState.QUNS_RUNNING_D3D_FULL_SCREEN + ? Windows.FullscreenCapability.Capable + : Windows.FullscreenCapability.Incapable; + + if (capability == Windows.FullscreenCapability.Incapable && attempts < max_attempts) + { + queueNextAttempt(); + return; + } + + fullscreenCapability.Value = capability; + Logger.Log($"Exclusive fullscreen capability: {fullscreenCapability.Value} ({notificationState})"); + } + catch (Exception ex) + { + Logger.Error(ex, "Failed to detect fullscreen capabilities."); + fullscreenCapability.Value = Windows.FullscreenCapability.Capable; + } + }), cancellationSource.Token); } public override void Create() @@ -269,5 +334,18 @@ namespace osu.Framework.Platform.Windows [DllImport("user32.dll", CharSet = CharSet.Auto)] private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam); + + [DllImport("shell32.dll")] + private static extern int SHQueryUserNotificationState(out QueryUserNotificationState state); + + private enum QueryUserNotificationState + { + QUNS_NOT_PRESENT = 1, + QUNS_BUSY = 2, + QUNS_RUNNING_D3D_FULL_SCREEN = 3, + QUNS_PRESENTATION_MODE = 4, + QUNS_ACCEPTS_NOTIFICATIONS = 5, + QUNS_QUIET_TIME = 6 + } } } diff --git a/osu.Framework/Properties/AssemblyInfo.cs b/osu.Framework/Properties/AssemblyInfo.cs index 619ff52c3..a11119df5 100644 --- a/osu.Framework/Properties/AssemblyInfo.cs +++ b/osu.Framework/Properties/AssemblyInfo.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Runtime.CompilerServices; #if NET6_0_OR_GREATER using System.Reflection.Metadata; diff --git a/osu.Framework/RuntimeInfo.cs b/osu.Framework/RuntimeInfo.cs index f3fa88233..2206bf37a 100644 --- a/osu.Framework/RuntimeInfo.cs +++ b/osu.Framework/RuntimeInfo.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Diagnostics; using System.Reflection; diff --git a/osu.Framework/Screens/IScreen.cs b/osu.Framework/Screens/IScreen.cs index 63be27b8e..dd3ed0d52 100644 --- a/osu.Framework/Screens/IScreen.cs +++ b/osu.Framework/Screens/IScreen.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Graphics; diff --git a/osu.Framework/Screens/Screen.cs b/osu.Framework/Screens/Screen.cs index 4a7aa85cf..cf4e097b4 100644 --- a/osu.Framework/Screens/Screen.cs +++ b/osu.Framework/Screens/Screen.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Allocation; using osu.Framework.Graphics; diff --git a/osu.Framework/Screens/ScreenExitEvent.cs b/osu.Framework/Screens/ScreenExitEvent.cs index decd3df1e..20767049f 100644 --- a/osu.Framework/Screens/ScreenExitEvent.cs +++ b/osu.Framework/Screens/ScreenExitEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Screens { /// diff --git a/osu.Framework/Screens/ScreenStack.cs b/osu.Framework/Screens/ScreenStack.cs index 1de4eaaee..7db39054f 100644 --- a/osu.Framework/Screens/ScreenStack.cs +++ b/osu.Framework/Screens/ScreenStack.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework/Screens/ScreenTransitionEvent.cs b/osu.Framework/Screens/ScreenTransitionEvent.cs index d0d8fd9f6..55992f748 100644 --- a/osu.Framework/Screens/ScreenTransitionEvent.cs +++ b/osu.Framework/Screens/ScreenTransitionEvent.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Screens { /// diff --git a/osu.Framework/Statistics/BackgroundStackTraceCollector.cs b/osu.Framework/Statistics/BackgroundStackTraceCollector.cs index fe253c531..d1af1f210 100644 --- a/osu.Framework/Statistics/BackgroundStackTraceCollector.cs +++ b/osu.Framework/Statistics/BackgroundStackTraceCollector.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Diagnostics; using System.Linq; @@ -49,7 +51,7 @@ namespace osu.Framework.Statistics logger = new Lazy(() => { - var l = Logger.GetLogger($"performance-{threadName?.ToLower() ?? "unknown"}"); + var l = Logger.GetLogger($"performance-{threadName?.ToLowerInvariant() ?? "unknown"}"); l.OutputToListeners = false; return l; }); diff --git a/osu.Framework/Statistics/DotNetRuntimeListener.cs b/osu.Framework/Statistics/DotNetRuntimeListener.cs index 534467bd1..ba492da21 100644 --- a/osu.Framework/Statistics/DotNetRuntimeListener.cs +++ b/osu.Framework/Statistics/DotNetRuntimeListener.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Diagnostics; using System.Diagnostics.Tracing; diff --git a/osu.Framework/Statistics/FrameStatistics.cs b/osu.Framework/Statistics/FrameStatistics.cs index a8f120ce4..24a8fc3af 100644 --- a/osu.Framework/Statistics/FrameStatistics.cs +++ b/osu.Framework/Statistics/FrameStatistics.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; @@ -28,7 +30,13 @@ namespace osu.Framework.Statistics internal static void Increment(StatisticsCounterType type) => ++COUNTERS[(int)type]; - internal static void Add(StatisticsCounterType type, long amount) => COUNTERS[(int)type] += amount; + internal static void Add(StatisticsCounterType type, long amount) + { + if (amount < 0) + throw new ArgumentException($"Statistics counter {type} was attempted to be decremented via {nameof(Add)} call.", nameof(amount)); + + COUNTERS[(int)type] += amount; + } } internal enum PerformanceCollectionType diff --git a/osu.Framework/Statistics/GlobalStatistic.cs b/osu.Framework/Statistics/GlobalStatistic.cs index c879d0cd8..346372059 100644 --- a/osu.Framework/Statistics/GlobalStatistic.cs +++ b/osu.Framework/Statistics/GlobalStatistic.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Statistics { public class GlobalStatistic : IGlobalStatistic diff --git a/osu.Framework/Statistics/GlobalStatistics.cs b/osu.Framework/Statistics/GlobalStatistics.cs index ef882f94f..90b8f56f4 100644 --- a/osu.Framework/Statistics/GlobalStatistics.cs +++ b/osu.Framework/Statistics/GlobalStatistics.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Specialized; using System.Linq; diff --git a/osu.Framework/Statistics/IGlobalStatistic.cs b/osu.Framework/Statistics/IGlobalStatistic.cs index e7b4b4cc0..aeee8bd99 100644 --- a/osu.Framework/Statistics/IGlobalStatistic.cs +++ b/osu.Framework/Statistics/IGlobalStatistic.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Statistics { public interface IGlobalStatistic diff --git a/osu.Framework/Statistics/PerformanceMonitor.cs b/osu.Framework/Statistics/PerformanceMonitor.cs index 0330d4936..31144545c 100644 --- a/osu.Framework/Statistics/PerformanceMonitor.cs +++ b/osu.Framework/Statistics/PerformanceMonitor.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Concurrent; using System.Collections.Generic; diff --git a/osu.Framework/Statistics/TypePerformanceMonitor.cs b/osu.Framework/Statistics/TypePerformanceMonitor.cs index 253e68c2c..8bbf88dd4 100644 --- a/osu.Framework/Statistics/TypePerformanceMonitor.cs +++ b/osu.Framework/Statistics/TypePerformanceMonitor.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework/Testing/Dependencies/CachedNullableProvider.cs b/osu.Framework/Testing/Dependencies/CachedNullableProvider.cs index dd3225a74..d09d9c42a 100644 --- a/osu.Framework/Testing/Dependencies/CachedNullableProvider.cs +++ b/osu.Framework/Testing/Dependencies/CachedNullableProvider.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Allocation; namespace osu.Framework.Testing.Dependencies diff --git a/osu.Framework/Testing/Dependencies/CachedStructProvider.cs b/osu.Framework/Testing/Dependencies/CachedStructProvider.cs index 25e5ca5c8..454ddcdc0 100644 --- a/osu.Framework/Testing/Dependencies/CachedStructProvider.cs +++ b/osu.Framework/Testing/Dependencies/CachedStructProvider.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Allocation; namespace osu.Framework.Testing.Dependencies diff --git a/osu.Framework/Testing/DrawFrameRecordingContainer.cs b/osu.Framework/Testing/DrawFrameRecordingContainer.cs index 9f5639cd5..e3799200b 100644 --- a/osu.Framework/Testing/DrawFrameRecordingContainer.cs +++ b/osu.Framework/Testing/DrawFrameRecordingContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using JetBrains.Annotations; using osu.Framework.Allocation; diff --git a/osu.Framework/Testing/Drawables/Sections/ToolbarAssemblySection.cs b/osu.Framework/Testing/Drawables/Sections/ToolbarAssemblySection.cs index 8d5d4ddc2..b4f73e5a8 100644 --- a/osu.Framework/Testing/Drawables/Sections/ToolbarAssemblySection.cs +++ b/osu.Framework/Testing/Drawables/Sections/ToolbarAssemblySection.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Linq; using System.Reflection; using osu.Framework.Allocation; diff --git a/osu.Framework/Testing/Drawables/Sections/ToolbarRateSection.cs b/osu.Framework/Testing/Drawables/Sections/ToolbarRateSection.cs index 3c85fa259..9b23445db 100644 --- a/osu.Framework/Testing/Drawables/Sections/ToolbarRateSection.cs +++ b/osu.Framework/Testing/Drawables/Sections/ToolbarRateSection.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework/Testing/Drawables/Sections/ToolbarRecordSection.cs b/osu.Framework/Testing/Drawables/Sections/ToolbarRecordSection.cs index 87aa2f2fb..0e23d93e3 100644 --- a/osu.Framework/Testing/Drawables/Sections/ToolbarRecordSection.cs +++ b/osu.Framework/Testing/Drawables/Sections/ToolbarRecordSection.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; diff --git a/osu.Framework/Testing/Drawables/Steps/AssertButton.cs b/osu.Framework/Testing/Drawables/Steps/AssertButton.cs index 6ea0d8040..d31b5c2f0 100644 --- a/osu.Framework/Testing/Drawables/Steps/AssertButton.cs +++ b/osu.Framework/Testing/Drawables/Steps/AssertButton.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Diagnostics; using osuTK.Graphics; diff --git a/osu.Framework/Testing/Drawables/Steps/LabelStep.cs b/osu.Framework/Testing/Drawables/Steps/LabelStep.cs index f951fc62c..3341ee16e 100644 --- a/osu.Framework/Testing/Drawables/Steps/LabelStep.cs +++ b/osu.Framework/Testing/Drawables/Steps/LabelStep.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osuTK.Graphics; namespace osu.Framework.Testing.Drawables.Steps diff --git a/osu.Framework/Testing/Drawables/Steps/RepeatStepButton.cs b/osu.Framework/Testing/Drawables/Steps/RepeatStepButton.cs index 5d48b8e40..333e19f6d 100644 --- a/osu.Framework/Testing/Drawables/Steps/RepeatStepButton.cs +++ b/osu.Framework/Testing/Drawables/Steps/RepeatStepButton.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; namespace osu.Framework.Testing.Drawables.Steps diff --git a/osu.Framework/Testing/Drawables/Steps/SingleStepButton.cs b/osu.Framework/Testing/Drawables/Steps/SingleStepButton.cs index 03dd65ada..36bba8e2d 100644 --- a/osu.Framework/Testing/Drawables/Steps/SingleStepButton.cs +++ b/osu.Framework/Testing/Drawables/Steps/SingleStepButton.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; namespace osu.Framework.Testing.Drawables.Steps diff --git a/osu.Framework/Testing/Drawables/Steps/StepButton.cs b/osu.Framework/Testing/Drawables/Steps/StepButton.cs index ca72cd311..62d45221d 100644 --- a/osu.Framework/Testing/Drawables/Steps/StepButton.cs +++ b/osu.Framework/Testing/Drawables/Steps/StepButton.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework/Testing/Drawables/Steps/StepSlider.cs b/osu.Framework/Testing/Drawables/Steps/StepSlider.cs index 2380a7690..aaa041664 100644 --- a/osu.Framework/Testing/Drawables/Steps/StepSlider.cs +++ b/osu.Framework/Testing/Drawables/Steps/StepSlider.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osuTK.Graphics; using osu.Framework.Graphics; using osu.Framework.Graphics.Shapes; diff --git a/osu.Framework/Testing/Drawables/Steps/ToggleStepButton.cs b/osu.Framework/Testing/Drawables/Steps/ToggleStepButton.cs index 1682e3c8d..782a10e01 100644 --- a/osu.Framework/Testing/Drawables/Steps/ToggleStepButton.cs +++ b/osu.Framework/Testing/Drawables/Steps/ToggleStepButton.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Graphics; using osuTK.Graphics; diff --git a/osu.Framework/Testing/Drawables/Steps/UntilStepButton.cs b/osu.Framework/Testing/Drawables/Steps/UntilStepButton.cs index 043ff8d24..81585d2ff 100644 --- a/osu.Framework/Testing/Drawables/Steps/UntilStepButton.cs +++ b/osu.Framework/Testing/Drawables/Steps/UntilStepButton.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Diagnostics; using osu.Framework.Graphics; @@ -14,7 +16,7 @@ namespace osu.Framework.Testing.Drawables.Steps private int invocations; - private const int max_attempt_milliseconds = 10000; + private static readonly int max_attempt_milliseconds = Environment.GetEnvironmentVariable("OSU_TESTS_NO_TIMEOUT") == "1" ? int.MaxValue : 10000; public override int RequiredRepetitions => success ? 0 : int.MaxValue; diff --git a/osu.Framework/Testing/Drawables/TestBrowserToolbar.cs b/osu.Framework/Testing/Drawables/TestBrowserToolbar.cs index bf1825371..03620aa67 100644 --- a/osu.Framework/Testing/Drawables/TestBrowserToolbar.cs +++ b/osu.Framework/Testing/Drawables/TestBrowserToolbar.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Reflection; using osu.Framework.Allocation; using osu.Framework.Graphics; diff --git a/osu.Framework/Testing/Drawables/TestButton.cs b/osu.Framework/Testing/Drawables/TestButton.cs index 9c75c7a5a..3a9b8ffd1 100644 --- a/osu.Framework/Testing/Drawables/TestButton.cs +++ b/osu.Framework/Testing/Drawables/TestButton.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Allocation; using osu.Framework.Graphics; diff --git a/osu.Framework/Testing/Drawables/TestButtonBase.cs b/osu.Framework/Testing/Drawables/TestButtonBase.cs index d06c2561a..40bfd173b 100644 --- a/osu.Framework/Testing/Drawables/TestButtonBase.cs +++ b/osu.Framework/Testing/Drawables/TestButtonBase.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.ComponentModel; @@ -8,6 +10,7 @@ using System.Linq; using System.Reflection; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Localisation; using osuTK.Graphics; using Container = osu.Framework.Graphics.Containers.Container; @@ -15,7 +18,7 @@ namespace osu.Framework.Testing.Drawables { internal abstract class TestButtonBase : ClickableContainer, IFilterable { - public IEnumerable FilterTerms => text.Children.OfType().SelectMany(c => c.FilterTerms); + public IEnumerable FilterTerms => text.Children.OfType().SelectMany(c => c.FilterTerms); private bool matchingFilter = true; diff --git a/osu.Framework/Testing/Drawables/TestGroup.cs b/osu.Framework/Testing/Drawables/TestGroup.cs index a383a9878..5c100ebe7 100644 --- a/osu.Framework/Testing/Drawables/TestGroup.cs +++ b/osu.Framework/Testing/Drawables/TestGroup.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; namespace osu.Framework.Testing.Drawables diff --git a/osu.Framework/Testing/Drawables/TestGroupButton.cs b/osu.Framework/Testing/Drawables/TestGroupButton.cs index 19ce7d12a..26fd6eb68 100644 --- a/osu.Framework/Testing/Drawables/TestGroupButton.cs +++ b/osu.Framework/Testing/Drawables/TestGroupButton.cs @@ -1,9 +1,12 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Localisation; using System.Collections.Generic; using System.Linq; using osu.Framework.Extensions.IEnumerableExtensions; @@ -12,7 +15,7 @@ namespace osu.Framework.Testing.Drawables { internal class TestGroupButton : VisibilityContainer, IHasFilterableChildren { - public IEnumerable FilterTerms => headerButton?.FilterTerms ?? Enumerable.Empty(); + public IEnumerable FilterTerms => headerButton?.FilterTerms ?? Enumerable.Empty(); public bool MatchingFilter { diff --git a/osu.Framework/Testing/Drawables/TestSubButton.cs b/osu.Framework/Testing/Drawables/TestSubButton.cs index 16c272ef1..74c66ec07 100644 --- a/osu.Framework/Testing/Drawables/TestSubButton.cs +++ b/osu.Framework/Testing/Drawables/TestSubButton.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using osu.Framework.Allocation; using osu.Framework.Graphics; diff --git a/osu.Framework/Testing/Drawables/ToolbarSection.cs b/osu.Framework/Testing/Drawables/ToolbarSection.cs index 4ef540a7c..d5eb85d50 100644 --- a/osu.Framework/Testing/Drawables/ToolbarSection.cs +++ b/osu.Framework/Testing/Drawables/ToolbarSection.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.Containers; namespace osu.Framework.Testing.Drawables diff --git a/osu.Framework/Testing/ExcludeFromDynamicCompileAttribute.cs b/osu.Framework/Testing/ExcludeFromDynamicCompileAttribute.cs index ab1c0eb56..c4eb4fa31 100644 --- a/osu.Framework/Testing/ExcludeFromDynamicCompileAttribute.cs +++ b/osu.Framework/Testing/ExcludeFromDynamicCompileAttribute.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; namespace osu.Framework.Testing diff --git a/osu.Framework/Testing/GridTestScene.cs b/osu.Framework/Testing/GridTestScene.cs index 3ea90fa19..cf1aa431e 100644 --- a/osu.Framework/Testing/GridTestScene.cs +++ b/osu.Framework/Testing/GridTestScene.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework/Testing/HeadlessTestAttribute.cs b/osu.Framework/Testing/HeadlessTestAttribute.cs index 554268152..40ea956be 100644 --- a/osu.Framework/Testing/HeadlessTestAttribute.cs +++ b/osu.Framework/Testing/HeadlessTestAttribute.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using JetBrains.Annotations; diff --git a/osu.Framework/Testing/HotReloadCallbackReceiver.cs b/osu.Framework/Testing/HotReloadCallbackReceiver.cs index c30f66d55..affd262c8 100644 --- a/osu.Framework/Testing/HotReloadCallbackReceiver.cs +++ b/osu.Framework/Testing/HotReloadCallbackReceiver.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using JetBrains.Annotations; diff --git a/osu.Framework/Testing/Input/ManualInputManager.cs b/osu.Framework/Testing/Input/ManualInputManager.cs index d61968032..25a90d9f6 100644 --- a/osu.Framework/Testing/Input/ManualInputManager.cs +++ b/osu.Framework/Testing/Input/ManualInputManager.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Linq; using System; using osu.Framework.Graphics; diff --git a/osu.Framework/Testing/Input/TestCursorContainer.cs b/osu.Framework/Testing/Input/TestCursorContainer.cs index 2e760f052..6c288ec24 100644 --- a/osu.Framework/Testing/Input/TestCursorContainer.cs +++ b/osu.Framework/Testing/Input/TestCursorContainer.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Linq; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -146,8 +148,7 @@ namespace osu.Framework.Testing.Input protected override bool OnScroll(ScrollEvent e) { - var delta = new Vector2(e.ScrollDelta.X, -e.ScrollDelta.Y); - circle.MoveTo(circle.Position + delta * 10).MoveTo(Vector2.Zero, 500, Easing.OutQuint); + circle.MoveTo(circle.Position - e.ScrollDelta * 10).MoveTo(Vector2.Zero, 500, Easing.OutQuint); return base.OnScroll(e); } diff --git a/osu.Framework/Testing/ManualInputManagerTestScene.cs b/osu.Framework/Testing/ManualInputManagerTestScene.cs index 81b3b28e2..efb6d4d56 100644 --- a/osu.Framework/Testing/ManualInputManagerTestScene.cs +++ b/osu.Framework/Testing/ManualInputManagerTestScene.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using NUnit.Framework; using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Graphics; diff --git a/osu.Framework/Testing/MenuTestScene.cs b/osu.Framework/Testing/MenuTestScene.cs index dd0f87840..2d4140fff 100644 --- a/osu.Framework/Testing/MenuTestScene.cs +++ b/osu.Framework/Testing/MenuTestScene.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/osu.Framework/Testing/SetUpStepsAttribute.cs b/osu.Framework/Testing/SetUpStepsAttribute.cs index f3d33b7a1..08a50a357 100644 --- a/osu.Framework/Testing/SetUpStepsAttribute.cs +++ b/osu.Framework/Testing/SetUpStepsAttribute.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using JetBrains.Annotations; diff --git a/osu.Framework/Testing/TearDownStepsAttribute.cs b/osu.Framework/Testing/TearDownStepsAttribute.cs index 37cab3054..d608d36fe 100644 --- a/osu.Framework/Testing/TearDownStepsAttribute.cs +++ b/osu.Framework/Testing/TearDownStepsAttribute.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using JetBrains.Annotations; diff --git a/osu.Framework/Testing/TemporaryNativeStorage.cs b/osu.Framework/Testing/TemporaryNativeStorage.cs index 5b05bb3ec..34a72c37e 100644 --- a/osu.Framework/Testing/TemporaryNativeStorage.cs +++ b/osu.Framework/Testing/TemporaryNativeStorage.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.IO; using osu.Framework.Platform; diff --git a/osu.Framework/Testing/TestBrowser.cs b/osu.Framework/Testing/TestBrowser.cs index f52a4f0cf..746535a21 100644 --- a/osu.Framework/Testing/TestBrowser.cs +++ b/osu.Framework/Testing/TestBrowser.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections; using System.Collections.Generic; @@ -246,7 +248,7 @@ namespace osu.Framework.Testing toolbar.AddAssembly(asm.GetName().Name, asm); Assembly.BindValueChanged(updateList); - RunAllSteps.BindValueChanged(v => runTests(null)); + RunAllSteps.BindValueChanged(_ => runTests(null)); PlaybackRate.BindValueChanged(e => { rateAdjustClock.Rate = e.NewValue; diff --git a/osu.Framework/Testing/TestBrowserConfig.cs b/osu.Framework/Testing/TestBrowserConfig.cs index e5d86ac2c..e28106f3d 100644 --- a/osu.Framework/Testing/TestBrowserConfig.cs +++ b/osu.Framework/Testing/TestBrowserConfig.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Configuration; using osu.Framework.Platform; diff --git a/osu.Framework/Testing/TestBrowserTestRunner.cs b/osu.Framework/Testing/TestBrowserTestRunner.cs index 3b8d5942f..f998e805f 100644 --- a/osu.Framework/Testing/TestBrowserTestRunner.cs +++ b/osu.Framework/Testing/TestBrowserTestRunner.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Linq; using osu.Framework.Allocation; diff --git a/osu.Framework/Testing/TestRunHeadlessGameHost.cs b/osu.Framework/Testing/TestRunHeadlessGameHost.cs index cf43e7b6c..880114163 100644 --- a/osu.Framework/Testing/TestRunHeadlessGameHost.cs +++ b/osu.Framework/Testing/TestRunHeadlessGameHost.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.IO; diff --git a/osu.Framework/Testing/TestScene.cs b/osu.Framework/Testing/TestScene.cs index 2930ab774..dc6be20a8 100644 --- a/osu.Framework/Testing/TestScene.cs +++ b/osu.Framework/Testing/TestScene.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Diagnostics; using System.Linq; @@ -421,6 +423,13 @@ namespace osu.Framework.Testing checkForErrors(); runner.RunTestBlocking(this); checkForErrors(); + + if (Environment.GetEnvironmentVariable("OSU_TESTS_FORCED_GC") == "1") + { + // Force any unobserved exceptions to fire against the current test run. + // Without this they could be delayed until a future test scene is running, making tracking down the cause difficult. + collectAndFireUnobserved(); + } } [OneTimeTearDown] @@ -456,6 +465,12 @@ namespace osu.Framework.Testing throw runTask.Exception; } + private static void collectAndFireUnobserved() + { + GC.Collect(); + GC.WaitForPendingFinalizers(); + } + private class TestSceneHost : TestRunHeadlessGameHost { private readonly Action onExitRequest; diff --git a/osu.Framework/Testing/TestSceneTestRunner.cs b/osu.Framework/Testing/TestSceneTestRunner.cs index 312a40b68..87ad16b96 100644 --- a/osu.Framework/Testing/TestSceneTestRunner.cs +++ b/osu.Framework/Testing/TestSceneTestRunner.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Diagnostics; using System.Runtime.ExceptionServices; using System.Threading; diff --git a/osu.Framework/Testing/TestingExtensions.cs b/osu.Framework/Testing/TestingExtensions.cs index 9c6210002..7c79f430f 100644 --- a/osu.Framework/Testing/TestingExtensions.cs +++ b/osu.Framework/Testing/TestingExtensions.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; diff --git a/osu.Framework/Text/CharacterGlyph.cs b/osu.Framework/Text/CharacterGlyph.cs index 3812a1dbd..9d17aaa7a 100644 --- a/osu.Framework/Text/CharacterGlyph.cs +++ b/osu.Framework/Text/CharacterGlyph.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Runtime.CompilerServices; using JetBrains.Annotations; using osu.Framework.IO.Stores; diff --git a/osu.Framework/Text/ICharacterGlyph.cs b/osu.Framework/Text/ICharacterGlyph.cs index ba198225e..939a269b6 100644 --- a/osu.Framework/Text/ICharacterGlyph.cs +++ b/osu.Framework/Text/ICharacterGlyph.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Text { /// diff --git a/osu.Framework/Text/ITexturedCharacterGlyph.cs b/osu.Framework/Text/ITexturedCharacterGlyph.cs index 8ef4064d0..f6b6bf2eb 100644 --- a/osu.Framework/Text/ITexturedCharacterGlyph.cs +++ b/osu.Framework/Text/ITexturedCharacterGlyph.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Graphics.Textures; namespace osu.Framework.Text diff --git a/osu.Framework/Text/ITexturedGlyphLookupStore.cs b/osu.Framework/Text/ITexturedGlyphLookupStore.cs index 66a41c88b..2d45f5229 100644 --- a/osu.Framework/Text/ITexturedGlyphLookupStore.cs +++ b/osu.Framework/Text/ITexturedGlyphLookupStore.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Threading.Tasks; namespace osu.Framework.Text diff --git a/osu.Framework/Text/MultilineTextBuilder.cs b/osu.Framework/Text/MultilineTextBuilder.cs index da21e4f7f..193c6f792 100644 --- a/osu.Framework/Text/MultilineTextBuilder.cs +++ b/osu.Framework/Text/MultilineTextBuilder.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using osu.Framework.Graphics.Sprites; using osuTK; diff --git a/osu.Framework/Text/TextBuilder.cs b/osu.Framework/Text/TextBuilder.cs index 7b9b4b1d8..322717458 100644 --- a/osu.Framework/Text/TextBuilder.cs +++ b/osu.Framework/Text/TextBuilder.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using osu.Framework.Caching; @@ -221,7 +223,7 @@ namespace osu.Framework.Text return; TextBuilderGlyph removedCharacter = Characters[^1]; - TextBuilderGlyph? previousCharacter = Characters.Count == 1 ? null : (TextBuilderGlyph?)Characters[^2]; + TextBuilderGlyph? previousCharacter = Characters.Count == 1 ? null : Characters[^2]; Characters.RemoveAt(Characters.Count - 1); diff --git a/osu.Framework/Text/TextBuilderGlyph.cs b/osu.Framework/Text/TextBuilderGlyph.cs index 1394218df..0298d5c9d 100644 --- a/osu.Framework/Text/TextBuilderGlyph.cs +++ b/osu.Framework/Text/TextBuilderGlyph.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Runtime.CompilerServices; using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Textures; diff --git a/osu.Framework/Text/TexturedCharacterGlyph.cs b/osu.Framework/Text/TexturedCharacterGlyph.cs index 0a88e8915..e37d533d1 100644 --- a/osu.Framework/Text/TexturedCharacterGlyph.cs +++ b/osu.Framework/Text/TexturedCharacterGlyph.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Runtime.CompilerServices; using osu.Framework.Graphics.Textures; diff --git a/osu.Framework/Text/TruncatingTextBuilder.cs b/osu.Framework/Text/TruncatingTextBuilder.cs index c2fc2f9cf..4750ee9c7 100644 --- a/osu.Framework/Text/TruncatingTextBuilder.cs +++ b/osu.Framework/Text/TruncatingTextBuilder.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System.Collections.Generic; using osu.Framework.Graphics.Sprites; using osuTK; diff --git a/osu.Framework/Threading/AudioThread.cs b/osu.Framework/Threading/AudioThread.cs index 0a1626a6d..5874b87d3 100644 --- a/osu.Framework/Threading/AudioThread.cs +++ b/osu.Framework/Threading/AudioThread.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Statistics; using System; using System.Collections.Generic; diff --git a/osu.Framework/Threading/DrawThread.cs b/osu.Framework/Threading/DrawThread.cs index a03482445..fd80b8007 100644 --- a/osu.Framework/Threading/DrawThread.cs +++ b/osu.Framework/Threading/DrawThread.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Statistics; using System; using System.Collections.Generic; diff --git a/osu.Framework/Threading/GameThread.cs b/osu.Framework/Threading/GameThread.cs index 20b7a184d..af4dc2638 100644 --- a/osu.Framework/Threading/GameThread.cs +++ b/osu.Framework/Threading/GameThread.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Diagnostics; @@ -20,8 +22,8 @@ namespace osu.Framework.Threading /// public class GameThread { - internal const double DEFAULT_ACTIVE_HZ = 1000; - internal const double DEFAULT_INACTIVE_HZ = 60; + internal const int DEFAULT_ACTIVE_HZ = 1000; + internal const int DEFAULT_INACTIVE_HZ = 60; /// /// The name of this thread. @@ -344,6 +346,8 @@ namespace osu.Framework.Threading while (state.Value != targetState) Thread.Sleep(1); } + + Debug.Assert(state.Value == targetState); } /// @@ -490,6 +494,8 @@ namespace osu.Framework.Threading Monitor?.Dispose(); initializedEvent?.Dispose(); + synchronizationContext.DisassociateGameThread(); + OnExit(); break; } diff --git a/osu.Framework/Threading/GameThreadScheduler.cs b/osu.Framework/Threading/GameThreadScheduler.cs index 36031bed8..9d93c7006 100644 --- a/osu.Framework/Threading/GameThreadScheduler.cs +++ b/osu.Framework/Threading/GameThreadScheduler.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Threading { internal class GameThreadScheduler : Scheduler diff --git a/osu.Framework/Threading/GameThreadState.cs b/osu.Framework/Threading/GameThreadState.cs index f0f182048..0130da46c 100644 --- a/osu.Framework/Threading/GameThreadState.cs +++ b/osu.Framework/Threading/GameThreadState.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Platform; namespace osu.Framework.Threading diff --git a/osu.Framework/Threading/GameThreadSynchronizationContext.cs b/osu.Framework/Threading/GameThreadSynchronizationContext.cs index f41faf1c3..9f22ffb11 100644 --- a/osu.Framework/Threading/GameThreadSynchronizationContext.cs +++ b/osu.Framework/Threading/GameThreadSynchronizationContext.cs @@ -1,11 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Diagnostics; using System.Threading; -#nullable enable - namespace osu.Framework.Threading { /// @@ -24,9 +21,9 @@ namespace osu.Framework.Threading /// /// The total tasks this synchronization context has run. /// - public int TotalTasksRun => scheduler.TotalTasksRun; + public int TotalTasksRun => scheduler?.TotalTasksRun ?? 0; - private readonly Scheduler scheduler; + private Scheduler? scheduler; public GameThreadSynchronizationContext(GameThread gameThread) { @@ -35,24 +32,39 @@ namespace osu.Framework.Threading public override void Send(SendOrPostCallback callback, object? state) { - var scheduledDelegate = scheduler.Add(() => callback(state)); + var scheduledDelegate = scheduler?.Add(() => callback(state)); - Debug.Assert(scheduledDelegate != null); + if (scheduledDelegate == null) + return; while (scheduledDelegate.State < ScheduledDelegate.RunState.Complete) { - if (scheduler.IsMainThread) - scheduler.Update(); + var runScheduler = scheduler; + + if (runScheduler == null) + return; + + if (runScheduler.IsMainThread) + runScheduler.Update(); else Thread.Sleep(1); } } - public override void Post(SendOrPostCallback callback, object? state) => scheduler.Add(() => callback(state)); + public override void Post(SendOrPostCallback callback, object? state) => scheduler?.Add(() => callback(state)); /// /// Run any pending work queued against this synchronization context. /// - public void RunWork() => scheduler.Update(); + public void RunWork() => scheduler?.Update(); + + /// + /// Disassociate any references to the provided at construction time. + /// This ensures external components cannot hold a reference to potentially expensive game instances. + /// + public void DisassociateGameThread() + { + scheduler = null; + } } } diff --git a/osu.Framework/Threading/InputThread.cs b/osu.Framework/Threading/InputThread.cs index 1598a4ae5..c8c303fab 100644 --- a/osu.Framework/Threading/InputThread.cs +++ b/osu.Framework/Threading/InputThread.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Statistics; using System.Collections.Generic; using osu.Framework.Development; diff --git a/osu.Framework/Threading/ScheduledDelegate.cs b/osu.Framework/Threading/ScheduledDelegate.cs index b96909709..a383e27e2 100644 --- a/osu.Framework/Threading/ScheduledDelegate.cs +++ b/osu.Framework/Threading/ScheduledDelegate.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Diagnostics; @@ -35,7 +37,7 @@ namespace osu.Framework.Threading /// public bool Cancelled => State == RunState.Cancelled; - public RunState State; + public RunState State { get; private set; } /// /// The work task. diff --git a/osu.Framework/Threading/ScheduledDelegateWithData.cs b/osu.Framework/Threading/ScheduledDelegateWithData.cs index 2fa39f8b4..dbd4ab353 100644 --- a/osu.Framework/Threading/ScheduledDelegateWithData.cs +++ b/osu.Framework/Threading/ScheduledDelegateWithData.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; namespace osu.Framework.Threading diff --git a/osu.Framework/Threading/Scheduler.cs b/osu.Framework/Threading/Scheduler.cs index d67fa780c..112172bc8 100644 --- a/osu.Framework/Threading/Scheduler.cs +++ b/osu.Framework/Threading/Scheduler.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Generic; using System.Linq; @@ -98,20 +100,29 @@ namespace osu.Framework.Threading /// Run any pending work tasks. /// /// The number of tasks that were run. - public virtual int Update() + public int Update() { - lock (queueLock) + bool hasTimedTasks = timedTasks.Count > 0; + bool hasPerUpdateTasks = perUpdateTasks.Count > 0; + + if (hasTimedTasks || hasPerUpdateTasks) // avoid taking out a lock if there are no items. { - queueTimedTasks(); - queuePerUpdateTasks(); + lock (queueLock) + { + queueTimedTasks(); + queuePerUpdateTasks(); + } } int countToRun = runQueue.Count; + + if (countToRun == 0) + return 0; // avoid taking out a lock via getNextTask() if there are no items. + int countRun = 0; while (getNextTask(out ScheduledDelegate sd)) { - //todo: error handling sd.RunTaskInternal(); TotalTasksRun++; @@ -125,10 +136,11 @@ namespace osu.Framework.Threading private void queueTimedTasks() { - double currentTimeLocal = currentTime; - - if (timedTasks.Count > 0) + // Already checked before this method is called, but helps with path prediction? + if (timedTasks.Count != 0) { + double currentTimeLocal = currentTime; + foreach (var sd in timedTasks) { if (sd.ExecutionTime <= currentTimeLocal) @@ -172,19 +184,23 @@ namespace osu.Framework.Threading private void queuePerUpdateTasks() { - for (int i = 0; i < perUpdateTasks.Count; i++) + // Already checked before this method is called, but helps with path prediction? + if (perUpdateTasks.Count != 0) { - ScheduledDelegate task = perUpdateTasks[i]; - - task.SetNextExecution(null); - - if (task.Cancelled) + for (int i = 0; i < perUpdateTasks.Count; i++) { - perUpdateTasks.RemoveAt(i--); - continue; - } + ScheduledDelegate task = perUpdateTasks[i]; - enqueue(task); + task.SetNextExecution(null); + + if (task.Cancelled) + { + perUpdateTasks.RemoveAt(i--); + continue; + } + + enqueue(task); + } } } diff --git a/osu.Framework/Threading/ThreadedTaskScheduler.cs b/osu.Framework/Threading/ThreadedTaskScheduler.cs index 1d8aa1474..3b454feb9 100644 --- a/osu.Framework/Threading/ThreadedTaskScheduler.cs +++ b/osu.Framework/Threading/ThreadedTaskScheduler.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -41,7 +43,7 @@ namespace osu.Framework.Threading this.name = name; tasks = new BlockingCollection(); - threads = Enumerable.Range(0, numberOfThreads).Select(i => + threads = Enumerable.Range(0, numberOfThreads).Select(_ => { var thread = new Thread(processTasks) { diff --git a/osu.Framework/Threading/UpdateThread.cs b/osu.Framework/Threading/UpdateThread.cs index 706be30ac..e716a98e2 100644 --- a/osu.Framework/Threading/UpdateThread.cs +++ b/osu.Framework/Threading/UpdateThread.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Statistics; using System; using System.Collections.Generic; diff --git a/osu.Framework/Timing/DecoupleableInterpolatingFramedClock.cs b/osu.Framework/Timing/DecoupleableInterpolatingFramedClock.cs index 1c2e87d2e..cf39f60eb 100644 --- a/osu.Framework/Timing/DecoupleableInterpolatingFramedClock.cs +++ b/osu.Framework/Timing/DecoupleableInterpolatingFramedClock.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using System; namespace osu.Framework.Timing diff --git a/osu.Framework/Timing/FrameTimeInfo.cs b/osu.Framework/Timing/FrameTimeInfo.cs index c8c289a91..7c7a86ec8 100644 --- a/osu.Framework/Timing/FrameTimeInfo.cs +++ b/osu.Framework/Timing/FrameTimeInfo.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using System; using System.Globalization; diff --git a/osu.Framework/Timing/FramedClock.cs b/osu.Framework/Timing/FramedClock.cs index 174800407..5f754521a 100644 --- a/osu.Framework/Timing/FramedClock.cs +++ b/osu.Framework/Timing/FramedClock.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using osu.Framework.Extensions.TypeExtensions; using System; diff --git a/osu.Framework/Timing/FramedOffsetClock.cs b/osu.Framework/Timing/FramedOffsetClock.cs index b7dfdb27c..aa1f838b9 100644 --- a/osu.Framework/Timing/FramedOffsetClock.cs +++ b/osu.Framework/Timing/FramedOffsetClock.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - namespace osu.Framework.Timing { /// diff --git a/osu.Framework/Timing/IAdjustableClock.cs b/osu.Framework/Timing/IAdjustableClock.cs index 548ca4d74..38e91a6e5 100644 --- a/osu.Framework/Timing/IAdjustableClock.cs +++ b/osu.Framework/Timing/IAdjustableClock.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Timing { /// diff --git a/osu.Framework/Timing/IClock.cs b/osu.Framework/Timing/IClock.cs index c17b9c5f2..ba8eb5dd9 100644 --- a/osu.Framework/Timing/IClock.cs +++ b/osu.Framework/Timing/IClock.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Timing { /// diff --git a/osu.Framework/Timing/IFrameBasedClock.cs b/osu.Framework/Timing/IFrameBasedClock.cs index 996974a9c..a03d782a6 100644 --- a/osu.Framework/Timing/IFrameBasedClock.cs +++ b/osu.Framework/Timing/IFrameBasedClock.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Timing { /// diff --git a/osu.Framework/Timing/ISourceChangeableClock.cs b/osu.Framework/Timing/ISourceChangeableClock.cs index fd27d9910..f8cf9568d 100644 --- a/osu.Framework/Timing/ISourceChangeableClock.cs +++ b/osu.Framework/Timing/ISourceChangeableClock.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Timing { /// diff --git a/osu.Framework/Timing/InterpolatingFramedClock.cs b/osu.Framework/Timing/InterpolatingFramedClock.cs index ca3786b7a..29e5e80cc 100644 --- a/osu.Framework/Timing/InterpolatingFramedClock.cs +++ b/osu.Framework/Timing/InterpolatingFramedClock.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using System; namespace osu.Framework.Timing diff --git a/osu.Framework/Timing/ManualClock.cs b/osu.Framework/Timing/ManualClock.cs index c40145ff3..5ab366520 100644 --- a/osu.Framework/Timing/ManualClock.cs +++ b/osu.Framework/Timing/ManualClock.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Timing { /// diff --git a/osu.Framework/Timing/OffsetClock.cs b/osu.Framework/Timing/OffsetClock.cs index f5363b2ab..7efb86ce4 100644 --- a/osu.Framework/Timing/OffsetClock.cs +++ b/osu.Framework/Timing/OffsetClock.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + namespace osu.Framework.Timing { public class OffsetClock : IClock diff --git a/osu.Framework/Timing/StopwatchClock.cs b/osu.Framework/Timing/StopwatchClock.cs index ea304afed..f9c49b986 100644 --- a/osu.Framework/Timing/StopwatchClock.cs +++ b/osu.Framework/Timing/StopwatchClock.cs @@ -1,6 +1,8 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +#nullable disable + using osu.Framework.Extensions.TypeExtensions; using System; using System.Diagnostics; diff --git a/osu.Framework/Timing/ThrottledFrameClock.cs b/osu.Framework/Timing/ThrottledFrameClock.cs index 7c158bb6f..caceb6f1a 100644 --- a/osu.Framework/Timing/ThrottledFrameClock.cs +++ b/osu.Framework/Timing/ThrottledFrameClock.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using System; using System.Diagnostics; using System.Threading; diff --git a/osu.Framework/Utils/ConvexPolygonClipper.cs b/osu.Framework/Utils/ConvexPolygonClipper.cs index 4931262d5..a0de4e79e 100644 --- a/osu.Framework/Utils/ConvexPolygonClipper.cs +++ b/osu.Framework/Utils/ConvexPolygonClipper.cs @@ -29,8 +29,9 @@ namespace osu.Framework.Utils [MethodImpl(MethodImplOptions.AggressiveInlining)] public int GetClipBufferSize() { - // There can only be at most two intersections for each of the subject's vertices - return subjectPolygon.GetVertices().Length * 2; + // Assume every line can intersect every other line. + // This clipper cannot handle concavity, however this allows for edge cases to be handled gracefully. + return subjectPolygon.GetVertices().Length * clipPolygon.GetVertices().Length; } /// diff --git a/osu.Framework/Utils/General.cs b/osu.Framework/Utils/General.cs new file mode 100644 index 000000000..a06d476c2 --- /dev/null +++ b/osu.Framework/Utils/General.cs @@ -0,0 +1,51 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Threading; +using osu.Framework.Logging; + +namespace osu.Framework.Utils +{ + public static class General + { + /// + /// Attempt an operation and perform retries on a matching exception, up to a limit. + /// Useful for IO operations which can fail for a short period due to an open file handle. + /// + /// The action to perform. + /// The number of attempts (250ms wait between each). + /// Whether to throw an exception on failure. If false, will silently fail. + /// The type of exception which should trigger retries. + /// Whether the operation succeeded. + public static bool AttemptWithRetryOnException(this Action action, int attempts = 10, bool throwOnFailure = true) + where TException : Exception + { + while (true) + { + try + { + action(); + return true; + } + catch (Exception e) + { + if (e is not TException) + throw; + + if (attempts-- == 0) + { + if (throwOnFailure) + throw; + + return false; + } + + Logger.Log($"Operation failed ({e.Message}). Retrying {attempts} more times..."); + } + + Thread.Sleep(250); + } + } + } +} diff --git a/osu.Framework/Utils/Interpolation.cs b/osu.Framework/Utils/Interpolation.cs index 96b052a53..3e434835c 100644 --- a/osu.Framework/Utils/Interpolation.cs +++ b/osu.Framework/Utils/Interpolation.cs @@ -3,7 +3,6 @@ using System; using System.Linq; -using System.Reflection; using System.Runtime.Serialization; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; @@ -382,9 +381,10 @@ namespace osu.Framework.Utils var parameters = typeof(InterpolationFunc) .GetMethod(nameof(InterpolationFunc.Invoke)) - ?.GetParameters().Select(p => p.ParameterType).ToArray(); + ?.GetParameters().Select(p => p.ParameterType).ToArray() + ?? Array.Empty(); - MethodInfo valueAtMethod = typeof(GenericInterpolation).GetMethod(interpolation_method, parameters); + var valueAtMethod = typeof(GenericInterpolation).GetMethod(interpolation_method, parameters); if (valueAtMethod != null) FUNCTION = (InterpolationFunc)valueAtMethod.CreateDelegate(typeof(InterpolationFunc)); diff --git a/osu.Framework/Utils/ThrowHelper.cs b/osu.Framework/Utils/ThrowHelper.cs index 42077e5b6..654292685 100644 --- a/osu.Framework/Utils/ThrowHelper.cs +++ b/osu.Framework/Utils/ThrowHelper.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - using System; namespace osu.Framework.Utils diff --git a/osu.Framework/Utils/Validation.cs b/osu.Framework/Utils/Validation.cs index a39a54574..7020bc46a 100644 --- a/osu.Framework/Utils/Validation.cs +++ b/osu.Framework/Utils/Validation.cs @@ -8,8 +8,6 @@ using osu.Framework.Bindables; using osuTK; using osu.Framework.Graphics; -#nullable enable - namespace osu.Framework.Utils { public static class Validation diff --git a/osu.Framework/osu.Framework.csproj b/osu.Framework/osu.Framework.csproj index 01c044c38..a2c9ddf8f 100644 --- a/osu.Framework/osu.Framework.csproj +++ b/osu.Framework/osu.Framework.csproj @@ -35,9 +35,9 @@ - + - + @@ -48,7 +48,7 @@ - +