]> Dogcows Code - chaz/yoink/blob - src/Moof/Core.hh
reformatting
[chaz/yoink] / src / Moof / Core.hh
1
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
4 *
5 * vi:ts=4 sw=4 tw=75
6 *
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
9 *
10 **************************************************************************/
11
12 #ifndef _MOOF_CORE_HH_
13 #define _MOOF_CORE_HH_
14
15 #include <string>
16
17 #include <boost/shared_ptr.hpp>
18
19 #include <Moof/Dispatch.hh>
20 #include <Moof/Error.hh>
21 #include <Moof/Layer.hh>
22
23
24 namespace Mf {
25
26
27 /**
28 * The core is essentially a stack of layers. While running, it updates
29 * each layer from the bottom up every timestep. It also draws each layer
30 * from the bottom up, adhering to the maximum frame-rate. Events are sent
31 * to each layer from the top down until a layer signals the event was
32 * handled. The core is also responsible for firing timers on time. The
33 * core will continue running as long as there are layers on the stack.
34 */
35
36 class Core
37 {
38 public:
39
40 Core();
41
42 // loads settings: rngseed, timestep, framerate, showfps
43 void init();
44
45 int getFps() const;
46
47 void push(LayerP layer); // push a layer onto the top
48 LayerP pop(); // pop the top layer
49 LayerP pop(Layer* layer); // pops a specific layer and layers above it
50 void clear(); // remove all layers (the core will stop)
51
52 int getSize() const; // get the size of the stack
53
54 // set this machine in motion
55 void run();
56
57 Dispatch::Handler addHandler(const std::string& event,
58 const Dispatch::Function& callback);
59 Dispatch::Handler addHandler(const std::string& event,
60 const Dispatch::Function& callback,
61 Dispatch::Handler handler);
62
63 void dispatch(const std::string& event,
64 const Dispatch::Message* message = 0);
65
66 private:
67
68 class Impl;
69 boost::shared_ptr<Impl> mImpl;
70 };
71
72 extern Core core;
73
74
75 /*
76 * Some classes and subsystems require certain backend libraries to be
77 * initialized. This is the mechanism to accomplish that. Classes which
78 * rely on any backend libraries just need to instantiate this class as a
79 * member. Backend cleanup will occur automagically when there are no more
80 * instances.
81 */
82
83 class Backend
84 {
85 public:
86
87 Backend();
88 ~Backend();
89
90 static bool isInitialized();
91 static const Error& getError();
92 };
93
94
95 } // namespace Mf
96
97 #endif // _MOOF_CORE_HH_
98
This page took 0.035429 seconds and 4 git commands to generate.