@@ -2,9 +2,7 @@ use bevy::prelude::*;
22use noise:: { NoiseFn , OpenSimplex } ;
33use rand:: { rngs:: SmallRng , RngExt , SeedableRng } ;
44
5- use crate :: { assets:: CityAssets , Car , Road } ;
6- #[ cfg( feature = "traffic" ) ]
7- use crate :: { traffic, CarAtStopState , CarState } ;
5+ use crate :: { assets:: CityAssets , traffic, Car , CarAtStopState , CarState , Road } ;
86#[ derive( Component ) ]
97pub struct CityRoot ;
108
@@ -88,30 +86,25 @@ fn spawn_roads_and_cars<R: RngExt>(
8886 let x = offset. x ;
8987 let z = offset. z ;
9088
91- #[ cfg_attr( not( feature = "traffic" ) , allow( unused_variables) ) ]
9289 let crossroad = commands
9390 . spawn ( (
9491 SceneRoot ( assets. crossroad . clone ( ) ) ,
9592 Transform :: from_xyz ( x, 0.0 , z) ,
96- #[ cfg ( feature = "traffic" ) ]
9793 traffic:: TrafficLight :: new ( ( x * 7.3 + z * 3.7 ) . rem_euclid ( traffic:: CYCLE_DURATION ) ) ,
9894 ) )
9995 . id ( ) ;
10096
101- #[ cfg( feature = "traffic" ) ]
102- {
103- // 2 traffic lights at diagonal corners,
104- for ( dx, dz, y_rot) in [
105- ( -0.5_f32 , -0.5_f32 , 0.0_f32 ) , // NW corner
106- ( 0.5_f32 , -0.5_f32 , -std:: f32:: consts:: FRAC_PI_2 ) , // NE corner
107- ] {
108- commands. spawn ( (
109- SceneRoot ( assets. traffic_light . clone ( ) ) ,
110- Transform :: from_translation ( Vec3 :: new ( x + dx, 0.0 , z + dz) )
111- . with_rotation ( Quat :: from_rotation_y ( y_rot) )
112- . with_scale ( Vec3 :: splat ( 0.3 ) ) ,
113- ) ) ;
114- }
97+ // 2 traffic lights at diagonal corners
98+ for ( dx, dz, y_rot) in [
99+ ( -0.5_f32 , -0.5_f32 , 0.0_f32 ) ,
100+ ( 0.5_f32 , -0.5_f32 , std:: f32:: consts:: FRAC_PI_2 ) ,
101+ ] {
102+ commands. spawn ( (
103+ SceneRoot ( assets. traffic_light . clone ( ) ) ,
104+ Transform :: from_translation ( Vec3 :: new ( x + dx, 0.0 , z + dz) )
105+ . with_rotation ( Quat :: from_rotation_y ( y_rot) )
106+ . with_scale ( Vec3 :: splat ( 0.3 ) ) ,
107+ ) ) ;
115108 }
116109
117110 let max_car_density = 0.4 ;
@@ -130,7 +123,6 @@ fn spawn_roads_and_cars<R: RngExt>(
130123 Road {
131124 start : Vec3 :: new ( 0.75 , 0.0 , 0.0 ) ,
132125 end : Vec3 :: new ( 0.75 + ( 0.5 * car_count as f32 ) , 0.0 , 0.0 ) ,
133- #[ cfg( feature = "traffic" ) ]
134126 intersection : crossroad,
135127 } ,
136128 ) )
@@ -157,11 +149,8 @@ fn spawn_roads_and_cars<R: RngExt>(
157149 distance_traveled : i as f32 * 0.5 ,
158150 dir : -1.0 ,
159151 offset : Vec3 :: new ( 4.25 , 0.0 , -0.15 ) ,
160- #[ cfg( feature = "traffic" ) ]
161152 car_state : CarState :: Driving ,
162- #[ cfg( feature = "traffic" ) ]
163153 car_at_stop_state : CarAtStopState :: Default ,
164- #[ cfg( feature = "traffic" ) ]
165154 next_lane : None ,
166155 } ,
167156 ) ) ;
@@ -180,11 +169,8 @@ fn spawn_roads_and_cars<R: RngExt>(
180169 distance_traveled : i as f32 * 0.5 ,
181170 dir : 1.0 ,
182171 offset : Vec3 :: new ( -0.25 , 0.0 , 0.15 ) ,
183- #[ cfg( feature = "traffic" ) ]
184172 car_state : CarState :: Driving ,
185- #[ cfg( feature = "traffic" ) ]
186173 car_at_stop_state : CarAtStopState :: Default ,
187- #[ cfg( feature = "traffic" ) ]
188174 next_lane : None ,
189175 } ,
190176 ) ) ;
@@ -201,7 +187,6 @@ fn spawn_roads_and_cars<R: RngExt>(
201187 Road {
202188 start : Vec3 :: new ( 0.0 , 0.0 , 0.75 ) ,
203189 end : Vec3 :: new ( 0.0 , 0.0 , 0.75 + ( 0.5 * car_count as f32 ) ) ,
204- #[ cfg( feature = "traffic" ) ]
205190 intersection : crossroad,
206191 } ,
207192 ) )
@@ -225,11 +210,8 @@ fn spawn_roads_and_cars<R: RngExt>(
225210 distance_traveled : i as f32 * 0.5 ,
226211 dir : 1.0 ,
227212 offset : Vec3 :: new ( -0.15 , 0.0 , -0.25 ) ,
228- #[ cfg( feature = "traffic" ) ]
229213 car_state : CarState :: Driving ,
230- #[ cfg( feature = "traffic" ) ]
231214 car_at_stop_state : CarAtStopState :: Default ,
232- #[ cfg( feature = "traffic" ) ]
233215 next_lane : None ,
234216 } ,
235217 ) ) ;
@@ -245,11 +227,8 @@ fn spawn_roads_and_cars<R: RngExt>(
245227 distance_traveled : i as f32 * 0.5 ,
246228 dir : -1.0 ,
247229 offset : Vec3 :: new ( 0.15 , 0.0 , 2.75 ) ,
248- #[ cfg( feature = "traffic" ) ]
249230 car_state : CarState :: Driving ,
250- #[ cfg( feature = "traffic" ) ]
251231 car_at_stop_state : CarAtStopState :: Default ,
252- #[ cfg( feature = "traffic" ) ]
253232 next_lane : None ,
254233 } ,
255234 ) ) ;
0 commit comments