Changeset 166:064e0c4d99fe

Show
Ignore:
Timestamp:
03/21/2012 10:52:13 PM (15 months ago)
Author:
Andreas Schaefer <gentryx@…>
Branch:
default
Message:

simulation and visualization now run synchronously. not perfect, but it'll do

Location:
src/examples/flowingcanvas
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • src/examples/flowingcanvas/canvascell.h

    r165 r166  
    5050    }; 
    5151 
    52     static const int MAX_PARTICLES = 20; 
    53     static const int MAX_SPAWN_COUNTDOWN = 100; 
     52    static const int MAX_PARTICLES = 10; 
     53    static const int MAX_SPAWN_COUNTDOWN = 60; 
    5454    typedef Topologies::Cube<2>::Topology Topology; 
    5555    static const int TILE_WIDTH = 4; 
     
    5858    static inline unsigned nanoSteps() 
    5959    { 
    60         return 2; 
     60        return 5; 
    6161    } 
    6262 
     
    8181    void update(const CanvasCell *up, const CanvasCell *same, const CanvasCell *down, const unsigned& nanoStep) 
    8282    { 
    83         if (nanoStep == 1) { 
     83        if (nanoStep == (nanoSteps() - 1)) { 
    8484            // fixme: can we avoid this? 
    8585            *this = *same; 
     
    8989 
    9090        updateForces(up, same, down, nanoStep); 
    91         spawnParticles(); 
    92         updateParticles(); 
     91 
     92        if (nanoStep == (nanoSteps() - 2)) { 
     93            spawnParticles(); 
     94            updateParticles(); 
     95        } 
    9396    } 
    9497 
     
    106109 
    107110        int val = (int)r + (int)g + (int)b; 
    108         if (val < 500) { 
     111        if (val < 250) { 
    109112            cameraLevel = 1.0; 
    110113        } else { 
  • src/examples/flowingcanvas/canvaswriter.h

    r165 r166  
    180180                    QPoint origin(particle.pos[0] * factorX, 
    181181                                  particle.pos[1] * factorY); 
    182                     QPoint direction(particle.vel[0] * 50, 
    183                                      particle.vel[1] * 50); 
     182                    QPoint direction(particle.vel[0] * 20, 
     183                                     particle.vel[1] * 20); 
    184184                    QPoint end = origin + direction; 
    185185                    QPoint offset(2, 2); 
  • src/examples/flowingcanvas/interactivesimulator.h

    r158 r166  
    4141    virtual void step()  
    4242    { 
    43         if (newCameraFrame.tryAcquire())  
     43        if (newCameraFrame.tryAcquire()) { 
    4444            readCam(); 
     45        } 
    4546        if (newOutputFrameRequested.tryAcquire()) { 
    4647            renderOutput(); 
    47             newOutputFrameAvailable.release(); 
     48            // fixme: sync_update_patch 
     49            // newOutputFrameAvailable.release(); 
    4850        } 
    4951 
    5052        update(); 
    5153        incFrames(); 
     54        std::cout << getFrames() << " " << fps() << " FPS\r"; 
    5255    } 
    5356 
    5457    void renderImage(QImage *image)  
    5558    { 
    56         if (!running) { 
    57             return; 
    58         } 
    59  
     59        // fixme: sync_update_patch 
     60        // fixme 
     61        // if (!running) { 
     62        //     return; 
     63        // } 
     64         
    6065        outputFrame = image; 
    6166        newOutputFrameRequested.release(); 
    62         newOutputFrameAvailable.acquire(); 
     67        // fixme: sync_update_patch 
     68        // newOutputFrameAvailable.acquire(); 
    6369    } 
    6470 
     
    7783        while (running) { 
    7884            step(); 
    79             std::cout << getFrames() << " " << fps() << " FPS\r"; 
    8085        } 
    8186    } 
  • src/examples/flowingcanvas/interactivesimulatorgpu.h

    r163 r166  
    239239    virtual void update() 
    240240    { 
    241         for (int fixme = 0; fixme < 500; ++fixme)  
    242             GPUSimulator<CELL_TYPE>::step(); 
    243         sleep(1); 
     241        GPUSimulator<CELL_TYPE>::step(); 
    244242    } 
    245243 
  • src/examples/flowingcanvas/main.cu

    r165 r166  
    2727    flow.resize(1200, 900); 
    2828 
    29     // InteractiveSimulatorGPU<CanvasCell> *sim = new InteractiveSimulatorGPU<CanvasCell>( 
    30     InteractiveSimulatorCPU<CanvasCell> *sim = new InteractiveSimulatorCPU<CanvasCell>( 
     29    InteractiveSimulatorGPU<CanvasCell> *sim = new InteractiveSimulatorGPU<CanvasCell>( 
     30    // InteractiveSimulatorCPU<CanvasCell> *sim = new InteractiveSimulatorCPU<CanvasCell>( 
    3131        &flow, 
    3232        new CanvasInitializer()); 
    3333    CanvasWriter *writer = new CanvasWriter(sim->getOutputFrame(), sim); 
    34     FrameGrabber *grabber = new FrameGrabber(true, &flow); 
     34    FrameGrabber *grabber = new FrameGrabber(false, &flow); 
    3535 
    3636    QTimer *timerFlow = new QTimer(&flow); 
     
    5555 
    5656    QThreadPool *threadPool = QThreadPool::globalInstance(); 
    57     threadPool->start(sim); 
     57    // fixme: sync_update_patch 
     58    // threadPool->start(sim); 
     59    // fixme: sync_update_patch 
     60    QObject::connect(timerFlow, SIGNAL(timeout()),           sim,       SLOT(step())); 
    5861 
    5962    grabber->grab(); 
    60     timerFlow->start(50); 
    61     timerGrab->start(100); 
     63    timerFlow->start(10); 
     64    timerGrab->start(200); 
    6265    timerInfo->start(5000); 
    6366    flow.show();