mirror of
https://git.ryujinx.app/projects/Kenji-NX.git
synced 2026-11-19 17:21:15 +01:00
Memory Changes part 2
* Slightly refactors RangeLists from the last Memory Changes MR, which fixes issue 61. * Convert as many const size array iterators to span iterators as possible. When iterating over a const size array, every iteration created a Span, now only the first iteration does in most places. * Now using object pooling for a few object types that were rapidly deleted and recreated. * Converted a few flag checks to binary operations to save memory allocations.
This commit is contained in:
1 parent
01cb33f658
commit
171624e7f0
89 files changed
+2121
-1157
No files matched your search
@@ -1,4 +1,5 @@
|
||||
using Ryujinx.Common.Memory;
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Ryujinx.Input
|
||||
@@ -49,7 +50,7 @@ namespace Ryujinx.Input
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public (float, float) GetStick(StickInputId inputId)
|
||||
{
|
||||
var result = _joysticksState[(int)inputId];
|
||||
Span<float> result = _joysticksState[(int)inputId].AsSpan();
|
||||
|
||||
return (result[0], result[1]);
|
||||
}
|
||||
@@ -63,8 +64,9 @@ namespace Ryujinx.Input
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetStick(StickInputId inputId, float x, float y)
|
||||
{
|
||||
_joysticksState[(int)inputId][0] = x;
|
||||
_joysticksState[(int)inputId][1] = y;
|
||||
Span<float> stateSpan = _joysticksState[(int)inputId].AsSpan();
|
||||
stateSpan[0] = x;
|
||||
stateSpan[1] = y;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,25 +95,28 @@ namespace Ryujinx.Input
|
||||
{
|
||||
// NOTE: Update Array size if JoystickInputId is changed.
|
||||
Array3<Array2<float>> joysticksState = default;
|
||||
Span<Array2<float>> joysticksStateSpan = joysticksState.AsSpan();
|
||||
|
||||
for (StickInputId inputId = StickInputId.Left; inputId < StickInputId.Count; inputId++)
|
||||
{
|
||||
(float state0, float state1) = gamepad.GetStick(inputId);
|
||||
|
||||
Array2<float> state = default;
|
||||
Span<float> stateSpan = state.AsSpan();
|
||||
|
||||
state[0] = state0;
|
||||
state[1] = state1;
|
||||
stateSpan[0] = state0;
|
||||
stateSpan[1] = state1;
|
||||
|
||||
joysticksState[(int)inputId] = state;
|
||||
joysticksStateSpan[(int)inputId] = state;
|
||||
}
|
||||
|
||||
// NOTE: Update Array size if GamepadInputId is changed.
|
||||
Array28<bool> buttonsState = default;
|
||||
Span<bool> buttonsStateSpan = buttonsState.AsSpan();
|
||||
|
||||
for (GamepadButtonInputId inputId = GamepadButtonInputId.A; inputId < GamepadButtonInputId.Count; inputId++)
|
||||
{
|
||||
buttonsState[(int)inputId] = gamepad.IsPressed(inputId);
|
||||
buttonsStateSpan[(int)inputId] = gamepad.IsPressed(inputId);
|
||||
}
|
||||
|
||||
return new GamepadStateSnapshot(joysticksState, buttonsState);
|
||||
|
||||
Reference in new issue
Block a user