Mercurial > projects > openmelee
comparison main.d @ 0:c10bc63824e7
Initial commit!
author | zzzzrrr <mason.green@gmail.com> |
---|---|
date | Fri, 20 Mar 2009 06:41:25 -0400 |
parents | |
children | a40d066ebbd1 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c10bc63824e7 |
---|---|
1 /* | |
2 * Copyright (c) 2009, Mason Green (zzzzrrr) | |
3 * | |
4 * All rights reserved. | |
5 * | |
6 * Redistribution and use in source and binary forms, with or without modification, | |
7 * are permitted provided that the following conditions are met: | |
8 * | |
9 * * Redistributions of source code must retain the above copyright notice, | |
10 * this list of conditions and the following disclaimer. | |
11 * * Redistributions in binary form must reproduce the above copyright notice, | |
12 * this list of conditions and the following disclaimer in the documentation | |
13 * and/or other materials provided with the distribution. | |
14 * * Neither the name of the polygonal nor the names of its contributors may be | |
15 * used to endorse or promote products derived from this software without specific | |
16 * prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |
22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
25 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
26 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 */ | |
30 module melee.main; | |
31 | |
32 import tango.io.Stdout : Stdout; | |
33 | |
34 version(distrib) import tango.io.vfs.ZipFolder; | |
35 import tango.time.StopWatch; | |
36 import fc = tango.text.convert.Float : toString; | |
37 import tango.util.log.Trace; | |
38 import tango.math.Math; | |
39 | |
40 import xf.core.JobHub; | |
41 import xf.hybrid.Hybrid; | |
42 import xf.hybrid.backend.GL; | |
43 import xf.omg.core.LinearAlgebra; | |
44 | |
45 import melee.melee; | |
46 import melee.render; | |
47 | |
48 const ITERS_PER_SECOND = 60; | |
49 | |
50 void main() { | |
51 | |
52 Settings settings; | |
53 float timeStep = settings.hz > 0.0f ? 1.0f / settings.hz : 0.0f; | |
54 version(distrib) gui.vfs.mount(new ZipFolder("./gui.zip")); | |
55 scope cfg = loadHybridConfig("./gui.cfg"); | |
56 scope renderer = new Renderer; | |
57 auto whut = new Render(&settings); | |
58 | |
59 gui.begin(cfg).retained; | |
60 gui.push(`main`); | |
61 GLViewport(`glview`).renderingHandler(&whut.draw) | |
62 .addHandler(&whut.onClick) | |
63 .addHandler(&whut.onMove) | |
64 .addHandler(&whut.onKey) | |
65 .addHandler(&whut.onDT) | |
66 .addHandler(&whut.onMouseEnter) | |
67 .addHandler(&whut.onMouseLeave) | |
68 .grabKeyboardFocus; | |
69 gui.pop(); | |
70 gui.immediate.end; | |
71 | |
72 StopWatch timer; | |
73 | |
74 jobHub.addRepeatableJob( { | |
75 whut.world.step(timeStep, settings.velocityIterations, | |
76 settings.positionIterations); | |
77 }, ITERS_PER_SECOND); | |
78 | |
79 bool running = true; | |
80 | |
81 jobHub.addPreFrameJob( { | |
82 // Clean out the kill list | |
83 uint[] key = whut.killList.keys; | |
84 foreach(k; key) { | |
85 whut.world.destroyBody(whut.killList[k]); | |
86 whut.killList.remove(k); | |
87 } | |
88 }); | |
89 | |
90 jobHub.addPostFrameJob( { | |
91 gui.begin(cfg); | |
92 gui.push(`main`); | |
93 if (gui().getProperty!(bool)("frame.closeClicked")) { | |
94 running = false; | |
95 } | |
96 | |
97 if(whut.thrust) { | |
98 whut.ship1.thrust(); | |
99 } | |
100 | |
101 gui().setProperty!(bool)("showCursor", true); | |
102 gui.pop(); | |
103 gui.end; | |
104 gui.render(renderer); | |
105 | |
106 { | |
107 vec2 p1 = vec2.from(whut.ship1.rBody.position); | |
108 vec2 p2 = vec2.from(whut.ship2.rBody.position); | |
109 vec2 distance = p1 - p2; | |
110 whut.viewCenter = p1 - (distance * 0.5f); | |
111 } | |
112 | |
113 }); | |
114 | |
115 while (running && !whut.quit) { | |
116 float delta = timer.stop; | |
117 timer.start; | |
118 jobHub.update(delta); | |
119 } | |
120 } |