Changeset 166:064e0c4d99fe
- 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:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r165
|
r166
|
|
| 50 | 50 | }; |
| 51 | 51 | |
| 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; |
| 54 | 54 | typedef Topologies::Cube<2>::Topology Topology; |
| 55 | 55 | static const int TILE_WIDTH = 4; |
| … |
… |
|
| 58 | 58 | static inline unsigned nanoSteps() |
| 59 | 59 | { |
| 60 | | return 2; |
| | 60 | return 5; |
| 61 | 61 | } |
| 62 | 62 | |
| … |
… |
|
| 81 | 81 | void update(const CanvasCell *up, const CanvasCell *same, const CanvasCell *down, const unsigned& nanoStep) |
| 82 | 82 | { |
| 83 | | if (nanoStep == 1) { |
| | 83 | if (nanoStep == (nanoSteps() - 1)) { |
| 84 | 84 | // fixme: can we avoid this? |
| 85 | 85 | *this = *same; |
| … |
… |
|
| 89 | 89 | |
| 90 | 90 | updateForces(up, same, down, nanoStep); |
| 91 | | spawnParticles(); |
| 92 | | updateParticles(); |
| | 91 | |
| | 92 | if (nanoStep == (nanoSteps() - 2)) { |
| | 93 | spawnParticles(); |
| | 94 | updateParticles(); |
| | 95 | } |
| 93 | 96 | } |
| 94 | 97 | |
| … |
… |
|
| 106 | 109 | |
| 107 | 110 | int val = (int)r + (int)g + (int)b; |
| 108 | | if (val < 500) { |
| | 111 | if (val < 250) { |
| 109 | 112 | cameraLevel = 1.0; |
| 110 | 113 | } else { |
-
|
r165
|
r166
|
|
| 180 | 180 | QPoint origin(particle.pos[0] * factorX, |
| 181 | 181 | 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); |
| 184 | 184 | QPoint end = origin + direction; |
| 185 | 185 | QPoint offset(2, 2); |
-
|
r158
|
r166
|
|
| 41 | 41 | virtual void step() |
| 42 | 42 | { |
| 43 | | if (newCameraFrame.tryAcquire()) |
| | 43 | if (newCameraFrame.tryAcquire()) { |
| 44 | 44 | readCam(); |
| | 45 | } |
| 45 | 46 | if (newOutputFrameRequested.tryAcquire()) { |
| 46 | 47 | renderOutput(); |
| 47 | | newOutputFrameAvailable.release(); |
| | 48 | // fixme: sync_update_patch |
| | 49 | // newOutputFrameAvailable.release(); |
| 48 | 50 | } |
| 49 | 51 | |
| 50 | 52 | update(); |
| 51 | 53 | incFrames(); |
| | 54 | std::cout << getFrames() << " " << fps() << " FPS\r"; |
| 52 | 55 | } |
| 53 | 56 | |
| 54 | 57 | void renderImage(QImage *image) |
| 55 | 58 | { |
| 56 | | if (!running) { |
| 57 | | return; |
| 58 | | } |
| 59 | | |
| | 59 | // fixme: sync_update_patch |
| | 60 | // fixme |
| | 61 | // if (!running) { |
| | 62 | // return; |
| | 63 | // } |
| | 64 | |
| 60 | 65 | outputFrame = image; |
| 61 | 66 | newOutputFrameRequested.release(); |
| 62 | | newOutputFrameAvailable.acquire(); |
| | 67 | // fixme: sync_update_patch |
| | 68 | // newOutputFrameAvailable.acquire(); |
| 63 | 69 | } |
| 64 | 70 | |
| … |
… |
|
| 77 | 83 | while (running) { |
| 78 | 84 | step(); |
| 79 | | std::cout << getFrames() << " " << fps() << " FPS\r"; |
| 80 | 85 | } |
| 81 | 86 | } |
-
|
r163
|
r166
|
|
| 239 | 239 | virtual void update() |
| 240 | 240 | { |
| 241 | | for (int fixme = 0; fixme < 500; ++fixme) |
| 242 | | GPUSimulator<CELL_TYPE>::step(); |
| 243 | | sleep(1); |
| | 241 | GPUSimulator<CELL_TYPE>::step(); |
| 244 | 242 | } |
| 245 | 243 | |
-
|
r165
|
r166
|
|
| 27 | 27 | flow.resize(1200, 900); |
| 28 | 28 | |
| 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>( |
| 31 | 31 | &flow, |
| 32 | 32 | new CanvasInitializer()); |
| 33 | 33 | CanvasWriter *writer = new CanvasWriter(sim->getOutputFrame(), sim); |
| 34 | | FrameGrabber *grabber = new FrameGrabber(true, &flow); |
| | 34 | FrameGrabber *grabber = new FrameGrabber(false, &flow); |
| 35 | 35 | |
| 36 | 36 | QTimer *timerFlow = new QTimer(&flow); |
| … |
… |
|
| 55 | 55 | |
| 56 | 56 | 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())); |
| 58 | 61 | |
| 59 | 62 | grabber->grab(); |
| 60 | | timerFlow->start(50); |
| 61 | | timerGrab->start(100); |
| | 63 | timerFlow->start(10); |
| | 64 | timerGrab->start(200); |
| 62 | 65 | timerInfo->start(5000); |
| 63 | 66 | flow.show(); |