1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 /* 24 * This code is based on Broken Sword 2.5 engine 25 * 26 * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer 27 * 28 * Licensed under GNU GPL v2 29 * 30 */ 31 32 /* 33 * BS_Kernel 34 * --------- 35 * This is the main class of the engine. 36 * This class creates and manages all other Engine elements: the sound engine, graphics engine ... 37 * It is not necessary to release all the items individually, this is performed by the Kernel class. 38 * 39 * Autor: Malte Thiesen 40 */ 41 42 #ifndef SWORD25_KERNEL_H 43 #define SWORD25_KERNEL_H 44 45 #include "common/scummsys.h" 46 #include "common/random.h" 47 #include "common/stack.h" 48 #include "common/textconsole.h" 49 #include "common/util.h" 50 #include "engines/engine.h" 51 52 #include "sword25/kernel/common.h" 53 #include "sword25/kernel/resmanager.h" 54 55 namespace Sword25 { 56 57 // Class definitions 58 class Service; 59 class Geometry; 60 class GraphicEngine; 61 class ScriptEngine; 62 class SoundEngine; 63 class InputEngine; 64 class PackageManager; 65 class MoviePlayer; 66 67 /** 68 * This is the main engine class 69 * 70 * This class creates and manages all other engine components such as sound engine, graphics engine ... 71 * It is not necessary to release all the items individually, this is performed by the Kernel class. 72 */ 73 class Kernel { 74 public: 75 76 /** 77 * Returns the elapsed time since startup in milliseconds 78 */ 79 uint getMilliTicks(); 80 81 /** 82 * Specifies whether the kernel was successfully initialized 83 */ getInitSuccess()84 bool getInitSuccess() const { 85 return _initSuccess; 86 } 87 /** 88 * Returns a pointer to the BS_ResourceManager 89 */ getResourceManager()90 ResourceManager *getResourceManager() { 91 return _resourceManager; 92 } 93 /** 94 * Returns a random number 95 * @param Min The minimum allowed value 96 * @param Max The maximum allowed value 97 */ 98 int getRandomNumber(int min, int max); 99 /** 100 * Returns a pointer to the active Gfx Service, or NULL if no Gfx service is active 101 */ 102 GraphicEngine *getGfx(); 103 /** 104 * Returns a pointer to the active Sfx Service, or NULL if no Sfx service is active 105 */ 106 SoundEngine *getSfx(); 107 /** 108 * Returns a pointer to the active input service, or NULL if no input service is active 109 */ 110 InputEngine *getInput(); 111 /** 112 * Returns a pointer to the active package manager, or NULL if no manager is active 113 */ 114 PackageManager *getPackage(); 115 /** 116 * Returns a pointer to the script engine, or NULL if it is not active 117 */ 118 ScriptEngine *getScript(); 119 120 /** 121 * Returns a pointer to the movie player, or NULL if it is not active 122 */ 123 MoviePlayer *getFMV(); 124 125 /** 126 * Pauses for the specified amount of time 127 * @param Msecs The amount of time in milliseconds 128 */ 129 void sleep(uint msecs) const; 130 131 /** 132 * Returns the singleton instance for the kernel 133 */ getInstance()134 static Kernel *getInstance() { 135 if (!_instance) 136 _instance = new Kernel(); 137 return _instance; 138 } 139 140 /** 141 * Destroys the kernel instance 142 * This method should only be called when the game is ended. No subsequent calls to any kernel 143 * methods should be done after calling this method. 144 */ deleteInstance()145 static void deleteInstance() { 146 if (_instance) { 147 delete _instance; 148 _instance = NULL; 149 } 150 } 151 152 /** 153 * Raises an error. This method is used in crashing testing. 154 */ crash()155 void crash() const { 156 error("Kernel::Crash"); 157 } 158 159 private: 160 // ----------------------------------------------------------------------------- 161 // Constructor / destructor 162 // Private singleton methods 163 // ----------------------------------------------------------------------------- 164 165 Kernel(); 166 virtual ~Kernel(); 167 168 // ----------------------------------------------------------------------------- 169 // Singleton instance 170 // ----------------------------------------------------------------------------- 171 static Kernel *_instance; 172 173 bool _initSuccess; // Specifies whether the engine was set up correctly 174 175 // Random number generator 176 // ----------------------- 177 Common::RandomSource _rnd; 178 179 // Resourcemanager 180 // --------------- 181 ResourceManager *_resourceManager; 182 183 GraphicEngine *_gfx; 184 SoundEngine *_sfx; 185 InputEngine *_input; 186 PackageManager *_package; 187 ScriptEngine *_script; 188 Geometry *_geometry; 189 MoviePlayer *_fmv; 190 191 bool registerScriptBindings(); 192 }; 193 194 } // End of namespace Sword25 195 196 #endif 197