Mercurial > projects > mde
annotate mde/setup/init2.d @ 68:3a737e06dc50
Unittests: fixes and changes. Plus some doc changes.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Fri, 04 Jul 2008 18:49:16 +0100 |
parents | 66d555da083e |
children | 25cb7420dc91 |
rev | line source |
---|---|
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
1 /* LICENSE BLOCK |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
2 Part of mde: a Modular D game-oriented Engine |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
3 Copyright © 2007-2008 Diggory Hardy |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
4 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify it under the terms |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
6 of the GNU General Public License as published by the Free Software Foundation, either |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
7 version 2 of the License, or (at your option) any later version. |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
8 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
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; |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
11 See the GNU General Public License for more details. |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
12 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
13 You should have received a copy of the GNU General Public License |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
15 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
16 /** This module is the start of implementing the following: |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
17 * |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
18 * Idea: change import direction so this module adds all init functions. All init functions are |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
19 * wrapped in another function before being run in a thread (i.e. run indirectly). Functions fail |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
20 * either by throwing an exception or by returning a boolean. Functions may take parameters, e.g. |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
21 * "out cleanupFunc[]". |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
22 * |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
23 * This should make it much easier to tell what actually happens during init and to order init such |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
24 * that dependencies are honoured. |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
25 * |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
26 * Currently some external modules depend on InitFunctions, while some are set up from here. Once |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
27 * all are set up from here, the Init* modules can be rearranged. */ |
49
bca7e2342d77
Enabled getting the size of a text block (before or after rendering).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
48
diff
changeset
|
28 /* Idea: go back to init being controlled from elsewhere. Add a function to wait for another init |
bca7e2342d77
Enabled getting the size of a text block (before or after rendering).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
48
diff
changeset
|
29 * function to complete (threaded; might need to be done differently for non-threaded). */ |
63
66d555da083e
Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
49
diff
changeset
|
30 module mde.setup.init2; |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
31 |
63
66d555da083e
Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
49
diff
changeset
|
32 import mde.setup.initFunctions; |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
33 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
34 import tango.util.log.Log : Log, Logger; |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
35 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
36 // Modules requiring init code running: |
36
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
37 import imde = mde.imde; |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
38 import mde.gui.Gui; |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
39 import mde.input.Input; |
63
66d555da083e
Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
49
diff
changeset
|
40 import font = mde.font.font; |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
41 |
33
6886402c1545
Started implementing FreeType.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
32
diff
changeset
|
42 // NOTE: error reporting needs a revision |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
43 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
44 private Logger logger; |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
45 static this () { |
63
66d555da083e
Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
49
diff
changeset
|
46 logger = Log.getLogger ("mde.setup.init2"); |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
47 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
48 init.addFunc (&initInput, "initInput"); |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
49 init.addFunc (&guiLoad, "guiLoad"); |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
50 } |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
51 |
33
6886402c1545
Started implementing FreeType.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
32
diff
changeset
|
52 void guiLoad () { // init func |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
53 try { |
49
bca7e2342d77
Enabled getting the size of a text block (before or after rendering).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
48
diff
changeset
|
54 font.FontStyle.initialize; |
39
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
36
diff
changeset
|
55 gui.load (GUI); |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
36
diff
changeset
|
56 cleanup.addFunc (&guiSave, "guiSave"); |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
57 } catch (Exception e) { |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
58 logger.fatal ("guiLoad failed: " ~ e.msg); |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
59 setInitFailure; |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
60 } |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
61 } |
39
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
36
diff
changeset
|
62 void guiSave () { // cleanup func |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
36
diff
changeset
|
63 try { |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
36
diff
changeset
|
64 gui.save (GUI); |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
36
diff
changeset
|
65 } catch (Exception e) { |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
36
diff
changeset
|
66 logger.fatal ("guiSave failed: " ~ e.msg); |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
36
diff
changeset
|
67 setInitFailure; |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
36
diff
changeset
|
68 } |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
36
diff
changeset
|
69 } |
5132301e9ed7
Implemented widget saving.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
36
diff
changeset
|
70 private const GUI = "gui"; |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
71 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
72 void initInput () { // init func |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
73 try { |
68
3a737e06dc50
Unittests: fixes and changes. Plus some doc changes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
63
diff
changeset
|
74 imde.input.loadConfig ("input"); |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
75 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
76 // Quit on escape. NOTE: quit via SDL_QUIT event is handled completely independently! |
36
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
77 imde.input.addButtonCallback (cast(Input.inputID) 0x0u, delegate void(Input.inputID i, bool b) { |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
78 if (b) { |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
79 logger.info ("Quiting..."); |
36
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
34
diff
changeset
|
80 imde.run = false; |
32
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
81 } |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
82 } ); |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
83 } catch (Exception e) { |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
84 logger.fatal ("initInput failed: " ~ e.msg); |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
85 setInitFailure; |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
86 } |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
87 } |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
88 |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
89 /+ Potential wrapper function: |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
90 // Template to call function, catching exceptions: |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
91 void wrap(alias Func) () { |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
92 try { |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
93 Func(); |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
94 } catch (Exception e) { |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
95 logger.fatal (FAIL_MSG); |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
96 logger.fatal (e.msg); |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
97 setInitFailure; |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
98 } |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
99 } |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
100 private const FAIL_MSG = "Unexpected exception caught:"; |
316b0230a849
Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
101 +/ |