Skip to content

Commit

Permalink
Restored GUI signals + various fixes after refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
stgatilov committed Aug 6, 2021
1 parent 5b8b04e commit 4bb9cc6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
11 changes: 7 additions & 4 deletions plugins/dm.gameconnection/AutomationEngine.cpp
Expand Up @@ -18,12 +18,12 @@ namespace
}

struct ScopedDepthCounter {
int *ptr;
ScopedDepthCounter(int& counter) : ptr(&counter) {
*ptr++;
int& ref;
ScopedDepthCounter(int& counter) : ref(counter) {
ref++;
}
~ScopedDepthCounter() {
*ptr--;
ref--;
}
};
}
Expand Down Expand Up @@ -92,6 +92,9 @@ int AutomationEngine::generateNewSequenceNumber()

AutomationEngine::Request* AutomationEngine::sendRequest(const std::string& request, int tag) {
assert(tag < 31);
if (!_connection)
throw DisconnectException();

Request req;
req._seqno = generateNewSequenceNumber();
req._request = request;
Expand Down
6 changes: 3 additions & 3 deletions plugins/dm.gameconnection/AutomationEngine.h
Expand Up @@ -78,18 +78,18 @@ class AutomationEngine

// Send given request synchronously, i.e. wait until its completition.
// Returns response content.
// Throws DisconnectException if connection is missing.
// Throws DisconnectException if connection is missing or lost during execution.
std::string executeRequestBlocking(int tag, const std::string& request);

// Send request !a!synchronously, i.e. send it to socket and return immediately.
// Returns seqno of the request: it can be put to wait-list of multistep procedure or used for polling.
// When request is finished, optional callback will be executed (from "think" method).
// Note that if connection is lost already of while request is being executed, NO special callback is called.
// May throw DisconnectException is connection is missing (but never throws if isAlive() is true).
int executeRequestAsync(int tag, const std::string& request, const std::function<void(int)>& callback = {});

// Start executing given multistep procedure starting on next think.
// Execute given multistep procedure, starting on the next think.
// Returns ID of procedure for future queries.
// Throws DisconnectException if connection is missing (in case of blocking requests).
int executeMultistepProc(int tag, const std::function<MultistepProcReturn(int)>& function, int startStep = 0);


Expand Down
15 changes: 12 additions & 3 deletions plugins/dm.gameconnection/GameConnection.cpp
Expand Up @@ -124,6 +124,8 @@ bool GameConnection::connect()
sigc::mem_fun(*this, &GameConnection::onMapEvent)
);

signal_StatusChanged.emit(0);

return true;
}

Expand All @@ -142,6 +144,8 @@ void GameConnection::disconnect(bool force)
_thinkTimer.reset();
}
_mapEventListener.disconnect();

signal_StatusChanged.emit(0);
}

GameConnection::~GameConnection() {
Expand Down Expand Up @@ -555,14 +559,19 @@ bool GameConnection::isUpdateMapObserverEnabled() const
void GameConnection::setUpdateMapObserverEnabled(bool on)
{
_mapObserver.setEnabled(on);

signal_StatusChanged.emit(0);
}

bool GameConnection::setUpdateMapAlways(bool enable)
{
if (enable && !_engine->isAlive())
return false;
if (enable) {
if (!_engine->isAlive())
return false;
if (enable)
setUpdateMapObserverEnabled(true);
}

setUpdateMapObserverEnabled(enable);
_updateMapAlways = enable;
return true;
}
Expand Down

0 comments on commit 4bb9cc6

Please sign in to comment.