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