Netplay: Fixed regressions/crashes caused by refactoring
This commit is contained in:
parent
974bd8cd07
commit
2504fe0b71
3 changed files with 33 additions and 8 deletions
|
@ -27,7 +27,6 @@ GameClientConnection::GameClientConnection(shared_ptr<Console> console, shared_p
|
|||
_minimumQueueSize = 3;
|
||||
|
||||
MessageManager::DisplayMessage("NetPlay", "ConnectedToServer");
|
||||
_console->GetControlManager()->RegisterInputProvider(this);
|
||||
}
|
||||
|
||||
GameClientConnection::~GameClientConnection()
|
||||
|
@ -208,10 +207,10 @@ bool GameClientConnection::SetInput(BaseControlDevice *device)
|
|||
void GameClientConnection::InitControlDevice()
|
||||
{
|
||||
if(_controllerPort == BaseControlDevice::ExpDevicePort) {
|
||||
_newControlDevice = ControlManager::CreateExpansionDevice(EmulationSettings::GetExpansionDevice(), nullptr);
|
||||
_newControlDevice = ControlManager::CreateExpansionDevice(EmulationSettings::GetExpansionDevice(), _console);
|
||||
} else {
|
||||
//Pretend we are using port 0 (to use player 1's keybindings during netplay)
|
||||
_newControlDevice = ControlManager::CreateControllerDevice(EmulationSettings::GetControllerType(_controllerPort), 0, nullptr);
|
||||
_newControlDevice = ControlManager::CreateControllerDevice(EmulationSettings::GetControllerType(_controllerPort), 0, _console);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -219,6 +218,8 @@ void GameClientConnection::ProcessNotification(ConsoleNotificationType type, voi
|
|||
{
|
||||
if(type == ConsoleNotificationType::ConfigChanged) {
|
||||
InitControlDevice();
|
||||
} else if(type == ConsoleNotificationType::GameLoaded) {
|
||||
_console->GetControlManager()->RegisterInputProvider(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ using std::thread;
|
|||
#include "PlayerListMessage.h"
|
||||
#include "NotificationManager.h"
|
||||
|
||||
unique_ptr<GameServer> GameServer::Instance;
|
||||
shared_ptr<GameServer> GameServer::Instance;
|
||||
|
||||
GameServer::GameServer(shared_ptr<Console> console, uint16_t listenPort, string password, string hostPlayerName)
|
||||
{
|
||||
|
@ -20,8 +20,9 @@ GameServer::GameServer(shared_ptr<Console> console, uint16_t listenPort, string
|
|||
_password = password;
|
||||
_hostPlayerName = hostPlayerName;
|
||||
_hostControllerPort = 0;
|
||||
_console->GetControlManager()->RegisterInputRecorder(this);
|
||||
_console->GetControlManager()->RegisterInputProvider(this);
|
||||
|
||||
//If a game is already running, register ourselves as an input recorder/provider right away
|
||||
RegisterServerInput();
|
||||
}
|
||||
|
||||
GameServer::~GameServer()
|
||||
|
@ -35,6 +36,15 @@ GameServer::~GameServer()
|
|||
_console->GetControlManager()->UnregisterInputProvider(this);
|
||||
}
|
||||
|
||||
void GameServer::RegisterServerInput()
|
||||
{
|
||||
ControlManager* controlManager = _console->GetControlManager();
|
||||
if(controlManager) {
|
||||
controlManager->RegisterInputRecorder(this);
|
||||
controlManager->RegisterInputProvider(this);
|
||||
}
|
||||
}
|
||||
|
||||
void GameServer::AcceptConnections()
|
||||
{
|
||||
while(true) {
|
||||
|
@ -102,6 +112,14 @@ void GameServer::RecordInput(vector<shared_ptr<BaseControlDevice>> devices)
|
|||
}
|
||||
}
|
||||
|
||||
void GameServer::ProcessNotification(ConsoleNotificationType type, void * parameter)
|
||||
{
|
||||
if(type == ConsoleNotificationType::GameLoaded) {
|
||||
//Register the server as an input provider/recorder
|
||||
RegisterServerInput();
|
||||
}
|
||||
}
|
||||
|
||||
void GameServer::Exec()
|
||||
{
|
||||
_listener.reset(new Socket());
|
||||
|
@ -129,6 +147,7 @@ void GameServer::Stop()
|
|||
void GameServer::StartServer(shared_ptr<Console> console, uint16_t port, string password, string hostPlayerName)
|
||||
{
|
||||
Instance.reset(new GameServer(console, port, password, hostPlayerName));
|
||||
console->GetNotificationManager()->RegisterNotificationListener(Instance);
|
||||
Instance->_serverThread.reset(new thread(&GameServer::Exec, Instance.get()));
|
||||
}
|
||||
|
||||
|
|
|
@ -9,10 +9,10 @@
|
|||
using std::thread;
|
||||
class Console;
|
||||
|
||||
class GameServer : public IInputRecorder, public IInputProvider
|
||||
class GameServer : public IInputRecorder, public IInputProvider, public INotificationListener
|
||||
{
|
||||
private:
|
||||
static unique_ptr<GameServer> Instance;
|
||||
static shared_ptr<GameServer> Instance;
|
||||
shared_ptr<Console> _console;
|
||||
unique_ptr<thread> _serverThread;
|
||||
atomic<bool> _stop;
|
||||
|
@ -35,6 +35,8 @@ public:
|
|||
GameServer(shared_ptr<Console> console, uint16_t port, string password, string hostPlayerName);
|
||||
virtual ~GameServer();
|
||||
|
||||
void RegisterServerInput();
|
||||
|
||||
static void StartServer(shared_ptr<Console> console, uint16_t port, string password, string hostPlayerName);
|
||||
static void StopServer();
|
||||
static bool Started();
|
||||
|
@ -50,4 +52,7 @@ public:
|
|||
|
||||
bool SetInput(BaseControlDevice *device) override;
|
||||
void RecordInput(vector<shared_ptr<BaseControlDevice>> devices) override;
|
||||
|
||||
// Inherited via INotificationListener
|
||||
virtual void ProcessNotification(ConsoleNotificationType type, void * parameter) override;
|
||||
};
|
Loading…
Add table
Reference in a new issue