| 1 | /* |
|---|
| 2 | ----------------------------------------------------------------------------- |
|---|
| 3 | This source file is part of OGRE |
|---|
| 4 | (Object-oriented Graphics Rendering Engine) |
|---|
| 5 | For the latest info, see http://www.ogre3d.org/ |
|---|
| 6 | |
|---|
| 7 | Copyright (c) 2000-2006 Torus Knot Software Ltd |
|---|
| 8 | Also see acknowledgements in Readme.html |
|---|
| 9 | |
|---|
| 10 | This program is free software; you can redistribute it and/or modify it under |
|---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software |
|---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later |
|---|
| 13 | version. |
|---|
| 14 | |
|---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT |
|---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
|---|
| 18 | |
|---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with |
|---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
|---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
|---|
| 22 | http://www.gnu.org/copyleft/lesser.txt. |
|---|
| 23 | |
|---|
| 24 | You may alternatively use this source under the terms of a specific version of |
|---|
| 25 | the OGRE Unrestricted License provided you have obtained such a license from |
|---|
| 26 | Torus Knot Software Ltd. |
|---|
| 27 | ----------------------------------------------------------------------------- |
|---|
| 28 | */ |
|---|
| 29 | #ifndef __ROOT__ |
|---|
| 30 | #define __ROOT__ |
|---|
| 31 | |
|---|
| 32 | // Precompiler options |
|---|
| 33 | #include "OgrePrerequisites.h" |
|---|
| 34 | |
|---|
| 35 | #include "OgreSingleton.h" |
|---|
| 36 | #include "OgreString.h" |
|---|
| 37 | #include "OgreSceneManagerEnumerator.h" |
|---|
| 38 | #include "OgreResourceGroupManager.h" |
|---|
| 39 | |
|---|
| 40 | #include <exception> |
|---|
| 41 | |
|---|
| 42 | namespace Ogre |
|---|
| 43 | { |
|---|
| 44 | typedef std::vector<RenderSystem*> RenderSystemList; |
|---|
| 45 | |
|---|
| 46 | /** The root class of the Ogre system. |
|---|
| 47 | @remarks |
|---|
| 48 | The Ogre::Root class represents a starting point for the client |
|---|
| 49 | application. From here, the application can gain access to the |
|---|
| 50 | fundamentals of the system, namely the rendering systems |
|---|
| 51 | available, management of saved configurations, logging, and |
|---|
| 52 | access to other classes in the system. Acts as a hub from which |
|---|
| 53 | all other objects may be reached. An instance of Root must be |
|---|
| 54 | created before any other Ogre operations are called. Once an |
|---|
| 55 | instance has been created, the same instance is accessible |
|---|
| 56 | throughout the life of that object by using Root::getSingleton |
|---|
| 57 | (as a reference) or Root::getSingletonPtr (as a pointer). |
|---|
| 58 | */ |
|---|
| 59 | class _OgreExport Root : public Singleton<Root> |
|---|
| 60 | { |
|---|
| 61 | // To allow update of active renderer if |
|---|
| 62 | // RenderSystem::initialise is used directly |
|---|
| 63 | friend class RenderSystem; |
|---|
| 64 | private: |
|---|
| 65 | RenderSystemList mRenderers; |
|---|
| 66 | RenderSystem* mActiveRenderer; |
|---|
| 67 | String mVersion; |
|---|
| 68 | String mConfigFileName; |
|---|
| 69 | bool mQueuedEnd; |
|---|
| 70 | // In case multiple render windows are created, only once are the resources loaded. |
|---|
| 71 | bool mFirstTimePostWindowInit; |
|---|
| 72 | |
|---|
| 73 | // Singletons |
|---|
| 74 | LogManager* mLogManager; |
|---|
| 75 | ControllerManager* mControllerManager; |
|---|
| 76 | SceneManagerEnumerator* mSceneManagerEnum; |
|---|
| 77 | SceneManager* mCurrentSceneManager; |
|---|
| 78 | DynLibManager* mDynLibManager; |
|---|
| 79 | ArchiveManager* mArchiveManager; |
|---|
| 80 | MaterialManager* mMaterialManager; |
|---|
| 81 | MeshManager* mMeshManager; |
|---|
| 82 | ParticleSystemManager* mParticleManager; |
|---|
| 83 | SkeletonManager* mSkeletonManager; |
|---|
| 84 | OverlayElementFactory* mPanelFactory; |
|---|
| 85 | OverlayElementFactory* mBorderPanelFactory; |
|---|
| 86 | OverlayElementFactory* mTextAreaFactory; |
|---|
| 87 | OverlayManager* mOverlayManager; |
|---|
| 88 | FontManager* mFontManager; |
|---|
| 89 | ArchiveFactory *mZipArchiveFactory; |
|---|
| 90 | ArchiveFactory *mFileSystemArchiveFactory; |
|---|
| 91 | ResourceGroupManager* mResourceGroupManager; |
|---|
| 92 | ResourceBackgroundQueue* mResourceBackgroundQueue; |
|---|
| 93 | ShadowTextureManager* mShadowTextureManager; |
|---|
| 94 | |
|---|
| 95 | Timer* mTimer; |
|---|
| 96 | RenderWindow* mAutoWindow; |
|---|
| 97 | Profiler* mProfiler; |
|---|
| 98 | HighLevelGpuProgramManager* mHighLevelGpuProgramManager; |
|---|
| 99 | ExternalTextureSourceManager* mExternalTextureSourceManager; |
|---|
| 100 | CompositorManager* mCompositorManager; |
|---|
| 101 | unsigned long mCurrentFrame; |
|---|
| 102 | Real mFrameSmoothingTime; |
|---|
| 103 | |
|---|
| 104 | public: |
|---|
| 105 | typedef std::vector<DynLib*> PluginLibList; |
|---|
| 106 | typedef std::vector<Plugin*> PluginInstanceList; |
|---|
| 107 | protected: |
|---|
| 108 | /// List of plugin DLLs loaded |
|---|
| 109 | PluginLibList mPluginLibs; |
|---|
| 110 | /// List of Plugin instances registered |
|---|
| 111 | PluginInstanceList mPlugins; |
|---|
| 112 | |
|---|
| 113 | typedef std::map<String, MovableObjectFactory*> MovableObjectFactoryMap; |
|---|
| 114 | MovableObjectFactoryMap mMovableObjectFactoryMap; |
|---|
| 115 | uint32 mNextMovableObjectTypeFlag; |
|---|
| 116 | // stock movable factories |
|---|
| 117 | MovableObjectFactory* mEntityFactory; |
|---|
| 118 | MovableObjectFactory* mLightFactory; |
|---|
| 119 | MovableObjectFactory* mBillboardSetFactory; |
|---|
| 120 | MovableObjectFactory* mManualObjectFactory; |
|---|
| 121 | MovableObjectFactory* mBillboardChainFactory; |
|---|
| 122 | MovableObjectFactory* mRibbonTrailFactory; |
|---|
| 123 | |
|---|
| 124 | typedef std::map<String, RenderQueueInvocationSequence*> RenderQueueInvocationSequenceMap; |
|---|
| 125 | RenderQueueInvocationSequenceMap mRQSequenceMap; |
|---|
| 126 | |
|---|
| 127 | /// Are we initialised yet? |
|---|
| 128 | bool mIsInitialised; |
|---|
| 129 | |
|---|
| 130 | /** Method reads a plugins configuration file and instantiates all |
|---|
| 131 | plugins. |
|---|
| 132 | @param |
|---|
| 133 | pluginsfile The file that contains plugins information. |
|---|
| 134 | Defaults to "plugins.cfg". |
|---|
| 135 | */ |
|---|
| 136 | void loadPlugins( const String& pluginsfile = "plugins.cfg" ); |
|---|
| 137 | /** Initialise all loaded plugins - allows plugins to perform actions |
|---|
| 138 | once the renderer is initialised. |
|---|
| 139 | */ |
|---|
| 140 | void initialisePlugins(); |
|---|
| 141 | /** Shuts down all loaded plugins - allows things to be tidied up whilst |
|---|
| 142 | all plugins are still loaded. |
|---|
| 143 | */ |
|---|
| 144 | void shutdownPlugins(); |
|---|
| 145 | |
|---|
| 146 | /** Unloads all loaded plugins. |
|---|
| 147 | */ |
|---|
| 148 | void unloadPlugins(); |
|---|
| 149 | |
|---|
| 150 | // Internal method for one-time tasks after first window creation |
|---|
| 151 | void oneTimePostWindowInit(void); |
|---|
| 152 | |
|---|
| 153 | /** Set of registered frame listeners */ |
|---|
| 154 | std::set<FrameListener*> mFrameListeners; |
|---|
| 155 | |
|---|
| 156 | /** Set of frame listeners marked for removal*/ |
|---|
| 157 | std::set<FrameListener*> mRemovedFrameListeners; |
|---|
| 158 | |
|---|
| 159 | /** Indicates the type of event to be considered by calculateEventTime(). */ |
|---|
| 160 | enum FrameEventTimeType { |
|---|
| 161 | FETT_ANY, FETT_STARTED, FETT_ENDED |
|---|
| 162 | }; |
|---|
| 163 | |
|---|
| 164 | /// Contains the times of recently fired events |
|---|
| 165 | std::deque<unsigned long> mEventTimes[3]; |
|---|
| 166 | |
|---|
| 167 | /** Internal method for calculating the average time between recently fired events. |
|---|
| 168 | @param now The current time in ms. |
|---|
| 169 | @param type The type of event to be considered. |
|---|
| 170 | */ |
|---|
| 171 | Real calculateEventTime(unsigned long now, FrameEventTimeType type); |
|---|
| 172 | public: |
|---|
| 173 | |
|---|
| 174 | /** Constructor |
|---|
| 175 | @param pluginFileName The file that contains plugins information. |
|---|
| 176 | Defaults to "plugins.cfg", may be left blank to ignore. |
|---|
| 177 | @param configFileName The file that contains the configuration to be loaded. |
|---|
| 178 | Defaults to "ogre.cfg", may be left blank to load nothing. |
|---|
| 179 | @param logFileName The logfile to create, defaults to Ogre.log, may be |
|---|
| 180 | left blank if you've already set up LogManager & Log yourself |
|---|
| 181 | */ |
|---|
| 182 | Root(const String& pluginFileName = "plugins.cfg", |
|---|
| 183 | const String& configFileName = "ogre.cfg", |
|---|
| 184 | const String& logFileName = "Ogre.log"); |
|---|
| 185 | ~Root(); |
|---|
| 186 | |
|---|
| 187 | /** Saves the details of the current configuration |
|---|
| 188 | @remarks |
|---|
| 189 | Stores details of the current configuration so it may be |
|---|
| 190 | restored later on. |
|---|
| 191 | */ |
|---|
| 192 | void saveConfig(void); |
|---|
| 193 | |
|---|
| 194 | /** Checks for saved video/sound/etc settings |
|---|
| 195 | @remarks |
|---|
| 196 | This method checks to see if there is a valid saved configuration |
|---|
| 197 | from a previous run. If there is, the state of the system will |
|---|
| 198 | be restored to that configuration. |
|---|
| 199 | |
|---|
| 200 | @returns |
|---|
| 201 | If a valid configuration was found, <b>true</b> is returned. |
|---|
| 202 | @par |
|---|
| 203 | If there is no saved configuration, or if the system failed |
|---|
| 204 | with the last config settings, <b>false</b> is returned. |
|---|
| 205 | */ |
|---|
| 206 | bool restoreConfig(void); |
|---|
| 207 | |
|---|
| 208 | /** Displays a dialog asking the user to choose system settings. |
|---|
| 209 | @remarks |
|---|
| 210 | This method displays the default dialog allowing the user to |
|---|
| 211 | choose the renderering system, video mode etc. If there is are |
|---|
| 212 | any settings saved already, they will be restored automatically |
|---|
| 213 | before displaying the dialogue. When the user accepts a group of |
|---|
| 214 | settings, this will automatically call Root::setRenderSystem, |
|---|
| 215 | RenderSystem::setConfigOption and Root::saveConfig with the |
|---|
| 216 | user's choices. This is the easiest way to get the system |
|---|
| 217 | configured. |
|---|
| 218 | @returns |
|---|
| 219 | If the user clicked 'Ok', <b>true</b> is returned. |
|---|
| 220 | @par |
|---|
| 221 | If they clicked 'Cancel' (in which case the app should |
|---|
| 222 | strongly consider terminating), <b>false</b> is returned. |
|---|
| 223 | */ |
|---|
| 224 | bool showConfigDialog(void); |
|---|
| 225 | |
|---|
| 226 | /** Adds a new rendering subsystem to the list of available renderers. |
|---|
| 227 | @remarks |
|---|
| 228 | Intended for use by advanced users and plugin writers only! |
|---|
| 229 | Calling this method with a pointer to a valid RenderSystem |
|---|
| 230 | (sublcass) adds a rendering API implementation to the list of |
|---|
| 231 | available ones. Typical examples would be an OpenGL |
|---|
| 232 | implementation and a Direct3D implementation. |
|---|
| 233 | @note |
|---|
| 234 | <br>This should usually be called from the dllStartPlugin() |
|---|
| 235 | function of an extension plug-in. |
|---|
| 236 | */ |
|---|
| 237 | void addRenderSystem(RenderSystem* newRend); |
|---|
| 238 | |
|---|
| 239 | /** Retrieve a list of the available render systems. |
|---|
| 240 | @remarks |
|---|
| 241 | Retrieves a pointer to the list of available renderers as a |
|---|
| 242 | list of RenderSystem subclasses. Can be used to build a |
|---|
| 243 | custom settings dialog. |
|---|
| 244 | */ |
|---|
| 245 | RenderSystemList* getAvailableRenderers(void); |
|---|
| 246 | |
|---|
| 247 | /** Retrieve a pointer to the render system by the given name |
|---|
| 248 | @param |
|---|
| 249 | name Name of the render system intend to retrieve. |
|---|
| 250 | @returns |
|---|
| 251 | A pointer to the render system, <b>NULL</b> if no found. |
|---|
| 252 | */ |
|---|
| 253 | RenderSystem* getRenderSystemByName(const String& name); |
|---|
| 254 | |
|---|
| 255 | /** Sets the rendering subsystem to be used. |
|---|
| 256 | @remarks |
|---|
| 257 | This method indicates to OGRE which rendering system is to be |
|---|
| 258 | used (e.g. Direct3D, OpenGL etc). This is called |
|---|
| 259 | automatically by the default config dialog, and when settings |
|---|
| 260 | are restored from a previous configuraion. If used manually |
|---|
| 261 | it could be used to set the renderer from a custom settings |
|---|
| 262 | dialog. Once this has been done, the renderer can be |
|---|
| 263 | initialised using Root::initialise. |
|---|
| 264 | @par |
|---|
| 265 | This method is also called by render systems if they are |
|---|
| 266 | initialised directly. |
|---|
| 267 | @param |
|---|
| 268 | system Pointer to the render system to use. |
|---|
| 269 | @see |
|---|
| 270 | RenderSystem |
|---|
| 271 | */ |
|---|
| 272 | void setRenderSystem(RenderSystem* system); |
|---|
| 273 | |
|---|
| 274 | /** Retrieve a pointer to the currently selected render system. |
|---|
| 275 | */ |
|---|
| 276 | RenderSystem* getRenderSystem(void); |
|---|
| 277 | |
|---|
| 278 | /** Initialises the renderer. |
|---|
| 279 | @remarks |
|---|
| 280 | This method can only be called after a renderer has been |
|---|
| 281 | selected with Root::setRenderSystem, and it will initialise |
|---|
| 282 | the selected rendering system ready for use. |
|---|
| 283 | @param |
|---|
| 284 | autoCreateWindow If true, a rendering window will |
|---|
| 285 | automatically be created (saving a call to |
|---|
| 286 | RenderSystem::createRenderWindow). The window will be |
|---|
| 287 | created based on the options currently set on the render |
|---|
| 288 | system. |
|---|
| 289 | @returns |
|---|
| 290 | A pointer to the automatically created window, if |
|---|
| 291 | requested, otherwise <b>NULL</b>. |
|---|
| 292 | */ |
|---|
| 293 | RenderWindow* initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render Window"); |
|---|
| 294 | |
|---|
| 295 | /** Returns whether the system is initialised or not. */ |
|---|
| 296 | bool isInitialised(void) const { return mIsInitialised; } |
|---|
| 297 | |
|---|
| 298 | /** Register a new SceneManagerFactory, a factory object for creating instances |
|---|
| 299 | of specific SceneManagers. |
|---|
| 300 | @remarks |
|---|
| 301 | Plugins should call this to register as new SceneManager providers. |
|---|
| 302 | */ |
|---|
| 303 | void addSceneManagerFactory(SceneManagerFactory* fact); |
|---|
| 304 | |
|---|
| 305 | /** Unregister a SceneManagerFactory. |
|---|
| 306 | */ |
|---|
| 307 | void removeSceneManagerFactory(SceneManagerFactory* fact); |
|---|
| 308 | |
|---|
| 309 | /** Get more information about a given type of SceneManager. |
|---|
| 310 | @remarks |
|---|
| 311 | The metadata returned tells you a few things about a given type |
|---|
| 312 | of SceneManager, which can be created using a factory that has been |
|---|
| 313 | registered already. |
|---|
| 314 | @param typeName The type name of the SceneManager you want to enquire on. |
|---|
| 315 | If you don't know the typeName already, you can iterate over the |
|---|
| 316 | metadata for all types using getMetaDataIterator. |
|---|
| 317 | */ |
|---|
| 318 | const SceneManagerMetaData* getSceneManagerMetaData(const String& typeName) const; |
|---|
| 319 | |
|---|
| 320 | /** Iterate over all types of SceneManager available for construction, |
|---|
| 321 | providing some information about each one. |
|---|
| 322 | */ |
|---|
| 323 | SceneManagerEnumerator::MetaDataIterator getSceneManagerMetaDataIterator(void) const; |
|---|
| 324 | |
|---|
| 325 | /** Create a SceneManager instance of a given type. |
|---|
| 326 | @remarks |
|---|
| 327 | You can use this method to create a SceneManager instance of a |
|---|
| 328 | given specific type. You may know this type already, or you may |
|---|
| 329 | have discovered it by looking at the results from getMetaDataIterator. |
|---|
| 330 | @note |
|---|
| 331 | This method throws an exception if the named type is not found. |
|---|
| 332 | @param typeName String identifying a unique SceneManager type |
|---|
| 333 | @param instanceName Optional name to given the new instance that is |
|---|
| 334 | created. If you leave this blank, an auto name will be assigned. |
|---|
| 335 | */ |
|---|
| 336 | SceneManager* createSceneManager(const String& typeName, |
|---|
| 337 | const String& instanceName = StringUtil::BLANK); |
|---|
| 338 | |
|---|
| 339 | /** Create a SceneManager instance based on scene type support. |
|---|
| 340 | @remarks |
|---|
| 341 | Creates an instance of a SceneManager which supports the scene types |
|---|
| 342 | identified in the parameter. If more than one type of SceneManager |
|---|
| 343 | has been registered as handling that combination of scene types, |
|---|
| 344 | in instance of the last one registered is returned. |
|---|
| 345 | @note This method always succeeds, if a specific scene manager is not |
|---|
| 346 | found, the default implementation is always returned. |
|---|
| 347 | @param typeMask A mask containing one or more SceneType flags |
|---|
| 348 | @param instanceName Optional name to given the new instance that is |
|---|
| 349 | created. If you leave this blank, an auto name will be assigned. |
|---|
| 350 | */ |
|---|
| 351 | SceneManager* createSceneManager(SceneTypeMask typeMask, |
|---|
| 352 | const String& instanceName = StringUtil::BLANK); |
|---|
| 353 | |
|---|
| 354 | /** Destroy an instance of a SceneManager. */ |
|---|
| 355 | void destroySceneManager(SceneManager* sm); |
|---|
| 356 | |
|---|
| 357 | /** Get an existing SceneManager instance that has already been created, |
|---|
| 358 | identified by the instance name. |
|---|
| 359 | @param instanceName The name of the instance to retrieve. |
|---|
| 360 | */ |
|---|
| 361 | SceneManager* getSceneManager(const String& instanceName) const; |
|---|
| 362 | |
|---|
| 363 | /** Get an iterator over all the existing SceneManager instances. */ |
|---|
| 364 | SceneManagerEnumerator::SceneManagerIterator getSceneManagerIterator(void); |
|---|
| 365 | |
|---|
| 366 | /** Retrieves a reference to the current TextureManager. |
|---|
| 367 | @remarks |
|---|
| 368 | This performs the same function as |
|---|
| 369 | TextureManager::getSingleton, but is provided for convenience |
|---|
| 370 | particularly to scripting engines. |
|---|
| 371 | @par |
|---|
| 372 | Note that a TextureManager will NOT be available until the |
|---|
| 373 | Ogre system has been initialised by selecting a RenderSystem, |
|---|
| 374 | calling Root::initialise and a window having been created |
|---|
| 375 | (this may have been done by initialise if required). This is |
|---|
| 376 | because the exact runtime subclass which will be implementing |
|---|
| 377 | the calls will differ depending on the rendering engine |
|---|
| 378 | selected, and these typically require a window upon which to |
|---|
| 379 | base texture format decisions. |
|---|
| 380 | */ |
|---|
| 381 | TextureManager* getTextureManager(void); |
|---|
| 382 | |
|---|
| 383 | /** Retrieves a reference to the current MeshManager. |
|---|
| 384 | @remarks |
|---|
| 385 | This performs the same function as MeshManager::getSingleton |
|---|
| 386 | and is provided for convenience to scripting engines. |
|---|
| 387 | */ |
|---|
| 388 | MeshManager* getMeshManager(void); |
|---|
| 389 | |
|---|
| 390 | /** Utility function for getting a better description of an error |
|---|
| 391 | code. |
|---|
| 392 | */ |
|---|
| 393 | String getErrorDescription(long errorNumber); |
|---|
| 394 | |
|---|
| 395 | /** Registers a FrameListener which will be called back every frame. |
|---|
| 396 | @remarks |
|---|
| 397 | A FrameListener is a class which implements methods which |
|---|
| 398 | will be called every frame. |
|---|
| 399 | @par |
|---|
| 400 | See the FrameListener class for more details on the specifics |
|---|
| 401 | It is imperitive that the instance passed to this method is |
|---|
| 402 | not destroyed before either the rendering loop ends, or the |
|---|
| 403 | class is removed from the listening list using |
|---|
| 404 | removeFrameListener. |
|---|
| 405 | @note |
|---|
| 406 | <br>This method can only be called after Root::initialise has |
|---|
| 407 | been called. |
|---|
| 408 | @see |
|---|
| 409 | FrameListener, Root::removeFrameListener |
|---|
| 410 | */ |
|---|
| 411 | void addFrameListener(FrameListener* newListener); |
|---|
| 412 | |
|---|
| 413 | /** Removes a FrameListener from the list of listening classes. |
|---|
| 414 | @see |
|---|
| 415 | FrameListener, Root::addFrameListener |
|---|
| 416 | */ |
|---|
| 417 | void removeFrameListener(FrameListener* oldListener); |
|---|
| 418 | |
|---|
| 419 | /** Queues the end of rendering. |
|---|
| 420 | @remarks |
|---|
| 421 | This method will do nothing unless startRendering() has |
|---|
| 422 | been called, in which case before the next frame is rendered |
|---|
| 423 | the rendering loop will bail out. |
|---|
| 424 | @see |
|---|
| 425 | Root, Root::startRendering |
|---|
| 426 | */ |
|---|
| 427 | void queueEndRendering(void); |
|---|
| 428 | |
|---|
| 429 | /** Starts / restarts the automatic rendering cycle. |
|---|
| 430 | @remarks |
|---|
| 431 | This method begins the automatic rendering of the scene. It |
|---|
| 432 | will <b>NOT</b> return until the rendering cycle is halted. |
|---|
| 433 | @par |
|---|
| 434 | During rendering, any FrameListener classes registered using |
|---|
| 435 | addFrameListener will be called back for each frame that is |
|---|
| 436 | to be rendered, These classes can tell OGRE to halt the |
|---|
| 437 | rendering if required, which will cause this method to |
|---|
| 438 | return. |
|---|
| 439 | @note |
|---|
| 440 | <br>Users of the OGRE library do not have to use this |
|---|
| 441 | automatic rendering loop. It is there as a convenience and is |
|---|
| 442 | most useful for high frame rate applications e.g. games. For |
|---|
| 443 | applications that don't need to constantly refresh the |
|---|
| 444 | rendering targets (e.g. an editor utility), it is better to |
|---|
| 445 | manually refresh each render target only when required by |
|---|
| 446 | calling RenderTarget::update, or if you want to run your own |
|---|
| 447 | render loop you can update all targets on demand using |
|---|
| 448 | Root::renderOneFrame. |
|---|
| 449 | @note |
|---|
| 450 | This frees up the CPU to do other things in between |
|---|
| 451 | refreshes, since in this case frame rate is less important. |
|---|
| 452 | @note |
|---|
| 453 | This method can only be called after Root::initialise has |
|---|
| 454 | been called. |
|---|
| 455 | */ |
|---|
| 456 | void startRendering(void); |
|---|
| 457 | |
|---|
| 458 | /** Render one frame. |
|---|
| 459 | @remarks |
|---|
| 460 | Updates all the render targets automatically and then returns, |
|---|
| 461 | raising frame events before and after. |
|---|
| 462 | */ |
|---|
| 463 | bool renderOneFrame(void); |
|---|
| 464 | /** Shuts down the system manually. |
|---|
| 465 | @remarks |
|---|
| 466 | This is normally done by Ogre automatically so don't think |
|---|
| 467 | you have to call this yourself. However this is here for |
|---|
| 468 | convenience, especially for dealing with unexpected errors or |
|---|
| 469 | for systems which need to shut down Ogre on demand. |
|---|
| 470 | */ |
|---|
| 471 | void shutdown(void); |
|---|
| 472 | |
|---|
| 473 | /** Adds a location to the list of searchable locations for a |
|---|
| 474 | Resource type. |
|---|
| 475 | @remarks |
|---|
| 476 | Resource files (textures, models etc) need to be loaded from |
|---|
| 477 | specific locations. By calling this method, you add another |
|---|
| 478 | search location to the list. Locations added first are preferred |
|---|
| 479 | over locations added later. |
|---|
| 480 | @par |
|---|
| 481 | Locations can be folders, compressed archives, even perhaps |
|---|
| 482 | remote locations. Facilities for loading from different |
|---|
| 483 | locations are provided by plugins which provide |
|---|
| 484 | implementations of the Archive class. |
|---|
| 485 | All the application user has to do is specify a 'loctype' |
|---|
| 486 | string in order to indicate the type of location, which |
|---|
| 487 | should map onto one of the provided plugins. Ogre comes |
|---|
| 488 | configured with the 'FileSystem' (folders) and 'Zip' (archive |
|---|
| 489 | compressed with the pkzip / WinZip etc utilities) types. |
|---|
| 490 | @par |
|---|
| 491 | You can also supply the name of a resource group which should |
|---|
| 492 | have this location applied to it. The |
|---|
| 493 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME group is the |
|---|
| 494 | default, and one resource group which will always exist. You |
|---|
| 495 | should consider defining resource groups for your more specific |
|---|
| 496 | resources (e.g. per level) so that you can control loading / |
|---|
| 497 | unloading better. |
|---|
| 498 | @param |
|---|
| 499 | name The name of the location, e.g. './data' or |
|---|
| 500 | '/compressed/gamedata.zip' |
|---|
| 501 | @param |
|---|
| 502 | locType A string identifying the location type, e.g. |
|---|
| 503 | 'FileSystem' (for folders), 'Zip' etc. Must map to a |
|---|
| 504 | registered plugin which deals with this type (FileSystem and |
|---|
| 505 | Zip should always be available) |
|---|
| 506 | @param |
|---|
| 507 | groupName Type of name of the resource group which this location |
|---|
| 508 | should apply to; defaults to the General group which applies to |
|---|
| 509 | all non-specific resources. |
|---|
| 510 | @param |
|---|
| 511 | recursive If the resource location has a concept of recursive |
|---|
| 512 | directory traversal, enabling this option will mean you can load |
|---|
| 513 | resources in subdirectories using only their unqualified name. |
|---|
| 514 | The default is to disable this so that resources in subdirectories |
|---|
| 515 | with the same name are still unique. |
|---|
| 516 | @see |
|---|
| 517 | Archive |
|---|
| 518 | */ |
|---|
| 519 | void addResourceLocation(const String& name, const String& locType, |
|---|
| 520 | const String& groupName = ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, |
|---|
| 521 | bool recursive = false); |
|---|
| 522 | |
|---|
| 523 | /** Removes a resource location from the list. |
|---|
| 524 | @see addResourceLocation |
|---|
| 525 | @param name The name of the resource location as specified in addResourceLocation |
|---|
| 526 | @param groupName The name of the resource group to which this location |
|---|
| 527 | was assigned. |
|---|
| 528 | */ |
|---|
| 529 | void removeResourceLocation(const String& name, |
|---|
| 530 | const String& groupName = ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
|---|
| 531 | |
|---|
| 532 | /** Generates a packed data version of the passed in ColourValue suitable for |
|---|
| 533 | use with the current RenderSystem. |
|---|
| 534 | @remarks |
|---|
| 535 | Since different render systems have different colour data formats (eg |
|---|
| 536 | RGBA for GL, ARGB for D3D) this method allows you to use 1 method for all. |
|---|
| 537 | @param colour The colour to convert |
|---|
| 538 | @param pDest Pointer to location to put the result. |
|---|
| 539 | */ |
|---|
| 540 | void convertColourValue(const ColourValue& colour, uint32* pDest); |
|---|
| 541 | |
|---|
| 542 | /** Retrieves a pointer to the window that was created automatically |
|---|
| 543 | @remarks |
|---|
| 544 | When Root is initialised an optional window is created. This |
|---|
| 545 | method retreives a pointer to that window. |
|---|
| 546 | @note |
|---|
| 547 | returns a null pointer when Root has not been initialised with |
|---|
| 548 | the option of creating a window. |
|---|
| 549 | */ |
|---|
| 550 | RenderWindow* getAutoCreatedWindow(void); |
|---|
| 551 | |
|---|
| 552 | /** @copydoc RenderSystem::createRenderWindow |
|---|
| 553 | */ |
|---|
| 554 | RenderWindow* createRenderWindow(const String &name, unsigned int width, unsigned int height, |
|---|
| 555 | bool fullScreen, const NameValuePairList *miscParams = 0) ; |
|---|
| 556 | |
|---|
| 557 | /** Destroys a rendering window. |
|---|
| 558 | */ |
|---|
| 559 | void detachRenderTarget( RenderTarget* pWin ); |
|---|
| 560 | |
|---|
| 561 | /** Destroys a named rendering window. |
|---|
| 562 | */ |
|---|
| 563 | void detachRenderTarget( const String & name ); |
|---|
| 564 | |
|---|
| 565 | /** Retrieves a pointer to the a named render window. |
|---|
| 566 | */ |
|---|
| 567 | RenderTarget * getRenderTarget(const String &name); |
|---|
| 568 | |
|---|
| 569 | /** Manually load a Plugin contained in a DLL / DSO. |
|---|
| 570 | @remarks |
|---|
| 571 | Plugins embedded in DLLs can be loaded at startup using the plugin |
|---|
| 572 | configuration file specified when you create Root (default: plugins.cfg). |
|---|
| 573 | This method allows you to load plugin DLLs directly in code. |
|---|
| 574 | The DLL in question is expected to implement a dllStartPlugin |
|---|
| 575 | method which instantiates a Plugin subclass and calls Root::installPlugin. |
|---|
| 576 | It should also implement dllStopPlugin (see Root::unloadPlugin) |
|---|
| 577 | @param pluginName Name of the plugin library to load |
|---|
| 578 | */ |
|---|
| 579 | void loadPlugin(const String& pluginName); |
|---|
| 580 | |
|---|
| 581 | /** Manually unloads a Plugin contained in a DLL / DSO. |
|---|
| 582 | @remarks |
|---|
| 583 | Plugin DLLs are unloaded at shutdown automatically. This method |
|---|
| 584 | allows you to unload plugins in code, but make sure their |
|---|
| 585 | dependencies are decoupled first. This method will call the |
|---|
| 586 | dllStopPlugin method defined in the DLL, which in turn should call |
|---|
| 587 | Root::uninstallPlugin. |
|---|
| 588 | @param pluginName Name of the plugin library to unload |
|---|
| 589 | */ |
|---|
| 590 | void unloadPlugin(const String& pluginName); |
|---|
| 591 | |
|---|
| 592 | /** Install a new plugin. |
|---|
| 593 | @remarks |
|---|
| 594 | This installs a new extension to OGRE. The plugin itself may be loaded |
|---|
| 595 | from a DLL / DSO, or it might be statically linked into your own |
|---|
| 596 | application. Either way, something has to call this method to get |
|---|
| 597 | it registered and functioning. You should only call this method directly |
|---|
| 598 | if your plugin is not in a DLL that could otherwise be loaded with |
|---|
| 599 | loadPlugin, since the DLL function dllStartPlugin should call this |
|---|
| 600 | method when the DLL is loaded. |
|---|
| 601 | */ |
|---|
| 602 | void installPlugin(Plugin* plugin); |
|---|
| 603 | |
|---|
| 604 | /** Uninstall an existing plugin. |
|---|
| 605 | @remarks |
|---|
| 606 | This uninstalls an extension to OGRE. Plugins are automatically |
|---|
| 607 | uninstalled at shutdown but this lets you remove them early. |
|---|
| 608 | If the plugin was loaded from a DLL / DSO you should call unloadPlugin |
|---|
| 609 | which should result in this method getting called anyway (if the DLL |
|---|
| 610 | is well behaved). |
|---|
| 611 | */ |
|---|
| 612 | void uninstallPlugin(Plugin* plugin); |
|---|
| 613 | |
|---|
| 614 | /** Gets a read-only list of the currently installed plugins. */ |
|---|
| 615 | const PluginInstanceList& getInstalledPlugins() const { return mPlugins; } |
|---|
| 616 | |
|---|
| 617 | /** Gets a pointer to the central timer used for all OGRE timings */ |
|---|
| 618 | Timer* getTimer(void); |
|---|
| 619 | |
|---|
| 620 | /** Method for raising frame started events. |
|---|
| 621 | @remarks |
|---|
| 622 | This method is only for internal use when you use OGRE's inbuilt rendering |
|---|
| 623 | loop (Root::startRendering). However, if you run your own rendering loop then |
|---|
| 624 | you should call this method to ensure that FrameListener objects are notified |
|---|
| 625 | of frame events; processes like texture animation and particle systems rely on |
|---|
| 626 | this. |
|---|
| 627 | @par |
|---|
| 628 | Calling this method also increments the frame number, which is |
|---|
| 629 | important for keeping some elements of the engine up to date. |
|---|
| 630 | @note |
|---|
| 631 | This method takes an event object as a parameter, so you can specify the times |
|---|
| 632 | yourself. If you are happy for OGRE to automatically calculate the frame time |
|---|
| 633 | for you, then call the other version of this method with no parameters. |
|---|
| 634 | @param evt Event object which includes all the timing information which you have |
|---|
| 635 | calculated for yourself |
|---|
| 636 | @returns False if one or more frame listeners elected that the rendering loop should |
|---|
| 637 | be terminated, true otherwise. |
|---|
| 638 | */ |
|---|
| 639 | bool _fireFrameStarted(FrameEvent& evt); |
|---|
| 640 | /** Method for raising frame ended events. |
|---|
| 641 | @remarks |
|---|
| 642 | This method is only for internal use when you use OGRE's inbuilt rendering |
|---|
| 643 | loop (Root::startRendering). However, if you run your own rendering loop then |
|---|
| 644 | you should call this method to ensure that FrameListener objects are notified |
|---|
| 645 | of frame events; processes like texture animation and particle systems rely on |
|---|
| 646 | this. |
|---|
| 647 | @note |
|---|
| 648 | This method takes an event object as a parameter, so you can specify the times |
|---|
| 649 | yourself. If you are happy for OGRE to automatically calculate the frame time |
|---|
| 650 | for you, then call the other version of this method with no parameters. |
|---|
| 651 | @param evt Event object which includes all the timing information which you have |
|---|
| 652 | calculated for yourself |
|---|
| 653 | @returns False if one or more frame listeners elected that the rendering loop should |
|---|
| 654 | be terminated, true otherwise. |
|---|
| 655 | */ |
|---|
| 656 | bool _fireFrameEnded(FrameEvent& evt); |
|---|
| 657 | /** Method for raising frame started events. |
|---|
| 658 | @remarks |
|---|
| 659 | This method is only for internal use when you use OGRE's inbuilt rendering |
|---|
| 660 | loop (Root::startRendering). However, if you run your own rendering loop then |
|---|
| 661 | you should call this method to ensure that FrameListener objects are notified |
|---|
| 662 | of frame events; processes like texture animation and particle systems rely on |
|---|
| 663 | this. |
|---|
| 664 | @par |
|---|
| 665 | Calling this method also increments the frame number, which is |
|---|
| 666 | important for keeping some elements of the engine up to date. |
|---|
| 667 | @note |
|---|
| 668 | This method calculates the frame timing information for you based on the elapsed |
|---|
| 669 | time. If you want to specify elapsed times yourself you should call the other |
|---|
| 670 | version of this method which takes event details as a parameter. |
|---|
| 671 | @returns False if one or more frame listeners elected that the rendering loop should |
|---|
| 672 | be terminated, true otherwise. |
|---|
| 673 | */ |
|---|
| 674 | bool _fireFrameStarted(); |
|---|
| 675 | /** Method for raising frame ended events. |
|---|
| 676 | @remarks |
|---|
| 677 | This method is only for internal use when you use OGRE's inbuilt rendering |
|---|
| 678 | loop (Root::startRendering). However, if you run your own rendering loop then |
|---|
| 679 | you should call this method to ensure that FrameListener objects are notified |
|---|
| 680 | of frame events; processes like texture animation and particle systems rely on |
|---|
| 681 | this. |
|---|
| 682 | @note |
|---|
| 683 | This method calculates the frame timing information for you based on the elapsed |
|---|
| 684 | time. If you want to specify elapsed times yourself you should call the other |
|---|
| 685 | version of this method which takes event details as a parameter. |
|---|
| 686 | @returns False if one or more frame listeners elected that the rendering loop should |
|---|
| 687 | be terminated, true otherwise. |
|---|
| 688 | */ |
|---|
| 689 | bool _fireFrameEnded(); |
|---|
| 690 | |
|---|
| 691 | /** Gets the number of the current frame. */ |
|---|
| 692 | unsigned long getCurrentFrameNumber(void) const { return mCurrentFrame; } |
|---|
| 693 | |
|---|
| 694 | /** Returns the scene manager currently being used to render a frame. |
|---|
| 695 | @remarks |
|---|
| 696 | This is only intended for internal use; it is only valid during the |
|---|
| 697 | rendering of a frame. |
|---|
| 698 | */ |
|---|
| 699 | SceneManager* _getCurrentSceneManager(void) const { return mCurrentSceneManager; } |
|---|
| 700 | /** Sets the scene manager currently being used to render a frame. |
|---|
| 701 | @remarks |
|---|
| 702 | This is only intended for internal use. |
|---|
| 703 | */ |
|---|
| 704 | void _setCurrentSceneManager(SceneManager* sm); |
|---|
| 705 | |
|---|
| 706 | /** Internal method used for updating all RenderTarget objects (windows, |
|---|
| 707 | renderable textures etc) which are set to auto-update. |
|---|
| 708 | @remarks |
|---|
| 709 | You don't need to use this method if you're using Ogre's own internal |
|---|
| 710 | rendering loop (Root::startRendering). If you're running your own loop |
|---|
| 711 | you may wish to call it to update all the render targets which are |
|---|
| 712 | set to auto update (RenderTarget::setAutoUpdated). You can also update |
|---|
| 713 | individual RenderTarget instances using their own update() method. |
|---|
| 714 | */ |
|---|
| 715 | void _updateAllRenderTargets(void); |
|---|
| 716 | |
|---|
| 717 | /** Create a new RenderQueueInvocationSequence, useful for linking to |
|---|
| 718 | Viewport instances to perform custom rendering. |
|---|
| 719 | @param name The name to give the new sequence |
|---|
| 720 | */ |
|---|
| 721 | RenderQueueInvocationSequence* createRenderQueueInvocationSequence( |
|---|
| 722 | const String& name); |
|---|
| 723 | |
|---|
| 724 | /** Get a RenderQueueInvocationSequence. |
|---|
| 725 | @param name The name to identify the sequence |
|---|
| 726 | */ |
|---|
| 727 | RenderQueueInvocationSequence* getRenderQueueInvocationSequence( |
|---|
| 728 | const String& name); |
|---|
| 729 | |
|---|
| 730 | /** Destroy a RenderQueueInvocationSequence. |
|---|
| 731 | @remarks |
|---|
| 732 | You must ensure that no Viewports are using this sequence. |
|---|
| 733 | @param name The name to identify the sequence |
|---|
| 734 | */ |
|---|
| 735 | void destroyRenderQueueInvocationSequence( |
|---|
| 736 | const String& name); |
|---|
| 737 | |
|---|
| 738 | /** Destroy all RenderQueueInvocationSequences. |
|---|
| 739 | @remarks |
|---|
| 740 | You must ensure that no Viewports are using custom sequences. |
|---|
| 741 | @param name The name to identify the sequence |
|---|
| 742 | */ |
|---|
| 743 | void destroyAllRenderQueueInvocationSequences(void); |
|---|
| 744 | |
|---|
| 745 | /** Override standard Singleton retrieval. |
|---|
| 746 | @remarks |
|---|
| 747 | Why do we do this? Well, it's because the Singleton |
|---|
| 748 | implementation is in a .h file, which means it gets compiled |
|---|
| 749 | into anybody who includes it. This is needed for the |
|---|
| 750 | Singleton template to work, but we actually only want it |
|---|
| 751 | compiled into the implementation of the class based on the |
|---|
| 752 | Singleton, not all of them. If we don't change this, we get |
|---|
| 753 | link errors when trying to use the Singleton-based class from |
|---|
| 754 | an outside dll. |
|---|
| 755 | @par |
|---|
| 756 | This method just delegates to the template version anyway, |
|---|
| 757 | but the implementation stays in this single compilation unit, |
|---|
| 758 | preventing link errors. |
|---|
| 759 | */ |
|---|
| 760 | static Root& getSingleton(void); |
|---|
| 761 | /** Override standard Singleton retrieval. |
|---|
| 762 | @remarks |
|---|
| 763 | Why do we do this? Well, it's because the Singleton |
|---|
| 764 | implementation is in a .h file, which means it gets compiled |
|---|
| 765 | into anybody who includes it. This is needed for the |
|---|
| 766 | Singleton template to work, but we actually only want it |
|---|
| 767 | compiled into the implementation of the class based on the |
|---|
| 768 | Singleton, not all of them. If we don't change this, we get |
|---|
| 769 | link errors when trying to use the Singleton-based class from |
|---|
| 770 | an outside dll. |
|---|
| 771 | @par |
|---|
| 772 | This method just delegates to the template version anyway, |
|---|
| 773 | but the implementation stays in this single compilation unit, |
|---|
| 774 | preventing link errors. |
|---|
| 775 | */ |
|---|
| 776 | static Root* getSingletonPtr(void); |
|---|
| 777 | |
|---|
| 778 | /** Clears the history of all event times. |
|---|
| 779 | @remarks |
|---|
| 780 | OGRE stores a history of the last few event times in order to smooth |
|---|
| 781 | out any inaccuracies and temporary fluctuations. However, if you |
|---|
| 782 | pause or don't render for a little while this can cause a lurch, so |
|---|
| 783 | if you're resuming rendering after a break, call this method to reset |
|---|
| 784 | the stored times |
|---|
| 785 | */ |
|---|
| 786 | void clearEventTimes(void); |
|---|
| 787 | |
|---|
| 788 | /** Sets the period over which OGRE smooths out fluctuations in frame times. |
|---|
| 789 | @remarks |
|---|
| 790 | OGRE by default gives you the raw frame time, but can optionally |
|---|
| 791 | smooths it out over several frames, in order to reduce the |
|---|
| 792 | noticeable effect of occasional hiccups in framerate. |
|---|
| 793 | These smoothed values are passed back as parameters to FrameListener |
|---|
| 794 | calls. |
|---|
| 795 | @par |
|---|
| 796 | This method allow you to tweak the smoothing period, and is expressed |
|---|
| 797 | in seconds. Setting it to 0 will result in completely unsmoothed |
|---|
| 798 | frame times (the default). |
|---|
| 799 | */ |
|---|
| 800 | void setFrameSmoothingPeriod(Real period) { mFrameSmoothingTime = period; } |
|---|
| 801 | /** Gets the period over which OGRE smooths out fluctuations in frame times. */ |
|---|
| 802 | Real getFrameSmoothingPeriod(void) const { return mFrameSmoothingTime; } |
|---|
| 803 | |
|---|
| 804 | /** Register a new MovableObjectFactory which will create new MovableObject |
|---|
| 805 | instances of a particular type, as identified by the getType() method. |
|---|
| 806 | @remarks |
|---|
| 807 | Plugin creators can create subclasses of MovableObjectFactory which |
|---|
| 808 | construct custom subclasses of MovableObject for insertion in the |
|---|
| 809 | scene. This is the primary way that plugins can make custom objects |
|---|
| 810 | available. |
|---|
| 811 | @param fact Pointer to the factory instance |
|---|
| 812 | @param overrideExisting Set this to true to override any existing |
|---|
| 813 | factories which are registered for the same type. You should only |
|---|
| 814 | change this if you are very sure you know what you're doing. |
|---|
| 815 | */ |
|---|
| 816 | void addMovableObjectFactory(MovableObjectFactory* fact, |
|---|
| 817 | bool overrideExisting = false); |
|---|
| 818 | /** Removes a previously registered MovableObjectFactory. |
|---|
| 819 | @remarks |
|---|
| 820 | All instances of objects created by this factory will be destroyed |
|---|
| 821 | before removing the factory (by calling back the factories |
|---|
| 822 | 'destroyInstance' method). The plugin writer is responsible for actually |
|---|
| 823 | destroying the factory. |
|---|
| 824 | */ |
|---|
| 825 | void removeMovableObjectFactory(MovableObjectFactory* fact); |
|---|
| 826 | /// Checks whether a factory is registered for a given MovableObject type |
|---|
| 827 | bool hasMovableObjectFactory(const String& typeName) const; |
|---|
| 828 | /// Get a MovableObjectFactory for the given type |
|---|
| 829 | MovableObjectFactory* getMovableObjectFactory(const String& typeName); |
|---|
| 830 | /** Allocate the next MovableObject type flag. |
|---|
| 831 | @remarks |
|---|
| 832 | This is done automatically if MovableObjectFactory::requestTypeFlags |
|---|
| 833 | returns true; don't call this manually unless you're sure you need to. |
|---|
| 834 | */ |
|---|
| 835 | uint32 _allocateNextMovableObjectTypeFlag(void); |
|---|
| 836 | |
|---|
| 837 | typedef ConstMapIterator<MovableObjectFactoryMap> MovableObjectFactoryIterator; |
|---|
| 838 | /** Return an iterator over all the MovableObjectFactory instances currently |
|---|
| 839 | registered. |
|---|
| 840 | */ |
|---|
| 841 | MovableObjectFactoryIterator getMovableObjectFactoryIterator(void) const; |
|---|
| 842 | }; |
|---|
| 843 | } // Namespace Ogre |
|---|
| 844 | #endif |
|---|