@@ -1118,37 +1118,36 @@ impl WorldManager {
1118
1118
flags : world_model:: chunk:: PixelFlags :: Normal ,
1119
1119
material : 0 ,
1120
1120
} ;
1121
- for ( chunk_coord, chunk_encoded) in
1122
- self . chunk_storage . iter_mut ( ) . filter ( |( chunk_coord, _) | {
1123
- chunk_coord. 0 >= min_cx
1124
- && chunk_coord. 0 <= max_cx
1125
- && chunk_coord. 1 >= min_cy
1126
- && chunk_coord. 1 <= max_cy //TODO can filter more
1127
- } )
1128
- {
1129
- let chunk_start_x = chunk_coord. 0 * CHUNK_SIZE as i32 ;
1130
- let chunk_start_y = chunk_coord. 1 * CHUNK_SIZE as i32 ;
1131
- let mut chunk = Chunk :: default ( ) ;
1132
- chunk_encoded. apply_to_chunk ( & mut chunk) ;
1133
- for icx in 0 ..CHUNK_SIZE as i32 {
1134
- let cx = chunk_start_x + icx;
1135
- let dcx = cx - x;
1136
- let dx2 = dcx * dmx;
1137
- for icy in 0 ..CHUNK_SIZE as i32 {
1138
- let cy = chunk_start_y + icy;
1139
- let dcy = cy - y;
1140
- let m = ( ( dx2 + dcy * dmy) as f64 * dm2) . clamp ( 0.0 , 1.0 ) ;
1141
- let px = ( m * dmx as f64 ) as i32 ;
1142
- let py = ( m * dmy as f64 ) as i32 ;
1143
- let dx = dcx + px;
1144
- let dy = dcy - py;
1145
- if dx * dx + dy * dy <= r * r {
1146
- let px = icy as usize * CHUNK_SIZE + icx as usize ;
1147
- chunk. set_pixel ( px, air_pixel) ;
1121
+ for chunk_x in min_cx..=max_cx {
1122
+ for chunk_y in min_cy..=max_cy {
1123
+ //TODO can filter closer to line
1124
+ let coord = ChunkCoord ( chunk_x, chunk_y) ;
1125
+ let chunk_start_x = chunk_x * CHUNK_SIZE as i32 ;
1126
+ let chunk_start_y = chunk_y * CHUNK_SIZE as i32 ;
1127
+ let mut chunk = Chunk :: default ( ) ;
1128
+ if let Some ( chunk_encoded) = self . chunk_storage . get ( & coord) {
1129
+ chunk_encoded. apply_to_chunk ( & mut chunk)
1130
+ }
1131
+ for icx in 0 ..CHUNK_SIZE as i32 {
1132
+ let cx = chunk_start_x + icx;
1133
+ let dcx = cx - x;
1134
+ let dx2 = dcx * dmx;
1135
+ for icy in 0 ..CHUNK_SIZE as i32 {
1136
+ let cy = chunk_start_y + icy;
1137
+ let dcy = cy - y;
1138
+ let m = ( ( dx2 + dcy * dmy) as f64 * dm2) . clamp ( 0.0 , 1.0 ) ;
1139
+ let px = ( m * dmx as f64 ) as i32 ;
1140
+ let py = ( m * dmy as f64 ) as i32 ;
1141
+ let dx = dcx - px;
1142
+ let dy = dcy - py;
1143
+ if dx * dx + dy * dy <= r * r {
1144
+ let px = icy as usize * CHUNK_SIZE + icx as usize ;
1145
+ chunk. set_pixel ( px, air_pixel) ;
1146
+ }
1148
1147
}
1149
1148
}
1149
+ self . chunk_storage . insert ( coord, chunk. to_chunk_data ( ) ) ;
1150
1150
}
1151
- * chunk_encoded = chunk. to_chunk_data ( ) ;
1152
1151
}
1153
1152
}
1154
1153
pub ( crate ) fn cut_through_world_circle ( & mut self , x : i32 , y : i32 , r : i32 , mat : Option < u16 > ) {
@@ -1299,12 +1298,9 @@ impl WorldManager {
1299
1298
let theta = t * ( n as f32 + 0.5 ) ;
1300
1299
let end_x = x + ( r as f32 * theta. cos ( ) ) as i32 ;
1301
1300
let end_y = y + ( r as f32 * theta. sin ( ) ) as i32 ;
1302
- let mult = if ( 8.0 * theta / TAU ) . floor ( ) as u32 % 2 == 0 {
1303
- ( theta % ( TAU / 8.0 ) ) . cos ( )
1304
- } else {
1305
- ( theta % ( TAU / 4.0 ) ) . sin ( )
1306
- }
1307
- . recip ( ) ;
1301
+ let mult = ( ( ( theta + TAU / 8.0 ) % ( TAU / 4.0 ) ) - TAU / 8.0 )
1302
+ . cos ( )
1303
+ . recip ( ) ;
1308
1304
if let Some ( ( ex, ey) ) = self . do_ray ( x, y, end_x, end_y, ray, d, mult) {
1309
1305
let dx = ex - x;
1310
1306
let dy = ey - y;
0 commit comments