|
@@ -123,10 +123,20 @@ impl MainState {
|
123
|
123
|
SceneItemType::Soldier,
|
124
|
124
|
ScenePoint::new((x as f32 * 24.0) + 100.0, (y as f32 * 24.0) + 100.0),
|
125
|
125
|
ItemState::new(ItemBehavior::Standing),
|
|
126
|
+ &map,
|
126
|
127
|
));
|
127
|
128
|
}
|
128
|
129
|
}
|
129
|
130
|
|
|
131
|
+ let mut scene_items_by_grid_position: HashMap<GridPosition, Vec<usize>> = HashMap::new();
|
|
132
|
+ for (i, scene_item) in scene_items.iter().enumerate() {
|
|
133
|
+ let grid_position = util::grid_position_from_scene_point(&scene_item.position, &map);
|
|
134
|
+ scene_items_by_grid_position
|
|
135
|
+ .entry(grid_position)
|
|
136
|
+ .or_default()
|
|
137
|
+ .push(i);
|
|
138
|
+ }
|
|
139
|
+
|
130
|
140
|
let mut main_state = MainState {
|
131
|
141
|
frame_i: 0,
|
132
|
142
|
start: Instant::now(),
|
|
@@ -139,7 +149,7 @@ impl MainState {
|
139
|
149
|
ui_batch,
|
140
|
150
|
terrain_batch,
|
141
|
151
|
scene_items,
|
142
|
|
- scene_items_by_grid_position: HashMap::new(),
|
|
152
|
+ scene_items_by_grid_position,
|
143
|
153
|
physics_events: vec![],
|
144
|
154
|
last_key_consumed: HashMap::new(),
|
145
|
155
|
left_click_down: None,
|
|
@@ -151,15 +161,6 @@ impl MainState {
|
151
|
161
|
scene_item_prepare_order: None,
|
152
|
162
|
};
|
153
|
163
|
|
154
|
|
- for (i, scene_item) in main_state.scene_items.iter().enumerate() {
|
155
|
|
- let grid_position = util::grid_position_from_scene_point(&scene_item.position);
|
156
|
|
- main_state
|
157
|
|
- .scene_items_by_grid_position
|
158
|
|
- .entry(grid_position)
|
159
|
|
- .or_default()
|
160
|
|
- .push(i);
|
161
|
|
- }
|
162
|
|
-
|
163
|
164
|
Ok(main_state)
|
164
|
165
|
}
|
165
|
166
|
|
|
@@ -346,7 +347,7 @@ impl MainState {
|
346
|
347
|
scene_item.position.x += move_vector.x;
|
347
|
348
|
scene_item.position.y += move_vector.y;
|
348
|
349
|
scene_item.grid_position =
|
349
|
|
- util::grid_position_from_scene_point(&scene_item.position);
|
|
350
|
+ util::grid_position_from_scene_point(&scene_item.position, &self.map);
|
350
|
351
|
}
|
351
|
352
|
}
|
352
|
353
|
}
|