@@ -176,6 +176,12 @@ struct rt_transport_geo_index {
176
176
rt_rtree rtree_{};
177
177
};
178
178
179
+ struct realtime {
180
+ std::array<rt_transport_geo_index, n::kNumClasses > rt_geo_indices_;
181
+ n::vector_map<n::rt_transport_idx_t , float > rt_distances_{};
182
+ std::shared_ptr<n::rt_timetable> rtt_;
183
+ };
184
+
179
185
struct railviz ::impl {
180
186
impl (tag_lookup const & tags, n::timetable const & tt,
181
187
std::unique_ptr<n::shapes_storage>&& shapes_data)
@@ -191,7 +197,8 @@ struct railviz::impl {
191
197
using motis::railviz::RailVizTripsRequest;
192
198
auto const * req = motis_content (RailVizTripsRequest, msg);
193
199
194
- auto rtt = rtt__;
200
+ auto const rt = rt_;
201
+ auto const rtt = rt->rtt_ ;
195
202
196
203
auto runs = std::vector<stop_pair>{};
197
204
for (auto const t : *req->trips ()) {
@@ -213,7 +220,7 @@ struct railviz::impl {
213
220
});
214
221
}
215
222
}
216
- return create_response (rtt, runs);
223
+ return create_response (*rt, * rtt, runs);
217
224
}
218
225
219
226
mm::msg_ptr get_trains (mm::msg_ptr const & msg) {
@@ -235,7 +242,8 @@ struct railviz::impl {
235
242
236
243
mm::msg_ptr get_trains (n::interval<n::unixtime_t > time_interval,
237
244
geo::box const & area, int const zoom_level) {
238
- auto const rtt = rtt__;
245
+ auto const rt = rt_;
246
+ auto const rtt = rt->rtt_ ;
239
247
240
248
auto runs = std::vector<stop_pair>{};
241
249
for (auto c = int_clasz{0U }; c != n::kNumClasses ; ++c) {
@@ -247,8 +255,8 @@ struct railviz::impl {
247
255
248
256
if (rtt != nullptr ) {
249
257
for (auto const & rt_t :
250
- rt_geo_indices_[c].get_rt_transports (*rtt, area)) {
251
- if (should_display (cl, zoom_level, rt_distances_[rt_t ])) {
258
+ rt-> rt_geo_indices_ [c].get_rt_transports (*rtt, area)) {
259
+ if (should_display (cl, zoom_level, rt-> rt_distances_ [rt_t ])) {
252
260
add_rt_transports (rtt, rt_t , time_interval, area, runs);
253
261
}
254
262
}
@@ -260,10 +268,10 @@ struct railviz::impl {
260
268
}
261
269
}
262
270
}
263
- return create_response (rtt, runs);
271
+ return create_response (*rt, * rtt, runs);
264
272
}
265
273
266
- mm::msg_ptr create_response (std::shared_ptr< n::rt_timetable> const & rtt,
274
+ mm::msg_ptr create_response (realtime const & rt, n::rt_timetable const & rtt,
267
275
std::vector<stop_pair> const & runs) const {
268
276
geo::polyline_encoder<6 > enc;
269
277
@@ -291,7 +299,7 @@ struct railviz::impl {
291
299
auto fbs_polylines = std::vector<fbs::Offset<fbs::String>>{
292
300
mc.CreateString (" " ) /* no zero, zero doesn't have a sign=direction */ };
293
301
auto const trains = utl::to_vec (runs, [&](stop_pair const & r) {
294
- auto const fr = n::rt::frun{tt_, rtt. get () , r.r_ };
302
+ auto const fr = n::rt::frun{tt_, & rtt, r.r_ };
295
303
296
304
auto const from = fr[r.from_ ];
297
305
auto const to = fr[r.to_ ];
@@ -311,7 +319,7 @@ struct railviz::impl {
311
319
return motis::railviz::CreateTrain (
312
320
mc, mc.CreateVector (std::vector{mc.CreateString (fr.name ())}),
313
321
static_cast <int >(fr.get_clasz ()),
314
- fr.is_rt () ? rt_distances_[fr.rt_ ]
322
+ fr.is_rt () ? rt. rt_distances_ [fr.rt_ ]
315
323
: static_distances_[tt_.transport_route_ [fr.t_ .t_idx_ ]],
316
324
mc.CreateString (get_station_id (tags_, tt_, from_l)),
317
325
mc.CreateString (get_station_id (tags_, tt_, to_l)),
@@ -413,22 +421,22 @@ struct railviz::impl {
413
421
}
414
422
415
423
void update (std::shared_ptr<n::rt_timetable> const & rtt) {
416
- rtt__ = rtt;
417
- rt_distances_.resize (rtt__->rt_transport_location_seq_ .size ());
424
+ auto rt = std::make_shared<realtime>();
425
+ rt->rtt_ = rtt;
426
+ rt->rt_distances_ .resize (rtt->rt_transport_location_seq_ .size ());
418
427
for (auto c = int_clasz{0U }; c != n::kNumClasses ; ++c) {
419
- rt_geo_indices_[c] =
420
- rt_transport_geo_index{tt_, *rtt__ , n::clasz{c}, rt_distances_};
428
+ rt-> rt_geo_indices_ [c] =
429
+ rt_transport_geo_index{tt_, *rtt , n::clasz{c}, rt-> rt_distances_ };
421
430
}
431
+ rt_ = rt;
422
432
}
423
433
424
434
tag_lookup const & tags_;
425
435
n::timetable const & tt_;
426
436
std::unique_ptr<n::shapes_storage> shapes_data_;
427
- std::shared_ptr<n::rt_timetable> rtt__ ;
437
+ std::shared_ptr<realtime> rt_ ;
428
438
std::array<route_geo_index, n::kNumClasses > static_geo_indices_;
429
- std::array<rt_transport_geo_index, n::kNumClasses > rt_geo_indices_;
430
439
n::vector_map<n::route_idx_t , float > static_distances_{};
431
- n::vector_map<n::rt_transport_idx_t , float > rt_distances_{};
432
440
};
433
441
434
442
railviz::railviz (tag_lookup const & tags, n::timetable const & tt,
0 commit comments