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);
|
||||
//send to server
|
||||
Vector3f position = EntityUtils.getEntityPosition(Globals.playerCharacter);
|
||||
EntityMessage outgoingMessage = EntityMessage.constructMoveMessage(
|
||||
Globals.playerCharacter.getId(),
|
||||
System.currentTimeMillis(),
|
||||
position.x,
|
||||
position.y,
|
||||
position.z
|
||||
);
|
||||
Globals.clientConnection.queueOutgoingMessage(outgoingMessage);
|
||||
// Vector3f position = EntityUtils.getEntityPosition(Globals.playerCharacter);
|
||||
// EntityMessage outgoingMessage = EntityMessage.constructMoveMessage(
|
||||
// Globals.playerCharacter.getId(),
|
||||
// System.currentTimeMillis(),
|
||||
// position.x,
|
||||
// position.y,
|
||||
// position.z
|
||||
// );
|
||||
// Globals.clientConnection.queueOutgoingMessage(outgoingMessage);
|
||||
} else {
|
||||
if(controlsState.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD) == true){
|
||||
movementTree.slowdown();
|
||||
@ -248,15 +248,15 @@ public class ControlHandler {
|
||||
}
|
||||
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD, true);
|
||||
//send to server
|
||||
Vector3f position = EntityUtils.getEntityPosition(Globals.playerCharacter);
|
||||
EntityMessage outgoingMessage = EntityMessage.constructMoveMessage(
|
||||
Globals.playerCharacter.getId(),
|
||||
System.currentTimeMillis(),
|
||||
position.x,
|
||||
position.y,
|
||||
position.z
|
||||
);
|
||||
Globals.clientConnection.queueOutgoingMessage(outgoingMessage);
|
||||
// Vector3f position = EntityUtils.getEntityPosition(Globals.playerCharacter);
|
||||
// EntityMessage outgoingMessage = EntityMessage.constructMoveMessage(
|
||||
// Globals.playerCharacter.getId(),
|
||||
// System.currentTimeMillis(),
|
||||
// position.x,
|
||||
// position.y,
|
||||
// position.z
|
||||
// );
|
||||
// Globals.clientConnection.queueOutgoingMessage(outgoingMessage);
|
||||
} else {
|
||||
if(controlsState.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD) == true){
|
||||
movementTree.slowdown();
|
||||
@ -275,15 +275,15 @@ public class ControlHandler {
|
||||
}
|
||||
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT, true);
|
||||
//send to server
|
||||
Vector3f position = EntityUtils.getEntityPosition(Globals.playerCharacter);
|
||||
EntityMessage outgoingMessage = EntityMessage.constructMoveMessage(
|
||||
Globals.playerCharacter.getId(),
|
||||
System.currentTimeMillis(),
|
||||
position.x,
|
||||
position.y,
|
||||
position.z
|
||||
);
|
||||
Globals.clientConnection.queueOutgoingMessage(outgoingMessage);
|
||||
// Vector3f position = EntityUtils.getEntityPosition(Globals.playerCharacter);
|
||||
// EntityMessage outgoingMessage = EntityMessage.constructMoveMessage(
|
||||
// Globals.playerCharacter.getId(),
|
||||
// System.currentTimeMillis(),
|
||||
// position.x,
|
||||
// position.y,
|
||||
// position.z
|
||||
// );
|
||||
// Globals.clientConnection.queueOutgoingMessage(outgoingMessage);
|
||||
} else {
|
||||
if(controlsState.get(DATA_STRING_INPUT_CODE_MOVEMENT_LEFT) == true){
|
||||
movementTree.slowdown();
|
||||
@ -302,15 +302,15 @@ public class ControlHandler {
|
||||
}
|
||||
controlsState.put(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT, true);
|
||||
//send to server
|
||||
Vector3f position = EntityUtils.getEntityPosition(Globals.playerCharacter);
|
||||
EntityMessage outgoingMessage = EntityMessage.constructMoveMessage(
|
||||
Globals.playerCharacter.getId(),
|
||||
System.currentTimeMillis(),
|
||||
position.x,
|
||||
position.y,
|
||||
position.z
|
||||
);
|
||||
Globals.clientConnection.queueOutgoingMessage(outgoingMessage);
|
||||
// Vector3f position = EntityUtils.getEntityPosition(Globals.playerCharacter);
|
||||
// EntityMessage outgoingMessage = EntityMessage.constructMoveMessage(
|
||||
// Globals.playerCharacter.getId(),
|
||||
// System.currentTimeMillis(),
|
||||
// position.x,
|
||||
// position.y,
|
||||
// position.z
|
||||
// );
|
||||
// Globals.clientConnection.queueOutgoingMessage(outgoingMessage);
|
||||
} else {
|
||||
if(controlsState.get(DATA_STRING_INPUT_CODE_MOVEMENT_RIGHT) == true){
|
||||
movementTree.slowdown();
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package electrosphere.entity;
|
||||
|
||||
import electrosphere.main.Globals;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@ -51,6 +52,9 @@ public class Entity {
|
||||
public Entity(){
|
||||
data = new HashMap();
|
||||
dataKeys = new LinkedList();
|
||||
while(Globals.entityManager.getEntityFromId(entity_id_iterator)!=null){
|
||||
entity_id_iterator++;
|
||||
}
|
||||
id = entity_id_iterator;
|
||||
entity_id_iterator++;
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package electrosphere.entity;
|
||||
|
||||
import electrosphere.logger.LoggerInterface;
|
||||
import java.util.Iterator;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
@ -100,6 +101,7 @@ public class EntityManager {
|
||||
}
|
||||
|
||||
public void overrideEntityId(Entity e, int id){
|
||||
LoggerInterface.loggerGameLogic.DEBUG("Overriding entity ID " + e.getId() + " => " + id);
|
||||
if(entityIdMap.contains(e.getId())){
|
||||
entityIdMap.remove(e.getId());
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@ import electrosphere.renderer.anim.Animation;
|
||||
import electrosphere.renderer.Model;
|
||||
import java.util.LinkedList;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
/**
|
||||
@ -78,17 +79,45 @@ public class MovementTree {
|
||||
switch(message.getMessageSubtype()){
|
||||
case MOVE:
|
||||
position.set(message.getpositionX(), message.getpositionY(), message.getpositionZ());
|
||||
if(Globals.RUN_SERVER){
|
||||
Globals.server.broadcastMessage(
|
||||
EntityMessage.constructMoveMessage(
|
||||
parent.getId(),
|
||||
System.currentTimeMillis(),
|
||||
message.getpositionX(),
|
||||
message.getpositionY(),
|
||||
message.getpositionZ()
|
||||
)
|
||||
);
|
||||
// if(Globals.RUN_SERVER){
|
||||
// Globals.server.broadcastMessage(
|
||||
// EntityMessage.constructMoveMessage(
|
||||
// parent.getId(),
|
||||
// System.currentTimeMillis(),
|
||||
// message.getpositionX(),
|
||||
// message.getpositionY(),
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
@ -119,6 +148,37 @@ public class MovementTree {
|
||||
//actually update
|
||||
EntityUtils.getEntityPosition(parent).set(newPosition);
|
||||
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;
|
||||
case MOVE:
|
||||
//check if can restart animation
|
||||
@ -137,6 +197,37 @@ public class MovementTree {
|
||||
}
|
||||
EntityUtils.getEntityPosition(parent).set(newPosition);
|
||||
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;
|
||||
case SLOWDOWN:
|
||||
//run slowdown code
|
||||
@ -160,6 +251,37 @@ public class MovementTree {
|
||||
}
|
||||
EntityUtils.getEntityPosition(parent).set(newPosition);
|
||||
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;
|
||||
case IDLE:
|
||||
if(entityActor != null){
|
||||
|
||||
@ -17,7 +17,7 @@ public class LoggerInterface {
|
||||
public static Logger loggerEngine;
|
||||
|
||||
public static void initLoggers(){
|
||||
loggerNetworking = new Logger(LogLevel.INFO);
|
||||
loggerNetworking = new Logger(LogLevel.DEBUG);
|
||||
loggerFileIO = new Logger(LogLevel.ERROR);
|
||||
loggerGameLogic = new Logger(LogLevel.DEBUG);
|
||||
loggerRenderer = new Logger(LogLevel.WARNING);
|
||||
|
||||
@ -70,6 +70,7 @@ public class Globals {
|
||||
//
|
||||
public static ClientNetworking clientConnection;
|
||||
public static boolean RUN_CLIENT = true;
|
||||
public static int clientCharacterID;
|
||||
|
||||
//
|
||||
//Server manager thing
|
||||
|
||||
@ -78,6 +78,7 @@ public class ClientProtocol {
|
||||
if(target != null){
|
||||
CreatureUtils.setControllerPlayerId(target, message.getpropertyValue());
|
||||
if(message.getpropertyValue() == Main.playerId){
|
||||
Globals.clientCharacterID = message.getentityID();
|
||||
Globals.playerCharacter = target;
|
||||
}
|
||||
}
|
||||
@ -91,6 +92,9 @@ public class ClientProtocol {
|
||||
AttachUtils.attachEntityToEntityAtBone(parent, child, message.getbone());
|
||||
}
|
||||
break;
|
||||
case MOVEUPDATE:
|
||||
CreatureUtils.attachEntityMessageToMovementTree(Globals.entityManager.getEntityFromId(message.getentityID()),message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -9,6 +9,8 @@ public class EntityMessage extends NetworkMessage {
|
||||
public enum EntityMessageType {
|
||||
CREATE,
|
||||
SETPOSITION,
|
||||
SETFACING,
|
||||
MOVEUPDATE,
|
||||
MOVE,
|
||||
DESTROY,
|
||||
SETBEHAVIORTREE,
|
||||
@ -22,6 +24,12 @@ public class EntityMessage extends NetworkMessage {
|
||||
float positionX;
|
||||
float positionY;
|
||||
float positionZ;
|
||||
float rotationW;
|
||||
float rotationX;
|
||||
float rotationY;
|
||||
float rotationZ;
|
||||
float velocity;
|
||||
int moveState;
|
||||
int propertyType;
|
||||
int propertyValue;
|
||||
int treeType;
|
||||
@ -79,6 +87,54 @@ public class EntityMessage extends NetworkMessage {
|
||||
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() {
|
||||
return propertyType;
|
||||
}
|
||||
@ -154,6 +210,18 @@ public class EntityMessage extends NetworkMessage {
|
||||
} else {
|
||||
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:
|
||||
if(byteStream.size() >= TypeBytes.ENTITY_MESSAGE_TYPE_MOVE_SIZE){
|
||||
return true;
|
||||
@ -228,6 +296,60 @@ public class EntityMessage extends NetworkMessage {
|
||||
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){
|
||||
EntityMessage rVal = new EntityMessage(EntityMessageType.MOVE);
|
||||
stripPacketHeader(byteStream);
|
||||
@ -400,6 +522,70 @@ public class EntityMessage extends NetworkMessage {
|
||||
for(int i = 0; i < 4; i++){
|
||||
rawBytes[22+i] = intValues[i];
|
||||
} 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:
|
||||
rawBytes = new byte[2+4+8+4+4+4];
|
||||
//message header
|
||||
|
||||
@ -99,6 +99,16 @@ ENTITY_MESSAGE,
|
||||
rVal = EntityMessage.parseSetPositionMessage(byteStream);
|
||||
}
|
||||
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:
|
||||
if(EntityMessage.canParseMessage(byteStream,secondByte)){
|
||||
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_SETPOSITION = 1;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_MOVE = 2;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_DESTROY = 3;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_SETBEHAVIORTREE = 4;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_SETPROPERTY = 5;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_ATTACHENTITYTOENTITY = 6;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_SETFACING = 2;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_MOVEUPDATE = 3;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_MOVE = 4;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_DESTROY = 5;
|
||||
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
|
||||
*/
|
||||
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_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_DESTROY_SIZE = 6;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_SETBEHAVIORTREE_SIZE = 22;
|
||||
|
||||
@ -49,6 +49,7 @@ public class ServerConnectionHandler implements Runnable {
|
||||
boolean initialized;
|
||||
NetworkParser networkParser;
|
||||
int playerID;
|
||||
int playerCharacterID;
|
||||
|
||||
ServerProtocol serverProtocol;
|
||||
|
||||
@ -93,6 +94,7 @@ public class ServerConnectionHandler implements Runnable {
|
||||
}
|
||||
//spawn player in world
|
||||
Entity newPlayerCharacter = CreatureUtils.spawnBasicCreature(0, 0.001f, 0.05f);
|
||||
playerCharacterID = newPlayerCharacter.getId();
|
||||
EntityUtils.getEntityScale(newPlayerCharacter).set(0.005f);
|
||||
EntityUtils.getEntityPosition(newPlayerCharacter).set(Globals.spawnPoint.x,0,Globals.spawnPoint.z);
|
||||
//spawn player sword
|
||||
@ -206,6 +208,24 @@ public class ServerConnectionHandler implements Runnable {
|
||||
}
|
||||
|
||||
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){
|
||||
Entity targetEntity;
|
||||
switch(message.getMessageSubtype()){
|
||||
case CREATE:
|
||||
break;
|
||||
case DESTROY:
|
||||
break;
|
||||
case MOVE:
|
||||
Entity targetEntity = Globals.entityManager.getEntityFromId(message.getentityID());
|
||||
targetEntity = Globals.entityManager.getEntityFromId(message.getentityID());
|
||||
if(targetEntity != null){
|
||||
CreatureUtils.attachEntityMessageToMovementTree(targetEntity,message);
|
||||
}
|
||||
break;
|
||||
case SETBEHAVIORTREE:
|
||||
break;
|
||||
case MOVEUPDATE:
|
||||
targetEntity = Globals.entityManager.getEntityFromId(message.getentityID());
|
||||
if(targetEntity != null){
|
||||
CreatureUtils.attachEntityMessageToMovementTree(targetEntity,message);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -295,6 +295,30 @@
|
||||
"name" : "positionZ",
|
||||
"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",
|
||||
"type" : "FIXED_INT"
|
||||
@ -345,11 +369,35 @@
|
||||
"positionZ"
|
||||
]
|
||||
},
|
||||
{
|
||||
"messageName" : "setFacing",
|
||||
"data" : [
|
||||
"entityID",
|
||||
"time",
|
||||
"rotationX",
|
||||
"rotationY",
|
||||
"rotationZ"
|
||||
]
|
||||
},
|
||||
{
|
||||
"messageName" : "moveUpdate",
|
||||
"data" : [
|
||||
"entityID",
|
||||
"time",
|
||||
"positionX",
|
||||
"positionY",
|
||||
"positionZ",
|
||||
"rotationX",
|
||||
"rotationY",
|
||||
"rotationZ",
|
||||
"velocity",
|
||||
"moveState"
|
||||
]
|
||||
},
|
||||
{
|
||||
"messageName" : "Move",
|
||||
"data" : [
|
||||
"entityID",
|
||||
|
||||
"time",
|
||||
"positionX",
|
||||
"positionY",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user