euv_core/game/engine3d/city_eco/
impl.rs1use super::*;
2
3impl TrafficLightPhase3D {
5 #[must_use]
16 pub fn from_cycle_time(time_secs: f32, offset_secs: f32) -> Self {
17 let wrapped: f32 = (time_secs + offset_secs).rem_euclid(TRAFFIC_CYCLE_TOTAL_SECS);
18 if wrapped < TRAFFIC_PHASE_GREEN_SECS {
19 Self::Green
20 } else if wrapped < TRAFFIC_PHASE_GREEN_SECS + TRAFFIC_PHASE_AMBER_SECS {
21 Self::Amber
22 } else {
23 Self::Red
24 }
25 }
26}
27
28impl Default for CityEcosystemState3D {
30 fn default() -> Self {
36 let boids_cfg: BoidsConfig = BoidsConfig {
37 perception_radius: 26.0,
38 separation_radius: 7.5,
39 separation_weight: 2.35,
40 alignment_weight: 1.25,
41 cohesion_weight: 1.05,
42 obstacle_weight: 4.5,
43 wander_weight: 0.45,
44 goal_weight: 1.35,
45 };
46 Self {
47 populated: false,
48 traffic_signals: Vec::new(),
49 clouds: Vec::new(),
50 bird_flock: BoidsFlockSolver::new(boids_cfg, CITY_ECO_BOIDS_SEED),
51 birds: Vec::new(),
52 wind_sway_props: Vec::new(),
53 river_water_objects: Vec::new(),
54 summary: CityEcosystemSummary3D::default(),
55 }
56 }
57}
58
59impl CityOccupancyTracker3D {
61 #[must_use]
71 pub(crate) fn from_world(world: &World3D) -> Self {
72 let mut occupied_boxes: Vec<AxisAlignedBox3D> =
73 Vec::with_capacity(world.get_objects().len() + 384);
74 for obj in world.get_objects().iter() {
75 if obj.get_solid_collider() && !obj.get_is_dynamic() {
76 occupied_boxes.push(obj.get_world_bounds());
77 }
78 }
79 let ground_bounds: (f32, f32, f32, f32) = world.ground_play_bounds().unwrap_or((
80 CITY_GROUND_X_MIN,
81 CITY_GROUND_X_MAX,
82 CITY_GROUND_Z_MIN,
83 CITY_GROUND_Z_MAX,
84 ));
85 Self {
86 occupied_boxes,
87 ground_bounds,
88 }
89 }
90
91 #[must_use]
102 pub(crate) fn can_place_static(&self, candidate: AxisAlignedBox3D, margin: f32) -> bool {
103 let (min_x, max_x, min_z, max_z): (f32, f32, f32, f32) = self.get_ground_bounds();
104 let cmin: Vec3 = candidate.get_min();
105 let cmax: Vec3 = candidate.get_max();
106 if cmin.get_x() < min_x + 0.8
107 || cmax.get_x() > max_x - 0.8
108 || cmin.get_z() < min_z + 0.8
109 || cmax.get_z() > max_z - 0.8
110 {
111 return false;
112 }
113 let pad: f32 = margin.max(0.02);
114 for existing in self.get_occupied_boxes().iter() {
115 let emin: Vec3 = existing.get_min();
116 let emax: Vec3 = existing.get_max();
117 let ox: f32 = cmax.get_x().min(emax.get_x()) - cmin.get_x().max(emin.get_x());
118 let oy: f32 = cmax.get_y().min(emax.get_y()) - cmin.get_y().max(emin.get_y());
119 let oz: f32 = cmax.get_z().min(emax.get_z()) - cmin.get_z().max(emin.get_z());
120 if ox > -pad && oy > -pad && oz > -pad {
121 return false;
122 }
123 }
124 true
125 }
126
127 pub(crate) fn reserve_static(&mut self, bounds: AxisAlignedBox3D) {
133 self.get_mut_occupied_boxes().push(bounds);
134 }
135}