Changeset 200

Show
Ignore:
Timestamp:
11/05/07 18:11:13 (1 year ago)
Author:
LeoD
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/jobs/defend/Main.d

    r198 r200  
    125125    while(!gamestateManager.exit) 
    126126    { 
    127         profile!("main thread") 
    128         ({ 
     127        //profile!("main thread") 
     128        //({ 
    129129            // Start frame timer 
    130130            frameBegin = getTickCount(); 
     
    148148                //while((frameTime = getTickCount() - frameBegin) < 10) sleep(1); 
    149149            }); 
    150         }); 
     150        //}); 
    151151    } 
    152152 
  • branches/jobs/defend/com/Simulation.d

    r173 r200  
    1818    import tango.io.Stdout; 
    1919    import gen.util.Wrapper; 
     20    import gen.util.Profiler; 
    2021    import gen.util.ScreenDebugger; 
    2122 
    2223    void runSimulation() 
    2324    { 
    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
    3031            { 
    31                 final float step = phaseLength / simulationSteps; 
    32                 uint timeLeft = getTickCount() - phaseTimer + timeAdd; 
    33                  
    34                 if(doneSimulationSteps < simulationSteps && timeLeft >= step) 
     32                if(getTickCount() - phaseBegin < phaseLength) 
    3533                { 
    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) 
    3761                    { 
    3862                        SimulationStep(); 
    39                          
    4063                        doneSimulationSteps++; 
    41                          
    42                         if(doneSimulationSteps == simulationSteps) 
    43                         { 
    44                             phaseDone(); 
    45                             break; 
    46                         } 
    47                              
    48                         timeLeft -= step; 
    4964                    } 
    5065                     
    51                     timeAdd = timeLeft; 
    52                     phaseTimer = getTickCount(); 
     66                    phaseDone(); 
    5367                } 
    5468            } 
    5569            else 
    56             { 
    57                 while(doneSimulationSteps < simulationSteps) 
    58                 { 
    59                     SimulationStep(); 
    60                     doneSimulationSteps++; 
    61                 } 
    62                  
    63                 phaseDone(); 
    64             } 
    65         } 
    66         else 
    67             startPhase(); 
     70                startPhase(); 
     71        }); 
    6872    } 
    6973} 
  • branches/jobs/defend/game/Game.d

    r198 r200  
    227227    void jobUpdateSyncs() 
    228228    { 
    229         syncs.update(frameTime); 
     229        profile!("syncs.update") 
     230        ({ 
     231            syncs.update(frameTime); 
     232        }); 
    230233    } 
    231234     
    232235    void jobUpdateHUD() 
    233236    { 
    234         hud.update(frameTime); 
     237        profile!("hud.update") 
     238        ({ 
     239            hud.update(frameTime); 
     240        }); 
    235241    } 
    236242     
    237243    void jobUpdateGraph() 
    238244    { 
    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        }); 
    240257    } 
    241258     
    242259    void jobInput() 
    243260    { 
    244         inputManager.update(); 
    245          
    246         if(inputManager.keyPressed(KeyType.L)) 
     261        if(inputManager.keyPressedFirst(KeyType.L)) 
    247262            wireframe = !wireframe; 
    248263 
     
    275290         
    276291        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); 
    281296         
    282297        auto updateGraphJob = jobSystem.addFrameJob("graph", &jobUpdateGraph); 
     
    286301        renderJob.dependOn(hudJob); 
    287302        renderJob.dependOn(updateSyncsJob); 
    288         renderJob.dependOn(simulationJob); 
    289         renderJob.dependOn(gatewayJob); 
     303        //renderJob.dependOn(simulationJob); 
     304        //renderJob.dependOn(gatewayJob); 
    290305        renderJob.dependOn(updateGraphJob); 
    291306        renderJob.dependOn(mouseJob); 
     
    392407        while(!doRender) 
    393408            sleep(1); 
     409         
     410        inputManager.update(); 
    394411             
    395412        if(renderer.window.active) 
     
    401418            if(wireframe) renderer.setRenderState(RenderState.Wireframe, true); 
    402419 
    403             profile!("scene graph", "render") 
     420            profile!("graph.render") 
    404421            ({ 
    405422                sceneGraph.draw(); 
     
    413430 
    414431            // And then the 2D objects 
    415             profile!("hud", "render") 
     432            profile!("hud.render") 
    416433            ({ 
    417434                renderer.setRenderState(RenderState.DepthTest, false); 
  • branches/jobs/defend/game/net/client/Client.d

    r198 r200  
    370370    override void update() 
    371371    { 
    372         screenDebugger.write("current phase: {}", phase); 
    373          
    374         processMessages(); 
     372        //profile!("gateway") 
     373        //({ 
     374            screenDebugger.write("current phase: {}", phase); 
     375             
     376            processMessages(); 
     377        //}); 
    375378    } 
    376379 
  • branches/jobs/gen/core/JobSystem.d

    r199 r200  
    7979    class ThreadInstance : Thread 
    8080    { 
     81        Mutex mutex; 
     82        Condition condition; 
     83         
    8184        ThreadState state = ThreadState.Init; 
    8285        bool stop = false; 
     
    8487        this() 
    8588        { 
     89            mutex = new Mutex; 
     90            condition = new Condition(mutex); 
     91             
    8692            super(&run); 
    8793            start(); 
     
    95101                { 
    96102                    state = ThreadState.Wait; 
    97                     JobInfo info; 
    98103                     
    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) 
    100111                    { 
    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                        } 
    134147                    } 
    135148                } 
     
    151164        synchronized(jobQueue) 
    152165            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        } 
    153178    } 
    154179     
     
    242267                        if(thread.state != ThreadState.Wait) 
    243268                        { 
    244                             Thread.sleep(0.01); 
     269                            Thread.sleep(0); 
    245270                            continue outer; 
    246271                        } 
     
    255280            } 
    256281             
    257             Thread.sleep(0.01); 
     282            Thread.sleep(0); 
    258283        } 
    259284    } 
  • branches/jobs/gen/util/Profiler.d

    r191 r200  
    7878} 
    7979 
    80 template profile(char[] name, char[] space = ""
     80template profile(char[] name
    8181{ 
    8282    T profile(T)(T delegate() dg) 
  • branches/jobs/gen/util/ScreenDebugger.d

    r198 r200  
    7171            return typeid(char[]).compare(cast(void*)&first.text, cast(void*)&second.text); 
    7272        }); 
    73          
     73 
    7474        int i; 
    7575        foreach(l; sortList) 
  • trunk/defend/Main.d

    r188 r200  
    175175                // Limit FPS and calculate frame time 
    176176                frameTime = getTickCount() - frameBegin; 
    177                 while((frameTime = getTickCount() - frameBegin) < 10) sleep(1); 
     177                //while((frameTime = getTickCount() - frameBegin) < 10) sleep(1); 
    178178            }); 
    179179        });