Skip to content

Commit

Permalink
misc: Code cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
GreemDev committed Oct 19, 2024
1 parent 2facad4 commit b206136
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 84 deletions.
21 changes: 6 additions & 15 deletions src/Ryujinx.Graphics.Texture/Astc/IntegerEncoded.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Ryujinx.Graphics.Texture.Astc
{
internal struct IntegerEncoded
internal struct IntegerEncoded(IntegerEncoded.EIntegerEncoding encoding, int numBits)
{
internal const int StructSize = 8;
private static readonly IntegerEncoded[] _encodings;
Expand All @@ -15,11 +15,11 @@ public enum EIntegerEncoding : byte
Trit,
}

readonly EIntegerEncoding _encoding;
public byte NumberBits { get; private set; }
public byte TritValue { get; private set; }
public byte QuintValue { get; private set; }
public int BitValue { get; private set; }
readonly EIntegerEncoding _encoding = encoding;
public byte NumberBits { get; } = (byte)numBits;
public byte TritValue { get; private set; } = 0;
public byte QuintValue { get; private set; } = 0;
public int BitValue { get; private set; } = 0;

static IntegerEncoded()
{
Expand All @@ -31,15 +31,6 @@ static IntegerEncoded()
}
}

public IntegerEncoded(EIntegerEncoding encoding, int numBits)
{
_encoding = encoding;
NumberBits = (byte)numBits;
BitValue = 0;
TritValue = 0;
QuintValue = 0;
}

public readonly bool MatchesEncoding(IntegerEncoded other)
{
return _encoding == other._encoding && NumberBits == other.NumberBits;
Expand Down
10 changes: 2 additions & 8 deletions src/Ryujinx.HLE/HOS/Applets/IApplet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,8 @@ ResultCode Start(AppletSession normalSession,

ResultCode GetResult();

bool DrawTo(RenderingSurfaceInfo surfaceInfo, IVirtualMemoryManager destination, ulong position)
{
return false;
}
bool DrawTo(RenderingSurfaceInfo surfaceInfo, IVirtualMemoryManager destination, ulong position) => false;

static T ReadStruct<T>(ReadOnlySpan<byte> data) where T : unmanaged
{
return MemoryMarshal.Cast<byte, T>(data)[0];
}
static T ReadStruct<T>(ReadOnlySpan<byte> data) where T : unmanaged => MemoryMarshal.Cast<byte, T>(data)[0];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public ResultCode PresetLibraryAppletGpuTimeSliceZero(ServiceCtx context)
{
// NOTE: This call reset two internal fields to 0 and one internal field to "true".
// It seems to be used only with software keyboard inline.
// Since we doesn't support applets for now, it's fine to stub it.
// Since we don't support applets for now, it's fine to stub it.

Logger.Stub?.PrintStub(LogClass.ServiceAm);

Expand Down
13 changes: 4 additions & 9 deletions src/Ryujinx.Input/HLE/InputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@

namespace Ryujinx.Input.HLE
{
public class InputManager : IDisposable
public class InputManager(IGamepadDriver keyboardDriver, IGamepadDriver gamepadDriver)
: IDisposable
{
public IGamepadDriver KeyboardDriver { get; private set; }
public IGamepadDriver GamepadDriver { get; private set; }
public IGamepadDriver KeyboardDriver { get; } = keyboardDriver;
public IGamepadDriver GamepadDriver { get; } = gamepadDriver;
public IGamepadDriver MouseDriver { get; private set; }

public InputManager(IGamepadDriver keyboardDriver, IGamepadDriver gamepadDriver)
{
KeyboardDriver = keyboardDriver;
GamepadDriver = gamepadDriver;
}

public void SetMouseDriver(IGamepadDriver mouseDriver)
{
MouseDriver?.Dispose();
Expand Down
30 changes: 16 additions & 14 deletions src/Ryujinx/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using Avalonia.Platform;
using Avalonia.Styling;
using Avalonia.Threading;
using FluentAvalonia.UI.Windowing;
using Gommon;
using Ryujinx.Ava.Common;
using Ryujinx.Ava.Common.Locale;
using Ryujinx.Ava.UI.Helpers;
Expand All @@ -24,6 +26,15 @@ internal static string FormatTitle(LocaleKeys? windowTitleKey = null)
? $"Ryujinx {Program.Version}"
: $"Ryujinx {Program.Version} - {LocaleManager.Instance[windowTitleKey.Value]}";

public static MainWindow MainWindow => Current!
.ApplicationLifetime.Cast<IClassicDesktopStyleApplicationLifetime>()
.MainWindow.Cast<MainWindow>();

public static void SetTaskbarProgress(TaskBarProgressBarState state) => MainWindow.PlatformFeatures.SetTaskBarProgressBarState(state);
public static void SetTaskbarProgressValue(ulong current, ulong total) => MainWindow.PlatformFeatures.SetTaskBarProgressBarValue(current, total);
public static void SetTaskbarProgressValue(long current, long total) => SetTaskbarProgressValue(Convert.ToUInt64(current), Convert.ToUInt64(total));


public override void Initialize()
{
Name = FormatTitle();
Expand Down Expand Up @@ -62,8 +73,7 @@ private void CustomThemeChanged_Event(object sender, ReactiveEventArgs<bool> e)

private void ShowRestartDialog()
{
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
Dispatcher.UIThread.InvokeAsync(async () =>
_ = Dispatcher.UIThread.InvokeAsync(async () =>
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
Expand All @@ -82,7 +92,6 @@ private void ShowRestartDialog()
}
}
});
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
}

private void ThemeChanged_Event(object sender, ReactiveEventArgs<string> e)
Expand Down Expand Up @@ -134,16 +143,9 @@ public static ThemeVariant ConvertThemeVariant(PlatformThemeVariant platformThem
_ => ThemeVariant.Default,
};

public static ThemeVariant DetectSystemTheme()
{
if (Application.Current is App app)
{
var colorValues = app.PlatformSettings.GetColorValues();

return ConvertThemeVariant(colorValues.ThemeVariant);
}

return ThemeVariant.Default;
}
public static ThemeVariant DetectSystemTheme() =>
Current is App { PlatformSettings: not null } app
? ConvertThemeVariant(app.PlatformSettings.GetColorValues().ThemeVariant)
: ThemeVariant.Default;
}
}
7 changes: 4 additions & 3 deletions src/Ryujinx/Modules/Updater/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ private static void DoUpdateWithSingleThreadWorker(TaskDialog taskDialog, string
using Stream updateFileStream = File.Open(updateFile, FileMode.Create);

long totalBytes = response.Content.Headers.ContentLength.Value;
long byteWritten = 0;
long bytesWritten = 0;

byte[] buffer = new byte[32 * 1024];

Expand All @@ -479,9 +479,10 @@ private static void DoUpdateWithSingleThreadWorker(TaskDialog taskDialog, string
break;
}

byteWritten += readSize;
bytesWritten += readSize;

taskDialog.SetProgressBarState(GetPercentage(byteWritten, totalBytes), TaskDialogProgressState.Normal);
taskDialog.SetProgressBarState(GetPercentage(bytesWritten, totalBytes), TaskDialogProgressState.Normal);
App.SetTaskbarProgressValue(bytesWritten, totalBytes);

updateFileStream.Write(buffer, 0, readSize);
}
Expand Down
5 changes: 1 addition & 4 deletions src/Ryujinx/UI/Applet/AvaHostUIHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,6 @@ public bool DisplayErrorAppletDialog(string title, string message, string[] butt
return showDetails;
}

public IDynamicTextInputHandler CreateDynamicTextInputHandler()
{
return new AvaloniaDynamicTextInputHandler(_parent);
}
public IDynamicTextInputHandler CreateDynamicTextInputHandler() => new AvaloniaDynamicTextInputHandler(_parent);
}
}
18 changes: 4 additions & 14 deletions src/Ryujinx/UI/Applet/AvaloniaDynamicTextInputHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,8 @@ private void AvaloniaDynamicTextInputHandler_KeyPressed(object sender, KeyEventA

public bool TextProcessingEnabled
{
get
{
return Volatile.Read(ref _canProcessInput);
}
set
{
Volatile.Write(ref _canProcessInput, value);
}
get => Volatile.Read(ref _canProcessInput);
set => Volatile.Write(ref _canProcessInput, value);
}

public event DynamicTextChangedHandler TextChangedEvent;
Expand All @@ -135,23 +129,19 @@ public void Dispose()
});
}

public void SetText(string text, int cursorBegin)
{
public void SetText(string text, int cursorBegin) =>
Dispatcher.UIThread.Post(() =>
{
_hiddenTextBox.Text = text;
_hiddenTextBox.CaretIndex = cursorBegin;
});
}

public void SetText(string text, int cursorBegin, int cursorEnd)
{
public void SetText(string text, int cursorBegin, int cursorEnd) =>
Dispatcher.UIThread.Post(() =>
{
_hiddenTextBox.Text = text;
_hiddenTextBox.SelectionStart = cursorBegin;
_hiddenTextBox.SelectionEnd = cursorEnd;
});
}
}
}
30 changes: 14 additions & 16 deletions src/Ryujinx/UI/Helpers/ContentDialogHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public async static Task<UserResult> ShowTextDialog(
return await ShowContentDialog(title, content, primaryButton, secondaryButton, closeButton, primaryButtonResult, deferResetEvent, deferCloseAction);
}

public static Task<UserResult> ShowDeferredContentDialog(
public static async Task<UserResult> ShowDeferredContentDialog(
Window window,
string title,
string primaryText,
Expand All @@ -98,7 +98,7 @@ public static Task<UserResult> ShowDeferredContentDialog(
{
bool startedDeferring = false;

return ShowTextDialog(
return await ShowTextDialog(
title,
primaryText,
secondaryText,
Expand Down Expand Up @@ -209,14 +209,14 @@ public static Task<UserResult> CreateInfoDialog(
closeButton,
(int)Symbol.Important);

internal static Task<UserResult> CreateConfirmationDialog(
internal static async Task<UserResult> CreateConfirmationDialog(
string primaryText,
string secondaryText,
string acceptButtonText,
string cancelButtonText,
string title,
UserResult primaryButtonResult = UserResult.Yes)
=> ShowTextDialog(
=> await ShowTextDialog(
string.IsNullOrWhiteSpace(title) ? LocaleManager.Instance[LocaleKeys.DialogConfirmationTitle] : title,
primaryText,
secondaryText,
Expand All @@ -226,16 +226,16 @@ internal static Task<UserResult> CreateConfirmationDialog(
(int)Symbol.Help,
primaryButtonResult);

internal static Task<UserResult> CreateLocalizedConfirmationDialog(string primaryText, string secondaryText)
=> CreateConfirmationDialog(
internal static async Task<UserResult> CreateLocalizedConfirmationDialog(string primaryText, string secondaryText)
=> await CreateConfirmationDialog(
primaryText,
secondaryText,
LocaleManager.Instance[LocaleKeys.InputDialogYes],
LocaleManager.Instance[LocaleKeys.InputDialogNo],
LocaleManager.Instance[LocaleKeys.RyujinxConfirm]);

internal static Task CreateUpdaterInfoDialog(string primary, string secondaryText)
=> ShowTextDialog(
internal static async Task CreateUpdaterInfoDialog(string primary, string secondaryText)
=> await ShowTextDialog(
LocaleManager.Instance[LocaleKeys.DialogUpdaterTitle],
primary,
secondaryText,
Expand All @@ -244,8 +244,8 @@ internal static Task CreateUpdaterInfoDialog(string primary, string secondaryTex
LocaleManager.Instance[LocaleKeys.InputDialogOk],
(int)Symbol.Important);

internal static Task CreateWarningDialog(string primary, string secondaryText)
=> ShowTextDialog(
internal static async Task CreateWarningDialog(string primary, string secondaryText)
=> await ShowTextDialog(
LocaleManager.Instance[LocaleKeys.DialogWarningTitle],
primary,
secondaryText,
Expand All @@ -254,11 +254,11 @@ internal static Task CreateWarningDialog(string primary, string secondaryText)
LocaleManager.Instance[LocaleKeys.InputDialogOk],
(int)Symbol.Important);

internal static Task CreateErrorDialog(string errorMessage, string secondaryErrorMessage = "")
internal static async Task CreateErrorDialog(string errorMessage, string secondaryErrorMessage = "")
{
Logger.Error?.Print(LogClass.Application, errorMessage);

return ShowTextDialog(
await ShowTextDialog(
LocaleManager.Instance[LocaleKeys.DialogErrorTitle],
LocaleManager.Instance[LocaleKeys.DialogErrorMessage],
errorMessage,
Expand Down Expand Up @@ -399,11 +399,9 @@ async Task<ContentDialogResult> ShowDialog()
return result;
}

public static Task ShowWindowAsync(Window dialogWindow, Window mainWindow = null)
public static async Task ShowWindowAsync(Window dialogWindow, Window mainWindow = null)
{
mainWindow ??= GetMainWindow();

return dialogWindow.ShowDialog(_contentDialogOverlayWindow ?? mainWindow);
await dialogWindow.ShowDialog(_contentDialogOverlayWindow ?? mainWindow ?? GetMainWindow());
}

private static Window GetMainWindow()
Expand Down

0 comments on commit b206136

Please sign in to comment.