Skip to content

Commit

Permalink
rename Terrain -> Environment in simulation
Browse files Browse the repository at this point in the history
as this struct encapsulates the Terrain + Trees + ... (cliffs? water?
wildlife?..)
  • Loading branch information
Uriopass committed Dec 18, 2023
1 parent df8b813 commit 1d000cb
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 66 deletions.
2 changes: 1 addition & 1 deletion native_app/src/audio/ambient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl Ambient {
if volume > 0.0 {
let mut matches = 0;

for _ in map.terrain.trees.query(bbox.ll, bbox.ur) {
for _ in map.environment.trees.query(bbox.ll, bbox.ur) {
matches += 1;
if matches > 50 {
break;
Expand Down
8 changes: 4 additions & 4 deletions native_app/src/game_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl engine::framework::State for State {
self.uiw.write::<InputMap>().ray = ray;

if let Some(ray) = ray {
let cast = map.terrain.raycast(ray);
let cast = map.environment.raycast(ray);

self.uiw.write::<InputMap>().unprojected = cast.map(|x| x.0);
self.uiw.write::<InputMap>().unprojected_normal = cast.map(|x| x.1);
Expand Down Expand Up @@ -291,8 +291,8 @@ impl State {
ctx.delta,
&self.uiw.read::<InputMap>(),
&self.uiw.read::<Settings>(),
map.terrain.bounds(),
|p| map.terrain.height(p),
map.environment.bounds(),
|p| map.environment.height(p),
);
*self.uiw.write::<Camera>() = self.uiw.read::<OrbitCamera>().camera;

Expand Down Expand Up @@ -322,7 +322,7 @@ impl State {
unsafe {
for v in &geom::DEBUG_OBBS {
immediate
.obb(*v, map.terrain.height(v.center()).unwrap_or(0.0) + 8.0)
.obb(*v, map.environment.height(v.center()).unwrap_or(0.0) + 8.0)
.color(col);
}
for v in &geom::DEBUG_SPLINES {
Expand Down
4 changes: 2 additions & 2 deletions native_app/src/gui/roadbuild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub fn roadbuild(sim: &Simulation, uiworld: &mut UiWorld) {
let grid_size = 20.0;
let mousepos = if state.snap_to_grid {
let v = unproj.xy().snap(grid_size, grid_size);
v.z(unwrap_ret!(map.terrain.height(v)) + 0.3 + state.height_offset)
v.z(unwrap_ret!(map.environment.height(v)) + 0.3 + state.height_offset)
} else {
unproj.up(0.3 + state.height_offset)
};
Expand Down Expand Up @@ -438,7 +438,7 @@ impl RoadBuildResource {
terrain_height,
pos,
..
} in simulation::map::Road::pylons_positions(&p, &map.terrain)
} in simulation::map::Road::pylons_positions(&p, &map.environment)
{
immdraw
.circle(pos.xy().z(terrain_height + 0.1), patwidth * 0.5)
Expand Down
3 changes: 2 additions & 1 deletion native_app/src/gui/windows/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,8 @@ pub fn debug_spatialmap(tess: &mut Tesselator<true>, sim: &Simulation, _: &UiWor
for r in map.spatial_map().debug_grid() {
tess.set_color(LinearColor::BLUE.a(0.1));
tess.draw_rect_cos_sin(
r.center().z(map.terrain.height(r.center()).unwrap_or(0.0)),
r.center()
.z(map.environment.height(r.center()).unwrap_or(0.0)),
r.w(),
r.h(),
Vec2::X,
Expand Down
20 changes: 10 additions & 10 deletions native_app/src/rendering/map_rendering/map_mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use engine::{
};
use geom::{minmax, vec2, vec3, Color, LinearColor, PolyLine3, Polygon, Radians, Vec2, Vec3};
use simulation::map::{
Building, BuildingKind, CanonicalPosition, Intersection, LaneKind, Lanes, LotKind, Map,
MapSubscriber, ProjectFilter, ProjectKind, PylonPosition, Road, Roads, SubscriberChunkID,
Terrain, Turn, TurnKind, UpdateType, CROSSWALK_WIDTH,
Building, BuildingKind, CanonicalPosition, Environment, Intersection, LaneKind, Lanes, LotKind,
Map, MapSubscriber, ProjectFilter, ProjectKind, PylonPosition, Road, Roads, SubscriberChunkID,
Turn, TurnKind, UpdateType, CROSSWALK_WIDTH,
};
use simulation::souls::goods_company::GoodsCompanyRegistry;
use simulation::Simulation;
Expand Down Expand Up @@ -586,7 +586,7 @@ impl MapBuilders {
let lanes = map.lanes();
let roads = map.roads();
let lots = map.lots();
let terrain = &map.terrain;
let env = &map.environment;

for road in chunk_roads {
let road = &roads[road];
Expand All @@ -597,7 +597,7 @@ impl MapBuilders {
let first_dir = unwrap_cont!(cut.first_dir());
let last_dir = unwrap_cont!(cut.last_dir());

road_pylons(&mut self.tess_map.meshbuilder, terrain, road);
road_pylons(&mut self.tess_map.meshbuilder, env, road);

self.tess_map.normal.z = -1.0;
self.tess_map.draw_polyline_full(
Expand Down Expand Up @@ -674,7 +674,7 @@ impl MapBuilders {

self.crosswalks(inter, lanes);

inter_pylon(&mut self.tess_map.meshbuilder, terrain, inter, roads);
inter_pylon(&mut self.tess_map.meshbuilder, env, inter, roads);
intersection_mesh(&mut self.tess_map, &hig_col, inter, roads);

// Walking corners
Expand Down Expand Up @@ -819,19 +819,19 @@ fn add_polyon(
quad(3, 0, 7, 4, d2p);
}

fn road_pylons(meshb: &mut MeshBuilder<false>, terrain: &Terrain, road: &Road) {
for pylon in Road::pylons_positions(road.interfaced_points(), terrain) {
fn road_pylons(meshb: &mut MeshBuilder<false>, env: &Environment, road: &Road) {
for pylon in Road::pylons_positions(road.interfaced_points(), env) {
add_polyon(meshb, road.width * 0.5, pylon);
}
}

fn inter_pylon(
meshb: &mut MeshBuilder<false>,
terrain: &Terrain,
env: &Environment,
inter: &Intersection,
roads: &Roads,
) {
let h = unwrap_ret!(terrain.height(inter.pos.xy()));
let h = unwrap_ret!(env.height(inter.pos.xy()));
if (h - inter.pos.z).abs() <= 2.0 {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion native_app/src/rendering/map_rendering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl MapRenderer {
meshb: MapMeshHandler::new(gfx, sim),
trees: TreesRender::new(gfx, &sim.map()),
terrain: TerrainRender::new(gfx, sim),
water: Water::new(gfx, sim.map().terrain.bounds()),
water: Water::new(gfx, sim.map().environment.bounds()),
lamps: LampsRender::new(&sim.map()),
}
}
Expand Down
4 changes: 2 additions & 2 deletions native_app/src/rendering/map_rendering/terrain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct TerrainRender {

impl TerrainRender {
pub fn new(gfx: &mut GfxContext, sim: &Simulation) -> Self {
let (w, h) = sim.map().terrain.size();
let (w, h) = sim.map().environment.size();

let terrain = EngineTerrainRender::new(gfx, w as u32, h as u32);

Expand All @@ -29,7 +29,7 @@ impl TerrainRender {
}

pub fn update(&mut self, ctx: &mut Context, map: &Map) {
let ter = &map.terrain;
let ter = &map.environment;

if self.terrain_sub.take_cleared() {
for (chunk_id, chunk) in ter.chunks() {
Expand Down
8 changes: 4 additions & 4 deletions native_app/src/rendering/map_rendering/trees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ impl TreesRender {
self.tree_builder.instances.clear();

let aabb = chunkid.bbox();
map.terrain
map.environment
.trees
.query_aabb_visitor(aabb.ll, aabb.ur, |obj| {
let Some((_, t)) = map.terrain.trees.get(obj.0) else {
let Some((_, t)) = map.environment.trees.get(obj.0) else {
return;
};
self.tree_builder.instances.push(MeshInstance {
pos: t.pos.z(map.terrain.height(t.pos).unwrap_or_default()),
pos: t.pos.z(map.environment.height(t.pos).unwrap_or_default()),
dir: t.dir.z0() * t.size * 0.2,
tint: ((1.0 - t.size * 0.05) * t.col * LinearColor::WHITE).a(1.0),
});
Expand Down Expand Up @@ -109,7 +109,7 @@ impl TreesRender {
let chunkcenter = cid.center().z0();
let max_height = cid
.convert()
.filter_map(|c| map.terrain.get_chunk(c))
.filter_map(|c| map.environment.get_chunk(c))
.map(HeightmapChunk::max_height)
.fold(0.0, f32::max);

Expand Down
28 changes: 14 additions & 14 deletions simulation/src/map/map.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::map::serializing::SerializedMap;
use crate::map::{
Building, BuildingID, BuildingKind, Intersection, IntersectionID, Lane, LaneID, LaneKind,
LanePattern, Lot, LotID, LotKind, MapSubscriber, MapSubscribers, ParkingSpotID, ParkingSpots,
ProjectFilter, ProjectKind, Road, RoadID, RoadSegmentKind, SpatialMap, SubscriberChunkID,
TerraformKind, Terrain, UpdateType, Zone,
Building, BuildingID, BuildingKind, Environment, Intersection, IntersectionID, Lane, LaneID,
LaneKind, LanePattern, Lot, LotID, LotKind, MapSubscriber, MapSubscribers, ParkingSpotID,
ParkingSpots, ProjectFilter, ProjectKind, Road, RoadID, RoadSegmentKind, SpatialMap,
SubscriberChunkID, TerraformKind, UpdateType, Zone,
};
use crate::utils::time::Tick;
use common::descriptions::BuildingGen;
Expand Down Expand Up @@ -34,7 +34,7 @@ pub struct Map {
pub(crate) lots: Lots,
pub(crate) spatial_map: SpatialMap,
pub(crate) bkinds: BTreeMap<BuildingKind, Vec<BuildingID>>,
pub terrain: Terrain,
pub environment: Environment,
pub parking: ParkingSpots,
pub subscribers: MapSubscribers,
}
Expand All @@ -57,7 +57,7 @@ impl Map {
parking: ParkingSpots::default(),
buildings: Buildings::default(),
lots: Lots::default(),
terrain: Terrain::default(),
environment: Environment::default(),
spatial_map: SpatialMap::default(),
bkinds: Default::default(),
subscribers: Default::default(),
Expand Down Expand Up @@ -99,7 +99,7 @@ impl Map {

pub fn dispatch_all(&self) {
self.subscribers.dispatch_clear();
let bounds = self.terrain.bounds();
let bounds = self.environment.bounds();
let ll = SubscriberChunkID::new(bounds.ll);
let ur = SubscriberChunkID::new(bounds.ur);
for x in ll.0..ur.0 {
Expand Down Expand Up @@ -177,7 +177,7 @@ impl Map {
};
f(z);

self.terrain.remove_trees_near(&z.poly, |tree_chunk| {
self.environment.remove_trees_near(&z.poly, |tree_chunk| {
self.subscribers
.dispatch_chunk(UpdateType::Terrain, tree_chunk)
});
Expand Down Expand Up @@ -214,7 +214,7 @@ impl Map {

self.clean_lots_inner(self.spatial_map.query(obb, ProjectFilter::LOT).collect());

self.terrain
self.environment
.remove_trees_near(obb.expand(10.0), |tree_chunk| {
self.subscribers
.dispatch_chunk(UpdateType::Terrain, tree_chunk)
Expand All @@ -223,7 +223,7 @@ impl Map {
let v = Building::make(
&mut self.buildings,
&mut self.spatial_map,
&self.terrain,
&self.environment,
*obb,
kind,
gen,
Expand Down Expand Up @@ -255,7 +255,7 @@ impl Map {
let v = Building::make(
&mut self.buildings,
&mut self.spatial_map,
&self.terrain,
&self.environment,
lot.shape,
BuildingKind::House,
BuildingGen::House,
Expand Down Expand Up @@ -338,7 +338,7 @@ impl Map {
slope: Option<(Vec3, Vec3)>,
) {
let modified = self
.terrain
.environment
.terraform(tick, kind, center, radius, amount, level, slope);

for id in modified {
Expand All @@ -349,7 +349,7 @@ impl Map {
pub fn clear(&mut self) {
info!("clear");
let before = std::mem::replace(self, Self::empty());
self.terrain = before.terrain;
self.environment = before.environment;
self.subscribers.dispatch_clear();

self.check_invariants();
Expand Down Expand Up @@ -564,7 +564,7 @@ impl Map {
let r = &self.roads[id];
let mut b = r.boldline();
b.expand(40.0);
self.terrain.remove_trees_near(&b, |tree_chunk| {
self.environment.remove_trees_near(&b, |tree_chunk| {
self.subscribers
.dispatch_chunk(UpdateType::Terrain, tree_chunk)
});
Expand Down
6 changes: 3 additions & 3 deletions simulation/src/map/objects/building.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::map::procgen::{gen_exterior_farm, gen_exterior_house, ColoredMesh};
use crate::map::{Buildings, LanePattern, SpatialMap, Terrain};
use crate::map::{Buildings, Environment, LanePattern, SpatialMap};
use crate::souls::goods_company::GoodsCompanyID;
use common::descriptions::BuildingGen;
use egui_inspect::debug_inspect_impl;
Expand Down Expand Up @@ -84,13 +84,13 @@ impl Building {
pub fn make(
buildings: &mut Buildings,
spatial_map: &mut SpatialMap,
terrain: &Terrain,
env: &Environment,
obb: OBB,
kind: BuildingKind,
gen: BuildingGen,
zone: Option<Zone>,
) -> Option<BuildingID> {
let at = obb.center().z(terrain.height(obb.center())?);
let at = obb.center().z(env.height(obb.center())?);
let axis = (obb.corners[1] - obb.corners[0]).normalize();
let size = obb.corners[0].distance(obb.corners[1]);

Expand Down
2 changes: 1 addition & 1 deletion simulation/src/map/objects/lot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Lot {
axis: Vec2,
size: f32,
) -> Option<LotID> {
let height = map.terrain.height(at.xy())?;
let height = map.environment.height(at.xy())?;
if (height - at.z).abs() > 1.0 {
return None;
}
Expand Down
8 changes: 4 additions & 4 deletions simulation/src/map/objects/road.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::map::{
Intersection, IntersectionID, Lane, LaneDirection, LaneID, LaneKind, LanePattern, Lanes,
ParkingSpots, Roads, SpatialMap, Terrain,
Environment, Intersection, IntersectionID, Lane, LaneDirection, LaneID, LaneKind, LanePattern,
Lanes, ParkingSpots, Roads, SpatialMap,
};
use geom::Spline3;
use geom::{BoldLine, PolyLine3};
Expand Down Expand Up @@ -238,12 +238,12 @@ impl Road {

pub fn pylons_positions<'a>(
interfaced_points: &'a PolyLine3,
terrain: &'a Terrain,
env: &'a Environment,
) -> impl Iterator<Item = PylonPosition> + 'a {
interfaced_points
.equipoints_dir(80.0, true)
.filter_map(move |(pos, dir)| {
let h = terrain.height(pos.xy())?;
let h = env.height(pos.xy())?;
if (h - pos.z).abs() <= 2.0 {
return None;
}
Expand Down
10 changes: 5 additions & 5 deletions simulation/src/map/serializing.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::map::{
BuildingID, Buildings, Intersections, Lanes, Lots, Map, ParkingSpots, Roads, SpatialMap,
Terrain,
BuildingID, Buildings, Environment, Intersections, Lanes, Lots, Map, ParkingSpots, Roads,
SpatialMap,
};
use crate::BuildingKind;
use serde::{Deserialize, Serialize};
Expand All @@ -14,7 +14,7 @@ pub(crate) struct SerializedMap {
pub lanes: Lanes,
pub parking: ParkingSpots,
pub lots: Lots,
pub terrain: Terrain,
pub environment: Environment,
pub bkinds: BTreeMap<BuildingKind, Vec<BuildingID>>,
}

Expand All @@ -27,7 +27,7 @@ impl From<&Map> for SerializedMap {
lanes: m.lanes.clone(),
parking: m.parking.clone(),
lots: m.lots.clone(),
terrain: m.terrain.clone(),
environment: m.environment.clone(),
bkinds: m.bkinds.clone(),
}
}
Expand All @@ -44,7 +44,7 @@ impl From<SerializedMap> for Map {
spatial_map,
lots: sel.lots,
parking: sel.parking,
terrain: sel.terrain,
environment: sel.environment,
bkinds: sel.bkinds,
subscribers: Default::default(),
}
Expand Down
Loading

0 comments on commit 1d000cb

Please sign in to comment.