15 |
GNU General Public License for more details. |
GNU General Public License for more details. |
16 |
|
|
17 |
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License |
18 |
along with Adonthell; if not, write to the Free Software |
along with Adonthell; if not, write to the Free Software |
19 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20 |
*/ |
*/ |
21 |
|
|
23 |
/** |
/** |
24 |
* @file main/adonthell.cc |
* @file main/adonthell.cc |
25 |
* @author Kai Sterker <kaisterker@linuxgames.com> |
* @author Kai Sterker <kaisterker@linuxgames.com> |
26 |
* |
* |
27 |
* @brief The main application class for programs using the Adonthell framework. |
* @brief The main application class for programs using the Adonthell framework. |
28 |
*/ |
*/ |
29 |
|
|
47 |
|
|
48 |
/// The handler of our library file. |
/// The handler of our library file. |
49 |
static lt_dlhandle dlhandle = 0; |
static lt_dlhandle dlhandle = 0; |
50 |
|
|
51 |
/// pointer to method with backend/platform specific intialization code. |
/// pointer to method with backend/platform specific intialization code. |
52 |
static bool (*init_p)(adonthell::app* application) = 0; |
static bool (*init_p)(adonthell::app* application) = 0; |
53 |
|
|
58 |
lt_dlexit (); |
lt_dlexit (); |
59 |
} |
} |
60 |
|
|
61 |
// initialize engine subsystems |
// initialize engine subsystems |
62 |
bool app::init_modules (const u_int16 & modules) |
bool app::init_modules (const u_int16 & modules) |
63 |
{ |
{ |
64 |
// don't initialize previously loaded modules |
// don't initialize previously loaded modules |
65 |
u_int16 m = Modules ^ modules; |
u_int16 m = Modules ^ modules; |
66 |
Modules |= m; |
Modules |= m; |
67 |
|
|
68 |
// startup python |
// startup python |
69 |
if (m & PYTHON) |
if (m & PYTHON) |
70 |
{ |
{ |
86 |
{ |
{ |
87 |
if (!gfx::init (Backend)) return false; |
if (!gfx::init (Backend)) return false; |
88 |
} |
} |
89 |
|
|
90 |
// startup input |
// startup input |
91 |
if (m & INPUT) |
if (m & INPUT) |
92 |
{ |
{ |
93 |
if (!input::init (Backend)) return false; |
if (!input::init (Backend)) return false; |
94 |
} |
} |
95 |
|
|
96 |
// startup event system |
// startup event system |
97 |
if (m & EVENT) |
if (m & EVENT) |
98 |
{ |
{ |
99 |
event::manager::init (); |
events::manager::init (); |
100 |
} |
} |
101 |
|
|
102 |
return true; |
return true; |
103 |
} |
} |
104 |
|
|
106 |
void app::parse_args (int & argc, char *argv[]) |
void app::parse_args (int & argc, char *argv[]) |
107 |
{ |
{ |
108 |
int c; |
int c; |
109 |
|
|
110 |
Argc = argc; |
Argc = argc; |
111 |
Argv = argv; |
Argv = argv; |
112 |
|
|
117 |
|
|
118 |
// Check for options |
// Check for options |
119 |
while ((c = getopt (argc, argv, "b:c:g:hv")) != -1) |
while ((c = getopt (argc, argv, "b:c:g:hv")) != -1) |
120 |
{ |
{ |
121 |
switch (c) |
switch (c) |
122 |
{ |
{ |
123 |
// backend: |
// backend: |
124 |
case 'b': |
case 'b': |
125 |
Backend = optarg; |
Backend = optarg; |
146 |
break; |
break; |
147 |
} |
} |
148 |
} |
} |
149 |
|
|
150 |
// check whether the GAME parameter is given |
// check whether the GAME parameter is given |
151 |
if (argc - optind == 1) |
if (argc - optind == 1) |
152 |
{ |
{ |
159 |
{ |
{ |
160 |
Modules = 0; |
Modules = 0; |
161 |
dlhandle = NULL; |
dlhandle = NULL; |
162 |
|
|
163 |
// init libltdl |
// init libltdl |
164 |
if (lt_dlinit ()) |
if (lt_dlinit ()) |
165 |
{ |
{ |
166 |
cerr << lt_dlerror() << endl; |
cerr << lt_dlerror() << endl; |
167 |
cerr << "Error initializing liblt!" << endl; |
cerr << "Error initializing liblt!" << endl; |
168 |
return false; |
return false; |
169 |
} |
} |
170 |
|
|
171 |
// init base module (required for reading config file) |
// init base module (required for reading config file) |
172 |
base::init (Userdatadir, Game); |
base::init (Userdatadir, Game); |
173 |
|
|
174 |
// load configuration file |
// load configuration file |
175 |
if (!Cfg.read (Config)) |
if (!Cfg.read (Config)) |
176 |
{ |
{ |
177 |
// print message if that fails, but don't panic yet ... |
// print message if that fails, but don't panic yet ... |
178 |
cerr << "Error reading configuration '" << Config << ".xml'" << endl; |
cerr << "Error reading configuration '" << Config << ".xml'" << endl; |
179 |
} |
} |
180 |
|
|
181 |
// if we have been given no backend on the command line, |
// if we have been given no backend on the command line, |
182 |
// try to get it from config file; fallback to sdl if that fails |
// try to get it from config file; fallback to sdl if that fails |
183 |
if (Backend == "") |
if (Backend == "") |
184 |
{ |
{ |
186 |
// set type of config option (free form text entry) |
// set type of config option (free form text entry) |
187 |
Cfg.option ("General", "Backend", base::cfg_option::FREE); |
Cfg.option ("General", "Backend", base::cfg_option::FREE); |
188 |
} |
} |
189 |
|
|
190 |
// load backend init module |
// load backend init module |
191 |
dlhandle = base::get_module (string ("/main/") + Backend); |
dlhandle = base::get_module (string ("/main/") + Backend); |
192 |
if (!dlhandle) |
if (!dlhandle) |
194 |
cerr << lt_dlerror() << endl; |
cerr << lt_dlerror() << endl; |
195 |
return false; |
return false; |
196 |
} |
} |
197 |
|
|
198 |
// get pointer to init method |
// get pointer to init method |
199 |
init_p = (bool (*)(app*)) lt_dlsym (dlhandle, "main_init"); |
init_p = (bool (*)(app*)) lt_dlsym (dlhandle, "main_init"); |
200 |
if (!init_p) |
if (!init_p) |
202 |
cerr << lt_dlerror() << endl; |
cerr << lt_dlerror() << endl; |
203 |
return false; |
return false; |
204 |
} |
} |
205 |
|
|
206 |
// platform / backend specific initialization |
// platform / backend specific initialization |
207 |
return init_p (this); |
return init_p (this); |
208 |
} |
} |
214 |
Cfg.write (Config); |
Cfg.write (Config); |
215 |
|
|
216 |
// cleanup modules |
// cleanup modules |
217 |
if (Modules & EVENT) event::manager::cleanup (); |
if (Modules & EVENT) events::manager::cleanup (); |
218 |
if (Modules & INPUT) input::cleanup (); |
if (Modules & INPUT) input::cleanup (); |
219 |
if (Modules & GFX) gfx::cleanup (); |
if (Modules & GFX) gfx::cleanup (); |
220 |
if (Modules & PYTHON) python::cleanup (); |
if (Modules & PYTHON) python::cleanup (); |