streaming creature templates over network

This commit is contained in:
austin 2022-05-03 23:34:38 -04:00
parent db8024232f
commit 2c42b51907
16 changed files with 67 additions and 42 deletions

View File

@ -61,11 +61,11 @@
{
"name" : "realLocationX",
"type" : "FIXED_FLOAT"
"type" : "FIXED_DOUBLE"
},
{
"name" : "realLocationY",
"type" : "FIXED_FLOAT"
"type" : "FIXED_DOUBLE"
},

View File

@ -250,7 +250,9 @@ public class LoadingThread extends Thread {
//initialize the basic graphical entities of the world (skybox, camera)
initWorldBaseGraphicalEntities();
//init arena specific stuff (ie different skybox colors)
initArenaGraphicalEntities();
if(!Globals.RUN_SERVER){
initArenaGraphicalEntities();
}
//sets micro and macro sims to ready if they exist
if(!Globals.RUN_SERVER){
setSimulationsToReady();
@ -356,7 +358,7 @@ public class LoadingThread extends Thread {
static void initServerArenaWorldData(){
Globals.serverWorldData = ServerWorldData.createArenaWorld();
Globals.spawnPoint = new Vector3f(1,0.1f,1);
Globals.spawnPoint = new Vector3d(1,2.0,1);
// Globals.serverTerrainManager.getChunk(0, 0).addModification(new TerrainModification(0,0,5,5,5));
}

View File

@ -174,11 +174,11 @@ public class CollisionObjUtils {
return (CollisionObject)e.getData(EntityDataStrings.PHYSICS_COLLISION_BODY);
}
public static void positionCharacter(Entity e, Vector3f position){
public static void positionCharacter(Entity e, Vector3d position){
EntityUtils.getPosition(e).set(position);
Quaternionf rotation = EntityUtils.getRotation(e);
CollisionObject body = getCollisionBody(e);
PhysicsUtils.setRigidBodyTransform(position, rotation, body);
PhysicsUtils.setRigidBodyTransform(new Vector3f((float)position.x,(float)position.y,(float)position.z), rotation, body);
}
public static Collidable getCollidable(Entity e){

View File

@ -517,7 +517,8 @@ public class CreatureUtils {
}
}
//reposition entity
CollisionObjUtils.positionCharacter(creature, new Vector3f(Globals.spawnPoint.x,Globals.spawnPoint.y,Globals.spawnPoint.z));
// CreatureUtils.repositionCreature(creature, Globals.spawnPoint);
CollisionObjUtils.positionCharacter(creature, Globals.spawnPoint);
}

View File

@ -7,6 +7,8 @@ import electrosphere.entity.types.collision.CollisionObjUtils;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.entity.types.item.ItemUtils;
import electrosphere.game.server.ai.creature.MillAbout;
import org.joml.Vector3d;
import org.joml.Vector3f;
/**
@ -17,7 +19,7 @@ public class UnitUtils {
public static void spawnTextGoblin(float posX, float posY, float posZ){
Entity goblin = CreatureUtils.spawnBasicCreature("Goblin",null);
CollisionObjUtils.positionCharacter(goblin, new Vector3f(posX, posY, posZ));
CollisionObjUtils.positionCharacter(goblin, new Vector3d(posX, posY, posZ));
EntityUtils.getScale(goblin).set(0.005f);
//give evil goblin sword
Entity goblinSword = ItemUtils.spawnBasicItem("Katana");

View File

@ -70,6 +70,7 @@ import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.joml.Matrix4f;
import org.joml.Vector3d;
import org.joml.Vector3f;
import electrosphere.util.ModelLoader;
import electrosphere.util.Utilities;
@ -249,7 +250,7 @@ public class Globals {
//terrain manager
// public static boolean LOAD_TERRAIN = true;
public static ServerTerrainManager serverTerrainManager;
public static Vector3f spawnPoint = new Vector3f(0,0,0);
public static Vector3d spawnPoint = new Vector3d(0,0,0);
//manages all models loaded into memory
public static AssetManager assetManager;

View File

@ -104,8 +104,6 @@ public class MenuGeneratorsMultiplayer {
ActorPanel actorPanel = new ActorPanel(1200, 100, 500, 500, characterActor);
actorPanel.setAnimation(Animation.ANIMATION_IDLE_1);
actorPanel.setPosition(new Vector3f(0,-1,-0.5f));
RenderingEngine.setFOV(50);
RenderingEngine.setAspectRatio(1.0f);
// actorPanel.setRotation(new Quaternionf().rotateLocalY(0));
actorPanel.setScale(new Vector3f(0.01f,0.01f,0.01f));

View File

@ -11,8 +11,8 @@ public class CharacterProtocol {
switch(message.getMessageSubtype()){
case RESPONSECREATECHARACTERSUCCESS:
//trigger request to spawn character
Globals.clientConnection.queueOutgoingMessage(TerrainMessage.constructRequestMetadataMessage());
Globals.clientConnection.queueOutgoingMessage(CharacterMessage.constructRequestSpawnCharacterMessage());
Globals.clientConnection.queueOutgoingMessage(TerrainMessage.constructRequestMetadataMessage());
LoadingThread clientThread = new LoadingThread(LoadingThread.LOAD_CLIENT_WORLD);
Globals.loadingThreadsList.add(clientThread);
clientThread.start();

View File

@ -36,7 +36,7 @@ public class EntityProtocol {
}
break;
case SPAWNCREATURE:
LoggerInterface.loggerNetworking.DEBUG("Spawn ID " + message.getentityID() + " of type " + message.getentityCategory() + " subtype " + message.getentitySubtype());
LoggerInterface.loggerNetworking.DEBUG("Spawn Creature " + message.getentityID() + " at " + message.getpositionX() + " " + message.getpositionY() + " " + message.getpositionZ());
CreatureTemplate template = Utilities.deserialize(message.getcreatureTemplate(), CreatureTemplate.class);
newlySpawnedEntity = CreatureUtils.spawnBasicCreature(template.getCreatureType(),template);
EntityUtils.getScale(newlySpawnedEntity).set(0.005f);

View File

@ -1,5 +1,7 @@
package electrosphere.net.client.protocol;
import javax.vecmath.Vector3d;
import org.joml.Vector3f;
import electrosphere.game.client.world.ClientWorldData;
@ -26,7 +28,7 @@ public class TerrainProtocol {
Globals.clientTerrainManager.attachTerrainMessage(message);
break;
case SPAWNPOSITION:
Globals.spawnPoint.set(new Vector3f(message.getrealLocationX(),0.25f,message.getrealLocationY()));
Globals.spawnPoint.set(message.getrealLocationX(),0.25,message.getrealLocationY());
break;
case CHUNKLOADSTART:
Globals.clientTerrainManager.attachTerrainMessage(message);

View File

@ -30,8 +30,8 @@ public class TerrainMessage extends NetworkMessage {
float value;
int locationX;
int locationY;
float realLocationX;
float realLocationY;
double realLocationX;
double realLocationY;
float macroValue00;
float macroValue01;
float macroValue02;
@ -188,19 +188,19 @@ public class TerrainMessage extends NetworkMessage {
this.locationY = locationY;
}
public float getrealLocationX() {
public double getrealLocationX() {
return realLocationX;
}
public void setrealLocationX(float realLocationX) {
public void setrealLocationX(double realLocationX) {
this.realLocationX = realLocationX;
}
public float getrealLocationY() {
public double getrealLocationY() {
return realLocationY;
}
public void setrealLocationY(float realLocationY) {
public void setrealLocationY(double realLocationY) {
this.realLocationY = realLocationY;
}
@ -892,12 +892,12 @@ public class TerrainMessage extends NetworkMessage {
public static TerrainMessage parseSpawnPositionMessage(List<Byte> byteStream){
TerrainMessage rVal = new TerrainMessage(TerrainMessageType.SPAWNPOSITION);
stripPacketHeader(byteStream);
rVal.setrealLocationX(ByteStreamUtils.popFloatFromByteQueue(byteStream));
rVal.setrealLocationY(ByteStreamUtils.popFloatFromByteQueue(byteStream));
rVal.setrealLocationX(ByteStreamUtils.popDoubleFromByteQueue(byteStream));
rVal.setrealLocationY(ByteStreamUtils.popDoubleFromByteQueue(byteStream));
return rVal;
}
public static TerrainMessage constructSpawnPositionMessage(float realLocationX,float realLocationY){
public static TerrainMessage constructSpawnPositionMessage(double realLocationX,double realLocationY){
TerrainMessage rVal = new TerrainMessage(TerrainMessageType.SPAWNPOSITION);
rVal.setrealLocationX(realLocationX);
rVal.setrealLocationY(realLocationY);
@ -1216,18 +1216,20 @@ public class TerrainMessage extends NetworkMessage {
}
break;
case SPAWNPOSITION:
rawBytes = new byte[2+4+4];
rawBytes = new byte[2+8+8];
//message header
rawBytes[0] = TypeBytes.MESSAGE_TYPE_TERRAIN;
//entity messaage header
rawBytes[1] = TypeBytes.TERRAIN_MESSAGE_TYPE_SPAWNPOSITION;
intValues = ByteStreamUtils.serializeFloatToBytes(realLocationX);
for(int i = 0; i < 4; i++){
intValues = ByteStreamUtils.serializeDoubleToBytes(realLocationX);
for(int i = 0; i < 8; i++){
rawBytes[2+i] = intValues[i];
} intValues = ByteStreamUtils.serializeFloatToBytes(realLocationY);
for(int i = 0; i < 4; i++){
rawBytes[6+i] = intValues[i];
} break;
}
intValues = ByteStreamUtils.serializeDoubleToBytes(realLocationY);
for(int i = 0; i < 8; i++){
rawBytes[10+i] = intValues[i];
}
break;
}
serialized = true;
}

View File

@ -84,7 +84,7 @@ Message categories
public static final byte TERRAIN_MESSAGE_TYPE_CHUNKLOADSTART_SIZE = 14;
public static final short TERRAIN_MESSAGE_TYPE_MACROVALUE_SIZE = 310;
public static final byte TERRAIN_MESSAGE_TYPE_HEIGHTMAPMODIFICATION_SIZE = 22;
public static final byte TERRAIN_MESSAGE_TYPE_SPAWNPOSITION_SIZE = 10;
public static final byte TERRAIN_MESSAGE_TYPE_SPAWNPOSITION_SIZE = 18;
/*
Server subcategories
*/

View File

@ -167,6 +167,8 @@ public class ServerConnectionHandler implements Runnable {
networkParser.addOutgoingMessage(message);
}
break;
case SPAWNCREATURE:
break;
default:
networkParser.addOutgoingMessage(message);
break;

View File

@ -17,10 +17,6 @@ public class EntityProtocol {
protected static void handleEntityMessage(ServerConnectionHandler connectionHandler, EntityMessage message){
Entity targetEntity;
switch(message.getMessageSubtype()){
case CREATE:
break;
case DESTROY:
break;
case MOVE:
targetEntity = Globals.entityManager.getEntityFromId(message.getentityID());
if(targetEntity != null){
@ -42,6 +38,10 @@ public class EntityProtocol {
}
break;
//ignore stack
case KILL:
case SPAWNCREATURE:
case DESTROY:
case CREATE:
case ATTACHENTITYTOENTITY:
case SETFACING:
case SETPOSITION:

View File

@ -198,6 +198,10 @@ public class RenderingEngine {
ShaderProgram activeProgram;
static int outputFramebuffer = 0;
//used in calculating projection matrix
static float aspectRatio = 1.0f;
static float verticalFOV = 90.0f;
public void createOpenglContext(){
@ -388,10 +392,11 @@ public class RenderingEngine {
//
Globals.projectionMatrix = new Matrix4f();
Globals.viewMatrix = new Matrix4f();
float verticalFOV = (float)(Globals.verticalFOV * Math.PI /180.0f);
float aspectRatio = (float)Globals.WINDOW_WIDTH / (float)Globals.WINDOW_HEIGHT;
verticalFOV = (float)(Globals.verticalFOV * Math.PI /180.0f);
//set local aspect ratio and global aspect ratio at the same time
aspectRatio = Globals.aspectRatio = Globals.WINDOW_WIDTH / (float)Globals.WINDOW_HEIGHT;
float nearClip = 0.001f;
Globals.projectionMatrix.setPerspective(verticalFOV, aspectRatio, nearClip, Globals.userSettings.getGraphicsViewDistance());
Globals.projectionMatrix.setPerspective(verticalFOV, Globals.aspectRatio, nearClip, Globals.userSettings.getGraphicsViewDistance());
Globals.viewMatrix.translation(new Vector3f(0.0f,0.0f,-3.0f));
}
@ -1314,19 +1319,19 @@ public class RenderingEngine {
}
public static void setFOV(float verticalFOV){
Globals.verticalFOV = verticalFOV;
RenderingEngine.verticalFOV = verticalFOV;
calculateProjectionMatrix();
}
public static void setAspectRatio(float aspectRatio){
Globals.aspectRatio = aspectRatio;
RenderingEngine.aspectRatio = aspectRatio;
calculateProjectionMatrix();
}
static void calculateProjectionMatrix(){
float radVerticalFOV = (float)(Globals.verticalFOV * Math.PI /180.0f);
float radVerticalFOV = (float)(RenderingEngine.verticalFOV * Math.PI /180.0f);
float nearClip = 0.001f;
Globals.projectionMatrix.setPerspective(radVerticalFOV, Globals.aspectRatio, nearClip, Globals.userSettings.getGraphicsViewDistance());
Globals.projectionMatrix.setPerspective(radVerticalFOV, RenderingEngine.aspectRatio, nearClip, Globals.userSettings.getGraphicsViewDistance());
}
}

View File

@ -22,6 +22,7 @@ import electrosphere.main.Globals;
import electrosphere.main.Main;
import electrosphere.renderer.Material;
import electrosphere.renderer.Model;
import electrosphere.renderer.RenderingEngine;
import electrosphere.renderer.actor.Actor;
import electrosphere.renderer.framebuffer.Framebuffer;
import electrosphere.renderer.framebuffer.FramebufferUtils;
@ -43,6 +44,8 @@ public class ActorPanel implements DrawableElement, DraggableElement {
Vector3f actorPosition = new Vector3f(0,0,0);
Quaternionf actorRotation = new Quaternionf();
Vector3f actorScale = new Vector3f(1,1,1);
float FOV = 50.0f;
float aspectRatio = 1.9f;
Vector3f texPosition = new Vector3f(0,0,0);
@ -60,6 +63,7 @@ public class ActorPanel implements DrawableElement, DraggableElement {
this.positionY = y;
this.width = width;
this.height = height;
this.aspectRatio = (float)width / (float)height;
recalculateModelMatrix();
}
@ -70,6 +74,9 @@ public class ActorPanel implements DrawableElement, DraggableElement {
elementBuffer.bind();
// Globals.renderingEngine.setViewportSize(width, height);
RenderingEngine.setFOV(FOV);
RenderingEngine.setAspectRatio(aspectRatio);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
@ -89,6 +96,9 @@ public class ActorPanel implements DrawableElement, DraggableElement {
actor.applyModelMatrix(modelMatrix);
actor.draw(true);
RenderingEngine.setFOV(Globals.verticalFOV);
RenderingEngine.setAspectRatio(Globals.aspectRatio);
glDisable(GL_DEPTH_TEST);
//this call binds the screen as the "texture" we're rendering to