From 5bf5080f7401b452db7b238f023afcbdf3ce77ad Mon Sep 17 00:00:00 2001 From: austin Date: Wed, 28 May 2025 16:42:14 -0400 Subject: [PATCH] server physics destruction fix --- docs/src/progress/renderertodo.md | 1 + .../collision/PhysicsEntityUtils.java | 18 ++++++++++++++++++ .../entity/state/lod/ServerLODComponent.java | 10 +--------- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index bd04c00c..71335477 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -2029,6 +2029,7 @@ Moving data packages around Fix client LOD component re-enabling physics positioning Debug rendering of server physics objects Server LOD component properly attaches physics bodies when the entity comes in range +Fix physics destruction on server via ServerLODComponent diff --git a/src/main/java/electrosphere/collision/PhysicsEntityUtils.java b/src/main/java/electrosphere/collision/PhysicsEntityUtils.java index 0115ea0c..0bda9f13 100644 --- a/src/main/java/electrosphere/collision/PhysicsEntityUtils.java +++ b/src/main/java/electrosphere/collision/PhysicsEntityUtils.java @@ -867,6 +867,24 @@ public class PhysicsEntityUtils { } } + /** + * Destroys the physics attached to an entity without outright destroying the entity + * @param entity The entity + */ + public static void serverDestroyPhysics(Entity entity){ + Realm realm = Globals.serverState.realmManager.getEntityRealm(entity); + if(PhysicsEntityUtils.containsDBody(entity)){ + PhysicsUtils.destroyPhysicsPair( + realm.getCollisionEngine(), + PhysicsEntityUtils.getDBody(entity), + PhysicsEntityUtils.getCollidable(entity) + ); + } + PhysicsEntityUtils.setCollidable(entity, null); + Vector3d entityPos = EntityUtils.getPosition(entity); + ServerEntityUtils.repositionEntity(entity, entityPos); + } + /** * Gets the transform from parent entity position to rigid body * @param entity The entity diff --git a/src/main/java/electrosphere/entity/state/lod/ServerLODComponent.java b/src/main/java/electrosphere/entity/state/lod/ServerLODComponent.java index 2224453d..d4a22ac0 100644 --- a/src/main/java/electrosphere/entity/state/lod/ServerLODComponent.java +++ b/src/main/java/electrosphere/entity/state/lod/ServerLODComponent.java @@ -4,7 +4,6 @@ package electrosphere.entity.state.lod; import org.joml.Vector3d; import electrosphere.collision.PhysicsEntityUtils; -import electrosphere.collision.PhysicsUtils; import electrosphere.data.entity.common.CommonEntityType; import electrosphere.engine.Globals; import electrosphere.entity.EntityDataStrings; @@ -71,14 +70,7 @@ public class ServerLODComponent implements BehaviorTree { if(this.lodLevel != LOW_RES){ //make low res this.setLodLevel(LOW_RES); - Realm realm = Globals.serverState.realmManager.getEntityRealm(this.parent); - if(PhysicsEntityUtils.containsDBody(this.parent)){ - PhysicsUtils.destroyPhysicsPair( - realm.getCollisionEngine(), - PhysicsEntityUtils.getDBody(this.parent), - PhysicsEntityUtils.getCollidable(this.parent) - ); - } + PhysicsEntityUtils.serverDestroyPhysics(this.parent); } } }