From: Christoph Sommer Date: Wed, 22 Mar 2006 12:51:22 +0000 (+0000) Subject: autoscoll Camera now references Path, just like the Platform does X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=6e5fcfe8493510de0950745163690819f2b2cd90;p=supertux.git autoscoll Camera now references Path, just like the Platform does SVN-Revision: 3112 --- diff --git a/data/levels/bonus1/wansti-level3.stl b/data/levels/bonus1/wansti-level3.stl index 8a2716270..182312998 100644 --- a/data/levels/bonus1/wansti-level3.stl +++ b/data/levels/bonus1/wansti-level3.stl @@ -90,12 +90,17 @@ (particles-clouds (layer -200) ) + (path + (name "cameraPath1") + (circular #f) + (nodes + (node (x 100) (y 300)) + (node (x 16000) (y 300) (time 177)) + ) + ) (camera (mode "autoscroll") - (path - (point (x 100) (y 300) (speed 90.0)) - (point (x 16000) (y 300) (speed 0.0)) - ) + (path "cameraPath1") ) (spawnpoint (name "main") diff --git a/data/levels/bonus2/level1.stl b/data/levels/bonus2/level1.stl index 88ab3f9eb..13334387f 100644 --- a/data/levels/bonus2/level1.stl +++ b/data/levels/bonus2/level1.stl @@ -47,12 +47,17 @@ (particles-clouds (layer -200) ) + (path + (name "cameraPath1") + (circular #f) + (nodes + (node (x 100) (y 352)) + (node (x 18500) (y 352) (time 205)) + ) + ) (camera (mode "autoscroll") - (path - (point (x 100) (y 352) (speed 90.0)) - (point (x 18500) (y 352) (speed 0.0)) - ) + (path "cameraPath1") ) (spawnpoint (name "main") diff --git a/data/levels/bonus2/level2.stl b/data/levels/bonus2/level2.stl index 6831f0fe5..cd48024dc 100644 --- a/data/levels/bonus2/level2.stl +++ b/data/levels/bonus2/level2.stl @@ -44,12 +44,17 @@ (leveltime (time 350) ) + (path + (name "cameraPath1") + (circular #f) + (nodes + (node (x 100) (y 170)) + (node (x 22383) (y 225) (time 223)) + ) + ) (camera (mode "autoscroll") - (path - (point (x 100) (y 170) (speed 100.0)) - (point (x 22383) (y 225) (speed 0.0)) - ) + (path "cameraPath1") ) (spawnpoint (name "main") diff --git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0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 )) + (path + (name "cameraPath1") + (circular #f) + (nodes + (node (x 0) (y 0) (speed 50)) + (node (x 500) (y 0) (time 10)) + (node (x 1200) (y 0) (time 3.5)) + (node (x 3000) (y 0) (time 18)) + (node (x 1500) (y 0) (time 15)) + (node (x 99999) (y 0) (time 704)) + ) + ) (camera (mode "autoscroll") - (path - (point (x 0) (y 0) (speed 50)) - (point (x 500) (y 0) (speed 200)) - (point (x 1200) (y 0) (speed 100)) - (point (x 3000) (y 0) (speed 100)) - (point (x 1500) (y 0) (speed 140)) - (point (x 99999) (y 0)) - ) - ) + (path "cameraPath1") + ) (background (image "images/background/semi_arctic.jpg") diff --git a/data/levels/test/forest1-grumbel.stl b/data/levels/test/forest1-grumbel.stl index c2f6f1fb9..6e6e88856 100644 --- a/data/levels/test/forest1-grumbel.stl +++ b/data/levels/test/forest1-grumbel.stl @@ -191,8 +191,7 @@ )) (camera (mode "normal") - (path - )) + ) ) ) diff --git a/data/levels/test/platform.stl b/data/levels/test/platform.stl index d6fb14a27..c20008d87 100644 --- a/data/levels/test/platform.stl +++ b/data/levels/test/platform.stl @@ -180,16 +180,16 @@ ) ) - (platform (use_path "path1") (x 200) (y 850) (type "block1")) - (platform (use_path "path1") (x 232) (y 850) (type "block3")) - (platform (use_path "path2") (x 264) (y 850) (type "block1")) - (platform (use_path "path2") (x 296) (y 850) (type "block3")) - (platform (use_path "path3") (x 328) (y 850) (type "block1")) - (platform (use_path "path3") (x 360) (y 850) (type "block3")) - (platform (use_path "path4") (x 392) (y 850) (type "block1")) - (platform (use_path "path4") (x 424) (y 850) (type "block3")) - (platform (use_path "path5") (x 456) (y 850) (type "block1")) - (platform (use_path "path5") (x 488) (y 850) (type "block3")) + (platform (path "path1") (x 200) (y 850) (type "block1")) + (platform (path "path1") (x 232) (y 850) (type "block3")) + (platform (path "path2") (x 264) (y 850) (type "block1")) + (platform (path "path2") (x 296) (y 850) (type "block3")) + (platform (path "path3") (x 328) (y 850) (type "block1")) + (platform (path "path3") (x 360) (y 850) (type "block3")) + (platform (path "path4") (x 392) (y 850) (type "block1")) + (platform (path "path4") (x 424) (y 850) (type "block3")) + (platform (path "path5") (x 456) (y 850) (type "block1")) + (platform (path "path5") (x 488) (y 850) (type "block3")) (powerup (x 100) (y 700) (sprite "images/powerups/egg/egg.sprite")) (jumpy (x 140) (y 750)) (spawnpoint (name "main") (x 340) (y 800)) diff --git a/src/object/camera.cpp b/src/object/camera.cpp index 5afd926b1..99e5a6e33 100644 --- a/src/object/camera.cpp +++ b/src/object/camera.cpp @@ -34,8 +34,7 @@ #include "object_factory.hpp" Camera::Camera(Sector* newsector) - : sector(newsector), do_backscrolling(true), scrollchange(NONE), - auto_idx(0), auto_t(0) + : sector(newsector), do_backscrolling(true), scrollchange(NONE) { mode = NORMAL; } @@ -63,30 +62,15 @@ Camera::parse(const lisp::Lisp& reader) reader.get("backscrolling", do_backscrolling); } else if(modename == "autoscroll") { mode = AUTOSCROLL; + std::string use_path; - const lisp::Lisp* path_lisp = reader.get_lisp("path"); - if(!path_lisp) - throw std::runtime_error("No path specified in autoscroll camera."); - - 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; - } - const lisp::Lisp* point_lisp = iter.lisp(); - - ScrollPoint point; - 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"); - } - point_lisp->get("speed", speed); - point.speed = speed; - scrollpoints.push_back(point); + if (!reader.get("path", use_path)) throw std::runtime_error("No path specified in autoscroll camera."); + + autoscrollPath = Path::GetByName(use_path); + if (autoscrollPath == NULL) { + std::cerr << "Warning: Path for autoscroll camera not found! Make sure that the name is spelled correctly and that the path is initialized before the platform in the level file!" << std::endl; } + } else if(modename == "manual") { mode = MANUAL; } else { @@ -106,17 +90,7 @@ Camera::write(lisp::Writer& writer) writer.write_bool("backscrolling", do_backscrolling); } else if(mode == AUTOSCROLL) { writer.write_string("mode", "autoscroll"); - writer.start_list("path"); - for(std::vector::iterator i = scrollpoints.begin(); - i != scrollpoints.end(); ++i) { - writer.start_list("point"); - writer.write_float("x", i->position.x); - writer.write_float("y", i->position.y); - writer.write_float("speed", i->speed); - writer.end_list("point"); - } - - writer.end_list("path"); + writer.write_string("path", autoscrollPath->GetName()); } else if(mode == MANUAL) { writer.write_string("mode", "manual"); } @@ -301,30 +275,7 @@ Camera::update_scroll_autoscroll(float elapsed_time) if(player->is_dying()) return; - if(auto_t - elapsed_time >= 0) { - translation += current_dir * elapsed_time; - auto_t -= elapsed_time; - } else { - // do the rest of the old movement - translation += current_dir * auto_t; - elapsed_time -= auto_t; - auto_t = 0; - - // construct path for next point - if(auto_idx+1 >= scrollpoints.size()) { - keep_in_bounds(translation); - return; - } - Vector distance = scrollpoints[auto_idx+1].position - - scrollpoints[auto_idx].position; - current_dir = distance.unit() * scrollpoints[auto_idx].speed; - auto_t = distance.norm() / scrollpoints[auto_idx].speed; - - // do movement for the remaining time - translation += current_dir * elapsed_time; - auto_t -= elapsed_time; - auto_idx++; - } + translation = autoscrollPath->GetPosition(); keep_in_bounds(translation); shake(); diff --git a/src/object/camera.hpp b/src/object/camera.hpp index fa4728a80..72157cdbe 100644 --- a/src/object/camera.hpp +++ b/src/object/camera.hpp @@ -27,6 +27,7 @@ #include "video/drawing_context.hpp" #include "serializable.hpp" #include "timer.hpp" +#include "object/path.hpp" namespace lisp { class Lisp; @@ -99,15 +100,7 @@ private: LeftRightScrollChange scrollchange; // autoscroll mode - class ScrollPoint { - public: - Vector position; - float speed; - }; - std::vector scrollpoints; - size_t auto_idx; - float auto_t; - Vector current_dir; + Path* autoscrollPath; // shaking Timer shaketimer; diff --git a/src/object/path.cpp b/src/object/path.cpp index bf7fefc78..be234d712 100644 --- a/src/object/path.cpp +++ b/src/object/path.cpp @@ -84,6 +84,34 @@ Path::~Path() Path::update(float elapsed_time) { + // TODO: carry excess time over to next node? This is how it was done in camera.cpp: + /* + if(auto_t - elapsed_time >= 0) { + translation += current_dir * elapsed_time; + auto_t -= elapsed_time; + } else { + // do the rest of the old movement + translation += current_dir * auto_t; + elapsed_time -= auto_t; + auto_t = 0; + + // construct path for next point + if(auto_idx+1 >= scrollpoints.size()) { + keep_in_bounds(translation); + return; + } + Vector distance = scrollpoints[auto_idx+1].position + - scrollpoints[auto_idx].position; + current_dir = distance.unit() * scrollpoints[auto_idx].speed; + auto_t = distance.norm() / scrollpoints[auto_idx].speed; + + // do movement for the remaining time + translation += current_dir * elapsed_time; + auto_t -= elapsed_time; + auto_idx++; + } + */ + // advance to next node at scheduled time if (timeToGo <= 0) { position = pathNodes[destinationNode].position; @@ -143,6 +171,10 @@ Path::GetLastMovement() { return last_movement; } +const std::string +Path::GetName() { + return name; +} ////////////////////////////////////////////////////////////////////////////// // static stuff diff --git a/src/object/path.hpp b/src/object/path.hpp index 452e942fa..68a1161a8 100644 --- a/src/object/path.hpp +++ b/src/object/path.hpp @@ -56,6 +56,8 @@ public: const Vector& GetPosition(); const Vector& GetLastMovement(); + const std::string GetName(); + // WARNING: returns NULL if not found ! static Path* GetByName(const std::string& name); diff --git a/src/object/platform.cpp b/src/object/platform.cpp index 8d1a8f385..bc872b01a 100644 --- a/src/object/platform.cpp +++ b/src/object/platform.cpp @@ -37,7 +37,7 @@ Platform::Platform(const lisp::Lisp& reader) reader.get("x", bbox.p1.x); reader.get("y", bbox.p1.y); reader.get("type", type); - reader.get("use_path", use_path); + reader.get("path", use_path); sprite = sprite_manager->create("images/objects/flying_platform/platform.sprite"); sprite->set_action(type); bbox.set_size(sprite->get_width(), sprite->get_height());