static gboolean idle_state_event_cb (void *dummy) { double cur_time; if (quitting_flag) return FALSE; cur_time = xg_timer_elapsed (timer); if (initialized_flag && !minimized_flag) { if (active_flag) { //audio_time_cur = cur_time; if (run_full_speed_flag || ((cur_time - before_update_time) > UPDATE_RATE)) { repl_tick (); if (do_idle != SCM_UNSPECIFIED) scm_call_1 (do_idle, scm_from_double (cur_time)); update_count ++; before_update_time = cur_time; after_update_time = xg_timer_elapsed (timer); if (update_count % 1000 == 0) { measured_updates_rate = 1000.0 / (after_update_time - thousand_updates_time); thousand_updates_time = after_update_time; g_debug ("Update Rate: %f", measured_updates_rate); } } } else { //audio_pause (); // Figure out a way to sleep until the next gtk event comes in } /* if (!run_full_speed_flag) */ /* xg_usleep(10); */ } return TRUE; }
void loop_initialize () { timer = xg_timer_new(); g_timer_start (timer); update_count = 0; draw_count = 0; before_update_time = xg_timer_elapsed (timer); after_update_time = before_update_time; before_draw_time = before_update_time; after_draw_time = before_update_time; main_loop = xg_default_main_loop_new (); idle_event_source_id = g_timeout_add (1, idle_state_event_cb, NULL); main_screen_tick_id = gtk_widget_add_tick_callback (GTK_WIDGET(main_screen), tick_cb, NULL, NULL); initialized_flag = TRUE; }
double loop_time() { return xg_timer_elapsed(timer); }
cairo_surface_t * console_render_to_cairo_surface () { uint32_t timer, fast_blink_on, slow_blink_on; int width, height; cairo_surface_t *surf; uint32_t *data; int stride; int glyph_bpd, glyph_stride, glyph_width, glyph_height, glyph_xoffset, glyph_yoffset; uint8_t *glyph_bitmap; /* Convert time to integer milliseconds */ timer = xg_timer_elapsed (console_timer) * 1000.0; fast_blink_on = (timer / FAST_BLINK_TIME) % 2; slow_blink_on = (timer / SLOW_BLINK_TIME) % 2; width = CONSOLE_COLS; height = CONSOLE_ROWS; surf = xcairo_image_surface_create (CAIRO_FORMAT_ARGB32, width * FIXED_MAXWIDTH, height * FIXED_MAXHEIGHT); data = xcairo_image_surface_get_argb32_data (surf); stride = xcairo_image_surface_get_argb32_stride (surf); xcairo_surface_flush (surf); for (int r = 0; r < height; r++) { for (int c = 0; c < width; c++) { uint32_t cell = cells[r * CONSOLE_COLS + c]; uint16_t rendering = RENDERING (cell); uint16_t codepoint = CODEPOINT (cell); uint16_t fg_color_index = (rendering & COLOR_FG_MASK) >> COLOR_FG_OFFSET; uint16_t bg_color_index = (rendering & COLOR_BG_MASK) >> COLOR_BG_OFFSET; uint16_t intensity_index = (rendering & INTENSITY_MASK) >> INTENSITY_OFFSET; uint16_t polarity = rendering & POLARITY_MASK; uint16_t blink = rendering & BLINK_MASK; uint16_t underline = rendering & UNDERLINE_MASK; uint32_t fg_argb = fg_palette[fg_color_index * NUM_INTENSITIES + intensity_index]; uint32_t bg_argb = bg_palette[bg_color_index]; // Xor the inverse and blink states to see if we're inverse now. if ((polarity == POLARITY_NEGATIVE) != (((blink == BLINK_FAST) && (fast_blink_on)) || ((blink == BLINK_SLOW) && (slow_blink_on)))) { uint32_t temp_argb = fg_argb; fg_argb = bg_argb; bg_argb = temp_argb; } /* Swap again if we're the cursor and the cursor is visible */ if (r == row && c == col && cursor_visible && slow_blink_on) { uint32_t temp_argb = fg_argb; fg_argb = bg_argb; bg_argb = temp_argb; } glyph_bitmap = get_narrow_glyph (0, codepoint, &glyph_bpd, &glyph_stride, &glyph_width, &glyph_height, &glyph_xoffset, &glyph_yoffset); if (glyph_bitmap != NULL) { for (int j = 0; j < glyph_height; j++) { for (int i = 0; i < glyph_width; i++) { uint32_t pixel_argb; if ((underline == UNDERLINE_SINGLY || underline == UNDERLINE_DOUBLY) && (j == glyph_height - 1)) pixel_argb = fg_argb; else if ((underline == UNDERLINE_DOUBLY) && (j == glyph_height - 2)) pixel_argb = fg_argb; else if (glyph_bitmap && glyph_bitmap[j] & (1 << (8 - i - 1))) // FIXME: that '8' should be the number of bits in row type pixel_argb = fg_argb; else if (glyph_bitmap && (i > 0) && ((rendering & INTENSITY_MASK) == INTENSITY_BOLD) && (glyph_bitmap[j] & (1 << (8 - i - 2)))) // FIXME: that '8' should be the number of bits in row type pixel_argb = fg_argb; else pixel_argb = bg_argb; data[(r * FIXED_MAXHEIGHT + j) * stride + c * FIXED_MAXWIDTH + i] = pixel_argb; } } } else { for (int j = 0; j < FIXED_MAXHEIGHT; j++) { for (int i = 0; i < FIXED_MAXWIDTH; i++) { uint32_t pixel_argb; if ((underline == UNDERLINE_SINGLY || underline == UNDERLINE_DOUBLY) && (j == glyph_height - 1)) pixel_argb = fg_argb; else if ((underline == UNDERLINE_DOUBLY) && (j == glyph_height - 2)) pixel_argb = fg_argb; else pixel_argb = bg_argb; data[(r * FIXED_MAXHEIGHT + j) * stride + c * FIXED_MAXWIDTH + i] = pixel_argb; } } } xcairo_surface_mark_dirty (surf); } } return surf; }