void game_logic_tick(void) { time_diff = get_rel_time(); if(getkey(SDL_SCANCODE_A)) lander_x_pos_rate -= .0001 * time_diff * accel_scale; else if(getkey(SDL_SCANCODE_D)) lander_x_pos_rate += .0001 * time_diff * accel_scale; else if(lander_x_pos_rate > 0.0001) lander_x_pos_rate -= .00003 * time_diff * accel_scale; else if(lander_x_pos_rate < -0.0001) lander_x_pos_rate += .00003 * time_diff * accel_scale; lander_x_pos += lander_x_pos_rate * time_diff * move_scale; if(getkey(SDL_SCANCODE_W)) lander_z_pos_rate -= .0001 * time_diff * accel_scale; else if(getkey(SDL_SCANCODE_S)) lander_z_pos_rate += .0001 * time_diff * accel_scale; else if(lander_z_pos_rate > 0.0001) lander_z_pos_rate -= .00003 * time_diff * accel_scale; else if(lander_z_pos_rate < -0.0001) lander_z_pos_rate += .00003 * time_diff * accel_scale; lander_z_pos += lander_z_pos_rate * time_diff * move_scale; if(getkey(SDL_SCANCODE_UP)) lander_y_pos_rate += .0001 * time_diff * accel_scale; else if(getkey(SDL_SCANCODE_DOWN)) lander_y_pos_rate -= .0001 * time_diff * accel_scale; else if(lander_y_pos_rate > 0.0001) lander_y_pos_rate -= .00003 * time_diff * accel_scale; else if(lander_y_pos_rate < -0.0001) lander_y_pos_rate += .00003 * time_diff * accel_scale; lander_y_pos += lander_y_pos_rate * time_diff * move_scale; if(getkey(SDL_SCANCODE_LEFT)) lander_y_angle_rate += .0005 * time_diff * accel_scale; else if(getkey(SDL_SCANCODE_RIGHT)) lander_y_angle_rate -= .0005 * time_diff * accel_scale; else if(lander_y_angle_rate > 0.0001) lander_y_angle_rate -= .0001 * time_diff * accel_scale; else if(lander_y_angle_rate < -0.0001) lander_y_angle_rate += .0001 * time_diff * accel_scale; lander_y_angle += lander_y_angle_rate * time_diff * move_scale; earth_angle += 0.01; if(earth_angle > 360) earth_angle = 0; if(getkey(SDL_SCANCODE_ESCAPE)) quit(); }
static inline int32_t block_read_n(int fd, void* buf, int32_t size, int32_t timeout) { int exit_loop = 0; int revents = 0; int32_t next_to = -1; int32_t read_size = 0; int32_t total_read_size = 0; struct timespec abs_to; abs_to = get_abs_time(timeout); total_read_size = 0; exit_loop = 0; do { next_to = get_rel_time(&abs_to); if((timeout > 0 && next_to <= 0)) { set_errno(MQ_ETIMEDOUT); total_read_size = -1; exit_loop = 1; } else { revents = wait_fd(fd, POLLIN, (timeout <= 0 ? timeout : next_to)); switch (revents) { case POLLIN: do { read_size = read(fd, buf + total_read_size, size - total_read_size); }while(read_size < 0 && errno == EINTR); switch (read_size) { case -1: /* ERROR */ total_read_size = -1; case 0: /* EOF */ exit_loop = 1; break; default: total_read_size += read_size; break; } break; case 0: set_errno(MQ_ETIMEDOUT); total_read_size = -1; exit_loop = 1; break; default: /* other revents or error */ total_read_size = -1; exit_loop = 1; break; } } }while(!exit_loop && (total_read_size < size) && timeout != 0); return total_read_size; }
static inline int32_t nonblock_write_n(int fd, const void* buf, int32_t size, int32_t timeout) { int exit_loop = 0; int revents = 0; int32_t next_to = -1; int32_t write_size = 0; int32_t total_write_size = 0; struct timespec abs_to; abs_to = get_abs_time(timeout); total_write_size = 0; exit_loop = 0; do { write_size = write(fd, buf + total_write_size, size - total_write_size); if(write_size > 0) { total_write_size += write_size; } else if(write_size == 0) /* nothing was writen */ { exit_loop = 1; } else /* write_size < 0 */ { switch(errno) { case EINTR: continue; break; case EAGAIN: next_to = get_rel_time(&abs_to); if((timeout == 0) || (timeout > 0 && next_to <= 0)) { set_errno(MQ_ETIMEDOUT); total_write_size = -1; exit_loop = 1; } else { revents = wait_fd(fd, POLLOUT, (timeout < 0 ? timeout : next_to)); if(revents == POLLOUT) { continue; } else if(revents == 0) { set_errno(MQ_ETIMEDOUT); total_write_size = -1; exit_loop = 1; } else /* other revents or error */ { total_write_size = -1; exit_loop = 1; } } break; default: total_write_size = -1; exit_loop = 1; break; } /* switch(errno) */ } /* write_size < 0 */ }while(!exit_loop && (total_write_size < size) && timeout != 0); return total_write_size; }
static inline int32_t block_write_n(int fd, const void* buf, int32_t size, int32_t timeout) { int exit_loop = 0; int revents = 0; int32_t next_to = -1; int32_t write_size = 0; int32_t total_write_size = 0; struct timespec abs_to; abs_to = get_abs_time(timeout); total_write_size = 0; exit_loop = 0; do { next_to = get_rel_time(&abs_to); if((timeout > 0 && next_to <= 0)) { set_errno(MQ_ETIMEDOUT); total_write_size = -1; exit_loop = 1; } else { revents = wait_fd(fd, POLLOUT, (timeout <= 0 ? timeout : next_to)); if(revents == POLLOUT) { do { write_size = write(fd, buf + total_write_size, size - total_write_size); }while(write_size < 0 && errno == EINTR); if(write_size > 0) { total_write_size += write_size; } else if(write_size == 0) /* nothing was written */ { exit_loop = 1; } else /* write_size < 0 */ { total_write_size = -1; exit_loop = 1; } } else if(revents == 0) { set_errno(MQ_ETIMEDOUT); total_write_size = -1; exit_loop = 1; } else /* other revents or error */ { total_write_size = -1; exit_loop = 1; } } }while(!exit_loop && (total_write_size < size) && timeout != 0); return total_write_size; }
static inline int32_t nonblock_read_n(int fd, void* buf, int32_t size, int32_t timeout) { int exit_loop = 0; int revents = 0; int32_t next_to = -1; int32_t read_size = 0; int32_t total_read_size = 0; struct timespec abs_to; abs_to = get_abs_time(timeout); total_read_size = 0; exit_loop = 0; do { read_size = read(fd, buf + total_read_size, size - total_read_size); switch (read_size) { case -1: switch(errno) { case EINTR: continue; break; case EAGAIN: next_to = get_rel_time(&abs_to); if((timeout == 0) || (timeout > 0 && next_to <= 0)) { set_errno(MQ_ETIMEDOUT); total_read_size = -1; exit_loop = 1; } else { revents = wait_fd(fd, POLLIN, (timeout < 0 ? timeout : next_to)); switch (revents) { case POLLIN: continue; case 0: set_errno(MQ_ETIMEDOUT); total_read_size = -1; exit_loop = 1; break; default: /* other revents or error */ total_read_size = -1; exit_loop = 1; break; } } break; default: total_read_size = -1; exit_loop = 1; break; } /* switch(errno) */ break; case 0: exit_loop = 1; break; default: total_read_size += read_size; break; } }while(!exit_loop && (total_read_size < size) && timeout != 0); return total_read_size; }
bool t_dep_para_full_worker(yarn_word_t pool_id, void* task) { (void) task; calc_func_t* calc_fun = (calc_func_t*) task; while(true) { enum yarn_epoch_status old_status; yarn_word_t epoch; DBG printf("\t\t\t\t\t\t\t\t"STR_TS"<%zu> NEXT => START\n", get_rel_time(), pool_id); if (!yarn_epoch_next(&epoch, &old_status)) { DBG printf("\t\t\t\t\t\t\t\t"STR_TS"<%zu> STOP\n", get_rel_time(), pool_id); break; } if (old_status == yarn_epoch_rollback) { DBG printf("\t\t\t\t\t\t\t\t"STR_TS"<%zu> NEXT => [%3zu] - ROLLBACK\n", get_rel_time(), pool_id, epoch); yarn_dep_rollback(epoch); yarn_epoch_rollback_done(epoch); } else { DBG printf("\t\t\t\t\t\t\t\t"STR_TS"<%zu> NEXT => [%3zu]\n", get_rel_time(), pool_id, epoch); } bool init_ret = yarn_dep_thread_init(pool_id, epoch); if (!init_ret) goto init_error; DBG printf("\t\t\t\t\t\t\t\t"STR_TS"<%zu> CALC => [%3zu]\n", get_rel_time(), pool_id, epoch); ret_t calc_ret = (*calc_fun)(pool_id); if (calc_ret == done) { DBG printf("\t\t\t\t\t\t\t\t"STR_TS"<%zu> F_STOP => [%3zu]\n", get_rel_time(), pool_id, epoch); yarn_epoch_stop(epoch); } DBG printf("\t\t\t\t\t\t\t\t"STR_TS"<%zu> DONE => [%3zu]\n", get_rel_time(), pool_id, epoch); yarn_epoch_set_done(epoch); yarn_dep_thread_destroy(pool_id); yarn_word_t commit_epoch; void* task; while (yarn_epoch_get_next_commit(&commit_epoch, &task)) { DBG printf("\t\t\t\t\t\t\t\t"STR_TS"<%zu> COMMIT => [%3zu]\n", get_rel_time(), pool_id, commit_epoch); yarn_dep_commit(commit_epoch); yarn_epoch_commit_done(commit_epoch); } if (calc_ret == ok) { continue; } else if (calc_ret == err) { goto dep_error; } } fail_if(false); return true; dep_error: init_error: perror(__FUNCTION__); return false; }