From: Ingo Ruhnke Date: Sat, 10 Apr 2004 19:49:49 +0000 (+0000) Subject: - more c++-ification X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=c4183c0332f8e09dffc70f135689853fb2e3728a;p=supertux.git - more c++-ification SVN-Revision: 453 --- diff --git a/src/gameloop.cpp b/src/gameloop.cpp index 42a792ba6..5d1c64bc9 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -361,7 +361,7 @@ int game_action(void) if (st_gl_mode == ST_GL_LOAD_LEVEL_FILE) { - if(level_load(¤t_level, level_subset) != 0) + if(current_level.load(level_subset) != 0) return 0; } else @@ -599,7 +599,7 @@ int gameloop(const char * subset, int levelnb, int mode) if (st_gl_mode == ST_GL_LOAD_LEVEL_FILE) { - if (level_load(¤t_level, level_subset)) + if (current_level.load(level_subset)) exit(1); } else diff --git a/src/level.cpp b/src/level.cpp index ad36b2fe4..ecd15c995 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -241,10 +241,11 @@ st_level::load(const char *subset, int level) if(!faccessible(filename)) snprintf(filename, 1024, "%s/levels/%s/level%d.stl", datadir.c_str(), subset, level); - return level_load(this, filename); + return load(filename); } -int level_load(st_level* plevel, const char* filename) +int +st_level::load(const char* filename) { FILE * fi; lisp_object_t* root_obj = 0; @@ -274,17 +275,17 @@ int level_load(st_level* plevel, const char* filename) LispReader reader(lisp_cdr(root_obj)); reader.read_int("version", &version); - reader.read_int("width", &plevel->width); - reader.read_int("time", &plevel->time_left); - reader.read_int("bkgd_red", &plevel->bkgd_red); - reader.read_int("bkgd_green", &plevel->bkgd_green); - reader.read_int("bkgd_blue", &plevel->bkgd_blue); - reader.read_float("gravity", &plevel->gravity); - reader.read_string("name", &plevel->name); - reader.read_string("theme", &plevel->theme); - reader.read_string("music", &plevel->song_title); - reader.read_string("background", &plevel->bkgd_image); - reader.read_string("particle_system", &plevel->particle_system); + reader.read_int("width", &width); + reader.read_int("time", &time_left); + reader.read_int("bkgd_red", &bkgd_red); + reader.read_int("bkgd_green", &bkgd_green); + reader.read_int("bkgd_blue", &bkgd_blue); + reader.read_float("gravity", &gravity); + reader.read_string("name", &name); + reader.read_string("theme", &theme); + reader.read_string("music", &song_title); + reader.read_string("background", &bkgd_image); + reader.read_string("particle_system", &particle_system); reader.read_int_vector("background-tm", &bg_tm); if (!reader.read_int_vector("interactive-tm", &ia_tm)) @@ -306,7 +307,7 @@ int level_load(st_level* plevel, const char* filename) reader.read_int("x", &bg_data.x); reader.read_int("y", &bg_data.y); - plevel->badguy_data.push_back(bg_data); + badguy_data.push_back(bg_data); cur = lisp_cdr(cur); } @@ -362,7 +363,7 @@ int level_load(st_level* plevel, const char* filename) { if (*i == '0' || *i == '1' || *i == '2') { - plevel->badguy_data.push_back(BadGuyData(static_cast(*i-'0'), + badguy_data.push_back(BadGuyData(static_cast(*i-'0'), x*32, y*32)); *i = 0; } @@ -375,7 +376,7 @@ int level_load(st_level* plevel, const char* filename) printf("Error: conversion will fail, unsupported char: '%c' (%d)\n", *i, *i); } ++x; - if (x >= plevel->width) + if (x >= width) { x = 0; ++y; @@ -386,17 +387,17 @@ int level_load(st_level* plevel, const char* filename) for(int i = 0; i < 15; ++i) { - plevel->ia_tiles[i] = (unsigned int*) calloc((plevel->width +1) , sizeof(unsigned int) ); - plevel->bg_tiles[i] = (unsigned int*) calloc((plevel->width +1) , sizeof(unsigned int) ); - plevel->fg_tiles[i] = (unsigned int*) calloc((plevel->width +1) , sizeof(unsigned int) ); + ia_tiles[i] = (unsigned int*) calloc((width +1) , sizeof(unsigned int) ); + bg_tiles[i] = (unsigned int*) calloc((width +1) , sizeof(unsigned int) ); + fg_tiles[i] = (unsigned int*) calloc((width +1) , sizeof(unsigned int) ); } int i = 0; int j = 0; for(vector::iterator it = ia_tm.begin(); it != ia_tm.end(); ++it, ++i) { - plevel->ia_tiles[j][i] = (*it); - if(i == plevel->width - 1) + ia_tiles[j][i] = (*it); + if(i == width - 1) { i = -1; ++j; @@ -407,8 +408,8 @@ int level_load(st_level* plevel, const char* filename) for(vector::iterator it = bg_tm.begin(); it != bg_tm.end(); ++it, ++i) { - plevel->bg_tiles[j][i] = (*it); - if(i == plevel->width - 1) + bg_tiles[j][i] = (*it); + if(i == width - 1) { i = -1; ++j; @@ -419,21 +420,21 @@ int level_load(st_level* plevel, const char* filename) for(vector::iterator it = fg_tm.begin(); it != fg_tm.end(); ++it, ++i) { - plevel->fg_tiles[j][i] = (*it); - if(i == plevel->width - 1) + fg_tiles[j][i] = (*it); + if(i == width - 1) { i = -1; ++j; } } - /* Set the global gravity to the latest loaded level's gravity */ - gravity = plevel->gravity; + // FIXME: Set the global gravity to the latest loaded level's gravity + ::gravity = gravity; // Mark the end position of this level! // FIXME: -10 is a rather random value, we still need some kind of // real levelend gola - endpos = 32*(plevel->width-10); + endpos = 32*(width-10); fclose(fi); return 0; diff --git a/src/level.h b/src/level.h index 4ef9b4e76..8c48f8490 100644 --- a/src/level.h +++ b/src/level.h @@ -82,9 +82,10 @@ class st_level void cleanup(); int load(const char * subset, int level); + int load(const char* filename); + }; -int level_load (st_level* plevel, const char* filename); void level_save (st_level* plevel, const char * subset, int level); void level_load_gfx (st_level* plevel); void level_change (st_level* plevel, float x, float y, int tm, unsigned int c); diff --git a/src/title.cpp b/src/title.cpp index 68e5eb66d..263b18879 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -142,7 +142,7 @@ int title(void) st_pause_ticks_init(); - level_load(¤t_level, (datadir + "/levels/misc/menu.stl").c_str()); + current_level.load((datadir + "/levels/misc/menu.stl").c_str()); loadshared(); activate_particle_systems(); /* Lower the gravity that tux doesn't jump to hectically through the demo */