3 This file is part of R²C²
4 Copyright © 2009 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
15 NetTrain::NetTrain(Client &c, const TrainInfoPacket &pkt):
17 loco_type(client.get_catalogue().get_vehicle(pkt.loco_type)),
23 void NetTrain::set_control(const string &c, float v)
28 TrainControlPacket pkt;
29 pkt.address = address;
35 float NetTrain::get_control(const string &c) const
37 map<string, float>::const_iterator i = controls.find(c);
38 return i!=controls.end() ? i->second : 0;
41 void NetTrain::set_function(unsigned i, bool set)
43 TrainFunctionPacket pkt;
44 pkt.address = address;
45 pkt.functions = functions;
47 pkt.functions |= 1<<i;
49 pkt.functions &= ~(1<<i);
53 void NetTrain::set_route(const string &r)
59 pkt.address = address;
64 void NetTrain::process_packet(const TrainControlPacket &pkt)
66 controls[pkt.control] = pkt.value;
67 signal_control_changed.emit(pkt.control, pkt.value);
70 void NetTrain::process_packet(const TrainFunctionPacket &pkt)
72 unsigned old_funcs = functions;
73 functions = pkt.functions;
74 for(unsigned i=0; i<9; ++i)
75 if(((functions^old_funcs)>>i)&1)
76 signal_function_changed.emit(i, (functions>>i)&1);
79 void NetTrain::process_packet(const TrainStatusPacket &pkt)
82 signal_status_changed.emit(status);
85 void NetTrain::process_packet(const TrainRoutePacket &pkt)
88 signal_route_changed.emit(route);