blob: eec250e506463a969debe42b11b365c7491506e1 (
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
116
117
118
119
120
121
122
123
124
125
126
127
|
/*
core/module.cc
This file is part of the Osirion project and is distributed under
the terms of the GNU General Public License version 2
*/
#include "auxiliary/functions.h"
#include "core/module.h"
#include "sys/sys.h"
namespace core
{
/*-- static functions ----------------------------------------------*/
Module *Module::module_preload = 0;
Module *Module::module_active = 0;
Module::Registry Module::module_registry;
Module *Module::find(const std::string &label)
{
Registry::iterator it = module_registry.find(label);
if (it == module_registry.end())
return 0;
else
return (*it).second;
}
Module *Module::find(const char *label)
{
return(find(std::string(label)));
}
Module *Module::add(Module *module)
{
Module *m = find(module->label());
if (m) {
con_warn << "module '" << module->label() << "' already registered!" << std::endl;
delete module;
return 0;
}
module_registry[module->label()] = module;
if (!module_preload) {
module_preload = module;
}
con_debug << " " << module->label() << " " << module->name() << std::endl;
return module;
}
Module *Module::load(const char *label)
{
if (!label)
return 0;
Module *module = find(label);
if (!module) {
con_warn << "Could not find module '" << label << "'" << std::endl;
return 0;
}
con_print << " module " << module->label() << " " << module->name() << std::endl;
module_preload = module;
return module;
}
void Module::clear()
{
for (Registry::iterator it = module_registry.begin(); it != module_registry.end(); it++) {
Module *module = (*it).second;
con_print << " " << module->label() << " " << module->name() << std::endl;
}
module_registry.clear();
module_preload = 0;
}
void Module::list()
{
for (Registry::iterator it = module_registry.begin(); it != module_registry.end(); it++) {
Module *module = (*it).second;
con_print << " " << module->label() << " " << module->name() << std::endl;
}
con_print << module_registry.size() << " registered game " << aux::plural("modules", module_registry.size()) << std::endl;
}
/*-- instance functions --------------------------------------------*/
Module::Module(const char *label, const char *name, bool interactive) :
module_label(label), module_name(name)
{
module_running = false;
module_interactive = interactive;
}
Module::~Module()
{
module_running = false;
module_name.clear();
}
void Module::run()
{
module_active = this;
module_running = true;
init();
}
void Module::terminate()
{
shutdown();
module_running = false;
module_active = 0;
}
void Module::abort()
{
module_running = false;
module_active = 0;
}
}
|