Mercurial > projects > mde
annotate mde/mainLoop.d @ 179:1f9d00f392bd default tip
Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Optimised when ServiceContentList.opCall is called, I think without breaking anything.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Tue, 15 Sep 2009 20:09:59 +0200 |
parents | e45226d3deae |
children |
rev | line source |
---|---|
36
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
1 /* LICENSE BLOCK |
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
2 Part of mde: a Modular D game-oriented Engine |
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
3 Copyright © 2007-2008 Diggory Hardy |
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
4 |
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
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 |
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
6 of the GNU General Public License as published by the Free Software Foundation, either |
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
7 version 2 of the License, or (at your option) any later version. |
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
8 |
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
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; |
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
11 See the GNU General Public License for more details. |
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
12 |
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
13 You should have received a copy of the GNU General Public License |
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
15 |
132
264028f4115a
Cleaned up mde.imde and a couple of widget functions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
128
diff
changeset
|
16 /****************************************************************************** |
170
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
137
diff
changeset
|
17 * Adds some standard functionality to the main loop. |
132
264028f4115a
Cleaned up mde.imde and a couple of widget functions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
128
diff
changeset
|
18 *****************************************************************************/ |
137
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
132
diff
changeset
|
19 module mde.mainLoop; |
36
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
20 |
137
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
132
diff
changeset
|
21 import mde.imde; |
36
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
22 import mde.scheduler.Scheduler; |
137
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
132
diff
changeset
|
23 import mde.events; |
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
132
diff
changeset
|
24 import mde.content.AStringContent; // pollInterval option |
36
57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
25 |
75
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
36
diff
changeset
|
26 static this () { |
132
264028f4115a
Cleaned up mde.imde and a couple of widget functions.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
128
diff
changeset
|
27 // Make available to all importing modules: |
75
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
36
diff
changeset
|
28 mainSchedule = new Scheduler; |
137
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
132
diff
changeset
|
29 mainSchedule.add (mainSchedule.getNewID, &mde.events.pollEvents).frame = true; |
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
132
diff
changeset
|
30 // Polling interval of main loop; use old name to save renaming: |
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
132
diff
changeset
|
31 pollInterval = new DoubleContent ("MiscOptions.pollInterval"); |
170
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
137
diff
changeset
|
32 pollInterval.addCallback (delegate void(IContent) { |
137
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
132
diff
changeset
|
33 if (pollInterval() !<= 0.1 || pollInterval() !>= 0.0) |
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
132
diff
changeset
|
34 pollInterval = 0.01; |
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
132
diff
changeset
|
35 mainInterval = pollInterval(); |
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
132
diff
changeset
|
36 }); |
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
132
diff
changeset
|
37 |
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
132
diff
changeset
|
38 version (mdeBenchmark) { |
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
132
diff
changeset
|
39 // Print fps every 5 seconds: |
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
132
diff
changeset
|
40 void frameRateTest (TimeSpan elapsed) { |
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
132
diff
changeset
|
41 static TimeSpan total; |
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
132
diff
changeset
|
42 static size_t num; |
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
132
diff
changeset
|
43 total += elapsed; |
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
132
diff
changeset
|
44 ++num; |
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
132
diff
changeset
|
45 if (total.seconds > 5) { |
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
132
diff
changeset
|
46 logger.info ("{0} frames in {1:f3} seconds: {2:f3} fps", num, total.interval, num/total.interval); |
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
132
diff
changeset
|
47 total = TimeSpan.zero; |
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
132
diff
changeset
|
48 num = 0; |
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
132
diff
changeset
|
49 } |
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
132
diff
changeset
|
50 mainSchedule.request (SCHEDULE.DRAW); // force draw every frame |
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
132
diff
changeset
|
51 mainInterval = 0.0; // force zero wait |
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
132
diff
changeset
|
52 } |
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
132
diff
changeset
|
53 mainSchedule.add (mainSchedule.getNewID, &frameRateTest).frame = true; |
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
132
diff
changeset
|
54 } |
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
132
diff
changeset
|
55 |
75
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
36
diff
changeset
|
56 } |
25cb7420dc91
A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
36
diff
changeset
|
57 |
137
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
132
diff
changeset
|
58 DoubleContent pollInterval; |
9f035cd139c6
BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
132
diff
changeset
|
59 double mainInterval; /// Polling interval of main loop (kept in sync with pollInterval) |