Exemplo n.º 1
0
	bool Scene::run() {
		Graphics*		ptr_graphics = Graphics::instance();
		Audio*			ptr_audio = Audio::instance();
		TextureCache*	ptr_texture_cache = TextureCache::instance();
		InputManager*	ptr_inputManager = new InputManager();

		m_frame_timer.start(m_millis_per_frame);

		on_setup();
		setup_sprites();
		on_begin();
		while (!m_scene_is_ended) {
			ptr_inputManager->update();
			on_check_input(ptr_inputManager);
			if (!m_is_paused) {
				handle_messages();
				on_detect_collisions();
				on_update();
				update_sprites();
				ptr_graphics->begin_render();
				on_render(ptr_graphics);
				ptr_graphics->end_render();
			}
			while (!m_frame_timer.has_elapsed());
		}
		cleanup_sprites();
		on_cleanup();

		return !m_game_is_ended;
	}
Exemplo n.º 2
0
bool monitorable_actor::cleanup(error&& reason, execution_unit* host) {
  CAF_LOG_TRACE(CAF_ARG(reason));
  attachable_ptr head;
  bool set_fail_state = exclusive_critical_section([&]() -> bool {
    if (!getf(is_cleaned_up_flag)) {
      // local actors pass fail_state_ as first argument
      if (&fail_state_ != &reason)
        fail_state_ = std::move(reason);
      attachables_head_.swap(head);
      flags(flags() | is_terminated_flag | is_cleaned_up_flag);
      on_cleanup();
      return true;
    }
    return false;
  });
  if (!set_fail_state)
    return false;
  CAF_LOG_DEBUG("cleanup" << CAF_ARG(id())
                << CAF_ARG(node()) << CAF_ARG(reason));
  // send exit messages
  for (attachable* i = head.get(); i != nullptr; i = i->next.get())
    i->actor_exited(reason, host);
  // tell printer to purge its state for us if we ever used aout()
  if (getf(abstract_actor::has_used_aout_flag)) {
    auto pr = home_system().scheduler().printer();
    pr->enqueue(make_mailbox_element(nullptr, make_message_id(), {},
                                      delete_atom::value, id()),
                nullptr);
  }
  return true;
}
Exemplo n.º 3
0
int
CApp::on_execute() {
  if (!on_init())
    return -1;

  SDL_Event event;

  while (running) {
    while (SDL_PollEvent(&event))
      on_event(&event);

    on_loop();
    on_render();
  }

  on_cleanup();

  return 0;
}