forked from sin365/AxibugEmuOnline
减少InputResolver开销
This commit is contained in:
parent
c2ceb8de59
commit
7e8d0e8340
@ -92,5 +92,9 @@
|
|||||||
/// 网络即时存档删除
|
/// 网络即时存档删除
|
||||||
/// </summary>
|
/// </summary>
|
||||||
OnNetGameSavDeleted,
|
OnNetGameSavDeleted,
|
||||||
|
/// <summary>
|
||||||
|
/// 核心开始游戏
|
||||||
|
/// </summary>
|
||||||
|
OnEmuBeginGame,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -77,6 +77,7 @@ namespace AxibugEmuOnline.Client.Manager
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var result = m_emuCore.StartGame(romFile);
|
var result = m_emuCore.StartGame(romFile);
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
@ -98,6 +99,7 @@ namespace AxibugEmuOnline.Client.Manager
|
|||||||
StopGame();
|
StopGame();
|
||||||
OverlayManager.PopTip(result);
|
OverlayManager.PopTip(result);
|
||||||
}
|
}
|
||||||
|
Eventer.Instance.PostEvent(EEvent.OnEmuBeginGame);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnSlotDataChanged()
|
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 System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
@ -26,9 +29,15 @@ namespace AxibugEmuOnline.Client.InputDevices
|
|||||||
{
|
{
|
||||||
AxiScreenGamepad.OnGamepadActive += AxiScreenGamepad_OnGamepadActive;
|
AxiScreenGamepad.OnGamepadActive += AxiScreenGamepad_OnGamepadActive;
|
||||||
AxiScreenGamepad.OnGamepadDisactive += AxiScreenGamepad_OnGamepadDisactive;
|
AxiScreenGamepad.OnGamepadDisactive += AxiScreenGamepad_OnGamepadDisactive;
|
||||||
|
Eventer.Instance.RegisterEvent(EEvent.OnEmuBeginGame, OnEmuBeginGame);
|
||||||
OnInit();
|
OnInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnEmuBeginGame()
|
||||||
|
{
|
||||||
|
ClearLastCheckPerformingValue();
|
||||||
|
}
|
||||||
|
|
||||||
private void AxiScreenGamepad_OnGamepadDisactive(AxiScreenGamepad sender)
|
private void AxiScreenGamepad_OnGamepadDisactive(AxiScreenGamepad sender)
|
||||||
{
|
{
|
||||||
if (m_devices.TryGetValue(sender, out var device))
|
if (m_devices.TryGetValue(sender, out var device))
|
||||||
@ -95,15 +104,40 @@ namespace AxibugEmuOnline.Client.InputDevices
|
|||||||
OnDeviceConnected?.Invoke(connectDevice);
|
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
|
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;
|
protected abstract bool OnCheckPerforming<CONTROLLER>(CONTROLLER control) where CONTROLLER : InputControl_C;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user