8 NetTrain::NetTrain(Client &c, const TrainInfoPacket &pkt):
10 loco_type(client.get_catalogue().get_vehicle(pkt.loco_type)),
16 void NetTrain::set_control(const string &c, float v)
21 TrainControlPacket pkt;
22 pkt.address = address;
28 float NetTrain::get_control(const string &c) const
30 map<string, float>::const_iterator i = controls.find(c);
31 return i!=controls.end() ? i->second : 0;
34 void NetTrain::set_function(unsigned i, bool set)
36 TrainFunctionPacket pkt;
37 pkt.address = address;
38 pkt.functions = functions;
40 pkt.functions |= 1<<i;
42 pkt.functions &= ~(1<<i);
46 void NetTrain::set_route(const string &r)
52 pkt.address = address;
57 void NetTrain::process_packet(const TrainControlPacket &pkt)
59 controls[pkt.control] = pkt.value;
60 signal_control_changed.emit(pkt.control, pkt.value);
63 void NetTrain::process_packet(const TrainFunctionPacket &pkt)
65 unsigned old_funcs = functions;
66 functions = pkt.functions;
67 for(unsigned i=0; i<9; ++i)
68 if(((functions^old_funcs)>>i)&1)
69 signal_function_changed.emit(i, (functions>>i)&1);
72 void NetTrain::process_packet(const TrainStatusPacket &pkt)
75 signal_status_changed.emit(status);
78 void NetTrain::process_packet(const TrainRoutePacket &pkt)
81 signal_route_changed.emit(route);