Mercurial > projects > openmelee
annotate main.d @ 13:e1004697cae1
tracking
author | zzzzrrr <mason.green@gmail.com> |
---|---|
date | Mon, 23 Mar 2009 08:02:23 -0400 |
parents | 2ecd16840900 |
children | af1e8620f027 |
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 |
12 | 33 import tango.io.Stdout : Stdout; |
34 | |
0 | 35 version(distrib) import tango.io.vfs.ZipFolder; |
36 import tango.time.StopWatch; | |
37 import fc = tango.text.convert.Float : toString; | |
38 import tango.util.log.Trace; | |
39 import tango.math.Math; | |
40 | |
41 import xf.core.JobHub; | |
42 import xf.hybrid.Hybrid; | |
43 import xf.hybrid.backend.GL; | |
44 import xf.omg.core.LinearAlgebra; | |
45 | |
7
2217fd1fe384
added angular and linear velocity limit
zzzzrrr <mason.green@gmail.com>
parents:
5
diff
changeset
|
46 import blaze.common.bzMath: bzVec2; |
2217fd1fe384
added angular and linear velocity limit
zzzzrrr <mason.green@gmail.com>
parents:
5
diff
changeset
|
47 |
2 | 48 import openmelee.melee; |
49 import openmelee.render; | |
11
d998bf1b0654
Added utilities and AI; fixed steer
Mason Green <mason.green@gmail.com>
parents:
9
diff
changeset
|
50 import openmelee.ai; |
0 | 51 |
52 const ITERS_PER_SECOND = 60; | |
53 | |
54 void main() { | |
55 | |
56 Settings settings; | |
57 float timeStep = settings.hz > 0.0f ? 1.0f / settings.hz : 0.0f; | |
58 version(distrib) gui.vfs.mount(new ZipFolder("./gui.zip")); | |
59 scope cfg = loadHybridConfig("./gui.cfg"); | |
60 scope renderer = new Renderer; | |
61 auto whut = new Render(&settings); | |
11
d998bf1b0654
Added utilities and AI; fixed steer
Mason Green <mason.green@gmail.com>
parents:
9
diff
changeset
|
62 auto ai = new AI(whut.ship2); |
d998bf1b0654
Added utilities and AI; fixed steer
Mason Green <mason.green@gmail.com>
parents:
9
diff
changeset
|
63 |
0 | 64 gui.begin(cfg).retained; |
65 gui.push(`main`); | |
66 GLViewport(`glview`).renderingHandler(&whut.draw) | |
67 .addHandler(&whut.onClick) | |
68 .addHandler(&whut.onMove) | |
69 .addHandler(&whut.onKey) | |
70 .addHandler(&whut.onDT) | |
71 .addHandler(&whut.onMouseEnter) | |
72 .addHandler(&whut.onMouseLeave) | |
73 .grabKeyboardFocus; | |
74 gui.pop(); | |
75 gui.immediate.end; | |
76 | |
77 StopWatch timer; | |
78 | |
79 jobHub.addRepeatableJob( { | |
12 | 80 // Update AI |
81 ai.move(whut.ship1); | |
9 | 82 // Update physics |
83 whut.world.step(timeStep, settings.velocityIterations, | |
84 settings.positionIterations); | |
0 | 85 }, ITERS_PER_SECOND); |
86 | |
87 bool running = true; | |
88 | |
89 jobHub.addPreFrameJob( { | |
12 | 90 whut.ship1.updateState(); |
91 whut.ship2.updateState(); | |
7
2217fd1fe384
added angular and linear velocity limit
zzzzrrr <mason.green@gmail.com>
parents:
5
diff
changeset
|
92 whut.ship1.limitVelocity(); |
9 | 93 whut.ship2.limitVelocity(); |
0 | 94 }); |
95 | |
96 jobHub.addPostFrameJob( { | |
97 gui.begin(cfg); | |
98 gui.push(`main`); | |
99 if (gui().getProperty!(bool)("frame.closeClicked")) { | |
100 running = false; | |
101 } | |
2 | 102 |
0 | 103 |
104 if(whut.thrust) { | |
105 whut.ship1.thrust(); | |
106 } | |
107 | |
108 gui().setProperty!(bool)("showCursor", true); | |
109 gui.pop(); | |
110 gui.end; | |
111 gui.render(renderer); | |
112 | |
113 { | |
114 vec2 p1 = vec2.from(whut.ship1.rBody.position); | |
115 vec2 p2 = vec2.from(whut.ship2.rBody.position); | |
116 vec2 distance = p1 - p2; | |
2 | 117 float d = distance.length; |
7
2217fd1fe384
added angular and linear velocity limit
zzzzrrr <mason.green@gmail.com>
parents:
5
diff
changeset
|
118 whut.zoom = bzClamp(1/d*1000, 5, 50); |
0 | 119 whut.viewCenter = p1 - (distance * 0.5f); |
120 } | |
121 | |
122 }); | |
123 | |
124 while (running && !whut.quit) { | |
125 float delta = timer.stop; | |
126 timer.start; | |
127 jobHub.update(delta); | |
128 } | |
129 } |