Fix server part of entity instancing
This commit is contained in:
parent
3388325838
commit
e18e342492
@ -198,7 +198,7 @@ public class ControlHandler {
|
|||||||
if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && glfwGetKey(Globals.window, controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue()) == GLFW_PRESS){
|
if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && glfwGetKey(Globals.window, controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue()) == GLFW_PRESS){
|
||||||
Vector3f newFacingVector = new Vector3f(-cameraEyeVector.x,0,-cameraEyeVector.z).normalize();
|
Vector3f newFacingVector = new Vector3f(-cameraEyeVector.x,0,-cameraEyeVector.z).normalize();
|
||||||
CreatureUtils.setMovementVector(Globals.playerCharacter, newFacingVector);
|
CreatureUtils.setMovementVector(Globals.playerCharacter, newFacingVector);
|
||||||
System.out.println("Movement vector: " + newFacingVector);
|
// System.out.println("Movement vector: " + newFacingVector);
|
||||||
if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN){
|
if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN){
|
||||||
movementTree.start();
|
movementTree.start();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -83,6 +83,7 @@ public class MovementTree {
|
|||||||
// Model entityModel = Globals.assetManager.fetchModel(EntityUtils.getEntityModelPath(parent));
|
// Model entityModel = Globals.assetManager.fetchModel(EntityUtils.getEntityModelPath(parent));
|
||||||
Vector3f position = EntityUtils.getPosition(parent);
|
Vector3f position = EntityUtils.getPosition(parent);
|
||||||
Vector3f movementVector = CreatureUtils.getMovementVector(parent);
|
Vector3f movementVector = CreatureUtils.getMovementVector(parent);
|
||||||
|
Quaternionf movementQuaternion = new Quaternionf().rotationTo(new Vector3f(0,0,1), movementVector).normalize();
|
||||||
Quaternionf rotation = EntityUtils.getRotation(parent);
|
Quaternionf rotation = EntityUtils.getRotation(parent);
|
||||||
Vector3f newPosition;
|
Vector3f newPosition;
|
||||||
javax.vecmath.Matrix4f bodyTransformMatrix;
|
javax.vecmath.Matrix4f bodyTransformMatrix;
|
||||||
@ -120,7 +121,7 @@ public class MovementTree {
|
|||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
state = MovementTreeState.MOVE;
|
state = MovementTreeState.MOVE;
|
||||||
System.out.println("Set state MOVE");
|
// System.out.println("Set state MOVE");
|
||||||
activateGravityTree();
|
activateGravityTree();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
@ -171,16 +172,16 @@ public class MovementTree {
|
|||||||
state = MovementTreeState.MOVE;
|
state = MovementTreeState.MOVE;
|
||||||
}
|
}
|
||||||
// body.applyCentralForce(PhysicsUtils.jomlToVecmathVector3f(new Vector3f(movementVector.x,0,movementVector.z).normalize().mul(velocity)));
|
// body.applyCentralForce(PhysicsUtils.jomlToVecmathVector3f(new Vector3f(movementVector.x,0,movementVector.z).normalize().mul(velocity)));
|
||||||
EntityUtils.getRotation(parent).rotationTo(new Vector3f(0,0,1), new Vector3f(movementVector.x,0,movementVector.z));
|
EntityUtils.getRotation(parent).set(movementQuaternion);
|
||||||
//move the entity
|
//move the entity
|
||||||
newPosition = new Vector3f(position).add(new Vector3f(movementVector).mul(velocity));
|
newPosition = new Vector3f(position).add(new Vector3f(0,0,1).rotate(movementQuaternion).mul(velocity));
|
||||||
//check/update if collision
|
//check/update if collision
|
||||||
if(!Globals.collisionEngine.checkCanOccupyPosition(Globals.commonWorldData, parent, newPosition)){
|
if(!Globals.collisionEngine.checkCanOccupyPosition(Globals.commonWorldData, parent, newPosition)){
|
||||||
newPosition = Globals.collisionEngine.suggestMovementPosition(Globals.commonWorldData, parent, newPosition);
|
newPosition = Globals.collisionEngine.suggestMovementPosition(Globals.commonWorldData, parent, newPosition);
|
||||||
}
|
}
|
||||||
// //actually update
|
// //actually update
|
||||||
position.set(newPosition);
|
position.set(newPosition);
|
||||||
rotation.rotationTo(new Vector3f(0,0,1), movementVector);
|
rotation.set(movementQuaternion);
|
||||||
|
|
||||||
bodyTransformMatrix = new javax.vecmath.Matrix4f(PhysicsUtils.jomlToVecmathQuaternionf(rotation),PhysicsUtils.jomlToVecmathVector3f(newPosition),1.0f);
|
bodyTransformMatrix = new javax.vecmath.Matrix4f(PhysicsUtils.jomlToVecmathQuaternionf(rotation),PhysicsUtils.jomlToVecmathVector3f(newPosition),1.0f);
|
||||||
body.setWorldTransform(new electrosphere.linearmath.Transform(bodyTransformMatrix));
|
body.setWorldTransform(new electrosphere.linearmath.Transform(bodyTransformMatrix));
|
||||||
@ -244,17 +245,16 @@ public class MovementTree {
|
|||||||
entityActor.incrementAnimationTime(0.01);
|
entityActor.incrementAnimationTime(0.01);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Vector3f force = new Vector3f(movementVector).normalize().mul(velocity);
|
|
||||||
// body.applyCentralForce(PhysicsUtils.jomlToVecmathVector3f(force));
|
// body.applyCentralForce(PhysicsUtils.jomlToVecmathVector3f(force));
|
||||||
EntityUtils.getRotation(parent).rotationTo(new Vector3f(0,0,1), new Vector3f(movementVector.x,0,movementVector.z));
|
EntityUtils.getRotation(parent).set(movementQuaternion);
|
||||||
//check if can move forward (collision engine)
|
//check if can move forward (collision engine)
|
||||||
//if can, move forward by entity movement stats
|
//if can, move forward by entity movement stats
|
||||||
newPosition = new Vector3f(position).add(new Vector3f(movementVector).mul(velocity));
|
newPosition = new Vector3f(position).add(new Vector3f(0,0,1).rotate(movementQuaternion).mul(velocity));
|
||||||
if(!Globals.collisionEngine.checkCanOccupyPosition(Globals.commonWorldData, parent, newPosition)){
|
if(!Globals.collisionEngine.checkCanOccupyPosition(Globals.commonWorldData, parent, newPosition)){
|
||||||
newPosition = Globals.collisionEngine.suggestMovementPosition(Globals.commonWorldData, parent, newPosition);
|
newPosition = Globals.collisionEngine.suggestMovementPosition(Globals.commonWorldData, parent, newPosition);
|
||||||
}
|
}
|
||||||
position.set(newPosition);
|
position.set(newPosition);
|
||||||
rotation.rotationTo(new Vector3f(0,0,1), movementVector);
|
rotation.set(movementQuaternion);
|
||||||
|
|
||||||
bodyTransformMatrix = new javax.vecmath.Matrix4f(PhysicsUtils.jomlToVecmathQuaternionf(rotation),PhysicsUtils.jomlToVecmathVector3f(newPosition),1.0f);
|
bodyTransformMatrix = new javax.vecmath.Matrix4f(PhysicsUtils.jomlToVecmathQuaternionf(rotation),PhysicsUtils.jomlToVecmathVector3f(newPosition),1.0f);
|
||||||
body.setWorldTransform(new electrosphere.linearmath.Transform(bodyTransformMatrix));
|
body.setWorldTransform(new electrosphere.linearmath.Transform(bodyTransformMatrix));
|
||||||
@ -325,7 +325,7 @@ public class MovementTree {
|
|||||||
state = MovementTreeState.IDLE;
|
state = MovementTreeState.IDLE;
|
||||||
}
|
}
|
||||||
// body.applyCentralForce(PhysicsUtils.jomlToVecmathVector3f(new Vector3f(movementVector).mul(-1.0f).normalize().mul(velocity)));
|
// body.applyCentralForce(PhysicsUtils.jomlToVecmathVector3f(new Vector3f(movementVector).mul(-1.0f).normalize().mul(velocity)));
|
||||||
EntityUtils.getRotation(parent).rotationTo(new Vector3f(0,0,1), new Vector3f(movementVector.x,0,movementVector.z));
|
EntityUtils.getRotation(parent).rotationTo(new Vector3f(0,0,1), movementVector);
|
||||||
//move the entity
|
//move the entity
|
||||||
newPosition = new Vector3f(position).add(new Vector3f(movementVector).mul(velocity));
|
newPosition = new Vector3f(position).add(new Vector3f(movementVector).mul(velocity));
|
||||||
if(!Globals.collisionEngine.checkCanOccupyPosition(Globals.commonWorldData, parent, newPosition)){
|
if(!Globals.collisionEngine.checkCanOccupyPosition(Globals.commonWorldData, parent, newPosition)){
|
||||||
|
|||||||
@ -31,28 +31,16 @@ public class DataCellManager {
|
|||||||
|
|
||||||
public void addPlayer(Player player){
|
public void addPlayer(Player player){
|
||||||
playerList.add(player);
|
playerList.add(player);
|
||||||
}
|
|
||||||
|
|
||||||
public void movePlayer(Player player, int newX, int newY){
|
|
||||||
int playerSimulationRadius = player.getSimulationRadius();
|
int playerSimulationRadius = player.getSimulationRadius();
|
||||||
int oldX = player.getWorldX();
|
int oldX = player.getWorldX();
|
||||||
int oldY = player.getWorldY();
|
int oldY = player.getWorldY();
|
||||||
player.setWorldX(newX);
|
|
||||||
player.setWorldY(newY);
|
|
||||||
for(int x = oldX - playerSimulationRadius; x < oldX + playerSimulationRadius + 1; x++){
|
for(int x = oldX - playerSimulationRadius; x < oldX + playerSimulationRadius + 1; x++){
|
||||||
for(int y = oldY - playerSimulationRadius; y < oldY + playerSimulationRadius + 1; y++){
|
for(int y = oldY - playerSimulationRadius; y < oldY + playerSimulationRadius + 1; y++){
|
||||||
if(x >= 0 && x < discreteWorldSize && y >= 0 && y < discreteWorldSize){
|
if(
|
||||||
if(dataCells[x][y] != null){
|
x >= 0 && x < discreteWorldSize &&
|
||||||
if(dataCells[x][y].containsPlayer(player)){
|
y >= 0 && y < discreteWorldSize
|
||||||
dataCells[x][y].removePlayer(player);
|
){
|
||||||
}
|
System.out.println("Add player to " + x + " " + y);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(int x = newX - playerSimulationRadius; x < newX + playerSimulationRadius + 1; x++){
|
|
||||||
for(int y = newY - playerSimulationRadius; y < newY + playerSimulationRadius + 1; y++){
|
|
||||||
if(x >= 0 && x < discreteWorldSize && y >= 0 && y < discreteWorldSize){
|
|
||||||
if(dataCells[x][y] != null){
|
if(dataCells[x][y] != null){
|
||||||
dataCells[x][y].addPlayer(player);
|
dataCells[x][y].addPlayer(player);
|
||||||
} else {
|
} else {
|
||||||
@ -66,6 +54,57 @@ public class DataCellManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void movePlayer(Player player, int newX, int newY){
|
||||||
|
int playerSimulationRadius = player.getSimulationRadius();
|
||||||
|
int oldX = player.getWorldX();
|
||||||
|
int oldY = player.getWorldY();
|
||||||
|
player.setWorldX(newX);
|
||||||
|
player.setWorldY(newY);
|
||||||
|
// System.out.println("=======" + "SET" + newX + " " + newY + " FROM " + oldX + " " + oldY + "========");
|
||||||
|
int removals = 0;
|
||||||
|
int additions = 0;
|
||||||
|
for(int x = oldX - playerSimulationRadius; x < oldX + playerSimulationRadius + 1; x++){
|
||||||
|
for(int y = oldY - playerSimulationRadius; y < oldY + playerSimulationRadius + 1; y++){
|
||||||
|
if(
|
||||||
|
x >= 0 && x < discreteWorldSize &&
|
||||||
|
y >= 0 && y < discreteWorldSize &&
|
||||||
|
(x < newX - playerSimulationRadius || x > newX + playerSimulationRadius || y < newY - playerSimulationRadius || y > newY + playerSimulationRadius)
|
||||||
|
){
|
||||||
|
if(dataCells[x][y] != null){
|
||||||
|
if(dataCells[x][y].containsPlayer(player)){
|
||||||
|
removals++;
|
||||||
|
dataCells[x][y].removePlayer(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(int x = newX - playerSimulationRadius; x < newX + playerSimulationRadius + 1; x++){
|
||||||
|
for(int y = newY - playerSimulationRadius; y < newY + playerSimulationRadius + 1; y++){
|
||||||
|
if(
|
||||||
|
x >= 0 && x < discreteWorldSize &&
|
||||||
|
y >= 0 && y < discreteWorldSize &&
|
||||||
|
(x < oldX - playerSimulationRadius || x > oldX + playerSimulationRadius || y < oldY - playerSimulationRadius || y > oldY + playerSimulationRadius)
|
||||||
|
){
|
||||||
|
// System.out.println("Add player to " + x + " " + y);
|
||||||
|
if(dataCells[x][y] != null){
|
||||||
|
dataCells[x][y].addPlayer(player);
|
||||||
|
} else {
|
||||||
|
//create data cell
|
||||||
|
dataCells[x][y] = new ServerDataCell();
|
||||||
|
//add player
|
||||||
|
dataCells[x][y].addPlayer(player);
|
||||||
|
}
|
||||||
|
additions++;
|
||||||
|
} else {
|
||||||
|
// System.out.println(x + "\t" + (oldX - playerSimulationRadius) + "\t" + (oldX + playerSimulationRadius));
|
||||||
|
// System.out.println(y + "\t" + (oldY - playerSimulationRadius) + "\t" + (oldY + playerSimulationRadius));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// System.out.println("removals: " + removals + "\tadditions: " + additions);
|
||||||
|
}
|
||||||
|
|
||||||
public void removePlayer(Player player){
|
public void removePlayer(Player player){
|
||||||
throw new UnsupportedOperationException("Removing players from the data cell manager isn't supported -- DataCellManager -- removePlayer(Player player)");
|
throw new UnsupportedOperationException("Removing players from the data cell manager isn't supported -- DataCellManager -- removePlayer(Player player)");
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user