2
-----------------------------------------------------------------------------
4
Author: Erik Hjortsberg <erik.hjortsberg@gmail.com>, (C) 2009
6
This program is free software; you can redistribute it and/or modify it under
7
the terms of the GNU General Public License as published by the Free Software
8
Foundation; either version 2 of the License, or (at your option) any later
11
This program is distributed in the hope that it will be useful, but WITHOUT
12
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License along with
16
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17
Place - Suite 330, Boston, MA 02111-1307, USA, or go to
18
http://www.gnu.org/copyleft/lesser.txt.
21
#ifndef __EmberOgre_H__
22
#define __EmberOgre_H__
24
#include "EmberOgrePrerequisites.h"
26
// ------------------------------
27
// Include sigc header files
28
// ------------------------------
29
#include <sigc++/trackable.h>
30
#include <sigc++/signal.h>
33
#include "framework/Singleton.h"
49
class StreamLogObserver;
50
class InputCommandMapper;
53
namespace OgreOpcode {
54
class CollisionManager;
61
class TerrainGenerator;
62
class TerrainLayerDefinitionManager;
65
class SoundDefinitionManager;
68
class ModelDefinitionManager;
70
class EmberModelMappingManager;
76
class CameraFrameListener;
82
class AvatarController;
84
class AvatarEmberEntity;
86
class EmberEntityFactory;
88
class EmberPagingSceneManager;
98
class OgreResourceLoader;
100
class OgreLogObserver;
102
class EntityMoveManager;
104
class MaterialEditor;
108
class OgreResourceProvider;
109
class OpcodeCollisionDetectorVisualizer;
111
class EntityRecipeManager;
116
@brief The main class of ember. This functions as a hub for almost all subsystems.
118
This is the central class for the whole Ogre related part of Ember. It's quite large and could perhaps be refactored into smaller parts though.
119
It holds references to most subcomponents, and is instanciated at the start of Ember. A lot of different signals from different subsystems are routed through here. If you're not sure how to get access to a certain subsystem from another unrelated class, this is probably the first place you should look.
121
It's a singleton so you can access it through
123
EmberOgre::EmberOgre::getSingleton()
126
@author Erik Hjortsberg <erik.hjortsberg@gmail.com>
129
class EmberOgre : public Ember::Singleton<EmberOgre>,
130
public sigc::trackable,
131
public Ogre::FrameListener
146
virtual bool frameStarted(const Ogre::FrameEvent & evt);
147
virtual bool frameEnded(const Ogre::FrameEvent & evt);
152
* @brief Initialize all Ember services needed for this application
153
* @param the prefix for the application, not appliable if running under win32
154
* @param the an alternative home directory. If the default should be used, send an empty string.
156
void initializeEmberServices(const std::string& prefix, const std::string& homeDir);
161
// TODO: possibly we'd like to do the following in a different way,
162
// perhaps refactoring stuff
164
* @brief Gets the main avatar instance.
165
* @return The main avatar instance. This is currently valid even before the user has logged in to a server, but this will probably change in the future.
167
Avatar* getAvatar() const;
170
* @brief Gets the main scene manager.
171
* There will be many different scene managers created by Ember, but this one is the main one which represents the world.
172
* @return The main scene manager.
174
Ogre::SceneManager* getSceneManager() const;
177
* @brief Gets the terrain generator.
178
* @return The terrain generator, responsible for creating and handling the terrain.
180
Terrain::TerrainGenerator* getTerrainGenerator() const;
183
* @brief Gets the motion manager, which is responsible for handling all motion and animations of entities.
184
* @return The motion manager.
186
MotionManager* getMotionManager() const;
189
* @brief Gets the Ogre root object.
190
* @return The Ogre root object, which acts as an entry point for most of Ogre.
192
Ogre::Root* getOgreRoot() const;
195
* @brief Gets the entity factory which is responsible for creating all new entities in the world.
196
* @return The entity factory.
198
EmberEntityFactory* getEntityFactory() const;
201
* @brief Gets the main camera, which is attached to the Avatar.
202
* @return The main avatar camera.
204
AvatarCamera* getMainCamera() const;
207
* @brief Gets the avatar controller, which recieves input and makes sure that the Avatar is moved.
208
* @return The avatar controller.
210
AvatarController* getAvatarController() const;
213
* @brief Gets the entity move manager, which handles movement of entities in the world by the user.
214
* @return The entity move manager.
216
EntityMoveManager* getMoveManager() const;
219
* @brief Gets the shader manager, which handles setup of the graphic level and the shaders.
220
* @return The shader manager.
222
ShaderManager* getShaderManager() const;
225
* @brief Finds and returns the entity with the given id, if it's available.
226
* @param id The unique id for the entity.
227
* @return An instance of EmberEntity or null if no entity with the specified id could be found.
229
EmberEntity* getEmberEntity(const std::string & eid);
232
* @brief Returns the main Jesus object, which should be used as the main entry into the Jesus subsystem.
233
* @return The main Jesus instance.
235
Jesus* getJesus() const;
238
* @brief Gets the main render window.
239
* The system can contains many different render windows, but there's only one that's the main window.
240
* @return The main render window.
242
Ogre::RenderWindow* getRenderWindow() const;
245
* @brief Emitted when the Ember entity factory has been created.
247
sigc::signal<void, EmberEntityFactory*> EventCreatedEmberEntityFactory;
250
* @brief Emitted when the avatar entity has been created.
252
sigc::signal<void, AvatarEmberEntity*> EventCreatedAvatarEntity;
255
* @brief Emitted when the Jesus subsystem has been created.
257
sigc::signal<void, Jesus*> EventCreatedJesus;
261
* @brief Returns the scenenode of the world entity.
262
* Throws en exception if no such node has been created yet.
265
Ogre::SceneNode* getWorldSceneNode() const;
268
* @brief Returns the root scene node, to which all other nodes are attached.
269
* @return The Ogre root scene node.
271
Ogre::SceneNode* getRootSceneNode() const;
274
* @brief Emitted after the GUIManager has been created, but not yet initialized
276
sigc::signal<void, GUIManager&> EventGUIManagerCreated;
279
* @brief Emitted after the GUIManager has been initilized
281
sigc::signal<void, GUIManager&> EventGUIManagerInitialized;
284
* @brief Emitted after the Motion has been created
286
sigc::signal<void, MotionManager&> EventMotionManagerCreated;
290
* @brief Emitted after the TerrainGenerator has been created
292
sigc::signal<void, Terrain::TerrainGenerator&> EventTerrainGeneratorCreated;
295
* @brief Emitted after the AvatarController has been created
297
sigc::signal<void, AvatarController&> EventAvatarControllerCreated;
300
* @brief Emitted after the base Ogre scene has been created
302
sigc::signal<void> EventSceneCreated;
305
* @brief Emitted before the main Ogre render window is rendered.
307
sigc::signal<void> EventBeforeRender;
310
* @brief Emitted after the main Ogre render window is rendered.
312
sigc::signal<void> EventAfterRender;
315
* @brief Renders one frame.
316
* @return True if rendering should continue. False if the application should end.
318
bool renderOneFrame();
321
* @brief Sets up the application - returns false if the user chooses to abandon configuration.
327
* @brief Shuts down the gui.
328
* Call this at closing time, right before you destroy the view and shut down the scripting service.
335
* @brief Sent from the server service when we've recieved a Eris::View instance from the server.
338
void Server_GotView(Eris::View* world);
341
* @brief Sent from the server when we've successfully connected.
344
void Server_GotConnection(Eris::Connection* connection);
347
* @brief Utility object for setting up and tearing down ogre
349
std::auto_ptr<OgreSetup> mOgreSetup;
352
* @brief Gets the main Eris View instance, which is the main inteface to the world.
353
* The View can also be accessed through the Server service, but this can be used for convenience.
354
* @return The main Eris View instance which represents the server world.
356
Eris::View* getMainView();
359
* @brief The main user avatar
364
* @brief When connected to a world, handles the avatar and patches mouse and keyboard movement events on the avatar.
366
AvatarController* mAvatarController;
369
* @brief The main Ogre root object. All of Ogre is accessed through this.
374
* @brief The main scene manager of the world.
376
EmberPagingSceneManager* mSceneMgr;
379
* @brief The main render window. There can be many more render targets in the system, but they will all reside within this render window (such as entity preview through CEGUI).
381
Ogre::RenderWindow* mWindow;
384
* @brief Utility object to configure shaders
386
std::auto_ptr<ShaderManager> mShaderManager;
389
* @brief An InputCommandMapper that will handle all general input events.
391
std::auto_ptr<Ember::InputCommandMapper> mGeneralCommandMapper;
394
* @brief Main factory for all entities created in the world.
396
EmberEntityFactory* mEmberEntityFactory;
399
* @brief Creates the basic scene with a single avatar, just for testing purpose.
400
* NOTE: remove this when going final
402
void createScene(void);
405
* @brief Sets up Jesus. This inialized the mJesus member and loads all building blocks, blueprint and modelblocks etc.
410
* @brief Preloads the media, thus avoiding frame rate drops ingame.
411
* Note that preloading media can take quite a while.
416
* @brief Makes sure that there are files in ~/.ember.
417
* Call this early on at application startup. If the required files cannot be found they are copied there from their default versions as installed in the shared location.
419
void checkForConfigFiles();
422
* @brief Responsible for handling of terrain.
424
Terrain::TerrainGenerator* mTerrainGenerator;
427
* @brief Responsible for handling sound loading
429
SoundDefinitionManager* mSoundManager;
432
* @brief Responsible for updating motions and animations of entities.
434
MotionManager* mMotionManager;
437
* @brief Responsible for the GUI.
439
GUIManager* mGUIManager;
442
* @brief Resonsible for managing all Model definitions;
444
Model::ModelDefinitionManager* mModelDefinitionManager;
447
* @brief Handles all model mappings.
449
Model::Mapping::EmberModelMappingManager* mModelMappingManager;
452
* @brief Responsible for handling all terrain layers.
454
Terrain::TerrainLayerDefinitionManager* mTerrainLayerManager;
457
* @brief Responsible for handling all entity recipes.
459
EntityRecipeManager* mEntityRecipeManager;
462
* @brief Responsible for allowing movement of entities in the world by the user.
464
EntityMoveManager* mMoveManager;
467
* @brief Main entry point for the Jesus system (which is an Ember wrapper for the Carpenter lib)
468
* @note The Jesus and Carpenter system hasn't been touched in quite a while, and it's not certain that it will remain in Ember.
473
The main log observer used for all logging. This will send Ogre logging events on to the internal Ember logging framework.
475
OgreLogObserver* mLogObserver;
478
* @brief Helper object that allows for easy Ogre material editing.
480
MaterialEditor* mMaterialEditor;
483
* @brief Listen for when all of the application services has been initialized and then register needed objects with them.
484
* This should occur fairly early on in the application life cycle.
486
void Application_ServicesInitialized();
488
std::auto_ptr<OgreResourceProvider> mScriptingResourceProvider;
489
std::auto_ptr<OgreResourceProvider> mSoundResourceProvider;
492
* @brief The collision manager, responsible for handling collisions of the geometry in the world.
494
OgreOpcode::CollisionManager* mCollisionManager;
497
* @brief Responsible for visualizing collisions.
499
OpcodeCollisionDetectorVisualizer* mCollisionDetectorVisualizer;
502
*@brief Handles loading of resources. This will also take care of registering our own Ogre::ArchiveFactory instance, so it needs to be destroyed first after ogre is shutdown (since there's no way to remove an already added ArchiveFactory instance from Ogre).
504
OgreResourceLoader* mResourceLoader;
507
* @brief We hold a reference to our own Ogre log manager, thus making sure that Ogre doesn't create one itself.
508
* Since we do this we can better steer how Ogre log messages are handled.
510
Ogre::LogManager* mOgreLogManager;
513
* @brief Set this to true when we're not rendering. The reason is that later on, when we resume rendering, we need to reset the event times to prevent various particle effect strangeness.
515
bool mIsInPausedMode;
519
inline EntityMoveManager* EmberOgre::getMoveManager() const
524
inline Jesus* EmberOgre::getJesus() const
528
inline Ogre::RenderWindow* EmberOgre::getRenderWindow() const