int main(int argc, char **argv) { SDL_Surface *screen, *background, *pause_text, *press_enter_text, *game_over_text; const SDL_VideoInfo *video_info; Uint32 frame_start, frame_end = 0, game_frame_end = 0; systems_init(); screen = SDL_SetVideoMode(800, 600, 0, SDL_HWSURFACE|SDL_DOUBLEBUF); video_info = SDL_GetVideoInfo(); create_images(&press_enter_text, &pause_text, &game_over_text, &background); create_entities(); for(;;) { start_frame(&frame_start, &frame_end); if(check_SDL_events()) break; draw_background(background, screen, video_info); update_entities(game_frame_end ); if(is_paused()) { if(is_game_over()) { draw_centered(screen, video_info, game_over_text); } else if(is_started()) { draw_centered(screen, video_info, pause_text); } else { draw_centered(screen, video_info, press_enter_text); } } SDL_Flip(screen); finish_frame(&frame_start, &frame_end, &game_frame_end); } SDL_FreeSurface(background); SDL_FreeSurface(pause_text); SDL_FreeSurface(press_enter_text); systems_shutdown(); return 0; }
int main(int argc, char *argv[]) { const fixed dt = (1 << FIXPOINT_SHIFT) / 100; // 60 FPS fixed t = 0; fixed accumulator = 0; fixed delta_time = 0; SDL_Event event; init(); while (!app.quit) { start_frame(); delta_time = get_last_frame_time(); if (SDL_PollEvent(&event)) { handle_event(&event); } if (!app.paused) { accumulator += delta_time; // trace("accumulator %ld, dt: %ld, delta_time %ld", accumulator, dt, delta_time); while (accumulator >= dt) { move_objects(t, dt); t += dt; accumulator -= dt; } interpolate(fpdiv(accumulator, dt)); draw_scene(); } end_frame(); } return 0; }
void SerialConnection::receiver_complete(const boost::system::error_code& error, size_t bytes_transferred) { if (recv_raw_data_.size() == 0) start_frame(); recv_raw_data_.push_back(recv_byte_); start_receive(); if (recv_timer_->expires_from_now(boost::posix_time::milliseconds(rtu_silence_interval_ms_)) > 0) { // We managed to cancel the timer. Start new asynchronous wait. recv_timer_->async_wait(boost::bind(&SerialConnection::timer_expired, this, boost::asio::placeholders::error)); } else { // Too late, timer has already expired! recv_timer_->async_wait(boost::bind(&SerialConnection::timer_expired, this, boost::asio::placeholders::error)); } }
void Renderer::renderclient(Mailbox in) { FpsCounter fpsc(20); fpsc.start(); for (auto& cmd : gua::concurrent::pull_items_range<Item, Mailbox>(in)) { auto window_name(cmd.serialized_cam->config.get_output_window_name()); if (window_name != "") { auto window = WindowDatabase::instance()->lookup(window_name); if (window && !window->get_is_open()) { window->open(); } // update window if one is assigned if (window && window->get_is_open()) { window->set_active(true); window->start_frame(); if (window->get_context()->framecount == 0) { display_loading_screen(*window); } // make sure pipeline was created std::shared_ptr<Pipeline> pipe = nullptr; auto pipe_iter = window->get_context()->render_pipelines.find( cmd.serialized_cam->uuid); if (pipe_iter == window->get_context()->render_pipelines.end()) { pipe = std::make_shared<Pipeline>( *window->get_context(), cmd.serialized_cam->config.get_resolution()); window->get_context()->render_pipelines.insert( std::make_pair(cmd.serialized_cam->uuid, pipe)); } else { pipe = pipe_iter->second; } window->rendering_fps = fpsc.fps; if (cmd.serialized_cam->config.get_enable_stereo()) { if (window->config.get_stereo_mode() == StereoMode::NVIDIA_3D_VISION) { #ifdef GUACAMOLE_ENABLE_NVIDIA_3D_VISION if ((window->get_context()->framecount % 2) == 0) { auto img(pipe->render_scene(CameraMode::LEFT, *cmd.serialized_cam, *cmd.scene_graphs)); if (img) window->display(img, true); } else { auto img(pipe->render_scene(CameraMode::RIGHT, *cmd.serialized_cam, *cmd.scene_graphs)); if (img) window->display(img, false); } #else Logger::LOG_WARNING << "guacamole has not been compiled with NVIDIA 3D Vision support!" << std::endl; #endif } else { // TODO: add alternate frame rendering here? -> take clear and render methods auto img(pipe->render_scene(CameraMode::LEFT, *cmd.serialized_cam, *cmd.scene_graphs)); if (img) window->display(img, true); img = pipe->render_scene(CameraMode::RIGHT, *cmd.serialized_cam, *cmd.scene_graphs); if (img) window->display(img, false); } } else { auto img(pipe->render_scene(cmd.serialized_cam->config.get_mono_mode(), *cmd.serialized_cam, *cmd.scene_graphs)); if (img) window->display(img, cmd.serialized_cam->config.get_mono_mode() != CameraMode::RIGHT); } pipe->clear_frame_cache(); // swap buffers window->finish_frame(); ++(window->get_context()->framecount); fpsc.step(); } } } }
void Renderer::draw_single_threaded(std::vector<SceneGraph const*> const& scene_graphs) { for (auto graph : scene_graphs) { graph->update_cache(); } auto sgs = garbage_collected_copy(scene_graphs); for (auto graph : scene_graphs) { for (auto& cam : graph->get_camera_nodes()) { auto window_name(cam->config.get_output_window_name()); auto serialized_cam(cam->serialize()); if (window_name != "") { auto window = WindowDatabase::instance()->lookup(window_name); if (window && !window->get_is_open()) { window->open(); } // update window if one is assigned if (window && window->get_is_open()) { window->set_active(true); window->start_frame(); if (window->get_context()->framecount == 0) { display_loading_screen(*window); } // make sure pipeline was created std::shared_ptr<Pipeline> pipe = nullptr; auto pipe_iter = window->get_context()->render_pipelines.find( serialized_cam.uuid); if (pipe_iter == window->get_context()->render_pipelines.end()) { pipe = std::make_shared<Pipeline>( *window->get_context(), serialized_cam.config.get_resolution()); window->get_context()->render_pipelines.insert( std::make_pair(serialized_cam.uuid, pipe)); } else { pipe = pipe_iter->second; } window->rendering_fps = application_fps_.fps; if (serialized_cam.config.get_enable_stereo()) { if (window->config.get_stereo_mode() == StereoMode::NVIDIA_3D_VISION) { #ifdef GUACAMOLE_ENABLE_NVIDIA_3D_VISION if ((window->get_context()->framecount % 2) == 0) { auto img(pipe->render_scene(CameraMode::LEFT, serialized_cam, *sgs)); if (img) window->display(img, true); } else { auto img(pipe->render_scene(CameraMode::RIGHT, serialized_cam, *sgs)); if (img) window->display(img, false); } #else Logger::LOG_WARNING << "guacamole has not been compiled with NVIDIA 3D Vision support!" << std::endl; #endif } else { auto img(pipe->render_scene(CameraMode::LEFT, serialized_cam, *sgs)); if (img) window->display(img, true); img = pipe->render_scene(CameraMode::RIGHT, serialized_cam, *sgs); if (img) window->display(img, false); } } else { auto img(pipe->render_scene(serialized_cam.config.get_mono_mode(), serialized_cam, *sgs)); if (img) window->display(img, serialized_cam.config.get_mono_mode() != CameraMode::RIGHT); } pipe->clear_frame_cache(); // swap buffers window->finish_frame(); ++(window->get_context()->framecount); } } } } application_fps_.step(); }