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 @@ namespace Jellyfish.Library
_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 @@
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 @@ namespace Jellyfish.Virtu
_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 @@ namespace Jellyfish.Virtu
throw new ArgumentNullException("reader");
}
JoystickDeadZone = reader.ReadDouble();
JoystickDeadZone = reader.ReadSingle();
UseShiftKeyMod = reader.ReadBoolean();
UseKeyboard = reader.ReadBoolean();
Joystick0UpLeftKey = reader.ReadInt32();
@ -64,6 +65,7 @@ namespace Jellyfish.Virtu
}
writer.Write(JoystickDeadZone);
writer.Write(UseShiftKeyMod);
writer.Write(UseKeyboard);
writer.Write(Joystick0UpLeftKey);
@ -101,7 +103,7 @@ namespace Jellyfish.Virtu
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 @@ namespace Jellyfish.Virtu
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 @@ namespace Jellyfish.Virtu
{
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 @@ namespace Jellyfish.Virtu
{
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 @@ namespace Jellyfish.Virtu
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 @@ namespace Jellyfish.Virtu
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 @@ namespace Jellyfish.Virtu.Services
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 @@ namespace Jellyfish.Virtu.Services
#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 @@ namespace Jellyfish.Virtu
_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 @@ namespace Jellyfish.Virtu
throw new ArgumentNullException("reader");
}
Volume = reader.ReadDouble();
Volume = reader.ReadSingle();
}
public override void SaveState(BinaryWriter writer)
@ -77,7 +77,7 @@ namespace Jellyfish.Virtu
_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 @@ namespace Jellyfish.Virtu
private int _highCycles;
private int _totalCycles;
private long _lastCycles;
private double _volume;
private float _volume;
}
}

View File

@ -28,7 +28,7 @@ namespace Jellyfish.Virtu.Services
};
}
public override void SetVolume(double volume)
public override void SetVolume(float volume)
{
_directSound.SetVolume(volume);
}

View File

@ -23,9 +23,9 @@ namespace Jellyfish.Virtu.Services
_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 @@ namespace Jellyfish.Virtu.Services
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));