From 21421d2e86cf44a3236dd39da847ee15b366d95f Mon Sep 17 00:00:00 2001 From: Marcus Comstedt Date: Wed, 20 Apr 2011 22:30:01 +0200 Subject: DC: Move dynamic plugin handling into the platform --- backends/platform/dc/plugins.cpp | 100 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 backends/platform/dc/plugins.cpp (limited to 'backends/platform/dc/plugins.cpp') diff --git a/backends/platform/dc/plugins.cpp b/backends/platform/dc/plugins.cpp new file mode 100644 index 0000000000..7b07947847 --- /dev/null +++ b/backends/platform/dc/plugins.cpp @@ -0,0 +1,100 @@ +/* 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. + * + * $URL$ + * $Id$ + * + */ + +#include "common/scummsys.h" + +#if defined(DYNAMIC_MODULES) + +#include "backends/plugins/dynamic-plugin.h" +#include "common/fs.h" + +#include "dcloader.h" + + +class OSystem_Dreamcast::DCPlugin : public DynamicPlugin { +protected: + void *_dlHandle; + + virtual VoidFunc findSymbol(const char *symbol) { + void *func = dlsym(_dlHandle, symbol); + if (!func) + warning("Failed loading symbol '%s' from plugin '%s' (%s)", symbol, _filename.c_str(), dlerror()); + + // FIXME HACK: This is a HACK to circumvent a clash between the ISO C++ + // standard and POSIX: ISO C++ disallows casting between function pointers + // and data pointers, but dlsym always returns a void pointer. For details, + // see e.g. . + assert(sizeof(VoidFunc) == sizeof(func)); + VoidFunc tmp; + memcpy(&tmp, &func, sizeof(VoidFunc)); + return tmp; + } + +public: + DCPlugin(const Common::String &filename) + : DynamicPlugin(filename), _dlHandle(0) {} + + bool loadPlugin() { + assert(!_dlHandle); + _dlHandle = dlopen(_filename.c_str(), RTLD_LAZY); + + if (!_dlHandle) { + warning("Failed loading plugin '%s' (%s)", _filename.c_str(), dlerror()); + return false; + } + + bool ret = DynamicPlugin::loadPlugin(); + + if (ret) + dlforgetsyms(_dlHandle); + + return ret; + } + + void unloadPlugin() { + DynamicPlugin::unloadPlugin(); + if (_dlHandle) { + if (dlclose(_dlHandle) != 0) + warning("Failed unloading plugin '%s' (%s)", _filename.c_str(), dlerror()); + _dlHandle = 0; + } + } +}; + + +Plugin* OSystem_Dreamcast::createPlugin(const Common::FSNode &node) const { + return new DCPlugin(node.getPath()); +} + +bool OSystem_Dreamcast::isPluginFilename(const Common::FSNode &node) const { + // Check the plugin suffix + Common::String filename = node.getName(); + if (!filename.hasSuffix(".PLG")) + return false; + + return true; +} + +#endif // defined(DYNAMIC_MODULES) -- cgit v1.2.3 From 8a8742930665010b83ed6518fe019b68b7b9ae7f Mon Sep 17 00:00:00 2001 From: Marcus Comstedt Date: Wed, 20 Apr 2011 23:43:33 +0200 Subject: DC: Provide some feedback when loading plugins Display the names of the plugins being loaded, and display amount of free memory while doing so. This should make it easier to spot the case that too many engine plugins have been placed on the boot medium. --- backends/platform/dc/plugins.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'backends/platform/dc/plugins.cpp') diff --git a/backends/platform/dc/plugins.cpp b/backends/platform/dc/plugins.cpp index 7b07947847..be329ab314 100644 --- a/backends/platform/dc/plugins.cpp +++ b/backends/platform/dc/plugins.cpp @@ -32,6 +32,39 @@ #include "dcloader.h" +extern void draw_solid_quad(float x1, float y1, float x2, float y2, + int c0, int c1, int c2, int c3); + +static void drawPluginProgress(const Common::String &filename) +{ + ta_sync(); + void *mark = ta_txmark(); + Label lab1, lab2, lab3; + char buf[32]; + unsigned memleft = 0x8cf00000-((unsigned)sbrk(0)); + float ffree = memleft*(1.0/(16<<20)); + int fcol = (memleft < (1<<20)? 0xffff0000: + (memleft < (4<<20)? 0xffffff00: 0xff00ff00)); + snprintf(buf, sizeof(buf), "%dK free memory", memleft>>10); + lab1.create_texture("Loading plugins, please wait..."); + lab2.create_texture(filename.c_str()); + lab3.create_texture(buf); + ta_begin_frame(); + draw_solid_quad(80.0, 320.0, 560.0, 350.0, + 0xff808080, 0xff808080, 0xff808080, 0xff808080); + draw_solid_quad(85.0, 325.0, 555.0, 345.0, + 0xff202020, 0xff202020, 0xff202020, 0xff202020); + draw_solid_quad(85.0, 325.0, 85.0+470.0*ffree, 345.0, + fcol, fcol, fcol, fcol); + ta_commit_end(); + lab1.draw(100.0, 200.0, 0xffffffff); + lab2.draw(100.0, 240.0, 0xffffffff); + lab3.draw(100.0, 280.0, 0xffffffff); + ta_commit_frame(); + ta_sync(); + ta_txrelease(mark); +} + class OSystem_Dreamcast::DCPlugin : public DynamicPlugin { protected: @@ -58,6 +91,7 @@ public: bool loadPlugin() { assert(!_dlHandle); + drawPluginProgress(_filename); _dlHandle = dlopen(_filename.c_str(), RTLD_LAZY); if (!_dlHandle) { -- cgit v1.2.3