From 94de3c71c6a84c04ac9625413c67bfc8bc1674e9 Mon Sep 17 00:00:00 2001 From: Matthew Mott Date: Tue, 1 Sep 2020 21:13:57 +0100 Subject: [PATCH] Add a proper interface for IGameConnection Previously the IGameConnection interface was empty, but the code which used the module actually did a dynamic_cast down to the GameConnection implementing class and used its methods directly, thereby breaking the module abstraction. Now, the methods used by the UI code have been added as pure virtuals in the IGameConnection interface, eliminating the need for the dynamic downcast. --- include/igameconnection.h | 9 ++++++++- radiant/gameconnection/GameConnection.cpp | 7 ++++--- radiant/ui/UserInterfaceModule.cpp | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/include/igameconnection.h b/include/igameconnection.h index 2e77531e32..c70e239dc6 100644 --- a/include/igameconnection.h +++ b/include/igameconnection.h @@ -6,7 +6,14 @@ class IGameConnection : public RegisterableModule { public: - //TODO: to be determined... + virtual void setCameraSyncEnabled(bool enable) = 0; + virtual void backSyncCamera() = 0; + virtual void reloadMap() = 0; + virtual void setAutoReloadMapEnabled(bool enable) = 0; + virtual void setUpdateMapLevel(bool on, bool always) = 0; + virtual void doUpdateMap() = 0; + virtual void togglePauseGame() = 0; + virtual void respawnSelectedEntities() = 0; }; const char* const MODULE_GAMECONNECTION = "GameConnection"; diff --git a/radiant/gameconnection/GameConnection.cpp b/radiant/gameconnection/GameConnection.cpp index 5827f55bd4..85db170a45 100644 --- a/radiant/gameconnection/GameConnection.cpp +++ b/radiant/gameconnection/GameConnection.cpp @@ -24,9 +24,11 @@ static std::string messagePreamble(std::string type) { static std::string actionPreamble(std::string type) { return messagePreamble("action") + fmt::format("action \"{}\"\n", type); } +#if 0 static std::string queryPreamble(std::string type) { return messagePreamble("query") + fmt::format("query \"{}\"\n", type); } +#endif int GameConnection::newSeqno() { @@ -62,7 +64,7 @@ void GameConnection::think() { //validate and remove preamble int responseSeqno, lineLen; int ret = sscanf(_response.data(), "response %d\n%n", &responseSeqno, &lineLen); - assert(ret == 1); ret; + assert(ret == 1); assert(responseSeqno == _seqnoInProgress); _response.erase(_response.begin(), _response.begin() + lineLen); //mark request as "no longer in progress" @@ -72,8 +74,7 @@ void GameConnection::think() { } else { //doing nothing now: send async command if present - bool sentAsync = sendAnyPendingAsync(); - sentAsync = false; //unused + sendAnyPendingAsync(); } _connection->think(); if (!_connection->isAlive()) { diff --git a/radiant/ui/UserInterfaceModule.cpp b/radiant/ui/UserInterfaceModule.cpp index 8705540828..a042fcc9f7 100644 --- a/radiant/ui/UserInterfaceModule.cpp +++ b/radiant/ui/UserInterfaceModule.cpp @@ -162,7 +162,7 @@ void UserInterfaceModule::registerUICommands() // FIXME: should not dynamic_cast, required methods should be in the // IGameConnection interface - if (GameConnection *gameconn = dynamic_cast(GlobalGameConnection())) { + if (IGameConnection *gameconn = GlobalGameConnection()) { GlobalCommandSystem().addCommand("GameConnectionCameraSyncEnable", [gameconn](const cmd::ArgumentList&) { gameconn->setCameraSyncEnabled(true); }); GlobalCommandSystem().addCommand("GameConnectionCameraSyncDisable",