comparison melee/melee.d @ 27:d63faa81a5e4

removed Dog, added derelict and glfw
author zzzzrrr <mason.green@gmail.com>
date Mon, 30 Mar 2009 12:41:29 -0400
parents 88cca12cc8b9
children 1cc6b8c0acd2
comparison
equal deleted inserted replaced
26:88cca12cc8b9 27:d63faa81a5e4
36 version(distrib) import tango.io.vfs.ZipFolder; 36 version(distrib) import tango.io.vfs.ZipFolder;
37 import tango.time.StopWatch; 37 import tango.time.StopWatch;
38 import fc = tango.text.convert.Float : toString; 38 import fc = tango.text.convert.Float : toString;
39 import tango.util.log.Trace; 39 import tango.util.log.Trace;
40 40
41 import xf.core.JobHub;
42 import xf.hybrid.Hybrid;
43 import xf.hybrid.backend.GL;
44
45 import blaze.common.bzMath : bzVec2; 41 import blaze.common.bzMath : bzVec2;
46 import blaze.bzWorld : bzWorld; 42 import blaze.bzWorld : bzWorld;
47 import blaze.collision.bzCollision : bzAABB; 43 import blaze.collision.bzCollision : bzAABB;
48 44
49 import openmelee.melee.boundaryListener; 45 import openmelee.melee.boundaryListener;
99 ObjectList objectList; 95 ObjectList objectList;
100 Settings settings; 96 Settings settings;
101 float timeStep; 97 float timeStep;
102 const bzVec2 gravity = bzVec2(0.0f, 0.0f); 98 const bzVec2 gravity = bzVec2(0.0f, 0.0f);
103 bool allowSleep; 99 bool allowSleep;
104 Render draw; 100 Render render;
105 101
106 AI ai; 102 AI ai;
107 Human human; 103 Human human;
108 104
109 Ship ship1; 105 Ship ship1;
119 bzContactListener m_contactListener; 115 bzContactListener m_contactListener;
120 ContactPoint[k_maxContactPoints] points; 116 ContactPoint[k_maxContactPoints] points;
121 int pointCount; 117 int pointCount;
122 118
123 this() { 119 this() {
124 120 timeStep = settings.hz > 0.0f ? 1.0f / settings.hz : 0.0f;
125 objectList = new ObjectList; 121 objectList = new ObjectList;
126 }
127
128 void init() {
129
130 timeStep = settings.hz > 0.0f ? 1.0f / settings.hz : 0.0f;
131 version(distrib) gui.vfs.mount(new ZipFolder("./gui.zip"));
132 scope cfg = loadHybridConfig("./gui.cfg");
133 scope renderer = new Renderer;
134
135 m_boundaryListener = new BoundaryListener(this); 122 m_boundaryListener = new BoundaryListener(this);
123
124
136 initWorld(); 125 initWorld();
137 running = true; 126 running = true;
138 127
139 draw = new Render(world, ship1, ship2, settings);
140 human = new Human(ship1, this); 128 human = new Human(ship1, this);
129 ai = new AI(ship2, objectList);
130
131 render = new Render(world, ship1, ship2, human, settings);
132 render.keys();
141 133
142 objectList.add(planet); 134 objectList.add(planet);
143 objectList.add(ship1); 135 objectList.add(ship1);
144 objectList.add(ship2); 136 objectList.add(ship2);
145 137 }
146 ai = new AI(ship2, objectList); 138
147 139 void run() {
148 gui.begin(cfg).retained; 140 // Main game loop
149 gui.push(`main`); 141 while (running && !human.quit) {
150 GLViewport(`glview`).renderingHandler(&draw.draw) 142
151 .addHandler(&human.onClick) 143 float delta = timer.stop;
152 .addHandler(&human.onMove) 144 timer.start;
153 .addHandler(&human.onKey) 145
154 .addHandler(&human.onDT)
155 .addHandler(&human.onMouseEnter)
156 .addHandler(&human.onMouseLeave)
157 .grabKeyboardFocus;
158 gui.pop();
159 gui.immediate.end;
160
161 jobHub.addRepeatableJob( {
162 // Update physics
163 world.step(timeStep, settings.velocityIterations, settings.positionIterations);
164 }, ITERS_PER_SECOND);
165
166 jobHub.addPreFrameJob( {
167 // Update AI 146 // Update AI
168 ai.move(ship1); 147 ai.move(ship1);
169 }); 148 // Update Physics
170 149 world.step(timeStep, settings.velocityIterations, settings.positionIterations);
171 jobHub.addPostFrameJob( { 150 // Update screen
172 151 render.update();
173 // Limit velocity 152
153 // Limit velocities
174 foreach(o; objectList) { 154 foreach(o; objectList) {
175 o.limitVelocity(); 155 o.limitVelocity();
176 o.updateState(); 156 o.updateState();
177 } 157 }
178 158
179 gui.begin(cfg); 159 // Apply thrust
180 gui.push(`main`);
181 if (gui().getProperty!(bool)("frame.closeClicked")) {
182 running = false;
183 }
184
185 if(human.thrust && ship1) { 160 if(human.thrust && ship1) {
186 ship1.thrust(); 161 ship1.thrust();
187 } 162 }
188
189 gui().setProperty!(bool)("showCursor", true);
190 gui.pop();
191 gui.end;
192 gui.render(renderer);
193
194 });
195
196 while (running && !human.quit) {
197 float delta = timer.stop;
198 timer.start;
199 jobHub.update(delta);
200 } 163 }
164
165 delete render;
201 } 166 }
202 167
203 void initWorld() { 168 void initWorld() {
204 // Define world boundaries 169 // Define world boundaries
205 worldAABB.lowerBound.set(-400.0f, -250.0f); 170 worldAABB.lowerBound.set(-400.0f, -250.0f);