From 7e8d0e83409ecb8ef0c3068801beda6753b979c1 Mon Sep 17 00:00:00 2001
From: sin365 <353374337@qq.com>
Date: Wed, 17 Sep 2025 18:31:58 +0800
Subject: [PATCH] =?UTF-8?q?=E5=87=8F=E5=B0=91InputResolver=E5=BC=80?=
=?UTF-8?q?=E9=94=80?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Assets/Script/AppMain/Event/EEvent.cs | 4 ++
.../Assets/Script/AppMain/Manager/AppEmu.cs | 2 +
.../InputResolver/InputResolver.cs | 44 ++++++++++++++++---
3 files changed, 45 insertions(+), 5 deletions(-)
diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Event/EEvent.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Event/EEvent.cs
index c800f240..620cbbf9 100644
--- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Event/EEvent.cs
+++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Event/EEvent.cs
@@ -92,5 +92,9 @@
/// 网络即时存档删除
///
OnNetGameSavDeleted,
+ ///
+ /// 核心开始游戏
+ ///
+ OnEmuBeginGame,
}
}
diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppEmu.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppEmu.cs
index 50682b78..70dd3c16 100644
--- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppEmu.cs
+++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/AppEmu.cs
@@ -77,6 +77,7 @@ namespace AxibugEmuOnline.Client.Manager
break;
}
+
var result = m_emuCore.StartGame(romFile);
if (result)
{
@@ -98,6 +99,7 @@ namespace AxibugEmuOnline.Client.Manager
StopGame();
OverlayManager.PopTip(result);
}
+ Eventer.Instance.PostEvent(EEvent.OnEmuBeginGame);
}
private void OnSlotDataChanged()
diff --git a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/InputDevicesManager/InputResolver/InputResolver.cs b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/InputDevicesManager/InputResolver/InputResolver.cs
index 48cca5a5..60ac0a2d 100644
--- a/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/InputDevicesManager/InputResolver/InputResolver.cs
+++ b/AxibugEmuOnline.Client/Assets/Script/AppMain/Manager/InputDevicesManager/InputResolver/InputResolver.cs
@@ -1,4 +1,7 @@
-using AxiInputSP.UGUI;
+using AxibugEmuOnline.Client.ClientCore;
+using AxibugEmuOnline.Client.Event;
+using AxiInputSP.UGUI;
+using System;
using System.Collections.Generic;
using UnityEngine;
@@ -26,9 +29,15 @@ namespace AxibugEmuOnline.Client.InputDevices
{
AxiScreenGamepad.OnGamepadActive += AxiScreenGamepad_OnGamepadActive;
AxiScreenGamepad.OnGamepadDisactive += AxiScreenGamepad_OnGamepadDisactive;
+ Eventer.Instance.RegisterEvent(EEvent.OnEmuBeginGame, OnEmuBeginGame);
OnInit();
}
+ private void OnEmuBeginGame()
+ {
+ ClearLastCheckPerformingValue();
+ }
+
private void AxiScreenGamepad_OnGamepadDisactive(AxiScreenGamepad sender)
{
if (m_devices.TryGetValue(sender, out var device))
@@ -95,15 +104,40 @@ namespace AxibugEmuOnline.Client.InputDevices
OnDeviceConnected?.Invoke(connectDevice);
}
+ long last_CheckPerformingFrameIdx = -100;
+ bool last_CheckPerformingValue = false;
+ void ClearLastCheckPerformingValue()
+ {
+ last_CheckPerformingFrameIdx = -100;
+ last_CheckPerformingValue = false;
+ }
+
public bool CheckPerforming(CONTROLLER control) where CONTROLLER : InputControl_C
{
- if (control.Device is ScreenGamepad_D)
+ //减少遍历开销,因为每帧200+次的调用 居然CPU占用了2~3%
+ if (App.emu?.Core == null || last_CheckPerformingFrameIdx != App.emu.Core.Frame)
{
- ScreenGamepad_D device = control.Device as ScreenGamepad_D;
+ if (control.Device is ScreenGamepad_D)
+ {
+ ScreenGamepad_D device = control.Device as ScreenGamepad_D;
- return device.CheckPerforming(control);
+ last_CheckPerformingValue = device.CheckPerforming(control);
+ }
+ else last_CheckPerformingValue = OnCheckPerforming(control);
+
+ if (App.emu?.Core != null)
+ last_CheckPerformingFrameIdx = App.emu.Core.Frame;
}
- else return OnCheckPerforming(control);
+ return last_CheckPerformingValue;
+
+
+ //if (control.Device is ScreenGamepad_D)
+ //{
+ // ScreenGamepad_D device = control.Device as ScreenGamepad_D;
+
+ // return device.CheckPerforming(control);
+ //}
+ //else return OnCheckPerforming(control);
}
protected abstract bool OnCheckPerforming(CONTROLLER control) where CONTROLLER : InputControl_C;