From cc39c555f704de08b4abab30f4c92b5a1ad943f9 Mon Sep 17 00:00:00 2001 From: sin365 <353374337@qq.com> Date: Tue, 7 Jan 2025 17:01:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E6=8B=9F=E5=99=A8=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E6=B1=A0=E5=8C=96=EF=BC=8C=E5=8E=BB=E6=8E=89?= =?UTF-8?q?Xinput=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Essgee/Emulation/Audio/CGBAudio.cs | 8 +- .../Essgee/Emulation/Audio/DMGAudio.cs | 12 +- .../Plugins/Essgee/Emulation/Audio/SN76489.cs | 11 +- .../ExtDevices/Nintendo/GBPrinter.cs | 10 +- .../Essgee/Emulation/Machines/ColecoVision.cs | 12 +- .../Essgee/Emulation/Machines/GameBoy.cs | 45 +- .../Essgee/Emulation/Machines/GameBoyColor.cs | 29 +- .../Essgee/Emulation/Machines/GameGear.cs | 25 +- .../Essgee/Emulation/Machines/MasterSystem.cs | 64 ++- .../Essgee/Emulation/Machines/SC3000.cs | 34 +- .../Essgee/Emulation/Machines/SG1000.cs | 24 +- .../Emulation/Video/Nintendo/DMGVideo.cs | 15 +- .../Essgee/Emulation/Video/SegaGGVDP.cs | 18 +- .../Essgee/Emulation/Video/SegaSMSVDP.cs | 16 +- .../Essgee/Emulation/Video/TMS99xxA.cs | 18 +- Assets/Plugins/Essgee/EssgeeLogger.cs | 8 + .../EventArguments/ChangeViewportEventArgs.cs | 30 +- .../EventArguments/EnqueueSamplesEventArgs.cs | 43 +- .../EventArguments/PollInputEventArgs.cs | 53 ++- .../EventArguments/RenderScreenEventArgs.cs | 38 +- .../EventArguments/SaveExtraDataEventArgs.cs | 32 +- .../EventArguments/SendLogMessageEventArgs.cs | 24 +- .../EventArguments/SizeScreenEventArgs.cs | 27 +- Assets/Plugins/Essgee/ObjectPoolAuto.cs | 399 ++++++++++++++++++ Assets/Plugins/Essgee/ObjectPoolAuto.cs.meta | 2 + .../Essgee/Utilities/XInput/Controller.cs | 28 +- .../Utilities/XInput/ControllerState.cs | 196 +++++---- Assets/Scripts/Essgeeinit.cs | 7 +- Assets/Scripts/UniInterface/KeyCodeCore.cs | 10 +- 29 files changed, 897 insertions(+), 341 deletions(-) create mode 100644 Assets/Plugins/Essgee/ObjectPoolAuto.cs create mode 100644 Assets/Plugins/Essgee/ObjectPoolAuto.cs.meta diff --git a/Assets/Plugins/Essgee/Emulation/Audio/CGBAudio.cs b/Assets/Plugins/Essgee/Emulation/Audio/CGBAudio.cs index 9f32f39..8c4d38c 100644 --- a/Assets/Plugins/Essgee/Emulation/Audio/CGBAudio.cs +++ b/Assets/Plugins/Essgee/Emulation/Audio/CGBAudio.cs @@ -1,12 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Collections.Generic; namespace Essgee.Emulation.Audio { - public partial class CGBAudio : DMGAudio, IAudio + public partial class CGBAudio : DMGAudio, IAudio { public CGBAudio() { diff --git a/Assets/Plugins/Essgee/Emulation/Audio/DMGAudio.cs b/Assets/Plugins/Essgee/Emulation/Audio/DMGAudio.cs index 4a17e69..25dd67c 100644 --- a/Assets/Plugins/Essgee/Emulation/Audio/DMGAudio.cs +++ b/Assets/Plugins/Essgee/Emulation/Audio/DMGAudio.cs @@ -267,15 +267,19 @@ namespace Essgee.Emulation.Audio } if (mixedSampleBuffer.Count >= (samplesPerFrame * numOutputChannels)) - { - OnEnqueueSamples(new EnqueueSamplesEventArgs( + { + EnqueueSamplesEventArgs eventArgs = EnqueueSamplesEventArgs.Create( numChannels, channelSampleBuffer.Select(x => x.ToArray()).ToArray(), new bool[] { !channel1ForceEnable, !channel2ForceEnable, !channel3ForceEnable, !channel4ForceEnable }, - mixedSampleBuffer.ToArray())); + mixedSampleBuffer.ToArray()); + OnEnqueueSamples(eventArgs); FlushSamples(); - } + + eventArgs.Release(); + + } if (frameCycleCount >= cyclesPerFrame) { diff --git a/Assets/Plugins/Essgee/Emulation/Audio/SN76489.cs b/Assets/Plugins/Essgee/Emulation/Audio/SN76489.cs index 41dd4c6..7fb3c49 100644 --- a/Assets/Plugins/Essgee/Emulation/Audio/SN76489.cs +++ b/Assets/Plugins/Essgee/Emulation/Audio/SN76489.cs @@ -217,14 +217,19 @@ namespace Essgee.Emulation.Audio if (mixedSampleBuffer.Count >= (samplesPerFrame * numOutputChannels)) { - OnEnqueueSamples(new EnqueueSamplesEventArgs( + EnqueueSamplesEventArgs eventArgs = EnqueueSamplesEventArgs.Create( numChannels, channelSampleBuffer.Select(x => x.ToArray()).ToArray(), new bool[] { !channel1ForceEnable, !channel2ForceEnable, !channel3ForceEnable, !channel4ForceEnable }, - mixedSampleBuffer.ToArray())); + mixedSampleBuffer.ToArray()); + + OnEnqueueSamples(eventArgs); FlushSamples(); - } + + eventArgs.Release(); + + } if (frameCycleCount >= cyclesPerFrame) { diff --git a/Assets/Plugins/Essgee/Emulation/ExtDevices/Nintendo/GBPrinter.cs b/Assets/Plugins/Essgee/Emulation/ExtDevices/Nintendo/GBPrinter.cs index 6dac4db..0402e8b 100644 --- a/Assets/Plugins/Essgee/Emulation/ExtDevices/Nintendo/GBPrinter.cs +++ b/Assets/Plugins/Essgee/Emulation/ExtDevices/Nintendo/GBPrinter.cs @@ -252,8 +252,10 @@ namespace Essgee.Emulation.ExtDevices.Nintendo if (packet.isCompressed) { /* Decompress RLE first! */ - List decomp = new List(); - int ofs = 0, numbytes = 0; + //List decomp = new List(); + List decomp = ObjectPoolAuto.AcquireList(); + + int ofs = 0, numbytes = 0; while (ofs < packet.dataLen) { if ((packet.data[ofs] & 0x80) != 0) @@ -273,7 +275,9 @@ namespace Essgee.Emulation.ExtDevices.Nintendo } packet.data = decomp.ToArray(); packet.dataLen = (ushort)decomp.Count; - } + + ObjectPoolAuto.Release(decomp); + } imageData.AddRange(packet.data); imageHeight += (packet.data.Length / 0x28); diff --git a/Assets/Plugins/Essgee/Emulation/Machines/ColecoVision.cs b/Assets/Plugins/Essgee/Emulation/Machines/ColecoVision.cs index 819103b..8d4b585 100644 --- a/Assets/Plugins/Essgee/Emulation/Machines/ColecoVision.cs +++ b/Assets/Plugins/Essgee/Emulation/Machines/ColecoVision.cs @@ -129,10 +129,12 @@ namespace Essgee.Emulation.Machines vdp.EndOfScanline += (s, e) => { - PollInputEventArgs pollInputEventArgs = new PollInputEventArgs(); + PollInputEventArgs pollInputEventArgs = PollInputEventArgs.Create(); OnPollInput(pollInputEventArgs); ParseInput(pollInputEventArgs); - }; + pollInputEventArgs.Release(); + + }; } public void SetConfiguration(IConfiguration config) @@ -177,8 +179,10 @@ namespace Essgee.Emulation.Machines currentMasterClockCyclesInFrame = 0; totalMasterClockCyclesInFrame = (int)Math.Round(masterClock / refreshRate); - OnChangeViewport(new ChangeViewportEventArgs(vdp.Viewport)); - } + var eventArgs = ChangeViewportEventArgs.Create(vdp.Viewport); + OnChangeViewport(eventArgs); + eventArgs.Release(); + } private void LoadBios() { diff --git a/Assets/Plugins/Essgee/Emulation/Machines/GameBoy.cs b/Assets/Plugins/Essgee/Emulation/Machines/GameBoy.cs index 9c16241..9b7a020 100644 --- a/Assets/Plugins/Essgee/Emulation/Machines/GameBoy.cs +++ b/Assets/Plugins/Essgee/Emulation/Machines/GameBoy.cs @@ -148,10 +148,11 @@ namespace Essgee.Emulation.Machines video.EndOfScanline += (s, e) => { - PollInputEventArgs pollInputEventArgs = new PollInputEventArgs(); + PollInputEventArgs pollInputEventArgs = PollInputEventArgs.Create(); OnPollInput(pollInputEventArgs); ParseInput(pollInputEventArgs); - }; + pollInputEventArgs.Release(); + }; } public void SetConfiguration(IConfiguration config) @@ -211,9 +212,11 @@ namespace Essgee.Emulation.Machines currentMasterClockCyclesInFrame = 0; totalMasterClockCyclesInFrame = (int)Math.Round(masterClock / refreshRate); - /* Announce viewport */ - OnChangeViewport(new ChangeViewportEventArgs(video.Viewport)); - } + /* Announce viewport */ + var eventArgs = ChangeViewportEventArgs.Create(video.Viewport); + OnChangeViewport(eventArgs); + eventArgs.Release(); + } private void LoadBootstrap() { @@ -473,22 +476,22 @@ namespace Essgee.Emulation.Machines inputsPressed |= JoypadInputs.Start; /* XInput controller */ - if (eventArgs.ControllerState.IsAnyRightDirectionPressed() && !eventArgs.ControllerState.IsAnyLeftDirectionPressed()) - inputsPressed |= JoypadInputs.Right; - if (eventArgs.ControllerState.IsAnyLeftDirectionPressed() && !eventArgs.ControllerState.IsAnyRightDirectionPressed()) - inputsPressed |= JoypadInputs.Left; - if (eventArgs.ControllerState.IsAnyUpDirectionPressed() && !eventArgs.ControllerState.IsAnyDownDirectionPressed()) - inputsPressed |= JoypadInputs.Up; - if (eventArgs.ControllerState.IsAnyDownDirectionPressed() && !eventArgs.ControllerState.IsAnyUpDirectionPressed()) - inputsPressed |= JoypadInputs.Down; - if (eventArgs.ControllerState.IsAPressed()) - inputsPressed |= JoypadInputs.A; - if (eventArgs.ControllerState.IsXPressed() || eventArgs.ControllerState.IsBPressed()) - inputsPressed |= JoypadInputs.B; - if (eventArgs.ControllerState.IsBackPressed()) - inputsPressed |= JoypadInputs.Select; - if (eventArgs.ControllerState.IsStartPressed()) - inputsPressed |= JoypadInputs.Start; + //if (eventArgs.ControllerState.IsAnyRightDirectionPressed() && !eventArgs.ControllerState.IsAnyLeftDirectionPressed()) + // inputsPressed |= JoypadInputs.Right; + //if (eventArgs.ControllerState.IsAnyLeftDirectionPressed() && !eventArgs.ControllerState.IsAnyRightDirectionPressed()) + // inputsPressed |= JoypadInputs.Left; + //if (eventArgs.ControllerState.IsAnyUpDirectionPressed() && !eventArgs.ControllerState.IsAnyDownDirectionPressed()) + // inputsPressed |= JoypadInputs.Up; + //if (eventArgs.ControllerState.IsAnyDownDirectionPressed() && !eventArgs.ControllerState.IsAnyUpDirectionPressed()) + // inputsPressed |= JoypadInputs.Down; + //if (eventArgs.ControllerState.IsAPressed()) + // inputsPressed |= JoypadInputs.A; + //if (eventArgs.ControllerState.IsXPressed() || eventArgs.ControllerState.IsBPressed()) + // inputsPressed |= JoypadInputs.B; + //if (eventArgs.ControllerState.IsBackPressed()) + // inputsPressed |= JoypadInputs.Select; + //if (eventArgs.ControllerState.IsStartPressed()) + // inputsPressed |= JoypadInputs.Start; } private byte ReadMemory(ushort address) diff --git a/Assets/Plugins/Essgee/Emulation/Machines/GameBoyColor.cs b/Assets/Plugins/Essgee/Emulation/Machines/GameBoyColor.cs index 1ba1308..7eb8b23 100644 --- a/Assets/Plugins/Essgee/Emulation/Machines/GameBoyColor.cs +++ b/Assets/Plugins/Essgee/Emulation/Machines/GameBoyColor.cs @@ -179,10 +179,11 @@ namespace Essgee.Emulation.Machines video.EndOfScanline += (s, e) => { - PollInputEventArgs pollInputEventArgs = new PollInputEventArgs(); + PollInputEventArgs pollInputEventArgs = PollInputEventArgs.Create(); OnPollInput(pollInputEventArgs); ParseInput(pollInputEventArgs); - }; + pollInputEventArgs.Release(); + }; } public void SetConfiguration(IConfiguration config) @@ -262,9 +263,11 @@ namespace Essgee.Emulation.Machines currentMasterClockCyclesInFrame = 0; totalMasterClockCyclesInFrame = (int)Math.Round(masterClock / refreshRate); - /* Announce viewport */ - OnChangeViewport(new ChangeViewportEventArgs(video.Viewport)); - } + /* Announce viewport */ + var eventArgs = ChangeViewportEventArgs.Create(video.Viewport); + OnChangeViewport(eventArgs); + eventArgs.Release(); + } private void LoadBootstrap() { @@ -591,14 +594,14 @@ namespace Essgee.Emulation.Machines } /* XInput controller */ - if (eventArgs.ControllerState.IsAnyRightDirectionPressed() && !eventArgs.ControllerState.IsAnyLeftDirectionPressed()) inputsPressed |= JoypadInputs.Right; - if (eventArgs.ControllerState.IsAnyLeftDirectionPressed() && !eventArgs.ControllerState.IsAnyRightDirectionPressed()) inputsPressed |= JoypadInputs.Left; - if (eventArgs.ControllerState.IsAnyUpDirectionPressed() && !eventArgs.ControllerState.IsAnyDownDirectionPressed()) inputsPressed |= JoypadInputs.Up; - if (eventArgs.ControllerState.IsAnyDownDirectionPressed() && !eventArgs.ControllerState.IsAnyUpDirectionPressed()) inputsPressed |= JoypadInputs.Down; - if (eventArgs.ControllerState.IsAPressed()) inputsPressed |= JoypadInputs.A; - if (eventArgs.ControllerState.IsXPressed() || eventArgs.ControllerState.IsBPressed()) inputsPressed |= JoypadInputs.B; - if (eventArgs.ControllerState.IsBackPressed()) inputsPressed |= JoypadInputs.Select; - if (eventArgs.ControllerState.IsStartPressed()) inputsPressed |= JoypadInputs.Start; + //if (eventArgs.ControllerState.IsAnyRightDirectionPressed() && !eventArgs.ControllerState.IsAnyLeftDirectionPressed()) inputsPressed |= JoypadInputs.Right; + //if (eventArgs.ControllerState.IsAnyLeftDirectionPressed() && !eventArgs.ControllerState.IsAnyRightDirectionPressed()) inputsPressed |= JoypadInputs.Left; + //if (eventArgs.ControllerState.IsAnyUpDirectionPressed() && !eventArgs.ControllerState.IsAnyDownDirectionPressed()) inputsPressed |= JoypadInputs.Up; + //if (eventArgs.ControllerState.IsAnyDownDirectionPressed() && !eventArgs.ControllerState.IsAnyUpDirectionPressed()) inputsPressed |= JoypadInputs.Down; + //if (eventArgs.ControllerState.IsAPressed()) inputsPressed |= JoypadInputs.A; + //if (eventArgs.ControllerState.IsXPressed() || eventArgs.ControllerState.IsBPressed()) inputsPressed |= JoypadInputs.B; + //if (eventArgs.ControllerState.IsBackPressed()) inputsPressed |= JoypadInputs.Select; + //if (eventArgs.ControllerState.IsStartPressed()) inputsPressed |= JoypadInputs.Start; } private byte ReadMemory(ushort address) diff --git a/Assets/Plugins/Essgee/Emulation/Machines/GameGear.cs b/Assets/Plugins/Essgee/Emulation/Machines/GameGear.cs index 6b70ad5..2d1e847 100644 --- a/Assets/Plugins/Essgee/Emulation/Machines/GameGear.cs +++ b/Assets/Plugins/Essgee/Emulation/Machines/GameGear.cs @@ -138,10 +138,11 @@ namespace Essgee.Emulation.Machines vdp.EndOfScanline += (s, e) => { - PollInputEventArgs pollInputEventArgs = new PollInputEventArgs(); + PollInputEventArgs pollInputEventArgs = PollInputEventArgs.Create(); OnPollInput(pollInputEventArgs); ParseInput(pollInputEventArgs); - }; + pollInputEventArgs.Release(); + }; } public void SetConfiguration(IConfiguration config) @@ -186,8 +187,10 @@ namespace Essgee.Emulation.Machines currentMasterClockCyclesInFrame = 0; totalMasterClockCyclesInFrame = (int)Math.Round(masterClock / refreshRate); - OnChangeViewport(new ChangeViewportEventArgs(vdp.Viewport)); - } + var eventArgs = ChangeViewportEventArgs.Create(vdp.Viewport); + OnChangeViewport(eventArgs); + eventArgs.Release(); + } private void LoadBootstrap() { @@ -373,13 +376,13 @@ namespace Essgee.Emulation.Machines if (eventArgs.Keyboard.Contains(configuration.ControlsStart)) portCInputsPressed |= IOPortCInputs.Start; /* XInput controller */ - if (eventArgs.ControllerState.IsAnyUpDirectionPressed() && !eventArgs.ControllerState.IsAnyDownDirectionPressed()) portAInputsPressed |= IOPortABInputs.PortAUp; - if (eventArgs.ControllerState.IsAnyDownDirectionPressed() && !eventArgs.ControllerState.IsAnyUpDirectionPressed()) portAInputsPressed |= IOPortABInputs.PortADown; - if (eventArgs.ControllerState.IsAnyLeftDirectionPressed() && !eventArgs.ControllerState.IsAnyRightDirectionPressed()) portAInputsPressed |= IOPortABInputs.PortALeft; - if (eventArgs.ControllerState.IsAnyRightDirectionPressed() && !eventArgs.ControllerState.IsAnyLeftDirectionPressed()) portAInputsPressed |= IOPortABInputs.PortARight; - if (eventArgs.ControllerState.IsAPressed()) portAInputsPressed |= IOPortABInputs.PortATL; - if (eventArgs.ControllerState.IsXPressed() || eventArgs.ControllerState.IsBPressed()) portAInputsPressed |= IOPortABInputs.PortATR; - if (eventArgs.ControllerState.IsStartPressed()) portCInputsPressed |= IOPortCInputs.Start; + //if (eventArgs.ControllerState.IsAnyUpDirectionPressed() && !eventArgs.ControllerState.IsAnyDownDirectionPressed()) portAInputsPressed |= IOPortABInputs.PortAUp; + //if (eventArgs.ControllerState.IsAnyDownDirectionPressed() && !eventArgs.ControllerState.IsAnyUpDirectionPressed()) portAInputsPressed |= IOPortABInputs.PortADown; + //if (eventArgs.ControllerState.IsAnyLeftDirectionPressed() && !eventArgs.ControllerState.IsAnyRightDirectionPressed()) portAInputsPressed |= IOPortABInputs.PortALeft; + //if (eventArgs.ControllerState.IsAnyRightDirectionPressed() && !eventArgs.ControllerState.IsAnyLeftDirectionPressed()) portAInputsPressed |= IOPortABInputs.PortARight; + //if (eventArgs.ControllerState.IsAPressed()) portAInputsPressed |= IOPortABInputs.PortATL; + //if (eventArgs.ControllerState.IsXPressed() || eventArgs.ControllerState.IsBPressed()) portAInputsPressed |= IOPortABInputs.PortATR; + //if (eventArgs.ControllerState.IsStartPressed()) portCInputsPressed |= IOPortCInputs.Start; portIoAB |= (byte)(IOPortABInputs.PortAUp | IOPortABInputs.PortADown | IOPortABInputs.PortALeft | IOPortABInputs.PortARight | IOPortABInputs.PortATL | IOPortABInputs.PortATR | IOPortABInputs.PortBUp | IOPortABInputs.PortBDown); portIoBMisc |= (byte)(IOPortBMiscInputs.PortBLeft | IOPortBMiscInputs.PortBRight | IOPortBMiscInputs.PortBTL | IOPortBMiscInputs.PortBTR | IOPortBMiscInputs.Reset | IOPortBMiscInputs.CartSlotCONTPin | IOPortBMiscInputs.PortATH | IOPortBMiscInputs.PortBTH); diff --git a/Assets/Plugins/Essgee/Emulation/Machines/MasterSystem.cs b/Assets/Plugins/Essgee/Emulation/Machines/MasterSystem.cs index dd0a4aa..4d53c73 100644 --- a/Assets/Plugins/Essgee/Emulation/Machines/MasterSystem.cs +++ b/Assets/Plugins/Essgee/Emulation/Machines/MasterSystem.cs @@ -124,8 +124,8 @@ namespace Essgee.Emulation.Machines public Configuration.MasterSystem configuration { get; private set; } - IEnumerable lastKeysDown; - ControllerState lastControllerState; + List lastKeysDown; + //ControllerState lastControllerState; MouseButtons lastMouseButtons; (int x, int y) lastMousePosition; @@ -146,20 +146,23 @@ namespace Essgee.Emulation.Machines inputDevices[1] = InputDevice.None; lastKeysDown = new List(); - lastControllerState = new ControllerState(); + //lastControllerState = new ControllerState(); vdp.EndOfScanline += (s, e) => { - PollInputEventArgs pollInputEventArgs = new PollInputEventArgs(); + PollInputEventArgs pollInputEventArgs = PollInputEventArgs.Create(); OnPollInput(pollInputEventArgs); - lastKeysDown = pollInputEventArgs.Keyboard; - lastControllerState = pollInputEventArgs.ControllerState; + lastKeysDown.Clear(); + lastKeysDown.AddRange(pollInputEventArgs.Keyboard); + //lastControllerState = pollInputEventArgs.ControllerState; lastMouseButtons = pollInputEventArgs.MouseButtons; lastMousePosition = pollInputEventArgs.MousePosition; HandlePauseButton(); - }; + pollInputEventArgs.Release(); + + }; } public void SetConfiguration(IConfiguration config) @@ -215,9 +218,11 @@ namespace Essgee.Emulation.Machines currentMasterClockCyclesInFrame = 0; totalMasterClockCyclesInFrame = (int)Math.Round(masterClock / RefreshRate); - OnChangeViewport(new ChangeViewportEventArgs(vdp.Viewport)); + var eventArgs = ChangeViewportEventArgs.Create(vdp.Viewport); + OnChangeViewport(eventArgs); + eventArgs.Release(); - inputDevices[0] = configuration.Joypad1DeviceType; + inputDevices[0] = configuration.Joypad1DeviceType; inputDevices[1] = configuration.Joypad2DeviceType; } @@ -376,7 +381,7 @@ namespace Essgee.Emulation.Machines private void HandlePauseButton() { - var pausePressed = lastKeysDown.Contains(configuration.InputPause) || lastControllerState.IsStartPressed(); + var pausePressed = lastKeysDown.Contains(configuration.InputPause);// || lastControllerState.IsStartPressed(); var pauseButtonHeld = pauseButtonToggle && pausePressed; if (pausePressed) { @@ -398,19 +403,32 @@ namespace Essgee.Emulation.Machines break; case InputDevice.Controller: - if (lastKeysDown.Contains(port == 0 ? configuration.Joypad1Up : configuration.Joypad2Up) || (port == 0 && lastControllerState.IsAnyUpDirectionPressed() && !lastControllerState.IsAnyDownDirectionPressed())) - state &= (byte)~ControllerInputs.Up; - if (lastKeysDown.Contains(port == 0 ? configuration.Joypad1Down : configuration.Joypad2Down) || (port == 0 && lastControllerState.IsAnyDownDirectionPressed() && !lastControllerState.IsAnyUpDirectionPressed())) - state &= (byte)~ControllerInputs.Down; - if (lastKeysDown.Contains(port == 0 ? configuration.Joypad1Left : configuration.Joypad2Left) || (port == 0 && lastControllerState.IsAnyLeftDirectionPressed() && !lastControllerState.IsAnyRightDirectionPressed())) - state &= (byte)~ControllerInputs.Left; - if (lastKeysDown.Contains(port == 0 ? configuration.Joypad1Right : configuration.Joypad2Right) || (port == 0 && lastControllerState.IsAnyRightDirectionPressed() && !lastControllerState.IsAnyLeftDirectionPressed())) - state &= (byte)~ControllerInputs.Right; - if (lastKeysDown.Contains(port == 0 ? configuration.Joypad1Button1 : configuration.Joypad2Button1) || (port == 0 && lastControllerState.IsAPressed())) - state &= (byte)~ControllerInputs.TL; - if (lastKeysDown.Contains(port == 0 ? configuration.Joypad1Button2 : configuration.Joypad2Button2) || (port == 0 && (lastControllerState.IsXPressed() || lastControllerState.IsBPressed()))) - state &= (byte)~ControllerInputs.TR; - break; + if (lastKeysDown.Contains(port == 0 ? configuration.Joypad1Up : configuration.Joypad2Up)) + state &= (byte)~ControllerInputs.Up; + if (lastKeysDown.Contains(port == 0 ? configuration.Joypad1Down : configuration.Joypad2Down)) + state &= (byte)~ControllerInputs.Down; + if (lastKeysDown.Contains(port == 0 ? configuration.Joypad1Left : configuration.Joypad2Left)) + state &= (byte)~ControllerInputs.Left; + if (lastKeysDown.Contains(port == 0 ? configuration.Joypad1Right : configuration.Joypad2Right)) + state &= (byte)~ControllerInputs.Right; + if (lastKeysDown.Contains(port == 0 ? configuration.Joypad1Button1 : configuration.Joypad2Button1)) + state &= (byte)~ControllerInputs.TL; + if (lastKeysDown.Contains(port == 0 ? configuration.Joypad1Button2 : configuration.Joypad2Button2)) + state &= (byte)~ControllerInputs.TR; + + //if (lastKeysDown.Contains(port == 0 ? configuration.Joypad1Up : configuration.Joypad2Up) || (port == 0 && lastControllerState.IsAnyUpDirectionPressed() && !lastControllerState.IsAnyDownDirectionPressed())) + // state &= (byte)~ControllerInputs.Up; + //if (lastKeysDown.Contains(port == 0 ? configuration.Joypad1Down : configuration.Joypad2Down) || (port == 0 && lastControllerState.IsAnyDownDirectionPressed() && !lastControllerState.IsAnyUpDirectionPressed())) + // state &= (byte)~ControllerInputs.Down; + //if (lastKeysDown.Contains(port == 0 ? configuration.Joypad1Left : configuration.Joypad2Left) || (port == 0 && lastControllerState.IsAnyLeftDirectionPressed() && !lastControllerState.IsAnyRightDirectionPressed())) + // state &= (byte)~ControllerInputs.Left; + //if (lastKeysDown.Contains(port == 0 ? configuration.Joypad1Right : configuration.Joypad2Right) || (port == 0 && lastControllerState.IsAnyRightDirectionPressed() && !lastControllerState.IsAnyLeftDirectionPressed())) + // state &= (byte)~ControllerInputs.Right; + //if (lastKeysDown.Contains(port == 0 ? configuration.Joypad1Button1 : configuration.Joypad2Button1) || (port == 0 && lastControllerState.IsAPressed())) + // state &= (byte)~ControllerInputs.TL; + //if (lastKeysDown.Contains(port == 0 ? configuration.Joypad1Button2 : configuration.Joypad2Button2) || (port == 0 && (lastControllerState.IsXPressed() || lastControllerState.IsBPressed()))) + // state &= (byte)~ControllerInputs.TR; + break; case InputDevice.Lightgun: if (GetIOControlDirection(port == 0 ? IOControlPort.A : IOControlPort.B, IOControlPin.TH, portIoControl) == IOControlDirection.Input) diff --git a/Assets/Plugins/Essgee/Emulation/Machines/SC3000.cs b/Assets/Plugins/Essgee/Emulation/Machines/SC3000.cs index 82ff3f6..00e9076 100644 --- a/Assets/Plugins/Essgee/Emulation/Machines/SC3000.cs +++ b/Assets/Plugins/Essgee/Emulation/Machines/SC3000.cs @@ -144,10 +144,11 @@ namespace Essgee.Emulation.Machines vdp.EndOfScanline += (s, e) => { - PollInputEventArgs pollInputEventArgs = new PollInputEventArgs(); + PollInputEventArgs pollInputEventArgs = PollInputEventArgs.Create(); OnPollInput(pollInputEventArgs); ParseInput(pollInputEventArgs); - }; + pollInputEventArgs.Release(); + }; } public void SetConfiguration(IConfiguration config) @@ -203,8 +204,10 @@ namespace Essgee.Emulation.Machines currentMasterClockCyclesInFrame = 0; totalMasterClockCyclesInFrame = (int)Math.Round(masterClock / RefreshRate); - OnChangeViewport(new ChangeViewportEventArgs(vdp.Viewport)); - } + var eventArgs = ChangeViewportEventArgs.Create(vdp.Viewport); + OnChangeViewport(eventArgs); + eventArgs.Release(); + } public void Startup() { @@ -360,8 +363,11 @@ namespace Essgee.Emulation.Machines { keyboardMode = !keyboardMode; var modeString = (keyboardMode ? "keyboard" : "controller"); - SendLogMessage(this, new SendLogMessageEventArgs($"Selected {modeString} mode.")); - } + var logeventArgs = SendLogMessageEventArgs.Create($"Selected {modeString} mode."); + SendLogMessage(this, logeventArgs); + logeventArgs.Release(); + + } changeInputButtonPressed = keysDown.Contains(configuration.InputChangeMode); /* Toggle tape playback */ @@ -369,7 +375,9 @@ namespace Essgee.Emulation.Machines { isTapePlaying = !isTapePlaying; var playString = (isTapePlaying ? "playing" : "stopped"); - SendLogMessage(this, new SendLogMessageEventArgs($"Tape is {playString}.")); + var logeventArgs = SendLogMessageEventArgs.Create($"Tape is {playString}."); + SendLogMessage(this, logeventArgs); + logeventArgs.Release(); } tapePlayButtonPressed = keysDown.Contains(configuration.InputPlayTape); @@ -478,12 +486,12 @@ namespace Essgee.Emulation.Machines if (keysDown.Contains(configuration.Joypad2Button2)) portBInputsPressed |= PortBInputs.P2Button2; /* XInput controller */ - if (eventArgs.ControllerState.IsAnyUpDirectionPressed() && !eventArgs.ControllerState.IsAnyDownDirectionPressed()) portAInputsPressed |= PortAInputs.P1Up; - if (eventArgs.ControllerState.IsAnyDownDirectionPressed() && !eventArgs.ControllerState.IsAnyUpDirectionPressed()) portAInputsPressed |= PortAInputs.P1Down; - if (eventArgs.ControllerState.IsAnyLeftDirectionPressed() && !eventArgs.ControllerState.IsAnyRightDirectionPressed()) portAInputsPressed |= PortAInputs.P1Left; - if (eventArgs.ControllerState.IsAnyRightDirectionPressed() && !eventArgs.ControllerState.IsAnyLeftDirectionPressed()) portAInputsPressed |= PortAInputs.P1Right; - if (eventArgs.ControllerState.IsAPressed()) portAInputsPressed |= PortAInputs.P1Button1; - if (eventArgs.ControllerState.IsXPressed() || eventArgs.ControllerState.IsBPressed()) portAInputsPressed |= PortAInputs.P1Button2; + //if (eventArgs.ControllerState.IsAnyUpDirectionPressed() && !eventArgs.ControllerState.IsAnyDownDirectionPressed()) portAInputsPressed |= PortAInputs.P1Up; + //if (eventArgs.ControllerState.IsAnyDownDirectionPressed() && !eventArgs.ControllerState.IsAnyUpDirectionPressed()) portAInputsPressed |= PortAInputs.P1Down; + //if (eventArgs.ControllerState.IsAnyLeftDirectionPressed() && !eventArgs.ControllerState.IsAnyRightDirectionPressed()) portAInputsPressed |= PortAInputs.P1Left; + //if (eventArgs.ControllerState.IsAnyRightDirectionPressed() && !eventArgs.ControllerState.IsAnyLeftDirectionPressed()) portAInputsPressed |= PortAInputs.P1Right; + //if (eventArgs.ControllerState.IsAPressed()) portAInputsPressed |= PortAInputs.P1Button1; + //if (eventArgs.ControllerState.IsXPressed() || eventArgs.ControllerState.IsBPressed()) portAInputsPressed |= PortAInputs.P1Button2; } } diff --git a/Assets/Plugins/Essgee/Emulation/Machines/SG1000.cs b/Assets/Plugins/Essgee/Emulation/Machines/SG1000.cs index 00adea9..732e62d 100644 --- a/Assets/Plugins/Essgee/Emulation/Machines/SG1000.cs +++ b/Assets/Plugins/Essgee/Emulation/Machines/SG1000.cs @@ -130,10 +130,11 @@ namespace Essgee.Emulation.Machines vdp.EndOfScanline += (s, e) => { - PollInputEventArgs pollInputEventArgs = new PollInputEventArgs(); + PollInputEventArgs pollInputEventArgs = PollInputEventArgs.Create(); OnPollInput(pollInputEventArgs); ParseInput(pollInputEventArgs); - }; + pollInputEventArgs.Release(); + }; } public void SetConfiguration(IConfiguration config) @@ -189,8 +190,11 @@ namespace Essgee.Emulation.Machines currentMasterClockCyclesInFrame = 0; totalMasterClockCyclesInFrame = (int)Math.Round(masterClock / RefreshRate); - OnChangeViewport(new ChangeViewportEventArgs(vdp.Viewport)); - } + var eventArgs = ChangeViewportEventArgs.Create(vdp.Viewport); + OnChangeViewport(eventArgs); + eventArgs.Release(); + + } public void Startup() { @@ -346,12 +350,12 @@ namespace Essgee.Emulation.Machines if (keysDown.Contains(configuration.Joypad2Button2)) portIoBMiscPressed |= PortIoBMiscValues.P2Button2; /* XInput controller */ - if (eventArgs.ControllerState.IsAnyUpDirectionPressed() && !eventArgs.ControllerState.IsAnyDownDirectionPressed()) portIoABPressed |= PortIoABValues.P1Up; - if (eventArgs.ControllerState.IsAnyDownDirectionPressed() && !eventArgs.ControllerState.IsAnyUpDirectionPressed()) portIoABPressed |= PortIoABValues.P1Down; - if (eventArgs.ControllerState.IsAnyLeftDirectionPressed() && !eventArgs.ControllerState.IsAnyRightDirectionPressed()) portIoABPressed |= PortIoABValues.P1Left; - if (eventArgs.ControllerState.IsAnyRightDirectionPressed() && !eventArgs.ControllerState.IsAnyLeftDirectionPressed()) portIoABPressed |= PortIoABValues.P1Right; - if (eventArgs.ControllerState.IsAPressed()) portIoABPressed |= PortIoABValues.P1Button1; - if (eventArgs.ControllerState.IsXPressed() || eventArgs.ControllerState.IsBPressed()) portIoABPressed |= PortIoABValues.P1Button2; + //if (eventArgs.ControllerState.IsAnyUpDirectionPressed() && !eventArgs.ControllerState.IsAnyDownDirectionPressed()) portIoABPressed |= PortIoABValues.P1Up; + //if (eventArgs.ControllerState.IsAnyDownDirectionPressed() && !eventArgs.ControllerState.IsAnyUpDirectionPressed()) portIoABPressed |= PortIoABValues.P1Down; + //if (eventArgs.ControllerState.IsAnyLeftDirectionPressed() && !eventArgs.ControllerState.IsAnyRightDirectionPressed()) portIoABPressed |= PortIoABValues.P1Left; + //if (eventArgs.ControllerState.IsAnyRightDirectionPressed() && !eventArgs.ControllerState.IsAnyLeftDirectionPressed()) portIoABPressed |= PortIoABValues.P1Right; + //if (eventArgs.ControllerState.IsAPressed()) portIoABPressed |= PortIoABValues.P1Button1; + //if (eventArgs.ControllerState.IsXPressed() || eventArgs.ControllerState.IsBPressed()) portIoABPressed |= PortIoABValues.P1Button2; portIoBMiscPressed |= (PortIoBMiscValues.IC21Pin6 | PortIoBMiscValues.IC21Pin10 | PortIoBMiscValues.IC21Pin13); /* Unused, always 1 */ } diff --git a/Assets/Plugins/Essgee/Emulation/Video/Nintendo/DMGVideo.cs b/Assets/Plugins/Essgee/Emulation/Video/Nintendo/DMGVideo.cs index 9840b5f..16d3930 100644 --- a/Assets/Plugins/Essgee/Emulation/Video/Nintendo/DMGVideo.cs +++ b/Assets/Plugins/Essgee/Emulation/Video/Nintendo/DMGVideo.cs @@ -387,7 +387,9 @@ namespace Essgee.Emulation.Video.Nintendo if (cycleCount == clockCyclesPerLine) EndHBlank(); } - protected virtual void EndHBlank() + + GCHandle? lasyRenderHandle; + protected virtual void EndHBlank() { /* End of scanline reached */ OnEndOfScanline(EventArgs.Empty); @@ -409,14 +411,19 @@ namespace Essgee.Emulation.Video.Nintendo if (skipFrames > 0) skipFrames--; - /* Submit screen for rendering */ - + /* Submit screen for rendering */ // 固定数组,防止垃圾回收器移动它 var bitmapcolorRect_handle = GCHandle.Alloc(outputFramebuffer.Clone() as byte[], GCHandleType.Pinned); // 获取数组的指针 IntPtr mFrameDataPtr = bitmapcolorRect_handle.AddrOfPinnedObject(); - OnRenderScreen(new RenderScreenEventArgs(displayActiveWidth, displayActiveHeight, mFrameDataPtr)); + var eventArgs = RenderScreenEventArgs.Create(displayActiveWidth, displayActiveHeight, mFrameDataPtr); + OnRenderScreen(eventArgs); + eventArgs.Release(); + if (lasyRenderHandle != null) + lasyRenderHandle.Value.Free(); + lasyRenderHandle = bitmapcolorRect_handle; + //OnRenderScreen(new RenderScreenEventArgs(displayActiveWidth, displayActiveHeight, outputFramebuffer.Clone() as byte[])); } else diff --git a/Assets/Plugins/Essgee/Emulation/Video/SegaGGVDP.cs b/Assets/Plugins/Essgee/Emulation/Video/SegaGGVDP.cs index 061091b..3f77844 100644 --- a/Assets/Plugins/Essgee/Emulation/Video/SegaGGVDP.cs +++ b/Assets/Plugins/Essgee/Emulation/Video/SegaGGVDP.cs @@ -53,17 +53,23 @@ namespace Essgee.Emulation.Video UpdateResolution(); } - protected override void PrepareRenderScreen() - { - - + GCHandle? lasyRenderHandle; + protected override void PrepareRenderScreen() + { // 固定数组,防止垃圾回收器移动它 var bitmapcolorRect_handle = GCHandle.Alloc(outputFramebuffer.Clone() as byte[], GCHandleType.Pinned); // 获取数组的指针 IntPtr mFrameDataPtr = bitmapcolorRect_handle.AddrOfPinnedObject(); - OnRenderScreen(new RenderScreenEventArgs(numVisiblePixels, numVisibleScanlines, mFrameDataPtr)); + + var eventArgs = RenderScreenEventArgs.Create(numVisiblePixels, numVisibleScanlines, mFrameDataPtr); + OnRenderScreen(eventArgs); + eventArgs.Release(); + if (lasyRenderHandle != null) + lasyRenderHandle.Value.Free(); + lasyRenderHandle = bitmapcolorRect_handle; + //OnRenderScreen(new RenderScreenEventArgs(Viewport.Width, Viewport.Height, outputFramebuffer.Clone() as byte[])); - } + } private bool ModifyAndVerifyCoordinates(ref int x, ref int y) { diff --git a/Assets/Plugins/Essgee/Emulation/Video/SegaSMSVDP.cs b/Assets/Plugins/Essgee/Emulation/Video/SegaSMSVDP.cs index a2d02f6..2fc6646 100644 --- a/Assets/Plugins/Essgee/Emulation/Video/SegaSMSVDP.cs +++ b/Assets/Plugins/Essgee/Emulation/Video/SegaSMSVDP.cs @@ -445,17 +445,23 @@ namespace Essgee.Emulation.Video } } - protected override void PrepareRenderScreen() + GCHandle? lasyRenderHandle; + protected override void PrepareRenderScreen() { - - // 固定数组,防止垃圾回收器移动它 var bitmapcolorRect_handle = GCHandle.Alloc(outputFramebuffer.Clone() as byte[], GCHandleType.Pinned); // 获取数组的指针 IntPtr mFrameDataPtr = bitmapcolorRect_handle.AddrOfPinnedObject(); - OnRenderScreen(new RenderScreenEventArgs(numVisiblePixels, numVisibleScanlines, mFrameDataPtr)); + + var eventArgs = RenderScreenEventArgs.Create(numVisiblePixels, numVisibleScanlines, mFrameDataPtr); + OnRenderScreen(eventArgs); + eventArgs.Release(); + if (lasyRenderHandle != null) + lasyRenderHandle.Value.Free(); + lasyRenderHandle = bitmapcolorRect_handle; + //OnRenderScreen(new RenderScreenEventArgs(numVisiblePixels, numVisibleScanlines, outputFramebuffer.Clone() as byte[])); - } + } protected override byte ReadVram(ushort address) { diff --git a/Assets/Plugins/Essgee/Emulation/Video/TMS99xxA.cs b/Assets/Plugins/Essgee/Emulation/Video/TMS99xxA.cs index 186d237..50396c8 100644 --- a/Assets/Plugins/Essgee/Emulation/Video/TMS99xxA.cs +++ b/Assets/Plugins/Essgee/Emulation/Video/TMS99xxA.cs @@ -304,9 +304,11 @@ namespace Essgee.Emulation.Video pixelRightBorder = (pixelActiveDisplay + horizontalActiveDisplaySize); numVisiblePixels = (leftBorderSize + horizontalActiveDisplaySize + rightBorderSize); + var eventArgs = SizeScreenEventArgs.Create(numVisiblePixels, numVisibleScanlines); + OnSizeScreen(eventArgs); + eventArgs.Release(); - OnSizeScreen(new SizeScreenEventArgs(numVisiblePixels, numVisibleScanlines)); - } + } public virtual void Step(int clockCyclesInStep) { @@ -341,15 +343,19 @@ namespace Essgee.Emulation.Video } } - protected virtual void PrepareRenderScreen() + GCHandle? lasyRenderHandle; + protected virtual void PrepareRenderScreen() { - // 固定数组,防止垃圾回收器移动它 var bitmapcolorRect_handle = GCHandle.Alloc(outputFramebuffer.Clone() as byte[], GCHandleType.Pinned); // 获取数组的指针 IntPtr mFrameDataPtr = bitmapcolorRect_handle.AddrOfPinnedObject(); - OnRenderScreen(new RenderScreenEventArgs(numVisiblePixels, numVisibleScanlines, mFrameDataPtr)); - + var eventArgs = RenderScreenEventArgs.Create(numVisiblePixels, numVisibleScanlines, mFrameDataPtr); + OnRenderScreen(eventArgs); + eventArgs.Release(); + if (lasyRenderHandle != null) + lasyRenderHandle.Value.Free(); + lasyRenderHandle = bitmapcolorRect_handle; //OnRenderScreen(new RenderScreenEventArgs(numVisiblePixels, numVisibleScanlines, outputFramebuffer.Clone() as byte[])); } diff --git a/Assets/Plugins/Essgee/EssgeeLogger.cs b/Assets/Plugins/Essgee/EssgeeLogger.cs index ebd63b2..24a49fd 100644 --- a/Assets/Plugins/Essgee/EssgeeLogger.cs +++ b/Assets/Plugins/Essgee/EssgeeLogger.cs @@ -1,3 +1,4 @@ +using System; using UnityEngine; public interface IEssgeeLogger @@ -34,4 +35,11 @@ public static class EssgeeLogger essgeeLogger.Warning(message); } + internal static void Assert(bool condition, string message) + { + if (!condition) + { + essgeeLogger.Debug(message); + } + } } \ No newline at end of file diff --git a/Assets/Plugins/Essgee/EventArguments/ChangeViewportEventArgs.cs b/Assets/Plugins/Essgee/EventArguments/ChangeViewportEventArgs.cs index 4428cdf..3d6cea7 100644 --- a/Assets/Plugins/Essgee/EventArguments/ChangeViewportEventArgs.cs +++ b/Assets/Plugins/Essgee/EventArguments/ChangeViewportEventArgs.cs @@ -1,18 +1,28 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Essgee.EventArguments { - public class ChangeViewportEventArgs : EventArgs + public class ChangeViewportEventArgs : EventArgs { public (int X, int Y, int Width, int Height) Viewport { get; private set; } - public ChangeViewportEventArgs((int, int, int, int) viewport) - { - Viewport = viewport; - } - } + //public ChangeViewportEventArgs((int, int, int, int) viewport) + //{ + // Viewport = viewport; + //} + + public static ChangeViewportEventArgs Create((int, int, int, int) viewport) + { + var eventArgs = ObjectPoolAuto.Acquire(); + eventArgs.Viewport = viewport; + return eventArgs; + } + } + public static class ChangeViewportEventArgsEx + { + public static void Release(this ChangeViewportEventArgs eventArgs) + { + ObjectPoolAuto.Release(eventArgs); + } + } } diff --git a/Assets/Plugins/Essgee/EventArguments/EnqueueSamplesEventArgs.cs b/Assets/Plugins/Essgee/EventArguments/EnqueueSamplesEventArgs.cs index e485702..df2faeb 100644 --- a/Assets/Plugins/Essgee/EventArguments/EnqueueSamplesEventArgs.cs +++ b/Assets/Plugins/Essgee/EventArguments/EnqueueSamplesEventArgs.cs @@ -1,24 +1,41 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Essgee.EventArguments { - public class EnqueueSamplesEventArgs : EventArgs + public class EnqueueSamplesEventArgs : EventArgs { public int NumChannels { get; set; } public short[][] ChannelSamples { get; set; } public bool[] IsChannelMuted { get; set; } public short[] MixedSamples { get; set; } - public EnqueueSamplesEventArgs(int numChannels, short[][] channelSamples, bool[] isMuted, short[] mixedSamples) - { - NumChannels = numChannels; - ChannelSamples = channelSamples; - IsChannelMuted = isMuted; - MixedSamples = mixedSamples; - } - } + //public EnqueueSamplesEventArgs(int numChannels, short[][] channelSamples, bool[] isMuted, short[] mixedSamples) + //{ + // NumChannels = numChannels; + // ChannelSamples = channelSamples; + // IsChannelMuted = isMuted; + // MixedSamples = mixedSamples; + //} + + public static EnqueueSamplesEventArgs Create(int numChannels, short[][] channelSamples, bool[] isMuted, short[] mixedSamples) + { + var eventArgs = ObjectPoolAuto.Acquire(); + eventArgs.NumChannels = numChannels; + eventArgs.ChannelSamples = channelSamples; + eventArgs.IsChannelMuted = isMuted; + eventArgs.MixedSamples = mixedSamples; + return eventArgs; + } + } + public static class EnqueueSamplesEventArgsEx + { + public static void Release(this EnqueueSamplesEventArgs eventArgs) + { + eventArgs.NumChannels = 1; + eventArgs.ChannelSamples = null; + eventArgs.IsChannelMuted = null; + eventArgs.MixedSamples = null; + ObjectPoolAuto.Release(eventArgs); + } + } } diff --git a/Assets/Plugins/Essgee/EventArguments/PollInputEventArgs.cs b/Assets/Plugins/Essgee/EventArguments/PollInputEventArgs.cs index 05029e7..327782a 100644 --- a/Assets/Plugins/Essgee/EventArguments/PollInputEventArgs.cs +++ b/Assets/Plugins/Essgee/EventArguments/PollInputEventArgs.cs @@ -5,22 +5,49 @@ using System.Collections.Generic; namespace Essgee.EventArguments { public class PollInputEventArgs : EventArgs - { - public IEnumerable Keyboard { get; set; } + { + public List Keyboard { get; set; } - public MouseButtons MouseButtons { get; set; } - public (int X, int Y) MousePosition { get; set; } + public MouseButtons MouseButtons { get; set; } + public (int X, int Y) MousePosition { get; set; } - public ControllerState ControllerState { get; set; } + //public ControllerState ControllerState { get; set; } - public PollInputEventArgs() - { - Keyboard = new List(); + //public PollInputEventArgs() + //{ + // Keyboard = new List(); - MouseButtons = MouseButtons.None; - MousePosition = (0, 0); + // MouseButtons = MouseButtons.None; + // MousePosition = (0, 0); - ControllerState = new ControllerState(); - } - } + // ControllerState = new ControllerState(); + //} + + public static PollInputEventArgs Create() + { + var eventArgs = ObjectPoolAuto.Acquire(); + //eventArgs.Keyboard = new List(); + eventArgs.Keyboard = ObjectPoolAuto.AcquireList(); + eventArgs.MouseButtons = MouseButtons.None; + eventArgs.MousePosition = (0, 0); + + //eventArgs.ControllerState = new ControllerState(); + //eventArgs.ControllerState = ObjectPoolAuto.Acquire(); + return eventArgs; + } + } + public static class PollInputEventArgsEx + { + public static void Release(this PollInputEventArgs eventArgs) + { + ObjectPoolAuto.Release(eventArgs.Keyboard); + eventArgs.Keyboard = null; + eventArgs.MouseButtons = MouseButtons.None; + eventArgs.MousePosition = (0, 0); + //ObjectPoolAuto.Release(eventArgs.ControllerState); + //eventArgs.ControllerState = null; + + ObjectPoolAuto.Release(eventArgs); + } + } } diff --git a/Assets/Plugins/Essgee/EventArguments/RenderScreenEventArgs.cs b/Assets/Plugins/Essgee/EventArguments/RenderScreenEventArgs.cs index efd776c..300d3c7 100644 --- a/Assets/Plugins/Essgee/EventArguments/RenderScreenEventArgs.cs +++ b/Assets/Plugins/Essgee/EventArguments/RenderScreenEventArgs.cs @@ -1,25 +1,37 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Essgee.EventArguments { - public class RenderScreenEventArgs : EventArgs + public class RenderScreenEventArgs : EventArgs { public int Width { get; private set; } public int Height { get; private set; } //public byte[] FrameData { get; private set; } public IntPtr FrameDataPtr { get; private set; } + // public RenderScreenEventArgs(int width, int height, IntPtr ptr) + //{ + // Width = width; + // Height = height; + // //FrameData = data; + // FrameDataPtr = ptr; + //} - public RenderScreenEventArgs(int width, int height, IntPtr ptr) - { - Width = width; - Height = height; - //FrameData = data; - FrameDataPtr = ptr; - } - } + public static RenderScreenEventArgs Create(int width, int height, IntPtr ptr) + { + var eventArgs = ObjectPoolAuto.Acquire(); + eventArgs.Width = width; + eventArgs.Height = height; + //FrameData = data; + eventArgs.FrameDataPtr = ptr; + return eventArgs; + } + } + public static class RenderScreenEventArgsEx + { + public static void Release(this RenderScreenEventArgs eventArgs) + { + ObjectPoolAuto.Release(eventArgs); + } + } } diff --git a/Assets/Plugins/Essgee/EventArguments/SaveExtraDataEventArgs.cs b/Assets/Plugins/Essgee/EventArguments/SaveExtraDataEventArgs.cs index 50f3fa0..a86b24a 100644 --- a/Assets/Plugins/Essgee/EventArguments/SaveExtraDataEventArgs.cs +++ b/Assets/Plugins/Essgee/EventArguments/SaveExtraDataEventArgs.cs @@ -1,25 +1,29 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Essgee.EventArguments { - public class SaveExtraDataEventArgs : EventArgs + public class SaveExtraDataEventArgs : EventArgs { public ExtraDataTypes DataType { get; private set; } public ExtraDataOptions Options { get; private set; } - public string Description { get; private set; } public object Data { get; private set; } - public SaveExtraDataEventArgs(ExtraDataTypes type, ExtraDataOptions option, string desc, object data) - { - DataType = type; - Options = option; - Description = desc; - Data = data; - } - } + public static SaveExtraDataEventArgs Create(ExtraDataTypes type, ExtraDataOptions option, string desc, object data) + { + var eventArgs = ObjectPoolAuto.Acquire(); + eventArgs.DataType = type; + eventArgs.Options = option; + eventArgs.Description = desc; + eventArgs.Data = data; + return eventArgs; + } + } + public static class SaveExtraDataEventArgsEx + { + public static void Release(this SaveExtraDataEventArgs eventArgs) + { + ObjectPoolAuto.Release(eventArgs); + } + } } diff --git a/Assets/Plugins/Essgee/EventArguments/SendLogMessageEventArgs.cs b/Assets/Plugins/Essgee/EventArguments/SendLogMessageEventArgs.cs index 00c664c..ec1a32c 100644 --- a/Assets/Plugins/Essgee/EventArguments/SendLogMessageEventArgs.cs +++ b/Assets/Plugins/Essgee/EventArguments/SendLogMessageEventArgs.cs @@ -1,18 +1,24 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Essgee.EventArguments { - public class SendLogMessageEventArgs : EventArgs + public class SendLogMessageEventArgs : EventArgs { public string Message { get; private set; } - public SendLogMessageEventArgs(string message) + + public static SendLogMessageEventArgs Create(string message) { - Message = message; - } - } + var eventArgs = ObjectPoolAuto.Acquire(); + eventArgs.Message = message; + return eventArgs; + } + } + public static class SendLogMessageEventArgsEx + { + public static void Release(this SendLogMessageEventArgs eventArgs) + { + ObjectPoolAuto.Release(eventArgs); + } + } } diff --git a/Assets/Plugins/Essgee/EventArguments/SizeScreenEventArgs.cs b/Assets/Plugins/Essgee/EventArguments/SizeScreenEventArgs.cs index 25f36a3..6ecd22f 100644 --- a/Assets/Plugins/Essgee/EventArguments/SizeScreenEventArgs.cs +++ b/Assets/Plugins/Essgee/EventArguments/SizeScreenEventArgs.cs @@ -1,20 +1,25 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Essgee.EventArguments { - public class SizeScreenEventArgs : EventArgs + public class SizeScreenEventArgs : EventArgs { public int Width { get; private set; } public int Height { get; private set; } - public SizeScreenEventArgs(int width, int height) - { - Width = width; - Height = height; - } - } + public static SizeScreenEventArgs Create(int width, int height) + { + var eventArgs = ObjectPoolAuto.Acquire(); + eventArgs.Width = width; + eventArgs.Height = height; + return eventArgs; + } + } + public static class SizeScreenEventArgsEx + { + public static void Release(this SizeScreenEventArgs eventArgs) + { + ObjectPoolAuto.Release(eventArgs); + } + } } diff --git a/Assets/Plugins/Essgee/ObjectPoolAuto.cs b/Assets/Plugins/Essgee/ObjectPoolAuto.cs new file mode 100644 index 0000000..c55fd88 --- /dev/null +++ b/Assets/Plugins/Essgee/ObjectPoolAuto.cs @@ -0,0 +1,399 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using System.Text; + +internal static class ObjectPoolAuto +{ + /************************************************************************************************************************/ + + /// + /// 获取或者创建一个新的 + /// + /// Remember to 需要回收参见这个 + public static T Acquire() + where T : class, new() + => ObjectPool.Acquire(); + + /// + /// 获取或者创建一个新的 + /// + /// Remember to 需要回收参见这个 + public static void Acquire(out T item) + where T : class, new() + => item = ObjectPool.Acquire(); + /************************************************************************************************************************/ + + /// + /// 回收对象 + /// + public static void Release(T item) + where T : class, new() + => ObjectPool.Release(item); + + /// + /// 回收对象 + /// + public static void Release(ref T item) where T : class, new() + { + if (item != null) + { + ObjectPool.Release(item); + item = null; + } + } + + /************************************************************************************************************************/ + public const string + NotClearError = " They must be cleared before being released to the pool and not modified after that."; + + /************************************************************************************************************************/ + + /// + /// 获取或创建List + /// + /// Remember to 回收参见此方法 + public static List AcquireList() + { + var list = ObjectPool>.Acquire(); + EssgeeLogger.Assert(list.Count == 0, "A pooled list is not empty." + NotClearError); + return list; + } + + /// + /// 回收List + /// + public static void Release(List list) + { + list.Clear(); + ObjectPool>.Release(list); + } + + /************************************************************************************************************************/ + + /// + /// 获取或创建Queue + /// + /// Remember to 回收参见此方法 + public static Queue AcquireQueue() + { + var queue = ObjectPool>.Acquire(); + EssgeeLogger.Assert(queue.Count == 0, "A pooled list is not empty." + NotClearError); + return queue; + } + + /// + /// 回收Queue + /// + public static void Release(Queue list) + { + list.Clear(); + ObjectPool>.Release(list); + } + + + /************************************************************************************************************************/ + + /// + /// 获取或创建HashSet + /// + public static HashSet AcquireSet() + { + var set = ObjectPool>.Acquire(); + EssgeeLogger.Assert(set.Count == 0, "A pooled set is not empty." + NotClearError); + return set; + } + + /// + /// 释放HashSet + /// + public static void Release(HashSet set) + { + set.Clear(); + ObjectPool>.Release(set); + } + + /************************************************************************************************************************/ + + /// + /// 获取一个字符串StringBuilder + /// + /// Remember to 回收参见这个 + public static StringBuilder AcquireStringBuilder() + { + var builder = ObjectPool.Acquire(); + EssgeeLogger.Assert(builder.Length == 0, $"A pooled {nameof(StringBuilder)} is not empty." + NotClearError); + return builder; + } + + /// + /// 回收 StringBuilder + /// + public static void Release(StringBuilder builder) + { + builder.Length = 0; + ObjectPool.Release(builder); + } + + /// + /// 回收 StringBuilder + /// + public static string ReleaseToString(this StringBuilder builder) + { + var result = builder.ToString(); + Release(builder); + return result; + } + + /************************************************************************************************************************/ + + private static class Cache + { + public static readonly Dictionary, T>> + Results = new Dictionary, T>>(); + } + + /// + /// 此方法主要用于频繁绘制缓存,比如说GUI绘制 + /// + public static T GetCachedResult(Func function) + { + var method = function.Method; + if (!Cache.Results.TryGetValue(method, out var result)) + { + + result = new KeyValuePair, T>(function, function()); + Cache.Results.Add(method, result); + } + else if (result.Key != function) + { + EssgeeLogger.WriteLine( + $"{nameof(GetCachedResult)}<{typeof(T).Name}>" + + $" was previously called on {method.Name} with a different target." + + " This likely means that a new delegate is being passed into every call" + + " so it can't actually return the same cached object."); + } + + return result.Value; + } + + /************************************************************************************************************************/ + + public static class Disposable + { + /************************************************************************************************************************/ + + /// + /// Calls to get a spare if + /// + public static IDisposable Acquire(out T item) + where T : class, new() + => ObjectPool.Disposable.Acquire(out item); + + /************************************************************************************************************************/ + + /// + /// Calls to get a spare if + /// + public static IDisposable AcquireList(out List list) + { + var disposable = ObjectPool>.Disposable.Acquire(out list, onRelease: (l) => l.Clear()); + EssgeeLogger.Assert(list.Count == 0, "A pooled list is not empty." + NotClearError); + return disposable; + } + + /************************************************************************************************************************/ + + /// + /// Calls to get a spare if + /// + public static IDisposable AcquireSet(out HashSet set) + { + var disposable = ObjectPool>.Disposable.Acquire(out set, onRelease: (s) => s.Clear()); + EssgeeLogger.Assert(set.Count == 0, "A pooled set is not empty." + NotClearError); + return disposable; + } + + /************************************************************************************************************************/ + } + /************************************************************************************************************************/ +} + +public static class ObjectPool where T : class, new() +{ + /************************************************************************************************************************/ + + private static readonly List + Items = new List(); + + /************************************************************************************************************************/ + + /// The number of spare items currently in the pool. + public static int Count + { + get => Items.Count; + set + { + var count = Items.Count; + if (count < value) + { + if (Items.Capacity < value) + Items.Capacity = NextPowerOfTwo(value); + + do + { + Items.Add(new T()); + count++; + } + while (count < value); + + } + else if (count > value) + { + Items.RemoveRange(value, count - value); + } + } + } + + public static int NextPowerOfTwo(int value) + { + if (value <= 0) + { + throw new ArgumentException("Value must be greater than zero."); + } + + int powerOfTwo = 1; + while (powerOfTwo < value) + { + powerOfTwo <<= 1; // equivalent to multiplying by 2 + } + + return powerOfTwo; + } + + /************************************************************************************************************************/ + + /// + /// If the is less than the specified value, this method increases it to that value by + /// creating new objects. + /// + public static void SetMinCount(int count) + { + if (Count < count) + Count = count; + } + + /************************************************************************************************************************/ + + /// The of the internal list of spare items. + public static int Capacity + { + get => Items.Capacity; + set + { + if (Items.Count > value) + Items.RemoveRange(value, Items.Count - value); + Items.Capacity = value; + } + } + + /************************************************************************************************************************/ + + /// Returns a spare item if there are any, or creates a new one. + /// Remember to it when you are done. + public static T Acquire() + { + var count = Items.Count; + if (count == 0) + { + return new T(); + } + else + { + count--; + var item = Items[count]; + Items.RemoveAt(count); + + return item; + } + } + + /************************************************************************************************************************/ + + /// Adds the `item` to the list of spares so it can be reused. + public static void Release(T item) + { + Items.Add(item); + + } + + /************************************************************************************************************************/ + + /// Returns a description of the state of this pool. + public static string GetDetails() + { + return + $"{typeof(T).Name}" + + $" ({nameof(Count)} = {Items.Count}" + + $", {nameof(Capacity)} = {Items.Capacity}" + + ")"; + } + + /************************************************************************************************************************/ + + /// + /// An system to allow pooled objects to be acquired and released within using + /// statements instead of needing to manually release everything. + /// + public sealed class Disposable : IDisposable + { + /************************************************************************************************************************/ + + private static readonly List LazyStack = new List(); + + private static int _ActiveDisposables; + + private T _Item; + private Action _OnRelease; + + /************************************************************************************************************************/ + + private Disposable() { } + + /// + /// Calls to set the `item` and returns an + /// that will call on the `item` when disposed. + /// + public static IDisposable Acquire(out T item, Action onRelease = null) + { + Disposable disposable; + + if (LazyStack.Count <= _ActiveDisposables) + { + LazyStack.Add(disposable = new Disposable()); + } + else + { + disposable = LazyStack[_ActiveDisposables]; + } + + _ActiveDisposables++; + + disposable._Item = item = ObjectPool.Acquire(); + disposable._OnRelease = onRelease; + return disposable; + } + + /************************************************************************************************************************/ + + void IDisposable.Dispose() + { + _OnRelease?.Invoke(_Item); + Release(_Item); + _ActiveDisposables--; + } + + /************************************************************************************************************************/ + } +} + diff --git a/Assets/Plugins/Essgee/ObjectPoolAuto.cs.meta b/Assets/Plugins/Essgee/ObjectPoolAuto.cs.meta new file mode 100644 index 0000000..92543ea --- /dev/null +++ b/Assets/Plugins/Essgee/ObjectPoolAuto.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 401c483d18aba7c45b7ae47fc4a5b19a \ No newline at end of file diff --git a/Assets/Plugins/Essgee/Utilities/XInput/Controller.cs b/Assets/Plugins/Essgee/Utilities/XInput/Controller.cs index f959b27..38af1c5 100644 --- a/Assets/Plugins/Essgee/Utilities/XInput/Controller.cs +++ b/Assets/Plugins/Essgee/Utilities/XInput/Controller.cs @@ -1,12 +1,8 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Essgee.Utilities.XInput { - public class Controller + public class Controller { XInputState inputStatesCurrent, inputStatesPrev; bool timedVibrationEnabled; @@ -64,17 +60,17 @@ namespace Essgee.Utilities.XInput throw new Exception(string.Format("Error code {0}", (int)result)); } - public ControllerState GetControllerState() - { - return new ControllerState - { - Buttons = inputStatesCurrent.Gamepad.Buttons, - LeftThumbstick = new ThumbstickPosition(inputStatesCurrent.Gamepad.sThumbLX / 32768.0f, inputStatesCurrent.Gamepad.sThumbLY / 32768.0f), - RightThumbstick = new ThumbstickPosition(inputStatesCurrent.Gamepad.sThumbRX / 32768.0f, inputStatesCurrent.Gamepad.sThumbRY / 32768.0f), - LeftTrigger = (inputStatesCurrent.Gamepad.bLeftTrigger / 255.0f), - RightTrigger = (inputStatesCurrent.Gamepad.bRightTrigger / 255.0f) - }; - } + //public ControllerState GetControllerState() + //{ + // return new ControllerState + // { + // Buttons = inputStatesCurrent.Gamepad.Buttons, + // LeftThumbstick = new ThumbstickPosition(inputStatesCurrent.Gamepad.sThumbLX / 32768.0f, inputStatesCurrent.Gamepad.sThumbLY / 32768.0f), + // RightThumbstick = new ThumbstickPosition(inputStatesCurrent.Gamepad.sThumbRX / 32768.0f, inputStatesCurrent.Gamepad.sThumbRY / 32768.0f), + // LeftTrigger = (inputStatesCurrent.Gamepad.bLeftTrigger / 255.0f), + // RightTrigger = (inputStatesCurrent.Gamepad.bRightTrigger / 255.0f) + // }; + //} public bool IsDPadUpPressed() { diff --git a/Assets/Plugins/Essgee/Utilities/XInput/ControllerState.cs b/Assets/Plugins/Essgee/Utilities/XInput/ControllerState.cs index 0883f6d..57c2cba 100644 --- a/Assets/Plugins/Essgee/Utilities/XInput/ControllerState.cs +++ b/Assets/Plugins/Essgee/Utilities/XInput/ControllerState.cs @@ -1,122 +1,116 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +//namespace Essgee.Utilities.XInput +//{ +// public class ControllerState +// { +// public Buttons Buttons { get; set; } +// public ThumbstickPosition LeftThumbstick { get; set; } +// public ThumbstickPosition RightThumbstick { get; set; } +// public float LeftTrigger { get; set; } +// public float RightTrigger { get; set; } -namespace Essgee.Utilities.XInput -{ - public class ControllerState - { - public Buttons Buttons { get; set; } - public ThumbstickPosition LeftThumbstick { get; set; } - public ThumbstickPosition RightThumbstick { get; set; } - public float LeftTrigger { get; set; } - public float RightTrigger { get; set; } +// public bool IsConnected { get; set; } +// public int UserIndex { get; set; } - public bool IsConnected { get; set; } - public int UserIndex { get; set; } +// public ControllerState() +// { +// Buttons = Buttons.None; +// LeftThumbstick = new ThumbstickPosition(0.0f, 0.0f); +// RightThumbstick = new ThumbstickPosition(0.0f, 0.0f); +// LeftTrigger = 0.0f; +// RightTrigger = 0.0f; - public ControllerState() - { - Buttons = Buttons.None; - LeftThumbstick = new ThumbstickPosition(0.0f, 0.0f); - RightThumbstick = new ThumbstickPosition(0.0f, 0.0f); - LeftTrigger = 0.0f; - RightTrigger = 0.0f; +// IsConnected = false; +// UserIndex = -1; +// } - IsConnected = false; - UserIndex = -1; - } +// public bool IsAnyUpDirectionPressed() +// { +// return IsDPadUpPressed() || LeftThumbstick.Y > 0.5f; +// } - public bool IsAnyUpDirectionPressed() - { - return IsDPadUpPressed() || LeftThumbstick.Y > 0.5f; - } +// public bool IsAnyDownDirectionPressed() +// { +// return IsDPadDownPressed() || LeftThumbstick.Y < -0.5f; +// } - public bool IsAnyDownDirectionPressed() - { - return IsDPadDownPressed() || LeftThumbstick.Y < -0.5f; - } +// public bool IsAnyLeftDirectionPressed() +// { +// return IsDPadLeftPressed() || LeftThumbstick.X < -0.5f; +// } - public bool IsAnyLeftDirectionPressed() - { - return IsDPadLeftPressed() || LeftThumbstick.X < -0.5f; - } +// public bool IsAnyRightDirectionPressed() +// { +// return IsDPadRightPressed() || LeftThumbstick.X > 0.5f; +// } - public bool IsAnyRightDirectionPressed() - { - return IsDPadRightPressed() || LeftThumbstick.X > 0.5f; - } +// public bool IsDPadUpPressed() +// { +// return Buttons.HasFlag(Buttons.DPadUp); +// } - public bool IsDPadUpPressed() - { - return Buttons.HasFlag(Buttons.DPadUp); - } +// public bool IsDPadDownPressed() +// { +// return Buttons.HasFlag(Buttons.DPadDown); +// } - public bool IsDPadDownPressed() - { - return Buttons.HasFlag(Buttons.DPadDown); - } +// public bool IsDPadLeftPressed() +// { +// return Buttons.HasFlag(Buttons.DPadLeft); +// } - public bool IsDPadLeftPressed() - { - return Buttons.HasFlag(Buttons.DPadLeft); - } +// public bool IsDPadRightPressed() +// { +// return Buttons.HasFlag(Buttons.DPadRight); +// } - public bool IsDPadRightPressed() - { - return Buttons.HasFlag(Buttons.DPadRight); - } +// public bool IsStartPressed() +// { +// return Buttons.HasFlag(Buttons.Start); +// } - public bool IsStartPressed() - { - return Buttons.HasFlag(Buttons.Start); - } +// public bool IsBackPressed() +// { +// return Buttons.HasFlag(Buttons.Back); +// } - public bool IsBackPressed() - { - return Buttons.HasFlag(Buttons.Back); - } +// public bool IsLeftThumbPressed() +// { +// return Buttons.HasFlag(Buttons.LeftThumb); +// } - public bool IsLeftThumbPressed() - { - return Buttons.HasFlag(Buttons.LeftThumb); - } +// public bool IsRightThumbPressed() +// { +// return Buttons.HasFlag(Buttons.RightThumb); +// } - public bool IsRightThumbPressed() - { - return Buttons.HasFlag(Buttons.RightThumb); - } +// public bool IsLeftShoulderPressed() +// { +// return Buttons.HasFlag(Buttons.LeftShoulder); +// } - public bool IsLeftShoulderPressed() - { - return Buttons.HasFlag(Buttons.LeftShoulder); - } +// public bool IsRightShoulderPressed() +// { +// return Buttons.HasFlag(Buttons.RightShoulder); +// } - public bool IsRightShoulderPressed() - { - return Buttons.HasFlag(Buttons.RightShoulder); - } +// public bool IsAPressed() +// { +// return Buttons.HasFlag(Buttons.A); +// } - public bool IsAPressed() - { - return Buttons.HasFlag(Buttons.A); - } +// public bool IsBPressed() +// { +// return Buttons.HasFlag(Buttons.B); +// } - public bool IsBPressed() - { - return Buttons.HasFlag(Buttons.B); - } +// public bool IsXPressed() +// { +// return Buttons.HasFlag(Buttons.X); +// } - public bool IsXPressed() - { - return Buttons.HasFlag(Buttons.X); - } - - public bool IsYPressed() - { - return Buttons.HasFlag(Buttons.Y); - } - } -} +// public bool IsYPressed() +// { +// return Buttons.HasFlag(Buttons.Y); +// } +// } +//} diff --git a/Assets/Scripts/Essgeeinit.cs b/Assets/Scripts/Essgeeinit.cs index 51373e5..5f25b58 100644 --- a/Assets/Scripts/Essgeeinit.cs +++ b/Assets/Scripts/Essgeeinit.cs @@ -39,8 +39,8 @@ public class Essgeeinit : MonoBehaviour { instance = this; InitAll(Application.streamingAssetsPath, Application.persistentDataPath); - LoadAndRunCartridge("G:/Ninja_Gaiden_(UE)_type_A_[!].sms"); - //LoadAndRunCartridge("G:/SML2.gb"); + //LoadAndRunCartridge("G:/Ninja_Gaiden_(UE)_type_A_[!].sms"); + LoadAndRunCartridge("G:/SML2.gb"); } void OnDisable() @@ -605,7 +605,8 @@ public class Essgeeinit : MonoBehaviour { //TODO Inputʵ - e.Keyboard = mUniKeyboard.mKeyCodeCore.GetPressedKeys(); + //e.Keyboard = mUniKeyboard.mKeyCodeCore.GetPressedKeys(); + e.Keyboard.AddRange(mUniKeyboard.mKeyCodeCore.GetPressedKeys()); e.MouseButtons = default; e.MousePosition = default; diff --git a/Assets/Scripts/UniInterface/KeyCodeCore.cs b/Assets/Scripts/UniInterface/KeyCodeCore.cs index 814fc73..14a80a3 100644 --- a/Assets/Scripts/UniInterface/KeyCodeCore.cs +++ b/Assets/Scripts/UniInterface/KeyCodeCore.cs @@ -1,6 +1,4 @@ -using Essgee.Emulation.Configuration; -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using UnityEngine; @@ -173,7 +171,7 @@ public class KeyCodeCore Joypad2Button2 = MotionKey.NumPad3; */ - dictKeyCfgs.Add(KeyCode.F12, machine.configuration.InputReset); + //dictKeyCfgs.Add(KeyCode.F12, machine.configuration.InputReset); dictKeyCfgs.Add(KeyCode.F1, machine.configuration.InputChangeMode); dictKeyCfgs.Add(KeyCode.F2, machine.configuration.InputPlayTape); @@ -226,8 +224,8 @@ public class KeyCodeCore dictKeyCfgs.Add(KeyCode.DownArrow, machine.configuration.Joypad2Down); dictKeyCfgs.Add(KeyCode.LeftArrow, machine.configuration.Joypad2Left); dictKeyCfgs.Add(KeyCode.RightAlt, machine.configuration.Joypad2Right); - dictKeyCfgs.Add(KeyCode.Alpha1, machine.configuration.Joypad2Button1); - dictKeyCfgs.Add(KeyCode.Alpha2, machine.configuration.Joypad2Button2); + dictKeyCfgs.Add(KeyCode.Alpha1, machine.configuration.Joypad2Button2); + dictKeyCfgs.Add(KeyCode.Alpha2, machine.configuration.Joypad2Button1); } CheckList = dictKeyCfgs.Keys.ToArray();