减少InputResolver开销
This commit is contained in:
parent
c2ceb8de59
commit
7e8d0e8340
@ -92,5 +92,9 @@
|
||||
/// 网络即时存档删除
|
||||
/// </summary>
|
||||
OnNetGameSavDeleted,
|
||||
/// <summary>
|
||||
/// 核心开始游戏
|
||||
/// </summary>
|
||||
OnEmuBeginGame,
|
||||
}
|
||||
}
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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
|
||||
{
|
||||
//减少遍历开销,因为每帧200+次的调用 居然CPU占用了2~3%
|
||||
if (App.emu?.Core == null || last_CheckPerformingFrameIdx != App.emu.Core.Frame)
|
||||
{
|
||||
if (control.Device is ScreenGamepad_D)
|
||||
{
|
||||
ScreenGamepad_D device = control.Device as ScreenGamepad_D;
|
||||
|
||||
return device.CheckPerforming(control);
|
||||
last_CheckPerformingValue = device.CheckPerforming(control);
|
||||
}
|
||||
else return OnCheckPerforming(control);
|
||||
else last_CheckPerformingValue = OnCheckPerforming(control);
|
||||
|
||||
if (App.emu?.Core != null)
|
||||
last_CheckPerformingFrameIdx = App.emu.Core.Frame;
|
||||
}
|
||||
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;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user