Mercurial > projects > mde
comparison mde/setup/initFunctions.d @ 63:66d555da083e
Moved many modules/packages to better reflect usage.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Fri, 27 Jun 2008 18:35:33 +0100 |
parents | mde/scheduler/initFunctions.d@5132301e9ed7 |
children |
comparison
equal
deleted
inserted
replaced
62:960206198cbd | 63:66d555da083e |
---|---|
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.setup.initFunctions; | |
25 | |
26 /+ unused | |
27 import tango.util.log.Log : Log, Logger; | |
28 static this() { | |
29 logger = Log.getLogger ("mde.setup.initFunctions"); | |
30 } | |
31 private Logger logger; | |
32 +/ | |
33 | |
34 void setInitFailure () { /// Call to indicate failure in an init function | |
35 initFailure = true; | |
36 } | |
37 | |
38 /** Represents all functions to be called for a particular init stage. */ | |
39 struct InitStage | |
40 { | |
41 struct InitFunction { | |
42 void delegate() func; // the actual function | |
43 char[] name; // it's name; | |
44 } | |
45 | |
46 /** Add a function to be called during this init stage. | |
47 * | |
48 * Called in order added when not threaded (reverse order for cleanup). | |
49 * | |
50 * Exceptions should never be thrown, since each function may run as a thread, and catching | |
51 * thread exceptions is not guaranteed to work. Log a message, call setFailure() and return | |
52 * instead. */ | |
53 void addFunc (void delegate() f, char[] name) { | |
54 InitFunction s; | |
55 s.func = f; | |
56 s.name = name; | |
57 funcs ~= s; | |
58 } | |
59 void addFunc (void function() f, char[] name) { /// ditto | |
60 InitFunction s; | |
61 s.func.funcptr = f; | |
62 s.name = name; | |
63 funcs ~= s; | |
64 } | |
65 | |
66 InitFunction[] funcs = []; | |
67 } | |
68 | |
69 InitStage init; // all functions called during init (all should be thread-safe) | |
70 //FIXME: implement: | |
71 InitStage save; // all functions to be called to save data (possible to run more than once) | |
72 InitStage cleanup; // all functions called during cleanup (all should be thread-safe) | |
73 | |
74 package: | |
75 bool initFailure = false; // set on failure (throwing through threads isn't a good idea) |