4 // Copyright (C) 2005 Philipp <balinor@pnxs.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 #include "lisp/lisp.hpp"
24 #include "lisp/list_iterator.hpp"
25 #include "object_factory.hpp"
31 #define DEFAULT_PIXELS_PER_SECOND 50
34 Path::Path(const lisp::Lisp& reader)
39 lisp::ListIterator iter(&reader);
42 std::string token = iter.item();
43 assert(token == "name");
44 iter.value()->get(name);
49 if (token == "circular") {
50 iter.value()->get(circular);
54 pixels_per_second = DEFAULT_PIXELS_PER_SECOND;
57 if (token == "speed") {
58 iter.value()->get(pixels_per_second);
65 } else if(token == "y") {
67 points.push_back(Vector(x,y));
71 next_target = points.begin();
76 // register this path for lookup:
77 registry[name] = this;
86 Path::update(float elapsed_time)
88 last_movement = velocity * elapsed_time;
90 if ((pos - *next_target).norm() < EPSILON) {
97 Path::draw(DrawingContext& context)
99 // TODO: Add a visible flag, draw the path if true
103 Path::GetPosition() {
109 return *(points.begin());
113 Path::GetLastMovement() {
114 return last_movement;
118 Path::calc_next_velocity()
124 if (next_target == points.end()) {
125 next_target = points.begin();
130 if (next_target == points.end()) {
135 //FIXME: Implement going backwards on the list
136 // I have no f***ing idea how this is done in C++
139 distance = *next_target - pos;
140 velocity = distance.unit() * pixels_per_second;
143 //////////////////////////////////////////////////////////////////////////////
146 PathRegistry Path::registry;
149 Path::GetByName(const std::string& name) {
150 return registry[name];
153 IMPLEMENT_FACTORY(Path, "path");