Beispiel #1
0
int check_SDL_events()
{
    SDL_Event event;
    while(SDL_PollEvent(&event)) {
        if(event.type == SDL_QUIT)
            return 1;
        else if(event.type == SDL_KEYDOWN) {
            if(event.key.keysym.sym == SDLK_ESCAPE)
                return 1;
            else if(event.key.keysym.sym == SDLK_RETURN) {
                if(is_paused()) {
                    if(!is_started()) {
                        set_started(1);
                    }
                    else if(is_game_over()) {
                        set_game_over(0);
                        ent_table_shutdown();
                        ent_table_init();
                        create_entities();
                    }
                }

                toggle_paused();
            }
        }
    }

    return 0;
}
Beispiel #2
0
bool CPUThread::check_status()
{
    std::unique_lock<std::mutex> lock(mutex, std::defer_lock);

    while (true)
    {
        CHECK_EMU_STATUS; // check at least once

        if (!is_paused()) break;

        if (!lock)
        {
            lock.lock();
            continue;
        }

        cv.wait(lock);
    }

    if (m_state.load() & CPU_STATE_RETURN || is_stopped())
    {
        return true;
    }

    if (m_state.load() & CPU_STATE_STEP)
    {
        // set PAUSE, but allow to execute once
        m_state |= CPU_STATE_PAUSED;
        m_state &= ~CPU_STATE_STEP;
    }

    return false;
}
Beispiel #3
0
void CBaseMonster::UpdateCL()
{
#ifdef DEBUG
	if ( Level().CurrentEntity() == this )
	{
		DBG().get_text_tree().clear();
		add_debug_info(DBG().get_text_tree());
	}
	if ( is_paused () )
	{
		return;
	}
#endif

	if ( EatedCorpse && !CorpseMemory.is_valid_corpse(EatedCorpse) )
	{
		EatedCorpse = NULL;
	}

	inherited::UpdateCL();
	
	if ( g_Alive() ) 
	{
		update_enemy_accessible_and_at_home_info();
		CStepManager::update(false);

		update_pos_by_grouping_behaviour();
	}

	control().update_frame();

	m_pPhysics_support->in_UpdateCL();
}
Beispiel #4
0
 void Timer::resume() {
     if (is_paused()) {
         i_settings &= ~TIMER_PAUSED;
         startTicks = SDL_GetTicks() - pausedTicks;
         pausedTicks = 0;
     }
 }
Beispiel #5
0
void
update_entities(Uint32 last_frame_time)
{
    const list_t *ent_iter = NULL;

    /* Ent updating follows, in 3 stages:
     * -First stage: update position, angles and bounds for all entities
     * -Second stage: call the think functions on any entities necessary
     * -Third stage: call frame callbacks, which check collisions and draw to surface
     */

    if(!is_paused()) {
        while((ent_iter = ent_table_next(ent_iter)) != NULL) {
            Ent *ent = ent_iter->item;
            if(game_time() >= Ent_GET(next_think, ent))
                Ent_CALL(think, ent);
        }

        while((ent_iter = ent_table_next(ent_iter)) != NULL) {
            Ent *ent = ent_iter->item;
            Ent_update(ent, last_frame_time);
        }
    }

    while((ent_iter = ent_table_next(ent_iter)) != NULL) {
        Ent *ent = ent_iter->item;
        Ent_CALL(on_frame, ent);
    }
}
Beispiel #6
0
void
start_frame(Uint32 *frame_start, Uint32 *frame_end)
{
    *frame_start = SDL_GetTicks();
    if(!is_paused())
        game_time_update(*frame_start - *frame_end);
}
Beispiel #7
0
void GameTime::resume() {
	if(is_paused()) {
		start_time += platform::getElapsedUs(pause_time);
		pause_time = 0;
		paused     = false;
	}
}
 void wait_if_paused()
 {
     if (is_paused())
     {
         base::MutexLock lock(_pause_mutex);//Wait for unlock
     };
 };
Beispiel #9
0
/**
 * @brief Displays the game.
 * @param screen_surface the surface where the game will be displayed
 */
void Game::display(Surface *screen_surface) {

  // display the map
  current_map->display();
  if (transition != NULL) {
    transition->display(current_map->get_visible_surface());
  }
  current_map->get_visible_surface()->blit(screen_surface);

  // display the pause screen if any
  if (is_paused()) {
    pause_menu->display(screen_surface);
  }

  // display the game over sequence if any
  else if (is_showing_gameover()) {
    gameover_sequence->display(screen_surface);
  }

  // display the hud
  if (hud_enabled) {
    hud->display(screen_surface);
  }

  // display the dialog box if any
  if (is_showing_message()) {
    dialog_box->display(screen_surface);
  }
}
Beispiel #10
0
/**
 * @brief Updates the game elements.
 *
 * Updates the map, the equipment, the HUD, etc.
 */
void Game::update() {

  // update the transitions between maps
  update_transitions();

  if (reseting || restarting) {
    return; // the game may have just been reset
  }

  // update the map
  current_map->update();

  // update the equipment and HUD
  get_equipment().update();
  update_keys_effect();
  if (hud_enabled) {
    hud->update();
  }
  dialog_box->update();

  // update the pause menu (if the game is paused)
  if (is_paused()) {
    pause_menu->update();
  }

  // update the game over sequence (if any)
  if (is_showing_gameover()) {
    update_gameover_sequence();
  }
}
Beispiel #11
0
/**
 * @brief This function is called when a game key is pressed.
 * @param key a key
 */
void Game::key_pressed(GameControls::GameKey key) {

  if (!is_suspended()) {    

    if (key == GameControls::PAUSE) {
      if (can_pause()) {
        set_paused(true);
      }
    }
    else {
      // when the game is not suspended, all other keys apply to the hero
      hero->key_pressed(key);
    }
  }

  // is a message being shown?
  else if (is_showing_message()) {
    dialog_box->key_pressed(key);
  }

  // is the game paused?
  else if (is_paused()) {
    pause_menu->key_pressed(key);
  }

  // is the game over sequence shown?
  else if (is_showing_gameover()) {
    gameover_sequence->key_pressed(key);
  }
}
Beispiel #12
0
void arx::time::resume() {
	if(is_paused()) {
		start_time += Time::getElapsedUs(pause_time);
		pause_time = 0;
		paused     = false;
	}
}
Beispiel #13
0
/**
 * \brief Returns whether the game is suspended.
 *
 * This is true in the following cases:
 * - the game is paused,
 * - a dialog a being dispayed,
 * - a transition between two maps is playing,
 * - the game over sequence is active,
 * - the camera is moving.
 *
 * \return true if the game is suspended
 */
bool Game::is_suspended() const {

  return current_map == NULL
      || is_paused()
      || is_dialog_enabled()
      || is_playing_transition()
      || is_showing_game_over()
      || current_map->is_camera_moving();
}
Beispiel #14
0
// Starts playback on the queued tracks.
void start_playing_queue() {
    in_main_thread([] {
        auto p_control = static_api_ptr_t<playback_control>();

        if (p_control->is_playing() || p_control->is_paused())
            p_control->next();
        else
            p_control->play_or_unpause();
    });
}
void DBSearch::stop()
{
    if (is_paused())
        toggle_pause();        
    if (!_working)
        return;
    _stop = true;
    while (_working);
    _state = "Cancelled";
}
Beispiel #16
0
std::string SMFTrack::inspect() const
{
  std::string s = "#<SMFTrack";
  s += " ";
  s += state_string[state_];
  if (is_paused()) {
    s += " PAUSED";
  }
  s += ">";
  return s;
}
void SpeakingAgent::draw()
{
   // store state
   placement2d::start_transform();

   // background
   al_draw_filled_rectangle(0, 0, size.x, size.y, color::hex("319cff"));

   // mouth
   ALLEGRO_BITMAP *mouth_shape = _get_phoneme_image(Speaker::get_current_phoneme());
   if (mouth_shape) al_draw_bitmap(mouth_shape, 0, 10, NULL);

   // eyes
   float eye_y = size.y/4;
   float eye_r = 2.3;
   float eye_1x = size.x/4;
   float eye_2x = size.x/4 * 3;
   if (blink_counter < 0.1)
   {
      al_draw_line(eye_1x-eye_r*2, eye_y, eye_1x+eye_r*2, eye_y, color::black, eye_r);
      al_draw_line(eye_2x-eye_r*2, eye_y, eye_2x+eye_r*2, eye_y, color::black, eye_r);
      if (blink_counter < 0.0) blink_counter = random_double(2.0, 6.0);
   }
   else
   {
      al_draw_filled_circle(eye_1x, eye_y, eye_r, color::black);
      al_draw_filled_circle(eye_2x, eye_y, eye_r, color::black);
   }
   blink_counter -= 1.0/60;

   // words
   float bx = size.x+size.x/4;
   float by = -size.y/3;
   float bw = size.x*2.5;
   float bh = size.y*0.8;
   float border_radius = 7;
   al_draw_filled_rounded_rectangle(bx, by, bx+bw, by+bh, border_radius, border_radius, color::white);
   float tx = bx+border_radius*4;
   float ty = by+bh-1;
   float ts = 20;
   al_draw_filled_triangle(tx, ty, tx+ts, ty, tx, ty+ts, color::white);
   std::string word = Speaker::get_current_word();
   ALLEGRO_FONT *font = fonts["lacuna.ttf 26"];
   if (is_paused()) word = "[PAUSED]";
   if (font) al_draw_text(font, color::black, bx+bw/2, by+bh/2-al_get_font_line_height(font)/2, ALLEGRO_ALIGN_CENTRE, word.c_str());

   // show stream #
   //al_draw_text(font, color::white, 0, 0, NULL, tostring(voice->get_current_stream()).c_str());

   // restore state
   placement2d::restore_transform();

   //draw_crosshair(x, y, color::white);
}
Beispiel #18
0
/**
 * @brief Pauses or resumes the game.
 * @param paused true to pause the game, false to resume it.
 */
void Game::set_paused(bool paused) {

  if (paused != is_paused()) {

    if (paused) {
      pause_menu = new PauseMenu(*this);
    }
    else {
      delete pause_menu;
      pause_menu = NULL;
    }
  }
}
void CCDemuxerThread::seek_backward()
{
	mutex_.lock();
    audio_thread->packet_queues()->clear();
    video_thread->packet_queues()->clear();
    demuxer->seek_backward();
	mutex_.unlock();
    if (is_paused()) {
        pause(false);
        video_thread->pause(false);
		std::this_thread::sleep_for(std::chrono::milliseconds(25));
        pause(true);
        video_thread->pause(true);
    }
}
Beispiel #20
0
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;
}
Beispiel #21
0
 clock_t elapsed(void)
 {
     if (is_stopped()) return 0;
     else
     if (is_paused())  return pause_elap_;
     else
     {
         clock_t now = ModelT::clock();
         if (start_time_ > now)
         {
             stop();
             return 0;
         }
         return now - start_time_;
     }
 }
void CSimulation::next_step()
{
	check_for_start();
	
	//std::cout << "RUNNING WITH BOOST SEED AND RAND SEED 1" << std::endl;
	
	//std::cout << "t: " << t << std::endl;
	
	if (is_paused()) return;
	
	calculateFinishTime();
	
	calculateForces();
		
	t++;
	check_for_end();

}
Beispiel #23
0
void
finish_frame(Uint32 *frame_start, Uint32 *frame_end, Uint32 *game_frame_end)
{
    Uint32 delay = 1000 / FRAME_RATE_MAX, elapsed;

    *frame_end = SDL_GetTicks();
    elapsed = *frame_end - *frame_start;

    if(elapsed < delay)
        delay -= elapsed;

    *frame_end = SDL_GetTicks();
    if(!is_paused()) {
        game_time_update(elapsed);
        *game_frame_end = game_time();
    }

    SDL_Delay(delay);
}
Beispiel #24
0
/**
 * \brief Makes sure the keys effects are coherent with the hero's equipment and abilities.
 */
void Game::update_keys_effect() {

  // when the game is paused or a dialog box is shown, the sword key is not the usual one
  if (is_paused() || is_dialog_enabled()) {
    return; // if the game is interrupted for some other reason (e.g. a transition), let the normal sword icon
  }

  // make sure the sword key is coherent with having a sword
  if (get_equipment().has_ability(ABILITY_SWORD)
      && keys_effect->get_sword_key_effect() != KeysEffect::SWORD_KEY_SWORD) {

    keys_effect->set_sword_key_effect(KeysEffect::SWORD_KEY_SWORD);
  }
  else if (!get_equipment().has_ability(ABILITY_SWORD)
      && keys_effect->get_sword_key_effect() == KeysEffect::SWORD_KEY_SWORD) {

    keys_effect->set_sword_key_effect(KeysEffect::SWORD_KEY_NONE);
  }
}
void CCDemuxerThread::seek_forward()
{
	//std::unique_lock<std::mutex> lock(mutex_);
	//if (!mutex_.try_lock()) {
	//	mutex_.unlock(); //may be still blocking in demux thread
	//	mutex_.lock();
	//}
	mutex_.lock();
    audio_thread->packet_queues()->clear();
    video_thread->packet_queues()->clear();
    demuxer->seek_forward();
	mutex_.unlock();
    if (is_paused()) {
        pause(false);
        video_thread->pause(false);
		std::this_thread::sleep_for(std::chrono::milliseconds(25));
        pause(true);
        video_thread->pause(true);
    }
}
Beispiel #26
0
    Uint32 Timer::get_ticks(Uint32 tick)const {
        if (tick != 0) {
            switch (tick) {
                case( TIMER_TICKS_STARTED): return startTicks;
                    break;
                case( TIMER_TICKS_PAUSED): return pausedTicks;
                    break;
                default: return 0;
                    break; // If the requesting param is other then the possible return 0
            }
        }

        if (is_started()) {
            if (is_paused())
                return pausedTicks;
            else
                return SDL_GetTicks() - startTicks;
        }

        return 0;
    }
Beispiel #27
0
/**
 * \brief Pauses or resumes the game.
 * \param paused true to pause the game, false to resume it.
 */
void Game::set_paused(bool paused) {

  if (paused != is_paused()) {

    this->paused = paused;
    if (paused) {
      keys_effect->save_action_key_effect();
      keys_effect->set_action_key_effect(KeysEffect::ACTION_KEY_NONE);
      keys_effect->save_sword_key_effect();
      keys_effect->set_sword_key_effect(KeysEffect::SWORD_KEY_NONE);
      keys_effect->set_pause_key_effect(KeysEffect::PAUSE_KEY_RETURN);
      get_lua_context().game_on_paused(*this);
    }
    else {
      get_lua_context().game_on_unpaused(*this);
      keys_effect->restore_action_key_effect();
      keys_effect->restore_sword_key_effect();
      keys_effect->set_pause_key_effect(KeysEffect::PAUSE_KEY_PAUSE);
    }
  }
}
Beispiel #28
0
/**
 * \brief This function is called when a game command is pressed.
 * \param command A game command.
 */
void Game::notify_command_pressed(GameCommands::Command command) {

  // Is a built-in dialog box being shown?
  if (is_dialog_enabled()) {
    if (dialog_box.notify_command_pressed(command)) {
      return;
    }
  }

  // See if the game script handles the command.
  if (get_lua_context().game_on_command_pressed(*this, command)) {
    return;
  }

  // See if the map script handled the command.
  if (get_lua_context().map_on_command_pressed(get_current_map(), command)) {
    return;
  }

  // Lua scripts did not override the command: do the built-in behavior.
  if (command == GameCommands::PAUSE) {
    if (is_paused()) {
      if (can_unpause()) {
        set_paused(false);
      }
    }
    else {
      if (can_pause()) {
        set_paused(true);
      }
    }
  }

  else if (!is_suspended()) {
    // When the game is not suspended, all other commands apply to the hero.
    hero->notify_command_pressed(command);
  }
}
Beispiel #29
0
void CBaseMonster::shedule_Update(u32 dt)
{
#ifdef DEBUG
	if ( is_paused () )
	{
		dbg_update_cl	= Device.dwFrame;
		return;
	}
#endif

	inherited::shedule_Update	(dt);

	update_eyes_visibility		();

	if ( m_anti_aim )
	{
		m_anti_aim->update_schedule();
	}

	m_psy_aura.update_schedule();
	m_fire_aura.update_schedule();
	m_base_aura.update_schedule();
	m_radiation_aura.update_schedule();

	control().update_schedule	();

	Morale.update_schedule		(dt);

	m_anomaly_detector->update_schedule();
	
	m_pPhysics_support->in_shedule_Update(dt);

#ifdef DEBUG	
	show_debug_info();
#endif
}
void
AIO_SSL_Client_Session::resume()
{
	if ( ssl_ )
	{
		{
			ACE_GUARD(ACE_SYNCH_MUTEX, monitor, this->lock_);

			if ( !is_paused() ) return;
			n_op_r_ -= 8; n_op_w_ -= 8;
			this->on_resume();

			if ( this->has_pending_io() ) return;
			if ( this->is_safe_to_delete_ == 0 ) { ssl_stream_.close(); return; }
			this->on_close();
		}

		manager_->destroy_session(this);
	}
	else
	{
		AIO_Session::resume();
	}
}