Added UseShiftKeyMod to GamePort settings.

Added signature to machine state.
Changed floating point precision from double to single.
This commit is contained in:
Sean Fausett 2010-12-05 11:18:48 +13:00
parent 0182641281
commit fe9abb1c2b
10 changed files with 37 additions and 34 deletions

View File

@ -26,7 +26,7 @@ public void Dispose()
_stopEvent.Close();
}
public void SetVolume(double volume)
public void SetVolume(float volume)
{
int attenuation = (volume < 0.01) ? (int)BufferVolume.Min : (int)Math.Floor(100 * 20 * Math.Log10(volume)); // 100 db
lock (_bufferLock)

View File

@ -7,11 +7,6 @@ public static int Clamp(int value, int min, int max)
return (value < min) ? min : (value > max) ? max : value;
}
public static double Clamp(double value, double min, double max)
{
return (value < min) ? min : (value > max) ? max : value;
}
public static int ClampByte(int value)
{
return Clamp(value, byte.MinValue, byte.MaxValue);

View File

@ -22,7 +22,7 @@ public override void Initialize()
_keyboardService = Machine.Services.GetService<KeyboardService>();
_gamePortService = Machine.Services.GetService<GamePortService>();
JoystickDeadZone = 0.4;
JoystickDeadZone = 0.4f;
}
public override void LoadState(BinaryReader reader, Version version)
@ -32,7 +32,8 @@ public override void LoadState(BinaryReader reader, Version version)
throw new ArgumentNullException("reader");
}
JoystickDeadZone = reader.ReadDouble();
JoystickDeadZone = reader.ReadSingle();
UseShiftKeyMod = reader.ReadBoolean();
UseKeyboard = reader.ReadBoolean();
Joystick0UpLeftKey = reader.ReadInt32();
@ -64,6 +65,7 @@ public override void SaveState(BinaryWriter writer)
}
writer.Write(JoystickDeadZone);
writer.Write(UseShiftKeyMod);
writer.Write(UseKeyboard);
writer.Write(Joystick0UpLeftKey);
@ -101,7 +103,7 @@ public bool ReadButton1()
public bool ReadButton2()
{
return (_gamePortService.IsButton2Down || !_keyboardService.IsShiftKeyDown || // Shift' [TN9]
return (_gamePortService.IsButton2Down || (UseShiftKeyMod && !_keyboardService.IsShiftKeyDown) || // Shift' [TN9]
(UseKeyboard && (Button2Key > 0) && _keyboardService.IsKeyDown(Button2Key)));
}
@ -196,7 +198,8 @@ private void ResetPaddle3StrobeEvent()
Paddle3Strobe = false;
}
public double JoystickDeadZone { get; set; }
public float JoystickDeadZone { get; set; }
public bool UseShiftKeyMod { get; set; }
public bool UseKeyboard { get; set; }
public int Joystick0UpLeftKey { get; set; }

View File

@ -110,11 +110,14 @@ private void LoadState()
{
try
{
var version = new Version(Version);
using (var reader = new BinaryReader(stream))
{
version = new Version(reader.ReadString());
Components.ForEach(component => component.LoadState(reader, version));
string stateSignature = reader.ReadString();
var stateVersion = new Version(reader.ReadString());
if ((stateSignature == StateSignature) && (stateVersion == new Version(Machine.Version))) // avoid state version mismatch (for now)
{
Components.ForEach(component => component.LoadState(reader, stateVersion));
}
}
}
catch (Exception)
@ -139,7 +142,8 @@ private void SaveState()
{
using (var writer = new BinaryWriter(stream))
{
writer.Write(Version);
writer.Write(StateSignature);
writer.Write(Machine.Version);
Components.ForEach(component => component.SaveState(writer));
}
});
@ -172,7 +176,7 @@ private void Run() // machine thread
Uninitialize();
}
public const string Version = "0.9.0.0";
public const string Version = "0.9.1.0";
public MachineEvents Events { get; private set; }
public MachineServices Services { get; private set; }
@ -201,6 +205,7 @@ private void Run() // machine thread
public Thread Thread { get; private set; }
private const string LastStateFileName = "LastState.bin";
private const string StateSignature = "Virtu";
private AutoResetEvent _pauseEvent = new AutoResetEvent(false);
private AutoResetEvent _unpauseEvent = new AutoResetEvent(false);

View File

@ -39,7 +39,7 @@ public void Reset()
Buffer.BlockCopy(SampleZero, 0, _buffer, 0, SampleSize);
}
public abstract void SetVolume(double volume);
public abstract void SetVolume(float volume);
protected void Update() // audio thread
{

View File

@ -28,7 +28,7 @@ public SilverlightAudioService(Machine machine, UserControl page, MediaElement m
#endif
}
public override void SetVolume(double volume)
public override void SetVolume(float volume)
{
_media.Dispatcher.Send(() => _media.Volume = volume);
}

View File

@ -17,9 +17,9 @@ public override void Initialize()
_audioService = Machine.Services.GetService<AudioService>();
#if WINDOWS_PHONE
Volume = 0.85;
Volume = 0.85f;
#else
Volume = 0.5;
Volume = 0.5f;
#endif
Machine.Events.AddEvent(CyclesPerFlush * Machine.Cpu.Multiplier, _flushOutputEvent);
}
@ -38,7 +38,7 @@ public override void LoadState(BinaryReader reader, Version version)
throw new ArgumentNullException("reader");
}
Volume = reader.ReadDouble();
Volume = reader.ReadSingle();
}
public override void SaveState(BinaryWriter writer)
@ -77,7 +77,7 @@ private void UpdateCycles()
_lastCycles = Machine.Cpu.Cycles;
}
public double Volume { get { return _volume; } set { _volume = value; _audioService.SetVolume(_volume); } }
public float Volume { get { return _volume; } set { _volume = value; _audioService.SetVolume(_volume); } }
private const int CyclesPerFlush = 23;
@ -89,6 +89,6 @@ private void UpdateCycles()
private int _highCycles;
private int _totalCycles;
private long _lastCycles;
private double _volume;
private float _volume;
}
}

View File

@ -28,7 +28,7 @@ public WpfAudioService(Machine machine, UserControl page) :
};
}
public override void SetVolume(double volume)
public override void SetVolume(float volume)
{
_directSound.SetVolume(volume);
}

View File

@ -23,9 +23,9 @@ public XnaAudioService(Machine machine, GameBase game) :
_dynamicSoundEffect.Play();
}
public override void SetVolume(double volume)
public override void SetVolume(float volume)
{
_dynamicSoundEffect.Volume = (float)volume;
_dynamicSoundEffect.Volume = volume;
}
protected override void Dispose(bool disposing)

View File

@ -20,22 +20,22 @@ public override void Update() // main thread
var left = _state.ThumbSticks.Left;
var right = _state.ThumbSticks.Right;
var dpad = _state.DPad;
float joystickDeadZone = (float)Machine.GamePort.JoystickDeadZone;
var gamePort = Machine.GamePort;
Paddle0 = (int)((1 + left.X) * PaddleScale);
Paddle1 = (int)((1 - left.Y) * PaddleScale); // invert y
Paddle2 = (int)((1 + right.X) * PaddleScale);
Paddle3 = (int)((1 - right.Y) * PaddleScale); // invert y
IsJoystick0Up = ((left.Y > joystickDeadZone) || (dpad.Up == ButtonState.Pressed));
IsJoystick0Left = ((left.X < -joystickDeadZone) || (dpad.Left == ButtonState.Pressed));
IsJoystick0Right = ((left.X > joystickDeadZone) || (dpad.Right == ButtonState.Pressed));
IsJoystick0Down = ((left.Y < -joystickDeadZone) || (dpad.Down == ButtonState.Pressed));
IsJoystick0Up = ((left.Y > gamePort.JoystickDeadZone) || (dpad.Up == ButtonState.Pressed));
IsJoystick0Left = ((left.X < -gamePort.JoystickDeadZone) || (dpad.Left == ButtonState.Pressed));
IsJoystick0Right = ((left.X > gamePort.JoystickDeadZone) || (dpad.Right == ButtonState.Pressed));
IsJoystick0Down = ((left.Y < -gamePort.JoystickDeadZone) || (dpad.Down == ButtonState.Pressed));
IsJoystick1Up = (right.Y > joystickDeadZone);
IsJoystick1Left = (right.X < -joystickDeadZone);
IsJoystick1Right = (right.X > joystickDeadZone);
IsJoystick1Down = (right.Y < -joystickDeadZone);
IsJoystick1Up = (right.Y > gamePort.JoystickDeadZone);
IsJoystick1Left = (right.X < -gamePort.JoystickDeadZone);
IsJoystick1Right = (right.X > gamePort.JoystickDeadZone);
IsJoystick1Down = (right.Y < -gamePort.JoystickDeadZone);
IsButton0Down = ((_state.Buttons.A == ButtonState.Pressed) || (_state.Buttons.LeftShoulder == ButtonState.Pressed));
IsButton1Down = ((_state.Buttons.B == ButtonState.Pressed) || (_state.Buttons.RightShoulder == ButtonState.Pressed));