aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Sandulenko2019-11-04 10:13:07 +0100
committerEugene Sandulenko2019-11-04 10:13:07 +0100
commit2721dd2fef4169d8bba29051383f28b85022f55d (patch)
treea065f0c54eaa1ff5d08b20aaa30c2ca1f8522e0a
parent4d4e8d3a25b55236905517e6dc6304ddb1d184da (diff)
downloadscummvm-rg350-2721dd2fef4169d8bba29051383f28b85022f55d.tar.gz
scummvm-rg350-2721dd2fef4169d8bba29051383f28b85022f55d.tar.bz2
scummvm-rg350-2721dd2fef4169d8bba29051383f28b85022f55d.zip
SCUMM HE: MBC: Query sessions asynchronously
-rw-r--r--engines/scumm/he/moonbase/net_main.cpp25
-rw-r--r--engines/scumm/he/moonbase/net_main.h2
2 files changed, 18 insertions, 9 deletions
diff --git a/engines/scumm/he/moonbase/net_main.cpp b/engines/scumm/he/moonbase/net_main.cpp
index cca97aa534..a315c92154 100644
--- a/engines/scumm/he/moonbase/net_main.cpp
+++ b/engines/scumm/he/moonbase/net_main.cpp
@@ -36,6 +36,8 @@ Net::Net(ScummEngine_v100he *vm) : _latencyTime(1), _fakeLatency(false), _vm(vm)
_myUserId = -1;
_lastResult = 0;
+ _sessionsBeingQueried = false;
+
_sessionid = -1;
_sessions = nullptr;
_packetdata = nullptr;
@@ -48,6 +50,7 @@ Net::~Net() {
free(_packbuffer);
delete _sessions;
+ delete _packetdata;
}
int Net::hostGame(char *sessionName, char *userName) {
@@ -237,18 +240,16 @@ bool Net::destroyPlayer(int32 playerDPID) {
}
int32 Net::startQuerySessions() {
- debug(1, "Net::startQuerySessions()"); // StartQuerySessions
-
- Networking::PostRequest rq(_serverprefix + "/lobbies",
- new Common::Callback<Net, Common::JSONValue *>(this, &Net::startQuerySessionsCallback),
- new Common::Callback<Net, Networking::ErrorResponse>(this, &Net::startQuerySessionsErrorCallback));
+ if (!_sessionsBeingQueried) { // Do not run parallel queries
+ debug(1, "Net::startQuerySessions()"); // StartQuerySessions
- delete _sessions;
+ Networking::PostRequest rq(_serverprefix + "/lobbies",
+ new Common::Callback<Net, Common::JSONValue *>(this, &Net::startQuerySessionsCallback),
+ new Common::Callback<Net, Networking::ErrorResponse>(this, &Net::startQuerySessionsErrorCallback));
- rq.start();
+ _sessionsBeingQueried = true;
- while(rq.state() == Networking::PROCESSING) {
- g_system->delayMillis(5);
+ rq.start();
}
if (!_sessions)
@@ -262,11 +263,17 @@ int32 Net::startQuerySessions() {
void Net::startQuerySessionsCallback(Common::JSONValue *response) {
debug(1, "startQuerySessions: Got: '%s' which is %lu", response->stringify().c_str(), response->countChildren());
+ _sessionsBeingQueried = false;
+
+ delete _sessions;
+
_sessions = new Common::JSONValue(*response);
}
void Net::startQuerySessionsErrorCallback(Networking::ErrorResponse error) {
warning("Error in startQuerySessions(): %ld %s", error.httpResponseCode, error.response.c_str());
+
+ _sessionsBeingQueried = false;
}
int32 Net::updateQuerySessions() {
diff --git a/engines/scumm/he/moonbase/net_main.h b/engines/scumm/he/moonbase/net_main.h
index b219b66430..aaa5b9a942 100644
--- a/engines/scumm/he/moonbase/net_main.h
+++ b/engines/scumm/he/moonbase/net_main.h
@@ -112,6 +112,8 @@ public:
int _sessionid;
+ bool _sessionsBeingQueried;
+
Common::JSONValue *_sessions;
Common::JSONValue *_packetdata;