simplified collecting contacts by removing expiry and just clearing the list
This commit is contained in:
parent
1e039c310b
commit
77c266b43f
|
@ -90,14 +90,13 @@ void physics_entity_update(PhysicsEntity self) {
|
|||
|
||||
ASSERT_RETURN(!visnanf(rigidbody_get_velocity(body)),, "Velocity is NaN (0)");
|
||||
|
||||
rigidbody_collect_contacts(body);
|
||||
|
||||
List* contacts = rigidbody_get_contacts(body);
|
||||
if(contacts->len > 0) {
|
||||
self.tc->collision_solver(self.data, contacts);
|
||||
list_foreach(Contact, contact, contacts)
|
||||
self.tc->on_collision(self.data, contact->hit);
|
||||
}
|
||||
rigidbody_collect_contacts(body);
|
||||
|
||||
ASSERT_RETURN(!visnanf(rigidbody_get_velocity(body)),, "Velocity is NaN (1)");
|
||||
}
|
||||
|
|
|
@ -45,36 +45,15 @@ void rigidbody_destroy(RigidBody* self) {
|
|||
}
|
||||
|
||||
void rigidbody_add_contact(RigidBody* self, Collision hit) {
|
||||
// update an existing contact
|
||||
list_foreach(Contact, contact, &self->contacts) {
|
||||
if(contact->hit.other.data == hit.other.data) {
|
||||
++contact->expiry;
|
||||
contact->hit = hit;
|
||||
contact->duration += delta_time();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// create a new contact
|
||||
list_add(&self->contacts,
|
||||
&(Contact) {
|
||||
.expiry = 1,
|
||||
.hit = hit,
|
||||
.duration = delta_time()
|
||||
});
|
||||
}
|
||||
|
||||
void rigidbody_collect_contacts(RigidBody* self) {
|
||||
for(size_t i = 0; i < self->contacts.len; ++i) {
|
||||
Contact* contact = list_at(&self->contacts, i);
|
||||
|
||||
if(contact->expiry <= 0) {
|
||||
list_erase(&self->contacts, i);
|
||||
i--;
|
||||
} else {
|
||||
--(contact->expiry);
|
||||
}
|
||||
}
|
||||
list_empty(&self->contacts);
|
||||
}
|
||||
|
||||
List* rigidbody_get_contacts(RigidBody* self) {
|
||||
|
|
Loading…
Reference in a new issue