static const int MAX_FRAME_SKIP = 2;
ScreenManager::ScreenManager() :
- waiting_threads(),
+ m_waiting_threads(),
m_menu_storage(new MenuStorage),
m_menu_manager(new MenuManager),
- running(),
- speed(1.0),
- nextpop(false),
- nextpush(false),
- fps(0),
- next_screen(),
- current_screen(),
- console(),
- screen_fade(),
- screen_stack(),
- screenshot_requested(false)
+ m_running(),
+ m_speed(1.0),
+ m_nextpop(false),
+ m_nextpush(false),
+ m_fps(0),
+ m_next_screen(),
+ m_current_screen(),
+ m_screen_fade(),
+ m_screen_stack(),
+ m_screenshot_requested(false)
{
using namespace scripting;
TimeScheduler::instance = new TimeScheduler();
void
ScreenManager::push_screen(std::unique_ptr<Screen> screen, std::unique_ptr<ScreenFade> screen_fade)
{
- assert(!this->next_screen);
- this->next_screen = std::move(screen);
- this->screen_fade = std::move(screen_fade);
- nextpush = !nextpop;
- nextpop = false;
- speed = 1.0f;
+ assert(!m_next_screen);
+ m_next_screen = std::move(screen);
+ m_screen_fade = std::move(screen_fade);
+ m_nextpush = !m_nextpop;
+ m_nextpop = false;
+ m_speed = 1.0f;
}
void
ScreenManager::exit_screen(std::unique_ptr<ScreenFade> screen_fade)
{
- next_screen.reset();
- this->screen_fade = std::move(screen_fade);
- nextpop = true;
- nextpush = false;
+ m_next_screen.reset();
+ m_screen_fade = std::move(screen_fade);
+ m_nextpop = true;
+ m_nextpush = false;
}
void
ScreenManager::set_screen_fade(std::unique_ptr<ScreenFade> screen_fade)
{
- this->screen_fade = std::move(screen_fade);
+ m_screen_fade = std::move(screen_fade);
}
void
ScreenManager::quit(std::unique_ptr<ScreenFade> screen_fade)
{
- screen_stack.clear();
+ m_screen_stack.clear();
exit_screen(std::move(screen_fade));
}
void
ScreenManager::set_speed(float speed)
{
- this->speed = speed;
+ m_speed = speed;
}
float
ScreenManager::get_speed() const
{
- return speed;
+ return m_speed;
}
bool
ScreenManager::has_no_pending_fadeout() const
{
- return screen_fade.get() == NULL || screen_fade->done();
+ return !m_screen_fade || m_screen_fade->done();
}
void
char str[60];
snprintf(str, sizeof(str), "%3.1f", fps_fps);
const char* fpstext = "FPS";
- context.draw_text(Resources::small_font, fpstext,
- Vector(SCREEN_WIDTH - Resources::small_font->get_text_width(fpstext) - Resources::small_font->get_text_width(" 99999") - BORDER_X,
+ context.draw_text(Resources::small_font, fpstext,
+ Vector(SCREEN_WIDTH - Resources::small_font->get_text_width(fpstext) - Resources::small_font->get_text_width(" 99999") - BORDER_X,
BORDER_Y + 20), ALIGN_LEFT, LAYER_HUD);
context.draw_text(Resources::small_font, str, Vector(SCREEN_WIDTH - BORDER_X, BORDER_Y + 20), ALIGN_RIGHT, LAYER_HUD);
}
static Uint32 fps_ticks = SDL_GetTicks();
static int frame_count = 0;
- current_screen->draw(context);
+ m_current_screen->draw(context);
m_menu_manager->draw(context);
- if(screen_fade.get() != NULL)
- screen_fade->draw(context);
+ if (m_screen_fade)
+ {
+ m_screen_fade->draw(context);
+ }
Console::instance->draw(context);
- if(g_config->show_fps)
- draw_fps(context, fps);
+ if (g_config->show_fps)
+ {
+ draw_fps(context, m_fps);
+ }
// if a screenshot was requested, pass request on to drawing_context
- if (screenshot_requested) {
+ if (m_screenshot_requested)
+ {
context.take_screenshot();
- screenshot_requested = false;
+ m_screenshot_requested = false;
}
context.do_drawing();
/* Calculate frames per second */
- if(g_config->show_fps)
+ if (g_config->show_fps)
{
++frame_count;
- if(SDL_GetTicks() - fps_ticks >= 500)
+ if (SDL_GetTicks() - fps_ticks >= 500)
{
- fps = (float) frame_count / .5;
+ m_fps = (float) frame_count / .5;
frame_count = 0;
fps_ticks = SDL_GetTicks();
}
{
scripting::update_debugger();
scripting::TimeScheduler::instance->update(game_time);
- current_screen->update(elapsed_time);
+ m_current_screen->update(elapsed_time);
m_menu_manager->process_input();
- if(screen_fade.get() != NULL)
- screen_fade->update(elapsed_time);
+ if (m_screen_fade)
+ {
+ m_screen_fade->update(elapsed_time);
+ }
Console::instance->update(elapsed_time);
}
{
g_input_manager->update();
SDL_Event event;
- while(SDL_PollEvent(&event))
+ while (SDL_PollEvent(&event))
{
g_input_manager->process_event(event);
case SDL_QUIT:
quit();
break;
-
+
case SDL_WINDOWEVENT:
switch(event.window.event)
{
break;
}
break;
-
+
case SDL_KEYDOWN:
if (event.key.keysym.sym == SDLK_F10)
{
g_config->show_fps = !g_config->show_fps;
}
- if (event.key.keysym.sym == SDLK_F11)
+ else if (event.key.keysym.sym == SDLK_F11)
{
g_config->use_fullscreen = !g_config->use_fullscreen;
Renderer::instance()->apply_config();
void
ScreenManager::handle_screen_switch()
{
- while((next_screen || nextpop) &&
+ while ((m_next_screen || m_nextpop) &&
has_no_pending_fadeout())
{
- if(current_screen) {
- current_screen->leave();
+ if (m_current_screen) {
+ m_current_screen->leave();
}
- if(nextpop) {
- if(screen_stack.empty()) {
- running = false;
+ if (m_nextpop) {
+ if (m_screen_stack.empty()) {
+ m_running = false;
break;
}
- next_screen = std::move(screen_stack.back());
- screen_stack.pop_back();
+ m_next_screen = std::move(m_screen_stack.back());
+ m_screen_stack.pop_back();
}
- if(nextpush && current_screen) {
- screen_stack.push_back(std::move(current_screen));
+ if (m_nextpush && m_current_screen) {
+ m_screen_stack.push_back(std::move(m_current_screen));
}
- nextpush = false;
- nextpop = false;
- speed = 1.0;
- current_screen = std::move(next_screen);
- if(current_screen)
- current_screen->setup();
- screen_fade.reset();
+ m_nextpush = false;
+ m_nextpop = false;
+ m_speed = 1.0;
+ m_current_screen = std::move(m_next_screen);
+ if (m_current_screen)
+ {
+ m_current_screen->setup();
+ }
+ m_screen_fade.reset();
- waiting_threads.wakeup();
+ m_waiting_threads.wakeup();
}
}
Uint32 last_ticks = 0;
Uint32 elapsed_ticks = 0;
- running = true;
- while(running) {
-
+ m_running = true;
+ while (m_running)
+ {
handle_screen_switch();
- if(!running || !current_screen)
+ if (!m_running || !m_current_screen)
+ {
break;
+ }
Uint32 ticks = SDL_GetTicks();
elapsed_ticks += ticks - last_ticks;
Uint32 ticks_per_frame = (Uint32) (TICKS_PER_FRAME * g_game_speed);
- if (elapsed_ticks > ticks_per_frame*4) {
+ if (elapsed_ticks > ticks_per_frame*4)
+ {
// when the game loads up or levels are switched the
// elapsed_ticks grows extremely large, so we just ignore those
// large time jumps
elapsed_ticks = 0;
}
- if(elapsed_ticks < ticks_per_frame)
+ if (elapsed_ticks < ticks_per_frame)
{
Uint32 delay_ticks = ticks_per_frame - elapsed_ticks;
SDL_Delay(delay_ticks);
int frames = 0;
- while(elapsed_ticks >= ticks_per_frame && frames < MAX_FRAME_SKIP)
+ while (elapsed_ticks >= ticks_per_frame && frames < MAX_FRAME_SKIP)
{
elapsed_ticks -= ticks_per_frame;
float timestep = 1.0 / LOGICAL_FPS;
real_time += timestep;
- timestep *= speed;
+ timestep *= m_speed;
game_time += timestep;
process_events();
}
}
-void
+void
ScreenManager::take_screenshot()
{
- screenshot_requested = true;
+ m_screenshot_requested = true;
}
/* EOF */