4 // Copyright (C) 2005 Philipp <balinor@pnxs.de>
5 // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
6 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License
10 // as published by the Free Software Foundation; either version 2
11 // of the License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 #include "lisp/lisp.hpp"
27 #include "lisp/list_iterator.hpp"
28 #include "object_factory.hpp"
45 Path::read(const lisp::Lisp& reader)
47 lisp::ListIterator iter(&reader);
51 if(iter.item() == "mode") {
52 std::string mode_string;
53 if(!iter.value()->get(mode_string))
54 throw std::runtime_error("Pathmode not a string");
56 if(mode_string == "oneshot")
58 else if(mode_string == "pingpong")
60 else if(mode_string == "circular")
63 std::ostringstream msg;
64 msg << "Unknown pathmode '" << mode_string << "' found";
65 throw std::runtime_error(msg.str());
70 if(iter.item() != "node") {
71 log_warning << "unknown token '" << iter.item() << "' in Path nodes list. Ignored." << std::endl;
74 const lisp::Lisp* node_lisp = iter.lisp();
76 // each new node will inherit all values from the last one
79 if( (!node_lisp->get("x", node.position.x) ||
80 !node_lisp->get("y", node.position.y)))
81 throw std::runtime_error("Path node without x and y coordinate specified");
82 node_lisp->get("time", node.time);
85 throw std::runtime_error("Path node with non-positive time");
87 nodes.push_back(node);
91 throw std::runtime_error("Path with zero nodes");
95 Path::write(lisp::Writer& writer)
97 writer.start_list("path");
101 writer.write_string("mode", "oneshot");
104 writer.write_string("mode", "pingpong");
107 writer.write_string("mode", "circular");
110 log_warning << "Don't know how to write mode " << (int) mode << " ?!?" << std::endl;
114 for (size_t i=0; i < nodes.size(); i++) {
115 const Node& node = nodes[i];
117 writer.start_list("node");
118 writer.write_float("x", node.position.x);
119 writer.write_float("y", node.position.y);
120 writer.write_float("time", node.time);
122 writer.end_list("node");
125 writer.end_list("path");
129 Path::get_base() const
134 return nodes[0].position;