From 99d0d76566743af33738f5264e57e1bba9829926 Mon Sep 17 00:00:00 2001 From: sin365 <353374337@qq.com> Date: Mon, 8 Sep 2025 18:16:59 +0800 Subject: [PATCH] =?UTF-8?q?StoicGoose=E6=A0=B8=E5=BF=83=E9=99=A4=E5=8D=B3?= =?UTF-8?q?=E6=97=B6=E5=AD=98=E6=A1=A3=E4=B9=8B=E5=A4=96=20=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0CoreInterface=EF=BC=88=E4=B8=BB=E8=A6=81Input=EF=BC=89?= =?UTF-8?q?=20|=20=E4=B8=80=E4=BA=9B=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UEssgeeInterface/UEGKeyboard.cs | 4 +- .../StoicGooseInterface/SGKeyboard.cs | 209 ++++++++++++++++-- .../StoicGooseInterface/SGSoundPlayer.cs | 6 + .../StoicGooseEmulator/UStoicGoose.cs | 32 +-- .../KeyMapperSetting/KeyMapperSetting.cs | 1 + .../Devices/PSVController_D.cs | 12 + 6 files changed, 225 insertions(+), 39 deletions(-) diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/UEGKeyboard.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/UEGKeyboard.cs index 409fee6e..040f2ef8 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/UEGKeyboard.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/EssgeeEmulator/UEssgeeInterface/UEGKeyboard.cs @@ -12,7 +12,7 @@ public class UEGKeyboard : MonoBehaviour { public EssgeeControllerMapper ControllerMapper { get; private set; } public Dictionary dictKey2Motion = new Dictionary(); - public Dictionary dictMotion2RealKey = new Dictionary() + /*public Dictionary dictMotion2RealKey = new Dictionary() { { EssgeeUnityKey.P1_UP,KeyCode.W}, { EssgeeUnityKey.P1_DOWN,KeyCode.S}, @@ -54,7 +54,7 @@ public class UEGKeyboard : MonoBehaviour { EssgeeUnityKey.P4_BTN_4,KeyCode.F12}, { EssgeeUnityKey.P4_POTION_1,KeyCode.F12}, { EssgeeUnityKey.P4_POTION_2,KeyCode.F12}, - }; + };*/ public ulong[] CheckList; public EssgeeMotionKey[] mCurrKey = new EssgeeMotionKey[0]; List temp = new List(); diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/StoicGooseEmulator/StoicGooseInterface/SGKeyboard.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/StoicGooseEmulator/StoicGooseInterface/SGKeyboard.cs index 716f8f5d..7627204c 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/StoicGooseEmulator/StoicGooseInterface/SGKeyboard.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/StoicGooseEmulator/StoicGooseInterface/SGKeyboard.cs @@ -1,3 +1,6 @@ +using AxibugEmuOnline.Client.ClientCore; +using AxibugEmuOnline.Client.Event; +using AxibugEmuOnline.Client.Settings; using StoicGooseUnity; using System; using System.Collections.Generic; @@ -6,12 +9,14 @@ using UnityEngine; public class SGKeyboard : MonoBehaviour { - Dictionary dictKey2SGKey = new Dictionary(); - KeyCode[] checkKeys; + public SGControllerMapper ControllerMapper { get; private set; } + //Dictionary dictKey2SGKey = new Dictionary(); + //KeyCode[] checkKeys; long currInput; private void Awake() { - SetVerticalOrientation(false); + ControllerMapper = new SGControllerMapper(); + //SetVerticalOrientation(false); } @@ -22,31 +27,187 @@ public class SGKeyboard : MonoBehaviour internal void SetVerticalOrientation(bool isVerticalOrientation) { - dictKey2SGKey[KeyCode.Return] = StoicGooseKey.Start; - dictKey2SGKey[KeyCode.W] = StoicGooseKey.X1; - dictKey2SGKey[KeyCode.S] = StoicGooseKey.X2; - dictKey2SGKey[KeyCode.A] = StoicGooseKey.X3; - dictKey2SGKey[KeyCode.D] = StoicGooseKey.X4; - dictKey2SGKey[KeyCode.G] = StoicGooseKey.Y1; - dictKey2SGKey[KeyCode.V] = StoicGooseKey.Y2; - dictKey2SGKey[KeyCode.C] = StoicGooseKey.Y3; - dictKey2SGKey[KeyCode.B] = StoicGooseKey.Y4; - dictKey2SGKey[KeyCode.Return] = StoicGooseKey.Start; - dictKey2SGKey[KeyCode.J] = StoicGooseKey.B; - dictKey2SGKey[KeyCode.K] = StoicGooseKey.A; - checkKeys = dictKey2SGKey.Keys.ToArray(); + //TODO 横屏竖屏 + + //dictKey2SGKey[KeyCode.Return] = StoicGooseKey.Start; + //dictKey2SGKey[KeyCode.W] = StoicGooseKey.X1; + //dictKey2SGKey[KeyCode.S] = StoicGooseKey.X2; + //dictKey2SGKey[KeyCode.A] = StoicGooseKey.X3; + //dictKey2SGKey[KeyCode.D] = StoicGooseKey.X4; + //dictKey2SGKey[KeyCode.G] = StoicGooseKey.Y1; + //dictKey2SGKey[KeyCode.V] = StoicGooseKey.Y2; + //dictKey2SGKey[KeyCode.C] = StoicGooseKey.Y3; + //dictKey2SGKey[KeyCode.B] = StoicGooseKey.Y4; + //dictKey2SGKey[KeyCode.Return] = StoicGooseKey.Start; + //dictKey2SGKey[KeyCode.J] = StoicGooseKey.B; + //dictKey2SGKey[KeyCode.K] = StoicGooseKey.A; + //checkKeys = dictKey2SGKey.Keys.ToArray(); } - public void Update_InputData() + internal void SetInputData(ulong inputData) { - currInput = 0; - for (int i = 0; i < checkKeys.Length; i++) + currInput = (long)inputData; + } + + public ulong Update_InputData() + { + ulong tempLocalInputAllData = 0; + tempLocalInputAllData |= ControllerMapper.Controller0.GetSingleAllInput(); + tempLocalInputAllData |= ControllerMapper.Controller1.GetSingleAllInput(); + tempLocalInputAllData |= ControllerMapper.Controller2.GetSingleAllInput(); + tempLocalInputAllData |= ControllerMapper.Controller3.GetSingleAllInput(); + return tempLocalInputAllData; + //currInput = tempLocalInputAllData; + + //currInput = 0; + //for (int i = 0; i < checkKeys.Length; i++) + //{ + // KeyCode key = checkKeys[i]; + // if (Input.GetKey(key)) + // { + // currInput |= (long)dictKey2SGKey[key]; + // } + //} + } + +} + + + +public class SGControllerMapper : IControllerSetuper +{ + public SGController Controller0 = new SGController(0); + public SGController Controller1 = new SGController(1); + public SGController Controller2 = new SGController(2); + public SGController Controller3 = new SGController(3); + + ulong mCurrAllInput; + + public void SetConnect(uint? con0ToSlot = null, + uint? con1ToSlot = null, + uint? con2ToSlot = null, + uint? con3ToSlot = null) + { + Controller0.ConnectSlot = con0ToSlot; + Controller1.ConnectSlot = con1ToSlot; + Controller2.ConnectSlot = con2ToSlot; + Controller3.ConnectSlot = con3ToSlot; + } + public int? GetSlotConnectingControllerIndex(int slotIndex) + { + if (Controller0.ConnectSlot.HasValue && Controller0.ConnectSlot.Value == slotIndex) return 0; + else if (Controller1.ConnectSlot.HasValue && Controller1.ConnectSlot.Value == slotIndex) return 1; + else if (Controller2.ConnectSlot.HasValue && Controller2.ConnectSlot.Value == slotIndex) return 2; + else if (Controller3.ConnectSlot.HasValue && Controller3.ConnectSlot.Value == slotIndex) return 3; + else return null; + } + public IController GetSlotConnectingController(int slotIndex) + { + if (Controller0.ConnectSlot.HasValue && Controller0.ConnectSlot.Value == slotIndex) return Controller0; + else if (Controller1.ConnectSlot.HasValue && Controller1.ConnectSlot.Value == slotIndex) return Controller1; + else if (Controller2.ConnectSlot.HasValue && Controller2.ConnectSlot.Value == slotIndex) return Controller2; + else if (Controller3.ConnectSlot.HasValue && Controller3.ConnectSlot.Value == slotIndex) return Controller3; + else return null; + } + static HashSet s_temp = new HashSet(); + public uint? GetFreeSlotIndex() + { + s_temp.Clear(); + s_temp.Add(0); + s_temp.Add(1); + s_temp.Add(2); + s_temp.Add(3); + + if (Controller0.ConnectSlot.HasValue) s_temp.Remove(Controller0.ConnectSlot.Value); + if (Controller1.ConnectSlot.HasValue) s_temp.Remove(Controller1.ConnectSlot.Value); + if (Controller2.ConnectSlot.HasValue) s_temp.Remove(Controller2.ConnectSlot.Value); + if (Controller3.ConnectSlot.HasValue) s_temp.Remove(Controller3.ConnectSlot.Value); + + if (s_temp.Count > 0) return s_temp.First(); + else return null; + } + public void LetControllerConnect(int conIndex, uint slotIndex) + { + SGController targetController; + switch (conIndex) { - KeyCode key = checkKeys[i]; - if (Input.GetKey(key)) - { - currInput |= (long)dictKey2SGKey[key]; - } + case 0: targetController = Controller0; break; + case 1: targetController = Controller1; break; + case 2: targetController = Controller2; break; + case 3: targetController = Controller3; break; + default: + throw new System.Exception($"Not Allowed conIndex Range: {conIndex}"); + break; } + if (targetController.ConnectSlot.HasValue) return; + + targetController.ConnectSlot = slotIndex; + Eventer.Instance.PostEvent(EEvent.OnControllerConnectChanged); + } + +} +public class SGController : IController +{ + public ulong CurrLocalSingleAllInput { get; private set; } + + int mControllerIndex; + uint? mConnectSlot; + + /// + /// 指示该手柄连接的手柄插槽 + /// 这个值代表了该手柄在实际游戏中控制的Player + /// [0,3] 例外:为空代表未连接 + /// + public uint? ConnectSlot + { + get { return mConnectSlot; } + set { mConnectSlot = value; } + } + + /// + /// 控制器编号 + /// 此编号并非对应游戏中的player1,player2,player3,player4,仅仅作为本地4个手柄的实例 + /// [0,3] + /// + public int ControllerIndex + { + get { return mControllerIndex; } + set { mControllerIndex = value; /*this.LoadControlKeyForConfig();*/ } + } + + public SGController(int controllerIndex) + { + ControllerIndex = controllerIndex; + } + + public bool AnyButtonDown() + { + return GetKeyMapper().AnyKeyDown(mControllerIndex); + } + + public StoicGooseBinding GetKeyMapper() + { + return App.settings.KeyMapper.GetBinder(UStoicGoose.instance.Platform); + } + + public ulong GetSingleAllInput() + { + if (!ConnectSlot.HasValue) + return 0; + CurrLocalSingleAllInput = 0; + + StoicGooseBinding essgeeKeys = GetKeyMapper(); + + if (essgeeKeys.GetKey(StoicGooseKey.X1, mControllerIndex)) CurrLocalSingleAllInput |= (ulong)StoicGooseKey.X1; + if (essgeeKeys.GetKey(StoicGooseKey.X2, mControllerIndex)) CurrLocalSingleAllInput |= (ulong)StoicGooseKey.X2; + if (essgeeKeys.GetKey(StoicGooseKey.X3, mControllerIndex)) CurrLocalSingleAllInput |= (ulong)StoicGooseKey.X3; + if (essgeeKeys.GetKey(StoicGooseKey.X4, mControllerIndex)) CurrLocalSingleAllInput |= (ulong)StoicGooseKey.X4; + if (essgeeKeys.GetKey(StoicGooseKey.Y1, mControllerIndex)) CurrLocalSingleAllInput |= (ulong)StoicGooseKey.Y1; + if (essgeeKeys.GetKey(StoicGooseKey.Y2, mControllerIndex)) CurrLocalSingleAllInput |= (ulong)StoicGooseKey.Y2; + if (essgeeKeys.GetKey(StoicGooseKey.Y3, mControllerIndex)) CurrLocalSingleAllInput |= (ulong)StoicGooseKey.Y3; + if (essgeeKeys.GetKey(StoicGooseKey.Y4, mControllerIndex)) CurrLocalSingleAllInput |= (ulong)StoicGooseKey.Y4; + if (essgeeKeys.GetKey(StoicGooseKey.Start, mControllerIndex)) CurrLocalSingleAllInput |= (ulong)StoicGooseKey.Start; + + return CurrLocalSingleAllInput; } } \ No newline at end of file diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/StoicGooseEmulator/StoicGooseInterface/SGSoundPlayer.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/StoicGooseEmulator/StoicGooseInterface/SGSoundPlayer.cs index 11279d35..c2b359b2 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/StoicGooseEmulator/StoicGooseInterface/SGSoundPlayer.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/StoicGooseEmulator/StoicGooseInterface/SGSoundPlayer.cs @@ -10,6 +10,12 @@ public class SGSoundPlayer : MonoBehaviour//, ISoundPlayer private TimeSpan lastElapsed; public double audioFPS { get; private set; } + //TODO 是否需要和 AudioConfiguration关联起来 + [HideInInspector] + public int sampleRate = 44100; + [HideInInspector] + public int channle = 2; + void Awake() { // 获取当前音频配置 diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/StoicGooseEmulator/UStoicGoose.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/StoicGooseEmulator/UStoicGoose.cs index 6c15d6c3..9247d6e9 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/StoicGooseEmulator/UStoicGoose.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Emulator/StoicGooseEmulator/UStoicGoose.cs @@ -93,7 +93,6 @@ public class UStoicGoose : EmuCore Init(); - //淇濆瓨褰撳墠姝e湪杩涜鐨勬父鎴忓瓨妗 if (emulatorHandler != null && !emulatorHandler.IsRunning) { @@ -123,11 +122,17 @@ public class UStoicGoose : EmuCore public override IControllerSetuper GetControllerSetuper() { - throw new NotImplementedException(); + return inputHandler.ControllerMapper; } protected override bool OnPushEmulatorFrame(ulong InputData) { - throw new NotImplementedException(); + if (!emulatorHandler.IsRunning) return false; + //if (!bLogicUpdatePause) return false; + + inputHandler.SetInputData(InputData); + + emulatorHandler.Frame_Update(); + return true; } protected override ulong ConvertInputDataFromNet(ReplayStep step) @@ -142,17 +147,17 @@ public class UStoicGoose : EmuCore protected override ulong GetLocalInput() { - throw new NotImplementedException(); + return inputHandler.Update_InputData(); } protected override void AfterPushFrame() { - throw new NotImplementedException(); } public override void GetAudioParams(out int frequency, out int channels) { - throw new NotImplementedException(); + channels = soundHandler.channle; + frequency = soundHandler.sampleRate; } #endregion @@ -177,15 +182,16 @@ public class UStoicGoose : EmuCore //Init(); //LoadAndRunCartridge("G:/BaiduNetdiskDownload/Rockman & Forte - Mirai Kara no Chousen Sha (J) [M][!].ws"); } - private void Update() - { - if (!emulatorHandler.IsRunning) - return; - inputHandler.Update_InputData(); + //渚濋潬澶栭儴鏍稿績椹卞姩 + //private void Update() + //{ + // if (!emulatorHandler.IsRunning) + // return; + // inputHandler.Update_InputData(); + // emulatorHandler.Frame_Update(); + //} - emulatorHandler.Frame_Update(); - } void OnDestroy() { EmuClose(); diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/KeyMapperSetting.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/KeyMapperSetting.cs index 1447b390..6afc72c7 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/KeyMapperSetting.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppSettings/KeyMapperSetting/KeyMapperSetting.cs @@ -13,6 +13,7 @@ namespace AxibugEmuOnline.Client.Settings Dictionary m_bindersByType = new Dictionary(); public KeyMapperSetting() { + //鍙嶅皠鎷挎墍鏈夋牳蹇冪殑閿綅缁戝畾 var baseType = typeof(InternalEmuCoreBinder); foreach (var t in baseType.Assembly.ExportedTypes) { diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/InputDevicesManager/Devices/PSVController_D.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/InputDevicesManager/Devices/PSVController_D.cs index f4da18c0..aa9b0176 100644 --- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/InputDevicesManager/Devices/PSVController_D.cs +++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/InputDevicesManager/Devices/PSVController_D.cs @@ -6,9 +6,21 @@ namespace AxibugEmuOnline.Client.InputDevices { public override GamePadType PadType => GamePadType.PsvitaControl; + /// + /// X + /// public Button_C Cross; + /// + /// O + /// public Button_C Circle; + /// + /// 鏂规 + /// public Button_C Square; + /// + /// 涓夎 + /// public Button_C Triangle; public Button_C L; public Button_C R;