comparison mde/scheduler/initFunctions.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 5132301e9ed7
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 responsible for calling all init functions.
17 *
18 * It is also responsible for setting up all scheduled functions for now.
19
20 * Idea: change import direction so this module adds all init functions. All init functions are
21 * wrapped in another function before being run in a thread (i.e. run indirectly). Functions fail
22 * either by throwing an exception or by returning a boolean. Functions may take parameters, e.g.
23 * "out cleanupFunc[]". */
24 module mde.scheduler.initFunctions;
25
26 /+ unused
27 import tango.util.log.Log : Log, Logger;
28 static this() {
29 logger = Log.getLogger ("mde.scheduler.InitFunctions");
30 }+/
31
32 void setInitFailure () { /// Call to indicate failure in an init function
33 initFailure = true;
34 }
35
36 /** Represents all functions to be called for a particular init stage. */
37 struct InitStage
38 {
39 struct InitFunction {
40 void delegate() func; // the actual function
41 char[] name; // it's name;
42 }
43
44 /** Add a function to be called during this init stage.
45 *
46 * Called in order added when not threaded (reverse order for cleanup).
47 *
48 * Exceptions should never be thrown, since each function may run as a thread, and catching
49 * thread exceptions is not guaranteed to work. Log a message, call setFailure() and return
50 * instead. */
51 void addFunc (void delegate() f, char[] name) {
52 InitFunction s;
53 s.func = f;
54 s.name = name;
55 funcs ~= s;
56 }
57 void addFunc (void function() f, char[] name) { /// ditto
58 InitFunction s;
59 s.func.funcptr = f;
60 s.name = name;
61 funcs ~= s;
62 }
63
64 InitFunction[] funcs = [];
65 }
66
67 InitStage init; // all functions called during init (all should be thread-safe)
68 InitStage cleanup; // all functions called during cleanup (all should be thread-safe)
69
70 package:
71 bool initFailure = false; // set on failure (throwing through threads isn't a good idea)
72
73 private:
74 //Logger logger;