From c16e4e64781e63c16c9e9a9850d71f925b5c8f93 Mon Sep 17 00:00:00 2001 From: turbo-devv Date: Sun, 22 Nov 2026 09:19:31 -0500 Subject: [PATCH 1/6] Lines: a path picked past the end of a trip no longer sends the way back to the start A path clicked after the end of a way picked by hand was put in as a way round between the first paths of the line wherever it led back into them round the block, so the way looped back to the start with every click. It now goes where it adds the least driving, and a way round must take the place of something or mend a gap. A trip whose way is not found all the way keeps the part found, and picking by hand goes on from there instead of from nothing. The list of the way's paths opens while picking and shows more of them. A lane driven against its path's direction no longer hides the link over it. Fixes #135 --- src/timetable/network.rs | 5 ++- src/timetable/route.rs | 12 ++++- src/timetable/tests.rs | 54 ++++++++++++++++++++++ src/timetable/way.rs | 97 ++++++++++++++++++++++++---------------- src/ui_timetable/way.rs | 7 +-- 5 files changed, 130 insertions(+), 45 deletions(-) diff --git a/src/timetable/network.rs b/src/timetable/network.rs index 40a070bb..40573af8 100644 --- a/src/timetable/network.rs +++ b/src/timetable/network.rs @@ -302,9 +302,10 @@ impl Network { // a lane reached over a piece shorter than a link spans (a junction's connector) is // not linked straight on as well: the way drives the piece, it does not jump over it // to the path after it (#122). (Two branches that start a little apart stay linked - // both, as OMSI 2's own station links have them.) + // both, as OMSI 2's own station links have them; and a piece driven against its + // path's direction is no way on, the link over it stays.) let skips: Vec> = (0..self.lanes.len()) - .map(|i| next[i].iter().copied().filter(|&b| next[i].iter().any(|&s| s != b && self.lanes[s].length() <= LINK * 2.0 && next[s].contains(&b))).collect()) + .map(|i| next[i].iter().copied().filter(|&b| next[i].iter().any(|&s| s != b && !self.lanes[s].against && self.lanes[s].length() <= LINK * 2.0 && next[s].contains(&b))).collect()) .collect(); for (n, skip) in next.iter_mut().zip(skips) { n.retain(|b| !skip.contains(b)); diff --git a/src/timetable/route.rs b/src/timetable/route.rs index d0320083..c65f5fed 100644 --- a/src/timetable/route.rs +++ b/src/timetable/route.rs @@ -441,13 +441,22 @@ fn find_on(net: &Network, positions: &[Option], left_hand: bool, ways: Wa } if row.iter().all(|x| x.is_none()) { r.problems.push(Problem::NoWay(i - 1)); + // (the way as far as it was found, to pick the rest of it by hand from there) + back(net, &mut r, &cands, &best, &ways); return r; } best.push(row); ways.push(leg_ways); } + back(net, &mut r, &cands, &best, &ways); + r +} + +/// The way through the stops found so far (`best` and `ways` as far as they reach), back +/// from the cheapest last of them, put into `r`. +fn back(net: &Network, r: &mut Route, cands: &[Vec<(StopOn, f64)>], best: &[Vec>], ways: &[HashMap<(usize, usize), Vec>]) { // back from the cheapest last stop - let last = cands.len() - 1; + let last = best.len() - 1; let mut c = (0..best[last].len()).filter(|&c| best[last][c].is_some()).min_by(|&a, &b| best[last][a].unwrap().0.total_cmp(&best[last][b].unwrap().0)).unwrap(); let mut picks = vec![c; cands.len()]; let mut legs = vec![0.0; last]; @@ -470,5 +479,4 @@ fn find_on(net: &Network, positions: &[Option], left_hand: bool, ways: Wa } } r.legs = legs; - r } diff --git a/src/timetable/tests.rs b/src/timetable/tests.rs index 5522defe..9601fb3e 100644 --- a/src/timetable/tests.rs +++ b/src/timetable/tests.rs @@ -641,6 +641,60 @@ fn a_way_picked_by_hand() { assert_eq!(r.problems, vec![route::Problem::OffWay(1)]); } +/// A path clicked past the end of the way is added after the end, even where it leads round +/// the block back into the way: the way does not turn back to the start of the line (#135). +#[test] +fn a_path_past_the_end_does_not_loop_back_to_the_start() { + let tile = (0, 0); + let mut net = Network::default(); + let p = |pts: &[(f64, f64)]| pts.iter().map(|q| DVec3::new(q.0, q.1, 0.0)).collect::>(); + let mut add = |id: i64, pts: Vec| { + let len: f64 = pts.windows(2).map(|w| (w[1] - w[0]).length()).sum(); + net.add(PathKey { tile, id, path: 0 }, pts, len, id as usize, 0, (true, false)); + }; + add(1, p(&[(0.0, 0.0), (0.0, 100.0)])); + add(2, p(&[(0.0, 100.0), (0.0, 200.0)])); + add(3, p(&[(0.0, 200.0), (0.0, 300.0)])); + // round the block from the end of 3 back into the start of 2 + add(4, p(&[(0.0, 300.0), (0.0, 320.0), (-20.0, 340.0), (-60.0, 340.0), (-80.0, 320.0), (-80.0, 80.0), (-60.0, 60.0), (-20.0, 60.0), (0.0, 80.0), (0.0, 100.0)])); + net.link(); + let id: std::collections::HashMap = (1..=4).map(|i| (i, net.by_key[&PathKey { tile, id: i, path: 0 }][0])).collect(); + assert!(net.lanes[id[&4]].next.contains(&id[&2]), "the block leads back into the way"); + let ids = |lanes: &[usize]| lanes.iter().map(|l| net.lanes[*l].key.id).collect::>(); + let w = way::with_lane(&net, &[id[&1], id[&2]], id[&3]); + assert_eq!(ids(&w), vec![1, 2, 3]); + // and the path after it too + let w = way::with_lane(&net, &w, id[&4]); + assert_eq!(ids(&w), vec![1, 2, 3, 4]); + // a gap in the way is mended by a path clicked in it + let w = way::with_lane(&net, &[id[&1], id[&3]], id[&2]); + assert_eq!(ids(&w), vec![1, 2, 3]); +} + +/// A way not found all the way keeps the part found, up to the stop it could not go on +/// from: the rest is picked by hand from there (#135). +#[test] +fn a_way_found_part_of_the_way_keeps_that_part() { + let tile = (0, 0); + let mut net = Network::default(); + let p = |pts: &[(f64, f64)]| pts.iter().map(|q| DVec3::new(q.0, q.1, 0.0)).collect::>(); + let mut add = |id: i64, pts: Vec| { + let len: f64 = pts.windows(2).map(|w| (w[1] - w[0]).length()).sum(); + net.add(PathKey { tile, id, path: 0 }, pts, len, id as usize, 0, (true, false)); + }; + add(1, p(&[(0.0, 0.0), (0.0, 100.0)])); + add(2, p(&[(0.0, 100.0), (0.0, 200.0)])); + // (10 m on from the end of 2: not joined) + add(3, p(&[(0.0, 210.0), (0.0, 300.0)])); + net.link(); + let at = |pts: &[(f64, f64)]| pts.iter().map(|p| Some(DVec3::new(p.0, p.1, 0.0))).collect::>(); + let r = route::find(&net, &at(&[(2.5, 20.0), (2.5, 150.0), (2.5, 250.0)]), false, None); + assert_eq!(r.problems, vec![route::Problem::NoWay(1)]); + assert!(!r.ok()); + assert_eq!(r.lanes.iter().map(|l| net.lanes[*l].key.id).collect::>(), vec![1, 2]); + assert_eq!(r.stops.len(), 2); +} + /// A trip's paths picked by hand are kept as they are when saved and read again: its track /// says so in a line the game passes over, and it reads back the same. #[test] diff --git a/src/timetable/way.rs b/src/timetable/way.rs index 3fe43f14..b0a7a641 100644 --- a/src/timetable/way.rs +++ b/src/timetable/way.rs @@ -256,9 +256,9 @@ fn path_to(found: &HashMap, a: usize, b: usize) -> Option Vec { if let Some(i) = lanes.iter().position(|x| *x == l) { let mut out = lanes.to_vec(); @@ -268,46 +268,67 @@ pub fn with_lane(net: &Network, lanes: &[usize], l: usize) -> Vec { let Some(&last) = lanes.last() else { return vec![l] }; let from_l = search_from(net, l); let to_l = search_to(net, l); - // a way round: from a lane of the way to `l` and on to a later one, as little of the way - // left out as can be (and not more than a detour would be: a click far along a ring road - // adds to the end) - let mut best: Option<(usize, usize)> = None; - let mut reach_before: Option = None; - for j in 0..lanes.len() { - if let Some(i) = reach_before { - if from_l.contains_key(&lanes[j]) && best.map(|b| j - i < b.1 - b.0).unwrap_or(true) { - best = Some((i, j)); + let len_l = net.lanes[l].length(); + // (what each choice adds to the way, in metres driven) + let mut best: Option<(f64, Vec)> = None; + let mut offer = |extra: f64, way: Option>| { + if let Some(w) = way { + if best.as_ref().map(|b| extra < b.0).unwrap_or(true) { + best = Some((extra, w)); } } - if to_l.contains_key(&lanes[j]) { - reach_before = Some(j); - } - } - if let Some((i, j)) = best { - let left_out: f64 = lanes[i + 1..j].iter().map(|x| net.lanes[*x].length()).sum(); - let detour = to_l[&lanes[i]].0 + net.lanes[l].length() + from_l[&lanes[j]].0; - if let (true, Some(before), Some(after)) = (left_out <= detour * 2.0 + 300.0, path_to(&to_l, lanes[i], l), path_from(&from_l, l, lanes[j])) { - let mut out = lanes[..=i].to_vec(); - out.extend(before); - out.push(l); - out.extend(after); - out.extend_from_slice(&lanes[j..]); - return out; - } - } + }; // after the end - if let Some(w) = path_to(&to_l, last, l) { - let mut out = lanes.to_vec(); - out.extend(w); - out.push(l); - return out; + if let Some(c) = to_l.get(&last) { + offer(c.0 + len_l, path_to(&to_l, last, l).map(|w| { + let mut out = lanes.to_vec(); + out.extend(w); + out.push(l); + out + })); } // before the start - if let Some(w) = path_from(&from_l, l, lanes[0]) { - let mut out = vec![l]; - out.extend(w); - out.extend_from_slice(lanes); - return out; + if let Some(c) = from_l.get(&lanes[0]) { + offer(c.0 + len_l, path_from(&from_l, l, lanes[0]).map(|w| { + let mut out = vec![l]; + out.extend(w); + out.extend_from_slice(lanes); + out + })); + } + // a way round: from a lane of the way to `l` and on to a later one, in place of the lanes + // between. Something must be left out, or a gap mended: a way from one lane to the next + // that joins it already is only a loop (round the block, or back to the start of the + // line from a path clicked past its end). + let mut left_out = vec![0.0; lanes.len() + 1]; + for (k, x) in lanes.iter().enumerate() { + left_out[k + 1] = left_out[k] + net.lanes[*x].length(); + } + for i in 0..lanes.len() { + let Some(&(ci, _)) = to_l.get(&lanes[i]) else { continue }; + for j in i + 1..lanes.len() { + let Some(&(cj, _)) = from_l.get(&lanes[j]) else { continue }; + if j == i + 1 && gap(net, lanes[i], lanes[j]) == 0.0 { + continue; + } + let out = left_out[j] - left_out[i + 1]; + let detour = ci + len_l + cj; + // (not a way round far longer, or far shorter, than what it takes the place of) + if detour > out * 2.0 + 300.0 || out > detour * 2.0 + 300.0 { + continue; + } + offer(detour - out, path_to(&to_l, lanes[i], l).zip(path_from(&from_l, l, lanes[j])).map(|(before, after)| { + let mut w = lanes[..=i].to_vec(); + w.extend(before); + w.push(l); + w.extend(after); + w.extend_from_slice(&lanes[j..]); + w + })); + } + } + if let Some((_, w)) = best { + return w; } // nowhere joined: at the end, a gap before it let mut out = lanes.to_vec(); diff --git a/src/ui_timetable/way.rs b/src/ui_timetable/way.rs index 47c0a573..ccb48076 100644 --- a/src/ui_timetable/way.rs +++ b/src/ui_timetable/way.rs @@ -33,7 +33,8 @@ impl TimetableUi { if doc.timetable.by_hand(name) { return saved_lanes(net, doc, name).unwrap_or_default(); } - self.shown.as_ref().filter(|s| s.0.eq_ignore_ascii_case(name) && s.3.ok()).map(|s| s.3.lanes.clone()).unwrap_or_default() + // (a way found only part of the way: picking goes on from where it stops) + self.shown.as_ref().filter(|s| s.0.eq_ignore_ascii_case(name)).map(|s| s.3.lanes.clone()).unwrap_or_default() } /// The trip's way set to `lanes`, picked by hand from now on. @@ -106,7 +107,7 @@ impl TimetableUi { } let mut remove: Option> = None; let shown = self.shown.as_ref().filter(|s| s.0 == name).map(|s| s.3.clone()); - egui::CollapsingHeader::new(icons::labelled(Icon::Route, &format!("{} ({})", tr("Paths of the way", "Пути маршрута"), lanes.len()))).id_salt(("tt way paths", lower(name))).default_open(false).show(ui, |ui| { + egui::CollapsingHeader::new(icons::labelled(Icon::Route, &format!("{} ({})", tr("Paths of the way", "Пути маршрута"), lanes.len()))).id_salt(("tt way paths", lower(name), self.way_edit)).default_open(self.way_edit).show(ui, |ui| { // (where the stops are, to trim the way before the first and after the last) let stop_at: Vec = shown.as_ref().filter(|r| r.lanes == lanes).map(|r| r.stops.iter().map(|s| s.0).collect()).unwrap_or_default(); ui.horizontal(|ui| { @@ -119,7 +120,7 @@ impl TimetableUi { } } }); - egui::ScrollArea::vertical().id_salt(("tt way list", lower(name))).max_height(260.0).show(ui, |ui| { + egui::ScrollArea::vertical().id_salt(("tt way list", lower(name))).max_height(480.0).show(ui, |ui| { for (k, &l) in lanes.iter().enumerate() { let lane = &net.lanes[l]; ui.horizontal(|ui| { From bbf253bc8c5a463ec4610d60b674c71ca39adcdb Mon Sep 17 00:00:00 2001 From: turbo-devv Date: Sun, 22 Nov 2026 09:29:31 -0500 Subject: [PATCH 2/6] Aerial imagery stays sharp round the camera on maps with many tiles With more than 64 tiles of pictures every tile's overlay went up at 512 pixels (about 60 cm a pixel on a 300 m tile), so adding the 65th tile suddenly turned all the imagery blurry, though the files in the imagery folder stay 4096 a side. Now the tile under the camera goes up at 4096, the eight round it at 2048 and the sixteen round those at 1024, following the camera; the far tiles keep what their number allows. Fixes #134 --- src/ui_geo.rs | 132 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 106 insertions(+), 26 deletions(-) diff --git a/src/ui_geo.rs b/src/ui_geo.rs index 4652ca28..2f7bbf2a 100644 --- a/src/ui_geo.rs +++ b/src/ui_geo.rs @@ -338,8 +338,8 @@ pub struct GeoUi { known: BTreeSet, // the overlay on the ground epoch: u64, - /// What each tile's texture shows (its file and the file's time). - shown: HashMap)>, + /// What each tile's texture shows (its file, the file's time and the texture's edge). + shown: HashMap, u32)>, load_tx: Sender<(PathBuf, TileKey, PathBuf, u32)>, loaded_rx: Receiver<(PathBuf, TileKey, Option)>, loading: BTreeSet, @@ -381,8 +381,9 @@ pub struct GeoUi { mini_pending: Vec<(TileKey, egui::ColorImage)>, /// Unloaded tiles beside loaded heights (their shared edge steps). edges: Vec, - /// The edge the pictures on the GPU were put up at (0: none up yet). - shown_side: u32, + /// The edge each held picture goes up at on the GPU, with the place and count it was + /// worked out for. + sides: Option<(HashMap, DVec2, usize)>, /// OMSI's own aerial photos for this map: the folder found beside it and how many tiles /// it has photos for (None: the map has none). aerial: Option<(PathBuf, usize)>, @@ -450,7 +451,7 @@ impl Default for GeoUi { mini: HashMap::new(), mini_pending: Vec::new(), edges: Vec::new(), - shown_side: 0, + sides: None, aerial: None, aerial_job: None, near: None, @@ -464,6 +465,44 @@ fn ts() -> f64 { tile_size() } +/// Edge of the textures on the GPU: the more of them are held at once, the smaller. What +/// counts is what is up on the card now, not how many tiles the map has: a map's own aerial +/// photos are 1024 or 2048 a side, and 485 of those kept at their own size would be 43 GB, +/// while a window of sixteen round the camera is a quarter of a gigabyte. +fn gpu_side(held: usize) -> u32 { + match held { + 0..=4 => 4096, + 5..=16 => 2048, + 17..=64 => 1024, + _ => 512, + } +} + +/// The edge of each held tile's texture: what their number allows (`gpu_side`), and more for +/// the tiles nearest `at`, where one looks - the one under it 4096, the eight round it 2048, the +/// sixteen round those 1024. Without that a map with more than 64 tiles of pictures showed +/// every one at 512 (60 cm a pixel on a 300 m tile), even the one being worked on; this way it +/// costs at most some 350 MB more on the card, whatever the map's size. +fn gpu_sides(held: &[TileKey], at: DVec2, tile: f64) -> HashMap { + let base = gpu_side(held.len()); + let half = DVec2::splat(tile * 0.5); + let mut by: Vec<(f64, TileKey)> = held.iter().map(|k| ((DVec2::new(k.0 as f64, k.1 as f64) * tile + half - at).length_squared(), *k)).collect(); + // (the key breaks a tie, so tiles as far as each other keep their edge from frame to frame) + by.sort_by(|a, b| a.0.total_cmp(&b.0).then(a.1.cmp(&b.1))); + by.iter() + .enumerate() + .map(|(i, (_, k))| { + let near = match i { + 0 => 4096, + 1..=8 => 2048, + 9..=24 => 1024, + _ => 0, + }; + (*k, base.max(near)) + }) + .collect() +} + impl GeoUi { /// A load is running. pub fn busy(&self) -> bool { @@ -1088,7 +1127,7 @@ impl GeoUi { let keys: Vec = pic.tiles().filter(|k| self.file.tile(*k).own.as_deref() == Some(id)).collect(); let (tx, rx) = channel(); let t = ts(); - let max = self.gpu_side(keys.len()); + let max = gpu_side(keys.len()); std::thread::spawn(move || { let n = if full { pic.piece_size(t, img.width()) } else { 384 }; for k in keys { @@ -1142,17 +1181,18 @@ impl GeoUi { // -------------------------------------------------------------- the overlay - /// Edge of the textures on the GPU: the more of them are held at once, the smaller. What - /// counts is what is up on the card now, not how many tiles the map has: a map's own aerial - /// photos are 1024 or 2048 a side, and 485 of those kept at their own size would be 43 GB, - /// while a window of sixteen round the camera is a quarter of a gigabyte. - fn gpu_side(&self, held: usize) -> u32 { - match held { - 0..=4 => 4096, - 5..=16 => 2048, - 17..=64 => 1024, - _ => 512, + /// The edge of each held tile's texture, worked out again only when the camera has moved + /// half a tile's width or another number of tiles is held, so a still view (or one moving + /// inside a tile) puts nothing up again. + fn sides_for(&mut self, held: &[TileKey], at: DVec2) -> HashMap { + if let Some((sides, from, was)) = &self.sides { + if *was == held.len() && (*from - at).length() < ts() * 0.5 && held.iter().all(|k| sides.contains_key(k)) { + return sides.clone(); + } } + let sides = gpu_sides(held, at, ts()); + self.sides = Some((sides.clone(), at, held.len())); + sides } /// The tiles whose photos are kept: the `photos_near` ones nearest `at`, or None for every @@ -1218,15 +1258,21 @@ impl GeoUi { // (the photos of the tiles round the camera, when the map asks for a window of them) let near = self.near_set(doc, at); // (the edge of the textures: what is held at once, not what the map has - a window of a - // few tiles can keep its photos near their own size, the whole map cannot) - let held = near.as_ref().map(|s| s.len()).unwrap_or_else(|| self.file.tiles.values().filter(|t| t.imagery.is_some() || t.own.is_some()).count()); - let max = self.gpu_side(held); - // (a different edge from the one the pictures went up at: they go up again) - if self.shown_side != max { - self.shown_side = max; - self.shown.clear(); - } + // few tiles can keep its photos near their own size, the whole map cannot - and larger + // round the camera; a tile whose edge changes goes up again) + let held: Vec = doc + .tiles + .keys() + .copied() + .filter(|k| near.as_ref().map(|s| s.contains(k)).unwrap_or(true)) + .filter(|k| { + let t = self.file.tile(*k); + t.imagery.is_some() || t.own.is_some() + }) + .collect(); + let sides = self.sides_for(&held, at); for k in doc.tiles.keys() { + let max = sides.get(k).copied().unwrap_or_else(|| gpu_side(held.len())); let t = self.file.tile(*k); if let Some(set) = &near { if !set.contains(k) { @@ -1242,7 +1288,7 @@ impl GeoUi { let want = self.picture_cached(&dir, *k); if let (Some(m), true) = (self.memory.get(k), t.own.is_none()) { // (held in memory only: put up once) - let now = (PathBuf::new(), None); + let now = (PathBuf::new(), None, max); if self.shown.get(k) != Some(&now) { self.shown.insert(*k, now); let mips = Mips::of((**m).clone(), max); @@ -1252,7 +1298,7 @@ impl GeoUi { } else { match want { Some((p, time)) => { - let now = (p, time); + let now = (p, time, max); if self.shown.get(k) != Some(&now) && !self.loading.contains(k) { let p = now.0.clone(); self.shown.insert(*k, now); @@ -1944,3 +1990,37 @@ impl Drop for GeoUi { self.flush(); } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn tiles_round_the_camera_stay_sharp_on_a_big_map() { + // 9 × 9 tiles of pictures, the camera in the middle of tile (4, 4) + let held: Vec = (0..9).flat_map(|x| (0..9).map(move |y| (x, y))).collect(); + let s = gpu_sides(&held, DVec2::new(4.5, 4.5) * 300.0, 300.0); + assert_eq!(s.len(), 81); + assert_eq!(s[&(4, 4)], 4096); + for k in [(3, 3), (4, 3), (5, 5), (3, 5)] { + assert_eq!(s[&k], 2048, "{k:?}"); + } + for k in [(2, 2), (6, 4), (4, 6), (2, 5)] { + assert_eq!(s[&k], 1024, "{k:?}"); + } + // (the far ones: what 81 tiles allow) + assert_eq!(s[&(0, 0)], 512); + assert_eq!(s[&(8, 8)], 512); + assert_eq!(s.values().filter(|e| **e > 512).count(), 25); + } + + #[test] + fn few_tiles_all_keep_their_size() { + let held = [(0, 0), (1, 0), (0, 1), (1, 1)]; + let s = gpu_sides(&held, DVec2::new(-5000.0, 0.0), 300.0); + assert!(s.values().all(|e| *e == 4096)); + let held: Vec = (0..4).flat_map(|x| (0..4).map(move |y| (x, y))).collect(); + let s = gpu_sides(&held, DVec2::ZERO, 300.0); + assert!(s.values().all(|e| *e >= 2048)); + } +} From 5ca890c34b88f8b20ac1f0227a942d9e991b3323 Mon Sep 17 00:00:00 2001 From: turbo-devv Date: Sun, 22 Nov 2026 09:33:16 -0500 Subject: [PATCH 3/6] An object marked Solid (collides) now really stops the bus in OMSI 2 and in a test drive Its .sco said [collision_mesh] but not [fixed], and OMSI 2 builds the collision shape only for [fixed] objects: any other is a loose body the bus drives through. A solid object now writes [fixed] beside its collision mesh (once, when the object it was made from already had one). Fixes #128 --- src/editable.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/editable.rs b/src/editable.rs index 9380f072..d9bdff43 100644 --- a/src/editable.rs +++ b/src/editable.rs @@ -288,6 +288,11 @@ pub fn save_on(roots: &Roots, rel: &str, src: &Source, ground: Option<&dyn Fn(gl let (x, _) = openmapper_mesh::export::to_x(&collision, &src.model.materials); std::fs::write(dir.join("model").join(&file), x)?; let _ = write!(sco, "[collision_mesh]\n{file}\n\n"); + // (Omsi.exe gives the collision mesh to the vehicles of a `[fixed]` object only: any + // other is a loose body the bus drives through; one kept from its object stays as it is) + if !src.extra.lines().any(|l| l.trim().eq_ignore_ascii_case("[fixed]")) { + sco.push_str("[fixed]\n\n"); + } } if let Some(sig) = &src.signal { write_signal_script(&dir, sig)?; @@ -724,6 +729,34 @@ mod tests { let _ = std::fs::remove_dir_all(&dir); } + #[test] + fn a_solid_object_is_fixed_and_its_collision_mesh_reads_back() { + let (dir, roots) = roots("solid"); + let mut src = primitive_source(openmapper_mesh::primitives::Primitive::Cube { size: Vec3::new(2.0, 1.0, 3.0) }); + src.collision = true; + let rel = new_rel(&roots, "My Map", "untitled"); + save(&roots, &rel, &src).unwrap(); + let path = omsi_cfg::resolve_path(&roots.content, &rel); + let sco = omsi_scenery::sco::SceneryObject::load(&path).unwrap(); + // Omsi.exe makes a collision shape for a [fixed] object only (#128) + assert!(sco.fixed); + let file = sco.collision_mesh.as_deref().unwrap(); + let m = omsi_o3d::load_mesh(&path.parent().unwrap().join("model").join(file)).unwrap(); + assert_eq!(m.triangles.len(), 12); + // a [fixed] kept from the object it was made from is not written twice + src.extra = "[fixed]\n".into(); + save(&roots, &rel, &src).unwrap(); + let text = std::fs::read_to_string(&path).unwrap(); + assert_eq!(text.matches("[fixed]").count(), 1, "{text}"); + // and one that does not collide is not fixed + src.extra.clear(); + src.collision = false; + save(&roots, &rel, &src).unwrap(); + let sco = omsi_scenery::sco::SceneryObject::load(&path).unwrap(); + assert!(!sco.fixed && sco.collision_mesh.is_none()); + let _ = std::fs::remove_dir_all(&dir); + } + #[test] fn a_mesh_file_comes_back_as_one_closed_surface_facing_out() { let cube = openmapper_mesh::primitives::Primitive::Cube { size: Vec3::ONE }.build(); From 8f9a34e6d3ba17d811aac9307f39c7882cdea546 Mon Sep 17 00:00:00 2001 From: turbo-devv Date: Sun, 22 Nov 2026 09:36:42 -0500 Subject: [PATCH 4/6] Objects put on a road drawn on from another road's end are drawn A road drawn on from the free end of another (also each new click while drawing a road on) counted its chain from 0 again, while it was linked to the road before it. A row's distance counts from the start of the chain, and the game - and the view with it - draws no row whose first object lies before its own spline by the links: an object put on the new road within the length of the road before it stood nowhere, in the editor as in the game. Further along the same road it was drawn, so some parts of a road seemed to swallow what was put on them. The new road's chain now goes on from the road it was drawn from. Fixes #131 --- src/editor.rs | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/editor.rs b/src/editor.rs index 85bc5e2f..bf83f0d1 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -4742,16 +4742,24 @@ impl Editor { } linked }; - if let Some((k, id, _)) = start.spline { + if let Some((k, id, at_end)) = start.spline { let first = made[0]; + // (drawn on from a road, the new road's chain goes on from that road's, as the game + // walks it along the links: counted from 0, a row near its start lay before its + // spline and was drawn neither by the game nor here, #131) + let from = doc.spline(k, id).map(|s| if at_end { crate::place::chain_offset_of(doc, s) + s.length } else { s.length }).unwrap_or(0.0); if link(doc, start.spline, first.1) { if let Some(t) = doc.tiles.get_mut(&first.0) { if let Some(s) = t.tile.splines.iter_mut().find(|s| s.id == first.1) { s.prev_id = id; } } + for &(mk, mid) in &made { + if let Some(s) = doc.tiles.get_mut(&mk).and_then(|t| t.tile.splines.iter_mut().find(|s| s.id == mid)) { + s.map_chain_offset = s.map_chain_offset.map(|o| o + from); + } + } } - let _ = k; } if let Some(e) = end { if let Some((_, id, _)) = e.spline { @@ -15982,6 +15990,31 @@ mod tests { assert_eq!(doc.spline((0, 0), 3).unwrap().prev_id, 0); } + /// A road drawn on from a free end counts its chain on from that road's (as the game walks + /// it along the links), so an object put on it near its start is drawn: counted from 0 it + /// lay before its spline and was not drawn, as the game draws it not (#131). + #[test] + fn an_object_put_on_a_road_drawn_on_from_an_end_is_drawn() { + let mut ed = editor(); + ed.follow_ground = false; + let mut assets = Assets::new(std::env::temp_dir().join("openmapper-no-omsi"), std::env::temp_dir().join("openmapper-no-content")); + // (on from spline 3's free end at (50, 80), 30 m along its chain) + let seg = roads::straight(DVec2::new(50.0, 80.0), DVec2::new(50.0, 110.0)).unwrap(); + let start = Anchor { pos: DVec3::new(50.0, 80.0, 0.0), heading: 0.0, spline: Some(((0, 0), 3, true)), ..Default::default() }; + let made = ed.build_road(&mut assets, "Splines\\road.sli", &[seg], 0.0, 0.0, start, None, 4.0).unwrap(); + ed.history.commit(); + // (a post 2 m right of the new road, 5 m along it) + add_object(ed.doc.as_mut().unwrap(), (0, 0), 50, 52.0, 85.0); + ed.attach_object_onto(&crate::library::Library::default(), (0, 0), 50, Some(made[0])).unwrap(); + let doc = ed.doc.as_ref().unwrap(); + let t = &doc.tiles[&(0, 0)].tile; + let a = t.spline_attachments.iter().find(|a| a.id == 50).unwrap(); + let objs = crate::place::row_objects(a, &t.splines, tile_origin((0, 0)), &crate::place::row_index(doc)); + assert_eq!(objs.len(), 1, "drawn: {:?}", a.offset); + assert!((objs[0].pose.pos.truncate() - DVec2::new(52.0, 85.0)).length() < 1e-3, "where it stood: {:?}", objs[0].pose.pos); + assert_eq!(doc.spline(made[0].0, made[0].1).unwrap().map_chain_offset, Some(30.0)); + } + /// An end that already continues into another piece is left as it is: the new road /// does not become that next piece. #[test] From 7f8f881ebf47d6c4940bac1203c0059b4f9bce19 Mon Sep 17 00:00:00 2001 From: turbo-devv Date: Sun, 22 Nov 2026 09:37:02 -0500 Subject: [PATCH 5/6] Changelog: the fixes of #128, #131, #134 and #135 --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 988de5fc..e80f0bc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ Releases are tagged `v`; the downloads are on the [Releases](https://github.com/openOMSI-org/openMapper/releases) page, each with the notes of its version from this file. +## Unreleased + +### Fixed +- **Lines: picking a trip's paths by hand no longer loops back to the start of the line** (#135, #130): a path clicked past the end of the way was put in as a way round between the line's first paths wherever it led back to them round the block. It now goes where it adds the least driving; a way round must replace part of the way or mend a gap. A trip whose way is found only part of the way keeps that part, so picking by hand goes on from where it stops instead of from nothing. The list of the way's paths opens while picking and shows more of them. +- **Aerial imagery stays sharp on maps with more than 64 tiles of pictures** (#134): every tile went up at 512 pixels. The tile under the camera now goes up at 4096, the eight round it at 2048 and the sixteen round those at 1024. +- **An object marked Solid (collides) stops the bus** (#128): its `.sco` lacked `[fixed]`, without which OMSI 2 gives vehicles no collision. +- **Objects put on a road drawn on from another road's end show** (#131): the new road's chain distance started at 0, so the game and the editor dropped objects within the old road's length of its start. + ## 0.2.1 - 2026-11-20 ### Changed From 467d642012858374562a61715ce653cf08f1de12 Mon Sep 17 00:00:00 2001 From: turbo-devv Date: Sun, 22 Nov 2026 09:44:17 -0500 Subject: [PATCH 6/6] Take out turn_end: turning a road's end no longer refits the road after it --- src/reshape.rs | 31 ------------------------------- 1 file changed, 31 deletions(-) diff --git a/src/reshape.rs b/src/reshape.rs index 79f6944f..526c2398 100644 --- a/src/reshape.rs +++ b/src/reshape.rs @@ -226,20 +226,6 @@ pub fn turn_this(doc: &Document, k: TileKey, id: i64, at_end: bool, heading: f64 Ok(Plan { pieces: vec![if at_end { mine } else { mine.reversed() }] }) } -/// Turn a spline's end (`at_end`, else its start) so the road runs heading `heading` there -/// (degrees, clockwise from north, the way the road itself runs). The end stays where it -/// is; the road bends to the new direction. A spline linked at that end follows, tangent -/// at the joint, its far end kept. -pub fn turn_end(doc: &Document, k: TileKey, id: i64, at_end: bool, heading: f64, locked: &dyn Fn(DVec2) -> bool) -> Result { - let s = doc.spline(k, id).ok_or("gone")?; - let e = ends_of(s, k); - let (p, z, now, arrive) = if at_end { (e.b.truncate(), e.b.z, e.hb, roads::norm_deg(heading)) } else { (e.a.truncate(), e.a.z, e.ha, roads::norm_deg(heading + 180.0)) }; - if angle_off(now, heading) < 0.05 { - return Ok(Plan::default()); - } - end_to(doc, k, id, at_end, p, Some(arrive), z, locked) -} - /// Carry a road's end along with what it is joined to (a junction moved or turned): to /// `p`, arriving there heading `arrive` (the way along the road towards that end), its height /// changed by `dz`. @@ -690,23 +676,6 @@ mod tests { assert!(angle_off(b.heading_at(b.length), 0.0) < 1e-6, "the end keeps its heading"); } - #[test] - fn turning_an_end_keeps_it_put_and_the_next_road_follows() { - let mut doc = flat_map(1); - add_spline(&mut doc, (0, 0), 1, 100.0, 100.0, 0.0, 40.0, 0, 2); - add_spline(&mut doc, (0, 0), 2, 100.0, 140.0, 0.0, 40.0, 1, 0); - let plan = turn_end(&doc, (0, 0), 1, true, 20.0, &|_| false).unwrap(); - apply(&mut doc, &plan); - let (a, b, _) = span(&doc, 1); - assert!((a.point_at(0.0).truncate() - DVec2::new(100.0, 100.0)).length() < 1e-4, "the start stays"); - assert!(a.heading_at(0.0).abs() < 1.0, "the start keeps its direction"); - assert!((b.end_point().truncate() - DVec2::new(100.0, 140.0)).length() < 1e-3, "the end stays put"); - assert!(angle_off(b.heading_at(b.length), 20.0) < 1.0, "the end turns to the heading asked for"); - let n = curve(&doc, 2); - assert!(angle_off(n.heading_at(0.0), 20.0) < 1.0, "the road joined there leaves along the same direction"); - assert!((n.end_point().truncate() - DVec2::new(100.0, 180.0)).length() < 1e-3, "that road's far end stays"); - } - #[test] fn a_joint_dragged_keeps_both_splines_tangent_and_linked() { let mut doc = flat_map(1);