comparison mde/scheduler/init2.d @ 32:316b0230a849

Lots more work on the GUI. Also renamed lots of files. Lots of changes to the GUI. Renderer is now used exclusively for rendering and WidgetDecoration is gone. Renamed lots of files to conform to case policies. committer: Diggory Hardy <diggory.hardy@gmail.com>
author Diggory Hardy <diggory.hardy@gmail.com>
date Wed, 30 Apr 2008 18:05:56 +0100
parents
children 6886402c1545
comparison
equal deleted inserted replaced
31:baa87e68d7dc 32:316b0230a849
1 /* LICENSE BLOCK
2 Part of mde: a Modular D game-oriented Engine
3 Copyright © 2007-2008 Diggory Hardy
4
5 This program is free software: you can redistribute it and/or modify it under the terms
6 of the GNU General Public License as published by the Free Software Foundation, either
7 version 2 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 See the GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */
15
16 /** This module is the start of implementing the following:
17 *
18 * Idea: change import direction so this module adds all init functions. All init functions are
19 * wrapped in another function before being run in a thread (i.e. run indirectly). Functions fail
20 * either by throwing an exception or by returning a boolean. Functions may take parameters, e.g.
21 * "out cleanupFunc[]".
22 *
23 * This should make it much easier to tell what actually happens during init and to order init such
24 * that dependencies are honoured.
25 *
26 * Currently some external modules depend on InitFunctions, while some are set up from here. Once
27 * all are set up from here, the Init* modules can be rearranged. */
28 module mde.scheduler.init2;
29
30 import mde.scheduler.initFunctions;
31
32 import tango.util.log.Log : Log, Logger;
33
34 // Modules requiring init code running:
35 import global = mde.global;
36 import mde.gui.Gui;
37 import mde.input.Input;
38
39 // NOTE: error reporting needs revision
40
41 private Logger logger;
42 static this () {
43 logger = Log.getLogger ("mde.scheduler.Init2");
44
45 init.addFunc (&initInput, "initInput");
46 init.addFunc (&guiLoad, "guiLoad");
47 }
48
49 void guiLoad () {
50 try {
51 gui.load ("gui");
52 } catch (Exception e) {
53 logger.fatal ("guiLoad failed: " ~ e.msg);
54 setInitFailure;
55 }
56 }
57
58 void initInput () { // init func
59 try {
60 global.input = new Input();
61 global.input.loadConfig (); // (may also create instance)
62
63 // Quit on escape. NOTE: quit via SDL_QUIT event is handled completely independently!
64 global.input.addButtonCallback (cast(Input.inputID) 0x0u, delegate void(Input.inputID i, bool b) {
65 if (b) {
66 logger.info ("Quiting...");
67 global.run = false;
68 }
69 } );
70 global.input.addMouseClickCallback(&gui.clickEvent);
71 } catch (Exception e) {
72 logger.fatal ("initInput failed: " ~ e.msg);
73 setInitFailure;
74 }
75 }
76
77 /+ Potential wrapper function:
78 // Template to call function, catching exceptions:
79 void wrap(alias Func) () {
80 try {
81 Func();
82 } catch (Exception e) {
83 logger.fatal (FAIL_MSG);
84 logger.fatal (e.msg);
85 setInitFailure;
86 }
87 }
88 private const FAIL_MSG = "Unexpected exception caught:";
89 +/