12 | | == Getting started == |
13 | | |
14 | | A following code snippet shows you how to start working with the engine. It will initialize the engine singleton and setup basic logging capabilities. |
15 | | |
16 | | {{{ |
17 | | #include <nrEngine/nrEngine.h> |
18 | | |
19 | | void main() |
20 | | { |
21 | | // initialize logging |
22 | | Engine::instance()->initializeLog("log/"); |
23 | | Engine::sLog()->setLevel(Log::LL_WARNING); |
24 | | |
25 | | // initialize essential parts of the engine |
26 | | Engine::instance()->initializeEngine(); |
27 | | |
28 | | |
29 | | .... |
30 | | |
31 | | |
32 | | // release the engine and free memory |
33 | | Engine::release(); |
34 | | } |
35 | | }}} |
36 | | |
37 | | Note: You do not have to initialize logging at all. However this helps to determine errors and to debug the engine integration into your application. I would suggest to enable logging during the development of your software (e.g. with level=LL_DEBUG) and to disable it in the release version. |
38 | | |
39 | | |
40 | | == How to use Kernel/Task subsystem == |
41 | | |
42 | | Most of the games has got a main-loop. During the execution of one cycle of the loop a game engine has to perfrom a lot of tasks, e.g. checking user input, rendering, physic update and so on. [[BR]] |
43 | | nrEngine's Kernel/Task subsystems provides a simple but powerfull interface to manage the main loop. The engine does contains a '''Kernel''' which runs in the background of the engine. A '''Task''' can be bound to the kernel, so that it gets updated every cycle. A task can be any user derived class which has to perform repetitive jobs, e.g. check for user input or stream data from the disk. [[BR]] |
44 | | Moreover a task can get a specific order number or it can depend on another task. Hence the engine does provide a simple graph based task execution system. The functionality of the nrEngine's kernel is similar to the operating system's one, but in a very simple form. [[BR]] |
45 | | And finally a task can be shifted to a thread, so that it executes in parallel to the main application. |
46 | | |
47 | | The following code show you how to use the engine's kernel subsystem for a simple managment of tasks in your application/game: |
48 | | {{{ |
49 | | #include <nrEngine/nrEngine.h> |
50 | | |
51 | | using namespace nrEngine; |
52 | | |
53 | | //! This is a simpel task performing sound output |
54 | | class SoundTask : public ITask |
55 | | { |
56 | | public: |
57 | | |
58 | | SoundTask(); |
59 | | ~SoundTask(); |
60 | | |
61 | | //! This method will be called when the task stops |
62 | | Result stopTask(); |
63 | | |
64 | | //! Task was added to the kernel, so initilize it |
65 | | Result onAddTask(); |
66 | | |
67 | | //! This is called every cycle, so that SoundTask can react on it |
68 | | Result updateTask(); |
69 | | |
70 | | ... |
71 | | }; |
72 | | |
73 | | void main() |
74 | | { |
75 | | // Initialize engine |
76 | | ... |
77 | | |
78 | | |
79 | | // Add the sound task to the kernel with a low order number |
80 | | Engine::sKernel()->AddTask(new SoundTask(), ORDER_LOW); |
81 | | |
82 | | // Executes engine's kernel, hence execute all tasks which are in the kernel |
83 | | // The function returns if there are no more tasks in the kernel (i.e. if all tasks stops) |
84 | | Engine::sKernel()->Execute(); |
85 | | } |
86 | | }}} |
87 | | |