Changeset 200
- Timestamp:
- 11/05/07 18:11:13 (1 year ago)
- Files:
-
- branches/jobs/defend/Main.d (modified) (2 diffs)
- branches/jobs/defend/com/Simulation.d (modified) (1 diff)
- branches/jobs/defend/game/Game.d (modified) (6 diffs)
- branches/jobs/defend/game/net/client/Client.d (modified) (1 diff)
- branches/jobs/gen/core/JobSystem.d (modified) (6 diffs)
- branches/jobs/gen/util/Profiler.d (modified) (1 diff)
- branches/jobs/gen/util/ScreenDebugger.d (modified) (1 diff)
- trunk/defend/Main.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/jobs/defend/Main.d
r198 r200 125 125 while(!gamestateManager.exit) 126 126 { 127 profile!("main thread")128 ({127 //profile!("main thread") 128 //({ 129 129 // Start frame timer 130 130 frameBegin = getTickCount(); … … 148 148 //while((frameTime = getTickCount() - frameBegin) < 10) sleep(1); 149 149 }); 150 });150 //}); 151 151 } 152 152 branches/jobs/defend/com/Simulation.d
r173 r200 18 18 import tango.io.Stdout; 19 19 import gen.util.Wrapper; 20 import gen.util.Profiler; 20 21 import gen.util.ScreenDebugger; 21 22 22 23 void runSimulation() 23 24 { 24 screenDebugger.write("simulation steps: {}/{}", doneSimulationSteps, simulationSteps); 25 screenDebugger.write("phase length: {}", phaseLength);26 27 if(runningPhase)28 {29 if( getTickCount() - phaseBegin < phaseLength)25 profile!("simulation") 26 ({ 27 screenDebugger.write("simulation steps: {}/{}", doneSimulationSteps, simulationSteps); 28 screenDebugger.write("phase length: {}", phaseLength); 29 30 if(runningPhase) 30 31 { 31 final float step = phaseLength / simulationSteps; 32 uint timeLeft = getTickCount() - phaseTimer + timeAdd; 33 34 if(doneSimulationSteps < simulationSteps && timeLeft >= step) 32 if(getTickCount() - phaseBegin < phaseLength) 35 33 { 36 while(timeLeft >= step) 34 final float step = phaseLength / simulationSteps; 35 uint timeLeft = getTickCount() - phaseTimer + timeAdd; 36 37 if(doneSimulationSteps < simulationSteps && timeLeft >= step) 38 { 39 while(timeLeft >= step) 40 { 41 SimulationStep(); 42 43 doneSimulationSteps++; 44 45 if(doneSimulationSteps == simulationSteps) 46 { 47 phaseDone(); 48 break; 49 } 50 51 timeLeft -= step; 52 } 53 54 timeAdd = timeLeft; 55 phaseTimer = getTickCount(); 56 } 57 } 58 else 59 { 60 while(doneSimulationSteps < simulationSteps) 37 61 { 38 62 SimulationStep(); 39 40 63 doneSimulationSteps++; 41 42 if(doneSimulationSteps == simulationSteps)43 {44 phaseDone();45 break;46 }47 48 timeLeft -= step;49 64 } 50 65 51 timeAdd = timeLeft; 52 phaseTimer = getTickCount(); 66 phaseDone(); 53 67 } 54 68 } 55 69 else 56 { 57 while(doneSimulationSteps < simulationSteps) 58 { 59 SimulationStep(); 60 doneSimulationSteps++; 61 } 62 63 phaseDone(); 64 } 65 } 66 else 67 startPhase(); 70 startPhase(); 71 }); 68 72 } 69 73 } branches/jobs/defend/game/Game.d
r198 r200 227 227 void jobUpdateSyncs() 228 228 { 229 syncs.update(frameTime); 229 profile!("syncs.update") 230 ({ 231 syncs.update(frameTime); 232 }); 230 233 } 231 234 232 235 void jobUpdateHUD() 233 236 { 234 hud.update(frameTime); 237 profile!("hud.update") 238 ({ 239 hud.update(frameTime); 240 }); 235 241 } 236 242 237 243 void jobUpdateGraph() 238 244 { 239 sceneGraph.update(frameTime); 245 profile!("graph.update") 246 ({ 247 sceneGraph.update(frameTime); 248 }); 249 } 250 251 void jobUpdateMouse() 252 { 253 profile!("mouse.update") 254 ({ 255 mouse.update(); 256 }); 240 257 } 241 258 242 259 void jobInput() 243 260 { 244 inputManager.update(); 245 246 if(inputManager.keyPressed(KeyType.L)) 261 if(inputManager.keyPressedFirst(KeyType.L)) 247 262 wireframe = !wireframe; 248 263 … … 275 290 276 291 auto hudJob = jobSystem.addFrameJob("hud", &jobUpdateHUD); 277 hudJob.dependOn(inputJob);278 279 auto mouseJob = jobSystem.addFrameJob("mouse", & mouse.update);280 mouseJob.dependOn(inputJob);292 //hudJob.dependOn(inputJob); 293 294 auto mouseJob = jobSystem.addFrameJob("mouse", &jobUpdateMouse); 295 //mouseJob.dependOn(inputJob); 281 296 282 297 auto updateGraphJob = jobSystem.addFrameJob("graph", &jobUpdateGraph); … … 286 301 renderJob.dependOn(hudJob); 287 302 renderJob.dependOn(updateSyncsJob); 288 renderJob.dependOn(simulationJob);289 renderJob.dependOn(gatewayJob);303 //renderJob.dependOn(simulationJob); 304 //renderJob.dependOn(gatewayJob); 290 305 renderJob.dependOn(updateGraphJob); 291 306 renderJob.dependOn(mouseJob); … … 392 407 while(!doRender) 393 408 sleep(1); 409 410 inputManager.update(); 394 411 395 412 if(renderer.window.active) … … 401 418 if(wireframe) renderer.setRenderState(RenderState.Wireframe, true); 402 419 403 profile!(" scene graph", "render")420 profile!("graph.render") 404 421 ({ 405 422 sceneGraph.draw(); … … 413 430 414 431 // And then the 2D objects 415 profile!("hud ", "render")432 profile!("hud.render") 416 433 ({ 417 434 renderer.setRenderState(RenderState.DepthTest, false); branches/jobs/defend/game/net/client/Client.d
r198 r200 370 370 override void update() 371 371 { 372 screenDebugger.write("current phase: {}", phase); 373 374 processMessages(); 372 //profile!("gateway") 373 //({ 374 screenDebugger.write("current phase: {}", phase); 375 376 processMessages(); 377 //}); 375 378 } 376 379 branches/jobs/gen/core/JobSystem.d
r199 r200 79 79 class ThreadInstance : Thread 80 80 { 81 Mutex mutex; 82 Condition condition; 83 81 84 ThreadState state = ThreadState.Init; 82 85 bool stop = false; … … 84 87 this() 85 88 { 89 mutex = new Mutex; 90 condition = new Condition(mutex); 91 86 92 super(&run); 87 93 start(); … … 95 101 { 96 102 state = ThreadState.Wait; 97 JobInfo info;98 103 99 synchronized(jobQueue) 104 Thread.yield; 105 106 //synchronized(Stdout) Stdout("waiting... and waiting...").newline; 107 //synchronized(mutex) condition.wait(); 108 //synchronized(Stdout) Stdout("but not forever! noes!").newline; 109 110 while(!jobQueue.empty) 100 111 { 101 if(jobQueue.count > 0) 102 { 103 info = jobQueue.pop; 104 state = ThreadState.Exec; 105 } 106 else 107 { 108 Thread.yield(); 109 continue; 110 } 111 } 112 113 assert(info !is null); 114 assert(info.dg !is null); 115 116 debug(jobs) synchronized(Stdout) Stdout("+ doing ")(info.name)(" from ")(cast(void*)this).newline; 117 118 info.dg(); 119 120 info.done = true; 121 jobsFinished++; 122 123 foreach(cdep; info.clientDeps) 124 { 125 assert(!cdep.done, cdep.name ~ " already done"); 126 cdep.depsResolved++; 127 128 if(cdep.resolved) 129 { 130 //debug(jobs) synchronized(Stdout) Stdout("> ")(cdep.name, cdep.depsResolved, cdep.done).newline; 131 132 devolve(cdep); 133 } 112 JobInfo info; 113 114 synchronized(jobQueue) 115 { 116 if(!jobQueue.empty) 117 { 118 info = jobQueue.pop; 119 state = ThreadState.Exec; 120 } 121 else 122 continue; 123 } 124 125 assert(info !is null); 126 assert(info.dg !is null); 127 128 debug(jobs) synchronized(Stdout) Stdout("+ doing ")(info.name)(" from ")(cast(void*)this).newline; 129 130 info.dg(); 131 132 info.done = true; 133 jobsFinished++; 134 135 foreach(cdep; info.clientDeps) 136 { 137 assert(!cdep.done, cdep.name ~ " already done"); 138 cdep.depsResolved++; 139 140 if(cdep.resolved) 141 { 142 //debug(jobs) synchronized(Stdout) Stdout("> ")(cdep.name, cdep.depsResolved, cdep.done).newline; 143 144 devolve(cdep); 145 } 146 } 134 147 } 135 148 } … … 151 164 synchronized(jobQueue) 152 165 jobQueue.push(job); 166 167 return; 168 169 foreach(thread; threads) 170 { 171 if(thread.state == ThreadState.Wait || true) 172 { 173 synchronized(Stdout) Stdout("I'm notifying here, though...").newline; 174 synchronized(thread.mutex) thread.condition.notify(); 175 //return; 176 } 177 } 153 178 } 154 179 … … 242 267 if(thread.state != ThreadState.Wait) 243 268 { 244 Thread.sleep(0 .01);269 Thread.sleep(0); 245 270 continue outer; 246 271 } … … 255 280 } 256 281 257 Thread.sleep(0 .01);282 Thread.sleep(0); 258 283 } 259 284 } branches/jobs/gen/util/Profiler.d
r191 r200 78 78 } 79 79 80 template profile(char[] name , char[] space = "")80 template profile(char[] name) 81 81 { 82 82 T profile(T)(T delegate() dg) branches/jobs/gen/util/ScreenDebugger.d
r198 r200 71 71 return typeid(char[]).compare(cast(void*)&first.text, cast(void*)&second.text); 72 72 }); 73 73 74 74 int i; 75 75 foreach(l; sortList) trunk/defend/Main.d
r188 r200 175 175 // Limit FPS and calculate frame time 176 176 frameTime = getTickCount() - frameBegin; 177 while((frameTime = getTickCount() - frameBegin) < 10) sleep(1);177 //while((frameTime = getTickCount() - frameBegin) < 10) sleep(1); 178 178 }); 179 179 });
