projects
/
supertux.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
* Update squirrel to 2.2.3
[supertux.git]
/
src
/
mainloop.cpp
diff --git
a/src/mainloop.cpp
b/src/mainloop.cpp
index
0add5f9
..
444d3d2
100644
(file)
--- a/
src/mainloop.cpp
+++ b/
src/mainloop.cpp
@@
-29,6
+29,7
@@
#include "scripting/time_scheduler.hpp"
#include "scripting/squirrel_util.hpp"
#include "gameconfig.hpp"
#include "scripting/time_scheduler.hpp"
#include "scripting/squirrel_util.hpp"
#include "gameconfig.hpp"
+#include "constants.hpp"
#include "main.hpp"
#include "resources.hpp"
#include "screen.hpp"
#include "main.hpp"
#include "resources.hpp"
#include "screen.hpp"
@@
-73,7
+74,7
@@
MainLoop::push_screen(Screen* screen, ScreenFade* screen_fade)
this->screen_fade.reset(screen_fade);
nextpush = !nextpop;
nextpop = false;
this->screen_fade.reset(screen_fade);
nextpush = !nextpop;
nextpop = false;
- speed = 1.0;
+ speed = 1.0
f
;
}
void
}
void
@@
-114,6
+115,12
@@
MainLoop::get_speed() const
return speed;
}
return speed;
}
+bool
+MainLoop::has_no_pending_fadeout() const
+{
+ return screen_fade.get() == NULL || screen_fade->done();
+}
+
void
MainLoop::draw_fps(DrawingContext& context, float fps_fps)
{
void
MainLoop::draw_fps(DrawingContext& context, float fps_fps)
{
@@
-167,6
+174,8
@@
MainLoop::update_gamelogic(float elapsed_time)
Scripting::update_debugger();
Scripting::TimeScheduler::instance->update(game_time);
current_screen->update(elapsed_time);
Scripting::update_debugger();
Scripting::TimeScheduler::instance->update(game_time);
current_screen->update(elapsed_time);
+ if (Menu::current() != NULL)
+ Menu::current()->update();
if(screen_fade.get() != NULL)
screen_fade->update(elapsed_time);
Console::instance->update(elapsed_time);
if(screen_fade.get() != NULL)
screen_fade->update(elapsed_time);
Console::instance->update(elapsed_time);
@@
-229,7
+238,7
@@
void
MainLoop::handle_screen_switch()
{
while( (next_screen.get() != NULL || nextpop) &&
MainLoop::handle_screen_switch()
{
while( (next_screen.get() != NULL || nextpop) &&
-
(screen_fade.get() == NULL || screen_fade->done()
)) {
+
has_no_pending_fadeout(
)) {
if(current_screen.get() != NULL) {
current_screen->leave();
}
if(current_screen.get() != NULL) {
current_screen->leave();
}
@@
-286,29
+295,32
@@
MainLoop::run(DrawingContext &context)
elapsed_ticks = 0;
}
elapsed_ticks = 0;
}
+ if(elapsed_ticks < ticks_per_frame)
+ {
+ Uint32 delay_ticks = ticks_per_frame - elapsed_ticks;
+ SDL_Delay(delay_ticks);
+ last_ticks += delay_ticks;
+ elapsed_ticks += delay_ticks;
+ }
+
int frames = 0;
int frames = 0;
-
if (elapsed_ticks > ticks_per_frame
)
+
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;
- game_time += timestep;
-
- process_events();
- update_gamelogic(timestep);
- frames += 1;
- }
-
- draw(context);
+ elapsed_ticks -= ticks_per_frame;
+ float timestep = 1.0 / LOGICAL_FPS;
+ real_time += timestep;
+ timestep *= speed;
+ game_time += timestep;
+
+ process_events();
+ update_gamelogic(timestep);
+ frames += 1;
}
}
-
sound_manager->update(
);
+
draw(context
);
-
SDL_Delay(0
);
+
sound_manager->update(
);
}
}
}
}