/* * Quick skeleton to map up a audio/video/input * source to an arcan frameserver along with some helpers. */ int afsrv_avfeed(struct arcan_shmif_cont* con, struct arg_arr* args) { if (!con){ dump_help(); return EXIT_FAILURE; } struct arcan_shmif_cont shms = *con; if (!arcan_shmif_resize(&shms, 320, 200)){ LOG("arcan_frameserver(decode) shmpage setup, resize failed\n"); return EXIT_FAILURE; } update_frame(&shms, RGBA(0xff, 0xff, 0xff, 0xff)); arcan_event ev; while(1) while(arcan_shmif_wait(&shms, &ev)){ if (ev.category == EVENT_TARGET){ if (ev.tgt.kind == TARGET_COMMAND_EXIT){ fprintf(stdout, "parent requested termination, leaving.\n"); return EXIT_SUCCESS; } else { static int red; update_frame(&shms, RGBA(red++, 0x00, 0x00, 0xff)); } } } return EXIT_FAILURE; }
/** * @brief Put char in cell * * @param [in] b burger * @param [in] dx normalized x position * @param [in] dy normalized y position * @param [in] c char to be put */ void put_burger(burger* b, double dx, double dy, char c) { int x = get_norm_x(b, dx); int y = get_norm_y(b, dy); update_frame(b,x,y); b->burger_matrix[y+(x*b->w)] = c; }
void put_burger_scooch(burger* b, double dx, double dy, char c, int direction) { int x = get_norm_x(b, dx); int y = get_norm_y(b, dy); if (occupied(b, x, y)) x += direction; update_frame(b,x,y); b->burger_matrix[y+(x*b->w)] = c; }
void Active::force_frame(int value) { if (loop_count == 0) return; int frame_count = direction_data->frame_count; forced_frame = int_max(0, int_min(value, frame_count - 1)); update_frame(); }
void Active::restore_frame() { if (forced_frame == -1) return; animation_frame = forced_frame; forced_frame = -1; update_frame(); }
void Yuv_window::show_frame(unsigned char* _yuv, int fmt, int _width, int _height) { mutex.lock(); yuv_data = _yuv; format = fmt; video_width = _width; video_height = _height; mutex.unlock(); emit update_frame(); }
int main(int argc, char *argv[]) { XEvent event; uint32_t timestamp = 0; init_x(); font_init(); ejoy2d_win_init(argc, argv); for (;;) { while(XPending(g_X.display) > 0) { XNextEvent(g_X.display, &event); if (XFilterEvent(&event,None)) continue; switch (event.type) { case Expose: if (event.xexpose.count==0) update_frame(); break; case ButtonPress: ejoy2d_win_touch(event.xbutton.x, event.xbutton.y, TOUCH_BEGIN); break; case ButtonRelease: ejoy2d_win_touch(event.xbutton.x,event.xbutton.y,TOUCH_END); break; case MotionNotify: ejoy2d_win_touch(event.xbutton.x,event.xbutton.y,TOUCH_MOVE); break; } } uint32_t old = timestamp; timestamp= _gettime(); if (timestamp - old >= UPDATE_INTERVAL) { ejoy2d_win_update(); update_frame(); } else usleep(1000); } }
Yuv_window::Yuv_window(int x, int y, int width, int height) :QWidget(0) , video_width(0) , video_height(0) , format(0) , yuv_data(0) { setAttribute(Qt::WA_OpaquePaintEvent); setAttribute(Qt::WA_PaintOnScreen); resize(width, height); port = get_xv_port(); connect(this, SIGNAL(update_frame()), this, SLOT(repaint())); }
void Active::update_direction(Direction * dir) { if (dir == NULL) dir = get_direction_data(); direction_data = dir; loop_count = direction_data->loop_count; // make sure frame is still in range int frame_count = direction_data->frame_count; if (forced_frame != -1 && forced_frame >= frame_count) forced_frame = -1; if (animation_frame >= frame_count) animation_frame = 0; if (active_flags & ANIMATION_STOPPED) return; update_frame(); }
/** * Main loop of the Powermanga game */ void main_loop (void) { Sint32 pause_delay = 0; Sint32 frame_diff = 0; do { loops_counter++; if (!power_conf->nosync) { frame_diff = get_time_difference (); if (movie_playing_switch != MOVIE_NOT_PLAYED) { pause_delay = wait_next_frame (MOVIE_FRAME_RATE - frame_diff + pause_delay, MOVIE_FRAME_RATE); } else { pause_delay = wait_next_frame (GAME_FRAME_RATE - frame_diff + pause_delay, GAME_FRAME_RATE); } } /* handle Powermanga game */ if (!update_frame ()) { quit_game = TRUE; } /* handle keyboard and joystick events */ display_handle_events (); /* update our main window */ display_update_window (); #ifdef USE_SDLMIXER /* play music and sounds */ sound_handle (); #endif } while (!quit_game); }
void fs_ml_render_iteration() { static int first = 1; if (first) { first = 0; initialize_opengl_sync(); } if (g_fs_ml_vblank_sync) { render_iteration_vsync(); } else if (g_fs_ml_benchmarking) { update_frame(); render_frame(); swap_opengl_buffers(); } else { // when vsync is off, we wait until a new frame is ready and // then we display it immediately if (fs_ml_is_quitting()) { // but when the emulation is quitting, we can't expect any new // frames so there's no point waiting for them. Instead, we just // sleep a bit to throttle the frame rate for the quit animation fs_ml_usleep(10000); } else { // wait max 33 ms to allow the user interface to work even if // the emu hangs // int64_t dest_time = fs_get_real_time() + 33 * 1000; int64_t end_time = fs_condition_get_wait_end_time(33 * 1000); int64_t check_time = 0; fs_mutex_lock(g_frame_available_mutex); // fs_log("cond wait until %lld\n", end_time); while (g_rendered_frame == g_available_frame) { fs_condition_wait_until( g_frame_available_cond, g_frame_available_mutex, end_time); check_time = fs_condition_get_wait_end_time(0); if (check_time >= end_time) { // fs_log("timed out at %lld\n", check_time); break; } else { // fs_log("wake-up at %lld (end_time = %lld)\n", check_time, end_time); } } fs_mutex_unlock(g_frame_available_mutex); } update_frame(); render_frame(); swap_opengl_buffers(); //gl_finish(); } if (g_fs_ml_video_screenshot_path) { fs_mutex_lock(g_fs_ml_video_screenshot_mutex); if (g_fs_ml_video_screenshot_path) { save_screenshot_of_opengl_framebuffer( g_fs_ml_video_screenshot_path); g_free(g_fs_ml_video_screenshot_path); g_fs_ml_video_screenshot_path = NULL; } fs_mutex_unlock(g_fs_ml_video_screenshot_mutex); } if (g_fs_ml_video_post_render_function) { g_fs_ml_video_post_render_function(); } }
static void render_iteration_vsync() { if (g_fs_ml_video_sync_low_latency) { int current_frame_at_start = g_available_frame; //int64_t t1 = fs_ml_monotonic_time(); int sleep_time = 0; int time_left = g_estimated_upload_render_duration; int64_t t = fs_emu_monotonic_time(); if (g_fs_ml_target_frame_time > 0) { sleep_time = g_estimated_next_vblank_time - t - time_left; } if (sleep_time > g_fs_ml_target_frame_time - time_left) { sleep_time = 0; } if (sleep_time > 0) { fs_ml_usleep(sleep_time); } if (g_available_frame > current_frame_at_start) { //printf("low latency %d\n", g_available_frame); } else { //printf("...\n"); } } update_frame(); CHECK_GL_ERROR_MSG("update_frame"); render_frame(); CHECK_GL_ERROR_MSG("render_frame"); //opengl_fence(FENCE_SET); //glFlush(); //opengl_fence(FENCE_WAIT); //int64_t upload_render_time = fs_ml_monotonic_time() - t1; //printf("urt %lld\n", upload_render_time); opengl_swap_synchronous(); g_measured_vblank_time = fs_ml_monotonic_time(); g_vblank_count++; fs_mutex_lock(g_vblank_mutex); g_measured_vblank_times[g_vblank_index] = g_measured_vblank_time; g_vblank_index = (g_vblank_index + 1) % VBLANK_COUNT; fs_mutex_unlock(g_vblank_mutex); // FIXME: adjust g_measured_vblank_time based on historical data (smooth out // irregularities) and save the result in g_adjusted_vblank_time g_adjusted_vblank_time = g_measured_vblank_time; g_sleep_until_vsync_last_time = g_adjusted_vblank_time; g_estimated_next_vblank_time = g_adjusted_vblank_time + \ g_fs_ml_target_frame_time; // g_start_new_frame_cond is used to signal that a new frame can be // generated when the emulation is running in sync - this is not used // when only display flipping is synced to vblank fs_mutex_lock(g_start_new_frame_mutex); g_start_new_frame = 1; fs_condition_signal(g_start_new_frame_cond); fs_mutex_unlock(g_start_new_frame_mutex); }
/** * @brief Put char in cell * * @param [in] b burger * @param [in] x cell index * @param [in] y cell index * @param [in] c char to be put */ void put_burger_int(burger* b, int x, int y, char c) { update_frame(b,x,y); b->burger_matrix[y+(x*b->w)] = c; }
void Active::update() { #ifdef CHOWDREN_DEFER_COLLISIONS flags |= DEFER_COLLISIONS; memcpy(old_aabb, sprite_col.aabb, sizeof(old_aabb)); #endif if (flags & FADEOUT) { if (fade_time > 0.0f) { fade_time -= manager.dt; if (fade_time <= 0.0f) { FrameObject::destroy(); } float p = fade_time / fade_duration; blend_color.set_alpha(p * 255.0f); return; } if (animation_finished == DISAPPEARING) { FrameObject::destroy(); return; } } update_flash(flash_interval, flash_time); animation_finished = -1; if (forced_animation == -1 && animation != current_animation) { current_animation = animation; animation_frame = 0; update_direction(); } if (forced_frame != -1 || (active_flags & ANIMATION_STOPPED) || loop_count == 0) { return; } int anim_speed; if (forced_speed != -1) anim_speed = forced_speed; else anim_speed = direction_data->max_speed; int counter = this->counter + int(anim_speed * frame->timer_mul); int old_frame = animation_frame; while (counter > 100) { counter -= 100; animation_frame++; if (animation_frame < direction_data->frame_count) continue; if (loop_count > 0) loop_count--; if (loop_count != 0) { animation_frame = direction_data->back_to; continue; } animation_finished = current_animation; animation_frame--; if (forced_animation != -1) { forced_animation = -1; forced_speed = -1; forced_direction = -1; } return; } this->counter = counter; if (animation_frame != old_frame) update_frame(); }
bool GameManager::update() { #ifdef CHOWDREN_USE_DYNAMIC_NUMBER static int save_time = 0; save_time--; if (save_time <= 0) { save_alterable_debug(); save_time += 60; } #endif #ifdef SHOW_STATS bool show_stats = false; static int measure_time = 0; measure_time -= 1; if (measure_time <= 0) { measure_time = 200; show_stats = true; } #endif #ifdef CHOWDREN_USER_PROFILER static int frame = 0; frame++; std::stringstream ss; ss << "Frame " << frame << ": " << fps_limit.dt << " "; #endif // update input keyboard.update(); mouse.update(); platform_poll_events(); #ifdef CHOWDREN_USE_GWEN gwen.update(); #endif // player controls int new_control = get_player_control_flags(1); player_press_flags = new_control & ~(player_flags); player_flags = new_control; // joystick controls new_control = get_joystick_control_flags(1); joystick_press_flags = new_control & ~(joystick_flags); joystick_release_flags = joystick_flags & ~(new_control); joystick_flags = new_control; #ifdef CHOWDREN_USE_JOYTOKEY for (int i = 0; i < simulate_count; i++) { if (simulate_keys[i].down) { simulate_keys[i].down = false; continue; } keyboard.remove(simulate_keys[i].key); simulate_keys[i] = simulate_keys[simulate_count-1]; i--; simulate_count--; } for (int i = 0; i < CHOWDREN_BUTTON_MAX-1; i++) { int key = key_mappings[i]; if (key == -1) continue; if (is_joystick_pressed_once(1, i+1)) keyboard.add(key); else if (is_joystick_released_once(1, i+1)) keyboard.remove(key); } axis_moved = false; for (int i = 0; i < CHOWDREN_AXIS_MAX-1; i++) { float value = get_joystick_axis(1, i+1); int pos = axis_pos_mappings[i]; int neg = axis_neg_mappings[i]; int axis_value = 0; if (value > deadzone) { last_axis = i; if (pos != -1 && axis_values[i] != 1) keyboard.add(pos); axis_value = 1; } else { if (pos != -1 && axis_values[i] == 1) keyboard.remove(pos); } if (value < -deadzone) { last_axis = i; if (neg != -1 && axis_values[i] != -1) keyboard.add(neg); axis_value = -1; } else { if (neg != -1 && axis_values[i] == -1) keyboard.remove(neg); } axis_values[i] = axis_value; static bool last_move = false; bool new_move = axis_value != 0; if (new_move && new_move != last_move) axis_moved = true; last_move = new_move; } static bool last_connected = false; bool connected = is_joystick_attached(1); pad_selected = connected && last_connected != connected; pad_disconnected = !connected && last_connected != connected; last_connected = connected; #endif // update mouse position platform_get_mouse_pos(&mouse_x, &mouse_y); #ifdef SHOW_STATS if (show_stats) std::cout << "Framerate: " << fps_limit.current_framerate << std::endl; #endif if (platform_has_error()) { if (platform_display_closed()) return false; } else { double event_update_time = platform_get_time(); int ret = update_frame(); #ifdef CHOWDREN_USER_PROFILER ss << (platform_get_time() - event_update_time) << " "; #endif #ifdef SHOW_STATS if (show_stats) std::cout << "Event update took " << platform_get_time() - event_update_time << std::endl; #endif if (ret == 0) return false; else if (ret == 2) return true; if (platform_display_closed()) return false; } double draw_time = platform_get_time(); draw(); #ifdef CHOWDREN_USER_PROFILER ss << (platform_get_time() - draw_time) << " "; #endif #ifdef SHOW_STATS if (show_stats) { std::cout << "Draw took " << platform_get_time() - draw_time << std::endl; #ifndef NDEBUG print_instance_stats(); #endif platform_print_stats(); } #endif fps_limit.finish(); #ifdef CHOWDREN_USER_PROFILER ss << "\n"; std::string logline = ss.str(); user_log.write(&logline[0], logline.size()); #endif #ifdef CHOWDREN_USE_PROFILER static int profile_time = 0; profile_time -= 1; if (profile_time <= 0) { profile_time += 500; PROFILE_UPDATE(); PROFILE_OUTPUT("data:/profile.txt"); } #endif return true; }