projects
/
supertux.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Made trampolines less likely to interfere with level design:
[supertux.git]
/
src
/
mainloop.cpp
diff --git
a/src/mainloop.cpp
b/src/mainloop.cpp
index
98c8efc
..
f9a54f1
100644
(file)
--- a/
src/mainloop.cpp
+++ b/
src/mainloop.cpp
@@
-26,14
+26,16
@@
#include "control/joystickkeyboardcontroller.hpp"
#include "gui/menu.hpp"
#include "audio/sound_manager.hpp"
#include "control/joystickkeyboardcontroller.hpp"
#include "gui/menu.hpp"
#include "audio/sound_manager.hpp"
+#include "scripting/time_scheduler.hpp"
+#include "scripting/squirrel_util.hpp"
#include "gameconfig.hpp"
#include "main.hpp"
#include "resources.hpp"
#include "gameconfig.hpp"
#include "main.hpp"
#include "resources.hpp"
-#include "script_manager.hpp"
#include "screen.hpp"
#include "screen_fade.hpp"
#include "timer.hpp"
#include "player_status.hpp"
#include "screen.hpp"
#include "screen_fade.hpp"
#include "timer.hpp"
#include "player_status.hpp"
+#include "random_generator.hpp"
// the engine will be run with a logical framerate of 64fps.
// We chose 64fps here because it is a power of 2, so 1/64 gives an "even"
// the engine will be run with a logical framerate of 64fps.
// We chose 64fps here because it is a power of 2, so 1/64 gives an "even"
@@
-43,12
+45,18
@@
static const float LOGICAL_FPS = 64.0;
MainLoop* main_loop = NULL;
MainLoop::MainLoop()
MainLoop* main_loop = NULL;
MainLoop::MainLoop()
- : speed(1.0)
+ : speed(1.0)
, nextpop(false), nextpush(false)
{
{
+ using namespace Scripting;
+ TimeScheduler::instance = new TimeScheduler();
}
MainLoop::~MainLoop()
{
}
MainLoop::~MainLoop()
{
+ using namespace Scripting;
+ delete TimeScheduler::instance;
+ TimeScheduler::instance = NULL;
+
for(std::vector<Screen*>::iterator i = screen_stack.begin();
i != screen_stack.end(); ++i) {
delete *i;
for(std::vector<Screen*>::iterator i = screen_stack.begin();
i != screen_stack.end(); ++i) {
delete *i;
@@
-60,6
+68,10
@@
MainLoop::push_screen(Screen* screen, ScreenFade* screen_fade)
{
this->next_screen.reset(screen);
this->screen_fade.reset(screen_fade);
{
this->next_screen.reset(screen);
this->screen_fade.reset(screen_fade);
+ if(nextpop)
+ nextpush = false;
+ else
+ nextpush = true;
nextpop = false;
speed = 1.0;
}
nextpop = false;
speed = 1.0;
}
@@
-70,6
+82,7
@@
MainLoop::exit_screen(ScreenFade* screen_fade)
next_screen.reset(NULL);
this->screen_fade.reset(screen_fade);
nextpop = true;
next_screen.reset(NULL);
this->screen_fade.reset(screen_fade);
nextpop = true;
+ nextpush = false;
}
void
}
void
@@
-84,6
+97,7
@@
MainLoop::quit(ScreenFade* screen_fade)
for(std::vector<Screen*>::iterator i = screen_stack.begin();
i != screen_stack.end(); ++i)
delete *i;
for(std::vector<Screen*>::iterator i = screen_stack.begin();
i != screen_stack.end(); ++i)
delete *i;
+ screen_stack.clear();
exit_screen(screen_fade);
}
exit_screen(screen_fade);
}
@@
-109,7
+123,7
@@
MainLoop::run()
{
DrawingContext context;
{
DrawingContext context;
- unsigned int frame_count;
+ unsigned int frame_count
= 0
;
float fps_fps = 0;
Uint32 fps_ticks = SDL_GetTicks();
Uint32 fps_nextframe_ticks = SDL_GetTicks();
float fps_fps = 0;
Uint32 fps_ticks = SDL_GetTicks();
Uint32 fps_nextframe_ticks = SDL_GetTicks();
@@
-118,7
+132,7
@@
MainLoop::run()
running = true;
while(running) {
running = true;
while(running) {
-
if
( (next_screen.get() != NULL || nextpop == true) &&
+
while
( (next_screen.get() != NULL || nextpop == true) &&
(screen_fade.get() == NULL || screen_fade->done())) {
if(current_screen.get() != NULL) {
current_screen->leave();
(screen_fade.get() == NULL || screen_fade->done())) {
if(current_screen.get() != NULL) {
current_screen->leave();
@@
-131,21
+145,24
@@
MainLoop::run()
}
next_screen.reset(screen_stack.back());
screen_stack.pop_back();
}
next_screen.reset(screen_stack.back());
screen_stack.pop_back();
- nextpop = false;
- speed = 1.0;
- } else if(current_screen.get() != NULL) {
+ }
+ if(nextpush && current_screen.get() != NULL) {
screen_stack.push_back(current_screen.release());
}
screen_stack.push_back(current_screen.release());
}
-
- next_screen->setup();
- ScriptManager::instance->fire_wakeup_event(ScriptManager::SCREEN_SWITCHED);
+
+ nextpush = false;
+ nextpop = false;
+ speed = 1.0;
+ if(next_screen.get() != NULL)
+ next_screen->setup();
current_screen.reset(next_screen.release());
current_screen.reset(next_screen.release());
- next_screen.reset(NULL);
screen_fade.reset(NULL);
screen_fade.reset(NULL);
+
+ waiting_threads.wakeup();
}
}
- if(current_screen.get() == NULL)
-
break;
+ if(
!running ||
current_screen.get() == NULL)
+ break;
float elapsed_time = 1.0 / LOGICAL_FPS;
ticks = SDL_GetTicks();
float elapsed_time = 1.0 / LOGICAL_FPS;
ticks = SDL_GetTicks();
@@
-199,10
+216,12
@@
MainLoop::run()
}
}
}
}
+ real_time += elapsed_time;
elapsed_time *= speed;
elapsed_time *= speed;
-
game_time += elapsed_time;
game_time += elapsed_time;
- ScriptManager::instance->update();
+
+ Scripting::update_debugger();
+ Scripting::TimeScheduler::instance->update(game_time);
current_screen->update(elapsed_time);
if(screen_fade.get() != NULL)
screen_fade->update(elapsed_time);
current_screen->update(elapsed_time);
if(screen_fade.get() != NULL)
screen_fade->update(elapsed_time);
@@
-219,6
+238,8
@@
MainLoop::run()
}
sound_manager->update();
}
sound_manager->update();
+
+ //log_info << "== periodic rand() = " << systemRandom.rand() << std::endl;
}
}
}
}