Mercurial > projects > mde
annotate mde/setup/Init.d @ 64:cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Sun, 29 Jun 2008 11:55:55 +0100 |
parents | 66d555da083e |
children | 108d123238c0 |
rev | line source |
---|---|
20 | 1 /* LICENSE BLOCK |
2 Part of mde: a Modular D game-oriented Engine | |
3 Copyright © 2007-2008 Diggory Hardy | |
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 | 8 |
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | |
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
11 See the GNU General Public License for more details. | |
12 | |
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 | 15 |
16 /************************************************************************************************** | |
17 * Initialisation setup and exit cleanup module. | |
18 * | |
19 * This module provides an infrastructure for handling much of the initialisation and | |
20 * deinitialisation of the program. It does not, however, provide much of the (de)initialisation | |
21 * code; with the exception of that for the logger. | |
22 *************************************************************************************************/ | |
63
66d555da083e
Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
56
diff
changeset
|
23 module mde.setup.Init; |
20 | 24 |
63
66d555da083e
Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
56
diff
changeset
|
25 import mde.setup.init2; // This module is responsible for setting up some init functions. |
66d555da083e
Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
56
diff
changeset
|
26 import mde.setup.initFunctions; |
66d555da083e
Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
56
diff
changeset
|
27 import mde.setup.exception; |
20 | 28 |
63
66d555da083e
Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
56
diff
changeset
|
29 import mde.lookup.Options; |
66d555da083e
Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
56
diff
changeset
|
30 import paths = mde.setup.paths; |
20 | 31 import mde.exception; |
32 | |
33 // tango imports | |
34 import tango.core.Thread; | |
35 import tango.core.Exception; | |
36 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
|
37 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
|
38 import TimeStamp = tango.text.convert.TimeStamp, tango.time.WallClock; // output date in log file |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
39 import tango.util.Arguments; |
20 | 40 import tango.util.log.Log : Log, Logger; |
41 import tango.util.log.ConsoleAppender : ConsoleAppender; | |
42 | |
25
2c28ee04a4ed
Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
24
diff
changeset
|
43 //version = SwitchAppender; |
20 | 44 version (SwitchAppender) { // My own variation, currently just a test |
45 import tango.util.log.SwitchingFileAppender : SwitchingFileAppender; | |
46 } else { | |
47 import tango.util.log.RollingFileAppender : RollingFileAppender; | |
48 } | |
49 | |
29
f985c28c0ec9
A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
28
diff
changeset
|
50 // Derelict imports |
f985c28c0ec9
A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
28
diff
changeset
|
51 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
|
52 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
|
53 //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
|
54 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
|
55 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
|
56 |
20 | 57 /** |
58 * Static CTOR | |
59 * | |
60 * This should handle a minimal amount of functionality where useful. For instance, configuring the | |
61 * logger here and not in Init allows unittests to use the logger. | |
62 */ | |
63 static this() | |
64 { | |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
65 Logger root = Log.getRootLogger(); |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
66 // Set the level here, but set it again once options have been loaded: |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
67 debug root.setLevel(root.Level.Trace); |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
68 else root.setLevel(root.Level.Info); |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
69 // Temporarily log to the console (until we've found paths and loaded options): |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
70 root.addAppender(new ConsoleAppender); |
20 | 71 } |
72 static ~this() | |
73 { | |
74 } | |
75 | |
76 /** | |
77 * Init class | |
78 * | |
79 * A scope class created at beginning of the program and destroyed at the end; thus the CTOR | |
80 * handles program initialisation and the DTOR handles program cleanup. | |
81 */ | |
82 scope class Init | |
83 { | |
25
2c28ee04a4ed
Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
24
diff
changeset
|
84 //private bool failure = false; // set true on failure during init, so that clean |
20 | 85 private static Logger logger; |
86 static this() { | |
63
66d555da083e
Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
56
diff
changeset
|
87 logger = Log.getLogger ("mde.setup.Init"); |
20 | 88 } |
89 | |
29
f985c28c0ec9
A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
28
diff
changeset
|
90 /** this() − initialisation |
20 | 91 * |
92 * Runs general initialisation code, in a threaded manner where this isn't difficult. | |
29
f985c28c0ec9
A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
28
diff
changeset
|
93 * If any init fails, cleanup is still handled by ~this(). |
20 | 94 * |
29
f985c28c0ec9
A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
28
diff
changeset
|
95 * Init order: 1. Pre-init (loads components needed by most init functions). 2. Dynamic library |
f985c28c0ec9
A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
28
diff
changeset
|
96 * loading (load any dynamic libraries first, so that if loading fails nothing else need be |
f985c28c0ec9
A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
28
diff
changeset
|
97 * done). 3. Init functions (threaded functions handling the rest of initialisation). |
f985c28c0ec9
A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
28
diff
changeset
|
98 */ |
20 | 99 /* In a single-threaded function this could be done with: |
100 * scope(failure) cleanup; | |
101 * This won't work with a threaded init function since any threads completing succesfully will | |
102 * not clean-up, and a fixed list of clean-up functions cannot be used since clean-up functions | |
103 * must not run where the initialisation functions have failed. | |
104 * Hence a list of clean-up functions is built similarly to scope(failure) --- see addCleanupFct. | |
105 */ | |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
106 this(char[][] cmdArgs) |
20 | 107 { |
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
|
108 debug logger.trace ("Init: starting"); |
20 | 109 |
110 //BEGIN Pre-init (stage init0) | |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
111 //FIXME: warn on invalid arguments, including base-path on non-Windows |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
112 // But Arguments doesn't support this (in tango 0.99.6 and in r3563). |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
113 Arguments args; |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
114 try { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
115 args = new Arguments(); |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
116 args.define("base-path").parameters(1); |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
117 args.define("data-path").parameters(1,-1); |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
118 args.define("conf-path").parameters(1,-1); |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
119 args.define("paths"); |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
120 args.define("q").aliases(["quick-exit"]); |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
121 args.define("help").aliases(["h"]); |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
122 args.parse(cmdArgs); |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
123 if (args.contains("help")) // lazy way to print help |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
124 throw new InitException ("Help requested"); // and stop |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
125 } catch (Exception e) { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
126 printUsage(cmdArgs[0]); |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
127 throw new InitException ("Parsing arguments failed: "~e.msg); |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
128 } |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
129 |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
130 // Find/create paths: |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
131 try { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
132 if (args.contains("data-path")) |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
133 paths.extraDataPath = args["data-path"]; |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
134 if (args.contains("conf-path")) |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
135 paths.extraConfPath = args["conf-path"]; |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
136 if (args.contains("base-path")) |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
137 paths.resolvePaths (args["base-path"]); |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
138 else |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
139 paths.resolvePaths(); |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
140 } catch (Exception e) { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
141 throw new InitException ("Resolving paths failed: " ~ e.msg); |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
142 } |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
143 if (args.contains("paths")) { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
144 paths.mdeDirectory.printPaths; |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
145 throw new InitException ("Paths requested"); // lazy way to stop |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
146 } |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
147 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
|
148 |
20 | 149 /* 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
|
150 * 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
|
151 * 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
|
152 * It's a really good idea to let the options apply to all other loading */ |
20 | 153 try { |
154 Options.load(); | |
155 } catch (optionsLoadException e) { | |
25
2c28ee04a4ed
Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
24
diff
changeset
|
156 throw new InitException ("Loading options failed: " ~ e.msg); |
20 | 157 } |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
158 debug logger.trace ("Init: loaded options successfully"); |
20 | 159 |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
160 // 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
|
161 Logger root; |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
162 try { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
163 enum LOG { |
55
f3d8c0441408
Implemented gl.texture (without testing) & fixed log options adjusted previously.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
164 LEVEL = 0xF, // mask for log level |
f3d8c0441408
Implemented gl.texture (without testing) & fixed log options adjusted previously.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
165 CONSOLE = 0x1000, // log to console? |
f3d8c0441408
Implemented gl.texture (without testing) & fixed log options adjusted previously.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
166 ROLLFILE= 0x2000 // use Rolling/Switching File Appender? |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
167 } |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
168 |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
169 // Where logging is done to is determined at compile-time, currently just via static ifs. |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
170 root = Log.getRootLogger(); |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
171 root.clearAppenders; // we may no longer want to log to the console |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
172 |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
173 // Now re-set the logging level, using the value from the config file: |
55
f3d8c0441408
Implemented gl.texture (without testing) & fixed log options adjusted previously.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
174 root.setLevel (cast(Log.Level) (miscOpts.logOptions & LOG.LEVEL), true); |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
175 |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
176 // Log to a file (first appender so root seperator messages don't show on console): |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
177 if (miscOpts.logOptions & LOG.ROLLFILE) { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
178 version (SwitchAppender) { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
179 root.addAppender (new SwitchingFileAppender (paths.logDir~"/log-.txt", 5)); |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
180 } else { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
181 // Use 2 log files with a maximum size of 1 MB: |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
182 root.addAppender (new RollingFileAppender (paths.logDir~"/log-.txt", 2, 1024*1024)); |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
183 root.info (""); // some kind of separation between runs |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
184 root.info (""); |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
185 } |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
186 } else if (!(miscOpts.logOptions & LOG.CONSOLE)) { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
187 // make sure at least one logger is enabled |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
188 miscOpts.set!(int) ("logOptions", miscOpts.logOptions | LOG.CONSOLE); |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
189 } |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
190 if (miscOpts.logOptions & LOG.CONSOLE) { // Log to the console |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
191 root.addAppender(new ConsoleAppender); |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
192 } |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
193 logger.info ("Starting mde [no version] on " ~ TimeStamp.toString(WallClock.now)); |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
194 } catch (Exception e) { |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
195 // 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
|
196 // logger and if that fails let the exception kill the program. |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
197 root.clearAppenders; |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
198 root.addAppender (new ConsoleAppender); |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
199 logger.warn ("Exception while setting up the logger; logging to the console instead."); |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
200 } |
20 | 201 |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
202 // a debugging option: |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
203 imde.run = !args.contains("q") && !miscOpts.exitImmediately; |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
204 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
|
205 |
f985c28c0ec9
A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
28
diff
changeset
|
206 //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
|
207 /* 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
|
208 * 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
|
209 try { |
f985c28c0ec9
A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
28
diff
changeset
|
210 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
|
211 // 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
|
212 //DerelictSDLImage.load(); |
29
f985c28c0ec9
A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
28
diff
changeset
|
213 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
|
214 DerelictFT.load(); |
29
f985c28c0ec9
A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
28
diff
changeset
|
215 } catch (DerelictException de) { |
f985c28c0ec9
A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
28
diff
changeset
|
216 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
|
217 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
|
218 |
f985c28c0ec9
A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
28
diff
changeset
|
219 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
|
220 } |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
221 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
|
222 //END Load dynamic libraries |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
223 //END Pre-init |
29
f985c28c0ec9
A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
28
diff
changeset
|
224 |
20 | 225 |
226 //BEGIN Init (stages init2, init4) | |
227 /* Call init functions. | |
228 * | |
229 * Current method is to try using threads, and on failure assume no threads were actually | |
230 * created and run functions in a non-threaded manner. */ | |
231 | |
21
a60cbb7359dd
Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
232 try { |
25
2c28ee04a4ed
Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
24
diff
changeset
|
233 if (runStageThreaded (init)) runStageForward (init); |
20 | 234 } |
235 catch (InitStageException) { // This init stage failed. | |
25
2c28ee04a4ed
Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
24
diff
changeset
|
236 // FIXME: check DTOR still runs |
2c28ee04a4ed
Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
24
diff
changeset
|
237 throw new InitException ("An init function failed (see above message(s))"); |
20 | 238 } |
239 //END Init | |
240 | |
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
|
241 debug logger.trace ("Init: done"); |
20 | 242 } |
243 | |
244 /** DTOR - runs cleanup functions. */ | |
245 ~this() | |
246 { | |
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
|
247 debug logger.trace ("Cleanup: starting"); |
20 | 248 |
249 Options.save(); // save options... do so here for now | |
250 | |
25
2c28ee04a4ed
Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
24
diff
changeset
|
251 // General cleanup: |
2c28ee04a4ed
Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
24
diff
changeset
|
252 try { |
2c28ee04a4ed
Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
24
diff
changeset
|
253 if (runStageThreaded (cleanup)) runStageReverse (cleanup); |
2c28ee04a4ed
Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
24
diff
changeset
|
254 } |
2c28ee04a4ed
Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
24
diff
changeset
|
255 catch (InitStageException) { |
2c28ee04a4ed
Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
24
diff
changeset
|
256 // Nothing else to do but report: |
2c28ee04a4ed
Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
24
diff
changeset
|
257 logger.error ("One or more cleanup functions failed!"); |
2c28ee04a4ed
Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
24
diff
changeset
|
258 } |
20 | 259 |
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
|
260 debug logger.trace ("Cleanup: done"); |
20 | 261 } |
262 | |
263 | |
264 //BEGIN runStage... | |
265 private static { | |
266 /* The following three functions, runStage*, each run all functions in a stage in some order, | |
267 * catching any exceptions thrown by the functions (although this isn't guaranteed for threads), | |
21
a60cbb7359dd
Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
268 * and throw an InitStageException on initFailure. */ |
20 | 269 |
29
f985c28c0ec9
A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
28
diff
changeset
|
270 const LOG_IF_MSG = "Init function "; |
f985c28c0ec9
A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
28
diff
changeset
|
271 const LOG_CF_MSG = "Cleanup function "; |
f985c28c0ec9
A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
28
diff
changeset
|
272 const LOG_F_START = " - running"; |
f985c28c0ec9
A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
28
diff
changeset
|
273 const LOG_F_END = " - completed"; |
45
0fd51d2c6c8a
Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
274 const LOG_F_BAD = " - failed"; |
29
f985c28c0ec9
A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
28
diff
changeset
|
275 const LOG_F_FAIL = " - failed: "; |
20 | 276 /* Runs all functions consecutively, first-to-last. |
277 * If any function fails, halts immediately. */ | |
278 void runStageForward (InitStage s) { | |
279 foreach (func; s.funcs) { | |
21
a60cbb7359dd
Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
280 if (initFailure) break; |
20 | 281 try { |
29
f985c28c0ec9
A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
28
diff
changeset
|
282 debug logger.trace (LOG_IF_MSG ~ func.name ~ LOG_F_START); |
f985c28c0ec9
A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
28
diff
changeset
|
283 func.func(); |
45
0fd51d2c6c8a
Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
284 debug logger.trace (LOG_IF_MSG ~ func.name ~ (initFailure ? LOG_F_BAD : LOG_F_END)); |
20 | 285 } catch (Exception e) { |
29
f985c28c0ec9
A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
28
diff
changeset
|
286 logger.fatal (LOG_IF_MSG ~ func.name ~ LOG_F_FAIL ~ |
f985c28c0ec9
A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
28
diff
changeset
|
287 ((e.msg is null || e.msg == "") ? "(no failure message)" : e.msg) ); |
20 | 288 |
21
a60cbb7359dd
Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
289 setInitFailure(); |
20 | 290 } |
291 } | |
21
a60cbb7359dd
Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
292 |
a60cbb7359dd
Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
293 if (initFailure) throw new InitStageException; // Problem running; abort and cleanup from here. |
20 | 294 } |
295 /* Runs all functions consecutively, last-to-first. | |
296 * If any function fails, continue until all have been run. */ | |
297 void runStageReverse (InitStage s) { | |
298 foreach_reverse (func; s.funcs) { | |
299 try { | |
29
f985c28c0ec9
A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
28
diff
changeset
|
300 debug logger.trace (LOG_CF_MSG ~ func.name ~ LOG_F_START); |
f985c28c0ec9
A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
28
diff
changeset
|
301 func.func(); |
45
0fd51d2c6c8a
Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
302 debug logger.trace (LOG_CF_MSG ~ func.name ~ (initFailure ? LOG_F_BAD : LOG_F_END)); |
20 | 303 } catch (Exception e) { |
29
f985c28c0ec9
A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
28
diff
changeset
|
304 logger.fatal (LOG_CF_MSG ~ func.name ~ LOG_F_FAIL ~ |
f985c28c0ec9
A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
28
diff
changeset
|
305 ((e.msg is null || e.msg == "") ? "(no failure message)" : e.msg) ); |
20 | 306 |
21
a60cbb7359dd
Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
307 setInitFailure(); |
20 | 308 } |
309 } | |
21
a60cbb7359dd
Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
310 if (initFailure) throw new InitStageException; // Problem running; abort and cleanup from here. |
20 | 311 } |
312 /* Tries running functions in a threaded way. Returns false if successful, true if not but | |
313 * functions should be run without threads. */ | |
314 bool runStageThreaded (InitStage s) { | |
24
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
315 if (!miscOpts.useThreads) return true; // Use unthreaded route instead |
20 | 316 |
317 ThreadGroup tg; | |
318 try { // creating/starting threads could fail | |
319 tg = new ThreadGroup; | |
29
f985c28c0ec9
A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
28
diff
changeset
|
320 foreach (func; s.funcs) { // Start all threads |
f985c28c0ec9
A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
28
diff
changeset
|
321 debug logger.trace (LOG_IF_MSG ~ func.name ~ LOG_F_START); |
f985c28c0ec9
A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
28
diff
changeset
|
322 tg.create(func.func); |
45
0fd51d2c6c8a
Several changes to resising windows and layout widgets. This commit still has some bugs.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
43
diff
changeset
|
323 debug logger.trace (LOG_IF_MSG ~ func.name ~ (initFailure ? LOG_F_BAD : LOG_F_END)); |
29
f985c28c0ec9
A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
28
diff
changeset
|
324 } |
20 | 325 } catch (ThreadException e) { // Problem with threading; try without threads |
24
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
326 logger.error ("Caught ThreadException while trying to create threads:"); |
32eff0e01c05
Only locally-changed options are stored in user-config now. Log levels revised.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
21
diff
changeset
|
327 logger.error (e.msg); |
29
f985c28c0ec9
A new GUI widget plus changes to the init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
28
diff
changeset
|
328 logger.info ("Will disable threads and continue, assuming no threads were created."); |
20 | 329 |
64
cc3763817b8a
Overhauled Options so that it now uses templates and mixins for type-specific internals, and supported types can be adjusted via just one list.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
330 miscOpts.set!(bool)("useThreads", false); // Disable threads entirely |
20 | 331 return true; // Try again without threads |
332 } | |
333 | |
334 /* Wait for all threads to complete. | |
335 * | |
336 * If something went wrong, we still need to do this before cleaning up. | |
337 */ | |
338 foreach (t; tg) { | |
339 try { | |
340 t.join (true); | |
341 } catch (Exception e) { | |
342 // Relying on catching exceptions thrown by other threads is a bad idea. | |
343 // Hence all threads should catch their own exceptions and return safely. | |
344 | |
345 logger.fatal ("Unhandled exception from Init function:"); | |
346 logger.fatal (e.msg); | |
347 | |
21
a60cbb7359dd
Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
348 setInitFailure (); // abort (but join other threads first) |
20 | 349 } |
350 } | |
21
a60cbb7359dd
Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
351 |
a60cbb7359dd
Window settings now come from options, and may use OpenGL (enabled/disabled at compile time).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
20
diff
changeset
|
352 if (initFailure) throw new InitStageException; // Problem running; abort and cleanup from here. |
20 | 353 return false; // Done successfully |
354 } | |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
355 //END runStage... |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
356 |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
357 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
|
358 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
|
359 Cout ("Usage:").newline; |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
360 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
|
361 version(Windows) |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
362 Cout ( |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
363 ` --base-path path Use path as the base (install) path (Windows only). It |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
364 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
|
365 Cout ( |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
366 ` --data-path path(s) Add path(s) as a potential location for data files. |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
367 First path argument becomes the preffered location to |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
368 load data files from. |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
369 --conf-path path(s) Add path(s) as a potential location for config files. |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
370 Configuration in the first path given take highest |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
371 priority. |
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
372 --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
|
373 --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
|
374 --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
|
375 } |
20 | 376 } |
377 | |
378 debug (mdeUnitTest) unittest { | |
379 /* Fake init and cleanup. Use unittest-specific init and cleanup InitStages to avoid | |
380 * messing other init/cleanup up. */ | |
381 static InitStage initUT, cleanupUT; | |
382 | |
383 static bool initialised = false; | |
384 static void cleanupFunc1 () { | |
385 initialised = false; | |
386 } | |
387 static void cleanupFunc2 () { | |
388 assert (initialised == true); | |
389 } | |
390 | |
391 static void initFunc () { | |
392 initialised = true; | |
30
467c74d4804d
Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
29
diff
changeset
|
393 cleanupUT.addFunc (&cleanupFunc1, "UT cleanup 1"); |
467c74d4804d
Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
29
diff
changeset
|
394 cleanupUT.addFunc (&cleanupFunc2, "UT cleanup 2"); |
20 | 395 } |
396 | |
30
467c74d4804d
Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
29
diff
changeset
|
397 initUT.addFunc (&initFunc, "UT init"); |
20 | 398 |
399 runStageForward (initUT); | |
400 assert (initialised); | |
401 | |
402 runStageReverse (cleanupUT); | |
403 assert (!initialised); | |
404 | |
405 logger.info ("Unittest complete."); | |
406 } | |
407 } |