减少InputResolver开销

This commit is contained in:
sin365 2025-09-17 18:31:58 +08:00
parent c2ceb8de59
commit 7e8d0e8340
3 changed files with 45 additions and 5 deletions

View File

@ -92,5 +92,9 @@
/// 网络即时存档删除
/// </summary>
OnNetGameSavDeleted,
/// <summary>
/// 核心开始游戏
/// </summary>
OnEmuBeginGame,
}
}

View File

@ -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()

View File

@ -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>(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>(CONTROLLER control) where CONTROLLER : InputControl_C;