-/* $Id$
-
-This file is part of R²C²
-Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa
-Distributed under the GPL
-*/
-
#include <cmath>
#include "tracktype.h"
TrackType::TrackType(const ArticleNumber &an):
art_nr(an),
- double_address(false),
+ state_bits(0),
autofit_preference(1)
{ }
const TrackType::Endpoint &TrackType::get_endpoint(unsigned i) const
{
if(i>=endpoints.size())
- throw InvalidParameterValue("Endpoint index out of range");
+ throw out_of_range("TrackType::get_endpoint");
return endpoints[i];
}
TrackPoint TrackType::get_point(unsigned epi, unsigned path, float d) const
{
if(epi>=endpoints.size())
- throw InvalidParameterValue("Endpoint index out of range");
+ throw out_of_range("TrackType::get_point");
const TrackPart *part = 0;
unsigned part_ep = 0;
}
if(!part)
- throw Exception("Internal error (endpoint does not match any part)");
+ throw logic_error("internal error (endpoint does not match any part)");
while(1)
{
d -= plen;
TrackPart *next = part->get_link(1-part_ep);
if(!next)
- throw InvalidParameterValue("Distance out of range");
+ throw invalid_argument("TrackType::get_point");
part_ep = (next->get_link(0)==part ? 0 : 1);
part = next;
}
}
}
+bool TrackType::collide_ray(const Vector &start, const Vector &dir, float width) const
+{
+ for(vector<TrackPart>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
+ if(i->collide_ray(start, dir, width))
+ return true;
+
+ return false;
+}
+
void TrackType::collect_endpoints()
{
endpoints.clear();
TrackType::Loader::Loader(TrackType &t):
- Msp::DataFile::BasicLoader<TrackType>(t)
+ Msp::DataFile::ObjectLoader<TrackType>(t),
+ state_bits_set(false)
{
add("autofit_preference", &TrackType::autofit_preference);
add("description", &TrackType::description);
- add("double_address", &TrackType::double_address);
+ add("object", &TrackType::object);
+ add("state_bits", &Loader::state_bits);
add("part", &Loader::part);
}
TrackPart p;
load_sub(p);
obj.parts.push_back(p);
+ if(!state_bits_set && p.get_path())
+ while(p.get_path()>=(1U<<obj.state_bits))
+ ++obj.state_bits;
+}
+
+void TrackType::Loader::state_bits(unsigned b)
+{
+ obj.state_bits = b;
+ state_bits_set = true;
}
} // namespace R2C2