static int stream_formatter_bin(FILE *pipe, void *data, metric_type type, char *name, void *value) { #define STREAM_BIN(...) if (stream_bin_writer(pipe, ((struct timeval *)data)->tv_sec, __VA_ARGS__, name)) return 1; #define STREAM_UINT(val) if (!fwrite(&val, sizeof(unsigned int), 1, pipe)) return 1; timer_hist *t; int i; switch (type) { case KEY_VAL: STREAM_BIN(BIN_TYPE_KV, BIN_OUT_NO_TYPE, *(double*)value); break; case GAUGE: STREAM_BIN(BIN_TYPE_GAUGE, BIN_OUT_NO_TYPE, ((gauge_t*)value)->value); break; case COUNTER: STREAM_BIN(BIN_TYPE_COUNTER, BIN_OUT_SUM, counter_sum(value)); STREAM_BIN(BIN_TYPE_COUNTER, BIN_OUT_SUM_SQ, counter_squared_sum(value)); STREAM_BIN(BIN_TYPE_COUNTER, BIN_OUT_MEAN, counter_mean(value)); STREAM_BIN(BIN_TYPE_COUNTER, BIN_OUT_COUNT, counter_count(value)); STREAM_BIN(BIN_TYPE_COUNTER, BIN_OUT_STDDEV, counter_stddev(value)); STREAM_BIN(BIN_TYPE_COUNTER, BIN_OUT_MIN, counter_min(value)); STREAM_BIN(BIN_TYPE_COUNTER, BIN_OUT_MAX, counter_max(value)); break; case SET: STREAM_BIN(BIN_TYPE_SET, BIN_OUT_SUM, set_size(value)); break; case TIMER: t = (timer_hist*)value; STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_SUM, timer_sum(&t->tm)); STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_SUM_SQ, timer_squared_sum(&t->tm)); STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_MEAN, timer_mean(&t->tm)); STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_COUNT, timer_count(&t->tm)); STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_STDDEV, timer_stddev(&t->tm)); STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_MIN, timer_min(&t->tm)); STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_MAX, timer_max(&t->tm)); STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_PCT | 50, timer_query(&t->tm, 0.5)); STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_PCT | 95, timer_query(&t->tm, 0.95)); STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_PCT | 99, timer_query(&t->tm, 0.99)); // Binary streaming for histograms if (t->conf) { STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_HIST_FLOOR, t->conf->min_val); STREAM_UINT(t->counts[0]); for (i=0; i < t->conf->num_bins-2; i++) { STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_HIST_BIN, t->conf->min_val+(t->conf->bin_width*i)); STREAM_UINT(t->counts[i+1]); } STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_HIST_CEIL, t->conf->max_val); STREAM_UINT(t->counts[i+1]); } break; default: syslog(LOG_ERR, "Unknown metric type: %d", type); break; } return 0; }
static void put_char_delay(const grs_font &cv_font, briefing *const br, const char ch) { char str[2]; int w; str[0] = ch; str[1] = '\0'; if (br->delay_count && (timer_query() < br->start_time + br->delay_count)) { br->message--; // Go back to same character return; } if (br->streamcount >= br->messagestream.size()) return; br->messagestream[br->streamcount].x = br->text_x; br->messagestream[br->streamcount].y = br->text_y; br->messagestream[br->streamcount].color = *Current_color; br->messagestream[br->streamcount].ch = ch; br->streamcount++; br->prev_ch = ch; gr_get_string_size(cv_font, str, &w, nullptr, nullptr); br->text_x += w; #if defined(DXX_BUILD_DESCENT_II) if (!EMULATING_D1 && !br->chattering) { br->printing_channel.reset(digi_start_sound(digi_xlat_sound(SOUND_BRIEFING_PRINTING), F1_0, 0xFFFF/2, 1, -1, -1, sound_object_none)); br->chattering=1; } #endif br->start_time = timer_query(); }
/** * Streaming callback to format our output */ static int stream_formatter(FILE *pipe, void *data, metric_type type, char *name, void *value) { #define STREAM(...) if (fprintf(pipe, __VA_ARGS__, (long long)tv->tv_sec) < 0) return 1; struct timeval *tv = data; switch (type) { case KEY_VAL: STREAM("kv.%s|%f|%lld\n", name, *(double*)value); break; case COUNTER: STREAM("counts.%s|%f|%lld\n", name, counter_sum(value)); break; case TIMER: STREAM("timers.%s.sum|%f|%lld\n", name, timer_sum(value)); STREAM("timers.%s.mean|%f|%lld\n", name, timer_mean(value)); STREAM("timers.%s.lower|%f|%lld\n", name, timer_min(value)); STREAM("timers.%s.upper|%f|%lld\n", name, timer_max(value)); STREAM("timers.%s.count|%lld|%lld\n", name, timer_count(value)); STREAM("timers.%s.stdev|%f|%lld\n", name, timer_stddev(value)); STREAM("timers.%s.median|%f|%lld\n", name, timer_query(value, 0.5)); STREAM("timers.%s.p95|%f|%lld\n", name, timer_query(value, 0.95)); STREAM("timers.%s.p99|%f|%lld\n", name, timer_query(value, 0.99)); break; default: syslog(LOG_ERR, "Unknown metric type: %d", type); break; } return 0; }
int main(int argc, char *argv[]) { struct local_drm_i915_reg_read reg_read; int ret, fd; uint64_t val; fd = drm_open_any(); reg_read.offset = 0x2358; ret = drmIoctl(fd, REG_READ_IOCTL, ®_read); if (errno == EINVAL) exit(77); else if (ret) exit(EXIT_FAILURE); val = timer_query(fd); sleep(1); if (timer_query(fd) == val) { fprintf(stderr, "Timer isn't moving, probably busted\n"); exit(EXIT_FAILURE); } /* bad reg */ reg_read.offset = 0x12345678; ret = drmIoctl(fd, REG_READ_IOCTL, ®_read); handle_bad(ret, errno, EINVAL, "bad register"); close(fd); exit(EXIT_SUCCESS); }
void show_framerate() { static int fps_count = 0, fps_rate = 0; int y = GHEIGHT; static fix64 fps_time = 0; gr_set_curfont(GAME_FONT); gr_set_fontcolor(BM_XRGB(0,31,0),-1); if (PlayerCfg.CockpitMode[1] == CM_FULL_SCREEN) { if ((Game_mode & GM_MULTI) || (Newdemo_state == ND_STATE_PLAYBACK && Newdemo_game_mode & GM_MULTI)) y -= LINE_SPACING * 10; else y -= LINE_SPACING * 4; } else if (PlayerCfg.CockpitMode[1] == CM_STATUS_BAR) { if ((Game_mode & GM_MULTI) || (Newdemo_state == ND_STATE_PLAYBACK && Newdemo_game_mode & GM_MULTI)) y -= LINE_SPACING * 6; else y -= LINE_SPACING * 1; } else { if ((Game_mode & GM_MULTI) || (Newdemo_state == ND_STATE_PLAYBACK && Newdemo_game_mode & GM_MULTI)) y -= LINE_SPACING * 7; else y -= LINE_SPACING * 2; } fps_count++; if (timer_query() >= fps_time + F1_0) { fps_rate = fps_count; fps_count = 0; fps_time = timer_query(); } gr_printf(SWIDTH-(GameArg.SysMaxFPS>999?FSPACX(43):FSPACX(37)),y,"FPS: %i",fps_rate); }
/** * Streaming callback to format our output */ static int stream_formatter(FILE *pipe, void *data, metric_type type, char *name, void *value) { #define STREAM(...) if (fprintf(pipe, __VA_ARGS__, (long long)tv->tv_sec) < 0) return 1; struct timeval *tv = data; timer_hist *t; int i; switch (type) { case KEY_VAL: STREAM("%s|%f|%lld\n", name, *(double*)value); break; case GAUGE: STREAM("%s|%f|%lld\n", name, ((gauge_t*)value)->value); break; case COUNTER: STREAM("%s|%f|%lld\n", name, counter_sum(value)); break; case SET: STREAM("%s|%lld|%lld\n", name, set_size(value)); break; case TIMER: t = (timer_hist*)value; STREAM("timers.%s.sum|%f|%lld\n", name, timer_sum(&t->tm)); STREAM("timers.%s.sum_sq|%f|%lld\n", name, timer_squared_sum(&t->tm)); STREAM("timers.%s.mean|%f|%lld\n", name, timer_mean(&t->tm)); STREAM("timers.%s.lower|%f|%lld\n", name, timer_min(&t->tm)); STREAM("timers.%s.upper|%f|%lld\n", name, timer_max(&t->tm)); STREAM("timers.%s.count|%lld|%lld\n", name, timer_count(&t->tm)); STREAM("timers.%s.stdev|%f|%lld\n", name, timer_stddev(&t->tm)); STREAM("timers.%s.median|%f|%lld\n", name, timer_query(&t->tm, 0.5)); STREAM("timers.%s.upper_90|%f|%lld\n", name, timer_query(&t->tm, 0.9)); STREAM("timers.%s.upper_95|%f|%lld\n", name, timer_query(&t->tm, 0.95)); STREAM("timers.%s.upper_99|%f|%lld\n", name, timer_query(&t->tm, 0.99)); // Stream the histogram values if (t->conf) { STREAM("%s.histogram.bin_<%0.2f|%u|%lld\n", name, t->conf->min_val, t->counts[0]); for (i=0; i < t->conf->num_bins-2; i++) { STREAM("%s.histogram.bin_%0.2f|%u|%lld\n", name, t->conf->min_val+(t->conf->bin_width*i), t->counts[i+1]); } STREAM("%s.histogram.bin_>%0.2f|%u|%lld\n", name, t->conf->max_val, t->counts[i+1]); } break; default: syslog(LOG_ERR, "Unknown metric type: %d", type); break; } return 0; }
// check if we need to call the 'finished' hook // needs to go in all event loops // a real hook would be ideal, but is currently unsupported by SDL Audio CD void RBACheckFinishedHook() { static fix64 last_check_time = 0; if (!s_cd) return; if ((timer_query() - last_check_time) >= F2_0) { if ((SDL_CDStatus(s_cd) == CD_STOPPED) && redbook_finished_hook) redbook_finished_hook(); last_check_time = timer_query(); } }
void digi_start_sound_queued( short soundnum, fix volume ) { int i; soundnum = digi_xlat_sound(soundnum); if (soundnum < 0 ) return; i = SoundQ_tail+1; if ( i>=MAX_Q ) i = 0; // Make sure its loud so it doesn't get cancelled! if ( volume < F1_0+1 ) volume = F1_0 + 1; if ( i != SoundQ_head ) { SoundQ[SoundQ_tail].time_added = timer_query(); SoundQ[SoundQ_tail].soundnum = soundnum; SoundQ_num++; SoundQ_tail = i; } // Try to start it! SoundQ_process(); }
static void show_title_screen(const char * filename, int allow_keys, int from_hog_only ) { int pcx_error; char new_filename[PATH_MAX] = ""; auto ts = make_unique<title_screen>(); ts->allow_keys = allow_keys; #ifdef RELEASE if (from_hog_only) strcpy(new_filename,"\x01"); //only read from hog file #else (void)from_hog_only; #endif strcat(new_filename,filename); filename = new_filename; if ((pcx_error=pcx_read_bitmap( filename, ts->title_bm, gr_palette ))!=PCX_ERROR_NONE) { Error( "Error loading briefing screen <%s>, PCX load error: %s (%i)\n",filename, pcx_errormsg(pcx_error), pcx_error); } ts->timer = timer_query() + i2f(3); gr_palette_load( gr_palette ); const auto wind = window_create(grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, title_handler, ts.get()); if (!wind) { return; } event_process_all(); }
static window_event_result robot_dialog_created(UI_DIALOG *const w, robot_dialog *const r) { r->quitButton = ui_add_gadget_button(w, 20, 286, 40, 32, "Done", NULL); r->prev_powerup_type = ui_add_gadget_button(w, GOODY_X+50, GOODY_Y-3, 25, 22, "<<", GoodyPrevType); r->next_powerup_type = ui_add_gadget_button(w, GOODY_X+80, GOODY_Y-3, 25, 22, ">>", GoodyNextType); r->prev_powerup_id = ui_add_gadget_button(w, GOODY_X+50, GOODY_Y+21, 25, 22, "<<", GoodyPrevID); r->next_powerup_id = ui_add_gadget_button(w, GOODY_X+80, GOODY_Y+21, 25, 22, ">>", GoodyNextID); r->prev_powerup_count = ui_add_gadget_button(w, GOODY_X+50, GOODY_Y+45, 25, 22, "<<", GoodyPrevCount); r->next_powerup_count = ui_add_gadget_button(w, GOODY_X+80, GOODY_Y+45, 25, 22, ">>", GoodyNextCount); r->initialMode[0] = ui_add_gadget_radio(w, 6, 58, 16, 16, 0, "Hover"); r->initialMode[1] = ui_add_gadget_radio(w, 76, 58, 16, 16, 0, "Normal"); r->initialMode[2] = ui_add_gadget_radio(w, 6, 78, 16, 16, 0, "(hide)"); r->initialMode[3] = ui_add_gadget_radio(w, 76, 78, 16, 16, 0, "Avoid"); r->initialMode[4] = ui_add_gadget_radio(w, 6, 98, 16, 16, 0, "Follow"); r->initialMode[5] = ui_add_gadget_radio(w, 76, 98, 16, 16, 0, "Station"); // The little box the robots will spin in. r->robotViewBox = ui_add_gadget_userbox(w, 155, 5, 150, 125); // The little box the robots will spin in. r->containsViewBox = ui_add_gadget_userbox(w, 10, 202, 100, 80); // A bunch of buttons... int i = 135; r->prev_robot_type = ui_add_gadget_button(w, 190, i, 53, 26, "<<Typ", RobotPrevType); r->next_robot_type = ui_add_gadget_button(w, 247, i, 53, 26, "Typ>>", RobotNextType); i += 29; r->next_segment = ui_add_gadget_button(w, 190, i, 110, 26, "Next in Seg", LocalObjectSelectNextinSegment); i += 29; r->prev_object = ui_add_gadget_button(w, 190, i, 53, 26, "<<Obj", LocalObjectSelectPrevinMine); r->next_object = ui_add_gadget_button(w, 247, i, 53, 26, ">>Obj", LocalObjectSelectNextinMine); i += 29; r->delete_object = ui_add_gadget_button(w, 190, i, 110, 26, "Delete", LocalObjectDelete); i += 29; r->new_object = ui_add_gadget_button(w, 190, i, 110, 26, "Create New", LocalObjectPlaceObject); i += 29; r->set_path = ui_add_gadget_button(w, 190, i, 110, 26, "Set Path", med_set_ai_path); r->time = timer_query(); r->old_object = -2; // Set to some dummy value so everything works ok on the first frame. if ( Cur_object_index == object_none) LocalObjectSelectNextinMine(); return window_event_result::handled; }
// If we want to display/hide cursor, do so if not already and also hide it automatically after some time. void mouse_cursor_autohide() { static fix64 hidden_time = 0; const auto is_showing = SDL_ShowCursor(SDL_QUERY); int result; if (Mouse.cursor_enabled) { const auto now = timer_query(); const auto cursor_time = Mouse.cursor_time; const auto recent_cursor_time = cursor_time + (F1_0*2) >= now; if (is_showing) { if (recent_cursor_time) return; hidden_time = now; result = SDL_DISABLE; } else { if (!(recent_cursor_time && hidden_time + (F1_0/2) < now)) return; result = SDL_ENABLE; } } else { if (!is_showing) return; result = SDL_DISABLE; } SDL_ShowCursor(result); }
//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(); }
static VALUE strstat_timer_query(VALUE self, VALUE rb_query) { double query; timer *i_timer; query = NUM2DBL(rb_query); if (query < 0 || query > 1) rb_raise(rb_eRuntimeError, "invalid quantile"); i_timer = (timer*) strstat_get_struct(self); return DBL2NUM(timer_query(i_timer, query)); }
window_event_result mouse_motion_handler(SDL_MouseMotionEvent *mme) { Mouse.cursor_time = timer_query(); Mouse.x += mme->xrel; Mouse.y += mme->yrel; // z handled in mouse_button_handler const d_event_mouse_moved event{EVENT_MOUSE_MOVED, mme->xrel, mme->yrel, 0}; //con_printf(CON_DEBUG, "Sending event EVENT_MOUSE_MOVED, relative motion %d,%d,%d", // event.dx, event.dy, event.dz); return event_send(event); }
window_event_result mouse_button_handler(SDL_MouseButtonEvent *mbe) { window_event_result highest_result(window_event_result::ignored); if (unlikely(CGameArg.CtlNoMouse)) return window_event_result::ignored; // to bad, SDL buttons use a different mapping as descent expects, // this is at least true and tested for the first three buttons static const array<int, 17> button_remap{{ MBTN_LEFT, MBTN_MIDDLE, MBTN_RIGHT, MBTN_Z_UP, MBTN_Z_DOWN, MBTN_PITCH_BACKWARD, MBTN_PITCH_FORWARD, MBTN_BANK_LEFT, MBTN_BANK_RIGHT, MBTN_HEAD_LEFT, MBTN_HEAD_RIGHT, MBTN_11, MBTN_12, MBTN_13, MBTN_14, MBTN_15, MBTN_16 }}; const unsigned button_idx = mbe->button - 1; // -1 since SDL seems to start counting at 1 if (unlikely(button_idx >= button_remap.size())) return window_event_result::ignored; const auto now = timer_query(); const auto button = button_remap[button_idx]; const auto mbe_state = mbe->state; Mouse.cursor_time = now; const auto pressed = mbe_state != SDL_RELEASED; if (pressed) { highest_result = maybe_send_z_move(button); } highest_result = std::max(send_singleclick(pressed, button), highest_result); //Double-click support if (pressed) { highest_result = std::max(maybe_send_doubleclick(now, button), highest_result); } return highest_result; }
static window_event_result hostage_dialog_created(UI_DIALOG *const w, hostage_dialog *const h) { h->quitButton = ui_add_gadget_button(w, 20, 222, 48, 40, "Done", NULL); // The little box the hostage vclip will play in. h->hostageViewBox = ui_add_gadget_userbox(w, 10, 90+10, 64, 64); // A bunch of buttons... int i = 90; h->next = ui_add_gadget_button(w, 155, i, 140, 26, "Next Hostage", SelectNextHostage); i += 29; h->prev = ui_add_gadget_button(w, 155, i, 140, 26, "Prev Hostage", SelectPrevHostage); i += 29; h->compress = ui_add_gadget_button(w, 155, i, 140, 26, "Compress All", CompressHostages); i += 29; h->delete_object = ui_add_gadget_button(w, 155, i, 140, 26, "Delete", ObjectDelete); i += 29; h->new_object = ui_add_gadget_button(w, 155, i, 140, 26, "Create New", PlaceHostage); i += 29; h->time = timer_query(); LastHostageIndex = -2; // Set to some dummy value so everything works ok on the first frame. return window_event_result::ignored; }
static window_event_result title_handler(window *, const d_event &event, title_screen *ts) { window_event_result result; switch (event.type) { case EVENT_MOUSE_BUTTON_DOWN: if (event_mouse_get_button(event) != 0) return window_event_result::ignored; else if (ts->allow_keys) { return window_event_result::close; } break; case EVENT_KEY_COMMAND: if ((result = call_default_handler(event)) == window_event_result::ignored) if (ts->allow_keys) { return window_event_result::close; } return result; case EVENT_IDLE: timer_delay2(50); if (timer_query() > ts->timer) { return window_event_result::close; } break; case EVENT_WINDOW_DRAW: gr_set_default_canvas(); show_fullscr(*grd_curcanv, ts->title_bm); break; case EVENT_WINDOW_CLOSE: break; default: break; } return window_event_result::ignored; }
void ui_listbox_change(UI_DIALOG *dlg, UI_GADGET_LISTBOX *listbox, short numitems, char **list) { int stop, start; UI_GADGET_SCROLLBAR * scrollbar; dlg = dlg; listbox->list = list; listbox->num_items = numitems; listbox->first_item = 0; listbox->current_item = -1; listbox->last_scrolled = timer_query(); listbox->dragging = 0; listbox->selected_item = -1; listbox->status = 1; listbox->first_item = 0; listbox->current_item = listbox->old_current_item = 0; listbox->moved = 0; scrollbar = listbox->scrollbar; start=0; stop= numitems - listbox->num_items_displayed; if (stop < start) stop = start; scrollbar->horz = 0; scrollbar->start = start; scrollbar->stop = stop; scrollbar->fake_length = scrollbar->height; scrollbar->fake_position = 0; if (stop!=start) scrollbar->fake_size = (listbox->num_items_displayed * scrollbar->height)/(stop-start+1+listbox->num_items_displayed); else scrollbar->fake_size = scrollbar->height; if (scrollbar->fake_size < 7) scrollbar->fake_size = 7; scrollbar->dragging = 0; scrollbar->moved=0; scrollbar->status=1; }
void SoundQ_process() { if ( SoundQ_channel > -1 ) { if ( digi_is_channel_playing(SoundQ_channel) ) return; SoundQ_end(); } while ( SoundQ_head != SoundQ_tail ) { sound_q * q = &SoundQ[SoundQ_head]; if ( q->time_added+MAX_LIFE > timer_query() ) { SoundQ_channel = digi_start_sound(q->soundnum, F1_0+1, 0xFFFF/2, 0, -1, -1, -1 ); return; } else { // expired; remove from Queue SoundQ_end(); } } }
void scores_view(stats_info *last_game, int citem) { scores_menu *menu; MALLOC(menu, scores_menu, 1); if (!menu) return; menu->citem = citem; menu->t1 = timer_query(); menu->looper = 0; if (last_game) menu->last_game = *last_game; newmenu_free_background(); scores_read(&menu->scores); set_screen_mode(SCREEN_MENU); show_menus(); window_create(&grd_curscreen->sc_canvas, (SWIDTH - FSPACX(320))/2, (SHEIGHT - FSPACY(200))/2, FSPACX(320), FSPACY(200), (int (*)(window *, d_event *, void *))scores_handler, menu); }
void do_automap( int key_code ) { int pcx_error; ubyte pal[256*3]; window *automap_wind = NULL; automap *am; CALLOC(am, automap, 1); if (am) { automap_wind = window_create(&grd_curscreen->sc_canvas, 0, 0, SWIDTH, SHEIGHT, (int (*)(window *, d_event *, void *)) automap_handler, am); } if (automap_wind == NULL) { Warning("Out of memory"); return; } am->leave_mode = 0; am->pause_game = 1; // Set to 1 if everything is paused during automap...No pause during net. am->max_segments_away = 0; am->segment_limit = 1; am->num_edges = 0; am->highest_edge_index = -1; am->max_edges = Num_segments*12; MALLOC(am->edges, Edge_info, am->max_edges); MALLOC(am->drawingListBright, int, am->max_edges); if (!am->edges || !am->drawingListBright) { if (am->edges) d_free(am->edges); if (am->drawingListBright) d_free(am->drawingListBright); Warning("Out of memory"); return; } am->zoom = 0x9000; am->farthest_dist = (F1_0 * 20 * 50); // 50 segments away am->viewDist = 0; init_automap_colors(am); key_code = key_code; // disable warning... if ((Game_mode & GM_MULTI) && (!Endlevel_sequence)) am->pause_game = 0; if (am->pause_game) { window_set_visible(Game_wind, 0); } if (!am->pause_game) { am->old_wiggle = ConsoleObject->mtype.phys_info.flags & PF_WIGGLE; // Save old wiggle ConsoleObject->mtype.phys_info.flags &= ~PF_WIGGLE; // Turn off wiggle } //Max_edges = min(MAX_EDGES_FROM_VERTS(Num_vertices),MAX_EDGES); //make maybe smaller than max gr_set_current_canvas(NULL); automap_build_edge_list(am); if ( am->viewDist==0 ) am->viewDist = ZOOM_DEFAULT; am->viewMatrix = Objects[Players[Player_num].objnum].orient; am->tangles.p = PITCH_DEFAULT; am->tangles.h = 0; am->tangles.b = 0; am->view_target = Objects[Players[Player_num].objnum].pos; if (PlayerCfg.AutomapFreeFlight) vm_vec_scale_add(&am->view_position, &Objects[Players[Player_num].objnum].pos, &am->viewMatrix.fvec, -ZOOM_DEFAULT ); am->t1 = am->entry_time = timer_query(); am->t2 = am->t1; //Fill in Automap_visited from Objects[Players[Player_num].objnum].segnum am->max_segments_away = set_segment_depths(Objects[Players[Player_num].objnum].segnum, Automap_visited); am->segment_limit = am->max_segments_away; adjust_segment_limit(am, am->segment_limit); // ZICO - code from above to show frame in OGL correctly. Redundant, but better readable. // KREATOR - Now applies to all platforms so double buffering is supported gr_init_bitmap_data (&am->automap_background); pcx_error = pcx_read_bitmap(MAP_BACKGROUND_FILENAME, &am->automap_background, BM_LINEAR, pal); if (pcx_error != PCX_ERROR_NONE) Error("File %s - PCX error: %s", MAP_BACKGROUND_FILENAME, pcx_errormsg(pcx_error)); gr_remap_bitmap_good(&am->automap_background, pal, -1, -1); gr_init_sub_canvas(&am->automap_view, &grd_curscreen->sc_canvas, (SWIDTH/23), (SHEIGHT/6), (SWIDTH/1.1), (SHEIGHT/1.45)); gr_palette_load( gr_palette ); Automap_active = 1; }
int wall_dialog_handler(UI_DIALOG *dlg, d_event *event, wall_dialog *wd) { int i; sbyte type; fix DeltaTime; fix64 Temp; int keypress = 0; int rval = 0; if (event->type == EVENT_KEY_COMMAND) keypress = event_key_get(event); Assert(MainWindow != NULL); //------------------------------------------------------------ // Call the ui code.. //------------------------------------------------------------ ui_button_any_drawn = 0; //------------------------------------------------------------ // If we change walls, we need to reset the ui code for all // of the checkboxes that control the wall flags. //------------------------------------------------------------ if (wd->old_wall_num != Cursegp->sides[Curside].wall_num) { if ( Cursegp->sides[Curside].wall_num != -1) { wall *w = &Walls[Cursegp->sides[Curside].wall_num]; ui_checkbox_check(wd->doorFlag[0], w->flags & WALL_DOOR_LOCKED); ui_checkbox_check(wd->doorFlag[1], w->flags & WALL_DOOR_AUTO); ui_checkbox_check(wd->doorFlag[2], w->flags & WALL_ILLUSION_OFF); ui_radio_set_value(wd->keyFlag[0], w->keys & KEY_NONE); ui_radio_set_value(wd->keyFlag[1], w->keys & KEY_BLUE); ui_radio_set_value(wd->keyFlag[2], w->keys & KEY_RED); ui_radio_set_value(wd->keyFlag[3], w->keys & KEY_GOLD); } } //------------------------------------------------------------ // If any of the checkboxes that control the wallflags are set, then // update the corresponding wall flag. //------------------------------------------------------------ if (Walls[Cursegp->sides[Curside].wall_num].type == WALL_DOOR) { if (GADGET_PRESSED(wd->doorFlag[0])) { if ( wd->doorFlag[0]->flag == 1 ) Walls[Cursegp->sides[Curside].wall_num].flags |= WALL_DOOR_LOCKED; else Walls[Cursegp->sides[Curside].wall_num].flags &= ~WALL_DOOR_LOCKED; rval = 1; } else if (GADGET_PRESSED(wd->doorFlag[1])) { if ( wd->doorFlag[1]->flag == 1 ) Walls[Cursegp->sides[Curside].wall_num].flags |= WALL_DOOR_AUTO; else Walls[Cursegp->sides[Curside].wall_num].flags &= ~WALL_DOOR_AUTO; rval = 1; } //------------------------------------------------------------ // If any of the radio buttons that control the mode are set, then // update the corresponding key. //------------------------------------------------------------ for ( i=0; i < 4; i++ ) { if (GADGET_PRESSED(wd->keyFlag[i])) { Walls[Cursegp->sides[Curside].wall_num].keys = 1<<i; // Set the ai_state to the cooresponding radio button rval = 1; } } } else { for (i = 0; i < 2; i++) ui_checkbox_check(wd->doorFlag[i], 0); for ( i=0; i < 4; i++ ) ui_radio_set_value(wd->keyFlag[i], 0); } if (Walls[Cursegp->sides[Curside].wall_num].type == WALL_ILLUSION) { if (GADGET_PRESSED(wd->doorFlag[2])) { if ( wd->doorFlag[2]->flag == 1 ) Walls[Cursegp->sides[Curside].wall_num].flags |= WALL_ILLUSION_OFF; else Walls[Cursegp->sides[Curside].wall_num].flags &= ~WALL_ILLUSION_OFF; rval = 1; } } else for ( i=2; i < 3; i++ ) if (wd->doorFlag[i]->flag == 1) { wd->doorFlag[i]->flag = 0; // Tells ui that this button isn't checked wd->doorFlag[i]->status = 1; // Tells ui to redraw button } //------------------------------------------------------------ // Draw the wall in the little 64x64 box //------------------------------------------------------------ if (event->type == EVENT_UI_DIALOG_DRAW) { // A simple frame time counter for animating the walls... Temp = timer_query(); DeltaTime = Temp - wd->time; gr_set_current_canvas( wd->wallViewBox->canvas ); if (Cursegp->sides[Curside].wall_num != -1) { type = Walls[Cursegp->sides[Curside].wall_num].type; if ((type == WALL_DOOR) || (type == WALL_BLASTABLE)) { if (DeltaTime > ((F1_0*200)/1000)) { wd->framenum++; wd->time = Temp; } if (wd->framenum >= WallAnims[Walls[Cursegp->sides[Curside].wall_num].clip_num].num_frames) wd->framenum=0; PIGGY_PAGE_IN(Textures[WallAnims[Walls[Cursegp->sides[Curside].wall_num].clip_num].frames[wd->framenum]]); gr_ubitmap(0,0, &GameBitmaps[Textures[WallAnims[Walls[Cursegp->sides[Curside].wall_num].clip_num].frames[wd->framenum]].index]); } else { if (type == WALL_OPEN) gr_clear_canvas( CBLACK ); else { if (Cursegp->sides[Curside].tmap_num2 > 0) gr_ubitmap(0,0, texmerge_get_cached_bitmap( Cursegp->sides[Curside].tmap_num, Cursegp->sides[Curside].tmap_num2)); else { PIGGY_PAGE_IN(Textures[Cursegp->sides[Curside].tmap_num]); gr_ubitmap(0,0, &GameBitmaps[Textures[Cursegp->sides[Curside].tmap_num].index]); } } } } else gr_clear_canvas( CGREY ); } //------------------------------------------------------------ // If anything changes in the ui system, redraw all the text that // identifies this wall. //------------------------------------------------------------ if (event->type == EVENT_UI_DIALOG_DRAW) { if ( Cursegp->sides[Curside].wall_num > -1 ) { ui_dprintf_at( MainWindow, 12, 6, "Wall: %d ", Cursegp->sides[Curside].wall_num); switch (Walls[Cursegp->sides[Curside].wall_num].type) { case WALL_NORMAL: ui_dprintf_at( MainWindow, 12, 23, " Type: Normal " ); break; case WALL_BLASTABLE: ui_dprintf_at( MainWindow, 12, 23, " Type: Blastable" ); break; case WALL_DOOR: ui_dprintf_at( MainWindow, 12, 23, " Type: Door " ); ui_dprintf_at( MainWindow, 223, 6, "%s", WallAnims[Walls[Cursegp->sides[Curside].wall_num].clip_num].filename); break; case WALL_ILLUSION: ui_dprintf_at( MainWindow, 12, 23, " Type: Illusion " ); break; case WALL_OPEN: ui_dprintf_at( MainWindow, 12, 23, " Type: Open " ); break; case WALL_CLOSED: ui_dprintf_at( MainWindow, 12, 23, " Type: Closed " ); break; default: ui_dprintf_at( MainWindow, 12, 23, " Type: Unknown " ); break; } if (Walls[Cursegp->sides[Curside].wall_num].type != WALL_DOOR) ui_dprintf_at( MainWindow, 223, 6, " " ); ui_dprintf_at( MainWindow, 12, 40, " Clip: %d ", Walls[Cursegp->sides[Curside].wall_num].clip_num ); ui_dprintf_at( MainWindow, 12, 57, " Trigger: %d ", Walls[Cursegp->sides[Curside].wall_num].trigger ); } else { ui_dprintf_at( MainWindow, 12, 6, "Wall: none "); ui_dprintf_at( MainWindow, 12, 23, " Type: none "); ui_dprintf_at( MainWindow, 12, 40, " Clip: none "); ui_dprintf_at( MainWindow, 12, 57, " Trigger: none "); } } if (ui_button_any_drawn || (wd->old_wall_num != Cursegp->sides[Curside].wall_num) ) Update_flags |= UF_WORLD_CHANGED; if (event->type == EVENT_WINDOW_CLOSE) { d_free(wd); MainWindow = NULL; return 0; } if ( GADGET_PRESSED(wd->quitButton) || (keypress==KEY_ESC) ) { close_wall_window(); return 1; } wd->old_wall_num = Cursegp->sides[Curside].wall_num; return rval; }
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); if (!MacHog) gr_printf((SWIDTH/8), (SHEIGHT/16), TXT_AUTOMAP); else gr_printf(80*(SWIDTH/640.0), 36*(SHEIGHT/480.0), TXT_AUTOMAP); gr_set_curfont(GAME_FONT); gr_set_fontcolor(BM_XRGB(20, 20, 20), -1); if (!MacHog) { gr_printf((SWIDTH/4.923), (SHEIGHT/1.126), TXT_TURN_SHIP); gr_printf((SWIDTH/4.923), (SHEIGHT/1.083), TXT_SLIDE_UPDOWN); gr_printf((SWIDTH/4.923), (SHEIGHT/1.043), "F9/F10 Changes viewing distance"); } else { // for the Mac automap they're shown up the top, hence the different layout gr_printf(265*(SWIDTH/640.0), 27*(SHEIGHT/480.0), TXT_TURN_SHIP); gr_printf(265*(SWIDTH/640.0), 44*(SHEIGHT/480.0), TXT_SLIDE_UPDOWN); gr_printf(265*(SWIDTH/640.0), 61*(SHEIGHT/480.0), "F9/F10 Changes viewing distance"); } 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); // Draw player... #ifdef NETWORK if (Game_mode & GM_TEAM) color = get_team(Player_num); else #endif color = Player_num; // Note link to above if! gr_setcolor(BM_XRGB(player_rgb[color].r,player_rgb[color].g,player_rgb[color].b)); draw_player(&Objects[Players[Player_num].objnum]); // Draw player(s)... #ifdef NETWORK if ( (Game_mode & (GM_TEAM | GM_MULTI_COOP)) || (Netgame.game_flags & NETGAME_FLAG_SHOW_MAP) || (Players[Player_num].spec_flags & PLAYER_FLAGS_SPECTATING)) // jinx 02-01-13 spec { 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(player_rgb[color].r,player_rgb[color].g,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 (PlayerCfg.MouseFlightSim && 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; FixedStepCalc(); } am->t1 = am->t2; }
/** * Streaming callback to format our output */ static int stream_formatter(FILE *pipe, void *data, metric_type type, char *name, void *value) { #define STREAM(...) if (fprintf(pipe, __VA_ARGS__, (long long)tv->tv_sec) < 0) return 1; struct config_time* ct = data; struct timeval *tv = ct->tv; timer_hist *t; int i; char *prefix = ct->global_config->prefixes_final[type]; switch (type) { case KEY_VAL: STREAM("%s%s|%f|%lld\n", prefix, name, *(double*)value); break; case GAUGE: STREAM("%s%s|%f|%lld\n", prefix, name, ((gauge_t*)value)->value); break; case COUNTER: if (ct->global_config->extended_counters) { STREAM("%s%s.count|%" PRIu64 "|%lld\n", prefix, name, counter_count(value)); STREAM("%s%s.mean|%f|%lld\n", prefix, name, counter_mean(value)); STREAM("%s%s.stdev|%f|%lld\n", prefix, name, counter_stddev(value)); STREAM("%s%s.sum|%f|%lld\n", prefix, name, counter_sum(value)); STREAM("%s%s.sum_sq|%f|%lld\n", prefix, name, counter_squared_sum(value)); STREAM("%s%s.lower|%f|%lld\n", prefix, name, counter_min(value)); STREAM("%s%s.upper|%f|%lld\n", prefix, name, counter_max(value)); STREAM("%s%s.rate|%f|%lld\n", prefix, name, counter_sum(value) / ct->global_config->flush_interval); } else { STREAM("%s%s|%f|%lld\n", prefix, name, counter_sum(value)); } break; case SET: STREAM("%s%s|%" PRIu64 "|%lld\n", prefix, name, set_size(value)); break; case TIMER: t = (timer_hist*)value; STREAM("%s%s.sum|%f|%lld\n", prefix, name, timer_sum(&t->tm)); STREAM("%s%s.sum_sq|%f|%lld\n", prefix, name, timer_squared_sum(&t->tm)); STREAM("%s%s.mean|%f|%lld\n", prefix, name, timer_mean(&t->tm)); STREAM("%s%s.lower|%f|%lld\n", prefix, name, timer_min(&t->tm)); STREAM("%s%s.upper|%f|%lld\n", prefix, name, timer_max(&t->tm)); STREAM("%s%s.count|%" PRIu64 "|%lld\n", prefix, name, timer_count(&t->tm)); STREAM("%s%s.stdev|%f|%lld\n", prefix, name, timer_stddev(&t->tm)); for (i=0; i < ct->global_config->num_quantiles; i++) { int percentile; double quantile = ct->global_config->quantiles[i]; if (quantile == 0.5) { STREAM("%s%s.median|%f|%lld\n", prefix, name, timer_query(&t->tm, 0.5)); } if (to_percentile(quantile, &percentile)) { syslog(LOG_ERR, "Invalid quantile: %lf", quantile); break; } STREAM("%s%s.p%d|%f|%lld\n", prefix, name, percentile, timer_query(&t->tm, quantile)); } STREAM("%s%s.rate|%f|%lld\n", prefix, name, timer_sum(&t->tm) / ct->global_config->flush_interval); STREAM("%s%s.sample_rate|%f|%lld\n", prefix, name, (double)timer_count(&t->tm) / ct->global_config->flush_interval); // Stream the histogram values if (t->conf) { STREAM("%s%s.histogram.bin_<%0.2f|%u|%lld\n", prefix, name, t->conf->min_val, t->counts[0]); for (i=0; i < t->conf->num_bins-2; i++) { STREAM("%s%s.histogram.bin_%0.2f|%u|%lld\n", prefix, name, t->conf->min_val+(t->conf->bin_width*i), t->counts[i+1]); } STREAM("%s%s.histogram.bin_>%0.2f|%u|%lld\n", prefix, name, t->conf->max_val, t->counts[i+1]); } break; default: syslog(LOG_ERR, "Unknown metric type: %d", type); break; } return 0; }
int kmatrix_handler(window *wind, d_event *event, kmatrix_screen *km) { int i = 0, k = 0, choice = 0; switch (event->type) { case EVENT_KEY_COMMAND: k = event_key_get(event); switch( k ) { case KEY_ESC: if (km->network) { StartAbortMenuTime=timer_query(); choice=nm_messagebox1( NULL,multi_endlevel_poll2, NULL, 2, TXT_YES, TXT_NO, TXT_ABORT_GAME ); } else choice=nm_messagebox( NULL, 2, TXT_YES, TXT_NO, TXT_ABORT_GAME ); if (choice==0) { Players[Player_num].connected=CONNECT_DISCONNECTED; if (km->network) multi_send_endlevel_packet(); multi_leave_game(); window_close(wind); if (Game_wind) window_close(Game_wind); return 1; } return 1; default: break; } break; case EVENT_WINDOW_DRAW: timer_delay2(50); if (km->network) multi_do_protocol_frame(0, 1); km->playing = 0; // Check if all connected players are also looking at this screen ... for (i = 0; i < MAX_PLAYERS; i++) if (Players[i].connected) if (Players[i].connected != CONNECT_END_MENU && Players[i].connected != CONNECT_DIED_IN_MINE) km->playing = 1; // ... and let the reactor blow sky high! if (!km->playing) Countdown_seconds_left = -1; // If Reactor is finished and end_time not inited, set the time when we will exit this loop if (km->end_time == -1 && Countdown_seconds_left < 0 && !km->playing) km->end_time = timer_query() + (KMATRIX_VIEW_SEC * F1_0); // Check if end_time has been reached and exit loop if (timer_query() >= km->end_time && km->end_time != -1) { if (km->network) multi_send_endlevel_packet(); // make sure if (is_D2_OEM) { if (Current_level_num==8) { Players[Player_num].connected=CONNECT_DISCONNECTED; if (km->network) multi_send_endlevel_packet(); multi_leave_game(); window_close(wind); if (Game_wind) window_close(Game_wind); return 0; } } window_close(wind); break; } kmatrix_redraw(km); if (km->playing) kmatrix_status_msg(Countdown_seconds_left, 1); else kmatrix_status_msg(f2i(timer_query()-km->end_time), 0); break; case EVENT_WINDOW_CLOSE: game_flush_inputs(); newmenu_free_background(); break; default: break; } return 0; }
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; }
static window_event_result con_handler(window *wind,const d_event &event, const unused_window_userdata_t *) { int key; static fix64 last_scroll_time = 0; switch (event.type) { case EVENT_WINDOW_ACTIVATED: key_toggle_repeat(1); break; case EVENT_WINDOW_DEACTIVATED: key_toggle_repeat(0); con_size = 0; con_state = CON_STATE_CLOSED; break; case EVENT_KEY_COMMAND: key = event_key_get(event); switch (key) { case KEY_SHIFTED + KEY_ESC: switch (con_state) { case CON_STATE_OPEN: case CON_STATE_OPENING: con_state = CON_STATE_CLOSING; break; case CON_STATE_CLOSED: case CON_STATE_CLOSING: con_state = CON_STATE_OPENING; default: break; } break; case KEY_PAGEUP: con_scroll_offset+=CON_SCROLL_OFFSET; if (con_scroll_offset >= CON_LINES_MAX-1) con_scroll_offset = CON_LINES_MAX-1; while (con_buffer[CON_LINES_MAX-1-con_scroll_offset].line[0]=='\0') con_scroll_offset--; break; case KEY_PAGEDOWN: con_scroll_offset-=CON_SCROLL_OFFSET; if (con_scroll_offset<0) con_scroll_offset=0; break; case KEY_CTRLED + KEY_A: case KEY_HOME: cli_cursor_home(); break; case KEY_END: case KEY_CTRLED + KEY_E: cli_cursor_end(); break; case KEY_CTRLED + KEY_C: cli_clear(); break; case KEY_LEFT: cli_cursor_left(); break; case KEY_RIGHT: cli_cursor_right(); break; case KEY_BACKSP: cli_cursor_backspace(); break; case KEY_CTRLED + KEY_D: case KEY_DELETE: cli_cursor_del(); break; case KEY_UP: cli_history_prev(); break; case KEY_DOWN: cli_history_next(); break; case KEY_TAB: cli_autocomplete(); break; case KEY_ENTER: cli_execute(); break; case KEY_INSERT: cli_toggle_overwrite_mode(); break; default: int character = key_ascii(); if (character == 255) break; cli_add_character(character); break; } return window_event_result::handled; case EVENT_WINDOW_DRAW: timer_delay2(50); if (con_state == CON_STATE_OPENING) { if (con_size < CON_LINES_ONSCREEN && timer_query() >= last_scroll_time+(F1_0/30)) { last_scroll_time = timer_query(); if (++ con_size >= CON_LINES_ONSCREEN) con_state = CON_STATE_OPEN; } } else if (con_state == CON_STATE_CLOSING) { if (con_size > 0 && timer_query() >= last_scroll_time+(F1_0/30)) { last_scroll_time = timer_query(); if (! -- con_size) con_state = CON_STATE_CLOSED; } } con_draw(); if (con_state == CON_STATE_CLOSED && wind) { return window_event_result::close; } break; case EVENT_WINDOW_CLOSE: break; default: break; } return window_event_result::ignored; }
void ui_mega_process() { int mx, my, mz; unsigned char k; event_process(); switch( Record ) { case 0: mouse_get_delta( &mx, &my, &mz ); Mouse.new_dx = mx; Mouse.new_dy = my; Mouse.new_buttons = mouse_get_btns(); last_keypress = key_inkey(); if ( Mouse.new_buttons || last_keypress || Mouse.new_dx || Mouse.new_dy ) { last_event = timer_query(); } break; case 1: if (ui_event_counter==0 ) { EventBuffer[ui_event_counter].frame = 0; EventBuffer[ui_event_counter].type = 7; EventBuffer[ui_event_counter].data = ui_number_of_events; ui_event_counter++; } if (ui_event_counter==1 && (RecordFlags & UI_RECORD_MOUSE) ) { Mouse.new_buttons = 0; EventBuffer[ui_event_counter].frame = FrameCount; EventBuffer[ui_event_counter].type = 6; EventBuffer[ui_event_counter].data = ((Mouse.y & 0xFFFF) << 16) | (Mouse.x & 0xFFFF); ui_event_counter++; } mouse_get_delta( &mx, &my, &mz ); MouseDX = mx; MouseDY = my; MouseButtons = mouse_get_btns(); Mouse.new_dx = MouseDX; Mouse.new_dy = MouseDY; if ((MouseDX != 0 || MouseDY != 0) && (RecordFlags & UI_RECORD_MOUSE) ) { if (ui_event_counter < ui_number_of_events-1 ) { EventBuffer[ui_event_counter].frame = FrameCount; EventBuffer[ui_event_counter].type = 1; EventBuffer[ui_event_counter].data = ((MouseDY & 0xFFFF) << 16) | (MouseDX & 0xFFFF); ui_event_counter++; } else { Record = 0; } } if ( (MouseButtons != Mouse.new_buttons) && (RecordFlags & UI_RECORD_MOUSE) ) { Mouse.new_buttons = MouseButtons; if (ui_event_counter < ui_number_of_events-1 ) { EventBuffer[ui_event_counter].frame = FrameCount; EventBuffer[ui_event_counter].type = 2; EventBuffer[ui_event_counter].data = MouseButtons; ui_event_counter++; } else { Record = 0; } } if ( keyd_last_pressed && (RecordFlags & UI_RECORD_KEYS) ) { _disable(); k = keyd_last_pressed; keyd_last_pressed= 0; _enable(); if (ui_event_counter < ui_number_of_events-1 ) { EventBuffer[ui_event_counter].frame = FrameCount; EventBuffer[ui_event_counter].type = 3; EventBuffer[ui_event_counter].data = k; ui_event_counter++; } else { Record = 0; } } if ( keyd_last_released && (RecordFlags & UI_RECORD_KEYS) ) { _disable(); k = keyd_last_released; keyd_last_released= 0; _enable(); if (ui_event_counter < ui_number_of_events-1 ) { EventBuffer[ui_event_counter].frame = FrameCount; EventBuffer[ui_event_counter].type = 4; EventBuffer[ui_event_counter].data = k; ui_event_counter++; } else { Record = 0; } } last_keypress = key_inkey(); if (last_keypress == KEY_F12 ) { ui_number_of_events = ui_event_counter; last_keypress = 0; Record = 0; break; } if ((last_keypress != 0) && (RecordFlags & UI_RECORD_KEYS) ) { if (ui_event_counter < ui_number_of_events-1 ) { EventBuffer[ui_event_counter].frame = FrameCount; EventBuffer[ui_event_counter].type = 5; EventBuffer[ui_event_counter].data = last_keypress; ui_event_counter++; } else { Record = 0; } } FrameCount++; break; case 2: case 3: Mouse.new_dx = 0; Mouse.new_dy = 0; Mouse.new_buttons = 0; last_keypress = 0; if ( keyd_last_pressed ) { _disable(); k = keyd_last_pressed; keyd_last_pressed = 0; _disable(); SavedState[k] = 1; } if ( keyd_last_released ) { _disable(); k = keyd_last_released; keyd_last_released = 0; _disable(); SavedState[k] = 0; } if (key_inkey() == KEY_F12 ) { restore_state(); Record = 0; break; } if (EventBuffer==NULL) { restore_state(); Record = 0; break; } while( (ui_event_counter < ui_number_of_events) && (EventBuffer[ui_event_counter].frame <= FrameCount) ) { switch ( EventBuffer[ui_event_counter].type ) { case 1: // Mouse moved Mouse.new_dx = EventBuffer[ui_event_counter].data & 0xFFFF; Mouse.new_dy = (EventBuffer[ui_event_counter].data >> 16) & 0xFFFF; break; case 2: // Mouse buttons changed Mouse.new_buttons = EventBuffer[ui_event_counter].data; break; case 3: // Key moved down keyd_pressed[ EventBuffer[ui_event_counter].data ] = 1; break; case 4: // Key moved up keyd_pressed[ EventBuffer[ui_event_counter].data ] = 0; break; case 5: // Key pressed last_keypress = EventBuffer[ui_event_counter].data; break; case 6: // Initial Mouse X position Mouse.x = EventBuffer[ui_event_counter].data & 0xFFFF; Mouse.y = (EventBuffer[ui_event_counter].data >> 16) & 0xFFFF; break; case 7: break; } ui_event_counter++; if (ui_event_counter >= ui_number_of_events ) { Record = 0; restore_state(); //( 0, "Done playing %d events.\n", ui_number_of_events ); } } switch (Record) { case 2: { int next_frame; if ( ui_event_counter < ui_number_of_events ) { next_frame = EventBuffer[ui_event_counter].frame; if ( (FrameCount+PlaybackSpeed) < next_frame ) FrameCount = next_frame - PlaybackSpeed; else FrameCount++; } else { FrameCount++; } } break; case 3: if ( ui_event_counter < ui_number_of_events ) FrameCount = EventBuffer[ui_event_counter].frame; else FrameCount++; break; default: FrameCount++; } } ui_mouse_process(); }
int ui_listbox_do( UI_DIALOG *dlg, UI_GADGET_LISTBOX * listbox, d_event *event ) { int mitem, oldfakepos, kf; int keypress = 0; int rval = 0; if (event->type == EVENT_WINDOW_DRAW) { ui_draw_listbox( dlg, listbox ); return 0; } if (event->type == EVENT_KEY_COMMAND) keypress = event_key_get(event); listbox->selected_item = -1; listbox->moved = 0; if (listbox->num_items < 1 ) { listbox->current_item = -1; listbox->first_item = 0; listbox->old_current_item = listbox->current_item; listbox->old_first_item = listbox->first_item; //ui_draw_listbox( dlg, listbox ); if (dlg->keyboard_focus_gadget == (UI_GADGET *)listbox) { dlg->keyboard_focus_gadget = ui_gadget_get_next((UI_GADGET *)listbox); } return rval; } listbox->old_current_item = listbox->current_item; listbox->old_first_item = listbox->first_item; if (GADGET_PRESSED(listbox->scrollbar)) { listbox->moved = 1; listbox->first_item = listbox->scrollbar->position; if (listbox->current_item<listbox->first_item) listbox->current_item = listbox->first_item; if (listbox->current_item>(listbox->first_item+listbox->num_items_displayed-1)) listbox->current_item = listbox->first_item + listbox->num_items_displayed-1; } if (B1_JUST_RELEASED) listbox->dragging = 0; if (B1_JUST_PRESSED && ui_mouse_on_gadget( (UI_GADGET *)listbox )) { listbox->dragging = 1; rval = 1; } if ( dlg->keyboard_focus_gadget==(UI_GADGET *)listbox ) { if (keypress==KEY_ENTER) { listbox->selected_item = listbox->current_item; rval = 1; } kf = 0; switch(keypress) { case (KEY_UP): listbox->current_item--; kf = 1; break; case (KEY_DOWN): listbox->current_item++; kf = 1; break; case (KEY_HOME): listbox->current_item=0; kf = 1; break; case (KEY_END): listbox->current_item=listbox->num_items-1; kf = 1; break; case (KEY_PAGEUP): listbox->current_item -= listbox->num_items_displayed; kf = 1; break; case (KEY_PAGEDOWN): listbox->current_item += listbox->num_items_displayed; kf = 1; break; } if (kf==1) { listbox->moved = 1; rval = 1; if (listbox->current_item<0) listbox->current_item=0; if (listbox->current_item>=listbox->num_items) listbox->current_item = listbox->num_items-1; if (listbox->current_item<listbox->first_item) listbox->first_item = listbox->current_item; if (listbox->current_item>=(listbox->first_item+listbox->num_items_displayed)) listbox->first_item = listbox->current_item-listbox->num_items_displayed+1; if (listbox->num_items <= listbox->num_items_displayed ) listbox->first_item = 0; else { oldfakepos = listbox->scrollbar->position; listbox->scrollbar->position = listbox->first_item; listbox->scrollbar->fake_position = listbox->scrollbar->position-listbox->scrollbar->start; listbox->scrollbar->fake_position *= listbox->scrollbar->height-listbox->scrollbar->fake_size; listbox->scrollbar->fake_position /= (listbox->scrollbar->stop-listbox->scrollbar->start); if (listbox->scrollbar->fake_position<0) { listbox->scrollbar->fake_position = 0; } if (listbox->scrollbar->fake_position > (listbox->scrollbar->height-listbox->scrollbar->fake_size)) { listbox->scrollbar->fake_position = (listbox->scrollbar->height-listbox->scrollbar->fake_size); } if (oldfakepos != listbox->scrollbar->position ) listbox->scrollbar->status = 1; } } } if (selected_gadget==(UI_GADGET *)listbox) { if (listbox->dragging) { int x, y, z; mouse_get_pos(&x, &y, &z); if (y < listbox->y1) mitem = -1; else mitem = (y - listbox->y1)/listbox->textheight; if ((mitem < 0) && (timer_query() > listbox->last_scrolled + 1)) { listbox->current_item--; listbox->last_scrolled = timer_query(); listbox->moved = 1; } if ((mitem >= listbox->num_items_displayed) && (timer_query() > listbox->last_scrolled + 1)) { listbox->current_item++; listbox->last_scrolled = timer_query(); listbox->moved = 1; } if ((mitem>=0) && (mitem<listbox->num_items_displayed)) { listbox->current_item = mitem+listbox->first_item; listbox->moved=1; } if (listbox->current_item <0 ) listbox->current_item = 0; if (listbox->current_item >= listbox->num_items ) listbox->current_item = listbox->num_items-1; if (listbox->current_item<listbox->first_item) listbox->first_item = listbox->current_item; if (listbox->current_item>=(listbox->first_item+listbox->num_items_displayed)) listbox->first_item = listbox->current_item-listbox->num_items_displayed+1; if (listbox->num_items <= listbox->num_items_displayed ) listbox->first_item = 0; else { oldfakepos = listbox->scrollbar->position; listbox->scrollbar->position = listbox->first_item; listbox->scrollbar->fake_position = listbox->scrollbar->position-listbox->scrollbar->start; listbox->scrollbar->fake_position *= listbox->scrollbar->height-listbox->scrollbar->fake_size; listbox->scrollbar->fake_position /= (listbox->scrollbar->stop-listbox->scrollbar->start); if (listbox->scrollbar->fake_position<0) { listbox->scrollbar->fake_position = 0; } if (listbox->scrollbar->fake_position > (listbox->scrollbar->height-listbox->scrollbar->fake_size)) { listbox->scrollbar->fake_position = (listbox->scrollbar->height-listbox->scrollbar->fake_size); } if (oldfakepos != listbox->scrollbar->position ) listbox->scrollbar->status = 1; } } if (B1_DOUBLE_CLICKED ) { listbox->selected_item = listbox->current_item; rval = 1; } } if (listbox->moved || (listbox->selected_item > 0)) { ui_gadget_send_event(dlg, (listbox->selected_item > 0) ? EVENT_UI_LISTBOX_SELECTED : EVENT_UI_LISTBOX_MOVED, (UI_GADGET *)listbox); rval = 1; } return rval; }
static int stream_formatter_bin(FILE *pipe, void *data, metric_type type, char *name, void *value) { #define STREAM_BIN(...) if (stream_bin_writer(pipe, ((struct timeval *)data)->tv_sec, __VA_ARGS__, name)) return 1; #define STREAM_UINT(val) if (!fwrite(&val, sizeof(unsigned int), 1, pipe)) return 1; timer_hist *t; int i; included_metrics_config* counters_config = &(GLOBAL_CONFIG->ext_counters_config); switch (type) { case KEY_VAL: STREAM_BIN(BIN_TYPE_KV, BIN_OUT_NO_TYPE, *(double*)value); break; case GAUGE: STREAM_BIN(BIN_TYPE_GAUGE, BIN_OUT_NO_TYPE, ((gauge_t*)value)->value); break; case COUNTER: if (counters_config->sum) { STREAM_BIN(BIN_TYPE_COUNTER, BIN_OUT_SUM, counter_sum(value)); } if (counters_config->sum_sq) { STREAM_BIN(BIN_TYPE_COUNTER, BIN_OUT_SUM_SQ, counter_squared_sum(value)); } if (counters_config->mean) { STREAM_BIN(BIN_TYPE_COUNTER, BIN_OUT_MEAN, counter_mean(value)); } if (counters_config->count) { STREAM_BIN(BIN_TYPE_COUNTER, BIN_OUT_COUNT, counter_count(value)); } if (counters_config->stdev) { STREAM_BIN(BIN_TYPE_COUNTER, BIN_OUT_STDDEV, counter_stddev(value)); } if (counters_config->lower) { STREAM_BIN(BIN_TYPE_COUNTER, BIN_OUT_MIN, counter_min(value)); } if (counters_config->upper) { STREAM_BIN(BIN_TYPE_COUNTER, BIN_OUT_MAX, counter_max(value)); } if (counters_config->rate) { STREAM_BIN(BIN_TYPE_COUNTER, BIN_OUT_RATE, counter_sum(value) / GLOBAL_CONFIG->flush_interval); } break; case SET: STREAM_BIN(BIN_TYPE_SET, BIN_OUT_SUM, set_size(value)); break; case TIMER: t = (timer_hist*)value; STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_SUM, timer_sum(&t->tm)); STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_SUM_SQ, timer_squared_sum(&t->tm)); STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_MEAN, timer_mean(&t->tm)); STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_COUNT, timer_count(&t->tm)); STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_STDDEV, timer_stddev(&t->tm)); STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_MIN, timer_min(&t->tm)); STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_MAX, timer_max(&t->tm)); STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_RATE, timer_sum(&t->tm) / GLOBAL_CONFIG->flush_interval); STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_SAMPLE_RATE, (double)timer_count(&t->tm) / GLOBAL_CONFIG->flush_interval); for (i=0; i < GLOBAL_CONFIG->num_quantiles; i++) { STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_PCT | (int)(GLOBAL_CONFIG->quantiles[i] * 100), timer_query(&t->tm, GLOBAL_CONFIG->quantiles[i])); } // Binary streaming for histograms if (t->conf) { STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_HIST_FLOOR, t->conf->min_val); STREAM_UINT(t->counts[0]); for (i=0; i < t->conf->num_bins-2; i++) { STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_HIST_BIN, t->conf->min_val+(t->conf->bin_width*i)); STREAM_UINT(t->counts[i+1]); } STREAM_BIN(BIN_TYPE_TIMER, BIN_OUT_HIST_CEIL, t->conf->max_val); STREAM_UINT(t->counts[i+1]); } break; default: syslog(LOG_ERR, "Unknown metric type: %d", type); break; } return 0; }