blob: 64b41bd44b2acdeb784e140dc1809e95ca5241b3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
/*
core/module.h
This file is part of the Osirion project and is distributed under
the terms of the GNU General Public License version 2
*/
#ifndef __INCLUDED_CORE_MODULE_H__
#define __INCLUDED_CORE_MODULE_H__
#include <string>
#include "core/player.h"
namespace core
{
// a loadable game module
class Module
{
public:
Module(const char *label, const char *name, bool interactive=true);
virtual ~Module();
/*----- inspectors ------------------------------------------------ */
/// return true if the game module can run a timeframe
inline bool running() const { return module_running; }
/// return true if the game module can not run a timeframe
inline bool error() const { return !module_running; }
/// label of the module
inline std::string const & label() const { return module_label; }
/// return the name of the module
inline std::string const & name() const { return module_name; }
/// indicates if this is an interactive module or not
inline bool interactive() const { return module_interactive; }
/*----- mutators -------------------------------------------------- */
/// run the game module
void run();
/// terminate a running game module
void terminate();
/// run one timeframe
virtual void frame(float seconds) = 0;
/// is called when a player connects
virtual void player_connect(Player *player) = 0;
/// is called when a player disconnects
virtual void player_disconnect(Player *player) = 0;
/*----- static ---------------------------------------------------- */
typedef std::map<std::string, Module *> Registry;
/// find a registered game module
static Module *find(const char *label);
/// find a registered game module
static Module *find(const std::string &label);
/// register a game module
static Module *add(Module *module);
/// load a registered game module
static Module *load(const char *label);
/// list modules
static void list();
/// unload all modules
static void clear();
/// currently active module
static inline Module *active() { return module_active; }
/// currently loaded module
static inline Module *loaded() { return module_preload; }
/// module registry
static inline Registry & registry() { return module_registry; }
protected:
/// initialize the game module
virtual void init() = 0;
/// shutdown the game module
virtual void shutdown() = 0;
/// abort a running module
void abort();
private:
bool module_interactive;
bool module_running;
std::string module_label;
std::string module_name;
static Registry module_registry;
static Module *module_preload;
static Module *module_active;
};
}
#endif // __INCLUDED_CORE_MODULE_H__
|