Mercurial > projects > openmelee
annotate main.d @ 7:2217fd1fe384
added angular and linear velocity limit
author | zzzzrrr <mason.green@gmail.com> |
---|---|
date | Sat, 21 Mar 2009 19:34:20 -0400 |
parents | 6f455ef24063 |
children | 4ee9e4a0c03b |
rev | line source |
---|---|
0 | 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 */ | |
2 | 30 module openmelee.main; |
0 | 31 |
32 version(distrib) import tango.io.vfs.ZipFolder; | |
33 import tango.time.StopWatch; | |
34 import fc = tango.text.convert.Float : toString; | |
35 import tango.util.log.Trace; | |
36 import tango.math.Math; | |
37 | |
38 import xf.core.JobHub; | |
39 import xf.hybrid.Hybrid; | |
40 import xf.hybrid.backend.GL; | |
41 import xf.omg.core.LinearAlgebra; | |
42 | |
7
2217fd1fe384
added angular and linear velocity limit
zzzzrrr <mason.green@gmail.com>
parents:
5
diff
changeset
|
43 import blaze.common.bzMath: bzVec2; |
2217fd1fe384
added angular and linear velocity limit
zzzzrrr <mason.green@gmail.com>
parents:
5
diff
changeset
|
44 |
2 | 45 import openmelee.melee; |
46 import openmelee.render; | |
0 | 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( { | |
7
2217fd1fe384
added angular and linear velocity limit
zzzzrrr <mason.green@gmail.com>
parents:
5
diff
changeset
|
82 bzVec2 velocity = whut.ship1.rBody.linearVelocity; |
2217fd1fe384
added angular and linear velocity limit
zzzzrrr <mason.green@gmail.com>
parents:
5
diff
changeset
|
83 whut.ship1.limitVelocity(); |
0 | 84 }); |
85 | |
86 jobHub.addPostFrameJob( { | |
87 gui.begin(cfg); | |
88 gui.push(`main`); | |
89 if (gui().getProperty!(bool)("frame.closeClicked")) { | |
90 running = false; | |
91 } | |
2 | 92 |
0 | 93 |
94 if(whut.thrust) { | |
95 whut.ship1.thrust(); | |
96 } | |
97 | |
98 gui().setProperty!(bool)("showCursor", true); | |
99 gui.pop(); | |
100 gui.end; | |
101 gui.render(renderer); | |
102 | |
103 { | |
104 vec2 p1 = vec2.from(whut.ship1.rBody.position); | |
105 vec2 p2 = vec2.from(whut.ship2.rBody.position); | |
106 vec2 distance = p1 - p2; | |
2 | 107 float d = distance.length; |
7
2217fd1fe384
added angular and linear velocity limit
zzzzrrr <mason.green@gmail.com>
parents:
5
diff
changeset
|
108 whut.zoom = bzClamp(1/d*1000, 5, 50); |
0 | 109 whut.viewCenter = p1 - (distance * 0.5f); |
110 } | |
111 | |
112 }); | |
113 | |
114 while (running && !whut.quit) { | |
115 float delta = timer.stop; | |
116 timer.start; | |
117 jobHub.update(delta); | |
118 } | |
119 } |