2010-07-31 06:23:38 +00:00
|
|
|
|
/* 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$
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2010-08-06 13:13:25 +00:00
|
|
|
|
/*
|
2010-07-31 09:53:02 +00:00
|
|
|
|
* This code is based on Broken Sword 2.5 engine
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
|
|
|
|
*
|
|
|
|
|
* Licensed under GNU GPL v2
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
#include "common/system.h"
|
2010-07-30 09:02:39 +00:00
|
|
|
|
#include "sword25/gfx/graphicengine.h"
|
2010-07-31 06:23:38 +00:00
|
|
|
|
#include "sword25/fmv/movieplayer.h"
|
2010-07-30 09:02:39 +00:00
|
|
|
|
#include "sword25/input/inputengine.h"
|
2010-07-31 06:23:38 +00:00
|
|
|
|
#include "sword25/kernel/kernel.h"
|
|
|
|
|
#include "sword25/kernel/persistenceservice.h"
|
|
|
|
|
#include "sword25/kernel/service_ids.h"
|
2010-07-30 09:02:39 +00:00
|
|
|
|
#include "sword25/package/packagemanager.h"
|
|
|
|
|
#include "sword25/script/script.h"
|
2010-07-31 06:23:38 +00:00
|
|
|
|
#include "sword25/sfx/soundengine.h"
|
|
|
|
|
|
|
|
|
|
namespace Sword25 {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
|
|
#define BS_LOG_PREFIX "KERNEL"
|
|
|
|
|
|
2010-10-19 21:03:33 +00:00
|
|
|
|
Kernel *Kernel::_instance = 0;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
2010-08-18 12:58:22 +00:00
|
|
|
|
Kernel::Kernel() :
|
2010-10-19 21:03:33 +00:00
|
|
|
|
_running(false),
|
2010-07-29 19:53:02 +00:00
|
|
|
|
_pResourceManager(NULL),
|
2010-10-19 21:03:33 +00:00
|
|
|
|
_initSuccess(false) {
|
2010-08-06 13:13:25 +00:00
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
// Log that the kernel is beign created
|
2010-07-29 19:53:02 +00:00
|
|
|
|
BS_LOGLN("created.");
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
// Read the BS_SERVICE_TABLE and prepare kernel structures
|
2010-10-19 09:43:53 +00:00
|
|
|
|
for (uint i = 0; i < ARRAYSIZE(BS_SERVICE_TABLE); i++) {
|
2010-07-31 06:23:38 +00:00
|
|
|
|
// Is the superclass already registered?
|
|
|
|
|
Superclass *pCurSuperclass = NULL;
|
2010-10-19 21:03:33 +00:00
|
|
|
|
Common::Array<Superclass *>::iterator iter;
|
|
|
|
|
for (iter = _superclasses.begin(); iter != _superclasses.end(); ++iter)
|
|
|
|
|
if ((*iter)->getIdentifier() == BS_SERVICE_TABLE[i].superclassId) {
|
|
|
|
|
pCurSuperclass = *iter;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
// If the superclass isn't already registered, then add it in
|
2010-07-29 19:53:02 +00:00
|
|
|
|
if (!pCurSuperclass)
|
2010-10-19 09:44:13 +00:00
|
|
|
|
_superclasses.push_back(new Superclass(this, BS_SERVICE_TABLE[i].superclassId));
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
// Create the resource manager
|
2010-08-18 12:58:22 +00:00
|
|
|
|
_pResourceManager = new ResourceManager(this);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
// Initialise the script engine
|
2010-10-19 21:03:33 +00:00
|
|
|
|
ScriptEngine *pScript = static_cast<ScriptEngine *>(newService("script", "lua"));
|
2010-10-03 13:25:22 +00:00
|
|
|
|
if (!pScript || !pScript->init()) {
|
2010-10-19 21:03:33 +00:00
|
|
|
|
_initSuccess = false;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
// Register kernel script bindings
|
2010-10-19 21:03:33 +00:00
|
|
|
|
if (!registerScriptBindings()) {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
BS_LOG_ERRORLN("Script bindings could not be registered.");
|
2010-10-19 21:03:33 +00:00
|
|
|
|
_initSuccess = false;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
BS_LOGLN("Script bindings registered.");
|
|
|
|
|
|
2010-10-19 21:03:33 +00:00
|
|
|
|
_initSuccess = true;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-18 12:58:22 +00:00
|
|
|
|
Kernel::~Kernel() {
|
2010-07-31 06:23:38 +00:00
|
|
|
|
// Services are de-registered in reverse order of creation
|
2010-10-19 21:03:33 +00:00
|
|
|
|
while (!_serviceCreationOrder.empty()) {
|
|
|
|
|
Superclass *superclass = getSuperclassByIdentifier(_serviceCreationOrder.top());
|
|
|
|
|
if (superclass)
|
|
|
|
|
superclass->disconnectService();
|
|
|
|
|
_serviceCreationOrder.pop();
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
// Empty the Superclass list
|
2010-10-19 09:44:13 +00:00
|
|
|
|
while (_superclasses.size()) {
|
|
|
|
|
delete _superclasses.back();
|
|
|
|
|
_superclasses.pop_back();
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
2010-08-06 13:13:25 +00:00
|
|
|
|
|
2010-07-29 19:53:02 +00:00
|
|
|
|
// Resource-Manager freigeben
|
|
|
|
|
delete _pResourceManager;
|
|
|
|
|
|
|
|
|
|
BS_LOGLN("destroyed.");
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-19 21:03:33 +00:00
|
|
|
|
Kernel::Superclass::Superclass(Kernel *pKernel, const Common::String &identifier) :
|
2010-07-29 19:53:02 +00:00
|
|
|
|
_pKernel(pKernel),
|
2010-10-19 21:03:33 +00:00
|
|
|
|
_identifier(identifier),
|
|
|
|
|
_serviceCount(0),
|
|
|
|
|
_activeService(NULL) {
|
2010-10-19 09:43:53 +00:00
|
|
|
|
for (uint i = 0; i < ARRAYSIZE(BS_SERVICE_TABLE); i++)
|
2010-10-19 21:03:33 +00:00
|
|
|
|
if (BS_SERVICE_TABLE[i].superclassId == _identifier)
|
|
|
|
|
_serviceCount++;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-08-18 12:58:22 +00:00
|
|
|
|
Kernel::Superclass::~Superclass() {
|
2010-10-19 21:03:33 +00:00
|
|
|
|
disconnectService();
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* Gets the identifier of a service with a given superclass.
|
|
|
|
|
* The number of services in a superclass can be learned with GetServiceCount().
|
2010-10-19 09:44:13 +00:00
|
|
|
|
* @param superclassId The name of the superclass
|
|
|
|
|
* e.g.: "sfx", "gfx", "package" ...
|
2010-07-31 06:23:38 +00:00
|
|
|
|
* @param Number die Nummer des Services, dessen Bezeichner man erfahren will.<br>
|
2010-08-06 13:13:25 +00:00
|
|
|
|
* Hierbei ist zu beachten, dass der erste Service die Nummer 0 erh<EFBFBD>lt. Number muss also eine Zahl zwischen
|
|
|
|
|
* 0 und GetServiceCount() - 1 sein.
|
2010-07-31 06:23:38 +00:00
|
|
|
|
*/
|
2010-10-19 21:03:33 +00:00
|
|
|
|
Common::String Kernel::Superclass::getServiceIdentifier(uint number) {
|
|
|
|
|
if (number > _serviceCount)
|
|
|
|
|
return NULL;
|
2010-08-06 13:13:25 +00:00
|
|
|
|
|
2010-10-19 21:03:33 +00:00
|
|
|
|
uint curServiceOrd = 0;
|
2010-10-19 09:43:53 +00:00
|
|
|
|
for (uint i = 0; i < ARRAYSIZE(BS_SERVICE_TABLE); i++) {
|
2010-10-19 21:03:33 +00:00
|
|
|
|
if (BS_SERVICE_TABLE[i].superclassId == _identifier) {
|
|
|
|
|
if (number == curServiceOrd)
|
2010-10-19 09:44:13 +00:00
|
|
|
|
return BS_SERVICE_TABLE[i].serviceId;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
else
|
2010-10-19 21:03:33 +00:00
|
|
|
|
curServiceOrd++;
|
2010-08-16 20:23:53 +00:00
|
|
|
|
}
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-10-19 09:44:13 +00:00
|
|
|
|
return Common::String();
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
/**
|
2010-08-06 13:13:25 +00:00
|
|
|
|
* Creates a new service with the given identifier. Returns a pointer to the service, or null if the
|
2010-07-31 06:23:38 +00:00
|
|
|
|
* service could not be created
|
|
|
|
|
* Note: All services must be registered in service_ids.h, otherwise they cannot be created here
|
2010-10-19 09:44:13 +00:00
|
|
|
|
* @param superclassId The name of the superclass of the service
|
|
|
|
|
* e.g.: "sfx", "gfx", "package" ...
|
|
|
|
|
* @param serviceId The name of the service
|
2010-08-06 13:13:25 +00:00
|
|
|
|
* For the superclass "sfx" an example could be "Fmod" or "directsound"
|
2010-07-31 06:23:38 +00:00
|
|
|
|
*/
|
2010-10-19 21:03:33 +00:00
|
|
|
|
Service *Kernel::Superclass::newService(const Common::String &serviceId) {
|
2010-10-19 09:43:53 +00:00
|
|
|
|
for (uint i = 0; i < ARRAYSIZE(BS_SERVICE_TABLE); i++)
|
2010-10-19 21:03:33 +00:00
|
|
|
|
if (BS_SERVICE_TABLE[i].superclassId == _identifier &&
|
2010-10-19 09:44:13 +00:00
|
|
|
|
BS_SERVICE_TABLE[i].serviceId == serviceId) {
|
2010-10-19 21:03:33 +00:00
|
|
|
|
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;
|
2010-08-06 13:13:25 +00:00
|
|
|
|
} else {
|
2010-10-19 21:03:33 +00:00
|
|
|
|
BS_LOG_ERRORLN("Failed to create service '%s' from superclass '%s'.", serviceId.c_str(), _identifier.c_str());
|
2010-07-29 19:53:02 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-19 21:03:33 +00:00
|
|
|
|
BS_LOG_ERRORLN("Service '%s' is not avaliable from superclass '%s'.", serviceId.c_str(), _identifier.c_str());
|
2010-07-29 19:53:02 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
/**
|
2010-08-06 13:13:25 +00:00
|
|
|
|
* Ends the current service of a superclass. Returns true on success, and false if the superclass
|
2010-07-31 06:23:38 +00:00
|
|
|
|
* does not exist or if not service was active
|
2010-10-19 09:44:13 +00:00
|
|
|
|
* @param superclassId The name of the superclass which is to be disconnected
|
|
|
|
|
* e.g.: "sfx", "gfx", "package" ...
|
2010-07-31 06:23:38 +00:00
|
|
|
|
*/
|
2010-10-19 21:03:33 +00:00
|
|
|
|
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());
|
2010-07-29 19:53:02 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-19 21:03:33 +00:00
|
|
|
|
Kernel::Superclass *Kernel::getSuperclassByIdentifier(const Common::String &identifier) const {
|
|
|
|
|
Common::Array<Superclass *>::const_iterator iter;
|
|
|
|
|
for (iter = _superclasses.begin(); iter != _superclasses.end(); ++iter) {
|
|
|
|
|
if ((*iter)->getIdentifier() == identifier)
|
|
|
|
|
return *iter;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-10-19 21:03:33 +00:00
|
|
|
|
// BS_LOG_ERRORLN("Superclass '%s' does not exist.", identifier.c_str());
|
2010-07-29 19:53:02 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns the number of register superclasses
|
|
|
|
|
*/
|
2010-10-19 21:03:33 +00:00
|
|
|
|
uint Kernel::getSuperclassCount() const {
|
2010-10-19 09:44:13 +00:00
|
|
|
|
return _superclasses.size();
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns the name of a superclass with the specified index.
|
|
|
|
|
* Note: The number of superclasses can be retrieved using GetSuperclassCount
|
2010-08-06 13:13:25 +00:00
|
|
|
|
* @param Number The number of the superclass to return the identifier for.
|
2010-07-31 06:23:38 +00:00
|
|
|
|
* It should be noted that the number should be between 0 und GetSuperclassCount() - 1.
|
|
|
|
|
*/
|
2010-10-19 21:03:33 +00:00
|
|
|
|
Common::String Kernel::getSuperclassIdentifier(uint number) const {
|
|
|
|
|
if (number > _superclasses.size())
|
2010-10-19 09:44:13 +00:00
|
|
|
|
return NULL;
|
2010-08-06 13:13:25 +00:00
|
|
|
|
|
2010-10-19 21:03:33 +00:00
|
|
|
|
uint curSuperclassOrd = 0;
|
|
|
|
|
Common::Array<Superclass *>::const_iterator iter;
|
|
|
|
|
for (iter = _superclasses.begin(); iter != _superclasses.end(); ++iter) {
|
|
|
|
|
if (curSuperclassOrd == number)
|
|
|
|
|
return ((*iter)->getIdentifier());
|
2010-08-06 13:13:25 +00:00
|
|
|
|
|
2010-10-19 21:03:33 +00:00
|
|
|
|
curSuperclassOrd++;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
2010-08-06 13:13:25 +00:00
|
|
|
|
|
2010-10-19 09:44:13 +00:00
|
|
|
|
return Common::String();
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns the number of services registered with a given superclass
|
2010-10-19 09:44:13 +00:00
|
|
|
|
* @param superclassId The name of the superclass
|
|
|
|
|
* e.g.: "sfx", "gfx", "package" ...
|
2010-07-31 06:23:38 +00:00
|
|
|
|
*/
|
2010-10-19 21:03:33 +00:00
|
|
|
|
uint Kernel::getServiceCount(const Common::String &superclassId) const {
|
|
|
|
|
Superclass *pSuperclass = getSuperclassByIdentifier(superclassId);
|
2010-10-19 09:44:13 +00:00
|
|
|
|
if (!pSuperclass)
|
2010-07-31 06:23:38 +00:00
|
|
|
|
return 0;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
2010-10-19 21:03:33 +00:00
|
|
|
|
return pSuperclass->getServiceCount();
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* Gets the identifier of a service with a given superclass.
|
|
|
|
|
* The number of services in a superclass can be learned with GetServiceCount().
|
2010-10-19 09:44:13 +00:00
|
|
|
|
* @param superclassId The name of the superclass
|
|
|
|
|
* e.g.: "sfx", "gfx", "package" ...
|
2010-07-31 06:23:38 +00:00
|
|
|
|
* @param Number die Nummer des Services, dessen Bezeichner man erfahren will.<br>
|
2010-08-06 13:13:25 +00:00
|
|
|
|
* Hierbei ist zu beachten, dass der erste Service die Nummer 0 erh<EFBFBD>lt. Number muss also eine Zahl zwischen
|
|
|
|
|
* 0 und GetServiceCount() - 1 sein.
|
2010-07-31 06:23:38 +00:00
|
|
|
|
*/
|
2010-10-19 21:03:33 +00:00
|
|
|
|
Common::String Kernel::getServiceIdentifier(const Common::String &superclassId, uint number) const {
|
|
|
|
|
Superclass *pSuperclass = getSuperclassByIdentifier(superclassId);
|
2010-10-19 09:44:13 +00:00
|
|
|
|
if (!pSuperclass)
|
|
|
|
|
return NULL;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
2010-10-19 21:03:33 +00:00
|
|
|
|
return (pSuperclass->getServiceIdentifier(number));
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
/**
|
2010-08-06 13:13:25 +00:00
|
|
|
|
* Creates a new service with the given identifier. Returns a pointer to the service, or null if the
|
2010-07-31 06:23:38 +00:00
|
|
|
|
* service could not be created
|
|
|
|
|
* Note: All services must be registered in service_ids.h, otherwise they cannot be created here
|
2010-10-19 09:44:13 +00:00
|
|
|
|
* @param superclassId The name of the superclass of the service
|
|
|
|
|
* e.g.: "sfx", "gfx", "package" ...
|
|
|
|
|
* @param serviceId The name of the service
|
2010-08-06 13:13:25 +00:00
|
|
|
|
* For the superclass "sfx" an example could be "Fmod" or "directsound"
|
2010-07-31 06:23:38 +00:00
|
|
|
|
*/
|
2010-10-19 21:03:33 +00:00
|
|
|
|
Service *Kernel::newService(const Common::String &superclassId, const Common::String &serviceId) {
|
|
|
|
|
Superclass *pSuperclass = getSuperclassByIdentifier(superclassId);
|
2010-10-19 09:44:13 +00:00
|
|
|
|
if (!pSuperclass)
|
|
|
|
|
return NULL;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
|
|
// Die Reihenfolge merken, in der Services erstellt werden, damit sie sp<73>ter in umgekehrter Reihenfolge entladen werden k<>nnen.
|
2010-10-19 21:03:33 +00:00
|
|
|
|
_serviceCreationOrder.push(superclassId);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
2010-10-19 21:03:33 +00:00
|
|
|
|
return pSuperclass->newService(serviceId);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
/**
|
2010-10-19 09:44:13 +00:00
|
|
|
|
* 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.
|
2010-07-31 06:23:38 +00:00
|
|
|
|
*/
|
2010-10-19 21:03:33 +00:00
|
|
|
|
bool Kernel::disconnectService(const Common::String &superclassId) {
|
|
|
|
|
Superclass *pSuperclass = getSuperclassByIdentifier(superclassId);
|
2010-10-19 09:44:13 +00:00
|
|
|
|
if (!pSuperclass)
|
|
|
|
|
return false;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
2010-10-19 21:03:33 +00:00
|
|
|
|
return pSuperclass->disconnectService();
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
/**
|
2010-10-19 09:44:13 +00:00
|
|
|
|
* Returns a pointer to the currently active service object of a superclass.
|
|
|
|
|
* @param superclassId The name of the superclass
|
|
|
|
|
* e.g.: "sfx", "gfx", "package" ...
|
2010-07-31 06:23:38 +00:00
|
|
|
|
*/
|
2010-10-19 21:03:33 +00:00
|
|
|
|
Service *Kernel::getService(const Common::String &superclassId) {
|
|
|
|
|
Superclass *pSuperclass = getSuperclassByIdentifier(superclassId);
|
2010-10-19 09:44:13 +00:00
|
|
|
|
if (!pSuperclass)
|
|
|
|
|
return NULL;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
2010-10-19 21:03:33 +00:00
|
|
|
|
return (pSuperclass->getActiveService());
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
/**
|
2010-10-19 09:44:13 +00:00
|
|
|
|
* Returns the name of the currently active service object of a superclass.
|
2010-07-31 06:23:38 +00:00
|
|
|
|
* If an error occurs, then an empty string is returned
|
2010-10-19 09:44:13 +00:00
|
|
|
|
* @param superclassId The name of the superclass
|
|
|
|
|
* e.g.: "sfx", "gfx", "package" ...
|
2010-07-31 06:23:38 +00:00
|
|
|
|
*/
|
2010-10-19 21:03:33 +00:00
|
|
|
|
Common::String Kernel::getActiveServiceIdentifier(const Common::String &superclassId) {
|
|
|
|
|
Superclass *pSuperclass = getSuperclassByIdentifier(superclassId);
|
2010-10-19 09:44:13 +00:00
|
|
|
|
if (!pSuperclass)
|
|
|
|
|
return Common::String();
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
2010-10-19 21:03:33 +00:00
|
|
|
|
return pSuperclass->getActiveServiceName();
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns a random number
|
2010-08-06 13:13:25 +00:00
|
|
|
|
* @param Min The minimum allowed value
|
|
|
|
|
* @param Max The maximum allowed value
|
2010-07-31 06:23:38 +00:00
|
|
|
|
*/
|
2010-10-19 21:03:33 +00:00
|
|
|
|
int Kernel::getRandomNumber(int min, int max) {
|
|
|
|
|
BS_ASSERT(min <= max);
|
2010-07-31 06:23:38 +00:00
|
|
|
|
|
2010-10-19 21:03:33 +00:00
|
|
|
|
return min + _rnd.getRandomNumber(max - min + 1);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns the elapsed time since startup in milliseconds
|
|
|
|
|
*/
|
2010-10-19 21:03:33 +00:00
|
|
|
|
uint Kernel::getMilliTicks() {
|
2010-07-31 06:23:38 +00:00
|
|
|
|
return g_system->getMillis();
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns how much memory is being used
|
|
|
|
|
*/
|
2010-10-19 21:03:33 +00:00
|
|
|
|
size_t Kernel::getUsedMemory() {
|
2010-07-31 06:23:38 +00:00
|
|
|
|
return 0;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
/**
|
2010-10-19 09:44:13 +00:00
|
|
|
|
* Returns a pointer to the active Gfx Service, or NULL if no Gfx service is active.
|
2010-07-31 06:23:38 +00:00
|
|
|
|
*/
|
2010-10-19 21:03:33 +00:00
|
|
|
|
GraphicEngine *Kernel::getGfx() {
|
|
|
|
|
return static_cast<GraphicEngine *>(getService("gfx"));
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
/**
|
2010-10-19 09:44:13 +00:00
|
|
|
|
* Returns a pointer to the active Sfx Service, or NULL if no Sfx service is active.
|
2010-07-31 06:23:38 +00:00
|
|
|
|
*/
|
2010-10-19 21:03:33 +00:00
|
|
|
|
SoundEngine *Kernel::getSfx() {
|
|
|
|
|
return static_cast<SoundEngine *>(getService("sfx"));
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
/**
|
2010-10-19 09:44:13 +00:00
|
|
|
|
* Returns a pointer to the active input service, or NULL if no input service is active.
|
2010-07-31 06:23:38 +00:00
|
|
|
|
*/
|
2010-10-19 21:03:33 +00:00
|
|
|
|
InputEngine *Kernel::getInput() {
|
|
|
|
|
return static_cast<InputEngine *>(getService("input"));
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
/**
|
2010-10-19 09:44:13 +00:00
|
|
|
|
* Returns a pointer to the active package manager, or NULL if no manager is active.
|
2010-07-31 06:23:38 +00:00
|
|
|
|
*/
|
2010-10-19 21:03:33 +00:00
|
|
|
|
PackageManager *Kernel::getPackage() {
|
|
|
|
|
return static_cast<PackageManager *>(getService("package"));
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
/**
|
2010-10-19 09:44:13 +00:00
|
|
|
|
* Returns a pointer to the script engine, or NULL if it is not active.
|
2010-07-31 06:23:38 +00:00
|
|
|
|
*/
|
2010-10-19 21:03:33 +00:00
|
|
|
|
ScriptEngine *Kernel::getScript() {
|
|
|
|
|
return static_cast<ScriptEngine *>(getService("script"));
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
/**
|
2010-10-19 09:44:13 +00:00
|
|
|
|
* Returns a pointer to the movie player, or NULL if it is not active.
|
2010-07-31 06:23:38 +00:00
|
|
|
|
*/
|
2010-10-19 21:03:33 +00:00
|
|
|
|
MoviePlayer *Kernel::getFMV() {
|
|
|
|
|
return static_cast<MoviePlayer *>(getService("fmv"));
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-10-19 21:03:33 +00:00
|
|
|
|
void Kernel::sleep(uint msecs) const {
|
|
|
|
|
g_system->delayMillis(msecs);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
2010-07-31 06:23:38 +00:00
|
|
|
|
|
|
|
|
|
} // End of namespace Sword25
|