From e761f76653b1c12493d1cb047ace29264e537e4b Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 25 Oct 2010 22:41:25 +0000 Subject: SWORD25: Get rid of most of the 'kernel service/superclass' code svn-id: r53835 --- engines/sword25/fmv/movieplayer.cpp | 4 - engines/sword25/gfx/graphicengine.cpp | 4 - engines/sword25/input/inputengine.cpp | 4 - engines/sword25/kernel/kernel.cpp | 312 ++++++----------------------- engines/sword25/kernel/kernel.h | 117 +---------- engines/sword25/kernel/kernel_script.cpp | 45 ++--- engines/sword25/kernel/service_ids.h | 86 -------- engines/sword25/math/geometry.cpp | 4 - engines/sword25/package/packagemanager.cpp | 4 - engines/sword25/script/luascript.cpp | 4 - engines/sword25/sfx/soundengine.cpp | 4 - engines/sword25/sword25.cpp | 15 +- 12 files changed, 88 insertions(+), 515 deletions(-) delete mode 100644 engines/sword25/kernel/service_ids.h (limited to 'engines/sword25') diff --git a/engines/sword25/fmv/movieplayer.cpp b/engines/sword25/fmv/movieplayer.cpp index a0dda3d7cc..4193e02b2e 100644 --- a/engines/sword25/fmv/movieplayer.cpp +++ b/engines/sword25/fmv/movieplayer.cpp @@ -47,10 +47,6 @@ namespace Sword25 { #define FLT_EPSILON 1.192092896e-07F /* smallest such that 1.0+FLT_EPSILON != 1.0 */ -Service *OggTheora_CreateObject(Kernel *pKernel) { - return new MoviePlayer(pKernel); -} - #ifdef USE_THEORADEC MoviePlayer::MoviePlayer(Kernel *pKernel) : Service(pKernel), _decoder(g_system->getMixer()) { if (!registerScriptBindings()) diff --git a/engines/sword25/gfx/graphicengine.cpp b/engines/sword25/gfx/graphicengine.cpp index 54aa243cd8..e26bd5f294 100644 --- a/engines/sword25/gfx/graphicengine.cpp +++ b/engines/sword25/gfx/graphicengine.cpp @@ -91,10 +91,6 @@ GraphicEngine::~GraphicEngine() { delete _thumbnail; } -Service *GraphicEngine_CreateObject(Kernel *pKernel) { - return new GraphicEngine(pKernel); -} - bool GraphicEngine::init(int width, int height, int bitDepth, int backbufferCount, bool isWindowed_) { // Warnung ausgeben, wenn eine nicht unterstützte Bittiefe gewählt wurde. if (bitDepth != BIT_DEPTH) { diff --git a/engines/sword25/input/inputengine.cpp b/engines/sword25/input/inputengine.cpp index d268bcb15f..5d996d7f54 100644 --- a/engines/sword25/input/inputengine.cpp +++ b/engines/sword25/input/inputengine.cpp @@ -80,10 +80,6 @@ InputEngine::~InputEngine() { unregisterScriptBindings(); } -Service *InputEngine_CreateObject(Kernel *pKernel) { - return new InputEngine(pKernel); -} - bool InputEngine::init() { // No initialisation needed return true; diff --git a/engines/sword25/kernel/kernel.cpp b/engines/sword25/kernel/kernel.cpp index 2b5e655de4..9bd8ac5ff7 100644 --- a/engines/sword25/kernel/kernel.cpp +++ b/engines/sword25/kernel/kernel.cpp @@ -38,9 +38,9 @@ #include "sword25/input/inputengine.h" #include "sword25/kernel/kernel.h" #include "sword25/kernel/persistenceservice.h" -#include "sword25/kernel/service_ids.h" +#include "sword25/math/geometry.h" #include "sword25/package/packagemanager.h" -#include "sword25/script/script.h" +#include "sword25/script/luascript.h" #include "sword25/sfx/soundengine.h" namespace Sword25 { @@ -50,35 +50,26 @@ namespace Sword25 { Kernel *Kernel::_instance = 0; Kernel::Kernel() : - _running(false), - _pResourceManager(NULL), - _initSuccess(false) { + _resourceManager(NULL), + _initSuccess(false), + _gfx(0), + _sfx(0), + _input(0), + _package(0), + _script(0), + _fmv(0) + { // Log that the kernel is beign created BS_LOGLN("created."); - - // Read the BS_SERVICE_TABLE and prepare kernel structures - for (uint i = 0; i < ARRAYSIZE(BS_SERVICE_TABLE); i++) { - // Is the superclass already registered? - Superclass *pCurSuperclass = NULL; - Common::Array::iterator iter; - for (iter = _superclasses.begin(); iter != _superclasses.end(); ++iter) - if ((*iter)->getIdentifier() == BS_SERVICE_TABLE[i].superclassId) { - pCurSuperclass = *iter; - break; - } - - // If the superclass isn't already registered, then add it in - if (!pCurSuperclass) - _superclasses.push_back(new Superclass(this, BS_SERVICE_TABLE[i].superclassId)); - } + _instance = this; // Create the resource manager - _pResourceManager = new ResourceManager(this); + _resourceManager = new ResourceManager(this); // Initialise the script engine - ScriptEngine *pScript = static_cast(newService("script", "lua")); - if (!pScript || !pScript->init()) { + _script = new LuaScriptEngine(this); + if (!_script || !_script->init()) { _initSuccess = false; return; } @@ -91,248 +82,59 @@ Kernel::Kernel() : } BS_LOGLN("Script bindings registered."); - _initSuccess = true; -} - -Kernel::~Kernel() { - // Services are de-registered in reverse order of creation - while (!_serviceCreationOrder.empty()) { - Superclass *superclass = getSuperclassByIdentifier(_serviceCreationOrder.top()); - if (superclass) - superclass->disconnectService(); - _serviceCreationOrder.pop(); - } - - // Empty the Superclass list - while (_superclasses.size()) { - delete _superclasses.back(); - _superclasses.pop_back(); - } - - // Resource-Manager freigeben - delete _pResourceManager; - - BS_LOGLN("destroyed."); -} - -Kernel::Superclass::Superclass(Kernel *pKernel, const Common::String &identifier) : - _pKernel(pKernel), - _identifier(identifier), - _serviceCount(0), - _activeService(NULL) { - for (uint i = 0; i < ARRAYSIZE(BS_SERVICE_TABLE); i++) - if (BS_SERVICE_TABLE[i].superclassId == _identifier) - _serviceCount++; -} - -Kernel::Superclass::~Superclass() { - disconnectService(); -} - -/** - * Gets the identifier of a service with a given superclass. - * The number of services in a superclass can be learned with GetServiceCount(). - * @param superclassId The name of the superclass - * e.g.: "sfx", "gfx", "package" ... - * @param Number die Nummer des Services, dessen Bezeichner man erfahren will.
- * Hierbei ist zu beachten, dass der erste Service die Nummer 0 erhält. Number muss also eine Zahl zwischen - * 0 und GetServiceCount() - 1 sein. - */ -Common::String Kernel::Superclass::getServiceIdentifier(uint number) { - if (number > _serviceCount) - return NULL; - - uint curServiceOrd = 0; - for (uint i = 0; i < ARRAYSIZE(BS_SERVICE_TABLE); i++) { - if (BS_SERVICE_TABLE[i].superclassId == _identifier) { - if (number == curServiceOrd) - return BS_SERVICE_TABLE[i].serviceId; - else - curServiceOrd++; - } - } - - return Common::String(); -} - -/** - * Creates a new service with the given identifier. Returns a pointer to the service, or null if the - * service could not be created - * Note: All services must be registered in service_ids.h, otherwise they cannot be created here - * @param superclassId The name of the superclass of the service - * e.g.: "sfx", "gfx", "package" ... - * @param serviceId The name of the service - * For the superclass "sfx" an example could be "Fmod" or "directsound" - */ -Service *Kernel::Superclass::newService(const Common::String &serviceId) { - for (uint i = 0; i < ARRAYSIZE(BS_SERVICE_TABLE); i++) - if (BS_SERVICE_TABLE[i].superclassId == _identifier && - BS_SERVICE_TABLE[i].serviceId == serviceId) { - Service *newService_ = BS_SERVICE_TABLE[i].create(_pKernel); - - if (newService_) { - disconnectService(); - BS_LOGLN("Service '%s' created from superclass '%s'.", serviceId.c_str(), _identifier.c_str()); - _activeService = newService_; - _activeServiceName = BS_SERVICE_TABLE[i].serviceId; - return _activeService; - } else { - BS_LOG_ERRORLN("Failed to create service '%s' from superclass '%s'.", serviceId.c_str(), _identifier.c_str()); - return NULL; - } - } - - BS_LOG_ERRORLN("Service '%s' is not avaliable from superclass '%s'.", serviceId.c_str(), _identifier.c_str()); - return NULL; -} - -/** - * Ends the current service of a superclass. Returns true on success, and false if the superclass - * does not exist or if not service was active - * @param superclassId The name of the superclass which is to be disconnected - * e.g.: "sfx", "gfx", "package" ... - */ -bool Kernel::Superclass::disconnectService() { - if (_activeService) { - delete _activeService; - _activeService = 0; - BS_LOGLN("Active service '%s' disconnected from superclass '%s'.", _activeServiceName.c_str(), _identifier.c_str()); - return true; - } - - return false; -} - -Kernel::Superclass *Kernel::getSuperclassByIdentifier(const Common::String &identifier) const { - Common::Array::const_iterator iter; - for (iter = _superclasses.begin(); iter != _superclasses.end(); ++iter) { - if ((*iter)->getIdentifier() == identifier) - return *iter; - } - - // BS_LOG_ERRORLN("Superclass '%s' does not exist.", identifier.c_str()); - return NULL; -} - -/** - * Returns the number of register superclasses - */ -uint Kernel::getSuperclassCount() const { - return _superclasses.size(); -} - -/** - * Returns the name of a superclass with the specified index. - * Note: The number of superclasses can be retrieved using GetSuperclassCount - * @param Number The number of the superclass to return the identifier for. - * It should be noted that the number should be between 0 und GetSuperclassCount() - 1. - */ -Common::String Kernel::getSuperclassIdentifier(uint number) const { - if (number > _superclasses.size()) - return NULL; + _input = new InputEngine(this); + assert(_input); - uint curSuperclassOrd = 0; - Common::Array::const_iterator iter; - for (iter = _superclasses.begin(); iter != _superclasses.end(); ++iter) { - if (curSuperclassOrd == number) - return ((*iter)->getIdentifier()); + _gfx = new GraphicEngine(this); + assert(_gfx); - curSuperclassOrd++; - } + _sfx = new SoundEngine(this); + assert(_sfx); - return Common::String(); -} + _package = new PackageManager(this); + assert(_package); -/** - * Returns the number of services registered with a given superclass - * @param superclassId The name of the superclass - * e.g.: "sfx", "gfx", "package" ... - */ -uint Kernel::getServiceCount(const Common::String &superclassId) const { - Superclass *pSuperclass = getSuperclassByIdentifier(superclassId); - if (!pSuperclass) - return 0; + _geometry = new Geometry(this); + assert(_geometry); - return pSuperclass->getServiceCount(); +#ifdef USE_THEORADEC + _fmv = new MoviePlayer(this); + assert(_fmv); +#endif + _initSuccess = true; } -/** - * Gets the identifier of a service with a given superclass. - * The number of services in a superclass can be learned with GetServiceCount(). - * @param superclassId The name of the superclass - * e.g.: "sfx", "gfx", "package" ... - * @param Number die Nummer des Services, dessen Bezeichner man erfahren will.
- * Hierbei ist zu beachten, dass der erste Service die Nummer 0 erhält. Number muss also eine Zahl zwischen - * 0 und GetServiceCount() - 1 sein. - */ -Common::String Kernel::getServiceIdentifier(const Common::String &superclassId, uint number) const { - Superclass *pSuperclass = getSuperclassByIdentifier(superclassId); - if (!pSuperclass) - return NULL; +Kernel::~Kernel() { + // Services are de-registered in reverse order of creation - return (pSuperclass->getServiceIdentifier(number)); -} + delete _input; + _input = 0; -/** - * Creates a new service with the given identifier. Returns a pointer to the service, or null if the - * service could not be created - * Note: All services must be registered in service_ids.h, otherwise they cannot be created here - * @param superclassId The name of the superclass of the service - * e.g.: "sfx", "gfx", "package" ... - * @param serviceId The name of the service - * For the superclass "sfx" an example could be "Fmod" or "directsound" - */ -Service *Kernel::newService(const Common::String &superclassId, const Common::String &serviceId) { - Superclass *pSuperclass = getSuperclassByIdentifier(superclassId); - if (!pSuperclass) - return NULL; + delete _gfx; + _gfx = 0; - // Die Reihenfolge merken, in der Services erstellt werden, damit sie später in umgekehrter Reihenfolge entladen werden können. - _serviceCreationOrder.push(superclassId); + delete _sfx; + _sfx = 0; - return pSuperclass->newService(serviceId); -} + delete _package; + _package = 0; -/** - * Ends the current service of a superclass. - * @param superclassId The name of the superclass which is to be disconnected - * e.g.: "sfx", "gfx", "package" ... - * @return true on success, and false if the superclass does not exist or if not service was active. - */ -bool Kernel::disconnectService(const Common::String &superclassId) { - Superclass *pSuperclass = getSuperclassByIdentifier(superclassId); - if (!pSuperclass) - return false; + delete _geometry; + _geometry = 0; - return pSuperclass->disconnectService(); -} +#ifdef USE_THEORADEC + delete _fmv; + _fmv = 0; +#endif -/** - * Returns a pointer to the currently active service object of a superclass. - * @param superclassId The name of the superclass - * e.g.: "sfx", "gfx", "package" ... - */ -Service *Kernel::getService(const Common::String &superclassId) { - Superclass *pSuperclass = getSuperclassByIdentifier(superclassId); - if (!pSuperclass) - return NULL; - - return (pSuperclass->getActiveService()); -} + delete _script; + _script = 0; -/** - * Returns the name of the currently active service object of a superclass. - * If an error occurs, then an empty string is returned - * @param superclassId The name of the superclass - * e.g.: "sfx", "gfx", "package" ... - */ -Common::String Kernel::getActiveServiceIdentifier(const Common::String &superclassId) { - Superclass *pSuperclass = getSuperclassByIdentifier(superclassId); - if (!pSuperclass) - return Common::String(); + // Resource-Manager freigeben + delete _resourceManager; - return pSuperclass->getActiveServiceName(); + BS_LOGLN("destroyed."); } /** @@ -364,42 +166,42 @@ size_t Kernel::getUsedMemory() { * Returns a pointer to the active Gfx Service, or NULL if no Gfx service is active. */ GraphicEngine *Kernel::getGfx() { - return static_cast(getService("gfx")); + return _gfx; } /** * Returns a pointer to the active Sfx Service, or NULL if no Sfx service is active. */ SoundEngine *Kernel::getSfx() { - return static_cast(getService("sfx")); + return _sfx; } /** * Returns a pointer to the active input service, or NULL if no input service is active. */ InputEngine *Kernel::getInput() { - return static_cast(getService("input")); + return _input; } /** * Returns a pointer to the active package manager, or NULL if no manager is active. */ PackageManager *Kernel::getPackage() { - return static_cast(getService("package")); + return _package; } /** * Returns a pointer to the script engine, or NULL if it is not active. */ ScriptEngine *Kernel::getScript() { - return static_cast(getService("script")); + return _script; } /** * Returns a pointer to the movie player, or NULL if it is not active. */ MoviePlayer *Kernel::getFMV() { - return static_cast(getService("fmv")); + return _fmv; } void Kernel::sleep(uint msecs) const { diff --git a/engines/sword25/kernel/kernel.h b/engines/sword25/kernel/kernel.h index f369ab3485..252de64e80 100644 --- a/engines/sword25/kernel/kernel.h +++ b/engines/sword25/kernel/kernel.h @@ -58,6 +58,7 @@ namespace Sword25 { // Class definitions class Service; +class Geometry; class GraphicEngine; class ScriptEngine; class SoundEngine; @@ -74,74 +75,6 @@ class MoviePlayer; class Kernel { public: - // Service Methods - // --------------- - - /** - * Creates a new service with the given identifier. Returns a pointer to the service, or null if the - * service could not be created - * Note: All services must be registered in service_ids.h, otherwise they cannot be created here - * @param SuperclassIdentifier The name of the superclass of the service - * z.B: "sfx", "gfx", "package" ... - * @param ServiceIdentifier The name of the service - * For the superclass "sfx" an example could be "Fmod" or "directsound" - */ - Service *newService(const Common::String &superclassIdentifier, const Common::String &serviceIdentifier); - - /** - * Ends the current service of a superclass. Returns true on success, and false if the superclass - * does not exist or if not service was active - * @param SuperclassIdentfier The name of the superclass which is to be disconnected - * z.B: "sfx", "gfx", "package" ... - */ - bool disconnectService(const Common::String &superclassIdentifier); - - /** - * Returns a pointer to the currently active service object of a superclass - * @param SuperclassIdentfier The name of the superclass - * z.B: "sfx", "gfx", "package" ... - */ - Service *getService(const Common::String &superclassIdentifier); - - /** - * Returns the name of the currentl active service object of a superclass. - * If an error occurs, then an empty string is returned - * @param SuperclassIdentfier The name of the superclass - * z.B: "sfx", "gfx", "package" ... - */ - Common::String getActiveServiceIdentifier(const Common::String &superclassIdentifier); - - /** - * Returns the number of register superclasses - */ - uint getSuperclassCount() const; - - /** - * Returns the name of a superclass with the specified index. - * Note: The number of superclasses can be retrieved using GetSuperclassCount - * @param Number The number of the superclass to return the identifier for. - * It should be noted that the number should be between 0 und GetSuperclassCount() - 1. - */ - Common::String getSuperclassIdentifier(uint number) const; - - /** - * Returns the number of services registered with a given superclass - * @param SuperclassIdentifier The name of the superclass - * z.B: "sfx", "gfx", "package" ... - */ - uint getServiceCount(const Common::String &superclassIdentifier) const; - - /** - * Gets the identifier of a service with a given superclass. - * The number of services in a superclass can be learned with GetServiceCount(). - * @param SuperclassIdentifier The name of the superclass - * z.B: "sfx", "gfx", "package" ... - * @param Number die Nummer des Services, dessen Bezeichner man erfahren will.
- * Hierbei ist zu beachten, dass der erste Service die Nummer 0 erhält. Number muss also eine Zahl zwischen - * 0 und GetServiceCount() - 1 sein. - */ - Common::String getServiceIdentifier(const Common::String &superclassIdentifier, uint number) const; - /** * Returns the elapsed time since startup in milliseconds */ @@ -157,7 +90,7 @@ public: * Returns a pointer to the BS_ResourceManager */ ResourceManager *getResourceManager() { - return _pResourceManager; + return _resourceManager; } /** * Returns how much memory is being used @@ -243,43 +176,7 @@ private: // ----------------------------------------------------------------------------- static Kernel *_instance; - // Superclass class - // ---------------- - class Superclass { - private: - Kernel *_pKernel; - uint _serviceCount; - Common::String _identifier; - Service *_activeService; - Common::String _activeServiceName; - - public: - Superclass(Kernel *pKernel, const Common::String &identifier); - ~Superclass(); - - uint getServiceCount() const { - return _serviceCount; - } - Common::String getIdentifier() const { - return _identifier; - } - Service *getActiveService() const { - return _activeService; - } - Common::String getActiveServiceName() const { - return _activeServiceName; - } - Common::String getServiceIdentifier(uint number); - Service *newService(const Common::String &serviceIdentifier); - bool disconnectService(); - }; - - Common::Array _superclasses; - Common::Stack _serviceCreationOrder; - Superclass *getSuperclassByIdentifier(const Common::String &identifier) const; - bool _initSuccess; // Specifies whether the engine was set up correctly - bool _running; // Specifies whether the application should keep running on the next main loop iteration // Random number generator // ----------------------- @@ -287,7 +184,15 @@ private: // Resourcemanager // --------------- - ResourceManager *_pResourceManager; + ResourceManager *_resourceManager; + + GraphicEngine *_gfx; + SoundEngine *_sfx; + InputEngine *_input; + PackageManager *_package; + ScriptEngine *_script; + Geometry *_geometry; + MoviePlayer *_fmv; bool registerScriptBindings(); }; diff --git a/engines/sword25/kernel/kernel_script.cpp b/engines/sword25/kernel/kernel_script.cpp index c00d72b019..275b55fb73 100644 --- a/engines/sword25/kernel/kernel_script.cpp +++ b/engines/sword25/kernel/kernel_script.cpp @@ -43,57 +43,43 @@ namespace Sword25 { static int disconnectService(lua_State *L) { - Kernel *pKernel = Kernel::getInstance(); - BS_ASSERT(pKernel); - - lua_pushboolean(L, pKernel->disconnectService(luaL_checkstring(L, 1))); + // This function apparently is not used by the game scripts + lua_pushboolean(L, true); return 1; } static int getActiveServiceIdentifier(lua_State *L) { - Kernel *pKernel = Kernel::getInstance(); - BS_ASSERT(pKernel); - - lua_pushstring(L, pKernel->getActiveServiceIdentifier(luaL_checkstring(L, 1)).c_str()); + // This function apparently is not used by the game scripts + lua_pushstring(L, "QUUX"); return 1; } static int getSuperclassCount(lua_State *L) { - Kernel *pKernel = Kernel::getInstance(); - BS_ASSERT(pKernel); - - lua_pushnumber(L, pKernel->getSuperclassCount()); + // This function is only used by a single function in system/kernel.lua which is never called. + lua_pushnumber(L, 0); return 1; } static int getSuperclassIdentifier(lua_State *L) { - Kernel *pKernel = Kernel::getInstance(); - BS_ASSERT(pKernel); - - lua_pushstring(L, pKernel->getSuperclassIdentifier( - static_cast(luaL_checknumber(L, 1))).c_str()); + // This function is only used by a single function in system/kernel.lua which is never called. + lua_pushstring(L, "FOO"); return 1; } static int getServiceCount(lua_State *L) { - Kernel *pKernel = Kernel::getInstance(); - BS_ASSERT(pKernel); - - lua_pushnumber(L, pKernel->getServiceCount(luaL_checkstring(L, 1))); + // This function is only used by a single function in system/kernel.lua which is never called. + lua_pushnumber(L, 0); return 1; } static int getServiceIdentifier(lua_State *L) { - Kernel *pKernel = Kernel::getInstance(); - BS_ASSERT(pKernel); - - lua_pushstring(L, pKernel->getServiceIdentifier(luaL_checkstring(L, 1), - static_cast(luaL_checknumber(L, 2))).c_str()); + // This function is only used by a single function in system/kernel.lua which is never called. + lua_pushstring(L, "BAR"); return 1; } @@ -117,10 +103,9 @@ static int getTimer(lua_State *L) { } static int startService(lua_State *L) { - Kernel *pKernel = Kernel::getInstance(); - BS_ASSERT(pKernel); - - lua_pushbooleancpp(L, pKernel->newService(luaL_checkstring(L, 1), luaL_checkstring(L, 2)) != NULL); + // This function is used by system/boot.lua to init all services. + // However, we do nothing here, as we just hard code the init sequence. + lua_pushbooleancpp(L, true); return 1; } diff --git a/engines/sword25/kernel/service_ids.h b/engines/sword25/kernel/service_ids.h deleted file mode 100644 index b5ffaef16c..0000000000 --- a/engines/sword25/kernel/service_ids.h +++ /dev/null @@ -1,86 +0,0 @@ -/* 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$ - * - */ - -/* - * This code is based on Broken Sword 2.5 engine - * - * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer - * - * Licensed under GNU GPL v2 - * - */ - -/* - * service_ids.h - * ------------- - * This file lists all the services. - * EVERY new service needs to be entered here, otherwise it cannot be instantiated - * by pKernel->NewService(..) - * - * Autor: Malte Thiesen - */ - -#ifndef SWORD25_SERVICE_IDS -#define SWORD25_SERVICE_IDS - -#include "sword25/kernel/common.h" - -namespace Sword25 { - -Service *GraphicEngine_CreateObject(Kernel *pKernel); -Service *PackageManager_CreateObject(Kernel *pKernel); -Service *InputEngine_CreateObject(Kernel *pKernel); -Service *SoundEngine_CreateObject(Kernel *pKernel); -Service *LuaScriptEngine_CreateObject(Kernel *pKernel); -Service *Geometry_CreateObject(Kernel *pKernel); -Service *OggTheora_CreateObject(Kernel *pKernel); - - -/** - * This is only a small struct that manages the data of a service. - */ -struct BS_ServiceInfo { - const char *superclassId; - const char *serviceId; - Service *(*create)(Kernel *); -}; - -// Services are recorded in this table -const BS_ServiceInfo BS_SERVICE_TABLE[] = { - // The first two values are the name of the superclass and service. - // The third value is the static method of the class that creates an object - // of the class and returns it. - { "gfx", "opengl", GraphicEngine_CreateObject }, - { "package", "archiveFS", PackageManager_CreateObject }, - { "input", "winapi", InputEngine_CreateObject }, - { "sfx", "fmodex", SoundEngine_CreateObject }, - { "script", "lua", LuaScriptEngine_CreateObject }, - { "geometry", "std", Geometry_CreateObject }, - { "fmv", "oggtheora", OggTheora_CreateObject } -}; - -} // End of namespace Sword25 - -#endif diff --git a/engines/sword25/math/geometry.cpp b/engines/sword25/math/geometry.cpp index caa10160e9..bad6fcdb06 100644 --- a/engines/sword25/math/geometry.cpp +++ b/engines/sword25/math/geometry.cpp @@ -46,8 +46,4 @@ Geometry::Geometry(Kernel *pKernel) : Service(pKernel) { } -Service *Geometry_CreateObject(Kernel *pKernel) { - return new Geometry(pKernel); -} - } // End of namespace Sword25 diff --git a/engines/sword25/package/packagemanager.cpp b/engines/sword25/package/packagemanager.cpp index 0286aad9e6..ee13cd5920 100644 --- a/engines/sword25/package/packagemanager.cpp +++ b/engines/sword25/package/packagemanager.cpp @@ -75,10 +75,6 @@ PackageManager::~PackageManager() { } -Service *PackageManager_CreateObject(Kernel *kernelPtr) { - return new PackageManager(kernelPtr); -} - /** * Scans through the archive list for a specified file */ diff --git a/engines/sword25/script/luascript.cpp b/engines/sword25/script/luascript.cpp index 4ed4a158f9..ad5fad1322 100644 --- a/engines/sword25/script/luascript.cpp +++ b/engines/sword25/script/luascript.cpp @@ -64,10 +64,6 @@ LuaScriptEngine::~LuaScriptEngine() { lua_close(_state); } -Service *LuaScriptEngine_CreateObject(Kernel *KernelPtr) { - return new LuaScriptEngine(KernelPtr); -} - namespace { int panicCB(lua_State *L) { BS_LOG_ERRORLN("Lua panic. Error message: %s", lua_isnil(L, -1) ? "" : lua_tostring(L, -1)); diff --git a/engines/sword25/sfx/soundengine.cpp b/engines/sword25/sfx/soundengine.cpp index 3498e23d3d..fa39639f51 100644 --- a/engines/sword25/sfx/soundengine.cpp +++ b/engines/sword25/sfx/soundengine.cpp @@ -67,10 +67,6 @@ SoundEngine::SoundEngine(Kernel *pKernel) : ResourceService(pKernel) { _handles[i].type = kFreeHandle; } -Service *SoundEngine_CreateObject(Kernel *pKernel) { - return new SoundEngine(pKernel); -} - bool SoundEngine::init(uint sampleRate, uint channels) { warning("STUB: SoundEngine::init(%d, %d)", sampleRate, channels); diff --git a/engines/sword25/sword25.cpp b/engines/sword25/sword25.cpp index 9f3c963013..62fb3506d9 100644 --- a/engines/sword25/sword25.cpp +++ b/engines/sword25/sword25.cpp @@ -95,14 +95,8 @@ Common::Error Sword25Engine::appStart() { return Common::kUnknownError; } - // Package-Manager starten, damit die Packfiles geladen werden können. - PackageManager *packageManagerPtr = static_cast(Kernel::getInstance()->newService("package", PACKAGE_MANAGER)); - if (!packageManagerPtr) { - BS_LOG_ERRORLN("PackageManager initialization failed."); - return Common::kUnknownError; - } - - // Packages laden oder das aktuelle Verzeichnis mounten, wenn das über Kommandozeile angefordert wurde. + // Load packages + PackageManager *packageManagerPtr = Kernel::getInstance()->getPackage(); if (getGameFlags() & GF_EXTRACTED) { if (!packageManagerPtr->loadDirectoryAsPackage(ConfMan.get("path"), "/")) return Common::kUnknownError; @@ -111,7 +105,7 @@ Common::Error Sword25Engine::appStart() { return Common::kUnknownError; } - // Einen Pointer auf den Skript-Engine holen. + // Pass the command line to the script engine. ScriptEngine *scriptPtr = Kernel::getInstance()->getScript(); if (!scriptPtr) { BS_LOG_ERRORLN("Script intialization failed."); @@ -152,7 +146,8 @@ bool Sword25Engine::loadPackages() { BS_ASSERT(packageManagerPtr); // Load the main package - if (!packageManagerPtr->loadPackage("data.b25c", "/")) return false; + if (!packageManagerPtr->loadPackage("data.b25c", "/")) + return false; // Get the contents of the main program directory and sort them alphabetically Common::FSNode dir(ConfMan.get("path")); -- cgit v1.2.3