Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ Releases are tagged `v<version>`; 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
Expand Down
33 changes: 33 additions & 0 deletions src/editable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down Expand Up @@ -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();
Expand Down
37 changes: 35 additions & 2 deletions src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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]
Expand Down
31 changes: 0 additions & 31 deletions src/reshape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Plan, &'static str> {
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`.
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions src/timetable/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<usize>> = (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));
Expand Down
12 changes: 10 additions & 2 deletions src/timetable/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,13 +441,22 @@ fn find_on(net: &Network, positions: &[Option<DVec3>], 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<Option<(f64, usize, f64)>>], ways: &[HashMap<(usize, usize), Vec<usize>>]) {
// 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];
Expand All @@ -470,5 +479,4 @@ fn find_on(net: &Network, positions: &[Option<DVec3>], left_hand: bool, ways: Wa
}
}
r.legs = legs;
r
}
54 changes: 54 additions & 0 deletions src/timetable/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>();
let mut add = |id: i64, pts: Vec<DVec3>| {
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<i64, usize> = (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::<Vec<_>>();
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::<Vec<_>>();
let mut add = |id: i64, pts: Vec<DVec3>| {
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::<Vec<_>>();
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<_>>(), 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]
Expand Down
Loading