From 45eeb0426b11c9e665eaf42e2d1cc7982a089c3f Mon Sep 17 00:00:00 2001 From: Souryo Date: Wed, 10 Feb 2016 19:48:15 -0500 Subject: [PATCH] NetPlay: Fixed zapper for clients (did not work at all) --- Core/GameClientConnection.cpp | 17 +++++++++++++++++ Core/GameClientConnection.h | 5 ++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Core/GameClientConnection.cpp b/Core/GameClientConnection.cpp index 66819e76..c52aa140 100644 --- a/Core/GameClientConnection.cpp +++ b/Core/GameClientConnection.cpp @@ -15,6 +15,7 @@ GameClientConnection::GameClientConnection(shared_ptr socket, shared_ptr connectionData) : GameConnection(socket, connectionData) { + MessageManager::RegisterNotificationListener(this); MessageManager::DisplayMessage("Net Play", "Connected to server."); SendHandshake(); } @@ -26,6 +27,7 @@ GameClientConnection::~GameClientConnection() MessageManager::SendNotification(ConsoleNotificationType::DisconnectedFromServer); MessageManager::DisplayMessage("Net Play", "Connection to server lost."); + MessageManager::UnregisterNotificationListener(this); } void GameClientConnection::SendHandshake() @@ -160,9 +162,24 @@ uint8_t GameClientConnection::GetControllerState(uint8_t port) return 0; } +void GameClientConnection::ProcessNotification(ConsoleNotificationType type, void* parameter) +{ + if(type == ConsoleNotificationType::ConfigChanged) { + switch(EmulationSettings::GetControllerType(_controllerPort)) { + case ControllerType::StandardController: _newControlDevice.reset(new StandardController(0)); break; + case ControllerType::Zapper: _newControlDevice = ControlManager::GetControlDevice(_controllerPort); break; + } + } +} + void GameClientConnection::SendInput() { if(_gameLoaded) { + if(_newControlDevice) { + _controlDevice = _newControlDevice; + _newControlDevice.reset(); + } + uint32_t inputState = 0; if(std::dynamic_pointer_cast(_controlDevice)) { shared_ptr zapper = std::dynamic_pointer_cast(_controlDevice); diff --git a/Core/GameClientConnection.h b/Core/GameClientConnection.h index cfbf8c6e..cdaae300 100644 --- a/Core/GameClientConnection.h +++ b/Core/GameClientConnection.h @@ -8,7 +8,7 @@ class ClientConnectionData; -class GameClientConnection : public GameConnection +class GameClientConnection : public GameConnection, public INotificationListener { private: std::deque _inputData[4]; @@ -22,6 +22,7 @@ private: vector _playerList; shared_ptr _controlDevice; + shared_ptr _newControlDevice; uint32_t _lastInputSent = 0x00; bool _gameLoaded = false; uint8_t _controllerPort = GameConnection::SpectatorPort; @@ -40,6 +41,8 @@ public: GameClientConnection(shared_ptr socket, shared_ptr connectionData); ~GameClientConnection(); + void ProcessNotification(ConsoleNotificationType type, void* parameter); + uint8_t GetControllerState(uint8_t port); void SendInput();