[Super-tux-commit] supertux/src camera.h,1.8,1.9 defines.h,1.46,1.47 gameobjs.cpp,1.39,1.40 gameobjs
Brought to you by:
wkendrick
From: Ingo R. <gr...@us...> - 2004-06-14 22:08:12
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13723 Modified Files: camera.h defines.h gameobjs.cpp gameobjs.h leveleditor.cpp lispwriter.h sector.cpp tile.cpp tile.h tilemap.cpp tilemap.h Log Message: - fixed the bouncybrick artifact bug - replaced plain tile-id integer with a hopefully lightwight struct - replaced a few Tile* with Tile& to make it more clear that Tilemap::get() always returns a valid tile - added support for (grid x y width height) for the .stgt file format, can be used to load multiple tiles from a single image Index: tile.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/tile.h,v retrieving revision 1.27 retrieving revision 1.28 diff -u -d -r1.27 -r1.28 --- tile.h 9 Jun 2004 05:23:20 -0000 1.27 +++ tile.h 14 Jun 2004 22:08:01 -0000 1.28 @@ -141,17 +141,18 @@ const Vector& pos, int layer); static std::set<TileGroup>* tilegroups() { if(!instance_) { instance_ = new TileManager(); } return tilegroups_ ? tilegroups_ : tilegroups_ = new std::set<TileGroup>; } - Tile* get(unsigned int id) { + Tile& get(unsigned int id) { + if(id < tiles.size()) { - return tiles[id]; + 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]; + return *tiles[0]; } } }; Index: sector.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/sector.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- sector.cpp 13 Jun 2004 17:54:28 -0000 1.9 +++ sector.cpp 14 Jun 2004 22:08:01 -0000 1.10 @@ -18,6 +18,7 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include <memory> +#include <algorithm> #include <stdexcept> #include <iostream> #include <fstream> @@ -761,7 +762,7 @@ throw SuperTuxException(errmsg, __FILE__, __LINE__); */ //Bad tiles (i.e. tiles that are not defined in supertux.stgt but appear in the map) are changed to ID 0 (blank tile) - std::cout << "Warning: Undefined tile at " <<(int)pos.x/32 << "/" << (int)pos.y/32 << " (ID: " << (int)solids->get_tile_id_at(pos) << ")" << std::endl; + std::cout << "Warning: Undefined tile at " <<(int)pos.x/32 << "/" << (int)pos.y/32 << " (ID: " << (int)solids->get_tile_id_at(pos).id << ")" << std::endl; solids->change_at(pos,0); tile = solids->get_tile_at(pos); } Index: lispwriter.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/lispwriter.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- lispwriter.h 9 Jun 2004 05:23:20 -0000 1.4 +++ lispwriter.h 14 Jun 2004 22:08:01 -0000 1.5 @@ -21,6 +21,7 @@ #define SUPERTUX_LISPWRITER_H #include <iostream> +#include <string> #include <vector> class LispWriter Index: gameobjs.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameobjs.h,v retrieving revision 1.26 retrieving revision 1.27 diff -u -d -r1.26 -r1.27 --- gameobjs.h 31 May 2004 02:40:30 -0000 1.26 +++ gameobjs.h 14 Jun 2004 22:08:01 -0000 1.27 @@ -37,6 +37,8 @@ #define NO_BOUNCE 0 #define BOUNCE 1 +struct TileId; + class BouncyDistro : public GameObject { public: @@ -82,7 +84,7 @@ Vector position; float offset; float offset_m; - int shape; + TileId& shape; }; class FloatingScore : public GameObject Index: tilemap.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/tilemap.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- tilemap.h 9 Jun 2004 05:23:20 -0000 1.7 +++ tilemap.h 14 Jun 2004 22:08:01 -0000 1.8 @@ -31,6 +31,15 @@ class LispReader; class Tile; +struct TileId +{ + TileId() : id(0), hidden(0) {} + explicit TileId(unsigned int i, bool hidden_ = false) : id(i), hidden(hidden_) {} + + unsigned id :31; + unsigned hidden :1; +}; + /** * This class is reponsible for drawing the level tiles */ @@ -63,7 +72,7 @@ bool is_solid() const { return solid; } - unsigned int get_tile_id_at(const Vector& pos) const; + TileId& get_tile_id_at(const Vector& pos); /// returns tile in row y and column y (of the tilemap) Tile* get_tile(int x, int y) const; @@ -74,8 +83,8 @@ void change_at(const Vector& pos, unsigned int newtile); -public: - std::vector<unsigned int> tiles; +private: + std::vector<TileId> tiles; private: TileManager* tilemanager; Index: defines.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/defines.h,v retrieving revision 1.46 retrieving revision 1.47 diff -u -d -r1.46 -r1.47 --- defines.h 13 Jun 2004 21:48:16 -0000 1.46 +++ defines.h 14 Jun 2004 22:08:01 -0000 1.47 @@ -118,5 +118,7 @@ #define DEBUG_MSG( msg ) {} #endif +#define UNUSED_ARG(a) do {/* null */} while (&a == 0) + #endif /*SUPERTUX_DEFINES_H*/ Index: tilemap.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/tilemap.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- tilemap.cpp 9 Jun 2004 05:23:20 -0000 1.9 +++ tilemap.cpp 14 Jun 2004 22:08:01 -0000 1.10 @@ -65,9 +65,19 @@ if(!reader.read_int("width", width) || !reader.read_int("height", height)) throw std::runtime_error("No width or height specified in tilemap."); + + std::vector<unsigned int> tmp_tiles; - if(!reader.read_int_vector("tiles", tiles)) + if(!reader.read_int_vector("tiles", tmp_tiles)) throw std::runtime_error("No tiles in tilemap."); + + tiles.resize(tmp_tiles.size()); + for(unsigned int i = 0; i < tmp_tiles.size(); ++i) + { + tiles[i].hidden = false; + tiles[i].id = tmp_tiles[i]; + } + if(int(tiles.size()) != width*height) throw std::runtime_error("wrong number of tiles in tilemap."); } @@ -95,7 +105,14 @@ writer.write_float("speed", speed); writer.write_int("width", width); writer.write_int("height", height); - writer.write_int_vector("tiles", tiles); + + std::vector<unsigned int> tmp_tiles; + tmp_tiles.resize(tiles.size()); + for(unsigned int i = 0; i < tmp_tiles.size(); ++i) + { + tmp_tiles[i] = tiles[i].id; + } + writer.write_int_vector("tiles", tmp_tiles); writer.end_list("tilemap"); } @@ -123,7 +140,8 @@ int tx, ty; for(pos.x = start_x, tx = tsx; pos.x < end_x; pos.x += 32, ++tx) { for(pos.y = start_y, ty = tsy; pos.y < end_y; pos.y += 32, ++ty) { - tilemanager->draw_tile(context, tiles[ty*width + tx], pos, layer); + if (!tiles[ty*width + tx].hidden) + tilemanager->draw_tile(context, tiles[ty*width + tx].id, pos, layer); } } } @@ -134,11 +152,18 @@ { assert(int(newt.size()) == newwidth * newheight); - width = newwidth; + width = newwidth; height = newheight; - tiles = newt; - layer = newlayer; - solid = newsolid; + + tiles.resize(newt.size()); + for(unsigned int i = 0; i < newt.size(); ++i) + { + tiles[i].hidden = false; + tiles[i].id = newt[i]; + } + + layer = newlayer; + solid = newsolid; } void @@ -160,7 +185,7 @@ for(int y = std::min(height, new_height)-1; y >= 0; --y) { for(int x = new_width-1; x >= 0; --x) { if(x >= width) { - tiles[y * new_width + x] = 0; + tiles[y * new_width + x] = TileId(); } else { tiles[y * new_width + x] = tiles[y * width + x]; } @@ -176,9 +201,9 @@ TileMap::get_tile(int x, int y) const { if(x < 0 || x >= width || y < 0 || y >= height) - return tilemanager->get(0); + return &tilemanager->get(0); - return tilemanager->get(tiles[y*width + x]); + return &tilemanager->get(tiles[y*width + x].id); } Tile* @@ -187,11 +212,12 @@ return get_tile(int(pos.x)/32, int(pos.y)/32); } -unsigned int -TileMap::get_tile_id_at(const Vector& pos) const +TileId& +TileMap::get_tile_id_at(const Vector& pos) { int x = int(pos.x)/32; int y = int(pos.y)/32; + return tiles[y*width + x]; } @@ -199,7 +225,7 @@ TileMap::change(int x, int y, unsigned int newtile) { assert(x >= 0 && x < width && y >= 0 && y < height); - tiles[y*width + x] = newtile; + tiles[y*width + x].id = newtile; } void Index: leveleditor.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/leveleditor.cpp,v retrieving revision 1.137 retrieving revision 1.138 diff -u -d -r1.137 -r1.138 --- leveleditor.cpp 9 Jun 2004 05:23:19 -0000 1.137 +++ leveleditor.cpp 14 Jun 2004 22:08:01 -0000 1.138 @@ -491,7 +491,7 @@ for(std::vector<int>::const_iterator sit = (*it).tiles.begin(); sit != (*it).tiles.end(); ++sit, ++i) { - Tile& tile = *(TileManager::instance()->get(*sit)); + Tile& tile = TileManager::instance()->get(*sit); Surface* image; if(tile.editor_images.size() > 0) image = tile.editor_images[0]; Index: gameobjs.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameobjs.cpp,v retrieving revision 1.39 retrieving revision 1.40 diff -u -d -r1.39 -r1.40 --- gameobjs.cpp 9 Jun 2004 05:23:19 -0000 1.39 +++ gameobjs.cpp 14 Jun 2004 22:08:01 -0000 1.40 @@ -80,9 +80,10 @@ } BouncyBrick::BouncyBrick(const Vector& pos) - : position(pos), offset(0), offset_m(-BOUNCY_BRICK_SPEED) -{ - shape = Sector::current()->solids->get_tile_id_at(pos); + : position(pos), offset(0), offset_m(-BOUNCY_BRICK_SPEED), + shape(Sector::current()->solids->get_tile_id_at(pos)) +{ + shape.hidden = true; } void @@ -96,14 +97,17 @@ /* Stop bouncing? */ if (offset >= 0) - remove_me(); + { + shape.hidden = false; + remove_me(); + } } void BouncyBrick::draw(DrawingContext& context) { TileManager::instance()-> - draw_tile(context, shape, position + Vector(0, offset), LAYER_TILES+1); + draw_tile(context, shape.id, position + Vector(0, offset), LAYER_TILES+1); } FloatingScore::FloatingScore(const Vector& pos, int score) Index: camera.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/camera.h,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- camera.h 9 Jun 2004 05:23:20 -0000 1.8 +++ camera.h 14 Jun 2004 22:08:01 -0000 1.9 @@ -23,6 +23,7 @@ #include <vector> #include <cassert> +#include "defines.h" #include "vector.h" #include "game_object.h" #include "serializable.h" @@ -51,7 +52,7 @@ virtual void draw(DrawingContext& context) { - (void) context; + UNUSED_ARG(context); } void set_scrolling(int scroll_x, int scroll_y) Index: tile.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/tile.cpp,v retrieving revision 1.28 retrieving revision 1.29 diff -u -d -r1.28 -r1.29 --- tile.cpp 9 Jun 2004 19:15:22 -0000 1.28 +++ tile.cpp 14 Jun 2004 22:08:01 -0000 1.29 @@ -84,13 +84,27 @@ std::vector<std::string> editor_filenames; reader.read_string_vector("editor-images", editor_filenames); + std::vector<int> grid; + reader.read_int_vector("grid", grid); + // read images for(std::vector<std::string>::iterator i = filenames.begin(); - i != filenames.end(); ++i) { - Surface* surface - = new Surface(datadir + "/images/tilesets/" + *i, USE_ALPHA); - images.push_back(surface); - } + i != filenames.end(); ++i) + { + if (grid.size() == 4) + { + Surface* surface = new Surface(datadir + "/images/tilesets/" + *i, + grid[0], grid[1], grid[2], grid[3], + USE_ALPHA); + images.push_back(surface); + } + else + { + Surface* surface = new Surface(datadir + "/images/tilesets/" + *i, USE_ALPHA); + images.push_back(surface); + } + } + for(std::vector<std::string>::iterator i = editor_filenames.begin(); i != editor_filenames.end(); ++i) { Surface* surface @@ -210,22 +224,20 @@ if(c == 0) return; - Tile* tile = get(c); - if(!tile) - return; + Tile& tile = get(c); - if(!tile->images.size()) + if(!tile.images.size()) return; - if(tile->images.size() > 1) + if(tile.images.size() > 1) { size_t frame - = ((global_frame_counter*25) / tile->anim_speed) % tile->images.size(); - context.draw_surface(tile->images[frame], pos, layer); + = ((global_frame_counter*25) / tile.anim_speed) % tile.images.size(); + context.draw_surface(tile.images[frame], pos, layer); } - else if (tile->images.size() == 1) + else if (tile.images.size() == 1) { - context.draw_surface(tile->images[0], pos, layer); + context.draw_surface(tile.images[0], pos, layer); } } |