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

View file

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

View file

@ -47,5 +47,5 @@ public:
static list<shared_ptr<GameServerConnection>> GetConnectionList(); static list<shared_ptr<GameServerConnection>> GetConnectionList();
bool SetInput(BaseControlDevice *device) override; 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 #pragma once
#include "stdafx.h"
class BaseControlDevice; class BaseControlDevice;
class IInputRecorder class IInputRecorder
{ {
public: public:
virtual void RecordInput(BaseControlDevice *device) = 0; virtual void RecordInput(vector<shared_ptr<BaseControlDevice>> devices) = 0;
virtual void EndFrame() { }
}; };

View file

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

View file

@ -31,8 +31,7 @@ public:
bool Record(string filename, bool reset); bool Record(string filename, bool reset);
bool Stop(); bool Stop();
void RecordInput(BaseControlDevice *device) override; void RecordInput(vector<shared_ptr<BaseControlDevice>> devices) override;
void EndFrame() override;
// Inherited via IBatteryRecorder // Inherited via IBatteryRecorder
virtual void OnLoadBattery(string extension, vector<uint8_t> batteryData) override; 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) { 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 ProcessNotification(ConsoleNotificationType type, void* parameter) override;
void ProcessEndOfFrame(); void ProcessEndOfFrame();
void RecordInput(BaseControlDevice *device) override; void RecordInput(vector<shared_ptr<BaseControlDevice>> devices) override;
bool SetInput(BaseControlDevice *device) override; bool SetInput(BaseControlDevice *device) override;
static void StartRewinding(bool forDebugger = false); static void StartRewinding(bool forDebugger = false);