aboutsummaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authorAlexander Tkachev2016-06-03 18:04:48 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commit9d186929e16ce023222028143a280aca03605fe9 (patch)
tree4a81c58a7613c49dfb44fb3efe7cbfe6ce5d74c4 /backends
parent7ff1f918084b8d41826ad869d8c9865e1d53e082 (diff)
downloadscummvm-rg350-9d186929e16ce023222028143a280aca03605fe9.tar.gz
scummvm-rg350-9d186929e16ce023222028143a280aca03605fe9.tar.bz2
scummvm-rg350-9d186929e16ce023222028143a280aca03605fe9.zip
CLOUD: Add CloudIcon
To achieve smoother animation, ConnectionManager's timer now is 20 times more frequent. I'm encountering some strange libcurl.dll segfault problem when I close the application while some Requests are active. It's not CloudIcon-related, so it's more likely related to this 20 FPS timer. This problem shows up only in Visual Studio for me.
Diffstat (limited to 'backends')
-rw-r--r--backends/module.mk1
-rw-r--r--backends/networking/curl/cloudicon.cpp50
-rw-r--r--backends/networking/curl/cloudicon.h40
-rw-r--r--backends/networking/curl/connectionmanager.cpp17
-rw-r--r--backends/networking/curl/connectionmanager.h10
5 files changed, 112 insertions, 6 deletions
diff --git a/backends/module.mk b/backends/module.mk
index 8833edc9db..f1ba8b8b1b 100644
--- a/backends/module.mk
+++ b/backends/module.mk
@@ -45,6 +45,7 @@ ifdef USE_LIBCURL
MODULE_OBJS += \
networking/curl/connectionmanager.o \
networking/curl/networkreadstream.o \
+ networking/curl/cloudicon.o \
networking/curl/curlrequest.o \
networking/curl/curljsonrequest.o \
networking/curl/request.o
diff --git a/backends/networking/curl/cloudicon.cpp b/backends/networking/curl/cloudicon.cpp
new file mode 100644
index 0000000000..477e864d82
--- /dev/null
+++ b/backends/networking/curl/cloudicon.cpp
@@ -0,0 +1,50 @@
+/* ScummVM - Graphic Adventure Engine
+*
+* ScummVM is the legal property of its developers, whose names
+* are too numerous to list here. Please refer to the COPYRIGHT
+* file distributed with this source distribution.
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*
+*/
+
+#include "backends/networking/curl/cloudicon.h"
+#include "backends/cloud/cloudmanager.h"
+#include "gui/ThemeEngine.h"
+#include "gui/gui-manager.h"
+
+namespace Networking {
+
+CloudIcon::CloudIcon(): _frame(0) {}
+
+CloudIcon::~CloudIcon() {}
+
+void CloudIcon::draw() {
+ Cloud::Storage *storage = CloudMan.getCurrentStorage();
+ bool working = (storage && storage->isWorking());
+ if (working) {
+ //buf = animation frame;
+ if (g_system) {
+ const Graphics::Surface *s = g_gui.theme()->getImageSurface(GUI::ThemeEngine::kImageLogoSmall);
+ int x = 10, y = 10;
+ g_system->copyRectToOSD(s->getPixels(), s->pitch, x, y, s->w, s->h);
+ }
+ } else {
+ //buf = empty;
+ //TODO: put empty piece to OSD?
+ }
+}
+
+} // End of namespace Networking
diff --git a/backends/networking/curl/cloudicon.h b/backends/networking/curl/cloudicon.h
new file mode 100644
index 0000000000..dc28c8290d
--- /dev/null
+++ b/backends/networking/curl/cloudicon.h
@@ -0,0 +1,40 @@
+/* ScummVM - Graphic Adventure Engine
+*
+* ScummVM is the legal property of its developers, whose names
+* are too numerous to list here. Please refer to the COPYRIGHT
+* file distributed with this source distribution.
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*
+*/
+
+#ifndef BACKENDS_NETWORKING_CURL_CLOUDICON_H
+#define BACKENDS_NETWORKING_CURL_CLOUDICON_H
+
+namespace Networking {
+
+class CloudIcon {
+ int _frame;
+
+public:
+ CloudIcon();
+ ~CloudIcon();
+
+ void draw();
+};
+
+} // End of namespace Networking
+
+#endif
diff --git a/backends/networking/curl/connectionmanager.cpp b/backends/networking/curl/connectionmanager.cpp
index 44511fdb23..c044a1577d 100644
--- a/backends/networking/curl/connectionmanager.cpp
+++ b/backends/networking/curl/connectionmanager.cpp
@@ -37,7 +37,7 @@ DECLARE_SINGLETON(Networking::ConnectionManager);
namespace Networking {
-ConnectionManager::ConnectionManager(): _multi(0), _timerStarted(false) {
+ConnectionManager::ConnectionManager(): _multi(0), _timerStarted(false), _frame(0) {
curl_global_init(CURL_GLOBAL_ALL);
_multi = curl_multi_init();
}
@@ -52,12 +52,13 @@ ConnectionManager::~ConnectionManager() {
delete request;
if (callback) (*callback)(request);
}
- _requests.clear();
- _handleMutex.unlock();
+ _requests.clear();
//cleanup
curl_multi_cleanup(_multi);
curl_global_cleanup();
+ _multi = nullptr;
+ _handleMutex.unlock();
}
void ConnectionManager::registerEasyHandle(CURL *easy) {
@@ -95,9 +96,13 @@ void ConnectionManager::stopTimer() {
void ConnectionManager::handle() {
//lock mutex here (in case another handle() would be called before this one ends)
_handleMutex.lock();
- interateRequests();
- processTransfers();
+ ++_frame;
+ if (_frame % CLOUD_PERIOD == 0) interateRequests();
+ if (_frame % CURL_PERIOD == 0) processTransfers();
_handleMutex.unlock();
+
+ //icon redrawing is doesn't require any mutex, but must be done after requests are iterated
+ _icon.draw();
}
void ConnectionManager::interateRequests() {
@@ -123,6 +128,8 @@ void ConnectionManager::interateRequests() {
}
void ConnectionManager::processTransfers() {
+ if (!_multi) return;
+
//check libcurl's transfers and notify requests of messages from queue (transfer completion or failure)
int transfersRunning;
curl_multi_perform(_multi, &transfersRunning);
diff --git a/backends/networking/curl/connectionmanager.h b/backends/networking/curl/connectionmanager.h
index a91bc01d87..3a2e974bf4 100644
--- a/backends/networking/curl/connectionmanager.h
+++ b/backends/networking/curl/connectionmanager.h
@@ -23,6 +23,7 @@
#ifndef BACKENDS_NETWORKING_CURL_CONNECTIONMANAGER_H
#define BACKENDS_NETWORKING_CURL_CONNECTIONMANAGER_H
+#include "backends/networking/curl/cloudicon.h"
#include "backends/networking/curl/request.h"
#include "common/str.h"
#include "common/singleton.h"
@@ -38,6 +39,11 @@ namespace Networking {
class NetworkReadStream;
class ConnectionManager : public Common::Singleton<ConnectionManager> {
+ static const uint32 FRAMES_PER_SECOND = 20;
+ static const uint32 TIMER_INTERVAL = 1000000 / FRAMES_PER_SECOND;
+ static const uint32 CLOUD_PERIOD = 20; //every 20th frame
+ static const uint32 CURL_PERIOD = 1; //every frame
+
friend void connectionsThread(void *); //calls handle()
typedef Common::BaseCallback<Request *> *RequestCallback;
@@ -73,8 +79,10 @@ class ConnectionManager : public Common::Singleton<ConnectionManager> {
bool _timerStarted;
Common::Array<RequestWithCallback> _requests;
Common::Mutex _handleMutex;
+ CloudIcon _icon;
+ uint32 _frame;
- void startTimer(int interval = 1000000); //1 second is the default interval
+ void startTimer(int interval = TIMER_INTERVAL);
void stopTimer();
void handle();
void interateRequests();