fix gravity tree not deactivating
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2024-12-03 13:19:17 -05:00
parent acfd28a0fc
commit e21bcbbe3f
5 changed files with 34 additions and 14 deletions

View File

@ -1226,6 +1226,8 @@ Add native testing step to jenkins pipeline
(12/03/2024) (12/03/2024)
Native code building correctly in jenkins pipeline Native code building correctly in jenkins pipeline
Refactoring native code
Fix gravity tree not deactivating when body is disabled

View File

@ -3,6 +3,7 @@ package electrosphere.entity.state.gravity;
import org.ode4j.ode.DBody; import org.ode4j.ode.DBody;
import electrosphere.collision.PhysicsEntityUtils;
import electrosphere.collision.collidable.Collidable; import electrosphere.collision.collidable.Collidable;
import electrosphere.engine.Globals; import electrosphere.engine.Globals;
import electrosphere.entity.Entity; import electrosphere.entity.Entity;
@ -65,11 +66,6 @@ public class ClientGravityTree implements BehaviorTree {
state = GravityTreeState.ACTIVE; state = GravityTreeState.ACTIVE;
} }
public void interrupt(){
state = GravityTreeState.NOT_ACTIVE;
}
public void stop(){ public void stop(){
state = GravityTreeState.NOT_ACTIVE; state = GravityTreeState.NOT_ACTIVE;
} }
@ -93,7 +89,7 @@ public class ClientGravityTree implements BehaviorTree {
//state machine //state machine
switch(state){ switch(state){
case ACTIVE: case ACTIVE:
if(hadGroundCollision()){ if(this.hadGroundCollision() || !this.bodyIsActive()){
ClientJumpTree jumpTree; ClientJumpTree jumpTree;
if((jumpTree = ClientJumpTree.getClientJumpTree(parent))!=null){ if((jumpTree = ClientJumpTree.getClientJumpTree(parent))!=null){
jumpTree.land(); jumpTree.land();
@ -133,6 +129,18 @@ public class ClientGravityTree implements BehaviorTree {
return rVal; return rVal;
} }
/**
* Checks if the physics body is active
* @return true if it is active (or not present), false otherwise
*/
private boolean bodyIsActive(){
if(PhysicsEntityUtils.getDBody(parent) == null){
return true;
}
DBody body = PhysicsEntityUtils.getDBody(parent);
return body.isEnabled();
}
public boolean hadEntityCollision(){ public boolean hadEntityCollision(){
boolean rVal = false; boolean rVal = false;
for(Impulse impulse : collidable.getImpulses()){ for(Impulse impulse : collidable.getImpulses()){

View File

@ -8,6 +8,7 @@ import electrosphere.server.datacell.utils.ServerBehaviorTreeUtils;
import org.ode4j.ode.DBody; import org.ode4j.ode.DBody;
import electrosphere.collision.PhysicsEntityUtils;
import electrosphere.collision.collidable.Collidable; import electrosphere.collision.collidable.Collidable;
import electrosphere.engine.Globals; import electrosphere.engine.Globals;
import electrosphere.entity.Entity; import electrosphere.entity.Entity;
@ -67,10 +68,6 @@ public class ServerGravityTree implements BehaviorTree {
} }
} }
public void interrupt(){
setState(GravityTreeState.NOT_ACTIVE);
}
public void stop(){ public void stop(){
setState(GravityTreeState.NOT_ACTIVE); setState(GravityTreeState.NOT_ACTIVE);
} }
@ -97,7 +94,7 @@ public class ServerGravityTree implements BehaviorTree {
//state machine //state machine
switch(state){ switch(state){
case ACTIVE: case ACTIVE:
if(hadGroundCollision()){ if(this.hadGroundCollision() || !this.bodyIsActive()){
setState(GravityTreeState.NOT_ACTIVE); setState(GravityTreeState.NOT_ACTIVE);
ServerJumpTree jumpTree; ServerJumpTree jumpTree;
if((jumpTree = ServerJumpTree.getServerJumpTree(parent))!=null){ if((jumpTree = ServerJumpTree.getServerJumpTree(parent))!=null){
@ -144,6 +141,18 @@ public class ServerGravityTree implements BehaviorTree {
return rVal; return rVal;
} }
/**
* Checks if the physics body is active
* @return true if it is active (or not present), false otherwise
*/
private boolean bodyIsActive(){
if(PhysicsEntityUtils.getDBody(parent) == null){
return true;
}
DBody body = PhysicsEntityUtils.getDBody(parent);
return body.isEnabled();
}
/** /**
* Checks if the gravity tree had a collision with an entity * Checks if the gravity tree had a collision with an entity
* @return true if collided on the most recent frame, false otherwise * @return true if collided on the most recent frame, false otherwise

View File

@ -408,6 +408,8 @@ public class ClientGroundMovementTree implements BehaviorTree {
} }
} }
CreatureUtils.setVelocity(parent, velocity); CreatureUtils.setVelocity(parent, velocity);
} else {
GravityUtils.clientAttemptActivateGravity(parent);
} }
PhysicsEntityUtils.getDBody(parent).enable(); PhysicsEntityUtils.getDBody(parent).enable();
body.setLinearVel( body.setLinearVel(
@ -418,7 +420,6 @@ public class ClientGroundMovementTree implements BehaviorTree {
body.setAngularVel(0, 0, 0); body.setAngularVel(0, 0, 0);
rotation.set(movementQuaternion); rotation.set(movementQuaternion);
GravityUtils.clientAttemptActivateGravity(parent);
} break; } break;
case IDLE: { case IDLE: {
Vector3d playerPos = EntityUtils.getPosition(parent); Vector3d playerPos = EntityUtils.getPosition(parent);

View File

@ -381,6 +381,8 @@ public class ServerGroundMovementTree implements BehaviorTree {
poseActor.stopAnimation(animationToPlay); poseActor.stopAnimation(animationToPlay);
} }
} }
} else {
GravityUtils.serverAttemptActivateGravity(parent);
} }
// PhysicsEntityUtils.getDBody(parent).addForce( // PhysicsEntityUtils.getDBody(parent).addForce(
// movementVector.x * velocity * Globals.timekeeper.getSimFrameTime(), // movementVector.x * velocity * Globals.timekeeper.getSimFrameTime(),
@ -396,8 +398,6 @@ public class ServerGroundMovementTree implements BehaviorTree {
body.setAngularVel(0, 0, 0); body.setAngularVel(0, 0, 0);
// position.set(newPosition); // position.set(newPosition);
GravityUtils.serverAttemptActivateGravity(parent);
DataCellSearchUtils.getEntityDataCell(parent).broadcastNetworkMessage( DataCellSearchUtils.getEntityDataCell(parent).broadcastNetworkMessage(
EntityMessage.constructmoveUpdateMessage( EntityMessage.constructmoveUpdateMessage(
parent.getId(), parent.getId(),