[Super-tux-commit] supertux/src/object background.cpp,1.1,1.2 background.h,1.1,1.2 camera.cpp,1.1,1.
Brought to you by:
wkendrick
From: Matze B. <mat...@us...> - 2004-11-28 14:57:06
|
Update of /cvsroot/super-tux/supertux/src/object In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13367/src/object Modified Files: background.cpp background.h camera.cpp camera.h gameobjs.cpp gameobjs.h particlesystem.cpp particlesystem.h platform.cpp platform.h tilemap.cpp tilemap.h Log Message: move over rewritten lispreader from tuxkart (with additional fixes), generalized TileManager and Tile classes and use them for the worldmap too Index: platform.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/platform.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- platform.cpp 23 Nov 2004 16:47:26 -0000 1.2 +++ platform.cpp 28 Nov 2004 14:56:51 -0000 1.3 @@ -5,14 +5,15 @@ #include "resources.h" #include "player.h" #include "special/sprite_manager.h" -#include "utils/lispreader.h" +#include "lisp/lisp.h" +#include "lisp/writer.h" -Platform::Platform(LispReader& reader) +Platform::Platform(const lisp::Lisp& reader) { sprite = sprite_manager->create("flying_platform"); movement = Vector(0, 1); - reader.read_float("x", bbox.p1.x); - reader.read_float("y", bbox.p1.y); + reader.get("x", bbox.p1.x); + reader.get("y", bbox.p1.y); bbox.set_size(sprite->get_width(), sprite->get_height()); flags |= FLAG_SOLID; Index: background.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/background.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- background.cpp 26 Nov 2004 14:45:41 -0000 1.1 +++ background.cpp 28 Nov 2004 14:56:51 -0000 1.2 @@ -23,25 +23,26 @@ #include "app/globals.h" #include "camera.h" #include "video/drawing_context.h" -#include "utils/lispwriter.h" +#include "lisp/lisp.h" +#include "lisp/writer.h" Background::Background() : type(INVALID), layer(LAYER_BACKGROUND0), image(0) { } -Background::Background(LispReader& reader) +Background::Background(const lisp::Lisp& reader) : type(INVALID), layer(LAYER_BACKGROUND0), image(0) { - reader.read_int("layer", layer); - if(reader.read_string("image", imagefile) - && reader.read_float("speed", speed)) { + reader.get("layer", layer); + if(reader.get("image", imagefile) + && reader.get("speed", speed)) { set_image(imagefile, speed); } std::vector <unsigned int> bkgd_top_color, bkgd_bottom_color; - if(reader.read_int_vector("top_color", bkgd_top_color) && - reader.read_int_vector("bottom_color", bkgd_bottom_color)) + if(reader.get_vector("top_color", bkgd_top_color) && + reader.get_vector("bottom_color", bkgd_bottom_color)) set_gradient(Color(bkgd_top_color), Color(bkgd_bottom_color)); } @@ -51,7 +52,7 @@ } void -Background::write(LispWriter& writer) +Background::write(lisp::Writer& writer) { if(type == INVALID) return; Index: particlesystem.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/particlesystem.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- particlesystem.cpp 26 Nov 2004 14:45:41 -0000 1.1 +++ particlesystem.cpp 28 Nov 2004 14:56:51 -0000 1.2 @@ -25,9 +25,10 @@ #include "particlesystem.h" #include "app/globals.h" -#include "utils/lispreader.h" -#include "utils/lispwriter.h" #include "video/drawing_context.h" +#include "lisp/parser.h" +#include "lisp/lisp.h" +#include "lisp/writer.h" ParticleSystem::ParticleSystem() { @@ -97,13 +98,13 @@ } void -SnowParticleSystem::parse(LispReader& reader) +SnowParticleSystem::parse(const lisp::Lisp& reader) { - reader.read_int("layer", layer); + reader.get("layer", layer); } void -SnowParticleSystem::write(LispWriter& writer) +SnowParticleSystem::write(lisp::Writer& writer) { writer.start_list("particles-snow"); writer.write_int("layer", layer); @@ -148,13 +149,13 @@ } void -CloudParticleSystem::parse(LispReader& reader) +CloudParticleSystem::parse(const lisp::Lisp& reader) { - reader.read_int("layer", layer); + reader.get("layer", layer); } void -CloudParticleSystem::write(LispWriter& writer) +CloudParticleSystem::write(lisp::Writer& writer) { writer.start_list("particles-clouds"); writer.write_int("layer", layer); Index: tilemap.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/tilemap.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- tilemap.cpp 26 Nov 2004 14:45:41 -0000 1.1 +++ tilemap.cpp 28 Nov 2004 14:56:52 -0000 1.2 @@ -28,29 +28,30 @@ #include "video/drawing_context.h" #include "level.h" #include "tile.h" +#include "resources.h" #include "tile_manager.h" #include "app/globals.h" -#include "utils/lispreader.h" -#include "utils/lispwriter.h" +#include "lisp/lisp.h" +#include "lisp/writer.h" TileMap::TileMap() : solid(false), speed(1), width(0), height(0), layer(LAYER_TILES), vertical_flip(false) { - tilemanager = TileManager::instance(); + tilemanager = tile_manager; if(solid) flags |= FLAG_SOLID; } -TileMap::TileMap(LispReader& reader) +TileMap::TileMap(const lisp::Lisp& reader) : solid(false), speed(1), width(0), height(0), layer(LAYER_TILES), vertical_flip(false) { - tilemanager = TileManager::instance(); + tilemanager = tile_manager; std::string layer_str; - if(reader.read_string("layer", layer_str)) { + if(reader.get("layer", layer_str)) { if(layer_str == "background") layer = LAYER_BACKGROUNDTILES; else if(layer_str == "interactive") @@ -61,8 +62,8 @@ std::cerr << "Unknown layer '" << layer_str << "' in tilemap.\n"; } - reader.read_bool("solid", solid); - reader.read_float("speed", speed); + reader.get("solid", solid); + reader.get("speed", speed); if(solid && speed != 1) { std::cout << "Speed of solid tilemap is not 1. fixing.\n"; @@ -71,22 +72,23 @@ if(solid) flags |= FLAG_SOLID; - if(!reader.read_int("width", width) || - !reader.read_int("height", height)) + if(!reader.get("width", width) || + !reader.get("height", height)) throw std::runtime_error("No width or height specified in tilemap."); - if(!reader.read_int_vector("tiles", tiles)) + if(!reader.get_vector("tiles", tiles)) throw std::runtime_error("No tiles in tilemap."); - if(int(tiles.size()) != width*height) + if(int(tiles.size()) != width*height) { throw std::runtime_error("wrong number of tiles in tilemap."); + } } TileMap::TileMap(int layer_, bool solid_, size_t width_, size_t height_) : solid(solid_), speed(1), width(0), height(0), layer(layer_), vertical_flip(false) { - tilemanager = TileManager::instance(); + tilemanager = tile_manager; resize(width_, height_); @@ -99,7 +101,7 @@ } void -TileMap::write(LispWriter& writer) +TileMap::write(lisp::Writer& writer) { writer.start_list("tilemap"); @@ -182,7 +184,8 @@ TileMap::set(int newwidth, int newheight, const std::vector<unsigned int>&newt, int newlayer, bool newsolid) { - assert(int(newt.size()) == newwidth * newheight); + if(int(newt.size()) != newwidth * newheight) + throw std::runtime_error("Wrong tilecount count."); width = newwidth; height = newheight; Index: background.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/background.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- background.h 26 Nov 2004 14:45:41 -0000 1.1 +++ background.h 28 Nov 2004 14:56:51 -0000 1.2 @@ -23,19 +23,22 @@ #include "video/surface.h" #include "video/drawing_context.h" #include "special/game_object.h" -#include "utils/lispreader.h" #include "serializable.h" class DisplayManager; +namespace lisp { +class Lisp; +} + class Background : public GameObject, public Serializable { public: Background(); - Background(LispReader& reader); + Background(const lisp::Lisp& reader); virtual ~Background(); - virtual void write(LispWriter& writer); + virtual void write(lisp::Writer& writer); void set_image(const std::string& name, float bkgd_speed); Index: gameobjs.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/gameobjs.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- gameobjs.h 26 Nov 2004 14:45:41 -0000 1.1 +++ gameobjs.h 28 Nov 2004 14:56:51 -0000 1.2 @@ -18,7 +18,6 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA // 02111-1307, USA. - #ifndef SUPERTUX_GAMEOBJS_H #define SUPERTUX_GAMEOBJS_H @@ -29,7 +28,6 @@ #include "special/game_object.h" #include "special/moving_object.h" #include "serializable.h" -#include "utils/lispwriter.h" /* Bounciness of distros: */ #define NO_BOUNCE 0 @@ -84,31 +82,6 @@ Timer2 timer; }; -#if 0 -extern Sprite *img_trampoline; - -class Trampoline : public MovingObject, public Serializable -{ -public: - Trampoline(LispReader& reader); - Trampoline(float x, float y); - - virtual void write(LispWriter& writer); - virtual void action(float frame_ratio); - virtual void draw(DrawingContext& context); - - virtual void collision(const MovingObject& other, int); - void collision(void *p_c_object, int c_object, CollisionType type); - - Physic physic; - enum { M_NORMAL, M_HELD } mode; - - private: - float power; - unsigned int frame; -}; -#endif - extern Sprite *img_smoke_cloud; class SmokeCloud : public GameObject Index: platform.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/platform.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- platform.h 20 Nov 2004 22:14:40 -0000 1.1 +++ platform.h 28 Nov 2004 14:56:51 -0000 1.2 @@ -12,7 +12,7 @@ class Platform : public SuperTux::MovingObject { public: - Platform(LispReader& reader); + Platform(const lisp::Lisp& reader); ~Platform(); virtual HitResponse collision(GameObject& other, const CollisionHit& hit); Index: tilemap.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/tilemap.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- tilemap.h 26 Nov 2004 14:45:41 -0000 1.1 +++ tilemap.h 28 Nov 2004 14:56:52 -0000 1.2 @@ -27,12 +27,12 @@ #include "serializable.h" #include "math/vector.h" -using namespace SuperTux; - -namespace SuperTux { -class LispReader; +namespace lisp { +class Lisp; } +using namespace SuperTux; + class Level; class TileManager; class Tile; @@ -44,11 +44,11 @@ { public: TileMap(); - TileMap(LispReader& reader); + TileMap(const lisp::Lisp& reader); TileMap(int layer_, bool solid_, size_t width_, size_t height_); virtual ~TileMap(); - virtual void write(LispWriter& writer); + virtual void write(lisp::Writer& writer); virtual void action(float elapsed_time); virtual void draw(DrawingContext& context); Index: camera.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/camera.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- camera.h 26 Nov 2004 14:45:41 -0000 1.1 +++ camera.h 28 Nov 2004 14:56:51 -0000 1.2 @@ -30,9 +30,8 @@ #include "serializable.h" using namespace SuperTux; - -namespace SuperTux { -class LispReader; +namespace lisp { +class Lisp; } class Sector; @@ -44,9 +43,9 @@ virtual ~Camera(); /// parse camera mode from lisp file - void parse(LispReader& reader); + void parse(const lisp::Lisp& reader); /// write camera mode to a lisp file - virtual void write(LispWriter& writer); + virtual void write(lisp::Writer& writer); /// reset camera postion virtual void reset(const Vector& tuxpos); Index: gameobjs.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/gameobjs.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- gameobjs.cpp 26 Nov 2004 14:45:41 -0000 1.1 +++ gameobjs.cpp 28 Nov 2004 14:56:51 -0000 1.2 @@ -146,289 +146,6 @@ context.pop_transform(); } -/* Trampoline */ - -#if 0 -Sprite *img_trampoline; - -Trampoline::Trampoline(LispReader& reader) -{ - reader.read_float("x", base.x); - reader.read_float("y", base.y); - base.width = 32; - base.height = 32; - power = 7.5; - reader.read_float("power", power); - - frame = 0; - mode = M_NORMAL; - physic.reset(); -} - -Trampoline::Trampoline(float x, float y) -{ - base.x = x; - base.y = y; - base.width = 32; - base.height = 32; - power = 7.5; - - frame = 0; - mode = M_NORMAL; - physic.reset(); -} - -void -Trampoline::write(LispWriter& writer) -{ - writer.start_list("trampoline"); - - writer.write_float("x", base.x); - writer.write_float("y", base.y); - writer.write_float("power", power); - - writer.end_list("trampoline"); -} - -void -Trampoline::draw(DrawingContext& context) -{ - img_trampoline->set_frame(frame); - img_trampoline->draw(context, base, LAYER_OBJECTS); - frame = 0; -} - -void -Trampoline::action(float frame_ratio) -{ - // TODO: Remove if we're too far off the screen - - // Falling - if (mode != M_HELD) - { - if (issolid(base.x + base.width/2, base.y + base.height)) - { - base.y = int((base.y + base.height)/32) * 32 - base.height; - - physic.enable_gravity(false); - physic.set_velocity_y(0.0f); - - physic.set_velocity_x(0); - } - else - { - physic.enable_gravity(true); - } - } - else // Player is carrying us around - { - /* FIXME: The trampoline object shouldn't know about pplayer objects. */ - /* If we're holding the iceblock */ - Player& tux = *Sector::current()->player; - Direction dir = tux.dir; - - if(dir == RIGHT) - { - base.x = tux.base.x + 16; - base.y = tux.base.y + tux.base.height/1.5 - base.height; - } - else /* facing left */ - { - base.x = tux.base.x - 16; - base.y = tux.base.y + tux.base.height/1.5 - base.height; - } - - if(collision_object_map(base)) - { - base.x = tux.base.x; - base.y = tux.base.y + tux.base.height/1.5 - base.height; - } - } - - physic.apply(frame_ratio, base.x, base.y, Sector::current()->gravity); - collision_swept_object_map(&old_base, &base); -} - -void -Trampoline::collision(const MovingObject&, int) -{ - // comes later -} - -void -Trampoline::collision(void *p_c_object, int c_object, CollisionType type) -{ - Player* pplayer_c = NULL; - switch (c_object) - { - case CO_PLAYER: - pplayer_c = (Player*) p_c_object; - - if (type == COLLISION_NORMAL) - { - // Pick up if HELD (done in Player) - } - - else if (type == COLLISION_SQUISH) - { - int squish_amount = (32 - (int)pplayer_c->base.y % 32); - - if (squish_amount < 24) - frame = 3; - else if (squish_amount < 28) - frame = 2; - else if (squish_amount < 30) - frame = 1; - else - frame = 0; - - if (squish_amount < 20) { - pplayer_c->physic.set_velocity_y(power); - pplayer_c->fall_mode = Player::TRAMPOLINE_JUMP; - } - else if (pplayer_c->physic.get_velocity_y() < 0) - pplayer_c->physic.set_velocity_y(-squish_amount/32); - } - - break; - - default: - break; - - } -} -#endif - -/* Flying Platform */ - -#if 0 -Sprite *img_flying_platform; - -FlyingPlatform::FlyingPlatform(LispReader& reader) -{ - reader.read_int_vector("x", pos_x); - reader.read_int_vector("y", pos_y); - - velocity = 2.0; - reader.read_float("velocity", velocity); - - base.x = pos_x[0]; - base.y = pos_y[0]; - base.width = 96; - base.height = 40; - - point = 0; - move = false; - - float x = pos_x[point+1] - pos_x[point]; - float y = pos_y[point+1] - pos_y[point]; - vel_x = x*velocity / sqrt(x*x + y*y); - vel_y = -(velocity - vel_x); - - frame = 0; -} - -FlyingPlatform::FlyingPlatform(int x, int y) -{ -base.x = x; -base.y = y; -point = 0; -move = false; -} - -void -FlyingPlatform::write(LispWriter& writer) -{ - writer.start_list("flying-trampoline"); - - writer.write_int_vector("x", pos_x); - writer.write_int_vector("y", pos_y); - writer.write_float("velocity", velocity); - - writer.end_list("flying-trampoline"); -} - -void -FlyingPlatform::draw(DrawingContext& context) -{ - img_flying_platform->draw(context, base, LAYER_OBJECTS); -} - -void -FlyingPlatform::action(float frame_ratio) -{ - // TODO: Remove if we're too far off the screen - -if(!move) - return; - -if((unsigned)point+1 != pos_x.size()) - { - if(((pos_x[point+1] > pos_x[point] && base.x >= pos_x[point+1]) || - (pos_x[point+1] < pos_x[point] && base.x <= pos_x[point+1]) || - pos_x[point] == pos_x[point+1]) && - ((pos_y[point+1] > pos_y[point] && base.y >= pos_y[point+1]) || - (pos_y[point+1] < pos_y[point] && base.y <= pos_y[point+1]) || - pos_y[point] == pos_y[point+1])) - { - point++; - - float x = pos_x[point+1] - pos_x[point]; - float y = pos_y[point+1] - pos_y[point]; - vel_x = x*velocity / sqrt(x*x + y*y); - vel_y = -(velocity - vel_x); - } - } -else // last point - { - // point = 0; - // reverse vector - return; - } -/* -if(pos_x[point+1] > base.x) - base.x += velocity * frame_ratio; -else if(pos_x[point+1] < base.x) - base.x -= velocity * frame_ratio; - -if(pos_y[point+1] > base.y) - base.y += velocity * frame_ratio; -else if(pos_y[point+1] < base.y) - base.y -= velocity * frame_ratio; -*/ - -base.x += vel_x * frame_ratio; -base.y += vel_y * frame_ratio; -} - -void -FlyingPlatform::collision(const MovingObject&, int) -{ - // comes later -} - -void -FlyingPlatform::collision(void *p_c_object, int c_object, CollisionType type) -{ -(void) p_c_object; -(void) type; - -// Player* pplayer_c = NULL; - switch (c_object) - { - case CO_PLAYER: -// pplayer_c = (Player*) p_c_object; - move = true; - - break; - - default: - break; - - } -} -#endif - Sprite *img_smoke_cloud = 0; SmokeCloud::SmokeCloud(const Vector& pos) Index: camera.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/camera.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- camera.cpp 26 Nov 2004 14:45:41 -0000 1.1 +++ camera.cpp 28 Nov 2004 14:56:51 -0000 1.2 @@ -23,9 +23,10 @@ #include <sstream> #include <cmath> +#include "lisp/lisp.h" +#include "lisp/writer.h" +#include "lisp/list_iterator.h" #include "camera.h" -#include "utils/lispreader.h" -#include "utils/lispwriter.h" #include "player.h" #include "tilemap.h" #include "gameloop.h" @@ -52,43 +53,41 @@ } void -Camera::parse(LispReader& reader) +Camera::parse(const lisp::Lisp& reader) { std::string modename; - reader.read_string("mode", modename); + reader.get("mode", modename); if(modename == "normal") { mode = NORMAL; do_backscrolling = true; - reader.read_bool("backscrolling", do_backscrolling); + reader.get("backscrolling", do_backscrolling); } else if(modename == "autoscroll") { mode = AUTOSCROLL; - lisp_object_t* cur = 0; - reader.read_lisp("path", cur); - if(cur == 0) { + const lisp::Lisp* path_lisp = reader.get_lisp("path"); + if(!path_lisp) throw std::runtime_error("No path specified in autoscroll camera."); - } - float speed = 50; - while(!lisp_nil_p(cur)) { - if(strcmp(lisp_symbol(lisp_car(lisp_car(cur))), "point") != 0) { - std::cerr << "Warning: unknown token in camera path.\n"; + + lisp::ListIterator iter(path_lisp); + float speed = .5; + while(iter.next()) { + if(iter.item() != "point") { + std::cerr << "Warning: unknown token '" << iter.item() + << "' in camera path.\n"; continue; } - - LispReader reader(lisp_cdr(lisp_car(cur))); + const lisp::Lisp* point_lisp = iter.lisp(); ScrollPoint point; - if(!reader.read_float("x", point.position.x) || - !reader.read_float("y", point.position.y)) { + if(!point_lisp->get("x", point.position.x) || + !point_lisp->get("y", point.position.y)) { throw std::runtime_error("x and y missing in point of camerapath"); } - reader.read_float("speed", speed); + point_lisp->get("speed", speed); point.speed = speed; scrollpoints.push_back(point); - - cur = lisp_cdr(cur); } } else if(modename == "manual") { mode = MANUAL; @@ -100,7 +99,7 @@ } void -Camera::write(LispWriter& writer) +Camera::write(lisp::Writer& writer) { writer.start_list("camera"); Index: particlesystem.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/particlesystem.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- particlesystem.h 26 Nov 2004 14:45:41 -0000 1.1 +++ particlesystem.h 28 Nov 2004 14:56:51 -0000 1.2 @@ -28,8 +28,8 @@ using namespace SuperTux; -namespace SuperTux { -class LispReader; +namespace lisp { +class Lisp; } class DisplayManager; @@ -80,8 +80,8 @@ SnowParticleSystem(); virtual ~SnowParticleSystem(); - void parse(LispReader& reader); - void write(LispWriter& writer); + void parse(const lisp::Lisp& lisp); + void write(lisp::Writer& writer); virtual void action(float elapsed_time); @@ -104,8 +104,8 @@ CloudParticleSystem(); virtual ~CloudParticleSystem(); - void parse(LispReader& reader); - void write(LispWriter& writer); + void parse(const lisp::Lisp& lisp); + void write(lisp::Writer& writer); virtual void action(float elapsed_time); |