Mercurial > projects > mde
comparison mde/events.d @ 25:2c28ee04a4ed
Some minor and some futile efforts.
Played around with init functions, had problems, gave up and put them back.
Removed idea for multiple init stages; it's not good for performance or simplicity.
Adjusted exception messages.
committer: Diggory Hardy <diggory.hardy@gmail.com>
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Thu, 03 Apr 2008 17:26:52 +0100 |
parents | 32eff0e01c05 |
children | 611f7b9063c6 |
comparison
equal
deleted
inserted
replaced
24:32eff0e01c05 | 25:2c28ee04a4ed |
---|---|
14 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ | 14 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ |
15 | 15 |
16 /// Handles all events from SDL_PollEvent. | 16 /// Handles all events from SDL_PollEvent. |
17 module mde.events; | 17 module mde.events; |
18 | 18 |
19 import mde.scheduler.InitStage; | |
20 import mde.scheduler.runTime; | |
21 | |
22 import global = mde.global; | 19 import global = mde.global; |
23 static import mde.SDL; | 20 static import mde.SDL; |
24 | 21 |
25 import mde.input.input; | 22 import mde.input.input; |
26 import mde.input.exception; | 23 import mde.input.exception; |
24 | |
25 import mde.scheduler.InitFunctions; | |
26 import mde.scheduler.runTime; | |
27 | 27 |
28 import derelict.sdl.events; | 28 import derelict.sdl.events; |
29 | 29 |
30 import tango.util.log.Log : Log, Logger; | 30 import tango.util.log.Log : Log, Logger; |
31 | 31 |
32 private Logger logger; | 32 private Logger logger; |
33 static this() { | 33 static this() { |
34 logger = Log.getLogger ("mde.events"); | 34 logger = Log.getLogger ("mde.events"); |
35 | |
36 init.addFunc (&initInput); | |
35 | 37 |
36 init2.addFunc (&initInput); | 38 Scheduler.perFrame (&mde.events.pollEvents); |
37 | |
38 Scheduler.perFrame (&pollEvents); | |
39 } | 39 } |
40 | 40 |
41 void initInput () { // init2 func | 41 void initInput () { // init func |
42 debug logger.trace ("init2: initInput() started"); | |
43 | |
44 try { | 42 try { |
45 global.input = new Input(); | 43 global.input = new Input(); |
46 global.input.loadConfig (); // (may also create instance) | 44 global.input.loadConfig (); // (may also create instance) |
47 } catch (Exception e) { | 45 |
48 setInitFailure (); // must clean up properly | 46 global.input.addButtonCallback (cast(Input.inputID) 0x0u, delegate void(Input.inputID i, bool b) { |
47 if (b) { | |
48 logger.info ("Quiting..."); | |
49 global.run = false; | |
50 } | |
51 } ); | |
52 } catch (Exception) { | |
53 setInitFailure; | |
49 } | 54 } |
50 | |
51 debug logger.trace ("init2: initInput() finished"); | |
52 } | 55 } |
53 | 56 |
54 void pollEvents (double) { | 57 void pollEvents (double) { |
55 SDL_Event event; | 58 SDL_Event event; |
56 while (SDL_PollEvent (&event)) { | 59 while (SDL_PollEvent (&event)) { |