bool game_init(scene_t initial_scene) { TICKS_PER_SECOND = g_sysconfig.desired_fps; SKIP_TICKS = (1000.0 / (double)TICKS_PER_SECOND); MAX_FRAMESKIP = 5; FIXED_DELTA = (1.0/TICKS_PER_SECOND); max_timer_delta = FIXED_DELTA*2.0; // game_paused = 0; timer_update(&timer); timer_update(&timer); fs_font_load("impact20.fnt", &fps_font); fps_font.ri.pos = vec2d_make(0.0, g_sysconfig.screen_h); fps_font.ri.anchor_point = vec2d_make(0.0, 1.0); scene_stack_pointer = 0; scene_stack[scene_stack_pointer] = initial_scene; current_scene = &scene_stack[scene_stack_pointer]; scene_stack[scene_stack_pointer].init_func(&scene_stack[scene_stack_pointer]); scene_queue_state = S_NONE; next_game_tick = timer_get_tick_count(); timer.delta = 0.0; return true; }
static int event_add(ohc_request_t *r, req_handler_f *handler, int event, time_t timeout) { uint32_t epoll_ev = (event == OHC_EV_READ) ? EPOLLIN : EPOLLOUT; int epoll_fd = r->worker_thread ? r->worker_thread->epoll_fd : master_epoll_fd; ohc_timer_t *timer; if(r->events == event) { timer_update(&r->tnode, timeout); } else if(r->events) { if(epoll_mod(epoll_fd, r->sock_fd, epoll_ev, r) != 0) { return OHC_ERROR; } if(timer_update(&r->tnode, timeout) != 0) { return OHC_ERROR; } } else { timer = r->worker_thread ? &r->worker_thread->timer : &master_timer; if(epoll_add(epoll_fd, r->sock_fd, epoll_ev, r) != 0) { return OHC_ERROR; } if(timer_add(timer, &r->tnode, timeout) != 0) { return OHC_ERROR; } } r->events = event; r->event_handler = handler; return OHC_OK; }
/** * Playstate implementation. Must initialize it, run the loop and clean it up */ state playstate(int doLoad) { GFraMe_ret rv; state ret; ret = -1; rv = ps_init(doLoad); GFraMe_assertRet(rv == GFraMe_ret_ok, "Failed to init playstate", __ret); GFraMe_event_init(_maxUfps, _maxDfps); _ps_pause = 0; _psRunning = 1; while (gl_running && _psRunning) { #ifdef DEBUG unsigned int t; #endif ps_event(); timer_update(); if (_ps_pause) { ps_doPause(); if (_ps_onOptions) { options(); _ps_onOptions = 0; _ps_lastPress = 300; } } else { if (gv_isZero(SWITCH_MAP)) ps_update(); else { rv = ps_switchMap(); GFraMe_assertRet(rv == GFraMe_ret_ok, "Failed to switch maps", __ret); } } ps_draw(); #ifdef DEBUG t = SDL_GetTicks(); if (t >= _time) { GFraMe_log("t=%04i, U=%03i/%03i D=%03i/%03i", _time - _ltime, _updCalls, _maxUfps, _drwCalls, _maxDfps); _updCalls = 0; _drwCalls = 0; _ltime = _time; _time = SDL_GetTicks() + 1000; } #endif } if (_timerTilCredits >= 5000) ret = CREDITS; else ret = MENUSTATE; __ret: ps_clean(); return ret; }
void display() { timer_update(); glClearColor(0,0,0,0); glClear(GL_COLOR_BUFFER_BIT); glColor3f(1,1,1); float pos = position(); if( pos > 1) failed=1; if(failed) { print("%d", score); glutSwapBuffers(); return; } glColor3f(1,0,0); quad(goal+LEEWAY); glColor3f(0,0,0); quad(goal-LEEWAY); glColor3f(1,1,1); quad(pos); print("%d", score); glutSwapBuffers(); }
void ledStringInit() { ledStringTimer = timer_register(0,0,0); if(ledStringTimer != INVALID_TIMERID) timer_update(0, 0,50, ledStringTimer); timer_start(ledStringTimer); }
void ledStringSetProgram(void ** args ) { unsigned int numArg = atoi(((unsigned char **) args)[1]); unsigned int numArg2 = atoi(((unsigned char **) args)[2]); /*get sub command*/ if(strcmp((((unsigned char **) args)[0]), "prog" )==0) { USART_printf("Setting ledString program...\r\n"); currentProgram = numArg; } else if(strcmp((((unsigned char **) args)[0]), "speed" )==0) { USART_printf("Update speed ledString...\r\n"); timer_update(0, 0,numArg, ledStringTimer); } else if(strcmp((((unsigned char **) args)[0]), "effect" )==0) { setLedEffect(numArg,(unsigned char)numArg2); } else { USART_printf("prog, speed, effect, are valid."); } }
void timer_tick(void) { static uint8_t i; for(i = 0; i < TIMER_NUM_SLOTS; i++) { timer_update(&timers[i]); } }
// Process the first event in queue, sending to the appropriate handler // This is the new object-oriented system // Uses the old system for now, but this may change void event_process(void) { d_event event; window *wind = window_get_front(); timer_update(); event_poll(); // send input events first // Doing this prevents problems when a draw event can create a newmenu, // such as some network menus when they report a problem if (window_get_front() != wind) return; event.type = EVENT_WINDOW_DRAW; // then draw all visible windows wind = window_get_first(); while (wind != NULL) { window *prev = window_get_prev(wind); if (window_is_visible(wind)) window_send_event(wind, &event); if (!window_exists(wind)) { if (!prev) // well there isn't a previous window ... break; // ... just bail out - we've done everything for this frame we can. wind = window_get_next(prev); // the current window seemed to be closed. so take the next one from the previous which should be able to point to the one after the current closed } else wind = window_get_next(wind); } gr_flip(); }
void interrupt(void (*op)()) { z80.regs.ime = 0; op(); z80.clock.m += z80.regs.m; timer_update(z80.regs.m); gpu_step(z80.regs.m); }
void update_devices(struct memory* m, uint64_t cycles) { if (m->devices[DEVICE_DISPLAY]) display_update(m->devices[DEVICE_DISPLAY], cycles); if (m->devices[DEVICE_TIMER]) timer_update(m->devices[DEVICE_TIMER], cycles); if (m->devices[DEVICE_INPUT]) input_update(m->devices[DEVICE_INPUT], cycles); }
int io_poll(int64_t *remain, int64_t *timeout) { int to = -1; uint64_t old; uint64_t deadline = timer_mtime; size_t i; int ret; old = timer_mtime; /* There is a timeout, set it */ if(timeout) if(*timeout >= 0LL) { to = (int)(*timeout); deadline = timer_mtime + *timeout + 10; } /* Do the actual poll() */ ret = syscall_poll(io_count ? io_pfds : NULL, io_count, to); /* Update system time */ timer_update(); /* * If a timeout was set then set the timeout pointer * to the remaining time until the poll deadline. */ if(timeout && remain) { *remain = deadline - timer_mtime; if(*remain < 0LL) { if(*remain < -POLL_WARN_DELTA) log(io_log, L_warning, "Timing error: poll() returned too late (diff: %lli)", *remain); *remain = 0; } if(*remain > *timeout) { if(*remain > *timeout + POLL_WARN_DELTA) log(io_log, L_warning, "Timing error: poll() returned too early (diff: %lli)", *remain); *remain = *timeout; } } /* Now set the returned events */ for(i = 0; i < io_count; i++) io_set_revents(io_pfds[i].fd); return ret; }
//initialize the player object position & orientation (at start of game, or new ship) void InitPlayerPosition(int random) { int NewPlayer=0; if (! ((Game_mode & GM_MULTI) && !(Game_mode&GM_MULTI_COOP)) ) // If not deathmatch NewPlayer = Player_num; #ifdef NETWORK else if ((Game_mode & GM_MULTI) && (Netgame.SpawnStyle == SPAWN_STYLE_PREVIEW) && Dead_player_camera != NULL) NewPlayer = previewed_spawn_point; #endif else if (random == 1) { int i, trys=0; fix closest_dist = 0x7ffffff, dist; timer_update(); d_srand((fix)timer_query()); do { trys++; NewPlayer = d_rand() % NumNetPlayerPositions; closest_dist = 0x7fffffff; for (i=0; i<N_players; i++ ) { if ( (i!=Player_num) && (Objects[Players[i].objnum].type == OBJ_PLAYER) ) { dist = find_connected_distance(&Objects[Players[i].objnum].pos, Objects[Players[i].objnum].segnum, &Player_init[NewPlayer].pos, Player_init[NewPlayer].segnum, 15, WID_FLY_FLAG ); // Used to be 5, search up to 15 segments if ( (dist < closest_dist) && (dist >= 0) ) { closest_dist = dist; } } } } while ( (closest_dist<i2f(15*20)) && (trys<MAX_PLAYERS*2) ); } else { // If deathmatch and not random, positions were already determined by sync packet reset_player_object(); reset_cruise(); return; } Assert(NewPlayer >= 0); Assert(NewPlayer < NumNetPlayerPositions); ConsoleObject->pos = Player_init[NewPlayer].pos; ConsoleObject->orient = Player_init[NewPlayer].orient; #ifdef NETWORK if ((Game_mode & GM_MULTI) && (Netgame.SpawnStyle == SPAWN_STYLE_PREVIEW) && Dead_player_camera != NULL) { ConsoleObject->orient = Dead_player_camera->orient; Dead_player_camera = NULL; } #endif obj_relink(ConsoleObject-Objects,Player_init[NewPlayer].segnum); reset_player_object(); reset_cruise(); }
void step_game(struct moag *m) { crate_update(m); for (int i = 0; i < MAX_PLAYERS; i++) tank_update(m, i); for (int i = 0; i < MAX_BULLETS; i++) bullet_update(m, i); for (int i = 0; i < MAX_TIMERS; i++) timer_update(m, i); m->frame += 1; }
static void timer_hit(void *opaque) { struct Msf2Timer *st = opaque; st->regs[R_TIM_RIS] |= TIMER_RIS_ACK; if (!(st->regs[R_TIM_CTRL] & TIMER_CTRL_ONESHOT)) { timer_update(st); } timer_update_irq(st); }
static void* trd_timer(void* p) { timer_init(); for(;;) { timer_update(); if(timer_interval() >= speeds[GAME->level]) { move_down(); timer_reset(); } usleep(50); } }
Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog) { /* UTF-8 support */ QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); ui->setupUi(this); QString title = "MyShell 0.4 - tanhangbo build " + tr(__DATE__); this->setWindowTitle(title); this->setWindowFlags(this->windowFlags() | Qt::WindowMinMaxButtonsHint); serial = new QSerialPort(this); connect(serial, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(handleError(QSerialPort::SerialPortError))); connect(serial, SIGNAL(readyRead()), this, SLOT(readData())); standardItemModel = new QStandardItemModel(this); ui->history_list->setModel(standardItemModel); ui->status->setText(""); /* arrow up and down event */ ui->sendcontent->installEventFilter(this); ui->receive_content->installEventFilter(this); history_index = 0; current_index = 0; log_current_file_name = ""; log_is_logging = false; cur_file = NULL; receive_buffer = ""; error_closed = 0; need_add_time = false; find_serial(); timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(timer_update())); timer->start(10); }
void skynet_updatetime(void) { uint32_t ct = _gettime(); if (ct != TI->current) { int diff = ct>=TI->current?ct-TI->current:(0xffffff+1)*100-TI->current+ct; TI->current = ct; int i; for (i=0;i<diff;i++) { timer_update(TI); } } }
vc_input_dialog::vc_input_dialog(avbotqtui_impl* _ui_impl, std::string imgdata, int timeout_sec, avbotui::vc_result_call_back cb, QWidget *parent) : QDialog(parent) , m_handler(cb) , ui_impl(_ui_impl) , m_time_remains(timeout_sec) { ui.setupUi(this); m_posted = false; setAttribute(Qt::WA_DeleteOnClose); QImage qimg; qimg.loadFromData(reinterpret_cast<const uchar*>(imgdata.data()), imgdata.size()); ui.vcimg->setPixmap(QPixmap::fromImage(qimg)); auto timer =new QTimer(this); QObject::connect(timer, SIGNAL(timeout()), this, SLOT(timer_update())); timer->start(1000); timer_update(); }
void niuniu(void) { int_init(); timer_init(); beeper_init(); uart_init(); timer_update(); while(1) { puts("haha ......\r\n"); sleep(1); } }
/* 更新定时器中的时间并触发定时器. 若时间变化将先增加至 current 厘秒字段, 仅当其无法表示时才更新至 starttime 秒字段中. * 同时更新的还有表示当前时间点的 current_point 字段. */ void skynet_updatetime(void) { /* 获取到精确的距离某个时间点的时间戳, 用于确定时间流逝. */ uint64_t cp = gettime(); if(cp < TI->current_point) { skynet_error(NULL, "time diff error: change from %lld to %lld", cp, TI->current_point); TI->current_point = cp; } else if (cp != TI->current_point) { uint32_t diff = (uint32_t)(cp - TI->current_point); TI->current_point = cp; TI->current += diff; int i; for (i=0;i<diff;i++) { timer_update(TI); } } }
static void *timer(void *p) { struct watcher *watcher = (struct watcher *)p; while (1) { timer_update(); if (service_total() == 0) break; if (watcher->sleep >= 1) pthread_cond_signal(&watcher->cond); usleep(2500); } socket_exit(); pthread_mutex_lock(&watcher->mutex); watcher->quit = 1; pthread_cond_broadcast(&watcher->cond); pthread_mutex_unlock(&watcher->mutex); return 0; }
void send_video_fn(void) { /* update the rate */ timer_update(send_video_fn, global_data.param[PARAM_VIDEO_RATE]); if (previous_image == NULL) return; /* transmit raw 8-bit image */ if (global_data.param[PARAM_USB_SEND_VIDEO] && !global_data.param[PARAM_VIDEO_ONLY]) { mavlink_send_image(previous_image); LEDToggle(LED_COM); } else if (!global_data.param[PARAM_USB_SEND_VIDEO]) { LEDOff(LED_COM); } }
void skynet_updatetime(void) { uint64_t cp = gettime(); if(cp < TI->current_point) { skynet_error(NULL, "time diff error: change from %lld to %lld", cp, TI->current_point); } else if (cp != TI->current_point) { uint32_t diff = (uint32_t)(cp - TI->current_point); TI->current_point = cp; uint32_t oc = TI->current; TI->current += diff; if (TI->current < oc) { // when cs > 0xffffffff(about 497 days), time rewind TI->starttime += 0xffffffff / 100; } int i; for (i=0;i<diff;i++) { timer_update(TI); } } }
int io_select(int64_t *remain, int64_t *timeout) { struct timeval tv; struct timeval *tp = NULL; int ret, i; /* timeout is present, set timeout pointer */ if(timeout) if(*timeout >= 0LL) { timer_to_timeval(&tv, (uint64_t *)timeout); tp = &tv; } /* Do the actual select() */ io_rfds_r = io_rfds; io_wfds_r = io_wfds; io_efds_r = io_efds; ret = syscall_select(io_top + 1, &io_rfds_r, &io_wfds_r, &io_efds_r, tp); /* Update system time */ timer_update(); /* Now set the returned events */ if(io_top >= 0) for(i = 0; i <= io_top; i++) { if(!io_list[i].type) continue; io_set_revents(i); } /* If there was timeout value then return remaining time */ if(tp && remain) timer_to_msec((uint64_t *)remain, tp); return ret; }
int main(int argc, char* args[]) { setlocale(LC_ALL, "de_DE.UTF-8"); if (init() == FALSE) return 1; Uint32 frameStart = 0; espeak_set_run(TRUE); int valid_input = -1; int do_input_name = FALSE; int do_input_continue = FALSE; int input_move_y = 0; while (quit == FALSE) { if (do_input_name == FALSE && do_input_continue == FALSE) timer_update(); frameStart = SDL_GetTicks(); while (SDL_PollEvent(&event)) { if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_RETURN) { int skip_input = (strcmp(input_str, "") == 0) ? TRUE : FALSE; if (do_input_continue && strcmp(input_str, "") != 0) { if (strcmp(input_str, "nein") == 0) { quit = TRUE; } else { do_input_continue = FALSE; textlist_init(); textlist_set_random_pos(); timer_start(); inputs_count = 0; input_init(); espeak_set_run(TRUE); } } else if (do_input_name == TRUE && strcmp(input_str, "") != 0) { scorelist_add_score(input_str_w, textlist_get_chars_count(), timer_get_seconds()); do_input_continue = TRUE; do_input_name = FALSE; input_init(); } else if (textlist_current_compare(input_str_w) == 0 || skip_input == TRUE) { if (skip_input == FALSE) valid_input = TRUE; inputs_count++; espeak_lock(); textlist_remove_current(skip_input); espeak_unlock(); if (inputs_count == max_inputs) { do_input_name = TRUE; input_init(); } if (do_input_name == FALSE && quit == FALSE) { espeak_lock(); quit = (textlist_set_random_pos() == TRUE) ? FALSE : TRUE; espeak_unlock(); input_init(); espeak_set_run(TRUE); } } else { valid_input = FALSE; input_init(); espeak_set_run(TRUE); } } else { handle_input(); } if (event.type == SDL_VIDEORESIZE) { screen_width = event.resize.w; screen_height = event.resize.h; screen = SDL_SetVideoMode( screen_width, screen_height, screen_bpp, SDL_SWSURFACE | SDL_RESIZABLE ); } if (event.type == SDL_QUIT) { quit = TRUE; } } SDL_FillRect(screen, &screen->clip_rect, SDL_MapRGB(screen->format, 0, 0, 0)); show_timer_text(); input_move_y = (do_input_continue == TRUE) ? screen_height * 0.1 : 0; if (do_input_continue == TRUE) output_scores(); show_info_text(valid_input, do_input_name, do_input_continue, input_move_y); input_show_centered(input_move_y); apply_surface( screen_width - footer_message->w, screen_height - footer_message->h, footer_message, screen ); apply_surface(0, 0, header_message, screen); if (SDL_Flip(screen) == -1) return 1; if ((SDL_GetTicks() - frameStart) < (1000 / FPS)) { SDL_Delay((1000 / FPS) - (SDL_GetTicks() - frameStart)); } } clean_up(); return 0; }
void calculator_task(void* vptr) { CalculationState calcState; uint16_t tankChange_ml = 0; uint16_t adc = 0; OS_ERR err; calculator_lcd_init(); adc_init(); timer_init(); // init values calcState.depth_mm = 0; calcState.rate_mm_per_m = 0; calcState.air_ml = 50 * 1000; // init air in ml calcState.elapsed_time_s = 0; calcState.current_alarms = ALARM_NONE; calcState.display_units = CALC_UNITS_METRIC; for (;;) { while (1) { // determine DisplayUnits - check if SW2 has been toggled OSSemPend(&g_sw2_sem, 0, OS_OPT_PEND_NON_BLOCKING, 0, &err); // Check for change if (OS_ERR_NONE == err) { calcState.display_units = (calcState.display_units == CALC_UNITS_METRIC ? CALC_UNITS_IMPERIAL : CALC_UNITS_METRIC); } else if (OS_ERR_PEND_WOULD_BLOCK == err) { // no update break; } else { assert(0); // error state } } adc = adc_read(); /* RATE and DEPTH */ // calculate ASCENT RATE int32_t rate_mm_per_m; int32_t descent_rate = ADC2RATE(adc); if(calcState.depth_mm > 0 || (calcState.depth_mm == 0 && descent_rate > 0)) { calcState.rate_mm_per_m = 1000 * descent_rate; } else { calcState.rate_mm_per_m = 0; } // calculate DEPTH int32_t depth_mm; calcState.depth_mm += depth_change_in_mm(calcState.rate_mm_per_m / 1000); // no flying divers if(calcState.depth_mm < 0) { calcState.depth_mm = 0; } /* UPDATE AIR */ // check SW2 air changes if(calcState.depth_mm == 0) { tankChange_ml = getTankChange_ml(); calcState.air_ml = (calcState.air_ml + tankChange_ml > 2000000) ? 2000000 : calcState.air_ml + tankChange_ml; } else { // calculate uint32_t air_ml; uint32_t gas_rate = gas_rate_in_cl(calcState.depth_mm) * 10; // cl -> ml if(gas_rate < calcState.air_ml) { calcState.air_ml -= gas_rate; } else { calcState.air_ml = 0; } } /* UPDATE TIMER */ // apply the timer logic timer_update(&calcState); // get value from timer calcState.elapsed_time_s = get_dive_time_in_seconds(); // alarms updateAlarms(&calcState); postAlarms(&calcState); /* DISPLAY STATE */ // determine alarm state enum CurrentAlarm current_alarm; calculator_lcd_update(&calcState); // sleep 500 ms OSTimeDlyHMSM(0, 0, 0, 500, OS_OPT_TIME_HMSM_STRICT, &err); } }
/* * SDL_main */ int SDL_main(int argc, char* argv[]) { SDL_Event event; SDL_Surface *screen, *icon; putenv(strdup("SDL_VIDEO_CENTERED=1")); if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) { printf("Unable to initialize SDL: %s\n", SDL_GetError()); return EXIT_FAILURE; } icon = SDL_LoadBMP("gui/icon.bmp"); SDL_WM_SetIcon(icon, NULL); SDL_WM_SetCaption("Convex Hull Testing", "Convex Hull Testing"); SDL_ShowCursor(SDL_DISABLE); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, etrue); //Initialize window // | SDL_FULLSCREEN screen = SDL_SetVideoMode(WINDOW_WIDTH, WINDOW_HEIGHT, 32, SDL_OPENGL | SDL_NOFRAME); if(!screen) { printf("Unable to set video mode: %s\n", SDL_GetError()); return EXIT_FAILURE; } SDL_WarpMouse(512.0, 384.0); //gameState = STATE_MAINMENU; timer_init(); renderer_init(); world_init(); //model_init(); //Main loop while(!user_exit) { //Handle input while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_KEYDOWN: input_keyDown(event.key.keysym.sym); break; case SDL_KEYUP: input_keyUp(event.key.keysym.sym); break; case SDL_MOUSEMOTION: input_mouseMove(event.motion.x, event.motion.y); break; case SDL_QUIT: user_exit = etrue; } } timer_update(); while(timer.accumulated >= TIMESTEP) { input_update(); world_update(); timer.accumulated -= TIMESTEP; } world_lerpPositions(timer.accumulated); renderer_drawFrame(); } SDL_Quit(); return EXIT_SUCCESS; }
/* * The main terminal loop: * - If there are characters received send them * to the screen via the appropriate translate function. */ int do_terminal(void) { char buf[128]; int buf_offset = 0; int c; int x; int blen; int zauto = 0; static const char zsig[] = "**\030B00"; int zpos = 0; const char *s; dirflush = 0; WIN *error_on_open_window = NULL; dirty_goto: /* Show off or online time */ update_status_time(); /* If the status line was shown temporarily, delete it again. */ if (tempst) { tempst = 0; mc_wclose(st, 1); st = NULL; } /* Auto Zmodem? */ if (P_PAUTO[0] >= 'A' && P_PAUTO[0] <= 'Z') zauto = P_PAUTO[0]; /* Set the terminal modes */ setcbreak(2); /* Raw, no echo */ keyboard(KSTART, 0); /* Main loop */ while (1) { /* See if window size changed */ if (size_changed) { size_changed = 0; wrapln = us->wrap; /* I got the resize code going again! Yeah! */ mc_wclose(us, 0); us = NULL; if (st) mc_wclose(st, 0); st = NULL; mc_wclose(stdwin, 0); if (win_init(tfcolor, tbcolor, XA_NORMAL) < 0) leave(_("Could not re-initialize window system.")); /* Set the terminal modes */ setcbreak(2); /* Raw, no echo */ init_emul(terminal, 0); } /* Update the timer. */ timer_update(); /* check if device is ok, if not, try to open it */ if (!get_device_status(portfd_connected)) { /* Ok, it's gone, most probably someone unplugged the USB-serial, we * need to free the FD so that a replug can get the same device * filename, open it again and be back */ int reopen = portfd == -1; close(portfd); lockfile_remove(); portfd = -1; if (open_term(reopen, reopen, 1) < 0) { if (!error_on_open_window) error_on_open_window = mc_tell(_("Cannot open %s!"), dial_tty); } else { if (error_on_open_window) { mc_wclose(error_on_open_window, 1); error_on_open_window = NULL; } } } /* Check for I/O or timer. */ x = check_io(portfd_connected, 0, 1000, buf + buf_offset, sizeof(buf) - buf_offset, &blen); blen += buf_offset; buf_offset = 0; /* Data from the modem to the screen. */ if ((x & 1) == 1) { char obuf[sizeof(buf)]; char *ptr; if (using_iconv()) { char *otmp = obuf; size_t output_len = sizeof(obuf); size_t input_len = blen; ptr = buf; do_iconv(&ptr, &input_len, &otmp, &output_len); // something happened at all? if (output_len < sizeof(obuf)) { if (input_len) { // something remained, we need to adapt buf accordingly memmove(buf, ptr, input_len); buf_offset = input_len; } blen = sizeof(obuf) - output_len; ptr = obuf; } else ptr = buf; } else { ptr = buf; } while (blen-- > 0) { /* Auto zmodem detect */ if (zauto) { if (zsig[zpos] == *ptr) zpos++; else zpos = 0; } if (P_PARITY[0] == 'M' || P_PARITY[0] == 'S') *ptr &= 0x7f; if (display_hex) { unsigned char c = *ptr++; unsigned char u = c >> 4; c &= 0xf; vt_out(u > 9 ? 'a' + (u - 10) : '0' + u); vt_out(c > 9 ? 'a' + (c - 10) : '0' + c); vt_out(' '); } else vt_out(*ptr++); if (zauto && zsig[zpos] == 0) { dirflush = 1; keyboard(KSTOP, 0); updown('D', zauto - 'A'); dirflush = 0; zpos = 0; blen = 0; goto dirty_goto; } } mc_wflush(); }
void draw_automap(automap *am) { int i; int color; object * objp; g3s_point sphere_point; if ( am->leave_mode==0 && am->controls.automap_state && (timer_query()-am->entry_time)>LEAVE_TIME) am->leave_mode = 1; gr_set_current_canvas(NULL); show_fullscr(&am->automap_background); gr_set_curfont(HUGE_FONT); gr_set_fontcolor(BM_XRGB(20, 20, 20), -1); gr_string((SWIDTH/8), (SHEIGHT/16), TXT_AUTOMAP); gr_set_curfont(GAME_FONT); gr_set_fontcolor(BM_XRGB(20, 20, 20), -1); gr_string((SWIDTH/10.666), (SHEIGHT/1.126), TXT_TURN_SHIP); gr_printf((SWIDTH/10.666), (SHEIGHT/1.083), "F9/F10 Changes viewing distance"); gr_string((SWIDTH/10.666), (SHEIGHT/1.043), TXT_AUTOMAP_MARKER); gr_set_current_canvas(&am->automap_view); gr_clear_canvas(BM_XRGB(0,0,0)); g3_start_frame(); render_start_frame(); if (!PlayerCfg.AutomapFreeFlight) vm_vec_scale_add(&am->view_position,&am->view_target,&am->viewMatrix.fvec,-am->viewDist); g3_set_view_matrix(&am->view_position,&am->viewMatrix,am->zoom); draw_all_edges(am); selected_player_rgb = player_rgb; // Draw player... #ifdef NETWORK if(Netgame.BlackAndWhitePyros) selected_player_rgb = player_rgb_alt; if (Game_mode & GM_TEAM) color = get_team(Player_num); else #endif color = Player_num; // Note link to above if! gr_setcolor(BM_XRGB(selected_player_rgb[color].r,selected_player_rgb[color].g,selected_player_rgb[color].b)); draw_player(&Objects[Players[Player_num].objnum]); DrawMarkers(am); // Draw player(s)... #ifdef NETWORK if ( (Game_mode & (GM_TEAM | GM_MULTI_COOP)) || (Netgame.game_flags & NETGAME_FLAG_SHOW_MAP) ) { for (i=0; i<N_players; i++) { if ( (i != Player_num) && ((Game_mode & GM_MULTI_COOP) || (get_team(Player_num) == get_team(i)) || (Netgame.game_flags & NETGAME_FLAG_SHOW_MAP)) ) { if ( Objects[Players[i].objnum].type == OBJ_PLAYER ) { if (Game_mode & GM_TEAM) color = get_team(i); else color = i; gr_setcolor(BM_XRGB(selected_player_rgb[color].r,selected_player_rgb[color].g,selected_player_rgb[color].b)); draw_player(&Objects[Players[i].objnum]); } } } } #endif objp = &Objects[0]; for (i=0;i<=Highest_object_index;i++,objp++) { switch( objp->type ) { case OBJ_HOSTAGE: gr_setcolor(am->hostage_color); g3_rotate_point(&sphere_point,&objp->pos); g3_draw_sphere(&sphere_point,objp->size); break; case OBJ_POWERUP: if ( Automap_visited[objp->segnum] ) { if ( (objp->id==POW_KEY_RED) || (objp->id==POW_KEY_BLUE) || (objp->id==POW_KEY_GOLD) ) { switch (objp->id) { case POW_KEY_RED: gr_setcolor(BM_XRGB(63, 5, 5)); break; case POW_KEY_BLUE: gr_setcolor(BM_XRGB(5, 5, 63)); break; case POW_KEY_GOLD: gr_setcolor(BM_XRGB(63, 63, 10)); break; default: Error("Illegal key type: %i", objp->id); } g3_rotate_point(&sphere_point,&objp->pos); g3_draw_sphere(&sphere_point,objp->size*4); } } break; } } g3_end_frame(); name_frame(am); if (HighlightMarker>-1 && MarkerMessage[HighlightMarker][0]!=0) { char msg[10+MARKER_MESSAGE_LEN+1]; sprintf(msg,"Marker %d: %s",HighlightMarker+1,MarkerMessage[(Player_num*2)+HighlightMarker]); gr_printf((SWIDTH/64),(SHEIGHT/18),"%s", msg); } if ((PlayerCfg.MouseControlStyle == MOUSE_CONTROL_FLIGHT_SIM) && PlayerCfg.MouseFSIndicator) show_mousefs_indicator(am->controls.raw_mouse_axis[0], am->controls.raw_mouse_axis[1], am->controls.raw_mouse_axis[2], GWIDTH-(GHEIGHT/8), GHEIGHT-(GHEIGHT/8), GHEIGHT/5); am->t2 = timer_query(); while (am->t2 - am->t1 < F1_0 / (GameCfg.VSync?MAXIMUM_FPS:GameArg.SysMaxFPS)) // ogl is fast enough that the automap can read the input too fast and you start to turn really slow. So delay a bit (and free up some cpu :) { if (GameArg.SysUseNiceFPS && !GameCfg.VSync) timer_delay(f1_0 / GameArg.SysMaxFPS - (am->t2 - am->t1)); timer_update(); am->t2 = timer_query(); } if (am->pause_game) { FrameTime=am->t2-am->t1; calc_d_tick(); } am->t1 = am->t2; }
MainWindow::MainWindow() : QMainWindow(), Ui_MainWindow() { // Initialize isMovingCircles, if we want to add a keyevent to // pause the moving circles we can call this, right now we make // sure that we only call it when we have circles inflated, but // it shouldn't matter, since the function only changes defined // points, so it should cause an issue if it's called even without // circles instantiated isMovingParticles = false; isMovingObstacles = false; isOpenFile = false; time_counter = 0.00; WIND_DIST_Y = 0.00; WIND_DIST_X = 0.00; OBSTACLE_RADIUS = .06; QString string_time = QString::number(time_counter,16); QString string_wind_x = QString::number(WIND_DIST_X); QString string_wind_y = QString::number(WIND_DIST_Y); QStringList list_wind_xy; list_wind_xy << string_wind_x << string_wind_y; QString string_wind_xy = list_wind_xy.join(","); exitAct = new QAction(tr("&Exit"), this); exitAct->setStatusTip(tr("exit the application")); connect(exitAct, SIGNAL(triggered()), this, SLOT(quit())); pauseAct = new QAction(tr("&Pause"), this); pauseAct->setStatusTip(tr("pause the simulation")); connect(pauseAct, SIGNAL(triggered()), this, SLOT(pause())); playAct = new QAction(tr("&Play"), this); playAct->setStatusTip(tr("continue the simulation")); connect(playAct, SIGNAL(triggered()), this, SLOT(play())); obstacleAct = new QAction(tr("&Oscillation"), this); obstacleAct->setStatusTip(tr("make the cilia oscillate")); connect(obstacleAct, SIGNAL(triggered()), this, SLOT(activate_obstacles())); coordAct = new QAction(tr("&Coordinates"), this); coordAct->setStatusTip(tr("print the coordinates data")); connect(coordAct, SIGNAL(triggered()), this, SLOT(coordinates())); radAct = new QAction(tr("&Radius"), this); radAct->setStatusTip(tr("print the radius data")); connect(radAct, SIGNAL(triggered()), this, SLOT(radius())); restartAct = new QAction(tr("&Restart"), this); restartAct->setStatusTip(tr("restart")); connect(restartAct, SIGNAL(triggered()), this, SLOT(restart())); defaultAct = new QAction(tr("&Default"), this); defaultAct->setStatusTip(tr("restart the simulation with default values")); connect(defaultAct, SIGNAL(triggered()), this, SLOT(default_values())); binAct = new QAction(tr("&Bins"), this); binAct->setStatusTip(tr("set the number of bins for histogram")); connect(binAct, SIGNAL(triggered()), this, SLOT(bin_count_window())); timeAct = new QAction(tr("&Time Elapsed:"), this); binAct->setStatusTip(tr("displaying the total time elapsed in milliseconds")); WindAct = new QAction(tr("&Wind:"), this); WindAct->setStatusTip(tr("Use the controls to increase or decrease wind")); upWindAct = new QAction(tr("&Up"), this); upWindAct->setStatusTip(tr("increase wind upwards")); connect(upWindAct, SIGNAL(triggered()), this, SLOT(upWind())); downWindAct = new QAction(tr("&Down"), this); downWindAct->setStatusTip(tr("increase wind downwards")); connect(downWindAct, SIGNAL(triggered()), this, SLOT(downWind())); leftWindAct = new QAction(tr("&Left"), this); leftWindAct->setStatusTip(tr("increase wind towards the left")); connect(leftWindAct, SIGNAL(triggered()), this, SLOT(leftWind())); rightWindAct = new QAction(tr("&Right"), this); rightWindAct->setStatusTip(tr("increase wind towards the right")); connect(rightWindAct, SIGNAL(triggered()), this, SLOT(rightWind())); OrAct = new QAction(tr("&Obstacle Size"), this); OrAct->setStatusTip(tr("set the Obstacle Size (radius)")); connect(OrAct, SIGNAL(triggered()), this, SLOT(setObstacleRadius_window())); //endtime = new QTimeEdit(); timetime = new QPlainTextEdit(string_time); timetime->setReadOnly(true); timetime->setMaximumHeight(25); timetime->setMaximumWidth(80); windwind = new QPlainTextEdit(string_wind_xy); windwind->setReadOnly(true); windwind->setMaximumHeight(25); windwind->setMaximumWidth(100); fileToolBar = addToolBar(tr("Tools")); fileToolBar->addAction(exitAct); fileToolBar->addAction(pauseAct); fileToolBar->addAction(playAct); fileToolBar->addAction(timeAct); fileToolBar->addWidget(timetime); fileToolBar->addAction(restartAct); fileToolBar->addAction(defaultAct); fileToolBar->addAction(binAct); fileToolBar->addAction(coordAct); fileToolBar->addAction(radAct); currentTool = addToolBar(tr("controls")); currentTool->addAction(obstacleAct); currentTool->addAction(WindAct); currentTool->addWidget(windwind); currentTool->addAction(upWindAct); currentTool->addAction(downWindAct); currentTool->addAction(leftWindAct); currentTool->addAction(rightWindAct); currentTool->addAction(OrAct); fileToolBar->setAllowedAreas(Qt::BottomToolBarArea); addToolBar(Qt::BottomToolBarArea, fileToolBar); // Start the timer with interval TIMER_INTERVAL, which is defined in // randomWalk.h. This calls timer_update() ever TIMER_INTERVAL ms QTimer *timer = new QTimer(this); QString it; //establish connections connect(timer, SIGNAL(timeout()), this, SLOT(timer_update())); timer->start(TIMER_INTERVAL); setupUi(this); }