[Super-tux-commit] supertux/src gameloop.cpp,1.25,1.26 level.cpp,1.13,1.14 tile.cpp,1.3,1.4 tile.h,1
Brought to you by:
wkendrick
From: Ingo R. <gr...@us...> - 2004-03-25 10:36:55
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29713 Modified Files: gameloop.cpp level.cpp tile.cpp tile.h Log Message: - made TileManager::get() always return a valid tile - made conversion code more robust against unknown tiles - added next_tile/next_tile2 to replace the old one on some events Index: tile.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/tile.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- tile.h 25 Mar 2004 02:13:17 -0000 1.2 +++ tile.h 25 Mar 2004 10:26:07 -0000 1.3 @@ -23,7 +23,10 @@ */ struct Tile { + int id; + std::vector<texture_type> images; + std::vector<std::string> filenames; /** solid tile that is indestructable by Tux */ bool solid; @@ -43,6 +46,11 @@ /** General purpose data attached to a tile (content of a box, type of coin) */ int data; + /** Id of the tile that is going to replace this tile once it has + been collected or jumped at */ + int next_tile; + int next_tile2; + int anim_speed; unsigned char alpha; }; @@ -57,7 +65,19 @@ public: static TileManager* instance() { return instance_ ? instance_ : instance_ = new TileManager(); } - Tile* get(unsigned int id) { if( id < tiles.size()) { return tiles[id]; } else { return NULL; } } + Tile* get(unsigned int id) { + if(id < tiles.size()) + { + return tiles[id]; + } + else + { + // Never return 0, but return the 0th tile instead so that + // user code doesn't have to check for NULL pointers all over + // the place + return tiles[0]; + } + } }; #endif Index: level.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- level.cpp 25 Mar 2004 02:27:45 -0000 1.13 +++ level.cpp 25 Mar 2004 10:26:07 -0000 1.14 @@ -10,6 +10,7 @@ // // +#include <map> #include <stdlib.h> #include <stdio.h> #include <string.h> @@ -300,54 +301,57 @@ // Convert old levels to the new tile numbers if (version == 0) { - int transtable[256]; - transtable[(int)'.'] = 0; - transtable[(int)'0'] = 0; - transtable[(int)'1'] = 1; - transtable[(int)'2'] = 2; - transtable[(int)'x'] = 77; - transtable[(int)'X'] = 77; - transtable[(int)'y'] = 78; - transtable[(int)'Y'] = 78; - transtable[(int)'A'] = 83; - transtable[(int)'B'] = 102; - transtable[(int)'!'] = 103; - transtable[(int)'a'] = 84; - transtable[(int)'C'] = 85; - transtable[(int)'D'] = 86; - transtable[(int)'E'] = 87; - transtable[(int)'F'] = 88; - transtable[(int)'c'] = 89; - transtable[(int)'d'] = 90; - transtable[(int)'e'] = 91; - transtable[(int)'f'] = 92; + std::map<char, int> transtable; + transtable['.'] = 0; + transtable['0'] = 0; + transtable['1'] = 1; + transtable['2'] = 2; + transtable['x'] = 77; + transtable['X'] = 77; + transtable['y'] = 78; + transtable['Y'] = 78; + transtable['A'] = 83; + transtable['B'] = 102; + transtable['!'] = 103; + transtable['a'] = 84; + transtable['C'] = 85; + transtable['D'] = 86; + transtable['E'] = 87; + transtable['F'] = 88; + transtable['c'] = 89; + transtable['d'] = 90; + transtable['e'] = 91; + transtable['f'] = 92; - transtable[(int)'G'] = 93; - transtable[(int)'H'] = 94; - transtable[(int)'I'] = 95; - transtable[(int)'J'] = 96; + transtable['G'] = 93; + transtable['H'] = 94; + transtable['I'] = 95; + transtable['J'] = 96; - transtable[(int)'g'] = 97; - transtable[(int)'h'] = 98; - transtable[(int)'i'] = 99; - transtable[(int)'j'] = 100 -; - transtable[(int)'#'] = 11; - transtable[(int)'['] = 13; - transtable[(int)'='] = 14; - transtable[(int)']'] = 15; - transtable[(int)'$'] = 82; - transtable[(int)'^'] = 76; - transtable[(int)'*'] = 80; - transtable[(int)'|'] = 79; - transtable[(int)'\\'] = 81; - transtable[(int)'&'] = 75; + transtable['g'] = 97; + transtable['h'] = 98; + transtable['i'] = 99; + transtable['j'] = 100 + ; + transtable['#'] = 11; + transtable['['] = 13; + transtable['='] = 14; + transtable[']'] = 15; + transtable['$'] = 82; + transtable['^'] = 76; + transtable['*'] = 80; + transtable['|'] = 79; + transtable['\\'] = 81; + transtable['&'] = 75; for(std::vector<int>::iterator i = ia_tm.begin(); i != ia_tm.end(); ++i) - if (*i < 256) - *i = transtable[*i]; - else - puts("Error: Value to high, conversion will fail"); + { + std::map<char, int>::iterator j = transtable.find(*i); + if (j != transtable.end()) + *i = j->second; + else + printf("Error: conversion will fail, unsupported char: '%c' (%d)\n", *i, *i); + } } } Index: tile.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/tile.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- tile.cpp 25 Mar 2004 02:27:45 -0000 1.3 +++ tile.cpp 25 Mar 2004 10:26:07 -0000 1.4 @@ -38,10 +38,8 @@ if (strcmp(lisp_symbol(lisp_car(element)), "tile") == 0) { - int id = 0; - std::vector<std::string> filenames; - - Tile* tile = new Tile; + Tile* tile = new Tile; + tile->id = -1; tile->solid = false; tile->brick = false; tile->ice = false; @@ -49,10 +47,12 @@ tile->distro = false; tile->data = 0; tile->alpha = 0; + tile->next_tile = 0; + tile->next_tile2 = 0; tile->anim_speed = 25; LispReader reader(lisp_cdr(element)); - reader.read_int("id", &id); + assert(reader.read_int("id", &tile->id)); reader.read_bool("solid", &tile->solid); reader.read_bool("brick", &tile->brick); reader.read_bool("ice", &tile->ice); @@ -61,9 +61,13 @@ reader.read_int("data", (int*)&tile->data); reader.read_int("alpha", (int*)&tile->alpha); reader.read_int("anim-speed", &tile->anim_speed); - reader.read_string_vector("images", &filenames); + reader.read_int("next-tile", &tile->next_tile); + reader.read_int("next-tile2", &tile->next_tile2); + reader.read_string_vector("images", &tile->filenames); - for(std::vector<std::string>::iterator it = filenames.begin(); it != filenames.end(); ++it) + for(std::vector<std::string>::iterator it = tile->filenames.begin(); + it != tile->filenames.end(); + ++it) { texture_type cur_image; tile->images.push_back(cur_image); @@ -72,10 +76,10 @@ USE_ALPHA); } - if (id+tileset_id >= int(tiles.size())) - tiles.resize(id+tileset_id+1); + if (tile->id + tileset_id >= int(tiles.size())) + tiles.resize(tile->id + tileset_id+1); - tiles[id+tileset_id] = tile; + tiles[tile->id + tileset_id] = tile; } else if (strcmp(lisp_symbol(lisp_car(element)), "tileset") == 0) { Index: gameloop.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.cpp,v retrieving revision 1.25 retrieving revision 1.26 diff -u -d -r1.25 -r1.26 --- gameloop.cpp 25 Mar 2004 02:27:45 -0000 1.25 +++ gameloop.cpp 25 Mar 2004 10:26:07 -0000 1.26 @@ -1327,10 +1327,14 @@ { texture_draw(&ptile->images[( ((global_frame_counter*25) / ptile->anim_speed) % (ptile->images.size()))],x,y); } - else + else if (ptile->images.size() == 1) { texture_draw(&ptile->images[0],x,y); } + else + { + printf("Tile not dravable %u\n", c); + } } } @@ -1508,12 +1512,12 @@ void trybreakbrick(float x, float y) { - if (isbrick(x, y)) + Tile* tile = gettile(x, y); + if (tile->brick) { - if (shape(x, y) == 'x' || shape(x, y) == 'y') + if (tile->data > 0) { /* Get a distro from it: */ - add_bouncy_distro(((int)(x + 1) / 32) * 32, (int)(y / 32) * 32); @@ -1524,7 +1528,7 @@ } if (distro_counter <= 0) - level_change(¤t_level,x, y, TM_IA, 'a'); + level_change(¤t_level,x, y, TM_IA, tile->next_tile2); play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER); score = score + SCORE_DISTRO; @@ -1533,8 +1537,7 @@ else { /* Get rid of it: */ - - level_change(¤t_level,x, y, TM_IA, '.'); + level_change(¤t_level,x, y, TM_IA, tile->next_tile); } @@ -1568,7 +1571,8 @@ void tryemptybox(float x, float y, int col_side) { - if (!isfullbox(x, y)) + Tile* tile = gettile(x,y); + if (!tile->fullbox) return; // according to the collision side, set the upgrade direction @@ -1579,7 +1583,7 @@ col_side = LEFT; // FIXME: Content of boxes must be handled otherwise - switch(gettile(x,y)->data) + switch(tile->data) { case 1: //'A': /* Box with a distro! */ add_bouncy_distro(((int)(x + 1) / 32) * 32, (int)(y / 32) * 32 - 32); @@ -1602,7 +1606,7 @@ } /* Empty the box: */ - level_change(¤t_level,x, y, TM_IA, 'a'); + level_change(¤t_level,x, y, TM_IA, tile->next_tile); } @@ -1613,7 +1617,7 @@ Tile* tile = gettile(x, y); if (tile && tile->distro) { - level_change(¤t_level,x, y, TM_IA, '.'); + level_change(¤t_level,x, y, TM_IA, tile->next_tile); play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER); if (bounciness == BOUNCE) |