[Super-tux-commit] supertux/src gameloop.cpp,1.46,1.47 gameloop.h,1.25,1.26 leveleditor.cpp,1.30,1.3
Brought to you by:
wkendrick
From: Ingo R. <gr...@us...> - 2004-04-10 20:40:04
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13726 Modified Files: gameloop.cpp gameloop.h leveleditor.cpp setup.cpp supertux.cpp worldmap.cpp Log Message: - turned gameloop into a class, in the hope to reduce some global variables in the long run Index: setup.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/setup.cpp,v retrieving revision 1.26 retrieving revision 1.27 diff -u -d -r1.26 -r1.27 --- setup.cpp 10 Apr 2004 19:40:49 -0000 1.26 +++ setup.cpp 10 Apr 2004 20:26:13 -0000 1.27 @@ -468,7 +468,9 @@ if (tmp.length() == strlen("Slot X - Free")) { // Slot is free, so start a new game - gameloop("default", 1, ST_GL_PLAY); + GameSession session("default", 1, ST_GL_PLAY); + session.run(); + show_menu = true; Menu::set_current(main_menu); } @@ -476,7 +478,9 @@ { // Slot contains a level, so load it if (game_started) { - gameloop("default",slot - 1,ST_GL_LOAD_GAME); + GameSession session("default",slot - 1,ST_GL_LOAD_GAME); + session.run(); + show_menu = true; Menu::set_current(main_menu); } Index: leveleditor.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/leveleditor.cpp,v retrieving revision 1.30 retrieving revision 1.31 diff -u -d -r1.30 -r1.31 --- leveleditor.cpp 10 Apr 2004 20:16:15 -0000 1.30 +++ leveleditor.cpp 10 Apr 2004 20:26:13 -0000 1.31 @@ -1186,7 +1186,10 @@ void le_testlevel() { le_current_level->save("test", le_level); - gameloop("test",le_level, ST_GL_TEST); + + GameSession session("test",le_level, ST_GL_TEST); + session.run(); + Menu::set_current(leveleditor_menu); arrays_free(); le_current_level->load_gfx(); Index: gameloop.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.h,v retrieving revision 1.25 retrieving revision 1.26 diff -u -d -r1.25 -r1.26 --- gameloop.h 10 Apr 2004 20:16:15 -0000 1.25 +++ gameloop.h 10 Apr 2004 20:26:13 -0000 1.26 @@ -29,11 +29,16 @@ extern int game_started; -/* Function prototypes: */ -class Tile; +class GameSession +{ + private: + timer_type fps_timer, frame_timer; + public: + GameSession(const char * subset, int levelnb, int mode); + int run(); +}; void activate_bad_guys(Level* plevel); -int gameloop(const char * subset, int levelnb, int mode); void savegame(int slot); void loadgame(int slot); std::string slotinfo(int slot); Index: worldmap.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/worldmap.cpp,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- worldmap.cpp 10 Apr 2004 18:56:17 -0000 1.19 +++ worldmap.cpp 10 Apr 2004 20:26:13 -0000 1.20 @@ -417,8 +417,9 @@ { std::cout << "Enter the current level: " << i->name << std::endl;; halt_music(); - gameloop(const_cast<char*>((datadir + "levels/default/" + i->name).c_str()), - 1, ST_GL_LOAD_LEVEL_FILE); + GameSession session(const_cast<char*>((datadir + "levels/default/" + i->name).c_str()), + 1, ST_GL_LOAD_LEVEL_FILE); + session.run(); play_music(song, 1); return; } Index: gameloop.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.cpp,v retrieving revision 1.46 retrieving revision 1.47 diff -u -d -r1.46 -r1.47 --- gameloop.cpp 10 Apr 2004 20:16:15 -0000 1.46 +++ gameloop.cpp 10 Apr 2004 20:26:13 -0000 1.47 @@ -579,10 +579,8 @@ /* --- GAME LOOP! --- */ -int gameloop(const char * subset, int levelnb, int mode) +GameSession::GameSession(const char * subset, int levelnb, int mode) { - int fps_cnt, jump, done; - timer_type fps_timer, frame_timer; timer_init(&fps_timer, true); timer_init(&frame_timer, true); @@ -627,11 +625,18 @@ if(st_gl_mode == ST_GL_LOAD_GAME) loadgame(levelnb); +} - /* --- MAIN GAME LOOP!!! --- */ +int +GameSession::run() +{ + int fps_cnt; + bool jump; + bool done; + /* --- MAIN GAME LOOP!!! --- */ jump = false; - done = 0; + done = false; quit = 0; global_frame_counter = 0; game_pause = 0; @@ -641,14 +646,12 @@ fps_cnt = 0; /* Clear screen: */ - clearscreen(0, 0, 0); updatescreen(); /* Play music: */ play_current_music(); - while (SDL_PollEvent(&event)) {} @@ -691,7 +694,7 @@ break; case 7: st_pause_ticks_stop(); - done = 1; + done = true; break; } } Index: supertux.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/supertux.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- supertux.cpp 9 Apr 2004 00:49:47 -0000 1.5 +++ supertux.cpp 10 Apr 2004 20:26:13 -0000 1.6 @@ -34,7 +34,8 @@ } else if (level_startup_file) { - gameloop(level_startup_file, 1, ST_GL_LOAD_LEVEL_FILE); + GameSession session(level_startup_file, 1, ST_GL_LOAD_LEVEL_FILE); + session.run(); } else { |