source: nrEngine/include/Engine.h @ 12

Revision 12, 6.6 KB checked in by art, 13 years ago (diff)
  • Friendly thread execution added (yielding of threads and main thread)
  • Test directory added, where simple test programms will be build
  • Each Makefile now contains the TOPDIR variable
Line 
1/***************************************************************************
2 *                                                                         *
3 *   (c) Art Tevs, MPI Informatik Saarbruecken                             *
4 *       mailto: <tevs@mpi-sb.mpg.de>                                      *
5 *                                                                         *
6 *   This program is free software; you can redistribute it and/or modify  *
7 *   it under the terms of the GNU General Public License as published by  *
8 *   the Free Software Foundation; either version 2 of the License, or     *
9 *   (at your option) any later version.                                   *
10 *                                                                         *
11 ***************************************************************************/
12
13#ifndef __NR_ENGINE_CORE_H_
14#define __NR_ENGINE_CORE_H_
15
16
17//----------------------------------------------------------------------------------
18// Includes
19//----------------------------------------------------------------------------------
20#include "Prerequisities.h"
21#include "Log.h"
22
23namespace nrEngine{
24
25        //! Core class of the engine. Used to create subsystems.
26        /**
27        * This is our main class representing the engine itself. This class is
28        * able to create and initialize particular elements of the engine's core.
29        * So before you can use the engine you have to create an instance
30        * of this class.
31        *
32        * The engine's core class is a singleton. We also store all subsystems as
33        * static, to be sure that they exists also only once in memory.
34        *
35        * \ingroup engine
36        **/
37        class _NRExport Engine{
38                public:
39
40                        /**
41                        * Initialize the log component of the engine. You have to call
42                        * this function before you get using of engine's components. They all
43                        * will log their work information to appropriate log files, so the log
44                        * part of the engie has to be initialized before.<br>
45                        * If you do not initilaize the logging functionality, so no log
46                        * files will be written. No error will occurs.
47                        *
48                        * \param logPath Under this directory all log files will be created
49                        * \return false if error occurs or true otherwise
50                        **/
51                        bool initializeLog(const std::string& logPath);
52
53                        /**
54                        * Release the engine and all used memory. The call of this function
55                        * will immidiately stop all kernel tasks and will stop the engine.<br>
56                        * Call this function if you want to quit the engine.
57                        **/
58                        void stopEngine();
59
60                        /**
61                        * "Gentlemans, start your engines!" - This is the entry point for
62                        * your application to start the engine. Starting of the engine will
63                        * also start a kernel, which is running system + application tasks.
64                        * If no more tasks is active, the kernel will be shutted down and engine
65                        * will stop.
66                        **/
67                        void runEngine();
68
69                        /**
70                        * If you do not want to run the engine in their own loop (\a startEngine() )
71                        * you can update the engine through this function. This function should be
72                        * called each frame. This will update the kernel tasks and all engine's
73                        * subsystems
74                        **/
75                        void updateEngine();
76
77                        /**
78                        * This method will initialize all engine's subsystems, that are essential
79                        * for engine's work. Please call this function after you have intialized
80                        * the logging, because there will be a lot of log information.
81                        *
82                        * \return true if all intialization are succeed, or false otherwise
83                        **/
84                        bool initializeEngine();
85
86                        /**
87                         * Load a certain plugin directly into the engine. The plugin will
88                         * be loaded and the initialize subroutine will be called. If the plugin
89                         * returns an invalid resulting code, so the plugin will be unloaded again.
90                         *
91                         * Use this function to load certain plugins needed for your application
92                         * (i.e. ScriptLoader) and let them run with certain parameters, so you are
93                         * able to use the engine as you need.
94                         *
95                         * @param path Path where the plugin can be founded
96                         * @param file Filename relative to the path of the plugin
97                         * @param name Name which will be then used to access the plugin later
98                         *
99                         * @return false if an error occurs
100                         *
101                         * NOTE: Check log files for more detailed error description
102                         **/
103                        bool loadPlugin(const std::string& path, const std::string& file, const std::string& name);
104
105
106                        /**
107                        * Get a pointer to a log subsystem of the engine.
108                        * The pointer is always not equal to NULL. By initializing of
109                        * the log subsystem you just setup the log target.
110                        * So you can always log to the log-system without checking
111                        * whenever pointer is valid or not.
112                        **/
113                        static Log* sLog();
114
115                        /**
116                        * Return a pointer to the kernel subsystem of the engine. Our kernel
117                        * is normaly a singleton, so you can access to it, without this method.
118                        *
119                        * Returned pointer is always valid.
120                        * @see Kernel
121                        **/
122                        static Kernel* sKernel();
123
124                        /**
125                        * Return a pointer to the underlying clock of the engine. The clock
126                        * is a singleton, so you can access it on another way.
127                        *
128                        * Returned pointer is always valid
129                        * @see Clock
130                        **/
131                        static Clock* sClock();
132
133                        /**
134                        * Returns a pointer to the profiler object. The profiler
135                        * is used to mess the time of execution
136                        **/
137                        static Profiler* sProfiler();
138                       
139                        /**
140                        * Returns a pointer to the ressource manager object.
141                        **/
142                        static ResourceManager* sResourceManager() ;
143                       
144                        /**
145                        * Return an instance of the event manager class
146                        **/
147                        static EventManager* sEventManager();
148                       
149                        /**
150                        * Get a pointer to the scripting engine interface
151                        **/
152                        static ScriptEngine* sScriptEngine();
153
154                        /**
155                         * Get the singleton instance. Passing the parameter specify
156                         * if the instance should be released
157                         **/
158                        static Engine* instance(bool release = false);
159
160                        /**
161                         * Get the pointer to the instance of the engine
162                         **/
163                        static Engine* sEngine() { return instance(); }
164                       
165                         /**
166                         * Check whenever the engine'S singleton was created before
167                         **/
168                        static bool valid(void* p = sSingleton.get(), char* name = "Engine", bool showWarn = true);
169                         
170                        /**
171                         * Release the singleton object
172                         **/
173                        static void release();
174
175                        /**
176                        * Delete the core object and try to deinitialize and to delete
177                        * all subcomponents of the engine
178                        **/
179                        ~Engine();
180
181                private:
182
183                        /**
184                        * Create an instance of the engine's core object. The constructor
185                        * is private, so you only can create instances through instance() method
186                        **/
187                        Engine();
188
189                        static Log*                     _logger;
190                        static Kernel*          _kernel;
191                        static Clock*           _clock;
192                        static Profiler*        _profiler;
193                        static ResourceManager* _resmgr;
194                        static ScriptEngine* _script;
195                        static EventManager* _event;
196                       
197                        //! Store pointer to the engine's core singleton object
198                        static SharedPtr<Engine> sSingleton;
199                       
200        };
201
202}; // end namespace
203
204
205#endif
Note: See TracBrowser for help on using the repository browser.