NetStream::NetStream( int port, const char *name ) : name_(name), port_(port), msgSize_(-1), processing_(0), print_name_(get_host_print_name(port,name)) { NetHost host(name); struct sockaddr_in serv_addr; host.get_address(&serv_addr); serv_addr.sin_port = htons((short) port); if ((_fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) _die("socket"); else if (connect(_fd, (struct sockaddr*) &serv_addr, sizeof(serv_addr)) < 0) _die("connect"); else no_linger(_fd); block(STD_FALSE); if (_fd != -1) { set_blocking(false); no_tcp_delay(); // don't wait for large packets before sending a message } }
// Public Methods void Car::collisionResponse(const GameObject& collidedObject, double time, Vector3& direction) { _movementSpeed = 0; $moveToCollision(time); if (collidedObject.isDeadly()) _die(); }
void warn(char *msg, ...) { va_list ap; va_start(ap, msg); _die(0, msg, ap); va_end(ap); }
void die(char *msg, ...) { va_list ap; va_start(ap, msg); _die(1, msg, ap); va_end(ap); }
NetStream * Network::wait_for_connect() { struct sockaddr_in cli_addr; socklen_t clilen = sizeof(cli_addr); int newFd; NetStream *newStream; if ((newFd = accept(_fd, (struct sockaddr*) &cli_addr, &clilen)) < 0) _die("accept"); // Should really handle EWOULDBLOCK... if (!(newStream = new NetStream(newFd, &cli_addr))) _die("out of memory"); return newStream; }
__attribute__((noreturn)) static void _die_overflow_mul(size_t x, size_t y) { _log_nomem(LOG_FATAL, "malloc", ENOMEM, "integer multiplication overflow allocating >", SIZE_MAX, -1); _die(); }
__attribute__((noreturn)) static void _die_overflow_sub(size_t x, size_t y) { _log_nomem(LOG_FATAL, "read", ENOMEM, "integer subtraction overflow reading ", y, -1); _die(); }
/* * low/no memory error handlers: used in signal handlers and to * report memory allocation errors. */ __attribute__((noreturn)) static void _die_malloc(int errnum, size_t bytes) { _log_nomem(LOG_FATAL, "malloc", errnum, "out of memory allocating ", bytes, -1); _die(); }
SYSHANDLER() { int (*ifunc[])(asm_env*) = { NULL, iexit, isys, }; int len = sizeof(ifunc)/sizeof(void*); if( env->regs[ R_EAX ] < 0 || env->regs[ R_EAX ] >= len || ifunc[ env->regs[ R_EAX ] ] == NULL ) _die( env, "SIGSEGV" ); else env->regs[ R_EAX ] = ifunc[ env->regs[ R_EAX ] ]( env ); }
// Constructors & Destructors Orange::Orange() { // Start managing this orange _id = ID_GENERATOR++; _orangeMap[_id] = this; setAABB(2, -2, 2, -2); $setDeadly(true); // Start with a random movement speed _incrementSpeed(); // Wait for a random time before spawning _die(); }
void Network::start( int myPort ) { const char *msg; // if myPort is 0, then we arbitrarily determine that this Network // will be responsible for configuring all new clients when they // arrive -- see accept_stream() first_ = (myPort == 0 ? 0 : 1); // setup master socket to wait for connections: if ((msg = configure(myPort))) _die(msg); }
void Pickup::_update(const UpdateState& us) { for (std::list<spUnit>::iterator i = _game->_units.begin(); i != _game->_units.end(); ++i) { spUnit unit = *i; //list of units has everything, but we need only Enemies spAircraftFighter player = dynamic_cast<AircraftFighter*>(unit.get()); if (!player) { continue; } else { Vector2 d = unit->getPosition() - _pos; if (d.length() < _diameter) { if (_lastPickUp + 300 < us.time) { _lastPickUp = us.time; log::message("Taken %s-%d\n", _type.c_str(), _id); if (!_type.compare("wpn")) { player->pickupWpn(_id); } else { player->pickupPup(_id); } if (_quantity > 0) { _quantity--; //new pos //pickup_wpn0->init(Vector2(scalar::randFloat(0, getWidth()), scalar::randFloat(0, getHeight())), 0, this); Vector2 newPos = Vector2(scalar::randFloat(0, 640), scalar::randFloat(0, 520)); this->_view->setPosition(newPos); //this->setPosition(newPos); _pos = newPos; } else if (_quantity == 0) _die(); return; } } } } }
void Orange::update(double delta_t) { if (_isDead) return; DynamicObject::update(delta_t); // Check if outside the table const Vector3& position = getPosition(); if (position.getX() > Table::TABLE_WIDTH || position.getY() > Table::TABLE_HEIGHT) { _die(); return; } // Rotate/Roll according to the movement _movementRotation = (int) (_movementRotation + _movementSpeed * 0.4) % 360; }
void* Boss::collision(CollidingObject * o) { if (is_invincible()) return NULL; Projectile* autre = dynamic_cast<Projectile*>(o); if ((autre != NULL) && (autre->get_shot_id() == Projectile::banker)){ _get_hit(_sprite); } // Meure si ses points de vie tombent à 0 if (_life <= 0) { EnemyFactory::reset_boss(); EnemyFactory::next_level(); _die(); return new DropObject(_sprite.GetPosition(), CASH + sf::Randomizer::Random(1, EnemyFactory::level())); } return NULL; }
void on_event(const char* event, const char* id, const char* data) { // fprintf(stderr, "on_event %s#%s: '%s'\n", event, id, data); // prepare command. command[command_ofs] = (char*)event; command[command_ofs+1] = (char*)id; // Prepare pipe for subprocess int fd[2]; if (pipe(fd) != 0) die("pipe"); // Start subprocess pid_t pid = fork(); if (pid == -1) die("fork"); if (pid == 0) { /* the child */ close(fd[FD_WRITE]); dup2(fd[FD_READ], FD_READ); execvp(command[0], command); _die(command[0]); /* die via _exit: a failed child should not flush parent files */ } else { /* code for parent */ close(fd[FD_READ]); write_all(fd[FD_WRITE], data, strlen(data)); close(fd[FD_WRITE]); int status = 0; waitpid(pid, &status, 0); // Show results if something broke. if(WIFEXITED(status) && WEXITSTATUS(status) != 0) fprintf(stderr, "child exited with stats %d\n", WEXITSTATUS(status)); else if(WIFSIGNALED(status)) fprintf(stderr, "child exited of signal %d\n", WTERMSIG(status)); } }
__attribute__((noreturn)) static void _die_writepipe(int errnum, int fd, size_t bytes) { _log_writepipe(LOG_FATAL, errnum, fd, bytes); _die(); }
__attribute__((noreturn)) static void _die_writepipehang(int fd) { _log_nomem(LOG_FATAL, "write", 0, "wrote ", 0, fd); _die(); }
__attribute__((noreturn)) static void _die_overwritepipe(int fd, size_t bytes) { _log_nomem(LOG_FATAL, "write", 0, "over write ", bytes, fd); _die(); }
void Car::update(double delta_t) { double directionRads, seconds = delta_t / 1000; // Handle steering switch (_controlSteer) { case 1: _movementDirection -= seconds * STEER; break; case -1: _movementDirection += seconds * STEER; break; } // Handle acceleration switch (_controlAcceleration) { case 1: // Accelerate _movementSpeed += ACCELERATION_FORWARD * seconds; if (_movementSpeed > LIMIT_FORWARD) _movementSpeed = LIMIT_FORWARD; break; case 0: // Apply drag if (_movementSpeed > 0) { _movementSpeed -= DRAG * seconds; if (_movementSpeed < 0) _movementSpeed = 0; } else { _movementSpeed += DRAG * seconds; if (_movementSpeed > 0) _movementSpeed = 0; } break; case -1: // Break / Reverse _movementSpeed = _movementSpeed - ACCELERATION_BACKWARD * seconds; if (_movementSpeed < -LIMIT_BACKWARD) _movementSpeed = -LIMIT_BACKWARD; break; } directionRads = _movementDirection * PI / 180; // Convert degrees to radians Vector3& direction = Vector3(-cos(directionRads), -sin(directionRads), 0); Vector3& perpendicularDirection = Vector3(sin(directionRads), -cos(directionRads), 0); // Update speed and position setSpeed(direction* _movementSpeed); DynamicObject::update(delta_t); // Update headlights const Vector3& position = getPosition(); Vector3& headLightPositionC = Vector3(direction*0.6 + perpendicularDirection* -0.5); Vector3& headLightPositionC2 = Vector3(direction*0.6 + perpendicularDirection* 0.5); _pLeftHeadlight->setPosition(position.getX() + headLightPositionC.getX(), position.getY() + headLightPositionC.getY(), position.getZ() + 0.35); _pRightHeadlight->setPosition(position.getX() + headLightPositionC2.getX(), position.getY() + headLightPositionC2.getY(), position.getZ() + 0.35); _pLeftHeadlight->setDirection(direction.getX(), direction.getY(), 0); _pRightHeadlight->setDirection(direction.getX(), direction.getY(), 0); // Check if outside the table if (position.getX() < 0 || position.getX() > Table::TABLE_WIDTH || position.getY() < 0 || position.getY() > Table::TABLE_HEIGHT) { _die(); } }
/* called in child process, use _exit */ __attribute__((noreturn)) static void _die_sigaction(int errnum, int signum) { _log_sigaction(LOG_FATAL, errnum, signum); _die(); }
/* called in child process, use _exit */ __attribute__((noreturn)) static void _die_execve(int errnum, const char *file) { _log_execve(LOG_FATAL, errnum, file); _die(); }
/* called in child process, use _exit */ __attribute__((noreturn)) static void _die_dup2(int errnum, int fd) { _log_dup2(LOG_FATAL, errnum, fd); _die(); }