ServerGroundMovementTree value fix

This commit is contained in:
austin 2025-06-04 17:10:47 -04:00
parent ace8a9b27b
commit 60feb2ed59
4 changed files with 48 additions and 23 deletions

View File

@ -2103,11 +2103,13 @@ ServerGroundMovementTree geom work
ServerLODComponent replaces bodies with geometries instead of just destroying the geometries
(06/04/2025)
(06/01/2025 - 06/04/2025)
Fix rebase world origin routine
Non-rigid-body collidables behave as expected
Fix physics performance issues
(06/04/2025)
ServerGroundMovementTree actually moves collidable-based entities

View File

@ -9,34 +9,54 @@ import electrosphere.engine.EngineState;
*/
public class Timekeeper {
//the time a single simulation frame should simulate for (this is fixed)
double simFrameTime = 0.0;
/**
* the time a single simulation frame should simulate for (this is fixed)
*/
private double simFrameTime = 0.0;
//the time that the system started (0 if using glfw reference, current system time if using java reference)
double engineStartTime = 0.0;
/**
* the time that the system started (0 if using glfw reference, current system time if using java reference)
*/
private double engineStartTime = 0.0;
//the system time at the last call to update()
double currentTime = 0.0;
/**
* the system time at the last call to update()
*/
private double currentTime = 0.0;
//accumulates time between current frame and next frame
double frameAccumulator = 0.0;
/**
* accumulates time between current frame and next frame
*/
private double frameAccumulator = 0.0;
//the number of frames that have elapsed
long numberOfSimFramesElapsed = 0;
/**
* the number of frames that have elapsed
*/
private long numberOfSimFramesElapsed = 0;
//the number of times the render pipeline has rendered a frame
/**
* the number of times the render pipeline has rendered a frame
*/
public long numberOfRenderedFrames = 0;
//the raw (not simulation) frametime of the most recent frame
double mostRecentRawFrametime = 0;
/**
* the raw (not simulation) frametime of the most recent frame
*/
private double mostRecentRawFrametime = 0;
//The maximum amount of time that can overflow (ie cause more than one sim frame/render frame) before the sim frames are tossed out
static double overflowMax = 20;
/**
* The maximum amount of time that can overflow (ie cause more than one sim frame/render frame) before the sim frames are tossed out
*/
private static double overflowMax = 20;
//the maximum number of simulation frames that can happen in a row before the main loop immediately skips more
/**
* the maximum number of simulation frames that can happen in a row before the main loop immediately skips more
*/
public static final int SIM_FRAME_HARDCAP = 3;
//step interval time size (for physics)
/**
* step interval time size (for physics)
*/
public static final float ENGINE_STEP_SIZE = 0.01f;

View File

@ -10,6 +10,7 @@ import electrosphere.collision.PhysicsEntityUtils;
import electrosphere.collision.collidable.Collidable;
import electrosphere.data.entity.creature.movement.GroundMovementSystem;
import electrosphere.engine.Globals;
import electrosphere.engine.time.Timekeeper;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
@ -291,7 +292,7 @@ public class ServerGroundMovementTree implements BehaviorTree {
}
if(body == null){
Vector3d velVec = new Vector3d(movementVector);
velVec.mul(velocity * Globals.engineState.timekeeper.getSimFrameTime());
velVec.mul(velocity * Globals.engineState.timekeeper.getSimFrameTime() * Timekeeper.ENGINE_STEP_SIZE);
velVec.add(position);
ServerEntityUtils.repositionEntity(parent, velVec);
} else {
@ -343,7 +344,7 @@ public class ServerGroundMovementTree implements BehaviorTree {
float velocity = this.getModifiedVelocity();
if(body == null){
Vector3d velVec = new Vector3d(movementVector);
velVec.mul(velocity * Globals.engineState.timekeeper.getSimFrameTime());
velVec.mul(velocity * Globals.engineState.timekeeper.getSimFrameTime() * Timekeeper.ENGINE_STEP_SIZE);
velVec.add(position);
ServerEntityUtils.repositionEntity(parent, velVec);
} else {
@ -414,7 +415,7 @@ public class ServerGroundMovementTree implements BehaviorTree {
}
if(body == null){
Vector3d velVec = new Vector3d(movementVector);
velVec.mul(velocity * Globals.engineState.timekeeper.getSimFrameTime());
velVec.mul(velocity * Globals.engineState.timekeeper.getSimFrameTime() * Timekeeper.ENGINE_STEP_SIZE);
velVec.add(position);
ServerEntityUtils.repositionEntity(parent, velVec);
} else {

View File

@ -146,8 +146,10 @@ public class MacroPathfindingNode implements AITreeNode {
targetPos = (Vector3d)targetRaw;
} else if(targetRaw instanceof Entity){
targetPos = new Vector3d(EntityUtils.getPosition((Entity)targetRaw));
} else if(targetRaw instanceof VirtualStructure){
targetPos = ((VirtualStructure)targetRaw).getPos();
} else if(targetRaw instanceof VirtualStructure struct){
targetPos = struct.getPos();
} else if(targetRaw instanceof MacroRegion region){
targetPos = region.getPos();
} else {
throw new Error("Unsupported target type " + targetRaw);
}