mirror of
https://git.ryujinx.app/projects/Kenji-NX.git
synced 2026-09-28 12:27:55 +02:00
Memory changes 3
General memory improvements to decrease GC pressure and frequency. Pool big arrays and objects that are created and deleted often. Skip data copies when they aren't needed. Inline flag checks to skip unneeded allocations. From my testing the performance is about the same, but the GC frequency is much lower and collection is faster causing less and smaller spikes.
This commit is contained in:
@@ -84,7 +84,7 @@ namespace Ryujinx.Input.SDL2
|
||||
_triggerThreshold = 0.0f;
|
||||
|
||||
// Enable motion tracking
|
||||
if (Features.HasFlag(GamepadFeaturesFlag.Motion))
|
||||
if ((Features & GamepadFeaturesFlag.Motion) != 0)
|
||||
{
|
||||
if (SDL_GameControllerSetSensorEnabled(_gamepadHandle, SDL_SensorType.SDL_SENSOR_ACCEL, SDL_bool.SDL_TRUE) != 0)
|
||||
{
|
||||
@@ -145,7 +145,7 @@ namespace Ryujinx.Input.SDL2
|
||||
|
||||
public void Rumble(float lowFrequency, float highFrequency, uint durationMs)
|
||||
{
|
||||
if (Features.HasFlag(GamepadFeaturesFlag.Rumble))
|
||||
if ((Features & GamepadFeaturesFlag.Rumble) == 0)
|
||||
{
|
||||
ushort lowFrequencyRaw = (ushort)(lowFrequency * ushort.MaxValue);
|
||||
ushort highFrequencyRaw = (ushort)(highFrequency * ushort.MaxValue);
|
||||
@@ -184,32 +184,32 @@ namespace Ryujinx.Input.SDL2
|
||||
sensorType = SDL_SensorType.SDL_SENSOR_GYRO;
|
||||
}
|
||||
|
||||
if (Features.HasFlag(GamepadFeaturesFlag.Motion) && sensorType != SDL_SensorType.SDL_SENSOR_INVALID)
|
||||
if ((Features & GamepadFeaturesFlag.Motion) == 0 || sensorType is SDL_SensorType.SDL_SENSOR_INVALID)
|
||||
return Vector3.Zero;
|
||||
|
||||
const int ElementCount = 3;
|
||||
|
||||
unsafe
|
||||
{
|
||||
const int ElementCount = 3;
|
||||
float* values = stackalloc float[ElementCount];
|
||||
|
||||
unsafe
|
||||
int result = SDL_GameControllerGetSensorData(_gamepadHandle, sensorType, (nint)values, ElementCount);
|
||||
|
||||
if (result == 0)
|
||||
{
|
||||
float* values = stackalloc float[ElementCount];
|
||||
Vector3 value = new(values[0], values[1], values[2]);
|
||||
|
||||
int result = SDL_GameControllerGetSensorData(_gamepadHandle, sensorType, (nint)values, ElementCount);
|
||||
|
||||
if (result == 0)
|
||||
if (inputId == MotionInputId.Gyroscope)
|
||||
{
|
||||
Vector3 value = new(values[0], values[1], values[2]);
|
||||
|
||||
if (inputId == MotionInputId.Gyroscope)
|
||||
{
|
||||
return RadToDegree(value);
|
||||
}
|
||||
|
||||
if (inputId == MotionInputId.Accelerometer)
|
||||
{
|
||||
return GsToMs2(value);
|
||||
}
|
||||
|
||||
return value;
|
||||
return RadToDegree(value);
|
||||
}
|
||||
|
||||
if (inputId == MotionInputId.Accelerometer)
|
||||
{
|
||||
return GsToMs2(value);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace Ryujinx.Input.SDL2
|
||||
Features = GetFeaturesFlag();
|
||||
|
||||
// Enable motion tracking
|
||||
if (Features.HasFlag(GamepadFeaturesFlag.Motion))
|
||||
if ((Features & GamepadFeaturesFlag.Motion) != 0)
|
||||
{
|
||||
if (SDL_GameControllerSetSensorEnabled(_gamepadHandle, SDL_SensorType.SDL_SENSOR_ACCEL,
|
||||
SDL_bool.SDL_TRUE) != 0)
|
||||
@@ -163,7 +163,7 @@ namespace Ryujinx.Input.SDL2
|
||||
|
||||
public void Rumble(float lowFrequency, float highFrequency, uint durationMs)
|
||||
{
|
||||
if (!Features.HasFlag(GamepadFeaturesFlag.Rumble))
|
||||
if ((Features & GamepadFeaturesFlag.Rumble) == 0)
|
||||
return;
|
||||
|
||||
ushort lowFrequencyRaw = (ushort)(lowFrequency * ushort.MaxValue);
|
||||
@@ -195,7 +195,7 @@ namespace Ryujinx.Input.SDL2
|
||||
_ => SDL_SensorType.SDL_SENSOR_INVALID
|
||||
};
|
||||
|
||||
if (!Features.HasFlag(GamepadFeaturesFlag.Motion) || sensorType is SDL_SensorType.SDL_SENSOR_INVALID)
|
||||
if ((Features & GamepadFeaturesFlag.Motion) == 0 || sensorType is SDL_SensorType.SDL_SENSOR_INVALID)
|
||||
return Vector3.Zero;
|
||||
|
||||
const int ElementCount = 3;
|
||||
|
||||
Reference in New Issue
Block a user