UI: Added widget focus for regular input blocking | Physics: Trigger callbacks
This commit is contained in:
@@ -76,9 +76,10 @@ nearly_equal :: (a: float, b: float) -> bool {
|
||||
return abs(a - b) < 0.00001;
|
||||
}
|
||||
|
||||
polytope : [..] Vector3;
|
||||
|
||||
epa :: (simplex: Simplex, collider_a: Collider, collider_b: Collider) -> Collision_Point {
|
||||
polytope : [..] Vector3;
|
||||
polytope.allocator = temp;
|
||||
polytope.count = 0;
|
||||
|
||||
array_reserve(*polytope, simplex.size);
|
||||
for simplex.points {
|
||||
|
||||
@@ -26,6 +26,9 @@ Trigger_Overlap :: struct {
|
||||
|
||||
MAX_TRIGGER_OVERLAPS :: 16;
|
||||
|
||||
on_trigger_enter_callback : (*Entity, *Entity);
|
||||
on_trigger_exit_callback : (*Entity, *Entity);
|
||||
|
||||
Collision_Layers :: enum_flags {
|
||||
NONE;
|
||||
|
||||
@@ -63,6 +66,7 @@ Collider :: struct {
|
||||
}
|
||||
|
||||
Physics_Body :: struct {
|
||||
enabled: bool = true;
|
||||
velocity: Vector3;
|
||||
|
||||
friction : float = 0.0;
|
||||
@@ -134,6 +138,7 @@ make_sure_nothing_collides :: (scene: *Scene) {
|
||||
update_gravity :: (scene: *Scene, dt: float) {
|
||||
for e: scene.entities {
|
||||
if !e.enabled continue;
|
||||
if !e.body.enabled continue;
|
||||
|
||||
if e.flags & .PHYSICS {
|
||||
#if NETWORKING { if e.is_proxy continue; }
|
||||
@@ -147,6 +152,7 @@ update_gravity :: (scene: *Scene, dt: float) {
|
||||
update_positions :: (scene: *Scene, dt: float) {
|
||||
for e: scene.entities {
|
||||
if !e.enabled continue;
|
||||
if !e.body.enabled continue;
|
||||
|
||||
#if NETWORKING { if e.is_proxy continue; }
|
||||
|
||||
@@ -172,18 +178,21 @@ update_positions :: (scene: *Scene, dt: float) {
|
||||
}
|
||||
}
|
||||
|
||||
add_trigger_overlap_if_new :: (e: *Entity, other_e: *Entity) {
|
||||
for 0..e.collider.num_overlaps-1 {
|
||||
overlap := *e.collider.overlaps[it];
|
||||
if overlap.entity == other_e {
|
||||
add_trigger_overlap_if_new :: (triggered_entity: *Entity, triggered_by_entity: *Entity) {
|
||||
for 0..triggered_entity.collider.num_overlaps-1 {
|
||||
overlap := *triggered_entity.collider.overlaps[it];
|
||||
if overlap.entity == triggered_by_entity {
|
||||
overlap.frame_index = frame_index;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
on_trigger_enter(e, other_e);
|
||||
e.collider.overlaps[e.collider.num_overlaps] = .{ other_e, frame_index };
|
||||
e.collider.num_overlaps += 1;
|
||||
if on_trigger_enter_callback != null {
|
||||
on_trigger_enter_callback(triggered_entity, triggered_by_entity);
|
||||
}
|
||||
|
||||
triggered_entity.collider.overlaps[triggered_entity.collider.num_overlaps] = .{ triggered_by_entity, frame_index };
|
||||
triggered_entity.collider.num_overlaps += 1;
|
||||
}
|
||||
|
||||
can_collide :: (e: *Entity, other: *Entity) -> bool {
|
||||
@@ -196,6 +205,7 @@ physics_step :: (scene: *Scene, timestep: float) {
|
||||
|
||||
for e: scene.entities {
|
||||
if !e.enabled continue;
|
||||
if !e.body.enabled continue;
|
||||
#if NETWORKING { if e.is_proxy continue;}
|
||||
if e.collider.ignore continue;
|
||||
|
||||
@@ -203,6 +213,8 @@ physics_step :: (scene: *Scene, timestep: float) {
|
||||
for other_e: scene.entities {
|
||||
if e == other_e continue;
|
||||
if other_e.collider.ignore continue;
|
||||
if !other_e.enabled continue;
|
||||
if !other_e.body.enabled continue;
|
||||
if !can_collide(e, other_e) continue;
|
||||
|
||||
if other_e.flags & .COLLISION {
|
||||
@@ -211,7 +223,7 @@ physics_step :: (scene: *Scene, timestep: float) {
|
||||
if point.has_collision {
|
||||
if other_e.flags & .TRIGGER {
|
||||
// TRIGGER CALLBACK
|
||||
add_trigger_overlap_if_new(e, other_e);
|
||||
add_trigger_overlap_if_new(other_e, e);
|
||||
} else {
|
||||
n := -point.normal;
|
||||
speed_along_normal := dot(e.body.velocity, n);
|
||||
@@ -241,18 +253,6 @@ physics_step :: (scene: *Scene, timestep: float) {
|
||||
}
|
||||
}
|
||||
|
||||
on_trigger_enter :: (e: *Entity, other_e: *Entity) {
|
||||
//if (e.type == Player || e.type == Npc) && other_e.type == Door {
|
||||
// other_e.enabled = false;
|
||||
//}
|
||||
}
|
||||
|
||||
on_trigger_exit :: (e: *Entity, other_e: *Entity) {
|
||||
//if other_e.type == Door {
|
||||
// other_e.enabled = true;
|
||||
//}
|
||||
}
|
||||
|
||||
update_physics :: (scene: *Scene, dt: float) {
|
||||
for scene.entities {
|
||||
if it.collider.type == .MESH {
|
||||
@@ -284,7 +284,9 @@ update_physics :: (scene: *Scene, dt: float) {
|
||||
defer index += 1;
|
||||
|
||||
if e.collider.overlaps[index].frame_index < frame_index {
|
||||
on_trigger_exit(e, e.collider.overlaps[index].entity);
|
||||
if on_trigger_exit_callback != null {
|
||||
on_trigger_exit_callback(e, e.collider.overlaps[index].entity);
|
||||
}
|
||||
|
||||
if e.collider.num_overlaps > 1 {
|
||||
e.collider.overlaps[index] = e.collider.overlaps[e.collider.num_overlaps-1];
|
||||
|
||||
Reference in New Issue
Block a user