Mercurial > projects > mde
annotate mde/scheduler/InitStage.d @ 21:a60cbb7359dd
Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
committer: Diggory Hardy <diggory.hardy@gmail.com>
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Mon, 24 Mar 2008 17:53:28 +0000 |
parents | 838577503598 |
children |
rev | line source |
---|---|
20 | 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 | |
21
a60cbb7359dd
Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
24 import tango.util.log.Log : Log, Logger; |
a60cbb7359dd
Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
25 private Logger logger; |
a60cbb7359dd
Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
26 static this() { |
a60cbb7359dd
Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
27 logger = Log.getLogger ("mde.scheduler.InitStage"); |
a60cbb7359dd
Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
28 } |
a60cbb7359dd
Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
29 |
20 | 30 /** Represents all functions to be called for a particular init stage. |
31 * | |
32 * No code is included here to run the functions intentionally, to keep dependancies minimal. | |
33 */ | |
34 struct InitStage | |
35 { | |
36 alias void function() InitFunction; /// Alias | |
37 | |
38 /** Add a function to be called during this init stage. | |
39 * | |
40 * Called in order added when not threaded (reverse order for cleanup). | |
41 * | |
42 * Exceptions should never be thrown, since each function may run as a thread, and catching | |
43 * thread exceptions is not guaranteed to work. Log a message, call setFailure() and return | |
44 * instead. */ | |
45 void addFunc (InitFunction f) { | |
46 funcs ~= f; | |
47 } | |
48 | |
21
a60cbb7359dd
Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
49 package InitFunction[] funcs = []; |
20 | 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 | |
21
a60cbb7359dd
Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
90 |
a60cbb7359dd
Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
91 /** Should be called by an init function when a failure occurs. */ |
a60cbb7359dd
Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
92 void setInitFailure () { |
a60cbb7359dd
Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
93 initFailure = true; |
a60cbb7359dd
Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
94 } |
a60cbb7359dd
Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
95 package bool initFailure = false; |