comparison examples/guiDemo.d @ 85:56c0ddd90193

Intermediate commit (not stable). Changes to init system.
author Diggory Hardy <diggory.hardy@gmail.com>
date Thu, 11 Sep 2008 11:33:51 +0100
parents mde/mde.d@e0f1ec7fe73a
children 2a364c7d82c9
comparison
equal deleted inserted replaced
84:e0f1ec7fe73a 85:56c0ddd90193
1 /* LICENSE BLOCK
2 Part of mde: a Modular D game-oriented Engine
3 Copyright © 2007-2008 Diggory Hardy
4
5 This program is free software: you can redistribute it and/or modify it under the terms
6 of the GNU General Public License as published by the Free Software Foundation, either
7 version 2 of the License, or (at your option) any later version.
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
13 You should have received a copy of the GNU General Public License
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */
15
16 /** Main module for a gui demo & testing executable. */
17 module examples.guiDemo;
18
19 import mde.imde; // this module's interface for external modules
20 import mde.events; // pollEvents() // NOTE: Must be imported before Init, otherwise fonts don't display properly (why??)
21 import mde.setup.Init; // initialization
22 import mde.lookup.Options; // pollInterval option
23 import mde.scheduler.Scheduler; // mainSchedule
24 import mde.setup.Screen; // Screen.draw()
25 import mde.setup.InitStage; // StageState
26 import mde.gui.WidgetManager;
27
28 import tango.core.Thread : Thread; // Thread.sleep()
29 import tango.time.Clock; // Clock.now()
30 import tango.util.log.Log : Log, Logger;
31 debug (mdeUnitTest) {
32 import mde.file.ssi;
33 import mde.file.mergetag.mdeUT;
34 }
35
36 int main(char[][] args)
37 {
38 Logger logger = Log.getLogger ("mde.mde");
39 // If compiled with unittests, notify that they completed and exit:
40 debug (mdeUnitTest) {
41 logger.info ("Compiled unittests have completed; terminating.");
42 return 0;
43 }
44
45 // Set up the gui
46 scope WidgetManager gui = new WidgetManager ("gui");
47 StageState guiLoad () { // init func
48 gui.init;
49 gui.loadDesign();
50 return StageState.ACTIVE;
51 }
52 StageState guiSave () {
53 gui.save;
54 return StageState.INACTIVE;
55 }
56 addInitStage ("GuiM", &guiLoad, &guiSave, ["SWnd", "Font"]);
57
58 scope Init init = new Init(args); // initialize mde
59
60 // Make sure pollInterval has a sane value. FIXME: get Options class to enforce range
61 if (miscOpts.pollInterval !<= 1.0 || miscOpts.pollInterval !>= 0.0)
62 miscOpts.set!(double) ("pollInterval", 0.01);
63
64 //BEGIN Main loop setup
65 /* Note: the main loop is currently controlled by the scheduler. This is not really ideal,
66 * since it provides no direct control of the order in which components are executed and does
67 * not allow running components simultaeneously with threads.
68 * Note: probably drawing should start at the beginning of the loop and glFlush()/swapBuffers
69 * be called at the end to optimise. */
70 mainSchedule.add (SCHEDULE.DRAW, &Screen.draw); // Draw, per event only.
71 mainSchedule.add (mainSchedule.getNewID, &mde.events.pollEvents).frame = true;
72 //END Main loop setup
73
74 while (run) {
75 mainSchedule.execute (Clock.now());
76
77 Thread.sleep (miscOpts.pollInterval); // sleep this many seconds
78 }
79
80 return 0; // cleanup handled by init's DTOR
81 }