annotate mde/setup/Init.d @ 178:62aa8845edd2

Coloured log output to the console.
author Diggory Hardy <diggory.hardy@gmail.com>
date Tue, 15 Sep 2009 10:36:37 +0200
parents a1ba9157510e
children
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 /**************************************************************************************************
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
17 * Initialisation and cleanup (shutdown) module.
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
18 *
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
19 * Program startup follows this sequence: static this() functions, pre-init, init.
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
20 * Shutdown consists of: cleanup, post-cleanup, static ~this() functions.
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
21 *
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
22 * static this and ~this functions should not use any external resources, such as dynamically
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
23 * loaded libraries or files, and should not interact with other modules. They should be almost
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
24 * guaranteed not to fail. Preferably, they shouldn't involve large amounts of memory or
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
25 * processing, but this is not a requirement.
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
26 *
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
27 * Pre-init: init code written in this module. Generally only prerequisets of most other stages
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
28 * go here.
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
29 *
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
30 * Init: This is where init code from external modules gets hooked in. Each stage consists of an
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
31 * initialization function, a corresponding cleanup function, a state, and any dependencies (other
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
32 * init functions which must be run before this one). Init functions are run according to these
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
33 * dependencies, potentially threaded simultaeneously with other init functions.
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
34 *
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
35 * Cleanup: Cleanup happens similarly to init for all stages requiring shutdown (according to their
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
36 * state). The init dependencies are applied in reverse order (so if X depended on Y, Y's cleanup
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
37 * will not run until X's cleanup has completed), and again the functions may be threaded.
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
38 *
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
39 * Post-cleanup: like pre-init, this is code written in Init.
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
40 *************************************************************************************************/
63
66d555da083e Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 56
diff changeset
41 module mde.setup.Init;
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
42
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
43 import mde.setup.InitStage; // Controls external delegates run by init
63
66d555da083e Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 56
diff changeset
44 import mde.setup.exception;
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 136
diff changeset
45 import mde.setup.logger;
178
62aa8845edd2 Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
46 import mde.setup.LogLayout;
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
47
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 136
diff changeset
48 import mde.content.AStringContent;
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 136
diff changeset
49 import mde.content.ContentLoader;
134
7ababdf97748 Moved mde.setup.paths to mde.file.paths and paths.mdeReader to mde.file.mergetag.Reader.MTMultiReader.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 132
diff changeset
50 import paths = mde.file.paths;
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
51 import mde.exception; // optionsLoadException
127
3328c6fb77ca 2 fixes for ldc - not that I was able to compile anyway (x86_64).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
52 import imde = mde.imde;
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 // tango imports
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
55 import tango.core.Thread;
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
56 import tango.core.sync.Condition;
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
57 import tango.core.Exception;
91
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 89
diff changeset
58 import tango.util.container.LinkedList;
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
59
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
60 //import tango.stdc.stringz : fromStringz;
53
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
61 import tango.io.Console; // for printing command-line usage
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
62 import TimeStamp = tango.text.convert.TimeStamp, tango.time.WallClock; // output date in log file
151
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
63 import tango.util.ArgParser;
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
64 import tango.util.log.Log;
67
108d123238c0 Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 64
diff changeset
65 import tango.util.log.AppendConsole;
108d123238c0 Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 64
diff changeset
66 import tango.util.log.AppendFiles;
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
67
29
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
68 // Derelict imports
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
69 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
70 import derelict.sdl.sdl;
56
f9f5e04f20b2 Bit of polish for a public release, including some more documentation.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 55
diff changeset
71 //import derelict.sdl.image; Was to be used... for now isn't
30
467c74d4804d Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 29
diff changeset
72 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
73 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
74
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
75
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 136
diff changeset
76 /******************************************************************************
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
77 * Init class
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
78 *
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 136
diff changeset
79 * A scope class created at beginning of the program and destroyed at the end;
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 136
diff changeset
80 * thus the CTOR handles program initialisation and the DTOR handles program
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 136
diff changeset
81 * cleanup.
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 136
diff changeset
82 *****************************************************************************/
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
83 scope class Init
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
84 {
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
85 static this() {
63
66d555da083e Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 56
diff changeset
86 logger = Log.getLogger ("mde.setup.Init");
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 136
diff changeset
87 exitImmediately = new BoolContent ("MiscOptions.exitImmediately");
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 136
diff changeset
88 maxThreads = new IntContent ("MiscOptions.maxThreads");
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 136
diff changeset
89 logLevel = new EnumContent ("MiscOptions.logLevel",
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 136
diff changeset
90 ["Trace", "Info", "Warn", "Error", "Fatal", "None"]);
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 136
diff changeset
91 logOutput = new EnumContent ("MiscOptions.logOutput",
151
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
92 ["both", "file", "console", "none"]);
178
62aa8845edd2 Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
93 logColour = new BoolContent ("MiscOptions.logColour");
151
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
94
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
95 // Callback to set the logging level on change:
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
96 logLevel.addCallback (&setLogLevel);
20
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
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
99 /** this() − pre-init and init */
53
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
100 this(char[][] cmdArgs)
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
101 {
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 136
diff changeset
102 /**********************************************************************
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
103 * Pre-init - init code written in this module.
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 136
diff changeset
104 *********************************************************************/
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
105 debug logger.trace ("Init: starting pre-init");
53
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
106 try {
151
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
107 // Create without a default-argument delegate; let ArgParser throw:
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
108 auto args = new ArgParser ();
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
109 char[] basePath = ".";
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
110 bool printPaths = false;
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
111 args.bind("--", "base-path=", delegate void(char[] value){
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
112 basePath=value;
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
113 });
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
114 args.bind("--", "data-path=", delegate void(char[] value){
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
115 paths.extraDataPath = value;
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
116 });
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
117 args.bind("--", "conf-path=", delegate void(char[] value){
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
118 paths.extraConfPath = value;
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
119 });
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
120 args.bind("--", "font-path=", delegate void(char[] value){
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
121 paths.addFontPath (value);
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
122 });
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
123 args.bind("--", "paths", delegate void(char[]){
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
124 printPaths = true;
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
125 });
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
126 args.bind([Argument("--", "quick-exit"), Argument ("-", "q")],
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
127 delegate void(char[]){
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
128 imde.run = false;
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
129 });
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
130 args.bind([Argument("--", "help"), Argument ("-", "h")],
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
131 delegate void(char[]){
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
132 printUsage(cmdArgs[0]);
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
133 // Requesting help is an "error" in that normal program operation is cut short.
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
134 throw new InitException ("Help requested"); // stops program
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
135 });
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
136 args.parse(cmdArgs[1..$]);
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
137 paths.resolvePaths (basePath);
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
138
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
139 if (printPaths) {
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
140 paths.mdeDirectory.printPaths;
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
141 throw new InitException ("Paths requested"); // lazy way to stop
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
142 }
53
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
143 } catch (Exception e) {
151
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
144 throw new InitException ("Command-line: "~e.msg);
53
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
145 }
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
146 debug logger.trace ("Init: resolved paths successfully");
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
147
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
148 /* Load options now. Don't load in a thread since:
53
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
149 * Loading should be fast & most work is probably disk access
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
150 * It enables logging to be controlled by options
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
151 * It's a really good idea to let the options apply to all other loading */
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
152 try {
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 136
diff changeset
153 ContentLoader.load();
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 136
diff changeset
154 } catch (Exception e) {
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 136
diff changeset
155 throw new InitException ("Loading options (content values) failed: " ~ e.msg);
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
156 }
53
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
157 debug logger.trace ("Init: loaded options successfully");
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
158
53
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
159 // Set up the logger:
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
160 Logger root;
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
161 try {
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
162 // Where logging is done to is determined at compile-time, currently just via static ifs.
67
108d123238c0 Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 64
diff changeset
163 root = Log.root;
108d123238c0 Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 64
diff changeset
164 root.clear; // we may no longer want to log to the console
178
62aa8845edd2 Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
165 Appender.Layout layout = null;
62aa8845edd2 Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
166 if (logColour())
62aa8845edd2 Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
167 layout = new LayoutTimerColour();
53
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
168
151
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
169 // logOutput == 0 enables both outputs, in case options aren't read
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
170 if (!(logOutput() & 2)) { // first appender so root seperator messages don't show on console
98
49e7cfed4b34 All types of Option have been converted to use ValueContent classes, and their values can be displayed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
171 // Use 2 log files with a maximum size of 16kiB:
49e7cfed4b34 All types of Option have been converted to use ValueContent classes, and their values can be displayed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
172 root.add (new AppendFiles (paths.logDir~"/log-.txt", 2, 16*1024));
49e7cfed4b34 All types of Option have been converted to use ValueContent classes, and their values can be displayed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
173 root.append (Level.None, ""); // some kind of separation between runs
49e7cfed4b34 All types of Option have been converted to use ValueContent classes, and their values can be displayed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 95
diff changeset
174 root.append (Level.None, "");
53
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
175 }
151
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
176 if (!(logOutput() & 1))
178
62aa8845edd2 Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
177 root.add(new AppendConsole (layout));
53
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
178 } catch (Exception e) {
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
179 // Presumably it was only adding a file appender which failed; set up a new console
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
180 // logger and if that fails let the exception kill the program.
67
108d123238c0 Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 64
diff changeset
181 root.clear;
108d123238c0 Changes to work with tango r3700 (post 0.99.6).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 64
diff changeset
182 root.add (new AppendConsole);
151
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
183 logger.error ("Exception while setting up the logger; logging to the console instead.");
53
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
184 }
153
2934fcacbb97 Fixed a bug preventing log messages from being displayed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 151
diff changeset
185
2934fcacbb97 Fixed a bug preventing log messages from being displayed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 151
diff changeset
186 // Done enough init to know where and when to log messages now
2934fcacbb97 Fixed a bug preventing log messages from being displayed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 151
diff changeset
187 logger.info ("Starting mde [no version] on " ~ TimeStamp.toString(WallClock.now));
2934fcacbb97 Fixed a bug preventing log messages from being displayed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 151
diff changeset
188
53
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
189 // a debugging option:
151
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
190 imde.run = imde.run && !exitImmediately();
53
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
191 debug logger.trace ("Init: applied pre-init options");
29
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
192
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
193 //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
194 /* 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
195 * 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
196 try {
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
197 DerelictSDL.load();
56
f9f5e04f20b2 Bit of polish for a public release, including some more documentation.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 55
diff changeset
198 // SDLImage was going to be used... for now it isn't because of gl texturing problems
f9f5e04f20b2 Bit of polish for a public release, including some more documentation.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 55
diff changeset
199 //DerelictSDLImage.load();
29
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
200 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
201 DerelictFT.load();
29
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
202 } catch (DerelictException de) {
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
203 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
204 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
205
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
206 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
207 }
53
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
208 debug logger.trace ("Init: dynamic libraries loaded");
29
f985c28c0ec9 A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 28
diff changeset
209 //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
210
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
211
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 136
diff changeset
212 /**********************************************************************
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
213 * Init − where init code from external modules gets hooked in.
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 136
diff changeset
214 *********************************************************************/
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
215 debug logger.trace ("Init: done pre-init, starting init stages");
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
216
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
217 // Calculate reverse dependencies of stages:
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
218 foreach (key,stage_p; stages)
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
219 foreach (name; stage_p.depends)
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
220 stages[name].rdepends ~= key;
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
221
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
222 runStages!(true); // startup delegates
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
223
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
224 debug logger.trace ("Init: done");
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
225 }
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
226
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
227 /** DTOR - runs cleanup functions. */
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
228 ~this()
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
229 {
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
230 debug logger.trace ("Cleanup: starting");
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
231
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
232 runStages!(false); // cleanup delegates
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
233
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 136
diff changeset
234 ContentLoader.save(); // save options before exiting
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
235
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
236 debug logger.trace ("Cleanup: done");
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
237 }
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
238
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
239 // run init stages or cleanup if startup is false
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
240 private static void runStages(bool startup) () {
91
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 89
diff changeset
241 auto toRun = new LinkedList!(InitStage*);
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
242 foreach (v; stages) {
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
243 // Filter only stages with the relevant delegate. It is not checked later that the
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
244 // delegate exists!
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
245 // If no init/cleanup function exists, implicit activation/deactivation can occur so
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
246 // that dependents/dependencies may activate/deactivate.
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
247 static if (startup) {
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
248 if (v.state == StageState.INACTIVE) {
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
249 if ((*v).init)
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
250 toRun.append (v);
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
251 else
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
252 v.state = StageState.ACTIVE;
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
253 }
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
254 } else {
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
255 if (v.state == StageState.ACTIVE) {
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
256 if (v.cleanup)
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
257 toRun.append (v);
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
258 else
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
259 v.state = StageState.INACTIVE;
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
260 }
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
261 }
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
262 }
89
97e6dce08037 Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 88
diff changeset
263 // Counts number of active threads, and before threads are started is number to use:
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 136
diff changeset
264 size_t numWorking = (toRun.size < maxThreads()) ? toRun.size : maxThreads();
88
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
265 enum STATE { WORKING = 0, DONE = 1, ABORT = 2 }
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
266 STATE doneInit = STATE.WORKING;
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
267 Mutex toRunM = new Mutex; // synchronization on toRun, numWorking
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
268 Condition toRunC = new Condition(toRunM); // used by threads waiting for remaining stages' dependencies to be met
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
269
95
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 94
diff changeset
270 /* initThreadFct is now in a class to allow reliably identifying whcich instance is run in the main thread.
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 94
diff changeset
271 * The main thread gets index 0, other threads indexes 2,3,4,etc. (there is no 1). */
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 94
diff changeset
272 class InitStageThread : Thread {
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 94
diff changeset
273 this (int n) {
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 94
diff changeset
274 debug threadNum = n;
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 94
diff changeset
275 super (&initThreadFct);
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 94
diff changeset
276 }
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 94
diff changeset
277 debug int threadNum;
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
278 /* This is a threadable member function to run init stages.
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
279 * Operation follows:
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
280 * 1 Look for a stage to run:
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
281 * if found:
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
282 * notify waiting threads work may be available
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
283 * init stage
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
284 * goto 1
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
285 * if not found:
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
286 * if any other threads are working, wait (dependencies may not be met yet)
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
287 * if no other threads are working, notify waiting threads and terminate (finished)
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
288 * When notified, threads start at 1. */
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
289 void initThreadFct () {
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
290 try { // created as a thread - must not throw exceptions
88
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
291 InitStage* stage;
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
292
88
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
293 threadLoop:
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
294 while (true) { // thread loops until a problem occurs or nothing else can be done
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
295 // Look for a job:
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
296 synchronized (toRunM) {
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
297 --numWorking; // stopped working: looking/waiting for a job
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
298 if (doneInit) break threadLoop; // something went wrong in another thread
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
299
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
300 static if (startup)
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
301 int num_rdepends = (stage is null) ? 0 : stage.rdepends.length;
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
302 else
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
303 int num_rdepends = (stage is null) ? 0 : stage.depends.length;
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
304
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
305 getStage:
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
306 while (true) {
91
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 89
diff changeset
307 auto toRunIt = toRun.iterator; // iterates toRun
88
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
308 itStages:
91
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 89
diff changeset
309 while (toRunIt.next (stage)) { // get next element of toRun
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 89
diff changeset
310 debug assert (stage !is null, "stage is null");
88
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
311 static if (startup) {
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
312 foreach (d; stage.depends)
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
313 if (stages[d].state != StageState.ACTIVE)
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
314 continue itStages; // dependency isn't met (yet)
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
315 } else {
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
316 foreach (d; stage.rdepends)
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
317 if (stages[d].state != StageState.INACTIVE)
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
318 continue itStages; // reverse dependency isn't unmet (yet)
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
319 }
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
320
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
321 // All dependencies met
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
322 debug assert (toRun.size, "toRun is empty (error with iterator)");
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
323 toRunIt.remove;
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
324 break getStage;
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
325 }
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
326
88
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
327 // No stage remaining with all dependencies met
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
328 if (toRun.size && numWorking) // still some working so more dependencies may be met later
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
329 toRunC.wait; // wait until another thread finishes
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
330 else // no thread is working, so none of what's left is doable, or nothing's left
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
331 break threadLoop;
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
332 }
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
333 ++numWorking; // got a job!
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
334 if (num_rdepends > 2) // how many stages depended on the last one run?
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
335 toRunC.notifyAll(); // tell all waiting threads there may be work now
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
336 else if (num_rdepends == 2)
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
337 toRunC.notify(); // there's potentially work for this thread and one other
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
338 // else there won't be additional work so don't notify
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
339 }
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
340
88
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
341 // Do a job:
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
342 try {
91
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 89
diff changeset
343 static if (startup) {
95
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 94
diff changeset
344 debug logger.trace ("({}) InitStage {}: starting init", threadNum, stage.name);
132
264028f4115a Cleaned up mde.imde and a couple of widget functions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 127
diff changeset
345 stage.state = (*stage).init(); // init is a property too :-(
91
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 89
diff changeset
346 } else {
95
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 94
diff changeset
347 debug logger.trace ("({}) InitStage {}: starting cleanup", threadNum, stage.name);
88
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
348 stage.state = stage.cleanup();
91
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 89
diff changeset
349 }
95
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 94
diff changeset
350 debug logger.trace ("({}) InitStage {}: completed; state: {}", threadNum, stage.name, stage.state);
88
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
351 } catch (InitStageException e) {
132
264028f4115a Cleaned up mde.imde and a couple of widget functions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 127
diff changeset
352 debug logger.error ("({}) InitStage {}: failed: "~e.msg, threadNum, stage.name);
264028f4115a Cleaned up mde.imde and a couple of widget functions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 127
diff changeset
353 else logger.error ("InitStage {}: failed: "~e.msg, stage.name);
173
a1ba9157510e Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
354 e.writeOut(delegate void(char[]s){ Cerr(s); });
a1ba9157510e Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
355 stage.state = e.state;
88
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
356 doneInit = STATE.ABORT;
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
357 break threadLoop;
88
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
358 } catch (Exception e) {
132
264028f4115a Cleaned up mde.imde and a couple of widget functions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 127
diff changeset
359 debug logger.error ("({}) InitStage {}: failed: "~e.msg, threadNum, stage.name);
264028f4115a Cleaned up mde.imde and a couple of widget functions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 127
diff changeset
360 else logger.error ("InitStage {}: failed: "~e.msg, stage.name);
173
a1ba9157510e Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
361 e.writeOut(delegate void(char[]s){ Cerr(s); });
a1ba9157510e Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
362 doneInit = STATE.ABORT;
88
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
363 break threadLoop;
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
364 }
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
365 }
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
366 } catch (Exception e) {
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
367 logger.fatal ("Exception in initThreadFct: "~e.msg);
88
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
368 doneInit = STATE.ABORT;
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
369 }
88
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
370 doneInit |= STATE.DONE; // allow other threads a faster exit
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
371 toRunC.notifyAll(); // Most likely if we're exiting, we should make sure others aren't waiting.
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
372 return;
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
373 }
95
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 94
diff changeset
374 }
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
375
89
97e6dce08037 Solved some/removed some obsolete jobs/FIXMEs (excluding from gui code). General cleanup.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 88
diff changeset
376 // Start min(miscOpts.maxThreads,toRun.size)-1 threads:
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
377 try {
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
378 ThreadGroup g = new ThreadGroup;
95
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 94
diff changeset
379 InitStageThread x;
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 94
diff changeset
380 for (size_t i = numWorking; i > 1; --i) {
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 94
diff changeset
381 //g.create (&initThreadFct);
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 94
diff changeset
382 x = new InitStageThread (i);
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 94
diff changeset
383 x.start;
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 94
diff changeset
384 g.add (x);
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 94
diff changeset
385 }
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 94
diff changeset
386 x = new InitStageThread (0);
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 94
diff changeset
387 x.initThreadFct(); // also run in current thread
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
388 g.joinAll (false); // don't rethrow exceptions - there SHOULD NOT be any
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
389 } catch (ThreadException e) {
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
390 logger.error ("Exception while using threads: "~e.msg);
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
391 logger.error ("Disabling threads and attempting to continue.");
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 136
diff changeset
392 maxThreads = 1; // count includes current thread
95
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 94
diff changeset
393 auto x = new InitStageThread (0);
2a364c7d82c9 Boolean options can be adjusted from the gui now (using a very basic widget). Also some bug-fixes.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 94
diff changeset
394 x.initThreadFct(); // try with just this thread
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
395 } // any other exception will be caught in main() and abort program
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
396
88
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
397 if (doneInit & STATE.ABORT)
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
398 throw new InitException ("An init/cleanup function failed (see above message(s))");
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
399
88
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
400 if (toRun.size)
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
401 foreach (stage; toRun)
91
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 89
diff changeset
402 logger.warn ("InitStage {}: was not run due to unmet dependencies", stage.name);
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
403 }
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
404
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
405 private static {
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
406 Logger logger;
178
62aa8845edd2 Coloured log output to the console.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
407 BoolContent exitImmediately, logColour;
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 136
diff changeset
408 IntContent maxThreads;
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 136
diff changeset
409 EnumContent logLevel, logOutput;
53
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
410
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 136
diff changeset
411 // Callback on logLevel
170
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 153
diff changeset
412 void setLogLevel (IContent = null) {
151
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
413 int level = logLevel();
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
414 if (level < Level.Trace || level > Level.None) {
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
415 logger.error ("incorrect logging level");
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
416 level = Level.Info;
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
417 return; // setting the level causes this function to be called again
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
418 }
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
419 debug {
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
420 Log.root.level (Level.Trace);
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
421 logger.trace ("Setting logging level {}", logLevel());
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
422 }
153
2934fcacbb97 Fixed a bug preventing log messages from being displayed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 151
diff changeset
423 Log.root.level (logOutput() == 3 ? Level.None : cast(Level) logLevel(), true);
115
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 103
diff changeset
424 }
1b1e2297e2fc Enums handled more generically now via either a popup list or flat list of BoolContentWidgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 103
diff changeset
425
53
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
426 void printUsage (char[] progName) {
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
427 Cout ("mde [no version]").newline;
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
428 Cout ("Usage:").newline;
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
429 Cout (progName ~ ` [options]`).newline;
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
430 version(Windows)
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
431 Cout (
151
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
432 ` --base-path=path Use path as the base (install) path (Windows only). It
53
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
433 should contain the "data" directory.`).newline;
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
434 Cout (
151
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
435 ` --data-path=path Add path as a potential location for data files. May be
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
436 given multiple times. First path argument becomes
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
437 the prefered location to load data files from.
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
438 --conf-path=path Add path as a potential location for config files. May
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
439 be given multiple times. Configuration in the first
e785e98d3b78 Updated for compatibility with tango 0.99.8.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
440 path given take highest priority.
53
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
441 --paths Print all paths found and exit.
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
442 --quick-exit, -q Exit immediately, without entering main loop.
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
443 --help, -h Print this message.`).newline;
f000d6cd0f74 Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 45
diff changeset
444 }
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
445 }
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
446
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
447 debug (mdeUnitTest) unittest {
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
448 auto realInit = stages; // backup the real init stages
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
449 stages = new typeof(stages); // an empty test-bed
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
450
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
451 bool init1, init2, init3 = true;
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
452 StageState s1InitReturns = StageState.ACTIVE;
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
453 addInitStage ("stg1", delegate StageState() {
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
454 init1 = true;
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
455 return s1InitReturns;
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
456 }, delegate StageState() {
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
457 init1 = false;
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
458 return StageState.INACTIVE;
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
459 });
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
460 addInitStage ("stg2", delegate StageState() {
88
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
461 assert (init1);
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
462 init2 = true;
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
463 return StageState.ACTIVE;
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
464 }, delegate StageState() {
88
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
465 assert (init1);
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
466 init2 = false;
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
467 return StageState.INACTIVE;
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
468 }, ["stg1"]);
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
469 InitStage s3;
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
470 s3.init = delegate StageState() {
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
471 throw new InitStageException (cast(StageState)7); // not a normal state, but good for a test
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
472 return StageState.ERROR;
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
473 };
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
474 s3.cleanup = delegate StageState() {
88
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
475 assert (init1);
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
476 init3 = false;
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
477 return StageState.INACTIVE;
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
478 };
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
479 s3.depends = [ toStageName("stg1") ];
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
480 s3.state = StageState.ACTIVE; // already active, so s3.init should not run (first time)
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
481 addInitStage ("stg3", &s3);
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
482
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
483 // Stuff normally done in Init.this():
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
484 // Calculate reverse dependencies of stages:
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
485 foreach (key,stage_p; stages)
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
486 foreach (name; stage_p.depends)
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
487 stages[name].rdepends ~= key;
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 136
diff changeset
488 int realMaxThreads = maxThreads();
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 136
diff changeset
489 maxThreads = 4; // force up to 4 threads for unittest
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
490
91
4d5d53e4f881 Shared alignment for dynamic content lists - finally implemented! Lots of smaller changes too.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 89
diff changeset
491 logger.level(Logger.Info); // hide a lot of trace messages
136
4084f07f2c7a Added simpler mergetag readers and writers, with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 135
diff changeset
492 logger.info ("You should see some messages about InitStages not run/failing:");
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
493 // Run the above.
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
494 runStages!(true);
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
495 assert (init1);
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
496 assert (init2);
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
497 foreach (s; stages)
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
498 assert (s.state == StageState.ACTIVE);
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
499
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
500 runStages!(false);
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
501 assert (!init1);
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
502 assert (!init2);
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
503 assert (!init3);
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
504 foreach (s; stages)
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
505 assert (s.state == StageState.INACTIVE);
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
506
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
507 s1InitReturns = StageState.ERROR;
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
508 // Run again. S2/S3 shouldn't run, S1 won't shut down
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
509 runStages!(true);
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
510 assert (init1);
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
511 assert (!init2);
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
512 assert (!init3);
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
513 runStages!(false);
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
514 assert (init1); // S1 cleanup won't run
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
515
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
516 stages[toStageName("stg1")].state = StageState.INACTIVE; // hack it back so we can still test
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
517 s1InitReturns = StageState.ACTIVE;
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
518 init1 = false;
88
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
519 bool a1 = false;
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
520 try {
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
521 runStages!(true);
88
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
522 a1 = true;
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
523 } catch (Exception e) {}
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
524 assert (!a1, "runStages didn't throw");
01f4f5f1acc9 Changes to init and to allow compiling with gdc.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 86
diff changeset
525 assert (init1); // s1.init should run first; s2.init may or may not get run
85
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
526 assert (stages[toStageName("stg3")].state == cast(StageState)7); // set by the exception
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
527
56c0ddd90193 Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 77
diff changeset
528 stages = realInit; // restore the real init stages
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 136
diff changeset
529 maxThreads = realMaxThreads;
20
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
530 logger.info ("Unittest complete.");
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
531 }
838577503598 Reworked much of Init.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
532 }