--- a/rust/hwphysics/src/collision.rs Wed Jul 24 23:37:58 2019 +0300
+++ b/rust/hwphysics/src/collision.rs Thu Jul 25 00:05:30 2019 +0300
@@ -79,7 +79,7 @@
}
pub struct DetectedCollisions {
- pub pairs: Vec<(GearId, GearId)>,
+ pub pairs: Vec<(GearId, Option<GearId>)>,
pub positions: Vec<Point>,
}
@@ -91,7 +91,12 @@
}
}
- pub fn push(&mut self, contact_gear_id1: GearId, contact_gear_id2: GearId, position: &FPPoint) {
+ pub fn push(
+ &mut self,
+ contact_gear_id1: GearId,
+ contact_gear_id2: Option<GearId>,
+ position: &FPPoint,
+ ) {
self.pairs.push((contact_gear_id1, contact_gear_id2));
self.positions.push(fppoint_round(&position));
}
@@ -119,7 +124,7 @@
.any(|(y, r)| (&land[y][r]).iter().any(|v| *v != 0))
{
self.detected_collisions
- .push(gear_id, 0, &collision.bounds.center)
+ .push(gear_id, None, &collision.bounds.center)
}
}
}
--- a/rust/hwphysics/src/common.rs Wed Jul 24 23:37:58 2019 +0300
+++ b/rust/hwphysics/src/common.rs Thu Jul 25 00:05:30 2019 +0300
@@ -1,4 +1,4 @@
-pub type GearId = u16;
+pub type GearId = std::num::NonZeroU16;
pub trait GearData {}
pub trait GearDataProcessor<T: GearData> {
--- a/rust/hwphysics/src/grid.rs Wed Jul 24 23:37:58 2019 +0300
+++ b/rust/hwphysics/src/grid.rs Thu Jul 25 00:05:30 2019 +0300
@@ -114,16 +114,24 @@
pub fn check_collisions(&self, collisions: &mut DetectedCollisions) {
for bin in &self.bins {
- for bounds in &bin.dynamic_entries {
- for other in &bin.dynamic_entries {
+ for (index, bounds) in bin.dynamic_entries.iter().enumerate() {
+ for (other_index, other) in bin.dynamic_entries.iter().enumerate().skip(index + 1) {
if bounds.intersects(other) && bounds != other {
- collisions.push(0, 0, &bounds.center)
+ collisions.push(
+ bin.dynamic_refs[index],
+ Some(bin.dynamic_refs[other_index]),
+ &bounds.center,
+ )
}
}
- for other in &bin.static_entries {
+ for (other_index, other) in bin.static_entries.iter().enumerate() {
if bounds.intersects(other) {
- collisions.push(0, 0, &bounds.center)
+ collisions.push(
+ bin.dynamic_refs[index],
+ Some(bin.static_refs[other_index]),
+ &bounds.center,
+ )
}
}
}
--- a/rust/lib-hedgewars-engine/src/world.rs Wed Jul 24 23:37:58 2019 +0300
+++ b/rust/lib-hedgewars-engine/src/world.rs Thu Jul 25 00:05:30 2019 +0300
@@ -40,7 +40,7 @@
map_renderer: None,
gear_renderer: None,
camera: Camera::new(),
- last_gear_id: GearId::default(),
+ last_gear_id: std::num::NonZeroU16::new(1).unwrap(),
}
}
@@ -130,7 +130,7 @@
fn get_unused_gear_id(&mut self) -> GearId {
let id = self.last_gear_id;
- self.last_gear_id += 1;
+ self.last_gear_id = std::num::NonZeroU16::new(self.last_gear_id.get() + 1).unwrap();
id
}