Mercurial > projects > mde
annotate mde/mde.d @ 86:79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
This (and the previous) commit are the result of several quite significant changes to mde. All the unittests run, but it hasn't had a huge amount of testing so don't be surprised if bugs show up.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Fri, 12 Sep 2008 17:36:14 +0100 |
parents | 56c0ddd90193 |
children | 97e6dce08037 |
rev | line source |
---|---|
17
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
16
diff
changeset
|
1 /* LICENSE BLOCK |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
16
diff
changeset
|
2 Part of mde: a Modular D game-oriented Engine |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
16
diff
changeset
|
3 Copyright © 2007-2008 Diggory Hardy |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
16
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. |
17
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
16
diff
changeset
|
8 |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
16
diff
changeset
|
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
16
diff
changeset
|
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
16
diff
changeset
|
11 See the GNU General Public License for more details. |
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
16
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/>. */ |
17
5f90774ea1ef
Applied the GNU GPL v2 to mde.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
16
diff
changeset
|
15 |
0 | 16 /** Modular D Engine |
17 * | |
83
2813ac68576f
Start of creating a separate gui demo module and leaving mde.d for testing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
18 * This module contains a minimal main() function. Practically, it is useful for running unittests |
2813ac68576f
Start of creating a separate gui demo module and leaving mde.d for testing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
19 * and some other testing. It also serves as a basic example program. |
0 | 20 */ |
21 module mde.mde; | |
22 | |
36
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
31
diff
changeset
|
23 import mde.imde; // this module's interface for external modules |
84 | 24 import mde.events; // pollEvents() // NOTE: Must be imported before Init, otherwise fonts don't display properly (why??) |
83
2813ac68576f
Start of creating a separate gui demo module and leaving mde.d for testing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
25 import mde.setup.Init; // initialization |
63
66d555da083e
Moved many modules/packages to better reflect usage.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
53
diff
changeset
|
26 import mde.lookup.Options; // pollInterval option |
83
2813ac68576f
Start of creating a separate gui demo module and leaving mde.d for testing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
27 import mde.scheduler.Scheduler; // mainSchedule |
85
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
28 import mde.setup.Screen; // Screen.draw() |
0 | 29 |
25
2c28ee04a4ed
Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
24
diff
changeset
|
30 import tango.core.Thread : Thread; // Thread.sleep() |
2c28ee04a4ed
Some minor and some futile efforts.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
24
diff
changeset
|
31 import tango.time.Clock; // Clock.now() |
4
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
3
diff
changeset
|
32 import tango.util.log.Log : Log, Logger; |
86
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
33 debug (mdeUnitTest) { // These modules contain unittests which wouldn't be run otherwise. |
82
ac1e3fd07275
New ssi file format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
81
diff
changeset
|
34 import mde.file.ssi; |
ac1e3fd07275
New ssi file format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
81
diff
changeset
|
35 import mde.file.mergetag.mdeUT; |
ac1e3fd07275
New ssi file format.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
81
diff
changeset
|
36 } |
4
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
3
diff
changeset
|
37 |
86
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
38 //BEGIN A simple drawable to print a message in the window. |
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
39 import mde.font.font; |
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
40 class SimpleDrawable : Screen.IDrawable { |
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
41 this () { |
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
42 msg = "Welcome to mde.\nThis executable is only for testing, and\nas such doesn't do anything interesting."; |
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
43 debug msg ~= "\nRunning in debug mode."; |
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
44 font = FontStyle.get("default");// get the default or fallback font |
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
45 } |
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
46 void sizeEvent (int,int) {}; // Don't care what the size is |
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
47 void draw () { |
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
48 font.textBlock (16,32, msg, textCache, Colour.WHITE); |
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
49 } |
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
50 char[] msg; |
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
51 FontStyle font; |
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
52 TextBlock textCache; |
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
53 } |
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
54 //END A simple drawable to print a message in the window. |
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
55 |
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
56 |
53
f000d6cd0f74
Changes to paths, command line arguments and font LCD rendering.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
45
diff
changeset
|
57 int main(char[][] args) |
0 | 58 { |
86
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
59 Logger logger = Log.getLogger ("mde.mde"); |
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
60 |
83
2813ac68576f
Start of creating a separate gui demo module and leaving mde.d for testing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
61 // If compiled with unittests, notify that they completed and exit: |
68
3a737e06dc50
Unittests: fixes and changes. Plus some doc changes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
64
diff
changeset
|
62 debug (mdeUnitTest) { |
3a737e06dc50
Unittests: fixes and changes. Plus some doc changes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
64
diff
changeset
|
63 logger.info ("Compiled unittests have completed; terminating."); |
3a737e06dc50
Unittests: fixes and changes. Plus some doc changes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
64
diff
changeset
|
64 return 0; |
3a737e06dc50
Unittests: fixes and changes. Plus some doc changes.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
64
diff
changeset
|
65 } |
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
|
66 |
83
2813ac68576f
Start of creating a separate gui demo module and leaving mde.d for testing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
67 scope Init init = new Init(args); // initialize mde |
36
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
31
diff
changeset
|
68 |
86
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
69 // Note: must create the drawable after init, since it uses font (initialized in init). |
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
70 Screen.addDrawable (new SimpleDrawable); // a drawable to print a message. |
79d816b3e2d2
New InitStage system, Screen & Screen.Drawable, separate testing and guiDemo binaries.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
85
diff
changeset
|
71 |
83
2813ac68576f
Start of creating a separate gui demo module and leaving mde.d for testing.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
75
diff
changeset
|
72 // Make sure pollInterval has a sane value. FIXME: get Options class to enforce range |
43
1530d9c04d4d
Column/row resizing implemented for GridLayoutWidget (finally)!
Diggory Hardy <diggory.hardy@gmail.com>
parents:
36
diff
changeset
|
73 if (miscOpts.pollInterval !<= 1.0 || miscOpts.pollInterval !>= 0.0) |
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
|
74 miscOpts.set!(double) ("pollInterval", 0.01); |
11
b940f267419e
Options class created & changes to mergetag exception messages.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
10
diff
changeset
|
75 |
30
467c74d4804d
Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
27
diff
changeset
|
76 //BEGIN Main loop setup |
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
|
77 /* Note: the main loop is currently controlled by the scheduler. This is not really ideal, |
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
|
78 * since it provides no direct control of the order in which components are executed and does |
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
|
79 * not allow running components simultaeneously with threads. |
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
|
80 * Note: probably drawing should start at the beginning of the loop and glFlush()/swapBuffers |
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
|
81 * be called at the end to optimise. */ |
85
56c0ddd90193
Intermediate commit (not stable). Changes to init system.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
84
diff
changeset
|
82 mainSchedule.add (SCHEDULE.DRAW, &Screen.draw); // Draw, per event only. |
36
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
31
diff
changeset
|
83 mainSchedule.add (mainSchedule.getNewID, &mde.events.pollEvents).frame = true; |
30
467c74d4804d
Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
27
diff
changeset
|
84 //END Main loop setup |
467c74d4804d
Major changes to the scheduler, previously only used by the main loop.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
27
diff
changeset
|
85 |
36
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
31
diff
changeset
|
86 while (run) { |
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
31
diff
changeset
|
87 mainSchedule.execute (Clock.now()); |
4
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
3
diff
changeset
|
88 |
36
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
31
diff
changeset
|
89 Thread.sleep (miscOpts.pollInterval); // sleep this many seconds |
4
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
3
diff
changeset
|
90 } |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
3
diff
changeset
|
91 |
9a990644948c
Many changes: upgraded to tango 0.99.4, reorganised mde/input, large changes to mde/mergetag and mde/init, separated off test/MTTest.d and more.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
3
diff
changeset
|
92 return 0; // cleanup handled by init's DTOR |
0 | 93 } |