Fixed bug where box colliders weren't being deleted on scene destroy

This commit is contained in:
Diren D Bharwani 2023-03-02 13:52:54 +08:00
parent 991912f7b4
commit e43089e6ff
9 changed files with 56 additions and 31 deletions

View File

@ -1,4 +1,4 @@
Start Maximized: true
Working Scene ID: 97402985
Working Scene ID: 92914350
Window Size: {x: 2000, y: 1518}
Style: 0

View File

@ -251,9 +251,9 @@
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 2, y: 5, z: 3}
Rotate: {x: 0, y: 0, z: 0.785398185}
Scale: {x: 0.999999642, y: 0.999998569, z: 0.999999642}
Translate: {x: 2.35593724, y: 3, z: 3}
Rotate: {x: -0, y: 0.785398006, z: -0}
Scale: {x: 0.999999702, y: 0.999998569, z: 0.999999702}
IsActive: true
RigidBody Component:
Type: Dynamic

View File

@ -4,7 +4,7 @@
NumberOfChildren: 0
Components:
Camera Component:
Position: {x: 0, y: 1, z: 5}
Position: {x: 1, y: -0.5, z: 5}
Pitch: 0
Yaw: 0
Roll: 0
@ -30,8 +30,8 @@
Colliders:
- Is Trigger: false
Collision Tag: 1
Type: Box
Half Extents: {x: 1, y: 1, z: 1}
Type: Sphere
Radius: 1
Friction: 0.400000006
Bounciness: 0
Density: 1
@ -45,8 +45,8 @@
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 1.5, y: 2, z: 1.5}
Rotate: {x: 0, y: 0.785398185, z: 0}
Translate: {x: 0, y: 5, z: 0}
Rotate: {x: -0, y: 0.785398006, z: -0}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
RigidBody Component:
@ -71,8 +71,8 @@
Colliders:
- Is Trigger: false
Collision Tag: 1
Type: Box
Half Extents: {x: 1, y: 1, z: 1}
Type: Sphere
Radius: 1
Friction: 0.400000006
Bounciness: 0
Density: 1
@ -83,4 +83,4 @@
- Type: PhysicsTestObj
Enabled: true
forceAmount: 50
torqueAmount: 500
torqueAmount: 25

View File

@ -64,8 +64,37 @@ public class PhysicsTestObj : Script
};
public float forceAmount = 50.0f;
public float torqueAmount = 500.0f;
public float torqueAmount = 25.0f;
protected override void onTriggerEnter(CollisionInfo info)
{
Debug.Log("Trigger Enter");
}
protected override void onTriggerStay(CollisionInfo info)
{
Debug.Log("Trigger Stay");
}
protected override void onTriggerExit(CollisionInfo info)
{
Debug.Log("Trigger Exit");
}
protected override void onCollisionEnter(CollisionInfo info)
{
Debug.Log("Collision Enter");
}
protected override void onCollisionStay(CollisionInfo info)
{
Debug.Log("Collision Stay");
}
protected override void onCollisionExit(CollisionInfo info)
{
Debug.Log("Collision Exit");
}
protected override void awake()
{
body = GetComponent<RigidBody>();

View File

@ -92,14 +92,6 @@ namespace SHADE
}
bool SHCollisionShape::IsTrigger() const noexcept
{
static constexpr int FLAG_POS = 3;
static constexpr uint8_t FLAG_VALUE = 1U << FLAG_POS;
return flags & FLAG_VALUE;
}
bool SHCollisionShape::IsColliding() const noexcept
{
static constexpr int FLAG_POS = 4;
static constexpr uint8_t FLAG_VALUE = 1U << FLAG_POS;
@ -158,7 +150,7 @@ namespace SHADE
void SHCollisionShape::SetIsTrigger(bool isTrigger) noexcept
{
static constexpr int FLAG_POS = 3;
static constexpr int FLAG_POS = 4;
static constexpr uint8_t FLAG_VALUE = 1U << FLAG_POS;
isTrigger ? flags |= FLAG_VALUE : flags &= ~FLAG_VALUE;

View File

@ -105,7 +105,6 @@ namespace SHADE
[[nodiscard]] Type GetType () const noexcept;
[[nodiscard]] bool IsTrigger () const noexcept;
[[nodiscard]] bool IsColliding () const noexcept;
[[nodiscard]] const SHCollisionTag& GetCollisionTag () const noexcept;
@ -201,7 +200,7 @@ namespace SHADE
// Needed for conversion to euler angles
SHVec3 rotationOffset;
uint8_t flags; // 0 0 0 trigger convexHull capsule sphere box
uint8_t flags; // 0 0 0 trigger convexHull capsule box sphere
RTTR_ENABLE()

View File

@ -86,6 +86,12 @@ namespace SHADE
{
case SHCollisionShape::Type::BOX:
{
SHBox* box = boxes.find(shape->id)->second;
boxes.erase(shape->id);
delete box;
box = nullptr;
break;
}
case SHCollisionShape::Type::SPHERE:

View File

@ -144,7 +144,7 @@ namespace SHADE
for (auto manifoldPair = manifolds.begin(); manifoldPair != manifolds.end();)
{
// Test collision of every manifold.
SHManifold& manifold = manifoldPair->second;
SHManifold& manifold = manifoldPair->second;
SHManifold oldManifold = manifold;
const bool IS_COLLIDING = SHCollisionDispatcher::Collide(manifold, *manifold.shapeA, *manifold.shapeB);
@ -159,6 +159,8 @@ namespace SHADE
continue;
}
SHLOG_INFO("State {}", static_cast<int>(manifold.state))
updateManifold(manifold, oldManifold);
++manifoldPair;
}
@ -167,12 +169,11 @@ namespace SHADE
for (auto triggerPair = triggers.begin(); triggerPair != triggers.end();)
{
// Test collision of every trigger.
Trigger& oldTrigger = triggerPair->second;
Trigger newTrigger = oldTrigger;
Trigger& trigger = triggerPair->second;
const bool IS_COLLIDING = SHCollisionDispatcher::Collide(*newTrigger.A, *newTrigger.B);
const bool IS_COLLIDING = SHCollisionDispatcher::Collide(*trigger.A, *trigger.B);
auto& collisionState = newTrigger.state;
auto& collisionState = trigger.state;
updateCollisionState(IS_COLLIDING, collisionState);
const bool IS_INVALID = collisionState == SHCollisionState::INVALID;

View File

@ -94,8 +94,6 @@ namespace SHADE
}
}
// Collision & Trigger messages
if (scriptingSystem != nullptr)
scriptingSystem->ExecuteCollisionFunctions();