From: Mikko Rasa Date: Sun, 13 Dec 2009 15:04:44 +0000 (+0000) Subject: Change terminology to better distinguish routes on the layout from paths across track... X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=6dc18b0e518407bd2a86602bae1e9bbae05da7c8;p=r2c2.git Change terminology to better distinguish routes on the layout from paths across tracks and blocks --- diff --git a/source/3d/track.cpp b/source/3d/track.cpp index 47e6e61..b2ee4fa 100644 --- a/source/3d/track.cpp +++ b/source/3d/track.cpp @@ -132,17 +132,17 @@ void Track3D::render_endpoints() const glPopMatrix(); } -void Track3D::render_route(int route) const +void Track3D::render_path(int path) const { prepare_render(true); varray.apply(); - if(route>=0 && static_cast(route)=0 && static_cast(path) &parts = track.get_type().get_parts(); unsigned index = 0; @@ -244,10 +244,10 @@ void Track3D::build_part(const TrackPart &part, GL::VertexArrayBuilder &va_build rail_seq.push_back(base_index+(i+1)*psize+1+j*2); rail_seq.push_back(base_index+i*psize+1+j*2); } - route_seq[part.route].push_back(base_index+i*psize+18); - route_seq[part.route].push_back(base_index+(i+1)*psize+18); - route_seq[part.route].push_back(base_index+(i+1)*psize+19); - route_seq[part.route].push_back(base_index+i*psize+19); + path_seq[part.path].push_back(base_index+i*psize+18); + path_seq[part.path].push_back(base_index+(i+1)*psize+18); + path_seq[part.path].push_back(base_index+(i+1)*psize+19); + path_seq[part.path].push_back(base_index+i*psize+19); } base_index += (nsegs+1)*psize; diff --git a/source/3d/track.h b/source/3d/track.h index 3630ac6..adc046b 100644 --- a/source/3d/track.h +++ b/source/3d/track.h @@ -26,7 +26,7 @@ private: Msp::GL::VertexArray varray; std::vector base_seq; std::vector rail_seq; - std::vector > route_seq; + std::vector > path_seq; unsigned quality; public: @@ -38,7 +38,7 @@ public: void get_bounds(float, Point &, Point &) const; void render() const; void render_endpoints() const; - void render_route(int) const; + void render_path(int) const; private: void prepare_render(bool) const; void build_object(); diff --git a/source/designer/designer.cpp b/source/designer/designer.cpp index c5c274e..a5bbc68 100644 --- a/source/designer/designer.cpp +++ b/source/designer/designer.cpp @@ -402,7 +402,7 @@ void Designer::key_press(unsigned code, unsigned mod, wchar_t) else if(key==Msp::Input::KEY_T) { Track *track = selection->get_track(); - if(selection->size()==1 && track->get_type().get_n_routes()>1) + if(selection->size()==1 && track->get_type().get_n_paths()>1) { ostringstream ss; ss<get_turnout_id(); @@ -419,7 +419,7 @@ void Designer::key_press(unsigned code, unsigned mod, wchar_t) int id = -1; for(set::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) { - if((*i)->get_type().get_n_routes()==1) + if((*i)->get_type().get_n_paths()==1) ok = true; if(static_cast((*i)->get_sensor_id())!=id) { @@ -597,14 +597,14 @@ void Designer::render() const map &turnouts = cur_route->get_turnouts(); for(set::const_iterator i=rtracks.begin(); i!=rtracks.end(); ++i) { - unsigned route = 0; + unsigned path = 0; if(unsigned tid=(*i)->get_turnout_id()) { map::const_iterator j = turnouts.find(tid); if(j!=turnouts.end()) - route = j->second; + path = j->second; } - layout_3d->get_track(**i).render_route(route); + layout_3d->get_track(**i).render_path(path); } } manipulator->render(); diff --git a/source/engineer/engineer.cpp b/source/engineer/engineer.cpp index a2e13f1..11729be 100644 --- a/source/engineer/engineer.cpp +++ b/source/engineer/engineer.cpp @@ -229,10 +229,10 @@ void Engineer::tick() if(track.get_turnout_id()) { Turnout &trnt = control.get_turnout(track.get_turnout_id()); - (*i)->render_route(trnt.get_route()); + (*i)->render_path(trnt.get_path()); } else - (*i)->render_route(-1); + (*i)->render_path(-1); } if(placing_train && placing_block) @@ -327,7 +327,7 @@ void Engineer::button_press(int x, int y, unsigned btn, unsigned) Turnout &turnout = control.get_turnout(tid); try { - turnout.set_route((turnout.get_route()+1)%track->get_track().get_type().get_n_routes()); + turnout.set_path((turnout.get_path()+1)%track->get_track().get_type().get_n_paths()); main_panel->set_status_text(format("Turnout %d switched", turnout.get_address())); } catch(const TurnoutBusy &e) diff --git a/source/libmarklin/block.cpp b/source/libmarklin/block.cpp index c562788..9a9164e 100644 --- a/source/libmarklin/block.cpp +++ b/source/libmarklin/block.cpp @@ -52,10 +52,10 @@ Block::Block(TrafficManager &tm, Track &start): for(unsigned i=0; i visited; - find_routes(*endpoints[i].track, endpoints[i].track_ep, route, visited); + find_paths(*endpoints[i].track, endpoints[i].track_ep, path, visited); } } @@ -82,18 +82,18 @@ int Block::traverse(unsigned epi, float *len) const while(1) { - unsigned cur_route = 0; + unsigned cur_path = 0; unsigned tid = track->get_turnout_id(); if(tid) { Turnout &turnout = trfc_mgr.get_control().get_turnout(tid); - cur_route = turnout.get_route(); + cur_path = turnout.get_path(); } if(len) - *len += track->get_type().get_route_length(cur_route); + *len += track->get_type().get_path_length(cur_path); - int other_ep = track->traverse(track_ep, cur_route); + int other_ep = track->traverse(track_ep, cur_path); if(other_ep<0) return -1; @@ -157,11 +157,11 @@ void Block::print_debug() cout<link->id; else cout<<"none"; - cout<<", routes="<routes<<'\n'; + cout<<", paths="<paths<<'\n'; } } -void Block::find_routes(Track &track, unsigned track_ep, unsigned route, set &visited) +void Block::find_paths(Track &track, unsigned track_ep, unsigned path, set &visited) { visited.insert(&track); @@ -172,15 +172,15 @@ void Block::find_routes(Track &track, unsigned track_ep, unsigned route, setget_endpoint_by_link(track), route, visited); + find_paths(*link, link->get_endpoint_by_link(track), path, visited); else { for(vector::iterator j=endpoints.begin(); j!=endpoints.end(); ++j) if(j->track==&track && j->track_ep==i) - j->routes |= route; + j->paths |= path; } } } @@ -190,7 +190,7 @@ Block::Endpoint::Endpoint(Track *t, unsigned e): track(t), track_ep(e), link(0), - routes(0) + paths(0) { } } // namespace Marklin diff --git a/source/libmarklin/block.h b/source/libmarklin/block.h index 770a352..64f02e5 100644 --- a/source/libmarklin/block.h +++ b/source/libmarklin/block.h @@ -25,7 +25,7 @@ public: Track *track; unsigned track_ep; Block *link; - unsigned routes; + unsigned paths; Endpoint(Track *, unsigned); }; @@ -54,7 +54,7 @@ public: const Train *get_train() const { return train; } void print_debug(); private: - void find_routes(Track &, unsigned, unsigned, std::set &); + void find_paths(Track &, unsigned, unsigned, std::set &); static unsigned next_id; }; diff --git a/source/libmarklin/endpoint.h b/source/libmarklin/endpoint.h index 9eade4d..7382404 100644 --- a/source/libmarklin/endpoint.h +++ b/source/libmarklin/endpoint.h @@ -16,10 +16,10 @@ struct Endpoint { Point pos; float dir; // Direction outwards from the endpoint - unsigned routes; + unsigned paths; - Endpoint(): dir(0), routes(0) { } - Endpoint(float x, float y, float d, unsigned r): pos(x, y), dir(d), routes(r) { } + Endpoint(): dir(0), paths(0) { } + Endpoint(float x, float y, float d, unsigned p): pos(x, y), dir(d), paths(p) { } }; } // namespace Marklin diff --git a/source/libmarklin/layout.cpp b/source/libmarklin/layout.cpp index 9ec0d0a..3a6b630 100644 --- a/source/libmarklin/layout.cpp +++ b/source/libmarklin/layout.cpp @@ -108,14 +108,14 @@ void Layout::check_routes() const map turnouts = (*i)->get_turnouts(); Track *track = 0; - unsigned trk_route = 0; + unsigned trk_path = 0; for(set::const_iterator j=tracks.begin(); j!=tracks.end(); ++j) { map::const_iterator k = turnouts.find((*j)->get_turnout_id()); if(k!=turnouts.end()) { track = *j; - trk_route = k->second; + trk_path = k->second; break; } } @@ -125,7 +125,7 @@ void Layout::check_routes() const vector &eps = track->get_type().get_endpoints(); unsigned ep = 0; for(unsigned j=0; jtraverse(ep, trk_route); + int out_ep = track->traverse(ep, trk_path); if(out_ep<0) break; Track *next = track->get_links()[out_ep]; if(!next || next == start) break; ep = next->get_endpoint_by_link(*track); - if(next->get_type().get_n_routes()>1) + if(next->get_type().get_n_paths()>1) { map::const_iterator j = turnouts.find(next->get_turnout_id()); if(j==turnouts.end()) break; - trk_route = j->second; + trk_path = j->second; } else - trk_route = 0; + trk_path = 0; (*i)->add_track(*next); track = next; } diff --git a/source/libmarklin/route.cpp b/source/libmarklin/route.cpp index 364509c..40638d9 100644 --- a/source/libmarklin/route.cpp +++ b/source/libmarklin/route.cpp @@ -100,21 +100,21 @@ void Route::update_turnouts() if(unsigned tid2=links[j]->get_turnout_id()) { const Endpoint &ep = links[j]->get_type().get_endpoints()[links[j]->get_endpoint_by_link(**i)]; - int r = get_turnout(tid2); - if(r>=0 && !(ep.routes&(1<=0 && !(ep.paths&(1<>=1, ++route) ; - turnouts[tid] = route; + unsigned path = 0; + for(; (mask && !(mask&1)); mask>>=1, ++path) ; + turnouts[tid] = path; } else turnouts[tid] = -1; @@ -144,7 +144,7 @@ unsigned Route::check_validity(const Track &trk) const int r = get_turnout(tid); if(r>=0) { - if(endpoints[epi].routes&(1<=0 && !(endpoints[epi].routes&endpoints[epj].routes)) + if(epj>=0 && !(endpoints[epi].paths&endpoints[epj].paths)) result &= 3; } } @@ -186,9 +186,9 @@ Route::Loader::Loader(Route &r): add("turnout", &Loader::turnout); } -void Route::Loader::turnout(unsigned id, unsigned route) +void Route::Loader::turnout(unsigned id, unsigned path) { - obj.turnouts[id] = route; + obj.turnouts[id] = path; } } // namespace Marklin diff --git a/source/libmarklin/track.cpp b/source/libmarklin/track.cpp index 617328a..d2822f6 100644 --- a/source/libmarklin/track.cpp +++ b/source/libmarklin/track.cpp @@ -223,7 +223,7 @@ Track *Track::get_link(unsigned i) const return links[i]; } -int Track::traverse(unsigned i, unsigned route) const +int Track::traverse(unsigned i, unsigned path) const { const vector &eps = type.get_endpoints(); if(i>=eps.size()) @@ -231,25 +231,25 @@ int Track::traverse(unsigned i, unsigned route) const const Endpoint &ep = eps[i]; - if(ep.routes&(1< &eps = type.get_endpoints(); if(epi>=eps.size()) @@ -264,7 +264,7 @@ Point Track::get_point(unsigned epi, unsigned route, float d) const { for(vector::const_iterator i=parts.begin(); i!=parts.end(); ++i) { - if((eps[epi].routes&(1<route!=route) + if((eps[epi].paths&(1<path!=path) continue; if(&*i==last_part) continue; diff --git a/source/libmarklin/trackpart.cpp b/source/libmarklin/trackpart.cpp index 943832f..f2b61be 100644 --- a/source/libmarklin/trackpart.cpp +++ b/source/libmarklin/trackpart.cpp @@ -16,13 +16,13 @@ TrackPart::TrackPart(): dir(0), length(0), radius(0), - route(0), + path(0), dead_end(false) { } void TrackPart::collect_endpoints(vector &eps) const { - eps.push_back(Endpoint(pos.x, pos.y, dir+M_PI, 1< &eps) const { float a = ((radius<0) ? -length : length); Point p = get_point(length*abs(radius)); - eps.push_back(Endpoint(p.x, p.y, dir+a, 1<::const_iterator i=parts.begin(); i!=parts.end(); ++i) - if(r<0 || i->route==static_cast(r)) + if(p<0 || i->path==static_cast(p)) { float l = i->length; if(i->radius) @@ -35,12 +35,12 @@ float TrackType::get_route_length(int r) const return len; } -unsigned TrackType::get_n_routes() const +unsigned TrackType::get_n_paths() const { unsigned n = 1; for(vector::const_iterator i=parts.begin(); i!=parts.end(); ++i) - if(i->route>=n) - n = i->route+1; + if(i->path>=n) + n = i->path+1; return n; } @@ -67,7 +67,7 @@ void TrackType::collect_endpoints() da -= M_PI*2; if(da<-3.1 || da>3.1) rm = true; - i->routes |= j->routes; + i->paths |= j->paths; j = endpoints.erase(j); } else diff --git a/source/libmarklin/tracktype.h b/source/libmarklin/tracktype.h index 65aa1f2..45d8720 100644 --- a/source/libmarklin/tracktype.h +++ b/source/libmarklin/tracktype.h @@ -39,8 +39,8 @@ public: unsigned get_article_number() const { return art_nr; } const std::string &get_description() const { return description; } float get_total_length() const; - float get_route_length(int) const; - unsigned get_n_routes() const; + float get_path_length(int) const; + unsigned get_n_paths() const; const std::vector &get_parts() const { return parts; } const std::vector &get_endpoints() const { return endpoints; } diff --git a/source/libmarklin/trafficmanager.cpp b/source/libmarklin/trafficmanager.cpp index 96cb269..b652d04 100644 --- a/source/libmarklin/trafficmanager.cpp +++ b/source/libmarklin/trafficmanager.cpp @@ -31,7 +31,7 @@ TrafficManager::TrafficManager(Control &c, Layout &l): for(set::const_iterator i=tracks.begin(); i!=tracks.end(); ++i) { if(unsigned tid=(*i)->get_turnout_id()) - new Turnout(control, tid, (*i)->get_type().get_n_routes()>=3); + new Turnout(control, tid, (*i)->get_type().get_n_paths()>=3); if(unsigned sid=(*i)->get_sensor_id()) if(!control.get_sensors().count(sid)) new Sensor(control, sid); @@ -115,7 +115,7 @@ void TrafficManager::save(const string &fn) const } } -void TrafficManager::turnout_route_changed(unsigned, Turnout *) +void TrafficManager::turnout_path_changed(unsigned, Turnout *) { } diff --git a/source/libmarklin/trafficmanager.h b/source/libmarklin/trafficmanager.h index 85381e0..b01860a 100644 --- a/source/libmarklin/trafficmanager.h +++ b/source/libmarklin/trafficmanager.h @@ -51,7 +51,7 @@ public: void tick(); void save(const std::string &) const; private: - void turnout_route_changed(unsigned, Turnout *); + void turnout_path_changed(unsigned, Turnout *); }; } // namespace Marklin diff --git a/source/libmarklin/train.cpp b/source/libmarklin/train.cpp index 9300267..e904ebf 100644 --- a/source/libmarklin/train.cpp +++ b/source/libmarklin/train.cpp @@ -42,8 +42,8 @@ Train::Train(TrafficManager &tm, Locomotive &l): const map &turnouts = trfc_mgr.get_control().get_turnouts(); for(map::const_iterator i=turnouts.begin(); i!=turnouts.end(); ++i) { - i->second->signal_route_changing.connect(sigc::bind(sigc::mem_fun(this, &Train::turnout_route_changing), i->second)); - i->second->signal_route_changed.connect(sigc::bind(sigc::mem_fun(this, &Train::turnout_route_changed), i->second)); + i->second->signal_path_changing.connect(sigc::bind(sigc::mem_fun(this, &Train::turnout_path_changing), i->second)); + i->second->signal_path_changed.connect(sigc::bind(sigc::mem_fun(this, &Train::turnout_path_changed), i->second)); } } @@ -140,14 +140,14 @@ void Train::tick(const Time::TimeStamp &t, const Time::TimeDelta &dt) if(cur_track) { - unsigned route = 0; + unsigned path = 0; if(cur_track->get_turnout_id()) - route = trfc_mgr.get_control().get_turnout(cur_track->get_turnout_id()).get_route(); + path = trfc_mgr.get_control().get_turnout(cur_track->get_turnout_id()).get_path(); offset += get_real_speed(loco.get_speed())*(dt/Time::sec); - if(offset>cur_track->get_type().get_route_length(route)) + if(offset>cur_track->get_type().get_path_length(path)) { - int out = cur_track->traverse(cur_track_ep, route); + int out = cur_track->traverse(cur_track_ep, path); if(out>=0) { Track *next = cur_track->get_link(out); @@ -161,7 +161,7 @@ void Train::tick(const Time::TimeStamp &t, const Time::TimeDelta &dt) } if(cur_track) - pos = cur_track->get_point(cur_track_ep, route, offset); + pos = cur_track->get_point(cur_track_ep, path, offset); } } @@ -186,11 +186,11 @@ void Train::locomotive_reverse_changed(bool) if(cur_track) { - unsigned route = 0; + unsigned path = 0; if(unsigned turnout = cur_track->get_turnout_id()) - route = trfc_mgr.get_control().get_turnout(turnout).get_route(); - cur_track_ep = cur_track->traverse(cur_track_ep, route); - offset = cur_track->get_type().get_route_length(route)-offset; + path = trfc_mgr.get_control().get_turnout(turnout).get_path(); + cur_track_ep = cur_track->traverse(cur_track_ep, path); + offset = cur_track->get_type().get_path_length(path)-offset; } } @@ -259,7 +259,7 @@ void Train::sensor_event(bool state, Sensor *sensor) } } -void Train::turnout_route_changing(unsigned, Turnout *turnout) +void Train::turnout_path_changing(unsigned, Turnout *turnout) { unsigned tid = turnout->get_address(); for(list::const_iterator i=cur_blocks.begin(); i!=cur_blocks.end(); ++i) @@ -280,7 +280,7 @@ void Train::turnout_route_changing(unsigned, Turnout *turnout) } } -void Train::turnout_route_changed(unsigned, Turnout *turnout) +void Train::turnout_path_changed(unsigned, Turnout *turnout) { unsigned tid = turnout->get_address(); for(list::iterator i=rsv_blocks.begin(); i!=rsv_blocks.end(); ++i) diff --git a/source/libmarklin/train.h b/source/libmarklin/train.h index 65caa3f..d4c7e18 100644 --- a/source/libmarklin/train.h +++ b/source/libmarklin/train.h @@ -90,8 +90,8 @@ public: private: void locomotive_reverse_changed(bool); void sensor_event(bool, Sensor *); - void turnout_route_changing(unsigned, Turnout *); - void turnout_route_changed(unsigned, Turnout *); + void turnout_path_changing(unsigned, Turnout *); + void turnout_path_changed(unsigned, Turnout *); unsigned reserve_more(); void update_speed(); float get_real_speed(unsigned) const; diff --git a/source/libmarklin/turnout.cpp b/source/libmarklin/turnout.cpp index efa98bb..d5f9617 100644 --- a/source/libmarklin/turnout.cpp +++ b/source/libmarklin/turnout.cpp @@ -20,7 +20,7 @@ namespace Marklin { Turnout::Turnout(Control &c, unsigned a, bool d): control(c), addr(a), - route(0), + path(0), dual(d) { control.add_turnout(*this); @@ -39,27 +39,27 @@ Turnout::Turnout(Control &c, unsigned a, bool d): } } -void Turnout::set_route(unsigned r) +void Turnout::set_path(unsigned p) { - signal_route_changing.emit(r); + signal_path_changing.emit(p); - route = r; + path = p; command(true); control.set_timer(200*Time::msec).signal_timeout.connect(sigc::mem_fun(this, &Turnout::switch_timeout)); - signal_route_changed.emit(route); + signal_path_changed.emit(path); } void Turnout::command(bool on) { unsigned char data[2]; data[0] = addr&0xFF; - data[1] = ((addr>>8)&0x7) | (on ? 0x40 : 0) | (route&1 ? 0 : 0x80); + data[1] = ((addr>>8)&0x7) | (on ? 0x40 : 0) | (path&1 ? 0 : 0x80); control.command(CMD_TURNOUT, data, 2); if(dual) { data[0] = (addr+1)&0xFF; - data[1] = (((addr+1)>>8)&0x7) | (on ? 0x40 : 0) | (route&2 ? 0 : 0x80); + data[1] = (((addr+1)>>8)&0x7) | (on ? 0x40 : 0) | (path&2 ? 0 : 0x80); control.command(CMD_TURNOUT, data, 2); } } @@ -70,8 +70,8 @@ void Turnout::status_reply(const Reply &reply, bool high) { bool v = !(reply.get_data()[0]&0x04); unsigned b = (high?2:1); - route = (route&~b)|(v?b:0); - signal_route_changed.emit(route); + path = (path&~b)|(v?b:0); + signal_path_changed.emit(path); } } @@ -82,17 +82,17 @@ bool Turnout::switch_timeout() return false; } -void Turnout::turnout_event(unsigned a, bool r) +void Turnout::turnout_event(unsigned a, bool p) { - if(a==addr && r!=(route&1)) + if(a==addr && p!=(path&1)) { - route = (route&2)|(r?1:0); - signal_route_changed.emit(route); + path = (path&2)|(p?1:0); + signal_path_changed.emit(path); } - else if(dual && a==addr+1 && r!=((route>>1)&1)) + else if(dual && a==addr+1 && p!=((path>>1)&1)) { - route = (route&1)|(r?2:0); - signal_route_changed.emit(route); + path = (path&1)|(p?2:0); + signal_path_changed.emit(path); } } diff --git a/source/libmarklin/turnout.h b/source/libmarklin/turnout.h index 2795714..01d3737 100644 --- a/source/libmarklin/turnout.h +++ b/source/libmarklin/turnout.h @@ -22,21 +22,21 @@ class Reply; class Turnout { public: - sigc::signal signal_route_changing; - sigc::signal signal_route_changed; + sigc::signal signal_path_changing; + sigc::signal signal_path_changed; private: Control &control; unsigned addr; - unsigned route; + unsigned path; bool dual; public: Turnout(Control &, unsigned, bool =false); - void set_route(unsigned); + void set_path(unsigned); unsigned get_address() const { return addr; } - unsigned get_route() const { return route; } + unsigned get_path() const { return path; } private: void command(bool); void status_reply(const Reply &, bool); diff --git a/tracks.dat b/tracks.dat index b33e97b..5fb597f 100644 --- a/tracks.dat +++ b/tracks.dat @@ -214,20 +214,20 @@ track 24671 part { length 77.5; - route 0; + path 0; }; part { start 77.5 0 0; length 30; radius 360; - route 0; + path 0; }; part { length 30; radius 360; - route 1; + path 1; }; }; @@ -237,20 +237,20 @@ track 24672 part { length 77.5; - route 0; + path 0; }; part { start 77.5 0 0; length 30; radius -360; - route 0; + path 0; }; part { length 30; radius -360; - route 1; + path 1; }; }; @@ -262,13 +262,13 @@ track 24611 part { length 188.3; - route 0; + path 0; }; part { length 24.3; radius 437.5; - route 1; + path 1; }; }; @@ -278,13 +278,13 @@ track 24612 part { length 188.3; - route 0; + path 0; }; part { length 24.3; radius -437.5; - route 1; + path 1; }; }; @@ -294,19 +294,19 @@ track 24630 part { length 188.3; - route 0; + path 0; }; part { length 24.3; radius 437.5; - route 1; + path 1; }; part { length 24.3; radius -437.5; - route 2; + path 2; }; }; @@ -343,13 +343,13 @@ track 24711 part { length 236.1; - route 0; + path 0; }; part { length 12.1; radius 1114.6; - route 1; + path 1; }; }; @@ -359,13 +359,13 @@ track 24712 part { length 236.1; - route 0; + path 0; }; part { length 12.1; radius -1114.6; - route 1; + path 1; }; };