Movement tree network streaming
This commit is contained in:
parent
d889e6126c
commit
f66dab4f5f
@ -221,15 +221,15 @@ public class ControlHandler {
|
|||||||
}
|
}
|
||||||
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD, true);
|
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD, true);
|
||||||
//send to server
|
//send to server
|
||||||
Vector3f position = EntityUtils.getEntityPosition(Globals.playerCharacter);
|
// Vector3f position = EntityUtils.getEntityPosition(Globals.playerCharacter);
|
||||||
EntityMessage outgoingMessage = EntityMessage.constructMoveMessage(
|
// EntityMessage outgoingMessage = EntityMessage.constructMoveMessage(
|
||||||
Globals.playerCharacter.getId(),
|
// Globals.playerCharacter.getId(),
|
||||||
System.currentTimeMillis(),
|
// System.currentTimeMillis(),
|
||||||
position.x,
|
// position.x,
|
||||||
position.y,
|
// position.y,
|
||||||
position.z
|
// position.z
|
||||||
);
|
// );
|
||||||
Globals.clientConnection.queueOutgoingMessage(outgoingMessage);
|
// Globals.clientConnection.queueOutgoingMessage(outgoingMessage);
|
||||||
} else {
|
} else {
|
||||||
if(controlsState.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD) == true){
|
if(controlsState.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD) == true){
|
||||||
movementTree.slowdown();
|
movementTree.slowdown();
|
||||||
@ -248,15 +248,15 @@ public class ControlHandler {
|
|||||||
}
|
}
|
||||||
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD, true);
|
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD, true);
|
||||||
//send to server
|
//send to server
|
||||||
Vector3f position = EntityUtils.getEntityPosition(Globals.playerCharacter);
|
// Vector3f position = EntityUtils.getEntityPosition(Globals.playerCharacter);
|
||||||
EntityMessage outgoingMessage = EntityMessage.constructMoveMessage(
|
// EntityMessage outgoingMessage = EntityMessage.constructMoveMessage(
|
||||||
Globals.playerCharacter.getId(),
|
// Globals.playerCharacter.getId(),
|
||||||
System.currentTimeMillis(),
|
// System.currentTimeMillis(),
|
||||||
position.x,
|
// position.x,
|
||||||
position.y,
|
// position.y,
|
||||||
position.z
|
// position.z
|
||||||
);
|
// );
|
||||||
Globals.clientConnection.queueOutgoingMessage(outgoingMessage);
|
// Globals.clientConnection.queueOutgoingMessage(outgoingMessage);
|
||||||
} else {
|
} else {
|
||||||
if(controlsState.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD) == true){
|
if(controlsState.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD) == true){
|
||||||
movementTree.slowdown();
|
movementTree.slowdown();
|
||||||
@ -275,15 +275,15 @@ public class ControlHandler {
|
|||||||
}
|
}
|
||||||
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT, true);
|
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT, true);
|
||||||
//send to server
|
//send to server
|
||||||
Vector3f position = EntityUtils.getEntityPosition(Globals.playerCharacter);
|
// Vector3f position = EntityUtils.getEntityPosition(Globals.playerCharacter);
|
||||||
EntityMessage outgoingMessage = EntityMessage.constructMoveMessage(
|
// EntityMessage outgoingMessage = EntityMessage.constructMoveMessage(
|
||||||
Globals.playerCharacter.getId(),
|
// Globals.playerCharacter.getId(),
|
||||||
System.currentTimeMillis(),
|
// System.currentTimeMillis(),
|
||||||
position.x,
|
// position.x,
|
||||||
position.y,
|
// position.y,
|
||||||
position.z
|
// position.z
|
||||||
);
|
// );
|
||||||
Globals.clientConnection.queueOutgoingMessage(outgoingMessage);
|
// Globals.clientConnection.queueOutgoingMessage(outgoingMessage);
|
||||||
} else {
|
} else {
|
||||||
if(controlsState.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT) == true){
|
if(controlsState.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT) == true){
|
||||||
movementTree.slowdown();
|
movementTree.slowdown();
|
||||||
@ -302,15 +302,15 @@ public class ControlHandler {
|
|||||||
}
|
}
|
||||||
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT, true);
|
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT, true);
|
||||||
//send to server
|
//send to server
|
||||||
Vector3f position = EntityUtils.getEntityPosition(Globals.playerCharacter);
|
// Vector3f position = EntityUtils.getEntityPosition(Globals.playerCharacter);
|
||||||
EntityMessage outgoingMessage = EntityMessage.constructMoveMessage(
|
// EntityMessage outgoingMessage = EntityMessage.constructMoveMessage(
|
||||||
Globals.playerCharacter.getId(),
|
// Globals.playerCharacter.getId(),
|
||||||
System.currentTimeMillis(),
|
// System.currentTimeMillis(),
|
||||||
position.x,
|
// position.x,
|
||||||
position.y,
|
// position.y,
|
||||||
position.z
|
// position.z
|
||||||
);
|
// );
|
||||||
Globals.clientConnection.queueOutgoingMessage(outgoingMessage);
|
// Globals.clientConnection.queueOutgoingMessage(outgoingMessage);
|
||||||
} else {
|
} else {
|
||||||
if(controlsState.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT) == true){
|
if(controlsState.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT) == true){
|
||||||
movementTree.slowdown();
|
movementTree.slowdown();
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package electrosphere.entity;
|
package electrosphere.entity;
|
||||||
|
|
||||||
|
import electrosphere.main.Globals;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -51,6 +52,9 @@ public class Entity {
|
|||||||
public Entity(){
|
public Entity(){
|
||||||
data = new HashMap();
|
data = new HashMap();
|
||||||
dataKeys = new LinkedList();
|
dataKeys = new LinkedList();
|
||||||
|
while(Globals.entityManager.getEntityFromId(entity_id_iterator)!=null){
|
||||||
|
entity_id_iterator++;
|
||||||
|
}
|
||||||
id = entity_id_iterator;
|
id = entity_id_iterator;
|
||||||
entity_id_iterator++;
|
entity_id_iterator++;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package electrosphere.entity;
|
package electrosphere.entity;
|
||||||
|
|
||||||
|
import electrosphere.logger.LoggerInterface;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
@ -100,6 +101,7 @@ public class EntityManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void overrideEntityId(Entity e, int id){
|
public void overrideEntityId(Entity e, int id){
|
||||||
|
LoggerInterface.loggerGameLogic.DEBUG("Overriding entity ID " + e.getId() + " => " + id);
|
||||||
if(entityIdMap.contains(e.getId())){
|
if(entityIdMap.contains(e.getId())){
|
||||||
entityIdMap.remove(e.getId());
|
entityIdMap.remove(e.getId());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import electrosphere.renderer.anim.Animation;
|
|||||||
import electrosphere.renderer.Model;
|
import electrosphere.renderer.Model;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
import org.joml.Quaternionf;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -78,17 +79,45 @@ public class MovementTree {
|
|||||||
switch(message.getMessageSubtype()){
|
switch(message.getMessageSubtype()){
|
||||||
case MOVE:
|
case MOVE:
|
||||||
position.set(message.getpositionX(), message.getpositionY(), message.getpositionZ());
|
position.set(message.getpositionX(), message.getpositionY(), message.getpositionZ());
|
||||||
if(Globals.RUN_SERVER){
|
// if(Globals.RUN_SERVER){
|
||||||
Globals.server.broadcastMessage(
|
// Globals.server.broadcastMessage(
|
||||||
EntityMessage.constructMoveMessage(
|
// EntityMessage.constructMoveMessage(
|
||||||
parent.getId(),
|
// parent.getId(),
|
||||||
System.currentTimeMillis(),
|
// System.currentTimeMillis(),
|
||||||
message.getpositionX(),
|
// message.getpositionX(),
|
||||||
message.getpositionY(),
|
// message.getpositionY(),
|
||||||
message.getpositionZ()
|
// message.getpositionZ()
|
||||||
)
|
// )
|
||||||
);
|
// );
|
||||||
|
// }
|
||||||
|
break;
|
||||||
|
case SETFACING:
|
||||||
|
break;
|
||||||
|
case MOVEUPDATE:
|
||||||
|
switch(message.getmoveState()){
|
||||||
|
case 0:
|
||||||
|
state = MovementTreeState.STARTUP;
|
||||||
|
// System.out.println("Set state STARTUP");
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
state = MovementTreeState.MOVE;
|
||||||
|
System.out.println("Set state MOVE");
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
state = MovementTreeState.SLOWDOWN;
|
||||||
|
// System.out.println("Set state SLOWDOWN");
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
state = MovementTreeState.IDLE;
|
||||||
|
// System.out.println("Set state IDLE");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
// System.out.println(EntityUtils.getEntityPosition(parent));
|
||||||
|
// System.out.println(message.getpositionX() + " " + message.getpositionY() + " " + message.getpositionZ());
|
||||||
|
EntityUtils.getEntityPosition(parent).set(message.getpositionX(),message.getpositionY(),message.getpositionZ());
|
||||||
|
CreatureUtils.setMovementVector(parent, new Vector3f(message.getrotationX(),message.getrotationY(),message.getrotationZ()));
|
||||||
|
// EntityUtils.getEntityRotation(parent).set(message.getrotationX(), message.getrotationY(), message.getrotationZ(), message.getrotationW()).normalize();
|
||||||
|
// velocity = message.getvelocity();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -119,6 +148,37 @@ public class MovementTree {
|
|||||||
//actually update
|
//actually update
|
||||||
EntityUtils.getEntityPosition(parent).set(newPosition);
|
EntityUtils.getEntityPosition(parent).set(newPosition);
|
||||||
EntityUtils.getEntityRotation(parent).rotationTo(new Vector3f(0,0,1), movementVector);
|
EntityUtils.getEntityRotation(parent).rotationTo(new Vector3f(0,0,1), movementVector);
|
||||||
|
if(Globals.RUN_SERVER){
|
||||||
|
Globals.server.broadcastMessage(
|
||||||
|
EntityMessage.constructmoveUpdateMessage(
|
||||||
|
parent.getId(),
|
||||||
|
System.currentTimeMillis(),
|
||||||
|
newPosition.x,
|
||||||
|
newPosition.y,
|
||||||
|
newPosition.z,
|
||||||
|
movementVector.x,
|
||||||
|
movementVector.y,
|
||||||
|
movementVector.z,
|
||||||
|
velocity,
|
||||||
|
0
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else if(Globals.RUN_CLIENT && parent.getId() == Globals.clientCharacterID){
|
||||||
|
Globals.clientConnection.queueOutgoingMessage(
|
||||||
|
EntityMessage.constructmoveUpdateMessage(
|
||||||
|
parent.getId(),
|
||||||
|
System.currentTimeMillis(),
|
||||||
|
newPosition.x,
|
||||||
|
newPosition.y,
|
||||||
|
newPosition.z,
|
||||||
|
movementVector.x,
|
||||||
|
movementVector.y,
|
||||||
|
movementVector.z,
|
||||||
|
velocity,
|
||||||
|
0
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case MOVE:
|
case MOVE:
|
||||||
//check if can restart animation
|
//check if can restart animation
|
||||||
@ -137,6 +197,37 @@ public class MovementTree {
|
|||||||
}
|
}
|
||||||
EntityUtils.getEntityPosition(parent).set(newPosition);
|
EntityUtils.getEntityPosition(parent).set(newPosition);
|
||||||
EntityUtils.getEntityRotation(parent).rotationTo(new Vector3f(0,0,1), movementVector);
|
EntityUtils.getEntityRotation(parent).rotationTo(new Vector3f(0,0,1), movementVector);
|
||||||
|
if(Globals.RUN_SERVER){
|
||||||
|
Globals.server.broadcastMessage(
|
||||||
|
EntityMessage.constructmoveUpdateMessage(
|
||||||
|
parent.getId(),
|
||||||
|
System.currentTimeMillis(),
|
||||||
|
newPosition.x,
|
||||||
|
newPosition.y,
|
||||||
|
newPosition.z,
|
||||||
|
movementVector.x,
|
||||||
|
movementVector.y,
|
||||||
|
movementVector.z,
|
||||||
|
velocity,
|
||||||
|
1
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else if(Globals.RUN_CLIENT && parent.getId() == Globals.clientCharacterID){
|
||||||
|
Globals.clientConnection.queueOutgoingMessage(
|
||||||
|
EntityMessage.constructmoveUpdateMessage(
|
||||||
|
parent.getId(),
|
||||||
|
System.currentTimeMillis(),
|
||||||
|
newPosition.x,
|
||||||
|
newPosition.y,
|
||||||
|
newPosition.z,
|
||||||
|
movementVector.x,
|
||||||
|
movementVector.y,
|
||||||
|
movementVector.z,
|
||||||
|
velocity,
|
||||||
|
1
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case SLOWDOWN:
|
case SLOWDOWN:
|
||||||
//run slowdown code
|
//run slowdown code
|
||||||
@ -160,6 +251,37 @@ public class MovementTree {
|
|||||||
}
|
}
|
||||||
EntityUtils.getEntityPosition(parent).set(newPosition);
|
EntityUtils.getEntityPosition(parent).set(newPosition);
|
||||||
EntityUtils.getEntityRotation(parent).rotationTo(new Vector3f(0,0,1), movementVector);
|
EntityUtils.getEntityRotation(parent).rotationTo(new Vector3f(0,0,1), movementVector);
|
||||||
|
if(Globals.RUN_SERVER){
|
||||||
|
Globals.server.broadcastMessage(
|
||||||
|
EntityMessage.constructmoveUpdateMessage(
|
||||||
|
parent.getId(),
|
||||||
|
System.currentTimeMillis(),
|
||||||
|
newPosition.x,
|
||||||
|
newPosition.y,
|
||||||
|
newPosition.z,
|
||||||
|
movementVector.x,
|
||||||
|
movementVector.y,
|
||||||
|
movementVector.z,
|
||||||
|
velocity,
|
||||||
|
2
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else if(Globals.RUN_CLIENT && parent.getId() == Globals.clientCharacterID){
|
||||||
|
Globals.clientConnection.queueOutgoingMessage(
|
||||||
|
EntityMessage.constructmoveUpdateMessage(
|
||||||
|
parent.getId(),
|
||||||
|
System.currentTimeMillis(),
|
||||||
|
newPosition.x,
|
||||||
|
newPosition.y,
|
||||||
|
newPosition.z,
|
||||||
|
movementVector.x,
|
||||||
|
movementVector.y,
|
||||||
|
movementVector.z,
|
||||||
|
velocity,
|
||||||
|
2
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case IDLE:
|
case IDLE:
|
||||||
if(entityActor != null){
|
if(entityActor != null){
|
||||||
|
|||||||
@ -17,7 +17,7 @@ public class LoggerInterface {
|
|||||||
public static Logger loggerEngine;
|
public static Logger loggerEngine;
|
||||||
|
|
||||||
public static void initLoggers(){
|
public static void initLoggers(){
|
||||||
loggerNetworking = new Logger(LogLevel.INFO);
|
loggerNetworking = new Logger(LogLevel.DEBUG);
|
||||||
loggerFileIO = new Logger(LogLevel.ERROR);
|
loggerFileIO = new Logger(LogLevel.ERROR);
|
||||||
loggerGameLogic = new Logger(LogLevel.DEBUG);
|
loggerGameLogic = new Logger(LogLevel.DEBUG);
|
||||||
loggerRenderer = new Logger(LogLevel.WARNING);
|
loggerRenderer = new Logger(LogLevel.WARNING);
|
||||||
|
|||||||
@ -70,6 +70,7 @@ public class Globals {
|
|||||||
//
|
//
|
||||||
public static ClientNetworking clientConnection;
|
public static ClientNetworking clientConnection;
|
||||||
public static boolean RUN_CLIENT = true;
|
public static boolean RUN_CLIENT = true;
|
||||||
|
public static int clientCharacterID;
|
||||||
|
|
||||||
//
|
//
|
||||||
//Server manager thing
|
//Server manager thing
|
||||||
|
|||||||
@ -78,6 +78,7 @@ public class ClientProtocol {
|
|||||||
if(target != null){
|
if(target != null){
|
||||||
CreatureUtils.setControllerPlayerId(target, message.getpropertyValue());
|
CreatureUtils.setControllerPlayerId(target, message.getpropertyValue());
|
||||||
if(message.getpropertyValue() == Main.playerId){
|
if(message.getpropertyValue() == Main.playerId){
|
||||||
|
Globals.clientCharacterID = message.getentityID();
|
||||||
Globals.playerCharacter = target;
|
Globals.playerCharacter = target;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -91,6 +92,9 @@ public class ClientProtocol {
|
|||||||
AttachUtils.attachEntityToEntityAtBone(parent, child, message.getbone());
|
AttachUtils.attachEntityToEntityAtBone(parent, child, message.getbone());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case MOVEUPDATE:
|
||||||
|
CreatureUtils.attachEntityMessageToMovementTree(Globals.entityManager.getEntityFromId(message.getentityID()),message);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -9,6 +9,8 @@ public class EntityMessage extends NetworkMessage {
|
|||||||
public enum EntityMessageType {
|
public enum EntityMessageType {
|
||||||
CREATE,
|
CREATE,
|
||||||
SETPOSITION,
|
SETPOSITION,
|
||||||
|
SETFACING,
|
||||||
|
MOVEUPDATE,
|
||||||
MOVE,
|
MOVE,
|
||||||
DESTROY,
|
DESTROY,
|
||||||
SETBEHAVIORTREE,
|
SETBEHAVIORTREE,
|
||||||
@ -22,6 +24,12 @@ public class EntityMessage extends NetworkMessage {
|
|||||||
float positionX;
|
float positionX;
|
||||||
float positionY;
|
float positionY;
|
||||||
float positionZ;
|
float positionZ;
|
||||||
|
float rotationW;
|
||||||
|
float rotationX;
|
||||||
|
float rotationY;
|
||||||
|
float rotationZ;
|
||||||
|
float velocity;
|
||||||
|
int moveState;
|
||||||
int propertyType;
|
int propertyType;
|
||||||
int propertyValue;
|
int propertyValue;
|
||||||
int treeType;
|
int treeType;
|
||||||
@ -79,6 +87,54 @@ public class EntityMessage extends NetworkMessage {
|
|||||||
this.positionZ = positionZ;
|
this.positionZ = positionZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getrotationW() {
|
||||||
|
return rotationW;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setrotationW(float rotationW) {
|
||||||
|
this.rotationW = rotationW;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getrotationX() {
|
||||||
|
return rotationX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setrotationX(float rotationX) {
|
||||||
|
this.rotationX = rotationX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getrotationY() {
|
||||||
|
return rotationY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setrotationY(float rotationY) {
|
||||||
|
this.rotationY = rotationY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getrotationZ() {
|
||||||
|
return rotationZ;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setrotationZ(float rotationZ) {
|
||||||
|
this.rotationZ = rotationZ;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getvelocity() {
|
||||||
|
return velocity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setvelocity(float velocity) {
|
||||||
|
this.velocity = velocity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getmoveState() {
|
||||||
|
return moveState;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setmoveState(int moveState) {
|
||||||
|
this.moveState = moveState;
|
||||||
|
}
|
||||||
|
|
||||||
public int getpropertyType() {
|
public int getpropertyType() {
|
||||||
return propertyType;
|
return propertyType;
|
||||||
}
|
}
|
||||||
@ -154,6 +210,18 @@ public class EntityMessage extends NetworkMessage {
|
|||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
case TypeBytes.ENTITY_MESSAGE_TYPE_SETFACING:
|
||||||
|
if(byteStream.size() >= TypeBytes.ENTITY_MESSAGE_TYPE_SETFACING_SIZE){
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
case TypeBytes.ENTITY_MESSAGE_TYPE_MOVEUPDATE:
|
||||||
|
if(byteStream.size() >= TypeBytes.ENTITY_MESSAGE_TYPE_MOVEUPDATE_SIZE){
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
case TypeBytes.ENTITY_MESSAGE_TYPE_MOVE:
|
case TypeBytes.ENTITY_MESSAGE_TYPE_MOVE:
|
||||||
if(byteStream.size() >= TypeBytes.ENTITY_MESSAGE_TYPE_MOVE_SIZE){
|
if(byteStream.size() >= TypeBytes.ENTITY_MESSAGE_TYPE_MOVE_SIZE){
|
||||||
return true;
|
return true;
|
||||||
@ -228,6 +296,60 @@ public class EntityMessage extends NetworkMessage {
|
|||||||
return rVal;
|
return rVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static EntityMessage parsesetFacingMessage(List<Byte> byteStream){
|
||||||
|
EntityMessage rVal = new EntityMessage(EntityMessageType.SETFACING);
|
||||||
|
stripPacketHeader(byteStream);
|
||||||
|
rVal.setentityID(ByteStreamUtils.popIntFromByteQueue(byteStream));
|
||||||
|
rVal.settime(ByteStreamUtils.popLongFromByteQueue(byteStream));
|
||||||
|
rVal.setrotationX(ByteStreamUtils.popFloatFromByteQueue(byteStream));
|
||||||
|
rVal.setrotationY(ByteStreamUtils.popFloatFromByteQueue(byteStream));
|
||||||
|
rVal.setrotationZ(ByteStreamUtils.popFloatFromByteQueue(byteStream));
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static EntityMessage constructsetFacingMessage(int entityID,long time,float rotationX,float rotationY,float rotationZ){
|
||||||
|
EntityMessage rVal = new EntityMessage(EntityMessageType.SETFACING);
|
||||||
|
rVal.setentityID(entityID);
|
||||||
|
rVal.settime(time);
|
||||||
|
rVal.setrotationX(rotationX);
|
||||||
|
rVal.setrotationY(rotationY);
|
||||||
|
rVal.setrotationZ(rotationZ);
|
||||||
|
rVal.serialize();
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static EntityMessage parsemoveUpdateMessage(List<Byte> byteStream){
|
||||||
|
EntityMessage rVal = new EntityMessage(EntityMessageType.MOVEUPDATE);
|
||||||
|
stripPacketHeader(byteStream);
|
||||||
|
rVal.setentityID(ByteStreamUtils.popIntFromByteQueue(byteStream));
|
||||||
|
rVal.settime(ByteStreamUtils.popLongFromByteQueue(byteStream));
|
||||||
|
rVal.setpositionX(ByteStreamUtils.popFloatFromByteQueue(byteStream));
|
||||||
|
rVal.setpositionY(ByteStreamUtils.popFloatFromByteQueue(byteStream));
|
||||||
|
rVal.setpositionZ(ByteStreamUtils.popFloatFromByteQueue(byteStream));
|
||||||
|
rVal.setrotationX(ByteStreamUtils.popFloatFromByteQueue(byteStream));
|
||||||
|
rVal.setrotationY(ByteStreamUtils.popFloatFromByteQueue(byteStream));
|
||||||
|
rVal.setrotationZ(ByteStreamUtils.popFloatFromByteQueue(byteStream));
|
||||||
|
rVal.setvelocity(ByteStreamUtils.popFloatFromByteQueue(byteStream));
|
||||||
|
rVal.setmoveState(ByteStreamUtils.popIntFromByteQueue(byteStream));
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static EntityMessage constructmoveUpdateMessage(int entityID,long time,float positionX,float positionY,float positionZ,float rotationX,float rotationY,float rotationZ,float velocity,int moveState){
|
||||||
|
EntityMessage rVal = new EntityMessage(EntityMessageType.MOVEUPDATE);
|
||||||
|
rVal.setentityID(entityID);
|
||||||
|
rVal.settime(time);
|
||||||
|
rVal.setpositionX(positionX);
|
||||||
|
rVal.setpositionY(positionY);
|
||||||
|
rVal.setpositionZ(positionZ);
|
||||||
|
rVal.setrotationX(rotationX);
|
||||||
|
rVal.setrotationY(rotationY);
|
||||||
|
rVal.setrotationZ(rotationZ);
|
||||||
|
rVal.setvelocity(velocity);
|
||||||
|
rVal.setmoveState(moveState);
|
||||||
|
rVal.serialize();
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
public static EntityMessage parseMoveMessage(List<Byte> byteStream){
|
public static EntityMessage parseMoveMessage(List<Byte> byteStream){
|
||||||
EntityMessage rVal = new EntityMessage(EntityMessageType.MOVE);
|
EntityMessage rVal = new EntityMessage(EntityMessageType.MOVE);
|
||||||
stripPacketHeader(byteStream);
|
stripPacketHeader(byteStream);
|
||||||
@ -400,6 +522,70 @@ public class EntityMessage extends NetworkMessage {
|
|||||||
for(int i = 0; i < 4; i++){
|
for(int i = 0; i < 4; i++){
|
||||||
rawBytes[22+i] = intValues[i];
|
rawBytes[22+i] = intValues[i];
|
||||||
} break;
|
} break;
|
||||||
|
case SETFACING:
|
||||||
|
rawBytes = new byte[2+4+8+4+4+4];
|
||||||
|
//message header
|
||||||
|
rawBytes[0] = TypeBytes.MESSAGE_TYPE_ENTITY;
|
||||||
|
//entity messaage header
|
||||||
|
rawBytes[1] = TypeBytes.ENTITY_MESSAGE_TYPE_SETFACING;
|
||||||
|
intValues = ByteStreamUtils.serializeIntToBytes(entityID);
|
||||||
|
for(int i = 0; i < 4; i++){
|
||||||
|
rawBytes[2+i] = intValues[i];
|
||||||
|
}
|
||||||
|
intValues = ByteStreamUtils.serializeLongToBytes(time);
|
||||||
|
for(int i = 0; i < 8; i++){
|
||||||
|
rawBytes[6+i] = intValues[i];
|
||||||
|
}
|
||||||
|
intValues = ByteStreamUtils.serializeFloatToBytes(rotationX);
|
||||||
|
for(int i = 0; i < 4; i++){
|
||||||
|
rawBytes[14+i] = intValues[i];
|
||||||
|
} intValues = ByteStreamUtils.serializeFloatToBytes(rotationY);
|
||||||
|
for(int i = 0; i < 4; i++){
|
||||||
|
rawBytes[18+i] = intValues[i];
|
||||||
|
} intValues = ByteStreamUtils.serializeFloatToBytes(rotationZ);
|
||||||
|
for(int i = 0; i < 4; i++){
|
||||||
|
rawBytes[22+i] = intValues[i];
|
||||||
|
} break;
|
||||||
|
case MOVEUPDATE:
|
||||||
|
rawBytes = new byte[2+4+8+4+4+4+4+4+4+4+4];
|
||||||
|
//message header
|
||||||
|
rawBytes[0] = TypeBytes.MESSAGE_TYPE_ENTITY;
|
||||||
|
//entity messaage header
|
||||||
|
rawBytes[1] = TypeBytes.ENTITY_MESSAGE_TYPE_MOVEUPDATE;
|
||||||
|
intValues = ByteStreamUtils.serializeIntToBytes(entityID);
|
||||||
|
for(int i = 0; i < 4; i++){
|
||||||
|
rawBytes[2+i] = intValues[i];
|
||||||
|
}
|
||||||
|
intValues = ByteStreamUtils.serializeLongToBytes(time);
|
||||||
|
for(int i = 0; i < 8; i++){
|
||||||
|
rawBytes[6+i] = intValues[i];
|
||||||
|
}
|
||||||
|
intValues = ByteStreamUtils.serializeFloatToBytes(positionX);
|
||||||
|
for(int i = 0; i < 4; i++){
|
||||||
|
rawBytes[14+i] = intValues[i];
|
||||||
|
} intValues = ByteStreamUtils.serializeFloatToBytes(positionY);
|
||||||
|
for(int i = 0; i < 4; i++){
|
||||||
|
rawBytes[18+i] = intValues[i];
|
||||||
|
} intValues = ByteStreamUtils.serializeFloatToBytes(positionZ);
|
||||||
|
for(int i = 0; i < 4; i++){
|
||||||
|
rawBytes[22+i] = intValues[i];
|
||||||
|
} intValues = ByteStreamUtils.serializeFloatToBytes(rotationX);
|
||||||
|
for(int i = 0; i < 4; i++){
|
||||||
|
rawBytes[26+i] = intValues[i];
|
||||||
|
} intValues = ByteStreamUtils.serializeFloatToBytes(rotationY);
|
||||||
|
for(int i = 0; i < 4; i++){
|
||||||
|
rawBytes[30+i] = intValues[i];
|
||||||
|
} intValues = ByteStreamUtils.serializeFloatToBytes(rotationZ);
|
||||||
|
for(int i = 0; i < 4; i++){
|
||||||
|
rawBytes[34+i] = intValues[i];
|
||||||
|
} intValues = ByteStreamUtils.serializeFloatToBytes(velocity);
|
||||||
|
for(int i = 0; i < 4; i++){
|
||||||
|
rawBytes[38+i] = intValues[i];
|
||||||
|
} intValues = ByteStreamUtils.serializeIntToBytes(moveState);
|
||||||
|
for(int i = 0; i < 4; i++){
|
||||||
|
rawBytes[42+i] = intValues[i];
|
||||||
|
}
|
||||||
|
break;
|
||||||
case MOVE:
|
case MOVE:
|
||||||
rawBytes = new byte[2+4+8+4+4+4];
|
rawBytes = new byte[2+4+8+4+4+4];
|
||||||
//message header
|
//message header
|
||||||
|
|||||||
@ -99,6 +99,16 @@ ENTITY_MESSAGE,
|
|||||||
rVal = EntityMessage.parseSetPositionMessage(byteStream);
|
rVal = EntityMessage.parseSetPositionMessage(byteStream);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case TypeBytes.ENTITY_MESSAGE_TYPE_SETFACING:
|
||||||
|
if(EntityMessage.canParseMessage(byteStream,secondByte)){
|
||||||
|
rVal = EntityMessage.parsesetFacingMessage(byteStream);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TypeBytes.ENTITY_MESSAGE_TYPE_MOVEUPDATE:
|
||||||
|
if(EntityMessage.canParseMessage(byteStream,secondByte)){
|
||||||
|
rVal = EntityMessage.parsemoveUpdateMessage(byteStream);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case TypeBytes.ENTITY_MESSAGE_TYPE_MOVE:
|
case TypeBytes.ENTITY_MESSAGE_TYPE_MOVE:
|
||||||
if(EntityMessage.canParseMessage(byteStream,secondByte)){
|
if(EntityMessage.canParseMessage(byteStream,secondByte)){
|
||||||
rVal = EntityMessage.parseMoveMessage(byteStream);
|
rVal = EntityMessage.parseMoveMessage(byteStream);
|
||||||
|
|||||||
@ -48,16 +48,20 @@ Message categories
|
|||||||
*/
|
*/
|
||||||
public static final byte ENTITY_MESSAGE_TYPE_CREATE = 0;
|
public static final byte ENTITY_MESSAGE_TYPE_CREATE = 0;
|
||||||
public static final byte ENTITY_MESSAGE_TYPE_SETPOSITION = 1;
|
public static final byte ENTITY_MESSAGE_TYPE_SETPOSITION = 1;
|
||||||
public static final byte ENTITY_MESSAGE_TYPE_MOVE = 2;
|
public static final byte ENTITY_MESSAGE_TYPE_SETFACING = 2;
|
||||||
public static final byte ENTITY_MESSAGE_TYPE_DESTROY = 3;
|
public static final byte ENTITY_MESSAGE_TYPE_MOVEUPDATE = 3;
|
||||||
public static final byte ENTITY_MESSAGE_TYPE_SETBEHAVIORTREE = 4;
|
public static final byte ENTITY_MESSAGE_TYPE_MOVE = 4;
|
||||||
public static final byte ENTITY_MESSAGE_TYPE_SETPROPERTY = 5;
|
public static final byte ENTITY_MESSAGE_TYPE_DESTROY = 5;
|
||||||
public static final byte ENTITY_MESSAGE_TYPE_ATTACHENTITYTOENTITY = 6;
|
public static final byte ENTITY_MESSAGE_TYPE_SETBEHAVIORTREE = 6;
|
||||||
|
public static final byte ENTITY_MESSAGE_TYPE_SETPROPERTY = 7;
|
||||||
|
public static final byte ENTITY_MESSAGE_TYPE_ATTACHENTITYTOENTITY = 8;
|
||||||
/*
|
/*
|
||||||
Entity packet sizes
|
Entity packet sizes
|
||||||
*/
|
*/
|
||||||
public static final byte ENTITY_MESSAGE_TYPE_CREATE_SIZE = 22;
|
public static final byte ENTITY_MESSAGE_TYPE_CREATE_SIZE = 22;
|
||||||
public static final byte ENTITY_MESSAGE_TYPE_SETPOSITION_SIZE = 26;
|
public static final byte ENTITY_MESSAGE_TYPE_SETPOSITION_SIZE = 26;
|
||||||
|
public static final byte ENTITY_MESSAGE_TYPE_SETFACING_SIZE = 26;
|
||||||
|
public static final byte ENTITY_MESSAGE_TYPE_MOVEUPDATE_SIZE = 46;
|
||||||
public static final byte ENTITY_MESSAGE_TYPE_MOVE_SIZE = 26;
|
public static final byte ENTITY_MESSAGE_TYPE_MOVE_SIZE = 26;
|
||||||
public static final byte ENTITY_MESSAGE_TYPE_DESTROY_SIZE = 6;
|
public static final byte ENTITY_MESSAGE_TYPE_DESTROY_SIZE = 6;
|
||||||
public static final byte ENTITY_MESSAGE_TYPE_SETBEHAVIORTREE_SIZE = 22;
|
public static final byte ENTITY_MESSAGE_TYPE_SETBEHAVIORTREE_SIZE = 22;
|
||||||
|
|||||||
@ -49,6 +49,7 @@ public class ServerConnectionHandler implements Runnable {
|
|||||||
boolean initialized;
|
boolean initialized;
|
||||||
NetworkParser networkParser;
|
NetworkParser networkParser;
|
||||||
int playerID;
|
int playerID;
|
||||||
|
int playerCharacterID;
|
||||||
|
|
||||||
ServerProtocol serverProtocol;
|
ServerProtocol serverProtocol;
|
||||||
|
|
||||||
@ -93,6 +94,7 @@ public class ServerConnectionHandler implements Runnable {
|
|||||||
}
|
}
|
||||||
//spawn player in world
|
//spawn player in world
|
||||||
Entity newPlayerCharacter = CreatureUtils.spawnBasicCreature(0, 0.001f, 0.05f);
|
Entity newPlayerCharacter = CreatureUtils.spawnBasicCreature(0, 0.001f, 0.05f);
|
||||||
|
playerCharacterID = newPlayerCharacter.getId();
|
||||||
EntityUtils.getEntityScale(newPlayerCharacter).set(0.005f);
|
EntityUtils.getEntityScale(newPlayerCharacter).set(0.005f);
|
||||||
EntityUtils.getEntityPosition(newPlayerCharacter).set(Globals.spawnPoint.x,0,Globals.spawnPoint.z);
|
EntityUtils.getEntityPosition(newPlayerCharacter).set(Globals.spawnPoint.x,0,Globals.spawnPoint.z);
|
||||||
//spawn player sword
|
//spawn player sword
|
||||||
@ -206,6 +208,24 @@ public class ServerConnectionHandler implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addMessagetoOutgoingQueue(NetworkMessage message){
|
public void addMessagetoOutgoingQueue(NetworkMessage message){
|
||||||
networkParser.addOutgoingMessage(message);
|
switch(message.getType()){
|
||||||
|
case ENTITY_MESSAGE:
|
||||||
|
switch(((EntityMessage)message).getMessageSubtype()){
|
||||||
|
case MOVEUPDATE:
|
||||||
|
if(((EntityMessage)message).getentityID()==playerCharacterID){
|
||||||
|
//basically don't send the message if this is the player's character and it's a move update
|
||||||
|
} else {
|
||||||
|
networkParser.addOutgoingMessage(message);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
networkParser.addOutgoingMessage(message);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
networkParser.addOutgoingMessage(message);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,19 +27,26 @@ public class ServerProtocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void handleEntityMessage(EntityMessage message){
|
void handleEntityMessage(EntityMessage message){
|
||||||
|
Entity targetEntity;
|
||||||
switch(message.getMessageSubtype()){
|
switch(message.getMessageSubtype()){
|
||||||
case CREATE:
|
case CREATE:
|
||||||
break;
|
break;
|
||||||
case DESTROY:
|
case DESTROY:
|
||||||
break;
|
break;
|
||||||
case MOVE:
|
case MOVE:
|
||||||
Entity targetEntity = Globals.entityManager.getEntityFromId(message.getentityID());
|
targetEntity = Globals.entityManager.getEntityFromId(message.getentityID());
|
||||||
if(targetEntity != null){
|
if(targetEntity != null){
|
||||||
CreatureUtils.attachEntityMessageToMovementTree(targetEntity,message);
|
CreatureUtils.attachEntityMessageToMovementTree(targetEntity,message);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SETBEHAVIORTREE:
|
case SETBEHAVIORTREE:
|
||||||
break;
|
break;
|
||||||
|
case MOVEUPDATE:
|
||||||
|
targetEntity = Globals.entityManager.getEntityFromId(message.getentityID());
|
||||||
|
if(targetEntity != null){
|
||||||
|
CreatureUtils.attachEntityMessageToMovementTree(targetEntity,message);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -295,6 +295,30 @@
|
|||||||
"name" : "positionZ",
|
"name" : "positionZ",
|
||||||
"type" : "FIXED_FLOAT"
|
"type" : "FIXED_FLOAT"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name" : "rotationW",
|
||||||
|
"type" : "FIXED_FLOAT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : "rotationX",
|
||||||
|
"type" : "FIXED_FLOAT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : "rotationY",
|
||||||
|
"type" : "FIXED_FLOAT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : "rotationZ",
|
||||||
|
"type" : "FIXED_FLOAT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : "velocity",
|
||||||
|
"type" : "FIXED_FLOAT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : "moveState",
|
||||||
|
"type" : "FIXED_INT"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name" : "propertyType",
|
"name" : "propertyType",
|
||||||
"type" : "FIXED_INT"
|
"type" : "FIXED_INT"
|
||||||
@ -345,11 +369,35 @@
|
|||||||
"positionZ"
|
"positionZ"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"messageName" : "setFacing",
|
||||||
|
"data" : [
|
||||||
|
"entityID",
|
||||||
|
"time",
|
||||||
|
"rotationX",
|
||||||
|
"rotationY",
|
||||||
|
"rotationZ"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"messageName" : "moveUpdate",
|
||||||
|
"data" : [
|
||||||
|
"entityID",
|
||||||
|
"time",
|
||||||
|
"positionX",
|
||||||
|
"positionY",
|
||||||
|
"positionZ",
|
||||||
|
"rotationX",
|
||||||
|
"rotationY",
|
||||||
|
"rotationZ",
|
||||||
|
"velocity",
|
||||||
|
"moveState"
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"messageName" : "Move",
|
"messageName" : "Move",
|
||||||
"data" : [
|
"data" : [
|
||||||
"entityID",
|
"entityID",
|
||||||
|
|
||||||
"time",
|
"time",
|
||||||
"positionX",
|
"positionX",
|
||||||
"positionY",
|
"positionY",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user