X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Fsignal.cpp;h=7ccb23874a7feb6c5659556b513ab4ecaea90a25;hb=54392d65e2053d1eacb4cfcc435f1013993f2973;hp=3494467d84daf3c166ccbf851742712987b72d8d;hpb=7a36d396eded897c421424905b2c938d770df341;p=r2c2.git diff --git a/source/libr2c2/signal.cpp b/source/libr2c2/signal.cpp index 3494467..7ccb238 100644 --- a/source/libr2c2/signal.cpp +++ b/source/libr2c2/signal.cpp @@ -1,4 +1,5 @@ #include "blockiter.h" +#include "catalogue.h" #include "driver.h" #include "layout.h" #include "signal.h" @@ -50,32 +51,36 @@ void Signal::set_address(unsigned a) } void Signal::set_position(const Vector &p) +{ + position = p; + + update_location(); +} + +void Signal::update_location() { const set &tracks = layout.get_tracks(); + float limit = layout.get_catalogue().get_gauge()*2; float dist = -1; for(set::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) if(!(*i)->get_type().is_turnout()) { Snap sn; - sn.position = p; + sn.position = position; sn.rotation = rotation; - (*i)->snap(sn, 1000, SNAP_SEGMENT); - float d = distance(p, sn.position); + (*i)->snap(sn, limit, SNAP_SEGMENT); + float d = distance(position, sn.position); if(dget_block(); + if(!track) + return; unsigned n_endpoints = track->get_type().get_endpoints().size(); for(unsigned j=0; j=Angle::quarter_turn()) { BlockIter biter = TrackIter(track, j).block_iter(); - entry = biter.entry(); + if(biter) + { + block = &track->get_block(); + entry = biter.entry(); + } } } } void Signal::set_rotation(const Angle &r) { - Angle a = wrap_with_base(rotation-r, -Angle::quarter_turn()); - if(a>=Angle::quarter_turn()) - rotation = wrap_positive(rotation+Angle::half_turn()); + rotation = r; - normalize_location(); + update_location(); } unsigned Signal::get_n_snap_nodes() const @@ -122,19 +129,6 @@ SnapType Signal::get_default_snap_type_to(const Object &other) const return NO_SNAP; } -bool Signal::collide_ray(const Vector &start, const Vector &ray) const -{ - // XXX Totally hardcoded stuff, should be replaced with a geometry system - Vector center = position+rotated_vector(Vector(0, -0.035, 0), rotation); - Vector span = center-start; - float x = (span.x*ray.x+span.y*ray.y)/(ray.x*ray.x+ray.y*ray.y); - Vector nearest = start+ray*x-center; - if(nearest.z<0 || nearest.z>0.12) - return false; - nearest.z = 0; - return dot(nearest, nearest)<0.0001; -} - void Signal::tick(const Time::TimeDelta &) { if(check_allocated_blocks) @@ -169,7 +163,7 @@ void Signal::block_reserved(const Block &b, Train *t) { if(t) { - int train_entry = t->get_entry_to_block(*block); + int train_entry = t->get_block_allocator().get_entry_to_block(*block); if(train_entry>=0 && static_cast(train_entry)==entry) { if(train_conn)