From: Ingo Ruhnke Date: Fri, 16 Apr 2004 14:26:19 +0000 (+0000) Subject: - replaced a few pure pointers with std::vector<> X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=724b85c7b10de201814ee0c548c59c122475a070;p=supertux.git - replaced a few pure pointers with std::vector<> SVN-Revision: 528 --- diff --git a/src/level.cpp b/src/level.cpp index bff9411ca..d13f44974 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -211,23 +211,21 @@ Level::init_defaults() for(int i = 0; i < 15; ++i) { - ia_tiles[i] = (unsigned int*) malloc((width+1)*sizeof(unsigned int)); + ia_tiles[i].resize(width+1, 0); ia_tiles[i][width] = (unsigned int) '\0'; + for(int y = 0; y < width; ++y) ia_tiles[i][y] = 0; - ia_tiles[i][width] = (unsigned int) '\0'; - bg_tiles[i] = (unsigned int*) malloc((width+1)*sizeof(unsigned int)); + bg_tiles[i].resize(width+1, 0); bg_tiles[i][width] = (unsigned int) '\0'; for(int y = 0; y < width; ++y) bg_tiles[i][y] = 0; - bg_tiles[i][width] = (unsigned int) '\0'; - fg_tiles[i] = (unsigned int*) malloc((width+1)*sizeof(unsigned int)); + fg_tiles[i].resize(width+1, 0); fg_tiles[i][width] = (unsigned int) '\0'; for(int y = 0; y < width; ++y) fg_tiles[i][y] = 0; - fg_tiles[i][width] = (unsigned int) '\0'; } } @@ -391,9 +389,9 @@ Level::load(const std::string& filename) for(int i = 0; i < 15; ++i) { - 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) ); + ia_tiles[i].resize(width + 1, 0); + bg_tiles[i].resize(width + 1, 0); + fg_tiles[i].resize(width + 1, 0); } int i = 0; @@ -533,11 +531,11 @@ void Level::cleanup() { for(int i=0; i < 15; ++i) - free(bg_tiles[i]); - for(int i=0; i < 15; ++i) - free(ia_tiles[i]); - for(int i=0; i < 15; ++i) - free(fg_tiles[i]); + { + bg_tiles[i].clear(); + ia_tiles[i].clear(); + fg_tiles[i].clear(); + } name.clear(); author.clear(); diff --git a/src/level.h b/src/level.h index 887d0aa05..e3efe0df7 100644 --- a/src/level.h +++ b/src/level.h @@ -61,9 +61,9 @@ class Level std::string song_title; std::string bkgd_image; std::string particle_system; - unsigned int* bg_tiles[15]; /* Tiles in the background */ - unsigned int* ia_tiles[15]; /* Tiles which can interact in the game (solids for example)*/ - unsigned int* fg_tiles[15]; /* Tiles in the foreground */ + std::vector bg_tiles[15]; /* Tiles in the background */ + std::vector ia_tiles[15]; /* Tiles which can interact in the game (solids for example)*/ + std::vector fg_tiles[15]; /* Tiles in the foreground */ int time_left; Color bkgd_top; Color bkgd_bottom; diff --git a/src/screen.h b/src/screen.h index 8231c5478..5785871ca 100644 --- a/src/screen.h +++ b/src/screen.h @@ -26,7 +26,15 @@ struct Color { -int red, green, blue; + Color() + : red(0), green(0), blue(0) + {} + + Color(int red_, int green_, int blue_) + : red(red_), green(green_), blue(blue_) + {} + + int red, green, blue; }; void drawline(int x1, int y1, int x2, int y2, int r, int g, int b, int a);