145 // clear tiles, but keep our textures for potential re-use |
145 // clear tiles, but keep our textures for potential re-use |
146 self.tiles.clear(); |
146 self.tiles.clear(); |
147 |
147 |
148 let tw = self.tile_size.width; |
148 let tw = self.tile_size.width; |
149 let th = self.tile_size.height; |
149 let th = self.tile_size.height; |
150 let lw = land.width(); |
150 let lw = land.width() as u32; |
151 let lh = land.height(); |
151 let lh = land.height() as u32; |
152 let num_tile_x = lw / tw; |
152 let num_tile_x = lw / tw; |
153 let num_tile_y = lh / th; |
153 let num_tile_y = lh / th; |
154 |
154 |
155 self.num_tile_x = num_tile_x; |
155 self.num_tile_x = num_tile_x; |
156 |
156 |
157 for y in 0..num_tile_y { |
157 for y in 0..num_tile_y { |
158 for x in 0..num_tile_x { |
158 for x in 0..num_tile_x { |
159 let idx = x + y * num_tile_x; |
159 let idx = (x + y * num_tile_x) as usize; |
160 |
160 |
161 let (data, stride) = { |
161 let (data, stride) = { |
162 let bpp = 4; |
162 let bpp = 4; |
163 |
163 |
164 let offset = x * tw * bpp + y * th * lw * bpp; |
164 let offset = x * tw * bpp + y * th * lw * bpp; |
165 |
165 |
166 let data = unsafe { &land.as_bytes()[offset..] }; |
166 let data = unsafe { &land.as_bytes()[offset as usize..] }; |
167 let stride = land.width(); |
167 let stride = land.width(); |
168 |
168 |
169 (data, NonZeroU32::new(stride as u32)) |
169 (data, NonZeroU32::new(stride as u32)) |
170 }; |
170 }; |
171 |
171 |
217 self.tile_indices.clear(); |
217 self.tile_indices.clear(); |
218 self.tile_draw_calls.clear(); |
218 self.tile_draw_calls.clear(); |
219 self.index_offset = 0; |
219 self.index_offset = 0; |
220 |
220 |
221 for (idx, tile) in self.tiles.iter().enumerate() { |
221 for (idx, tile) in self.tiles.iter().enumerate() { |
222 let tile_x = idx % self.num_tile_x; |
222 let tile_x = idx as u32 % self.num_tile_x; |
223 let tile_y = idx / self.num_tile_x; |
223 let tile_y = idx as u32 / self.num_tile_x; |
224 let tile_w = self.tile_size.width; |
224 let tile_w = self.tile_size.width; |
225 let tile_h = self.tile_size.width; |
225 let tile_h = self.tile_size.width; |
226 |
226 |
227 let origin = Point::new((tile_x * tile_w) as i32, (tile_y * tile_h) as i32); |
227 let origin = Point::new((tile_x * tile_w) as i32, (tile_y * tile_h) as i32); |
228 let tile_rect = Rect::from_size(origin, self.tile_size); |
228 let tile_rect = Rect::from_size(origin, self.tile_size); |