annotate mde/scheduler/Init.d @ 43:1530d9c04d4d

Column/row resizing implemented for GridLayoutWidget (finally)! Also new exitImmediately option and a few debug scope(failure) log messages. committer: Diggory Hardy <diggory.hardy@gmail.com>
author Diggory Hardy <diggory.hardy@gmail.com>
date Thu, 15 May 2008 10:39:57 +0100
parents 316b0230a849
children 0fd51d2c6c8a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
1 /* LICENSE BLOCK
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
2 Part of mde: a Modular D game-oriented Engine
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
3 Copyright © 2007-2008 Diggory Hardy
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
4
26
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 25
diff changeset
5 This program is free software: you can redistribute it and/or modify it under the terms
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 25
diff changeset
6 of the GNU General Public License as published by the Free Software Foundation, either
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 25
diff changeset
7 version 2 of the License, or (at your option) any later version.
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
8
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
11 See the GNU General Public License for more details.
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
12
26
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 25
diff changeset
13 You should have received a copy of the GNU General Public License
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 25
diff changeset
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
15
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
16 /**************************************************************************************************
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
17 * Initialisation setup and exit cleanup module.
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
18 *
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
19 * This module provides an infrastructure for handling much of the initialisation and
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
20 * deinitialisation of the program. It does not, however, provide much of the (de)initialisation
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
21 * code; with the exception of that for the logger.
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
22 *************************************************************************************************/
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
23 module mde.scheduler.Init;
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
24
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 31
diff changeset
25 import mde.scheduler.init2; // This module is responsible for setting up some init functions.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 31
diff changeset
26 import mde.scheduler.initFunctions;
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
27 import mde.scheduler.exception;
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
28
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 31
diff changeset
29 import mde.Options;
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
30 import paths = mde.resource.paths;
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
31 import mde.exception;
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
32
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
33 // tango imports
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
34 import tango.core.Thread;
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
35 import tango.core.Exception;
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
36 import tango.stdc.stringz : fromStringz;
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
37 import tango.util.log.Log : Log, Logger;
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
38 import tango.util.log.ConsoleAppender : ConsoleAppender;
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
39
25
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 24
diff changeset
40 //version = SwitchAppender;
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
41 version (SwitchAppender) { // My own variation, currently just a test
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
42 import tango.util.log.SwitchingFileAppender : SwitchingFileAppender;
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
43 } else {
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
44 import tango.util.log.RollingFileAppender : RollingFileAppender;
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
45 }
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
46
29
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
47 // Derelict imports
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
48 import derelict.opengl.gl;
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
49 import derelict.sdl.sdl;
30
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
50 import derelict.freetype.ft;
29
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
51 import derelict.util.exception;
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
52
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
53 /**
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
54 * Static CTOR
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
55 *
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
56 * This should handle a minimal amount of functionality where useful. For instance, configuring the
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
57 * logger here and not in Init allows unittests to use the logger.
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
58 */
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
59 static this()
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
60 {
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
61 // Find/create paths:
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
62 try {
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
63 paths.resolvePaths();
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
64 } catch (Exception e) {
28
b5fadd8d930b Small addition to GUI, paths work-around for Windows.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 26
diff changeset
65 // NOTE: an exception thrown here cannot be caught by main()!
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
66 throw new InitException ("Resolving paths failed: " ~ e.msg);
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
67 }
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
68
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
69 // Set up the logger:
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
70 {
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
71 // Where logging is done to is determined at compile-time, currently just via static ifs.
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
72 Logger root = Log.getRootLogger();
26
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 25
diff changeset
73
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 25
diff changeset
74 static if (true ) { // Log to files (first appender so root seperator messages don't show on console)
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
75 version (SwitchAppender) {
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
76 root.addAppender (new SwitchingFileAppender (paths.logDir~"/log-.txt", 5));
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
77 } else {
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
78 // Use 2 log files with a maximum size of 1 MB:
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
79 root.addAppender (new RollingFileAppender (paths.logDir~"/log-.txt", 2, 1024*1024));
26
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 25
diff changeset
80 root.info (""); // some kind of separation between runs
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 25
diff changeset
81 root.info ("");
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
82 }
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
83 }
26
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 25
diff changeset
84 static if (true ) { // Log to the console
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 25
diff changeset
85 root.addAppender(new ConsoleAppender);
611f7b9063c6 Changed the licensing and removed a few dead files.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 25
diff changeset
86 }
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
87
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
88 // Set the level here, but set it again once options have been loaded:
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
89 debug root.setLevel(root.Level.Trace);
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
90 else root.setLevel(root.Level.Info);
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
91 }
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
92 }
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
93 static ~this()
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
94 {
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
95 }
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
96
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
97 /**
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
98 * Init class
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
99 *
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
100 * A scope class created at beginning of the program and destroyed at the end; thus the CTOR
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
101 * handles program initialisation and the DTOR handles program cleanup.
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
102 */
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
103 scope class Init
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
104 {
25
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 24
diff changeset
105 //private bool failure = false; // set true on failure during init, so that clean
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
106 private static Logger logger;
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
107 static this() {
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
108 logger = Log.getLogger ("mde.scheduler.Init.Init");
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
109 }
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
110
29
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
111 /** this() − initialisation
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
112 *
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
113 * Runs general initialisation code, in a threaded manner where this isn't difficult.
29
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
114 * If any init fails, cleanup is still handled by ~this().
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
115 *
29
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
116 * Init order: 1. Pre-init (loads components needed by most init functions). 2. Dynamic library
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
117 * loading (load any dynamic libraries first, so that if loading fails nothing else need be
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
118 * done). 3. Init functions (threaded functions handling the rest of initialisation).
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
119 */
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
120 /* In a single-threaded function this could be done with:
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
121 * scope(failure) cleanup;
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
122 * This won't work with a threaded init function since any threads completing succesfully will
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
123 * not clean-up, and a fixed list of clean-up functions cannot be used since clean-up functions
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
124 * must not run where the initialisation functions have failed.
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
125 * Hence a list of clean-up functions is built similarly to scope(failure) --- see addCleanupFct.
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
126 */
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
127 this()
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
128 {
24
32eff0e01c05 Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
129 debug logger.trace ("Init: starting");
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
130
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
131 //BEGIN Pre-init (stage init0)
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
132 /* Load options now. Don't load in a thread since:
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
133 * Loading should be fast
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
134 * Most work is probably disk access
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
135 * It's a really good idea to let the options apply to all other loading. */
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
136 try {
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
137 Options.load();
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
138 } catch (optionsLoadException e) {
25
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 24
diff changeset
139 throw new InitException ("Loading options failed: " ~ e.msg);
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
140 }
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
141
43
1530d9c04d4d Column/row resizing implemented for GridLayoutWidget (finally)!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
142 // Now re-set the logging level, using the value from the config file:
1530d9c04d4d Column/row resizing implemented for GridLayoutWidget (finally)!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
143 Log.getRootLogger.setLevel (cast(Log.Level) miscOpts.logLevel, true);
1530d9c04d4d Column/row resizing implemented for GridLayoutWidget (finally)!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
144 // And set this (debug option):
1530d9c04d4d Column/row resizing implemented for GridLayoutWidget (finally)!
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
145 imde.run = !miscOpts.exitImmediately;
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
146 //END Pre-init
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
147
29
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
148 debug logger.trace ("Init: pre-init done");
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
149
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
150 //BEGIN Load dynamic libraries
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
151 /* Can be done by init functions but much neater to do here.
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
152 * Also means that init functions aren't run if a library fails to load. */
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
153 try {
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
154 DerelictSDL.load();
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
155 DerelictGL.load();
30
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
156 DerelictFT.load();
29
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
157 } catch (DerelictException de) {
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
158 logger.fatal ("Loading dynamic library failed:");
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
159 logger.fatal (de.msg);
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
160
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
161 throw new InitException ("Loading dynamic libraries failed (see above).");
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
162 }
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
163 //END Load dynamic libraries
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
164
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
165 debug logger.trace ("Init: dynamic libraries loaded");
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
166
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
167 //BEGIN Init (stages init2, init4)
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
168 /* Call init functions.
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
169 *
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
170 * Current method is to try using threads, and on failure assume no threads were actually
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
171 * created and run functions in a non-threaded manner. */
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
172
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
173 try {
25
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 24
diff changeset
174 if (runStageThreaded (init)) runStageForward (init);
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
175 }
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
176 catch (InitStageException) { // This init stage failed.
25
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 24
diff changeset
177 // FIXME: check DTOR still runs
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 24
diff changeset
178 throw new InitException ("An init function failed (see above message(s))");
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
179 }
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
180 //END Init
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
181
24
32eff0e01c05 Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
182 debug logger.trace ("Init: done");
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
183 }
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
184
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
185 /** DTOR - runs cleanup functions. */
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
186 ~this()
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
187 {
24
32eff0e01c05 Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
188 debug logger.trace ("Cleanup: starting");
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
189
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
190 Options.save(); // save options... do so here for now
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
191
25
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 24
diff changeset
192 // General cleanup:
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 24
diff changeset
193 try {
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 24
diff changeset
194 if (runStageThreaded (cleanup)) runStageReverse (cleanup);
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 24
diff changeset
195 }
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 24
diff changeset
196 catch (InitStageException) {
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 24
diff changeset
197 // Nothing else to do but report:
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 24
diff changeset
198 logger.error ("One or more cleanup functions failed!");
2c28ee04a4ed Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 24
diff changeset
199 }
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
200
24
32eff0e01c05 Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
201 debug logger.trace ("Cleanup: done");
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
202 }
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
203
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
204
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
205 //BEGIN runStage...
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
206 private static {
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
207 /* The following three functions, runStage*, each run all functions in a stage in some order,
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
208 * catching any exceptions thrown by the functions (although this isn't guaranteed for threads),
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
209 * and throw an InitStageException on initFailure. */
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
210
29
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
211 const LOG_IF_MSG = "Init function ";
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
212 const LOG_CF_MSG = "Cleanup function ";
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
213 const LOG_F_START = " - running";
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
214 const LOG_F_END = " - completed";
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
215 const LOG_F_FAIL = " - failed: ";
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
216 /* Runs all functions consecutively, first-to-last.
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
217 * If any function fails, halts immediately. */
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
218 void runStageForward (InitStage s) {
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
219 foreach (func; s.funcs) {
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
220 if (initFailure) break;
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
221 try {
29
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
222 debug logger.trace (LOG_IF_MSG ~ func.name ~ LOG_F_START);
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
223 func.func();
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
224 debug logger.trace (LOG_IF_MSG ~ func.name ~ LOG_F_END);
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
225 } catch (Exception e) {
29
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
226 logger.fatal (LOG_IF_MSG ~ func.name ~ LOG_F_FAIL ~
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
227 ((e.msg is null || e.msg == "") ? "(no failure message)" : e.msg) );
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
228
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
229 setInitFailure();
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
230 }
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
231 }
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
232
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
233 if (initFailure) throw new InitStageException; // Problem running; abort and cleanup from here.
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
234 }
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
235 /* Runs all functions consecutively, last-to-first.
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
236 * If any function fails, continue until all have been run. */
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
237 void runStageReverse (InitStage s) {
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
238 foreach_reverse (func; s.funcs) {
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
239 try {
29
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
240 debug logger.trace (LOG_CF_MSG ~ func.name ~ LOG_F_START);
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
241 func.func();
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
242 debug logger.trace (LOG_CF_MSG ~ func.name ~ LOG_F_END);
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
243 } catch (Exception e) {
29
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
244 logger.fatal (LOG_CF_MSG ~ func.name ~ LOG_F_FAIL ~
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
245 ((e.msg is null || e.msg == "") ? "(no failure message)" : e.msg) );
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
246
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
247 setInitFailure();
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
248 }
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
249 }
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
250 if (initFailure) throw new InitStageException; // Problem running; abort and cleanup from here.
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
251 }
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
252 /* Tries running functions in a threaded way. Returns false if successful, true if not but
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
253 * functions should be run without threads. */
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
254 bool runStageThreaded (InitStage s) {
24
32eff0e01c05 Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
255 if (!miscOpts.useThreads) return true; // Use unthreaded route instead
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
256
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
257 ThreadGroup tg;
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
258 try { // creating/starting threads could fail
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
259 tg = new ThreadGroup;
29
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
260 foreach (func; s.funcs) { // Start all threads
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
261 debug logger.trace (LOG_IF_MSG ~ func.name ~ LOG_F_START);
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
262 tg.create(func.func);
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
263 debug logger.trace (LOG_IF_MSG ~ func.name ~ LOG_F_END);
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
264 }
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
265 } catch (ThreadException e) { // Problem with threading; try without threads
24
32eff0e01c05 Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
266 logger.error ("Caught ThreadException while trying to create threads:");
32eff0e01c05 Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
267 logger.error (e.msg);
29
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
268 logger.info ("Will disable threads and continue, assuming no threads were created.");
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
269
24
32eff0e01c05 Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 21
diff changeset
270 Options.setBool("misc", "useThreads", false); // Disable threads entirely
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
271 return true; // Try again without threads
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
272 }
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
273
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
274 /* Wait for all threads to complete.
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
275 *
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
276 * If something went wrong, we still need to do this before cleaning up.
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
277 */
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
278 foreach (t; tg) {
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
279 try {
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
280 t.join (true);
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
281 } catch (Exception e) {
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
282 // Relying on catching exceptions thrown by other threads is a bad idea.
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
283 // Hence all threads should catch their own exceptions and return safely.
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
284
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
285 logger.fatal ("Unhandled exception from Init function:");
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
286 logger.fatal (e.msg);
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
287
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
288 setInitFailure (); // abort (but join other threads first)
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
289 }
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
290 }
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
291
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
292 if (initFailure) throw new InitStageException; // Problem running; abort and cleanup from here.
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
293 return false; // Done successfully
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
294 }
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
295 }
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
296 //END runStage...
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
297
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
298 debug (mdeUnitTest) unittest {
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
299 /* Fake init and cleanup. Use unittest-specific init and cleanup InitStages to avoid
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
300 * messing other init/cleanup up. */
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
301 static InitStage initUT, cleanupUT;
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
302
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
303 static bool initialised = false;
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
304 static void cleanupFunc1 () {
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
305 initialised = false;
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
306 }
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
307 static void cleanupFunc2 () {
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
308 assert (initialised == true);
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
309 }
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
310
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
311 static void initFunc () {
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
312 initialised = true;
30
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
313 cleanupUT.addFunc (&cleanupFunc1, "UT cleanup 1");
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
314 cleanupUT.addFunc (&cleanupFunc2, "UT cleanup 2");
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
315 }
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
316
30
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
317 initUT.addFunc (&initFunc, "UT init");
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
318
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
319 runStageForward (initUT);
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
320 assert (initialised);
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
321
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
322 runStageReverse (cleanupUT);
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
323 assert (!initialised);
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
324
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
325 logger.info ("Unittest complete.");
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
326 }
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
327 }