~ubuntu-branches/debian/sid/ember/sid

« back to all changes in this revision

Viewing changes to src/components/ogre/EmberOgre.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2009-07-23 07:46:40 UTC
  • Revision ID: james.westby@ubuntu.com-20090723074640-wh0ukzis0kda36qv
Tags: upstream-0.5.6
ImportĀ upstreamĀ versionĀ 0.5.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
-----------------------------------------------------------------------------
 
3
 
 
4
Author: Erik Hjortsberg <erik.hjortsberg@gmail.com>, (C) 2009
 
5
 
 
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
 
9
version.
 
10
 
 
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.
 
14
 
 
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.
 
19
*/
 
20
 
 
21
#ifndef __EmberOgre_H__
 
22
#define __EmberOgre_H__
 
23
 
 
24
#include "EmberOgrePrerequisites.h"
 
25
 
 
26
// ------------------------------
 
27
// Include sigc header files
 
28
// ------------------------------
 
29
#include <sigc++/trackable.h>
 
30
#include <sigc++/signal.h>
 
31
 
 
32
 
 
33
#include "framework/Singleton.h"
 
34
#include <memory>
 
35
 
 
36
namespace Eris {
 
37
class View;
 
38
class Connection;
 
39
}
 
40
 
 
41
namespace Carpenter
 
42
{
 
43
class Carpenter;
 
44
class BluePrint;
 
45
}
 
46
 
 
47
namespace Ember
 
48
{
 
49
class StreamLogObserver;
 
50
class InputCommandMapper;
 
51
}
 
52
 
 
53
namespace OgreOpcode {
 
54
class CollisionManager;
 
55
}
 
56
 
 
57
namespace EmberOgre {
 
58
 
 
59
namespace Terrain
 
60
{
 
61
class TerrainGenerator;
 
62
class TerrainLayerDefinitionManager;
 
63
}
 
64
 
 
65
class SoundDefinitionManager;
 
66
 
 
67
namespace Model {
 
68
        class ModelDefinitionManager;
 
69
        namespace Mapping {
 
70
                class EmberModelMappingManager;
 
71
        }
 
72
}
 
73
 
 
74
class CameraRotator;
 
75
 
 
76
class CameraFrameListener;
 
77
 
 
78
class Avatar;
 
79
 
 
80
class AvatarCamera;
 
81
 
 
82
class AvatarController;
 
83
 
 
84
class AvatarEmberEntity;
 
85
 
 
86
class EmberEntityFactory;
 
87
 
 
88
class EmberPagingSceneManager;
 
89
 
 
90
class MotionManager;
 
91
 
 
92
class GUIManager;
 
93
 
 
94
class Jesus;
 
95
 
 
96
class EmberEntity;
 
97
 
 
98
class OgreResourceLoader;
 
99
 
 
100
class OgreLogObserver;
 
101
 
 
102
class EntityMoveManager;
 
103
 
 
104
class MaterialEditor;
 
105
 
 
106
class OgreSetup;
 
107
 
 
108
class OgreResourceProvider;
 
109
class OpcodeCollisionDetectorVisualizer;
 
110
 
 
111
class EntityRecipeManager;
 
112
 
 
113
class ShaderManager;
 
114
 
 
115
/**
 
116
        @brief The main class of ember. This functions as a hub for almost all subsystems.
 
117
        
 
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.
 
120
        
 
121
        It's a singleton so you can access it through
 
122
        @code
 
123
        EmberOgre::EmberOgre::getSingleton()
 
124
        @endcode
 
125
        
 
126
        @author Erik Hjortsberg <erik.hjortsberg@gmail.com>
 
127
 
 
128
*/
 
129
class EmberOgre : public Ember::Singleton<EmberOgre>, 
 
130
public sigc::trackable,
 
131
public Ogre::FrameListener
 
132
{
 
133
public:
 
134
 
 
135
 
 
136
    /**
 
137
     * @brief Ctor.
 
138
     */
 
139
    EmberOgre();
 
140
 
 
141
    /**
 
142
     * @brief Dtor.
 
143
     */
 
144
    ~EmberOgre();
 
145
 
 
146
        virtual bool frameStarted(const Ogre::FrameEvent & evt);
 
147
        virtual bool frameEnded(const Ogre::FrameEvent & evt);
 
148
 
 
149
//      void shutdown();
 
150
 
 
151
        /**
 
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.
 
155
         */
 
156
        void initializeEmberServices(const std::string& prefix, const std::string& homeDir);
 
157
 
 
158
 
 
159
 
 
160
 
 
161
        // TODO: possibly we'd like to do the following in a different way,
 
162
        // perhaps refactoring stuff
 
163
        /**
 
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.
 
166
         */
 
167
        Avatar* getAvatar() const;
 
168
        
 
169
        /**
 
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.
 
173
         */
 
174
        Ogre::SceneManager* getSceneManager() const;
 
175
        
 
176
        /**
 
177
         * @brief Gets the terrain generator.
 
178
         * @return The terrain generator, responsible for creating and handling the terrain.
 
179
         */
 
180
        Terrain::TerrainGenerator* getTerrainGenerator() const;
 
181
        
 
182
        /**
 
183
         * @brief Gets the motion manager, which is responsible for handling all motion and animations of entities.
 
184
         * @return The motion manager.
 
185
         */
 
186
        MotionManager* getMotionManager() const;
 
187
        
 
188
        /**
 
189
         * @brief Gets the Ogre root object.
 
190
         * @return The Ogre root object, which acts as an entry point for most of Ogre.
 
191
         */
 
192
        Ogre::Root* getOgreRoot() const;
 
193
        
 
194
        /**
 
195
         * @brief Gets the entity factory which is responsible for creating all new entities in the world.
 
196
         * @return The entity factory.
 
197
         */
 
198
        EmberEntityFactory* getEntityFactory() const;
 
199
        
 
200
        /**
 
201
         * @brief Gets the main camera, which is attached to the Avatar.
 
202
         * @return The main avatar camera.
 
203
         */
 
204
        AvatarCamera* getMainCamera() const;
 
205
        
 
206
        /**
 
207
         * @brief Gets the avatar controller, which recieves input and makes sure that the Avatar is moved.
 
208
         * @return The avatar controller.
 
209
         */
 
210
        AvatarController* getAvatarController() const;
 
211
        
 
212
        /**
 
213
         * @brief Gets the entity move manager, which handles movement of entities in the world by the user.
 
214
         * @return The entity move manager.
 
215
         */
 
216
        EntityMoveManager* getMoveManager() const;
 
217
        
 
218
        /**
 
219
         * @brief Gets the shader manager, which handles setup of the graphic level and the shaders.
 
220
         * @return The shader manager.
 
221
         */
 
222
        ShaderManager* getShaderManager() const;
 
223
        
 
224
        /**
 
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.
 
228
         */
 
229
        EmberEntity* getEmberEntity(const std::string & eid);
 
230
        
 
231
        /**
 
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.
 
234
         */
 
235
        Jesus* getJesus() const;
 
236
        
 
237
        /**
 
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.
 
241
         */
 
242
        Ogre::RenderWindow* getRenderWindow() const;
 
243
        
 
244
        /**
 
245
         * @brief Emitted when the Ember entity factory has been created.
 
246
         */
 
247
        sigc::signal<void, EmberEntityFactory*> EventCreatedEmberEntityFactory;
 
248
        
 
249
        /**
 
250
         * @brief Emitted when the avatar entity has been created.
 
251
         */
 
252
        sigc::signal<void, AvatarEmberEntity*> EventCreatedAvatarEntity;
 
253
        
 
254
        /**
 
255
         * @brief Emitted when the Jesus subsystem has been created.
 
256
         */
 
257
        sigc::signal<void, Jesus*> EventCreatedJesus;
 
258
        
 
259
 
 
260
        /**
 
261
         * @brief Returns the scenenode of the world entity.
 
262
         * Throws en exception if no such node has been created yet.
 
263
         * @return 
 
264
         */
 
265
        Ogre::SceneNode* getWorldSceneNode() const;     
 
266
        
 
267
        /**
 
268
         * @brief Returns the root scene node, to which all other nodes are attached.
 
269
         * @return The Ogre root scene node.
 
270
         */
 
271
        Ogre::SceneNode* getRootSceneNode() const;      
 
272
        
 
273
        /**
 
274
         * @brief Emitted after the GUIManager has been created, but not yet initialized
 
275
         */
 
276
        sigc::signal<void, GUIManager&> EventGUIManagerCreated;
 
277
        
 
278
        /**
 
279
         * @brief Emitted after the GUIManager has been initilized
 
280
         */
 
281
        sigc::signal<void, GUIManager&> EventGUIManagerInitialized;
 
282
        
 
283
        /**
 
284
         * @brief Emitted after the Motion has been created
 
285
         */
 
286
        sigc::signal<void, MotionManager&> EventMotionManagerCreated;
 
287
        
 
288
        
 
289
        /**
 
290
         * @brief Emitted after the TerrainGenerator has been created
 
291
         */
 
292
        sigc::signal<void, Terrain::TerrainGenerator&> EventTerrainGeneratorCreated;
 
293
        
 
294
        /**
 
295
         * @brief Emitted after the AvatarController has been created
 
296
         */
 
297
        sigc::signal<void, AvatarController&> EventAvatarControllerCreated;
 
298
        
 
299
        /**
 
300
         * @brief Emitted after the base Ogre scene has been created
 
301
         */
 
302
        sigc::signal<void> EventSceneCreated;
 
303
        
 
304
        /**
 
305
         * @brief Emitted before the main Ogre render window is rendered.
 
306
         */
 
307
        sigc::signal<void> EventBeforeRender;
 
308
        
 
309
        /**
 
310
         * @brief Emitted after the main Ogre render window is rendered.
 
311
         */
 
312
        sigc::signal<void> EventAfterRender;
 
313
        
 
314
        /**
 
315
         * @brief Renders one frame.
 
316
         * @return True if rendering should continue. False if the application should end.
 
317
         */
 
318
        bool renderOneFrame();
 
319
 
 
320
    /**
 
321
     * @brief Sets up the application - returns false if the user chooses to abandon configuration.
 
322
     * @return 
 
323
     */
 
324
    bool setup();
 
325
    
 
326
    /**
 
327
     * @brief Shuts down the gui.
 
328
     * Call this at closing time, right before you destroy the view and shut down the scripting service.
 
329
     */
 
330
    void shutdownGui();
 
331
 
 
332
protected:
 
333
 
 
334
        /**
 
335
         * @brief Sent from the server service when we've recieved a Eris::View instance from the server.
 
336
         * @param world 
 
337
         */
 
338
        void Server_GotView(Eris::View* world);
 
339
        
 
340
        /**
 
341
         * @brief Sent from the server when we've successfully connected.
 
342
         * @param connection 
 
343
         */
 
344
        void Server_GotConnection(Eris::Connection* connection);
 
345
 
 
346
        /**
 
347
         * @brief Utility object for setting up and tearing down ogre
 
348
         */
 
349
        std::auto_ptr<OgreSetup> mOgreSetup;
 
350
        
 
351
        /**
 
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.
 
355
         */
 
356
        Eris::View* getMainView();
 
357
 
 
358
        /**
 
359
                * @brief The main user avatar
 
360
                */
 
361
        Avatar* mAvatar;
 
362
        
 
363
        /**
 
364
         * @brief When connected to a world, handles the avatar and patches mouse and keyboard movement events on the avatar.
 
365
         */
 
366
        AvatarController* mAvatarController;
 
367
 
 
368
        /**
 
369
         * @brief The main Ogre root object. All of Ogre is accessed through this.
 
370
         */
 
371
        Ogre::Root *mRoot;
 
372
        
 
373
        /**
 
374
         * @brief The main scene manager of the world.
 
375
         */
 
376
        EmberPagingSceneManager* mSceneMgr;
 
377
        
 
378
        /**
 
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).
 
380
         */
 
381
        Ogre::RenderWindow* mWindow;
 
382
 
 
383
        /**
 
384
         * @brief Utility object to configure shaders
 
385
         */
 
386
        std::auto_ptr<ShaderManager> mShaderManager;
 
387
 
 
388
        /**
 
389
         * @brief An InputCommandMapper that will handle all general input events.
 
390
         */
 
391
        std::auto_ptr<Ember::InputCommandMapper> mGeneralCommandMapper;
 
392
 
 
393
        /**
 
394
         * @brief Main factory for all entities created in the world.
 
395
         */
 
396
        EmberEntityFactory* mEmberEntityFactory;
 
397
 
 
398
        /**
 
399
         * @brief Creates the basic scene with a single avatar, just for testing purpose.
 
400
         * NOTE: remove this when going final
 
401
         */
 
402
        void createScene(void);
 
403
        
 
404
        /**
 
405
         * @brief Sets up Jesus. This inialized the mJesus member and loads all building blocks, blueprint and modelblocks etc.
 
406
         */
 
407
        void setupJesus();
 
408
        
 
409
        /**
 
410
         * @brief Preloads the media, thus avoiding frame rate drops ingame.
 
411
         * Note that preloading media can take quite a while.
 
412
         */
 
413
        void preloadMedia();
 
414
 
 
415
        /**
 
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.
 
418
         */
 
419
        void checkForConfigFiles();
 
420
 
 
421
        /**
 
422
         * @brief Responsible for handling of terrain.
 
423
         */
 
424
        Terrain::TerrainGenerator* mTerrainGenerator;
 
425
 
 
426
        /**
 
427
         * @brief Responsible for handling sound loading
 
428
         */
 
429
        SoundDefinitionManager* mSoundManager;
 
430
        
 
431
        /**
 
432
         * @brief Responsible for updating motions and animations of entities.
 
433
         */
 
434
        MotionManager* mMotionManager;
 
435
        
 
436
        /**
 
437
         * @brief Responsible for the GUI.
 
438
         */
 
439
        GUIManager* mGUIManager;  
 
440
        
 
441
        /**
 
442
         * @brief Resonsible for managing all Model definitions;
 
443
         */
 
444
        Model::ModelDefinitionManager* mModelDefinitionManager;
 
445
        
 
446
        /**
 
447
         * @brief Handles all model mappings.
 
448
         */
 
449
        Model::Mapping::EmberModelMappingManager* mModelMappingManager;
 
450
        
 
451
        /**
 
452
         * @brief Responsible for handling all terrain layers.
 
453
         */
 
454
        Terrain::TerrainLayerDefinitionManager* mTerrainLayerManager;
 
455
        
 
456
        /**
 
457
         * @brief Responsible for handling all entity recipes.
 
458
         */
 
459
        EntityRecipeManager* mEntityRecipeManager;
 
460
        
 
461
        /**
 
462
         * @brief Responsible for allowing movement of entities in the world by the user.
 
463
         */
 
464
        EntityMoveManager* mMoveManager;
 
465
        
 
466
        /**
 
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.
 
469
         */
 
470
        Jesus* mJesus;
 
471
        
 
472
        /**
 
473
        The main log observer used for all logging. This will send Ogre logging events on to the internal Ember logging framework.
 
474
        */
 
475
        OgreLogObserver* mLogObserver;
 
476
        
 
477
        /**
 
478
         * @brief Helper object that allows for easy Ogre material editing.
 
479
         */
 
480
        MaterialEditor* mMaterialEditor;
 
481
        
 
482
        /**
 
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.
 
485
         */
 
486
        void Application_ServicesInitialized();
 
487
        
 
488
        std::auto_ptr<OgreResourceProvider> mScriptingResourceProvider;
 
489
        std::auto_ptr<OgreResourceProvider> mSoundResourceProvider;
 
490
        
 
491
        /**
 
492
         * @brief The collision manager, responsible for handling collisions of the geometry in the world.
 
493
         */
 
494
        OgreOpcode::CollisionManager* mCollisionManager;
 
495
        
 
496
        /**
 
497
         * @brief Responsible for visualizing collisions.
 
498
         */
 
499
        OpcodeCollisionDetectorVisualizer* mCollisionDetectorVisualizer;
 
500
        
 
501
        /**
 
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).
 
503
         */
 
504
        OgreResourceLoader* mResourceLoader;
 
505
        
 
506
        /**
 
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.
 
509
         */
 
510
        Ogre::LogManager* mOgreLogManager;
 
511
        
 
512
        /**
 
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.
 
514
         */
 
515
        bool mIsInPausedMode;
 
516
        
 
517
};
 
518
 
 
519
inline EntityMoveManager* EmberOgre::getMoveManager() const 
 
520
{
 
521
        return mMoveManager;
 
522
}
 
523
 
 
524
inline Jesus* EmberOgre::getJesus() const 
 
525
 
526
        return mJesus; 
 
527
}
 
528
inline Ogre::RenderWindow* EmberOgre::getRenderWindow() const 
 
529
 
530
        return mWindow; 
 
531
}
 
532
 
 
533
 
 
534
}
 
535
 
 
536
 
 
537
#endif