[Super-tux-commit] supertux/src gameloop.cpp,1.51,1.52 gameloop.h,1.30,1.31 level.cpp,1.28,1.29 leve
Brought to you by:
wkendrick
From: Ingo R. <gr...@us...> - 2004-04-11 01:38:34
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30134 Modified Files: gameloop.cpp gameloop.h level.cpp level.h leveleditor.cpp scene.cpp scene.h supertux.cpp title.cpp title.h world.cpp Log Message: - moved some more level_ stuff into the levelclass - removed a quit, since it did the same as a done Index: scene.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/scene.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- scene.cpp 10 Apr 2004 22:37:13 -0000 1.13 +++ scene.cpp 11 Apr 2004 01:24:58 -0000 1.14 @@ -18,7 +18,6 @@ int level; int next_level; int game_pause; -bool quit; int score_multiplier; int endpos; bool counting_distros; Index: scene.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/scene.h,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- scene.h 10 Apr 2004 22:37:13 -0000 1.16 +++ scene.h 11 Apr 2004 01:24:58 -0000 1.17 @@ -29,7 +29,6 @@ extern int level; extern int next_level; extern int game_pause; -extern bool quit; extern int score_multiplier; extern int endpos; extern bool counting_distros; Index: level.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level.h,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -r1.22 -r1.23 --- level.h 11 Apr 2004 00:24:22 -0000 1.22 +++ level.h 11 Apr 2004 01:24:58 -0000 1.23 @@ -50,11 +50,11 @@ TM_FG }; -extern texture_type img_bkgd; - class Level { public: + texture_type img_bkgd; + std::string name; std::string theme; std::string song_title; @@ -87,7 +87,9 @@ int load(const std::string& filename); void load_gfx(); + void load_song(); + void free_song(); void save(const char* subset, int level); @@ -99,10 +101,11 @@ /** Return the id of the tile at position x/y */ unsigned int gettileid(float x, float y); + + void free_gfx(); + + void load_image(texture_type* ptexture, std::string theme, const char * file, int use_alpha); }; -void level_load_image(texture_type* ptexture, std::string theme, const char * file, int use_alpha); -void level_free_song(); -void level_free_gfx(); #endif /*SUPERTUX_LEVEL_H*/ Index: gameloop.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.cpp,v retrieving revision 1.51 retrieving revision 1.52 diff -u -d -r1.51 -r1.52 --- gameloop.cpp 11 Apr 2004 00:05:35 -0000 1.51 +++ gameloop.cpp 11 Apr 2004 01:24:58 -0000 1.52 @@ -191,7 +191,7 @@ switch(event.type) { case SDL_QUIT: /* Quit event - quit: */ - quit = 1; + quit = true; break; case SDL_KEYDOWN: /* A keypress! */ key = event.key.keysym.sym; @@ -205,7 +205,7 @@ if(!game_pause) { if(st_gl_mode == ST_GL_TEST) - quit = 1; + quit = true; else if(show_menu) { Menu::set_current(game_menu); @@ -367,9 +367,9 @@ } else { - level_free_gfx(); + world->get_level()->free_gfx(); world->get_level()->cleanup(); - level_free_song(); + world->get_level()->free_song(); unloadshared(); world->arrays_free(); return(0); @@ -392,9 +392,9 @@ if (score > hs_score) save_hs(score); } - level_free_gfx(); + world->get_level()->free_gfx(); world->get_level()->cleanup(); - level_free_song(); + world->get_level()->free_song(); unloadshared(); world->arrays_free(); return(0); @@ -421,10 +421,12 @@ world->arrays_free(); activate_bad_guys(world->get_level()); world->activate_particle_systems(); - level_free_gfx(); + + world->get_level()->free_gfx(); world->get_level()->load_gfx(); - level_free_song(); + world->get_level()->free_song(); world->get_level()->load_song(); + if(st_gl_mode != ST_GL_TEST) levelintro(); start_timers(); @@ -452,10 +454,7 @@ void GameSession::draw() { - - world->draw(); - drawstatus(); if(game_pause) @@ -470,12 +469,11 @@ } if(show_menu) - { - menu_process_current(); - mouse_cursor->draw(); - } + { + menu_process_current(); + mouse_cursor->draw(); + } - /* (Update it all!) */ updatescreen(); } @@ -486,13 +484,8 @@ current_ = this; int fps_cnt; - bool jump; bool done; - /* --- MAIN GAME LOOP!!! --- */ - jump = false; - done = false; - quit = 0; global_frame_counter = 0; game_pause = 0; timer_init(&fps_timer,true); @@ -511,10 +504,11 @@ {} draw(); - do - { - jump = false; + done = false; + quit = false; + while (!done && !quit) + { /* Calculate the movement-factor */ frame_ratio = ((double)(update_time-last_update_time))/((double)FRAME_RATE); if(frame_ratio > 1.5) /* Quick hack to correct the unprecise CPU clocks a little bit. */ @@ -617,17 +611,14 @@ /* Pause till next frame, if the machine running the game is too fast: */ /* FIXME: Works great for in OpenGl mode, where the CPU doesn't have to do that much. But the results in SDL mode aren't perfect (thought the 100 FPS are reached), even on an AMD2500+. */ - if(last_update_time >= update_time - 12 && !jump) { + if(last_update_time >= update_time - 12) { SDL_Delay(10); update_time = st_get_ticks(); } /*if((update_time - last_update_time) < 10) SDL_Delay((11 - (update_time - last_update_time))/2);*/ - - /* Handle time: */ - if (timer_check(&time_left)) { /* are we low on time ? */ @@ -642,7 +633,6 @@ else tux.kill(KILL); - /* Calculate frames per second */ if(show_fps) { @@ -655,15 +645,14 @@ fps_cnt = 0; } } - } - while (!done && !quit); halt_music(); - level_free_gfx(); + world->get_level()->free_gfx(); world->get_level()->cleanup(); - level_free_song(); + world->get_level()->free_song(); + unloadshared(); world->arrays_free(); @@ -860,10 +849,12 @@ world->arrays_free(); activate_bad_guys(world->get_level()); world->activate_particle_systems(); - level_free_gfx(); + + world->get_level()->free_gfx(); world->get_level()->load_gfx(); - level_free_song(); + world->get_level()->free_song(); world->get_level()->load_song(); + levelintro(); update_time = st_get_ticks(); Index: supertux.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/supertux.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- supertux.cpp 10 Apr 2004 20:26:13 -0000 1.6 +++ supertux.cpp 11 Apr 2004 01:24:58 -0000 1.7 @@ -17,7 +17,7 @@ int main(int argc, char * argv[]) { - int done; + bool done; st_directory_setup(); parseargs(argc, argv); @@ -39,8 +39,7 @@ } else { - done = 0; - + done = false; while (!done) { done = title(); @@ -52,5 +51,5 @@ st_shutdown(); - return(0); + return 0; } Index: title.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/title.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- title.h 15 Mar 2004 17:45:29 -0000 1.2 +++ title.h 11 Apr 2004 01:24:58 -0000 1.3 @@ -10,4 +10,4 @@ April 11, 2000 - March 15, 2004 */ -int title(void); +bool title(void); Index: gameloop.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.h,v retrieving revision 1.30 retrieving revision 1.31 diff -u -d -r1.30 -r1.31 --- gameloop.h 11 Apr 2004 00:05:35 -0000 1.30 +++ gameloop.h 11 Apr 2004 01:24:58 -0000 1.31 @@ -35,6 +35,7 @@ class GameSession { private: + bool quit; timer_type fps_timer, frame_timer; World* world; Index: level.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level.cpp,v retrieving revision 1.28 retrieving revision 1.29 diff -u -d -r1.28 -r1.29 --- level.cpp 11 Apr 2004 00:24:22 -0000 1.28 +++ level.cpp 11 Apr 2004 01:24:58 -0000 1.29 @@ -26,8 +26,6 @@ using namespace std; -texture_type img_bkgd; - st_subset::st_subset() { levels = 0; @@ -539,30 +537,9 @@ badguy_data.clear(); } -/* Load graphics: */ - void Level::load_gfx() { - /* - level_load_image(&img_brick[0],theme,"brick0.png", IGNORE_ALPHA); - level_load_image(&img_brick[1],theme,"brick1.png", IGNORE_ALPHA); - - level_load_image(&img_solid[0],theme,"solid0.png", USE_ALPHA); - level_load_image(&img_solid[1],theme,"solid1.png", USE_ALPHA); - level_load_image(&img_solid[2],theme,"solid2.png", USE_ALPHA); - level_load_image(&img_solid[3],theme,"solid3.png", USE_ALPHA); - - level_load_image(&img_bkgd_tile[0][0],theme,"bkgd-00.png", USE_ALPHA); - level_load_image(&img_bkgd_tile[0][1],theme,"bkgd-01.png", USE_ALPHA); - level_load_image(&img_bkgd_tile[0][2],theme,"bkgd-02.png", USE_ALPHA); - level_load_image(&img_bkgd_tile[0][3],theme,"bkgd-03.png", USE_ALPHA); - - level_load_image(&img_bkgd_tile[1][0],theme,"bkgd-10.png", USE_ALPHA); - level_load_image(&img_bkgd_tile[1][1],theme,"bkgd-11.png", USE_ALPHA); - level_load_image(&img_bkgd_tile[1][2],theme,"bkgd-12.png", USE_ALPHA); - level_load_image(&img_bkgd_tile[1][3],theme,"bkgd-13.png", USE_ALPHA); - */ if(!bkgd_image.empty()) { char fname[1024]; @@ -573,20 +550,20 @@ } else { - /* Quick hack to make sure an image is loaded, when we are freeing it afterwards. */# - level_load_image(&img_bkgd, theme,"solid0.png", IGNORE_ALPHA); + /* Quick hack to make sure an image is loaded, when we are freeing it afterwards. */ + load_image(&img_bkgd, theme,"solid0.png", IGNORE_ALPHA); } } -/* Free graphics data for this level: */ -void level_free_gfx(void) +void +Level::free_gfx() { texture_free(&img_bkgd); } /* Load a level-specific graphic... */ - -void level_load_image(texture_type* ptexture, string theme,const char * file, int use_alpha) +void +Level::load_image(texture_type* ptexture, string theme,const char * file, int use_alpha) { char fname[1024]; @@ -647,16 +624,13 @@ } } -/* Free music data for this level: */ - -void level_free_song(void) +void +Level::free_song(void) { free_music(level_song); free_music(level_song_fast); } -/* Load music: */ - void Level::load_song() { @@ -669,7 +643,8 @@ strlen(song_title.c_str()) + 8 + 5); song_subtitle = strdup(song_title.c_str()); strcpy(strstr(song_subtitle, "."), "\0"); - sprintf(song_path, "%s/music/%s-fast%s", datadir.c_str(), song_subtitle, strstr(song_title.c_str(), ".")); + sprintf(song_path, "%s/music/%s-fast%s", datadir.c_str(), + song_subtitle, strstr(song_title.c_str(), ".")); level_song_fast = ::load_song(song_path); free(song_subtitle); free(song_path); Index: world.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/world.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- world.cpp 11 Apr 2004 00:05:35 -0000 1.8 +++ world.cpp 11 Apr 2004 01:24:58 -0000 1.9 @@ -18,6 +18,7 @@ #include "screen.h" #include "defines.h" #include "world.h" +#include "level.h" #include "tile.h" texture_type img_distro[4]; @@ -95,8 +96,8 @@ if(get_level()->bkgd_image[0] != '\0') { int s = (int)scroll_x / 30; - texture_draw_part(&img_bkgd,s,0,0,0,img_bkgd.w - s, img_bkgd.h); - texture_draw_part(&img_bkgd,0,0,screen->w - s ,0,s,img_bkgd.h); + texture_draw_part(&level->img_bkgd, s, 0,0,0,level->img_bkgd.w - s, level->img_bkgd.h); + texture_draw_part(&level->img_bkgd, 0, 0,screen->w - s ,0,s,level->img_bkgd.h); } else { @@ -399,7 +400,8 @@ else { s = (int)scroll_x / 30; - texture_draw_part(&img_bkgd,dest.x + s,dest.y,dest.x,dest.y,dest.w,dest.h); + texture_draw_part(&plevel->img_bkgd, dest.x + s, dest.y, + dest.x, dest.y,dest.w,dest.h); } drawshape(pbouncy_brick->base.x - scroll_x, Index: title.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/title.cpp,v retrieving revision 1.27 retrieving revision 1.28 diff -u -d -r1.27 -r1.28 --- title.cpp 10 Apr 2004 22:01:27 -0000 1.27 +++ title.cpp 11 Apr 2004 01:24:58 -0000 1.28 @@ -129,9 +129,8 @@ /* --- TITLE SCREEN --- */ -int title(void) +bool title(void) { - int done; string_list_type level_subsets; st_subset subset; level_subsets = dsubdirs("/levels", "info"); @@ -162,9 +161,7 @@ texture_load(&img_choose_subset,datadir + "/images/status/choose-level-subset.png", USE_ALPHA); /* --- Main title loop: --- */ - - done = 0; - quit = 0; + bool done = 0; show_menu = 1; frame = 0; @@ -175,9 +172,8 @@ update_time = st_get_ticks(); timer_start(&random_timer, rand() % 2000 + 2000); - while (!done && !quit) + while (!done) { - /* Calculate the movement-factor */ frame_ratio = ((double)(update_time-last_update_time))/((double)FRAME_RATE); if(frame_ratio > 1.5) /* Quick hack to correct the unprecise CPU clocks a little bit. */ @@ -192,13 +188,11 @@ menu_event(event); if (event.type == SDL_QUIT) { - /* Quit event - quit: */ - quit = 1; + done = true; } else if (event.type == SDL_KEYDOWN) { /* Keypress... */ - key = event.key.keysym.sym; /* Check for menu events */ @@ -207,8 +201,7 @@ if (key == SDLK_ESCAPE) { /* Escape: Quit: */ - - quit = 1; + done = true; } } } @@ -237,7 +230,7 @@ */ /* Don't draw menu, if quit is true */ - if(show_menu && !quit) + if(show_menu && !done) menu_process_current(); if(current_menu == main_menu) @@ -276,8 +269,7 @@ switch(event.type) { case SDL_QUIT: - done = 1; - quit = 1; + done = true; break; case SDL_KEYDOWN: // key pressed // Keypress... @@ -333,13 +325,13 @@ break; case 3: done = 1; - quit = leveleditor(1); + done = leveleditor(1); break; case 4: display_credits(); break; case 5: - quit = 1; + done = true; break; } } @@ -382,8 +374,7 @@ string_list_free(&level_subsets); /* Return to main! */ - - return(quit); + return done; } #define MAX_VEL 10 Index: leveleditor.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/leveleditor.cpp,v retrieving revision 1.32 retrieving revision 1.33 diff -u -d -r1.32 -r1.33 --- leveleditor.cpp 10 Apr 2004 22:37:13 -0000 1.32 +++ leveleditor.cpp 11 Apr 2004 01:24:58 -0000 1.33 @@ -519,7 +519,7 @@ if(i) { - level_free_gfx(); + le_current_level->free_gfx(); le_current_level->load_gfx(); } @@ -556,9 +556,9 @@ le_set_defaults(); - - level_free_gfx(); + le_current_level->free_gfx(); le_current_level->load_gfx(); + activate_bad_guys(le_current_level); } @@ -593,7 +593,7 @@ if(le_current_level != NULL) { - level_free_gfx(); + le_current_level->free_gfx(); le_current_level->cleanup(); unloadshared(); world.arrays_free(); @@ -682,8 +682,10 @@ if(le_current_level->bkgd_image[0] != '\0') { s = pos_x / 30; - texture_draw_part(&img_bkgd,s,0,0,0,img_bkgd.w - s - 32, img_bkgd.h); - texture_draw_part(&img_bkgd,0,0,screen->w - s - 32 ,0,s,img_bkgd.h); + texture_draw_part(&le_current_level->img_bkgd,s,0,0,0, + le_current_level->img_bkgd.w - s - 32, le_current_level->img_bkgd.h); + texture_draw_part(&le_current_level->img_bkgd,0,0,screen->w - s - 32 ,0,s, + le_current_level->img_bkgd.h); } else { |