Lua: Fixed inputPolled event being called multiple times per frame

This commit is contained in:
Souryo 2017-11-21 17:54:54 -05:00
parent 2c7a169d9c
commit 9c5cfa2e79
8 changed files with 30 additions and 35 deletions

View file

@ -240,7 +240,7 @@ void ControlManager::UpdateInputState()
auto lock = _deviceLock.AcquireSafe();
string log = "";
//string log = "";
for(shared_ptr<BaseControlDevice> &device : _controlDevices) {
device->ClearState();
@ -258,24 +258,18 @@ void ControlManager::UpdateInputState()
}
device->OnAfterSetState();
shared_ptr<Debugger> debugger = Console::GetInstance()->GetDebugger(false);
if(debugger) {
debugger->ProcessEvent(EventType::InputPolled);
}
log += "|" + device->GetTextState();
for(IInputRecorder* recorder : _inputRecorders) {
recorder->RecordInput(device.get());
}
//log += "|" + device->GetTextState();
}
shared_ptr<Debugger> debugger = Console::GetInstance()->GetDebugger(false);
if(debugger) {
debugger->ProcessEvent(EventType::InputPolled);
}
for(IInputRecorder* recorder : _inputRecorders) {
recorder->EndFrame();
recorder->RecordInput(_controlDevices);
}
MessageManager::Log(log);
//MessageManager::Log(log);
}
uint32_t ControlManager::GetLagCounter()

View file

@ -85,12 +85,14 @@ bool GameServer::SetInput(BaseControlDevice *device)
return false;
}
void GameServer::RecordInput(BaseControlDevice *device)
void GameServer::RecordInput(vector<shared_ptr<BaseControlDevice>> devices)
{
for(shared_ptr<GameServerConnection> connection : _openConnections) {
if(!connection->ConnectionError()) {
//Send movie stream
connection->SendMovieData(device->GetPort(), device->GetRawState());
for(shared_ptr<BaseControlDevice> &device : devices) {
for(shared_ptr<GameServerConnection> connection : _openConnections) {
if(!connection->ConnectionError()) {
//Send movie stream
connection->SendMovieData(device->GetPort(), device->GetRawState());
}
}
}
}

View file

@ -47,5 +47,5 @@ public:
static list<shared_ptr<GameServerConnection>> GetConnectionList();
bool SetInput(BaseControlDevice *device) override;
void RecordInput(BaseControlDevice *device) override;
void RecordInput(vector<shared_ptr<BaseControlDevice>> devices) override;
};

View file

@ -1,10 +1,10 @@
#pragma once
#include "stdafx.h"
class BaseControlDevice;
class IInputRecorder
{
public:
virtual void RecordInput(BaseControlDevice *device) = 0;
virtual void EndFrame() { }
virtual void RecordInput(vector<shared_ptr<BaseControlDevice>> devices) = 0;
};

View file

@ -179,13 +179,11 @@ bool MovieRecorder::Stop()
return false;
}
void MovieRecorder::RecordInput(BaseControlDevice *device)
{
_inputData << ("|" + device->GetTextState());
}
void MovieRecorder::EndFrame()
void MovieRecorder::RecordInput(vector<shared_ptr<BaseControlDevice>> devices)
{
for(shared_ptr<BaseControlDevice> &device : devices) {
_inputData << ("|" + device->GetTextState());
}
_inputData << "\n";
}

View file

@ -31,8 +31,7 @@ public:
bool Record(string filename, bool reset);
bool Stop();
void RecordInput(BaseControlDevice *device) override;
void EndFrame() override;
void RecordInput(vector<shared_ptr<BaseControlDevice>> devices) override;
// Inherited via IBatteryRecorder
virtual void OnLoadBattery(string extension, vector<uint8_t> batteryData) override;

View file

@ -267,10 +267,12 @@ bool RewindManager::ProcessAudio(int16_t * soundBuffer, uint32_t sampleCount, ui
}
}
void RewindManager::RecordInput(BaseControlDevice *device)
void RewindManager::RecordInput(vector<shared_ptr<BaseControlDevice>> devices)
{
if(EmulationSettings::GetRewindBufferSize() > 0 && _instance && _instance->_rewindState == RewindState::Stopped) {
_instance->_currentHistory.InputLogs[device->GetPort()].push_back(device->GetRawState());
for(shared_ptr<BaseControlDevice> &device : devices) {
_instance->_currentHistory.InputLogs[device->GetPort()].push_back(device->GetRawState());
}
}
}

View file

@ -51,7 +51,7 @@ public:
void ProcessNotification(ConsoleNotificationType type, void* parameter) override;
void ProcessEndOfFrame();
void RecordInput(BaseControlDevice *device) override;
void RecordInput(vector<shared_ptr<BaseControlDevice>> devices) override;
bool SetInput(BaseControlDevice *device) override;
static void StartRewinding(bool forDebugger = false);