Time update
This commit is contained in:
parent
aec9a58f12
commit
a8644582cb
@ -63,8 +63,8 @@
|
||||
"movementSystems" : [
|
||||
{
|
||||
"type" : "GROUND",
|
||||
"acceleration" : 1000.0,
|
||||
"maxVelocity" : 2.5,
|
||||
"acceleration" : 10.0,
|
||||
"maxVelocity" : 0.025,
|
||||
"animationStartup" : {
|
||||
"name" : "Armature|Jog",
|
||||
"length" : 1,
|
||||
|
||||
@ -41,7 +41,7 @@ public class CameraHandler {
|
||||
}
|
||||
|
||||
public void updateGlobalCamera(){
|
||||
cameraSpeed = 2.5f * Main.deltaTime;
|
||||
cameraSpeed = 2.5f * Main.deltaFrames;
|
||||
|
||||
if(Crosshair.getCrosshairActive()){
|
||||
|
||||
|
||||
@ -970,10 +970,10 @@ public class ControlHandler {
|
||||
if(!control.isState()){
|
||||
//on press
|
||||
control.onPress();
|
||||
control.setPressFrame(Main.lastFrame);
|
||||
control.setPressFrame(Main.deltaFrames);
|
||||
} else {
|
||||
//on repeat
|
||||
if(Main.lastFrame - control.getPressFrame() > control.getRepeatTimeout()){
|
||||
if(Main.deltaFrames - control.getPressFrame() > control.getRepeatTimeout()){
|
||||
control.onRepeat();
|
||||
}
|
||||
}
|
||||
@ -983,7 +983,7 @@ public class ControlHandler {
|
||||
//on release
|
||||
control.onRelease();
|
||||
//on click
|
||||
if(Main.lastFrame - control.getPressFrame() < control.getRepeatTimeout()){
|
||||
if(Main.deltaFrames - control.getPressFrame() < control.getRepeatTimeout()){
|
||||
control.onClick();
|
||||
}
|
||||
} else {
|
||||
|
||||
@ -232,7 +232,7 @@ public class GroundMovementTree {
|
||||
}
|
||||
}
|
||||
//run startup code
|
||||
velocity = velocity + acceleration * Main.deltaTime;
|
||||
velocity = velocity + acceleration * Main.deltaFrames;
|
||||
//check if can transition state
|
||||
if(velocity >= maxNaturalVelocity){
|
||||
velocity = maxNaturalVelocity;
|
||||
@ -248,7 +248,7 @@ public class GroundMovementTree {
|
||||
// newPosition = Globals.collisionEngine.suggestMovementPosition(Globals.commonWorldData, parent, newPosition);
|
||||
// }
|
||||
// //actually update
|
||||
collidable.addImpulse(new Impulse(new Vector3d(movementVector), new Vector3d(0,0,0), new Vector3d(0,0,0), velocity * Main.deltaTime, "movement"));
|
||||
collidable.addImpulse(new Impulse(new Vector3d(movementVector), new Vector3d(0,0,0), new Vector3d(0,0,0), velocity * Main.deltaFrames, "movement"));
|
||||
// position.set(newPosition);
|
||||
rotation.set(movementQuaternion);
|
||||
|
||||
@ -328,7 +328,7 @@ public class GroundMovementTree {
|
||||
// if(!Globals.collisionEngine.checkCanOccupyPosition(Globals.commonWorldData, parent, newPosition)){
|
||||
// newPosition = Globals.collisionEngine.suggestMovementPosition(Globals.commonWorldData, parent, newPosition);
|
||||
// }
|
||||
collidable.addImpulse(new Impulse(new Vector3d(movementVector), new Vector3d(0,0,0), new Vector3d(0,0,0), velocity * Main.deltaTime, "movement"));
|
||||
collidable.addImpulse(new Impulse(new Vector3d(movementVector), new Vector3d(0,0,0), new Vector3d(0,0,0), velocity * Main.deltaFrames, "movement"));
|
||||
// position.set(newPosition);
|
||||
rotation.set(movementQuaternion);
|
||||
|
||||
@ -396,7 +396,7 @@ public class GroundMovementTree {
|
||||
}
|
||||
}
|
||||
//velocity stuff
|
||||
velocity = velocity - acceleration * Main.deltaTime;
|
||||
velocity = velocity - acceleration * Main.deltaFrames;
|
||||
//check if can transition state
|
||||
if(velocity <= 0){
|
||||
velocity = 0;
|
||||
@ -416,7 +416,7 @@ public class GroundMovementTree {
|
||||
// if(!Globals.collisionEngine.checkCanOccupyPosition(Globals.commonWorldData, parent, newPosition)){
|
||||
// newPosition = Globals.collisionEngine.suggestMovementPosition(Globals.commonWorldData, parent, newPosition);
|
||||
// }
|
||||
collidable.addImpulse(new Impulse(new Vector3d(movementVector), new Vector3d(0,0,0), new Vector3d(0,0,0), velocity * Main.deltaTime, "movement"));
|
||||
collidable.addImpulse(new Impulse(new Vector3d(movementVector), new Vector3d(0,0,0), new Vector3d(0,0,0), velocity * Main.deltaFrames, "movement"));
|
||||
// position.set(newPosition);
|
||||
rotation.set(movementQuaternion);
|
||||
|
||||
|
||||
@ -3,6 +3,8 @@ package electrosphere.game.client;
|
||||
import electrosphere.entity.EntityUtils;
|
||||
import electrosphere.entity.types.camera.CameraEntityUtils;
|
||||
import electrosphere.main.Globals;
|
||||
|
||||
import org.joml.Vector3d;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
/**
|
||||
@ -10,12 +12,26 @@ import org.joml.Vector3f;
|
||||
* @author amaterasu
|
||||
*/
|
||||
public class ClientFunctions {
|
||||
|
||||
static Vector3d oldPlayerCharacterPosition = new Vector3d();
|
||||
static Vector3d newPlayerCharacterPosition = new Vector3d();
|
||||
|
||||
public static void runBeforeSimulationFunctions(){
|
||||
//cell tracking values
|
||||
if(Globals.RUN_CLIENT){
|
||||
if(Globals.playerCharacter != null){
|
||||
oldPlayerCharacterPosition = new Vector3d(EntityUtils.getPosition(Globals.playerCharacter));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void runClientFunctions(){
|
||||
if(Globals.clientTerrainManager != null){
|
||||
Globals.clientTerrainManager.handleMessages();
|
||||
Globals.clientTerrainManager.ejectLoadedChunks();
|
||||
}
|
||||
updateSkyboxPos();
|
||||
updateCellManager();
|
||||
}
|
||||
|
||||
static void updateSkyboxPos(){
|
||||
@ -29,4 +45,18 @@ public class ClientFunctions {
|
||||
EntityUtils.getPosition(Globals.skybox).set(EntityUtils.getPosition(Globals.playerCharacter));
|
||||
}
|
||||
}
|
||||
|
||||
static void updateCellManager(){
|
||||
///
|
||||
/// C L I E N T C E L L M A N A G E R
|
||||
///
|
||||
if(Globals.drawCellManager != null){
|
||||
if(Globals.playerCharacter != null){
|
||||
newPlayerCharacterPosition = EntityUtils.getPosition(Globals.playerCharacter);
|
||||
}
|
||||
//Cell manager do your things
|
||||
Globals.drawCellManager.calculateDeltas(oldPlayerCharacterPosition, newPlayerCharacterPosition);
|
||||
Globals.drawCellManager.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,7 +29,6 @@ import electrosphere.entity.state.collidable.Impulse;
|
||||
import electrosphere.entity.types.hitbox.HitboxData;
|
||||
import electrosphere.game.collision.collidable.Collidable;
|
||||
|
||||
import static electrosphere.main.Main.deltaTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@ -19,10 +19,11 @@ import electrosphere.entity.state.movement.SprintTree;
|
||||
import electrosphere.entity.types.particle.ParticleUtils;
|
||||
import electrosphere.game.client.targeting.crosshair.Crosshair;
|
||||
import electrosphere.main.Globals;
|
||||
import electrosphere.main.Main;
|
||||
import electrosphere.renderer.actor.Actor;
|
||||
|
||||
import static electrosphere.main.Main.deltaTime;
|
||||
|
||||
import org.joml.Vector3d;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
/**
|
||||
@ -39,7 +40,7 @@ public class MicroSimulation {
|
||||
|
||||
public void simulate(){
|
||||
//simulate bullet physics engine step
|
||||
Globals.collisionEngine.simulatePhysics(deltaTime);
|
||||
Globals.collisionEngine.simulatePhysics(Main.deltaFrames);
|
||||
//update dynamic entity positions calculated by bullet
|
||||
// Globals.collisionEngine.updateDynamicObjectTransforms();
|
||||
//list dynamic object positions
|
||||
@ -52,7 +53,7 @@ public class MicroSimulation {
|
||||
Actor currentActor = EntityUtils.getActor(currentEntity);
|
||||
//increment animations
|
||||
if(currentActor.isPlayingAnimation()){
|
||||
currentActor.incrementAnimationTime(deltaTime);
|
||||
currentActor.incrementAnimationTime(Main.deltaFrames / Main.targetFrameRate);
|
||||
}
|
||||
}
|
||||
//make items play idle animation
|
||||
@ -72,7 +73,7 @@ public class MicroSimulation {
|
||||
//simulate creature gravity trees
|
||||
for(Entity currentGravity : Globals.entityManager.getGravityEntities()){
|
||||
GravityTree gravityTree = (GravityTree)currentGravity.getData(EntityDataStrings.GRAVITY_TREE);
|
||||
gravityTree.simulate(deltaTime);
|
||||
gravityTree.simulate(Main.deltaFrames);
|
||||
}
|
||||
//attacker behavior tree
|
||||
for(Entity currentAttacker : Globals.entityManager.getAttackerEntities()){
|
||||
|
||||
@ -66,9 +66,10 @@ public class Main {
|
||||
//Visualization Controls
|
||||
//
|
||||
//These are used in calculating the time between frames for visualization (camera) control and such
|
||||
public static float deltaTime = 0.0f;
|
||||
public static float lastFrame = 0.0f;
|
||||
static double deltaTime = 0.0f;
|
||||
static double lastFrame = 0.0f;
|
||||
public static long frameCount = 0;
|
||||
public static float deltaFrames = 0;
|
||||
//View Controls
|
||||
public static float view_Range = 200000.0f;
|
||||
/*
|
||||
@ -105,7 +106,9 @@ public class Main {
|
||||
|
||||
public static Entity letterEntity;
|
||||
|
||||
static float targetFrameRate = 1.0f/144.0f;
|
||||
//target amount of time per frame
|
||||
public static float targetFrameRate = 60.0f;
|
||||
static float targetFramePeriod = 1.0f/targetFrameRate;
|
||||
|
||||
public static void main(String args[]){
|
||||
|
||||
@ -225,8 +228,9 @@ public class Main {
|
||||
/*
|
||||
Frame calculation
|
||||
*/
|
||||
float currentFrame = (float) glfwGetTime();
|
||||
double currentFrame = glfwGetTime();
|
||||
deltaTime = currentFrame - lastFrame;
|
||||
deltaFrames = targetFrameRate * (float)deltaTime;
|
||||
lastFrame = currentFrame;
|
||||
|
||||
|
||||
@ -251,19 +255,6 @@ public class Main {
|
||||
///
|
||||
/// I N P U T C O N T R O L S
|
||||
///
|
||||
// cameraSpeed = 2.5f * deltaTime;
|
||||
// if (glfwGetKey(Globals.window, GLFW_KEY_ESCAPE) == GLFW_PRESS && Globals.RENDER_FLAG_RENDER_SCREEN_FRAMEBUFFER_CONTENT) {
|
||||
// break;
|
||||
// }
|
||||
|
||||
//cell tracking values
|
||||
Vector3d oldPlayerCharacterPosition = new Vector3d();
|
||||
if(Globals.playerCharacter != null){
|
||||
oldPlayerCharacterPosition = new Vector3d(EntityUtils.getPosition(Globals.playerCharacter));
|
||||
}
|
||||
Vector3d newPlayerCharacterPosition = oldPlayerCharacterPosition;
|
||||
|
||||
|
||||
//Poll controls
|
||||
Globals.controlHandler.pollControls();
|
||||
Globals.controlHandler.recaptureIfNecessary();
|
||||
@ -273,6 +264,7 @@ public class Main {
|
||||
///
|
||||
/// C L I E N T S I M U L A T I O N S T U F F
|
||||
///
|
||||
ClientFunctions.runBeforeSimulationFunctions();
|
||||
if(Globals.microSimulation != null && Globals.microSimulation.isReady()){
|
||||
Globals.microSimulation.simulate();
|
||||
}
|
||||
@ -285,26 +277,6 @@ public class Main {
|
||||
Globals.macroSimulation.simulate();
|
||||
}
|
||||
|
||||
//
|
||||
// P L A Y E R W O R L D P O S I T I O N U P D A T E
|
||||
//
|
||||
// if(Globals.playerCharacter != null && Globals.commonWorldData != null){
|
||||
// EntityUtils.getRotation(Globals.playerCharacter).rotateX(0.01f);
|
||||
// newPlayerCharacterPosition = EntityUtils.getPosition(Globals.playerCharacter);
|
||||
// Globals.clientPlayerData.setWorldPosition(Globals.commonWorldData.convertRealToWorld(newPlayerCharacterPosition.x), Globals.commonWorldData.convertRealToWorld(newPlayerCharacterPosition.z));
|
||||
// }
|
||||
|
||||
///
|
||||
/// C L I E N T C E L L M A N A G E R
|
||||
///
|
||||
if(Globals.drawCellManager != null){
|
||||
|
||||
//Cell manager do your things
|
||||
Globals.drawCellManager.calculateDeltas(oldPlayerCharacterPosition, newPlayerCharacterPosition);
|
||||
Globals.drawCellManager.update();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Globals.renderingEngine.drawScreen();
|
||||
@ -314,15 +286,18 @@ public class Main {
|
||||
running = false;
|
||||
}
|
||||
|
||||
// System.out.println(deltaTime + " - " + targetFrameRate);
|
||||
if(deltaTime < targetFrameRate){
|
||||
sleep((int)(1000.0 * (targetFrameRate - deltaTime)));
|
||||
if(deltaTime < targetFramePeriod){
|
||||
sleep((int)(1000.0 * (targetFramePeriod - deltaTime)));
|
||||
} else {
|
||||
sleep(1);
|
||||
}
|
||||
frameCount++;
|
||||
// sleep((int)(1000.0*Math.max(0.001, deltaTime-targetFrameRate)));
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// S H U T D O W N
|
||||
//
|
||||
//Terminate the program.
|
||||
glfwTerminate();
|
||||
//used to signal threads to stop
|
||||
@ -333,6 +308,7 @@ public class Main {
|
||||
}
|
||||
//shut down audio engine
|
||||
Globals.audioEngine.shutdown();
|
||||
|
||||
}
|
||||
|
||||
static void sleep(int i) {
|
||||
|
||||
@ -14,7 +14,6 @@ import electrosphere.game.server.pathfinding.navmesh.NavMesh;
|
||||
import electrosphere.game.server.pathfinding.navmesh.NavShape;
|
||||
import electrosphere.logger.LoggerInterface;
|
||||
import electrosphere.main.Globals;
|
||||
import static electrosphere.main.Main.deltaTime;
|
||||
import static electrosphere.main.Main.view_Range;
|
||||
import static electrosphere.renderer.RenderUtils.createScreenTextureVAO;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user