Mercurial > projects > mde
comparison mde/scheduler/InitStage.d @ 20:838577503598
Reworked much of Init.
Moved mde.Init to mde.scheduler.Init and largely cleaned up the code.
Implemented mde.scheduler.InitStage to reduce dependancies of modules running Init functions.
committer: Diggory Hardy <diggory.hardy@gmail.com>
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Sat, 22 Mar 2008 16:22:59 +0000 |
parents | |
children | a60cbb7359dd |
comparison
equal
deleted
inserted
replaced
19:db0b48f02b69 | 20:838577503598 |
---|---|
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 of | |
6 the GNU General Public License, version 2, as published by the Free Software Foundation. | |
7 | |
8 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | |
9 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
10 See the GNU General Public License for more details. | |
11 | |
12 You should have received a copy of the GNU General Public License along | |
13 with this program; if not, write to the Free Software Foundation, Inc., | |
14 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ | |
15 | |
16 /** This module is used to create a list of all functions required to run for initialisation and | |
17 * cleanup. | |
18 * | |
19 * It has been separated out of Init.d to massively reduce dependancies of modules adding init | |
20 * functions. | |
21 */ | |
22 module mde.scheduler.InitStage; | |
23 | |
24 /** Represents all functions to be called for a particular init stage. | |
25 * | |
26 * No code is included here to run the functions intentionally, to keep dependancies minimal. | |
27 */ | |
28 struct InitStage | |
29 { | |
30 alias void function() InitFunction; /// Alias | |
31 | |
32 /** Add a function to be called during this init stage. | |
33 * | |
34 * Called in order added when not threaded (reverse order for cleanup). | |
35 * | |
36 * Exceptions should never be thrown, since each function may run as a thread, and catching | |
37 * thread exceptions is not guaranteed to work. Log a message, call setFailure() and return | |
38 * instead. */ | |
39 void addFunc (InitFunction f) { | |
40 funcs ~= f; | |
41 } | |
42 | |
43 /** Should be called by an init function when a failure occurs. */ | |
44 void setFailure () { | |
45 synchronized failure = true; | |
46 } | |
47 | |
48 package InitFunction[] funcs = []; | |
49 package bool failure = false; | |
50 } | |
51 | |
52 /** Init can be divided up into these stages, each run in order: | |
53 * | |
54 * init0: | |
55 * static this() (not represented here) | |
56 * | |
57 * init1: | |
58 * Also known as pre-init; is where options get loaded by Init (not represented here). | |
59 * | |
60 * init2: | |
61 * Main symbol and config loading and general low-level stage. This stage is threaded, so all | |
62 * called functions need to be thread-safe. | |
63 * | |
64 * init3: | |
65 * Reserved as an unthreaded stage. | |
66 * | |
67 * init4: | |
68 * Main loading stage for data files and setup for higher-level elements, e.g. windows and input | |
69 * devices. This stage is threaded, so all called functions need to be thread-safe. | |
70 * | |
71 * cleanupX: | |
72 * Corresponding cleanup stage to initX. Called in reverse order (e.g. cleanup2 called before | |
73 * cleanup1). Cleanup is never threaded. | |
74 * | |
75 * The following functions get called (update list as appropriate): | |
76 * | |
77 * init2: | |
78 * mde.SDL.initSdlAndGl, mde.events.initInput | |
79 * | |
80 * init4: | |
81 * mde.SDL.setupWindow | |
82 * | |
83 * cleanup2: | |
84 * (Potentially): mde.SDL.cleanupSDL, mde.init.joystick.closeJoysticks | |
85 */ | |
86 InitStage init2; | |
87 InitStage init4; /// ditto | |
88 InitStage cleanup2; /// ditto | |
89 InitStage cleanup4; /// ditto |