//Critical zone code, partly from A3Files void criticalZone(Ship *ship, iArgs input, FILE *sketch) { sigset_t block_mask; sigset_t old_mask; sigemptyset( &block_mask ); sigaddset( &block_mask, SIGALRM ); // blocks signal if( sigprocmask( SIG_BLOCK, &block_mask, &old_mask ) < 0 ) { exit( EXIT_FAILURE ); } // CRITICAL CODE GOES if (checkCollision(ship, input)){ if (ship -> yspeed > 40 || ship -> xspeed > 20 || ship -> rotationAngle != 90){ printw("\nCollision speed x:%.2lf y:%.2lf, try to go slower and point your ship up!\n\n", ship -> xspeed, ship -> yspeed); explode(tship, sket); ship -> collision = 1; } else { printw("You landed!"); ship -> collision = 2; } } else applyAccelerations(ship, input, sketch); // // unblock signal by setting mask to old value from before we added SIGALRM if( sigprocmask( SIG_SETMASK, &old_mask, NULL ) < 0 ) { exit( EXIT_FAILURE ); } }
void update() { // Iterate through all particles and do various things to them. for (std::size_t i = 0; i < particles.size(); i++) { // Update the particle. particles[i]->update(); // Here we pass our particle "by reference". // This means that the applyAccelerations function can modify the particle. applyAccelerations(particles[i]); // Here we pass our particle "by reference". // This means that the checkCollisions function can modify the particle. checkCollisions(particles[i]); } }