pce: make slstart, slend non-sync settings because the core supports it and the waterbox supports it
This commit is contained in:
parent
842a7df215
commit
2cc106de98
|
@ -56,6 +56,10 @@ namespace BizHawk.Emulation.Cores.Consoles.NEC.PCE
|
|||
{ "nyma.rtcinitialtime", null },
|
||||
{ "nyma.rtcrealtime", null },
|
||||
};
|
||||
protected override ISet<string> NonSyncSettingNames { get; } = new HashSet<string>
|
||||
{
|
||||
"pce.slstart", "pce.slend",
|
||||
};
|
||||
|
||||
protected override IDictionary<string, string> ButtonNameOverrides { get; } = new Dictionary<string, string>
|
||||
{
|
||||
|
|
|
@ -47,9 +47,8 @@ namespace BizHawk.Emulation.Cores.Waterbox
|
|||
var s1 = SettingsInfo.Ports
|
||||
.Select((p, i) => new PortPropertyDescriptor(p, i))
|
||||
.Cast<PropertyDescriptor>();
|
||||
var s2 = SettingsInfo.Settings
|
||||
.Where(s => !SettingsInfo.HiddenSettings.Contains(s.SettingsKey))
|
||||
.Select(m => MednaPropertyDescriptor.Create(m));
|
||||
var s2 = SettingsInfo.SyncSettings
|
||||
.Select(m => MednaPropertyDescriptor.Create(m, true));
|
||||
return new PropertyDescriptorCollection(s1.Concat(s2).ToArray());
|
||||
}
|
||||
public override PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
|
||||
|
@ -67,8 +66,11 @@ namespace BizHawk.Emulation.Cores.Waterbox
|
|||
public override PropertyDescriptor GetDefaultProperty() => GetProperties()[0]; // "default" ??
|
||||
public override PropertyDescriptorCollection GetProperties()
|
||||
{
|
||||
return new PropertyDescriptorCollection(
|
||||
SettingsInfo.LayerNames.Select(l => new LayerPropertyDescriptor(l)).ToArray());
|
||||
var s1 = SettingsInfo.LayerNames.Select(l => new LayerPropertyDescriptor(l))
|
||||
.Cast<PropertyDescriptor>();
|
||||
var s2 = SettingsInfo.Settings
|
||||
.Select(m => MednaPropertyDescriptor.Create(m, true));
|
||||
return new PropertyDescriptorCollection(s1.Concat(s2).ToArray());
|
||||
}
|
||||
public override PropertyDescriptorCollection GetProperties(Attribute[] attributes) => GetProperties();
|
||||
}
|
||||
|
@ -76,13 +78,15 @@ namespace BizHawk.Emulation.Cores.Waterbox
|
|||
public abstract class MednaPropertyDescriptor : PropertyDescriptor
|
||||
{
|
||||
public SettingT Setting { get; private set; }
|
||||
public MednaPropertyDescriptor(SettingT setting)
|
||||
private bool _isSyncSetting;
|
||||
public MednaPropertyDescriptor(SettingT setting, bool isSyncSetting)
|
||||
: base(setting.SettingsKey, new Attribute[0])
|
||||
{
|
||||
Setting = setting;
|
||||
_isSyncSetting = isSyncSetting;
|
||||
}
|
||||
|
||||
public override Type ComponentType => typeof(NymaSyncSettings);
|
||||
public override Type ComponentType => _isSyncSetting ? typeof(NymaSyncSettings) : typeof(NymaSettings);
|
||||
public override bool IsReadOnly => false;
|
||||
// public override Type PropertyType => typeof(string);
|
||||
public override bool CanResetValue(object component) => true;
|
||||
|
@ -97,7 +101,7 @@ namespace BizHawk.Emulation.Cores.Waterbox
|
|||
|
||||
public override object GetValue(object component)
|
||||
{
|
||||
var ss = (NymaSyncSettings)component;
|
||||
var ss = (INymaDictionarySettings)component;
|
||||
if (!ss.MednafenValues.TryGetValue(Setting.SettingsKey, out var val))
|
||||
val = Setting.DefaultValue;
|
||||
var ret = ConvertFromString(val);
|
||||
|
@ -106,7 +110,7 @@ namespace BizHawk.Emulation.Cores.Waterbox
|
|||
|
||||
public override void ResetValue(object component)
|
||||
{
|
||||
((NymaSyncSettings)component).MednafenValues.Remove(Setting.SettingsKey);
|
||||
((INymaDictionarySettings)component).MednafenValues.Remove(Setting.SettingsKey);
|
||||
}
|
||||
|
||||
public override void SetValue(object component, object value)
|
||||
|
@ -117,30 +121,30 @@ namespace BizHawk.Emulation.Cores.Waterbox
|
|||
ResetValue(component);
|
||||
return;
|
||||
}
|
||||
((NymaSyncSettings)component).MednafenValues[Setting.SettingsKey] = s;
|
||||
((INymaDictionarySettings)component).MednafenValues[Setting.SettingsKey] = s;
|
||||
}
|
||||
|
||||
public override bool ShouldSerializeValue(object component)
|
||||
{
|
||||
return ((NymaSyncSettings)component).MednafenValues.ContainsKey(Setting.SettingsKey);
|
||||
return ((INymaDictionarySettings)component).MednafenValues.ContainsKey(Setting.SettingsKey);
|
||||
}
|
||||
|
||||
public static MednaPropertyDescriptor Create(SettingT s)
|
||||
public static MednaPropertyDescriptor Create(SettingT s, bool isSyncSetting)
|
||||
{
|
||||
switch (s.Type)
|
||||
{
|
||||
case SettingType.Int:
|
||||
return new MednaLongDescriptor(s);
|
||||
return new MednaLongDescriptor(s, isSyncSetting);
|
||||
case SettingType.Uint:
|
||||
return new MednaUlongDescriptor(s);
|
||||
return new MednaUlongDescriptor(s, isSyncSetting);
|
||||
case SettingType.Bool:
|
||||
return new MednaBoolDescriptor(s);
|
||||
return new MednaBoolDescriptor(s, isSyncSetting);
|
||||
case SettingType.Float:
|
||||
return new MednaDoubleDescriptor(s);
|
||||
return new MednaDoubleDescriptor(s, isSyncSetting);
|
||||
case SettingType.String:
|
||||
return new MednaStringDescriptor(s);
|
||||
return new MednaStringDescriptor(s, isSyncSetting);
|
||||
case SettingType.Enum:
|
||||
return new MednaEnumDescriptor(s);
|
||||
return new MednaEnumDescriptor(s, isSyncSetting);
|
||||
default:
|
||||
throw new NotImplementedException($"Unexpected SettingType {s.Type}");
|
||||
}
|
||||
|
@ -149,7 +153,7 @@ namespace BizHawk.Emulation.Cores.Waterbox
|
|||
|
||||
public class MednaEnumDescriptor : MednaPropertyDescriptor
|
||||
{
|
||||
public MednaEnumDescriptor(SettingT s) : base(s) {}
|
||||
public MednaEnumDescriptor(SettingT s, bool isSyncSetting) : base(s, isSyncSetting) {}
|
||||
public override Type PropertyType => typeof(string);
|
||||
protected override object ConvertFromString(string s)
|
||||
{
|
||||
|
@ -196,7 +200,7 @@ namespace BizHawk.Emulation.Cores.Waterbox
|
|||
}
|
||||
public class MednaStringDescriptor : MednaPropertyDescriptor
|
||||
{
|
||||
public MednaStringDescriptor(SettingT s) : base(s) {}
|
||||
public MednaStringDescriptor(SettingT s, bool isSyncSetting) : base(s, isSyncSetting) {}
|
||||
public override Type PropertyType => typeof(string);
|
||||
protected override object ConvertFromString(string s)
|
||||
{
|
||||
|
@ -209,7 +213,7 @@ namespace BizHawk.Emulation.Cores.Waterbox
|
|||
}
|
||||
public class MednaBoolDescriptor : MednaPropertyDescriptor
|
||||
{
|
||||
public MednaBoolDescriptor(SettingT s) : base(s) {}
|
||||
public MednaBoolDescriptor(SettingT s, bool isSyncSetting) : base(s, isSyncSetting) {}
|
||||
public override Type PropertyType => typeof(bool);
|
||||
protected override object ConvertFromString(string s)
|
||||
{
|
||||
|
@ -222,7 +226,7 @@ namespace BizHawk.Emulation.Cores.Waterbox
|
|||
}
|
||||
public class MednaLongDescriptor : MednaPropertyDescriptor
|
||||
{
|
||||
public MednaLongDescriptor(SettingT s) : base(s) {}
|
||||
public MednaLongDescriptor(SettingT s, bool isSyncSetting) : base(s, isSyncSetting) {}
|
||||
public override Type PropertyType => typeof(long);
|
||||
protected override object ConvertFromString(string s)
|
||||
{
|
||||
|
@ -238,7 +242,7 @@ namespace BizHawk.Emulation.Cores.Waterbox
|
|||
}
|
||||
public class MednaUlongDescriptor : MednaPropertyDescriptor
|
||||
{
|
||||
public MednaUlongDescriptor(SettingT s) : base(s) {}
|
||||
public MednaUlongDescriptor(SettingT s, bool isSyncSetting) : base(s, isSyncSetting) {}
|
||||
public override Type PropertyType => typeof(ulong);
|
||||
protected override object ConvertFromString(string s)
|
||||
{
|
||||
|
@ -265,7 +269,7 @@ namespace BizHawk.Emulation.Cores.Waterbox
|
|||
}
|
||||
public class MednaDoubleDescriptor : MednaPropertyDescriptor
|
||||
{
|
||||
public MednaDoubleDescriptor(SettingT s) : base(s) {}
|
||||
public MednaDoubleDescriptor(SettingT s, bool isSyncSetting) : base(s, isSyncSetting) {}
|
||||
public override Type PropertyType => typeof(double);
|
||||
protected override object ConvertFromString(string s)
|
||||
{
|
||||
|
|
|
@ -7,8 +7,6 @@ using System.Text;
|
|||
using BizHawk.BizInvoke;
|
||||
using BizHawk.Common;
|
||||
using BizHawk.Emulation.Common;
|
||||
using FlatBuffers;
|
||||
using Newtonsoft.Json;
|
||||
using NymaTypes;
|
||||
|
||||
namespace BizHawk.Emulation.Cores.Waterbox
|
||||
|
@ -20,6 +18,10 @@ namespace BizHawk.Emulation.Cores.Waterbox
|
|||
/// If the value is null, use the default value, otherwise override it.
|
||||
/// </summary>
|
||||
protected virtual IDictionary<string, string> SettingsOverrides { get; } = new Dictionary<string, string>();
|
||||
/// <summary>
|
||||
/// Add any settings here that your core is not sync sensitive to. Don't screw up and cause nondeterminism!
|
||||
/// </summary>
|
||||
protected virtual ISet<string> NonSyncSettingNames { get; } = new HashSet<string>();
|
||||
public NymaSettingsInfo SettingsInfo { get; private set; }
|
||||
private NymaSettings _settings;
|
||||
private NymaSyncSettings _syncSettings;
|
||||
|
@ -62,16 +64,26 @@ namespace BizHawk.Emulation.Cores.Waterbox
|
|||
: PutSettingsDirtyBits.RebootCore;
|
||||
}
|
||||
|
||||
public class NymaSettings
|
||||
public interface INymaDictionarySettings
|
||||
{
|
||||
Dictionary<string, string> MednafenValues { get; }
|
||||
}
|
||||
|
||||
public class NymaSettings : INymaDictionarySettings
|
||||
{
|
||||
public Dictionary<string, string> MednafenValues { get; set; } = new Dictionary<string, string>();
|
||||
public HashSet<string> DisabledLayers { get; set; } = new HashSet<string>();
|
||||
public NymaSettings Clone()
|
||||
{
|
||||
return new NymaSettings { DisabledLayers = new HashSet<string>(DisabledLayers) };
|
||||
return new NymaSettings
|
||||
{
|
||||
MednafenValues = new Dictionary<string, string>(MednafenValues),
|
||||
DisabledLayers = new HashSet<string>(DisabledLayers),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public class NymaSyncSettings
|
||||
public class NymaSyncSettings : INymaDictionarySettings
|
||||
{
|
||||
public Dictionary<string, string> MednafenValues { get; set; } = new Dictionary<string, string>();
|
||||
public Dictionary<int, string> PortDevices { get; set; } = new Dictionary<int, string>();
|
||||
|
@ -100,20 +112,27 @@ namespace BizHawk.Emulation.Cores.Waterbox
|
|||
|
||||
protected string SettingsQuery(string name)
|
||||
{
|
||||
var forced = SettingsOverrides.TryGetValue(name, out var val);
|
||||
if (SettingsOverrides.TryGetValue(name, out var val))
|
||||
{
|
||||
// use override
|
||||
}
|
||||
else
|
||||
{
|
||||
// try to get actual value from settings
|
||||
if (NonSyncSettingNames.Contains(name))
|
||||
_settings.MednafenValues.TryGetValue(name, out val);
|
||||
else
|
||||
_syncSettings.MednafenValues.TryGetValue(name, out val);
|
||||
}
|
||||
// in either case, might need defaults
|
||||
if (val == null)
|
||||
{
|
||||
if (forced || !_syncSettingsActual.MednafenValues.TryGetValue(name, out val))
|
||||
{
|
||||
if (SettingsInfo.SettingsByKey.TryGetValue(name, out var info))
|
||||
{
|
||||
val = info.DefaultValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException($"Core asked for setting {name} which was not found in the defaults");
|
||||
}
|
||||
}
|
||||
SettingsInfo.AllSettingsByKey.TryGetValue(name, out var info);
|
||||
val = info?.DefaultValue;
|
||||
}
|
||||
if (val == null)
|
||||
{
|
||||
throw new InvalidOperationException($"Core asked for setting {name} which was not found in the defaults");
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
@ -133,11 +152,11 @@ namespace BizHawk.Emulation.Cores.Waterbox
|
|||
/// <summary>
|
||||
/// If true, the settings object has at least one settable value in it
|
||||
/// </summary>
|
||||
public bool HasSettings => SettingsInfo.LayerNames.Any();
|
||||
public bool HasSettings => SettingsInfo.LayerNames.Count > 0|| SettingsInfo.Settings.Count > 0;
|
||||
/// <summary>
|
||||
/// If true, the syncSettings object has at least one settable value in it
|
||||
/// </summary>
|
||||
public bool HasSyncSettings => SettingsInfo.Ports.Any() || SettingsInfo.Settings.Any();
|
||||
public bool HasSyncSettings => SettingsInfo.Ports.Count > 0 || SettingsInfo.SyncSettings.Count > 0;
|
||||
|
||||
public class NymaSettingsInfo
|
||||
{
|
||||
|
@ -162,8 +181,8 @@ namespace BizHawk.Emulation.Cores.Waterbox
|
|||
/// </summary>
|
||||
public List<Port> Ports { get; set; } = new List<Port>();
|
||||
public List<SettingT> Settings { get; set; } = new List<SettingT>();
|
||||
public Dictionary<string, SettingT> SettingsByKey { get; set; } = new Dictionary<string, SettingT>();
|
||||
public HashSet<string> HiddenSettings { get; set; } = new HashSet<string>();
|
||||
public List<SettingT> SyncSettings { get; set; } = new List<SettingT>();
|
||||
public Dictionary<string, SettingT> AllSettingsByKey { get; set; } = new Dictionary<string, SettingT>();
|
||||
}
|
||||
private void InitSyncSettingsInfo(List<NPortInfoT> allPorts)
|
||||
{
|
||||
|
@ -184,16 +203,20 @@ namespace BizHawk.Emulation.Cores.Waterbox
|
|||
});
|
||||
}
|
||||
|
||||
foreach (var setting in GetSettingsData())
|
||||
foreach (var setting in GetSettingsData().Concat(ExtraSettings))
|
||||
{
|
||||
s.Settings.Add(setting);
|
||||
s.SettingsByKey.Add(setting.SettingsKey, setting);
|
||||
}
|
||||
s.HiddenSettings = new HashSet<string>(SettingsOverrides.Keys);
|
||||
foreach (var ss in ExtraSettings)
|
||||
{
|
||||
s.Settings.Add(ss);
|
||||
s.SettingsByKey.Add(ss.SettingsKey, ss);
|
||||
s.AllSettingsByKey.Add(setting.SettingsKey, setting);
|
||||
if (!SettingsOverrides.ContainsKey(setting.SettingsKey))
|
||||
{
|
||||
if (NonSyncSettingNames.Contains(setting.SettingsKey))
|
||||
{
|
||||
s.Settings.Add(setting);
|
||||
}
|
||||
else
|
||||
{
|
||||
s.SyncSettings.Add(setting);
|
||||
}
|
||||
}
|
||||
}
|
||||
SettingsInfo = s;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue