| 1 |
/*************************************************************************** |
| 2 |
* Copyright (C) 2005-2019 by the FIFE team * |
| 3 |
* http://www.fifengine.net * |
| 4 |
* This file is part of FIFE. * |
| 5 |
* * |
| 6 |
* FIFE is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Lesser General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2.1 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * |
| 14 |
* Lesser General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Lesser General Public * |
| 17 |
* License along with this library; if not, write to the * |
| 18 |
* Free Software Foundation, Inc., * |
| 19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * |
| 20 |
***************************************************************************/ |
| 21 |
|
| 22 |
#ifndef FIFE_ENGINE_H |
| 23 |
#define FIFE_ENGINE_H |
| 24 |
|
| 25 |
// Standard C++ library includes |
| 26 |
#include <map> |
| 27 |
#include <string> |
| 28 |
#include <vector> |
| 29 |
|
| 30 |
// Platform specific includes |
| 31 |
#ifdef USE_COCOA |
| 32 |
#include <objc/runtime.h> |
| 33 |
#endif |
| 34 |
|
| 35 |
// 3rd party library includes |
| 36 |
#include <SDL.h> |
| 37 |
|
| 38 |
// FIFE includes |
| 39 |
// These includes are split up in two parts, separated by one empty line |
| 40 |
// First block: files included from the FIFE root src directory |
| 41 |
// Second block: files included from the same folder |
| 42 |
#include "enginesettings.h" |
| 43 |
#include "video/devicecaps.h" |
| 44 |
|
| 45 |
namespace FIFE { |
| 46 |
|
| 47 |
class SoundManager; |
| 48 |
class RenderBackend; |
| 49 |
class IGUIManager; |
| 50 |
class VFS; |
| 51 |
class VFSSourceFactory; |
| 52 |
class EventManager; |
| 53 |
class TimeManager; |
| 54 |
class Model; |
| 55 |
class LogManager; |
| 56 |
class Cursor; |
| 57 |
class RendererBase; |
| 58 |
class Image; |
| 59 |
class ImageManager; |
| 60 |
class AnimationManager; |
| 61 |
class SoundClipManager; |
| 62 |
class OffRenderer; |
| 63 |
class TargetRenderer; |
| 64 |
|
| 65 |
class IEngineChangeListener { |
| 66 |
public: |
| 67 |
virtual ~IEngineChangeListener() {} |
| 68 |
|
| 69 |
/** Screen mode has been changed |
| 70 |
*/ |
| 71 |
virtual void onScreenModeChanged(const ScreenMode& newmode) = 0; |
| 72 |
}; |
| 73 |
|
| 74 |
/** Engine acts as a controller to the whole system |
| 75 |
* Responsibilities of the engine are: |
| 76 |
* - Construct and initialize engine internals |
| 77 |
* - Clean-up when the program ends |
| 78 |
* - Act as an entry point to the engine subsystems |
| 79 |
*/ |
| 80 |
class Engine { |
| 81 |
public: |
| 82 |
/** Constructor |
| 83 |
*/ |
| 84 |
Engine(); |
| 85 |
|
| 86 |
/** Destructor |
| 87 |
*/ |
| 88 |
virtual ~Engine(); |
| 89 |
|
| 90 |
/** Gets settings class for engine |
| 91 |
*/ |
| 92 |
EngineSettings& getSettings(); |
| 93 |
|
| 94 |
/** Gets device capabilities |
| 95 |
*/ |
| 96 |
const DeviceCaps& getDeviceCaps() const; |
| 97 |
|
| 98 |
/** Changes the screen mode. |
| 99 |
* This should be called instead of the renderer's setScreenMode() function. |
| 100 |
* It takes care of any objects that need to be re-created after switching |
| 101 |
* screen modes. |
| 102 |
* |
| 103 |
* @param mode A valid ScreenMode retrieved from FIFE::DeviceCaps::getNearestScreenMode() |
| 104 |
*/ |
| 105 |
void changeScreenMode(const ScreenMode& mode); |
| 106 |
|
| 107 |
/** Initializes the engine |
| 108 |
*/ |
| 109 |
void init(); |
| 110 |
|
| 111 |
/** Explicit destruction of engine |
| 112 |
*/ |
| 113 |
void destroy(); |
| 114 |
|
| 115 |
/** Initializes the continuous processing of the engine |
| 116 |
* Call this only once in your program |
| 117 |
*/ |
| 118 |
void initializePumping(); |
| 119 |
|
| 120 |
/** Finalizes the continuous processing of the engine |
| 121 |
* Call this only once in your program, after you have called |
| 122 |
* initializePumping + (pump() * N times) |
| 123 |
*/ |
| 124 |
void finalizePumping(); |
| 125 |
|
| 126 |
/** Runs one cycle for the engine |
| 127 |
*/ |
| 128 |
void pump(); |
| 129 |
|
| 130 |
/** Provides access point to the SoundManager |
| 131 |
*/ |
| 132 |
SoundManager* getSoundManager() const { return m_soundmanager; } |
| 133 |
|
| 134 |
/** Provides access point to the EventManager |
| 135 |
*/ |
| 136 |
EventManager* getEventManager() const { return m_eventmanager; } |
| 137 |
|
| 138 |
/** Provides access point to the TimeManager |
| 139 |
*/ |
| 140 |
TimeManager* getTimeManager() const { return m_timemanager; } |
| 141 |
|
| 142 |
|
| 143 |
/** Sets the GUI Manager to use. Engine takes |
| 144 |
* ownership of the manager so DONT DELETE IT! |
| 145 |
*/ |
| 146 |
void setGuiManager(IGUIManager* guimanager) { m_guimanager = guimanager; } |
| 147 |
|
| 148 |
/** Provides access point to the GUI Manager |
| 149 |
*/ |
| 150 |
IGUIManager* getGuiManager() const { return m_guimanager; } |
| 151 |
|
| 152 |
/** Provides access point to the ImageManager |
| 153 |
*/ |
| 154 |
ImageManager* getImageManager() const { return m_imagemanager; } |
| 155 |
|
| 156 |
/** Provides access point to the ImageManager |
| 157 |
*/ |
| 158 |
AnimationManager* getAnimationManager() const { return m_animationmanager; } |
| 159 |
|
| 160 |
/** Provides access point to the SoundClipManager |
| 161 |
*/ |
| 162 |
SoundClipManager* getSoundClipManager() const { return m_soundclipmanager; } |
| 163 |
|
| 164 |
/** Provides access point to the RenderBackend |
| 165 |
*/ |
| 166 |
RenderBackend* getRenderBackend() const { return m_renderbackend; } |
| 167 |
|
| 168 |
/** Provides access point to the Model |
| 169 |
*/ |
| 170 |
Model* getModel() const { return m_model; } |
| 171 |
|
| 172 |
/** Provides access point to the LogManager |
| 173 |
*/ |
| 174 |
LogManager* getLogManager() const { return m_logmanager; } |
| 175 |
|
| 176 |
/** Provides access point to the VFS |
| 177 |
*/ |
| 178 |
VFS* getVFS() const { return m_vfs; } |
| 179 |
|
| 180 |
/** Returns cursor used in the engine |
| 181 |
*/ |
| 182 |
Cursor* getCursor() const { return m_cursor; } |
| 183 |
|
| 184 |
/** Provides access point to the OffRenderer |
| 185 |
*/ |
| 186 |
OffRenderer* getOffRenderer() const { return m_offrenderer; } |
| 187 |
|
| 188 |
/** Provides access point to the TargetRenderer |
| 189 |
*/ |
| 190 |
TargetRenderer* getTargetRenderer() const { return m_targetrenderer; } |
| 191 |
|
| 192 |
/** Adds new change listener |
| 193 |
* @param listener to add |
| 194 |
*/ |
| 195 |
void addChangeListener(IEngineChangeListener* listener); |
| 196 |
|
| 197 |
/** Removes associated change listener |
| 198 |
* @param listener to remove |
| 199 |
*/ |
| 200 |
void removeChangeListener(IEngineChangeListener* listener); |
| 201 |
|
| 202 |
private: |
| 203 |
RenderBackend* m_renderbackend; |
| 204 |
IGUIManager* m_guimanager; |
| 205 |
EventManager* m_eventmanager; |
| 206 |
SoundManager* m_soundmanager; |
| 207 |
TimeManager* m_timemanager; |
| 208 |
ImageManager* m_imagemanager; |
| 209 |
AnimationManager* m_animationmanager; |
| 210 |
SoundClipManager* m_soundclipmanager; |
| 211 |
|
| 212 |
VFS* m_vfs; |
| 213 |
Model* m_model; |
| 214 |
LogManager* m_logmanager; |
| 215 |
|
| 216 |
Cursor* m_cursor; |
| 217 |
bool m_destroyed; |
| 218 |
|
| 219 |
EngineSettings m_settings; |
| 220 |
DeviceCaps m_devcaps; |
| 221 |
|
| 222 |
ScreenMode m_screenMode; |
| 223 |
|
| 224 |
OffRenderer* m_offrenderer; |
| 225 |
TargetRenderer* m_targetrenderer; |
| 226 |
std::vector<RendererBase*> m_renderers; |
| 227 |
|
| 228 |
std::vector<IEngineChangeListener*> m_changelisteners; |
| 229 |
|
| 230 |
#ifdef USE_COCOA |
| 231 |
id m_autoreleasePool; |
| 232 |
#endif |
| 233 |
|
| 234 |
}; |
| 235 |
|
| 236 |
}//FIFE |
| 237 |
|
| 238 |
#endif |