Compare commits

...

2 Commits

Author SHA1 Message Date
Isaac Marovitz
306f7e93a0 Dont Error on Invalid Enum Values (#5169)
* Dont Error on Invalid Enum

* Use TryParse

* Log warning
2023-06-05 01:19:46 +02:00
Marco Carvalho
8954ff3af2 Replacing ZbcColorArray with Array4<uint> (#5210)
* Related "if/else if" statements should not have the same condition

* replacing ZbcColorArray with Array4<uint>

* fix alignment
2023-06-04 20:30:04 +00:00
2 changed files with 14 additions and 44 deletions

View File

@@ -1,4 +1,5 @@
#nullable enable #nullable enable
using Ryujinx.Common.Logging;
using System; using System;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
@@ -18,12 +19,14 @@ namespace Ryujinx.Common.Utilities
public override TEnum Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) public override TEnum Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{ {
var enumValue = reader.GetString(); var enumValue = reader.GetString();
if (string.IsNullOrEmpty(enumValue))
if (Enum.TryParse(enumValue, out TEnum value))
{ {
return default; return value;
} }
return Enum.Parse<TEnum>(enumValue); Logger.Warning?.Print(LogClass.Configuration, $"Failed to parse enum value \"{enumValue}\" for {typeof(TEnum)}, using default \"{default(TEnum)}\"");
return default;
} }
public override void Write(Utf8JsonWriter writer, TEnum value, JsonSerializerOptions options) public override void Write(Utf8JsonWriter writer, TEnum value, JsonSerializerOptions options)

View File

@@ -1,47 +1,14 @@
using System; using Ryujinx.Common.Memory;
using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrlGpu.Types namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrlGpu.Types
{ {
[StructLayout(LayoutKind.Sequential)]
struct ZbcColorArray
{
private uint element0;
private uint element1;
private uint element2;
private uint element3;
public uint this[int index]
{
get
{
if (index == 0)
{
return element0;
}
else if (index == 1)
{
return element1;
}
else if (index == 2)
{
return element2;
}
else if (index == 2)
{
return element3;
}
throw new IndexOutOfRangeException();
}
}
}
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
struct ZbcSetTableArguments struct ZbcSetTableArguments
{ {
public ZbcColorArray ColorDs; public Array4<uint> ColorDs;
public ZbcColorArray ColorL2; public Array4<uint> ColorL2;
public uint Depth; public uint Depth;
public uint Format; public uint Format;
public uint Type; public uint Type;