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-10-13 15:00:51 +00:00
|
|
|
|
#ifdef USE_THEORADEC
|
2010-07-31 06:23:38 +00:00
|
|
|
|
#include "sword25/fmv/movieplayer.h"
|
2010-10-13 15:00:51 +00:00
|
|
|
|
#endif
|
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 09:43:53 +00:00
|
|
|
|
|
2010-08-18 12:58:22 +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-07-29 19:53:02 +00:00
|
|
|
|
_pWindow(NULL),
|
|
|
|
|
_Running(false),
|
|
|
|
|
_pResourceManager(NULL),
|
2010-07-31 06:23:38 +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;
|
|
|
|
|
Common::Array<Superclass *>::iterator Iter;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
for (Iter = _SuperclassList.begin(); Iter != _SuperclassList.end(); ++Iter)
|
2010-07-31 06:23:38 +00:00
|
|
|
|
if ((*Iter)->GetIdentifier() == BS_SERVICE_TABLE[i].SuperclassIdentifier) {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
pCurSuperclass = *Iter;
|
|
|
|
|
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)
|
|
|
|
|
_SuperclassList.push_back(new Superclass(this, BS_SERVICE_TABLE[i].SuperclassIdentifier));
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
// Create window object
|
2010-08-18 12:58:22 +00:00
|
|
|
|
_pWindow = Window::CreateBSWindow(0, 0, 0, 0, false);
|
2010-07-31 06:23:38 +00:00
|
|
|
|
if (!_pWindow) {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
BS_LOG_ERRORLN("Failed to create the window.");
|
2010-07-31 06:23:38 +00:00
|
|
|
|
} else
|
2010-07-29 19:53:02 +00:00
|
|
|
|
BS_LOGLN("Window created.");
|
|
|
|
|
|
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-08-18 12:57:47 +00:00
|
|
|
|
ScriptEngine *pScript = static_cast<ScriptEngine *>(NewService("script", "lua"));
|
2010-10-03 13:25:22 +00:00
|
|
|
|
if (!pScript || !pScript->init()) {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
_InitSuccess = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
// Register kernel script bindings
|
|
|
|
|
if (!_RegisterScriptBindings()) {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
BS_LOG_ERRORLN("Script bindings could not be registered.");
|
|
|
|
|
_InitSuccess = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
BS_LOGLN("Script bindings registered.");
|
|
|
|
|
|
|
|
|
|
_InitSuccess = true;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
while (!_ServiceCreationOrder.empty()) {
|
|
|
|
|
Superclass *superclass = GetSuperclassByIdentifier(_ServiceCreationOrder.top());
|
2010-07-29 19:53:02 +00:00
|
|
|
|
if (superclass) superclass->DisconnectService();
|
|
|
|
|
_ServiceCreationOrder.pop();
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
// Empty the Superclass list
|
|
|
|
|
while (_SuperclassList.size()) {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
delete _SuperclassList.back();
|
|
|
|
|
_SuperclassList.pop_back();
|
|
|
|
|
}
|
2010-08-06 13:13:25 +00:00
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
// Release the window object
|
2010-07-29 19:53:02 +00:00
|
|
|
|
delete _pWindow;
|
|
|
|
|
BS_LOGLN("Window destroyed.");
|
|
|
|
|
|
|
|
|
|
// Resource-Manager freigeben
|
|
|
|
|
delete _pResourceManager;
|
|
|
|
|
|
|
|
|
|
BS_LOGLN("destroyed.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Service Methoden
|
|
|
|
|
// ----------------
|
2010-07-31 06:23:38 +00:00
|
|
|
|
|
2010-08-18 12:58:22 +00:00
|
|
|
|
Kernel::Superclass::Superclass(Kernel *pKernel, const Common::String &Identifier) :
|
2010-07-29 19:53:02 +00:00
|
|
|
|
_pKernel(pKernel),
|
2010-08-06 13:13:25 +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-07-29 19:53:02 +00:00
|
|
|
|
if (BS_SERVICE_TABLE[i].SuperclassIdentifier == _Identifier)
|
|
|
|
|
_ServiceCount++;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-18 12:58:22 +00:00
|
|
|
|
Kernel::Superclass::~Superclass() {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
DisconnectService();
|
|
|
|
|
}
|
|
|
|
|
|
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-08-06 13:13:25 +00:00
|
|
|
|
* @param SuperclassIdentifier The name of the superclass
|
|
|
|
|
* z.B: "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-09-02 12:14:04 +00:00
|
|
|
|
Common::String Kernel::Superclass::GetServiceIdentifier(uint Number) {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
if (Number > _ServiceCount) return NULL;
|
2010-08-06 13:13:25 +00:00
|
|
|
|
|
2010-09-02 12:14:04 +00:00
|
|
|
|
uint CurServiceOrd = 0;
|
2010-10-19 09:43:53 +00:00
|
|
|
|
for (uint i = 0; i < ARRAYSIZE(BS_SERVICE_TABLE); i++) {
|
2010-08-16 20:23:53 +00:00
|
|
|
|
if (BS_SERVICE_TABLE[i].SuperclassIdentifier == _Identifier) {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
if (Number == CurServiceOrd)
|
|
|
|
|
return BS_SERVICE_TABLE[i].ServiceIdentifier;
|
|
|
|
|
else
|
|
|
|
|
CurServiceOrd++;
|
2010-08-16 20:23:53 +00:00
|
|
|
|
}
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-31 06:23:38 +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-08-06 13:13:25 +00:00
|
|
|
|
* @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"
|
2010-07-31 06:23:38 +00:00
|
|
|
|
*/
|
2010-08-18 12:58:22 +00:00
|
|
|
|
Service *Kernel::Superclass::NewService(const Common::String &ServiceIdentifier) {
|
2010-10-19 09:43:53 +00:00
|
|
|
|
for (uint i = 0; i < ARRAYSIZE(BS_SERVICE_TABLE); i++)
|
2010-07-29 19:53:02 +00:00
|
|
|
|
if (BS_SERVICE_TABLE[i].SuperclassIdentifier == _Identifier &&
|
2010-08-06 13:13:25 +00:00
|
|
|
|
BS_SERVICE_TABLE[i].ServiceIdentifier == ServiceIdentifier) {
|
2010-08-18 12:58:22 +00:00
|
|
|
|
Service *NewService_ = BS_SERVICE_TABLE[i].CreateMethod(_pKernel);
|
2010-08-06 13:13:25 +00:00
|
|
|
|
|
2010-08-14 19:56:15 +00:00
|
|
|
|
if (NewService_) {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
DisconnectService();
|
|
|
|
|
BS_LOGLN("Service '%s' created from superclass '%s'.", ServiceIdentifier.c_str(), _Identifier.c_str());
|
2010-08-14 19:56:15 +00:00
|
|
|
|
_ActiveService = NewService_;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
_ActiveServiceName = BS_SERVICE_TABLE[i].ServiceIdentifier;
|
|
|
|
|
return _ActiveService;
|
2010-08-06 13:13:25 +00:00
|
|
|
|
} else {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
BS_LOG_ERRORLN("Failed to create service '%s' from superclass '%s'.", ServiceIdentifier.c_str(), _Identifier.c_str());
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BS_LOG_ERRORLN("Service '%s' is not avaliable from superclass '%s'.", ServiceIdentifier.c_str(), _Identifier.c_str());
|
|
|
|
|
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-08-06 13:13:25 +00:00
|
|
|
|
* @param SuperclassIdentfier The name of the superclass which is to be disconnected
|
|
|
|
|
* z.B: "sfx", "gfx", "package" ...
|
2010-07-31 06:23:38 +00:00
|
|
|
|
*/
|
2010-08-18 12:58:22 +00:00
|
|
|
|
bool Kernel::Superclass::DisconnectService() {
|
2010-07-31 06:23:38 +00:00
|
|
|
|
if (_ActiveService) {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
delete _ActiveService;
|
|
|
|
|
_ActiveService = 0;
|
|
|
|
|
BS_LOGLN("Active service '%s' disconnected from superclass '%s'.", _ActiveServiceName.c_str(), _Identifier.c_str());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-18 12:58:22 +00:00
|
|
|
|
Kernel::Superclass *Kernel::GetSuperclassByIdentifier(const Common::String &Identifier) {
|
2010-08-06 13:13:25 +00:00
|
|
|
|
Common::Array<Superclass *>::iterator Iter;
|
2010-07-31 06:23:38 +00:00
|
|
|
|
for (Iter = _SuperclassList.begin(); Iter != _SuperclassList.end(); ++Iter) {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
if ((*Iter)->GetIdentifier() == Identifier)
|
|
|
|
|
return *Iter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// BS_LOG_ERRORLN("Superclass '%s' does not exist.", Identifier.c_str());
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns the number of register superclasses
|
|
|
|
|
*/
|
2010-09-02 12:14:04 +00:00
|
|
|
|
uint Kernel::GetSuperclassCount() {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
return _SuperclassList.size();
|
|
|
|
|
}
|
|
|
|
|
|
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-09-02 12:14:04 +00:00
|
|
|
|
Common::String Kernel::GetSuperclassIdentifier(uint Number) {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
if (Number > _SuperclassList.size()) return NULL;
|
2010-08-06 13:13:25 +00:00
|
|
|
|
|
2010-09-02 12:14:04 +00:00
|
|
|
|
uint CurSuperclassOrd = 0;
|
2010-08-06 13:13:25 +00:00
|
|
|
|
Common::Array<Superclass *>::iterator Iter;
|
2010-07-31 06:23:38 +00:00
|
|
|
|
for (Iter = _SuperclassList.begin(); Iter != _SuperclassList.end(); ++Iter) {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
if (CurSuperclassOrd == Number)
|
|
|
|
|
return ((*Iter)->GetIdentifier());
|
2010-08-06 13:13:25 +00:00
|
|
|
|
|
2010-07-29 19:53:02 +00:00
|
|
|
|
CurSuperclassOrd++;
|
|
|
|
|
}
|
2010-08-06 13:13:25 +00:00
|
|
|
|
|
2010-07-31 06:23:38 +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-08-06 13:13:25 +00:00
|
|
|
|
* @param SuperclassIdentifier The name of the superclass
|
|
|
|
|
* z.B: "sfx", "gfx", "package" ...
|
2010-07-31 06:23:38 +00:00
|
|
|
|
*/
|
2010-09-02 12:14:04 +00:00
|
|
|
|
uint Kernel::GetServiceCount(const Common::String &SuperclassIdentifier) {
|
2010-07-31 06:23:38 +00:00
|
|
|
|
Superclass *pSuperclass;
|
2010-08-06 13:13:25 +00:00
|
|
|
|
if (!(pSuperclass = GetSuperclassByIdentifier(SuperclassIdentifier)))
|
2010-07-31 06:23:38 +00:00
|
|
|
|
return 0;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
|
|
return pSuperclass->GetServiceCount();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
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-08-06 13:13:25 +00:00
|
|
|
|
* @param SuperclassIdentifier The name of the superclass
|
|
|
|
|
* z.B: "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-09-02 12:14:04 +00:00
|
|
|
|
Common::String Kernel::GetServiceIdentifier(const Common::String &SuperclassIdentifier, uint Number) {
|
2010-08-06 13:13:25 +00:00
|
|
|
|
Superclass *pSuperclass;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
if (!(pSuperclass = GetSuperclassByIdentifier(SuperclassIdentifier))) return NULL;
|
|
|
|
|
|
2010-08-06 13:13:25 +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-08-06 13:13:25 +00:00
|
|
|
|
* @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"
|
2010-07-31 06:23:38 +00:00
|
|
|
|
*/
|
2010-08-18 12:58:22 +00:00
|
|
|
|
Service *Kernel::NewService(const Common::String &SuperclassIdentifier, const Common::String &ServiceIdentifier) {
|
2010-07-31 06:23:38 +00:00
|
|
|
|
Superclass *pSuperclass;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
if (!(pSuperclass = GetSuperclassByIdentifier(SuperclassIdentifier))) return NULL;
|
|
|
|
|
|
|
|
|
|
// Die Reihenfolge merken, in der Services erstellt werden, damit sie sp<73>ter in umgekehrter Reihenfolge entladen werden k<>nnen.
|
|
|
|
|
_ServiceCreationOrder.push(SuperclassIdentifier);
|
|
|
|
|
|
|
|
|
|
return pSuperclass->NewService(ServiceIdentifier);
|
|
|
|
|
}
|
|
|
|
|
|
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-08-06 13:13:25 +00:00
|
|
|
|
* @param SuperclassIdentfier The name of the superclass which is to be disconnected
|
|
|
|
|
* z.B: "sfx", "gfx", "package" ...
|
2010-07-31 06:23:38 +00:00
|
|
|
|
*/
|
2010-08-18 12:58:22 +00:00
|
|
|
|
bool Kernel::DisconnectService(const Common::String &SuperclassIdentifier) {
|
2010-07-31 06:23:38 +00:00
|
|
|
|
Superclass *pSuperclass;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
if (!(pSuperclass = GetSuperclassByIdentifier(SuperclassIdentifier))) return false;
|
|
|
|
|
|
|
|
|
|
return pSuperclass->DisconnectService();
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns a pointer to the currently active service object of a superclass
|
2010-08-06 13:13:25 +00:00
|
|
|
|
* @param SuperclassIdentfier The name of the superclass
|
|
|
|
|
* z.B: "sfx", "gfx", "package" ...
|
2010-07-31 06:23:38 +00:00
|
|
|
|
*/
|
2010-08-18 12:58:22 +00:00
|
|
|
|
Service *Kernel::GetService(const Common::String &SuperclassIdentifier) {
|
2010-07-31 06:23:38 +00:00
|
|
|
|
Superclass *pSuperclass;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
if (!(pSuperclass = GetSuperclassByIdentifier(SuperclassIdentifier))) return NULL;
|
|
|
|
|
|
|
|
|
|
return (pSuperclass->GetActiveService());
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns the name of the currentl active service object of a superclass.
|
|
|
|
|
* If an error occurs, then an empty string is returned
|
2010-08-06 13:13:25 +00:00
|
|
|
|
* @param SuperclassIdentfier The name of the superclass
|
|
|
|
|
* z.B: "sfx", "gfx", "package" ...
|
2010-07-31 06:23:38 +00:00
|
|
|
|
*/
|
2010-08-18 12:58:22 +00:00
|
|
|
|
Common::String Kernel::GetActiveServiceIdentifier(const Common::String &SuperclassIdentifier) {
|
2010-08-06 13:13:25 +00:00
|
|
|
|
Superclass *pSuperclass = GetSuperclassByIdentifier(SuperclassIdentifier);
|
2010-07-31 06:23:38 +00:00
|
|
|
|
if (!pSuperclass) return Common::String("");
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
|
|
return (pSuperclass->GetActiveServiceName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
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-08-18 12:58:22 +00:00
|
|
|
|
int Kernel::GetRandomNumber(int Min, int Max) {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
BS_ASSERT(Min <= Max);
|
2010-07-31 06:23:38 +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-09-02 12:14:04 +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
|
|
|
|
// Other methods
|
2010-07-29 19:53:02 +00:00
|
|
|
|
// -----------------
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns how much memory is being used
|
|
|
|
|
*/
|
2010-08-18 12:58:22 +00:00
|
|
|
|
size_t Kernel::GetUsedMemory() {
|
2010-07-31 06:23:38 +00:00
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
#ifdef SCUMMVM_DISABLED_CODE
|
2010-07-29 19:53:02 +00:00
|
|
|
|
PROCESS_MEMORY_COUNTERS pmc;
|
|
|
|
|
pmc.cb = sizeof(pmc);
|
2010-08-06 13:13:25 +00:00
|
|
|
|
if (GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc))) {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
return pmc.WorkingSetSize;
|
2010-08-06 13:13:25 +00:00
|
|
|
|
} else {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
BS_LOG_ERRORLN("Call to GetProcessMemoryInfo() failed. Error code: %d", GetLastError());
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2010-07-31 06:23:38 +00:00
|
|
|
|
#endif
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns a pointer to the active Gfx Service, or NULL if no Gfx service is active
|
|
|
|
|
*/
|
2010-08-18 12:58:22 +00:00
|
|
|
|
GraphicEngine *Kernel::GetGfx() {
|
2010-08-18 10:52:24 +00:00
|
|
|
|
return static_cast<GraphicEngine *>(GetService("gfx"));
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns a pointer to the active Sfx Service, or NULL if no Sfx service is active
|
|
|
|
|
*/
|
2010-08-18 12:58:22 +00:00
|
|
|
|
SoundEngine *Kernel::GetSfx() {
|
2010-08-18 12:57:47 +00:00
|
|
|
|
return static_cast<SoundEngine *>(GetService("sfx"));
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns a pointer to the active input service, or NULL if no input service is active
|
|
|
|
|
*/
|
2010-08-18 12:58:22 +00:00
|
|
|
|
InputEngine *Kernel::GetInput() {
|
2010-08-18 12:57:47 +00:00
|
|
|
|
return static_cast<InputEngine *>(GetService("input"));
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns a pointer to the active package manager, or NULL if no manager is active
|
|
|
|
|
*/
|
2010-08-18 12:58:22 +00:00
|
|
|
|
PackageManager *Kernel::GetPackage() {
|
2010-08-18 12:57:47 +00:00
|
|
|
|
return static_cast<PackageManager *>(GetService("package"));
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2010-07-31 06:23:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns a pointer to the script engine, or NULL if it is not active
|
|
|
|
|
*/
|
2010-08-18 12:58:22 +00:00
|
|
|
|
ScriptEngine *Kernel::GetScript() {
|
2010-08-18 12:57:47 +00:00
|
|
|
|
return static_cast<ScriptEngine *>(GetService("script"));
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2010-10-13 13:32:30 +00:00
|
|
|
|
#ifdef USE_THEORADEC
|
2010-07-31 06:23:38 +00:00
|
|
|
|
/**
|
|
|
|
|
* Returns a pointer to the movie player, or NULL if it is not active
|
|
|
|
|
*/
|
2010-08-18 12:58:22 +00:00
|
|
|
|
MoviePlayer *Kernel::GetFMV() {
|
2010-08-18 10:52:24 +00:00
|
|
|
|
return static_cast<MoviePlayer *>(GetService("fmv"));
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
2010-10-13 13:07:16 +00:00
|
|
|
|
#endif
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2010-09-02 12:14:04 +00:00
|
|
|
|
void Kernel::Sleep(uint Msecs) const {
|
2010-07-31 06:23:38 +00:00
|
|
|
|
g_system->delayMillis(Msecs);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
2010-07-31 06:23:38 +00:00
|
|
|
|
|
|
|
|
|
} // End of namespace Sword25
|