networking creature templates
This commit is contained in:
parent
ab41020e1c
commit
db8024232f
@ -69,6 +69,39 @@
|
||||
"minValue" : -0.2,
|
||||
"maxValue" : 0.2
|
||||
},
|
||||
{
|
||||
"attributeId" : "TorsoWidth",
|
||||
"type" : "bone",
|
||||
"subtype" : "scalex",
|
||||
"primaryBone" : "UpperTorso",
|
||||
"minValue" : 0.8,
|
||||
"maxValue" : 1.2
|
||||
},
|
||||
{
|
||||
"attributeId" : "ShoulderSize",
|
||||
"type" : "bone",
|
||||
"subtype" : "scale",
|
||||
"primaryBone" : "Shoulder.R",
|
||||
"mirrorBone" : "Shoulder.L",
|
||||
"minValue" : 0.8,
|
||||
"maxValue" : 1.2
|
||||
},
|
||||
{
|
||||
"attributeId" : "JawWidth",
|
||||
"type" : "bone",
|
||||
"subtype" : "scalex",
|
||||
"primaryBone" : "Jaw",
|
||||
"minValue" : 0.8,
|
||||
"maxValue" : 1.2
|
||||
},
|
||||
{
|
||||
"attributeId" : "JawExtrude",
|
||||
"type" : "bone",
|
||||
"subtype" : "posz",
|
||||
"primaryBone" : "Jaw",
|
||||
"minValue" : -0.1,
|
||||
"maxValue" : 0.1
|
||||
},
|
||||
{
|
||||
"attributeId" : "HeadWidth",
|
||||
"type" : "bone",
|
||||
|
||||
File diff suppressed because one or more lines are too long
51
net/character.json
Normal file
51
net/character.json
Normal file
@ -0,0 +1,51 @@
|
||||
{
|
||||
"outputPath" : "./src/main/java/electrosphere/net/parser/",
|
||||
"packageName" : "electrosphere.net.parser",
|
||||
"categories":[
|
||||
{
|
||||
"categoryName" : "Character",
|
||||
"data" : [
|
||||
{
|
||||
"name" : "data",
|
||||
"type" : "VAR_STRING"
|
||||
}
|
||||
],
|
||||
"messageTypes" : [
|
||||
{
|
||||
"messageName" : "RequestCharacterList",
|
||||
"data" : []
|
||||
},
|
||||
{
|
||||
"messageName" : "ResponseCharacterList",
|
||||
"data" : [
|
||||
"data"
|
||||
]
|
||||
},
|
||||
{
|
||||
"messageName" : "RequestCreateCharacter",
|
||||
"data" : [
|
||||
"data"
|
||||
]
|
||||
},
|
||||
{
|
||||
"messageName" : "ResponseCreateCharacterSuccess",
|
||||
"data" : []
|
||||
},
|
||||
{
|
||||
"messageName" : "ResponseCreateCharacterFailure",
|
||||
"data" : []
|
||||
},
|
||||
{
|
||||
"messageName" : "RequestSpawnCharacter",
|
||||
"data" : []
|
||||
},
|
||||
{
|
||||
"messageName" : "ResponseSpawnCharacter",
|
||||
"data" : [
|
||||
"data"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -17,6 +17,10 @@
|
||||
"name" : "entityID",
|
||||
"type" : "FIXED_INT"
|
||||
},
|
||||
{
|
||||
"name" : "creatureTemplate",
|
||||
"type" : "VAR_STRING"
|
||||
},
|
||||
{
|
||||
"name" : "positionX",
|
||||
"type" : "FIXED_DOUBLE"
|
||||
@ -94,6 +98,16 @@
|
||||
"positionZ"
|
||||
]
|
||||
},
|
||||
{
|
||||
"messageName" : "SpawnCreature",
|
||||
"data" : [
|
||||
"entityID",
|
||||
"creatureTemplate",
|
||||
"positionX",
|
||||
"positionY",
|
||||
"positionZ"
|
||||
]
|
||||
},
|
||||
{
|
||||
"messageName" : "SetPosition",
|
||||
"data" : [
|
||||
|
||||
@ -2,47 +2,6 @@
|
||||
"outputPath" : "./src/main/java/electrosphere/net/parser/",
|
||||
"packageName" : "electrosphere.net.parser",
|
||||
"categories":[
|
||||
{
|
||||
"categoryName" : "Character",
|
||||
"data" : [
|
||||
{
|
||||
"name" : "data",
|
||||
"type" : "VAR_STRING"
|
||||
}
|
||||
],
|
||||
"messageTypes" : [
|
||||
{
|
||||
"messageName" : "RequestCharacterList",
|
||||
"data" : []
|
||||
},
|
||||
{
|
||||
"messageName" : "ResponseCharacterList",
|
||||
"data" : [
|
||||
"data"
|
||||
]
|
||||
},
|
||||
{
|
||||
"messageName" : "RequestCreateCharacter",
|
||||
"data" : []
|
||||
},
|
||||
{
|
||||
"messageName" : "ResponseCreateCharacter",
|
||||
"data" : [
|
||||
"data"
|
||||
]
|
||||
},
|
||||
{
|
||||
"messageName" : "RequestSpawnCharacter",
|
||||
"data" : []
|
||||
},
|
||||
{
|
||||
"messageName" : "ResponseSpawnCharacter",
|
||||
"data" : [
|
||||
"data"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"categoryName" : "Player",
|
||||
"data" : [
|
||||
|
||||
@ -45,6 +45,7 @@ public class EntityDataStrings {
|
||||
public static final String ROTATOR_TREE = "rotatorTree";
|
||||
public static final String JUMP_TREE = "jumpTree";
|
||||
public static final String FALL_TREE = "fallTree";
|
||||
public static final String CREATURE_TEMPLATE = "creatureTemplate";
|
||||
|
||||
|
||||
/*
|
||||
|
||||
@ -0,0 +1,64 @@
|
||||
package electrosphere.entity.types.creature;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class CreatureTemplate {
|
||||
|
||||
String creatureType;
|
||||
|
||||
Map<String,CreatureTemplateAttributeValue> attributeMap = new HashMap<String,CreatureTemplateAttributeValue>();
|
||||
|
||||
public CreatureTemplate(String creatureType){
|
||||
this.creatureType = creatureType;
|
||||
}
|
||||
|
||||
public void putValue(String attributeName, float value){
|
||||
attributeMap.put(attributeName,new CreatureTemplateAttributeValue(value));
|
||||
}
|
||||
|
||||
public void putValue(String attributeName, String value){
|
||||
attributeMap.put(attributeName,new CreatureTemplateAttributeValue(value));
|
||||
}
|
||||
|
||||
public CreatureTemplateAttributeValue getValue(String attributeName){
|
||||
return attributeMap.get(attributeName);
|
||||
}
|
||||
|
||||
public String getCreatureType(){
|
||||
return creatureType;
|
||||
}
|
||||
|
||||
|
||||
public class CreatureTemplateAttributeValue {
|
||||
|
||||
String variantId;
|
||||
float value;
|
||||
|
||||
public CreatureTemplateAttributeValue(float value){
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public CreatureTemplateAttributeValue(String variantId){
|
||||
this.variantId = variantId;
|
||||
}
|
||||
|
||||
public float getValue(){
|
||||
return value;
|
||||
}
|
||||
|
||||
public String getVariantId(){
|
||||
return variantId;
|
||||
}
|
||||
|
||||
public void setValue(float value){
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public void setVariantId(String variantId){
|
||||
this.variantId = variantId;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -54,6 +54,7 @@ import electrosphere.renderer.actor.ActorStaticMorph;
|
||||
import electrosphere.renderer.actor.ActorUtils;
|
||||
import electrosphere.renderer.light.PointLight;
|
||||
import electrosphere.util.ModelLoader;
|
||||
import electrosphere.util.Utilities;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@ -88,7 +89,7 @@ public class CreatureUtils {
|
||||
// return rVal;
|
||||
// }
|
||||
|
||||
public static Entity spawnBasicCreature(String type){
|
||||
public static Entity spawnBasicCreature(String type, CreatureTemplate template){
|
||||
CreatureType rawType = Globals.gameConfigCurrent.getCreatureTypeLoader().getCreature(type);
|
||||
Entity rVal = EntityUtils.spawnDrawableEntity(rawType.getModelPath());
|
||||
Actor creatureActor = EntityUtils.getActor(rVal);
|
||||
@ -195,7 +196,7 @@ public class CreatureUtils {
|
||||
}
|
||||
//round out end of move system
|
||||
rVal.putData(EntityDataStrings.DATA_STRING_MOVEMENT_BT, moveTree);
|
||||
rVal.putData(EntityDataStrings.DATA_STRING_FACING_VECTOR, new Vector3f(0,0,0));
|
||||
CreatureUtils.setFacingVector(rVal, new Vector3d(0,0,0));
|
||||
rVal.putData(EntityDataStrings.DATA_STRING_MAX_NATURAL_VELOCITY, groundMovementSystem.getMaxVelocity());
|
||||
rVal.putData(EntityDataStrings.DATA_STRING_ACCELERATION, groundMovementSystem.getAcceleration());
|
||||
rVal.putData(EntityDataStrings.DATA_STRING_VELOCITY, 0f);
|
||||
@ -291,10 +292,28 @@ public class CreatureUtils {
|
||||
//variants
|
||||
if(rawType.getVisualAttributes() != null){
|
||||
ActorStaticMorph staticMorph = null;
|
||||
CreatureTemplate storedTemplate = new CreatureTemplate(rawType.getCreatureId());
|
||||
for(VisualAttribute attributeType : rawType.getVisualAttributes()){
|
||||
if(attributeType.getType().equals("remesh")){
|
||||
if(attributeType.getVariants() != null && attributeType.getVariants().size() > 0){
|
||||
AttributeVariant variant = attributeType.getVariants().get(0);
|
||||
//if the template isn't null, try to find the variant from the template in the variant list
|
||||
//if the variant is found, set the variable "variant" to the searched for variant
|
||||
if(template != null && template.getValue(attributeType.getAttributeId()) != null){
|
||||
String variantId = template.getValue(attributeType.getAttributeId()).getVariantId();
|
||||
for(AttributeVariant searchVariant : attributeType.getVariants()){
|
||||
if(searchVariant.getId().equals(variantId)){
|
||||
variant = searchVariant;
|
||||
//if we find the variant, store in on-creature template as well
|
||||
storedTemplate.putValue(attributeType.getAttributeId(), variantId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//make sure stored template contains creature data
|
||||
if(storedTemplate.getValue(attributeType.getAttributeId())==null){
|
||||
storedTemplate.putValue(attributeType.getAttributeId(), attributeType.getVariants().get(0).getId());
|
||||
}
|
||||
// attributeType.getAttributeId();
|
||||
// variant.getId();
|
||||
rVal.putData(EntityDataStrings.CREATURE_ATTRIBUTE_VARIANT + attributeType.getAttributeId(), variant.getId());
|
||||
@ -311,12 +330,31 @@ public class CreatureUtils {
|
||||
}
|
||||
if(attributeType.getPrimaryBone() != null && staticMorph.getBoneTransforms(attributeType.getPrimaryBone()) == null){
|
||||
staticMorph.initBoneTransforms(attributeType.getPrimaryBone());
|
||||
//if the template isn't null, set the value of the morph
|
||||
if(template != null && template.getValue(attributeType.getAttributeId()) != null){
|
||||
float templateValue = template.getValue(attributeType.getAttributeId()).getValue();
|
||||
staticMorph.updateValue(attributeType.getSubtype(), attributeType.getPrimaryBone(), templateValue);
|
||||
}
|
||||
}
|
||||
if(attributeType.getMirrorBone() != null && staticMorph.getBoneTransforms(attributeType.getMirrorBone()) == null){
|
||||
staticMorph.initBoneTransforms(attributeType.getMirrorBone());
|
||||
//if the template isn't null, set the value of the morph
|
||||
if(template != null && template.getValue(attributeType.getAttributeId()) != null){
|
||||
float templateValue = template.getValue(attributeType.getAttributeId()).getValue();
|
||||
staticMorph.updateValue(attributeType.getSubtype(), attributeType.getMirrorBone(), templateValue);
|
||||
}
|
||||
}
|
||||
//make sure stored template contains creature data
|
||||
if(template != null && template.getValue(attributeType.getAttributeId()) != null) {
|
||||
storedTemplate.putValue(attributeType.getAttributeId(), template.getValue(attributeType.getAttributeId()).getValue());
|
||||
} else {
|
||||
float midpoint = (attributeType.getMaxValue() - attributeType.getMinValue())/2.0f + attributeType.getMinValue();
|
||||
storedTemplate.putValue(attributeType.getAttributeId(), midpoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
//store template on creature
|
||||
CreatureUtils.setCreatureTemplate(rVal, storedTemplate);
|
||||
}
|
||||
//rotator system
|
||||
if(rawType.getRotatorSystem() != null){
|
||||
@ -345,7 +383,7 @@ public class CreatureUtils {
|
||||
Globals.entityManager.registerCreatureEntity(rVal);
|
||||
rVal.putData(EntityDataStrings.DATA_STRING_CREATURE_IS_CREATURE, true);
|
||||
rVal.putData(EntityDataStrings.DATA_STRING_CREATURE_TYPE, type);
|
||||
rVal.putData(EntityDataStrings.DATA_STRING_FACING_VECTOR, new Vector3d(0,0,1));
|
||||
CreatureUtils.setFacingVector(rVal, new Vector3d(0,0,1));
|
||||
rVal.putData(EntityDataStrings.DRAW_CAST_SHADOW, true);
|
||||
return rVal;
|
||||
}
|
||||
@ -354,7 +392,13 @@ public class CreatureUtils {
|
||||
int id = creature.getId();
|
||||
String type = CreatureUtils.getType(creature);
|
||||
Vector3d position = EntityUtils.getPosition(creature);
|
||||
NetworkMessage message = EntityMessage.constructCreateMessage(id, EntityDataStrings.ENTITY_CATEGORY_CREATURE, type, (float)position.x, (float)position.y, (float)position.z);
|
||||
NetworkMessage message = EntityMessage.constructSpawnCreatureMessage(
|
||||
id,
|
||||
Utilities.stringify(CreatureUtils.getCreatureTemplate(creature)),
|
||||
(float)position.x,
|
||||
(float)position.y,
|
||||
(float)position.z);
|
||||
// NetworkMessage message = EntityMessage.constructCreateMessage(id, EntityDataStrings.ENTITY_CATEGORY_CREATURE, type, (float)position.x, (float)position.y, (float)position.z);
|
||||
player.addMessage(message);
|
||||
if(CreatureUtils.hasControllerPlayerId(creature)){
|
||||
LoggerInterface.loggerNetworking.INFO("Sending controller packets");
|
||||
@ -442,6 +486,14 @@ public class CreatureUtils {
|
||||
return (SprintTree)e.getData(EntityDataStrings.SPRINT_TREE);
|
||||
}
|
||||
|
||||
public static void setCreatureTemplate(Entity e, CreatureTemplate template){
|
||||
e.putData(EntityDataStrings.CREATURE_TEMPLATE, template);
|
||||
}
|
||||
|
||||
public static CreatureTemplate getCreatureTemplate(Entity e){
|
||||
return (CreatureTemplate)e.getData(EntityDataStrings.CREATURE_TEMPLATE);
|
||||
}
|
||||
|
||||
|
||||
public static void repositionCreature(Entity creature, Vector3d position){
|
||||
//if server, get current server data cell
|
||||
|
||||
@ -11,6 +11,7 @@ public class VisualAttribute {
|
||||
String type; //remesh or bone
|
||||
String subtype; //if bone: yaw,pitch,roll,scalex,scaley,scalez,offx,offy,offz,offl
|
||||
//offl = length offset, scaling along the offset from the previous bone (as if to elongate a limb)
|
||||
//likely not updated, check out ActorStaticMorph for more details on up to date docs if out of date
|
||||
List<AttributeVariant> variants;
|
||||
float minValue;
|
||||
float maxValue;
|
||||
|
||||
@ -16,7 +16,7 @@ import org.joml.Vector3f;
|
||||
public class UnitUtils {
|
||||
|
||||
public static void spawnTextGoblin(float posX, float posY, float posZ){
|
||||
Entity goblin = CreatureUtils.spawnBasicCreature("Goblin");
|
||||
Entity goblin = CreatureUtils.spawnBasicCreature("Goblin",null);
|
||||
CollisionObjUtils.positionCharacter(goblin, new Vector3f(posX, posY, posZ));
|
||||
EntityUtils.getScale(goblin).set(0.005f);
|
||||
//give evil goblin sword
|
||||
|
||||
@ -196,6 +196,7 @@ public class Globals {
|
||||
public static int WINDOW_TITLE_BAR_HEIGHT = 0;
|
||||
|
||||
public static float verticalFOV = 90;
|
||||
public static float aspectRatio = 2.0f;
|
||||
|
||||
//matrices for drawing models
|
||||
public static Matrix4f viewMatrix = new Matrix4f();
|
||||
|
||||
@ -7,11 +7,13 @@ import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import electrosphere.entity.types.camera.CameraEntityUtils;
|
||||
import electrosphere.entity.types.creature.CreatureTemplate;
|
||||
import electrosphere.game.data.creature.type.CreatureType;
|
||||
import electrosphere.game.data.creature.type.visualattribute.AttributeVariant;
|
||||
import electrosphere.game.data.creature.type.visualattribute.VisualAttribute;
|
||||
import electrosphere.main.Globals;
|
||||
import electrosphere.renderer.Camera;
|
||||
import electrosphere.net.parser.net.message.CharacterMessage;
|
||||
import electrosphere.renderer.RenderingEngine;
|
||||
import electrosphere.renderer.actor.Actor;
|
||||
import electrosphere.renderer.actor.ActorStaticMorph;
|
||||
import electrosphere.renderer.actor.ActorUtils;
|
||||
@ -30,6 +32,7 @@ import electrosphere.renderer.ui.elements.StringCarousel;
|
||||
import electrosphere.renderer.ui.events.ClickEvent;
|
||||
import electrosphere.renderer.ui.events.ValueChangeEvent;
|
||||
import electrosphere.renderer.ui.form.FormElement;
|
||||
import electrosphere.util.Utilities;
|
||||
|
||||
public class MenuGeneratorsMultiplayer {
|
||||
|
||||
@ -91,19 +94,27 @@ public class MenuGeneratorsMultiplayer {
|
||||
CreatureType selectedRaceType = Globals.gameConfigCurrent.getCreatureTypeLoader().getCreature(race);
|
||||
|
||||
//spawn camera so renderer doesn't crash (once render pipeline is modularized this shouldn't be necessary)
|
||||
Globals.playerCamera = CameraEntityUtils.spawnBasicCameraEntity(new Vector3f(0,0,0), new Vector3f(-1,0.2f,0).normalize());
|
||||
Globals.playerCamera = CameraEntityUtils.spawnBasicCameraEntity(new Vector3f(0,0,0), new Vector3f(0,0.3f,1).normalize());
|
||||
Globals.viewMatrix = CameraEntityUtils.getCameraViewMatrix(Globals.playerCamera);
|
||||
// CameraEntityUtils.setCameraEye(Globals.playerCamera, new Vector3f(-1,3f,0).normalize());
|
||||
// CameraEntityUtils.setCameraCenter(Globals.playerCamera, new Vector3f(0,0,0));
|
||||
|
||||
//create actor panel
|
||||
Actor characterActor = ActorUtils.createActorFromModelPath(selectedRaceType.getModelPath());
|
||||
ActorPanel actorPanel = new ActorPanel(1200, 100, 500, 500, characterActor);
|
||||
actorPanel.setAnimation(Animation.ANIMATION_IDLE_1);
|
||||
actorPanel.setPosition(new Vector3f(-5,-2,0));
|
||||
actorPanel.setRotation(new Quaternionf().rotateLocalY((float)(Math.PI/4.0)));
|
||||
actorPanel.setScale(new Vector3f(0.03f,0.03f,0.03f));
|
||||
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));
|
||||
|
||||
//have to build static morph while looping through attributes
|
||||
ActorStaticMorph staticMorph = new ActorStaticMorph();
|
||||
|
||||
//create creature template
|
||||
CreatureTemplate template = new CreatureTemplate(race);
|
||||
|
||||
List<Element> controlsToAdd = new LinkedList<Element>();
|
||||
//create edit controls here
|
||||
for(VisualAttribute attribute : selectedRaceType.getVisualAttributes()){
|
||||
@ -116,9 +127,10 @@ public class MenuGeneratorsMultiplayer {
|
||||
Slider boneSlider = new Slider(horizontalPosition, verticalPosition + 10, 500, 20, new Vector3f(0.1f,0.1f,0.1f), new Vector3f(1,1,1));
|
||||
float min = attribute.getMinValue();
|
||||
float max = attribute.getMaxValue();
|
||||
float defaultValue = min + (max - min)/2.0f;
|
||||
boneSlider.setMinimum(min);
|
||||
boneSlider.setMaximum(max);
|
||||
boneSlider.setValue(min + (max - min)/2.0f);
|
||||
boneSlider.setValue(defaultValue);
|
||||
controlsToAdd.add(boneSlider);
|
||||
//actually add attributes to static morph
|
||||
if(attribute.getPrimaryBone() != null && staticMorph.getBoneTransforms(attribute.getPrimaryBone()) == null){
|
||||
@ -127,14 +139,17 @@ public class MenuGeneratorsMultiplayer {
|
||||
if(attribute.getMirrorBone() != null && staticMorph.getBoneTransforms(attribute.getMirrorBone()) == null){
|
||||
staticMorph.initBoneTransforms(attribute.getMirrorBone());
|
||||
}
|
||||
//add attribute to creature template
|
||||
template.putValue(attribute.getAttributeId(), defaultValue);
|
||||
//set callback for when we change the slider value to update the static morph
|
||||
boneSlider.setOnValueChangeCallback(new ValueChangeEventCallback() {public void execute(ValueChangeEvent event) {
|
||||
if(characterActor.getStaticMorph() != null){
|
||||
ActorStaticMorph staticMorph = characterActor.getStaticMorph();
|
||||
staticMorph.updateValue(attribute.getSubtype(), attribute.getPrimaryBone(), event.getAsFloat());
|
||||
if(attribute.getMirrorBone() != null){
|
||||
staticMorph.updateValue(attribute.getSubtype(), attribute.getMirrorBone(), -event.getAsFloat());
|
||||
staticMorph.updateValue(attribute.getSubtype(), attribute.getMirrorBone(), event.getAsFloat());
|
||||
}
|
||||
template.getValue(attribute.getAttributeId()).setValue(event.getAsFloat());
|
||||
}
|
||||
}});
|
||||
} else if(attribute.getType().equals(VisualAttribute.TYPE_REMESH)){
|
||||
@ -142,11 +157,24 @@ public class MenuGeneratorsMultiplayer {
|
||||
Label sliderName = new Label(20, verticalPosition, 0.6f);
|
||||
sliderName.setText(attribute.getAttributeId());
|
||||
controlsToAdd.add(sliderName);
|
||||
//for adding the value to the creature template
|
||||
boolean hasAddedValue = false;
|
||||
//add a carousel
|
||||
StringCarousel variantCarousel = new StringCarousel(horizontalPosition, verticalPosition, 1.0f);
|
||||
for(AttributeVariant variant : attribute.getVariants()){
|
||||
variantCarousel.addOption(variant.getId());
|
||||
//if we haven't already added a value, add a value to the creature template
|
||||
if(!hasAddedValue){
|
||||
hasAddedValue = true;
|
||||
//add attribute to template
|
||||
template.putValue(attribute.getAttributeId(), variant.getId());
|
||||
}
|
||||
}
|
||||
//callback for updating remesh
|
||||
variantCarousel.setOnValueChangeCallback(new ValueChangeEventCallback(){public void execute(ValueChangeEvent event) {
|
||||
//TODO: implement updating visuals
|
||||
template.getValue(attribute.getAttributeId()).setVariantId(event.getAsString());
|
||||
}});
|
||||
controlsToAdd.add(variantCarousel);
|
||||
}
|
||||
verticalPosition = verticalPosition + 100;
|
||||
@ -161,7 +189,7 @@ public class MenuGeneratorsMultiplayer {
|
||||
createCharacterButton.addChild(createCharacterLabel);
|
||||
controlsToAdd.add(createCharacterButton);
|
||||
createCharacterButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
|
||||
WindowUtils.replaceMainMenuContents(MenuGenerators.createTitleMenu());
|
||||
Globals.clientConnection.queueOutgoingMessage(CharacterMessage.constructRequestCreateCharacterMessage(Utilities.stringify(template)));
|
||||
return false;
|
||||
}});
|
||||
|
||||
|
||||
@ -17,9 +17,6 @@ public class AuthProtocol {
|
||||
Globals.clientConnection.queueOutgoingMessage(AuthMessage.constructAuthDetailsMessage("myuser","mypass"));
|
||||
break;
|
||||
case AUTHSUCCESS:
|
||||
//trigger request to spawn character
|
||||
// Globals.clientConnection.queueOutgoingMessage(TerrainMessage.constructRequestMetadataMessage());
|
||||
// Globals.clientConnection.queueOutgoingMessage(CharacterMessage.constructRequestSpawnCharacterMessage());
|
||||
//request playable races
|
||||
Globals.clientConnection.queueOutgoingMessage(LoreMessage.constructRequestRacesMessage());
|
||||
break;
|
||||
|
||||
@ -0,0 +1,31 @@
|
||||
package electrosphere.net.client.protocol;
|
||||
|
||||
import electrosphere.engine.LoadingThread;
|
||||
import electrosphere.main.Globals;
|
||||
import electrosphere.net.parser.net.message.CharacterMessage;
|
||||
import electrosphere.net.parser.net.message.TerrainMessage;
|
||||
|
||||
public class CharacterProtocol {
|
||||
|
||||
protected static void handleCharacterMessage(CharacterMessage message){
|
||||
switch(message.getMessageSubtype()){
|
||||
case RESPONSECREATECHARACTERSUCCESS:
|
||||
//trigger request to spawn character
|
||||
Globals.clientConnection.queueOutgoingMessage(TerrainMessage.constructRequestMetadataMessage());
|
||||
Globals.clientConnection.queueOutgoingMessage(CharacterMessage.constructRequestSpawnCharacterMessage());
|
||||
LoadingThread clientThread = new LoadingThread(LoadingThread.LOAD_CLIENT_WORLD);
|
||||
Globals.loadingThreadsList.add(clientThread);
|
||||
clientThread.start();
|
||||
break;
|
||||
case REQUESTCHARACTERLIST:
|
||||
case REQUESTCREATECHARACTER:
|
||||
case REQUESTSPAWNCHARACTER:
|
||||
case RESPONSECHARACTERLIST:
|
||||
case RESPONSECREATECHARACTERFAILURE:
|
||||
case RESPONSESPAWNCHARACTER:
|
||||
//silently ignore
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -10,6 +10,7 @@ import electrosphere.logger.LoggerInterface;
|
||||
import electrosphere.main.Globals;
|
||||
import electrosphere.main.Main;
|
||||
import electrosphere.net.parser.net.message.AuthMessage;
|
||||
import electrosphere.net.parser.net.message.CharacterMessage;
|
||||
import electrosphere.net.parser.net.message.EntityMessage;
|
||||
import electrosphere.net.parser.net.message.LoreMessage;
|
||||
import electrosphere.net.parser.net.message.NetworkMessage;
|
||||
@ -45,6 +46,9 @@ public class ClientProtocol {
|
||||
case LORE_MESSAGE:
|
||||
LoreProtocol.handleLoreMessage((LoreMessage)message);
|
||||
break;
|
||||
case CHARACTER_MESSAGE:
|
||||
CharacterProtocol.handleCharacterMessage((CharacterMessage)message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -3,27 +3,29 @@ package electrosphere.net.client.protocol;
|
||||
import electrosphere.entity.Entity;
|
||||
import electrosphere.entity.EntityUtils;
|
||||
import electrosphere.entity.types.attach.AttachUtils;
|
||||
import electrosphere.entity.types.creature.CreatureTemplate;
|
||||
import electrosphere.entity.types.creature.CreatureUtils;
|
||||
import electrosphere.entity.types.item.ItemUtils;
|
||||
import electrosphere.logger.LoggerInterface;
|
||||
import electrosphere.main.Globals;
|
||||
import electrosphere.main.Main;
|
||||
import electrosphere.net.parser.net.message.EntityMessage;
|
||||
import electrosphere.util.Utilities;
|
||||
|
||||
public class EntityProtocol {
|
||||
|
||||
protected static void handleEntityMessage(EntityMessage message){
|
||||
LoggerInterface.loggerNetworking.DEBUG("Parse entity message of type " + message.getMessageSubtype());
|
||||
Entity newlySpawnedEntity;
|
||||
switch(message.getMessageSubtype()){
|
||||
case CREATE:
|
||||
LoggerInterface.loggerNetworking.DEBUG("Spawn ID " + message.getentityID() + " of type " + message.getentityCategory() + " subtype " + message.getentitySubtype());
|
||||
Entity newlySpawnedEntity;
|
||||
switch(message.getentityCategory()){
|
||||
case 0:
|
||||
newlySpawnedEntity = CreatureUtils.spawnBasicCreature(message.getentitySubtype());
|
||||
EntityUtils.getScale(newlySpawnedEntity).set(0.005f);
|
||||
EntityUtils.getPosition(newlySpawnedEntity).set(message.getpositionX(),message.getpositionY(),message.getpositionZ());
|
||||
EntityUtils.setEntityID(newlySpawnedEntity, message.getentityID());
|
||||
// newlySpawnedEntity = CreatureUtils.spawnBasicCreature(message.getentitySubtype());
|
||||
// EntityUtils.getScale(newlySpawnedEntity).set(0.005f);
|
||||
// EntityUtils.getPosition(newlySpawnedEntity).set(message.getpositionX(),message.getpositionY(),message.getpositionZ());
|
||||
// EntityUtils.setEntityID(newlySpawnedEntity, message.getentityID());
|
||||
break;
|
||||
case 1:
|
||||
newlySpawnedEntity = ItemUtils.spawnBasicItem(message.getentitySubtype());
|
||||
@ -33,6 +35,14 @@ public class EntityProtocol {
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SPAWNCREATURE:
|
||||
LoggerInterface.loggerNetworking.DEBUG("Spawn ID " + message.getentityID() + " of type " + message.getentityCategory() + " subtype " + message.getentitySubtype());
|
||||
CreatureTemplate template = Utilities.deserialize(message.getcreatureTemplate(), CreatureTemplate.class);
|
||||
newlySpawnedEntity = CreatureUtils.spawnBasicCreature(template.getCreatureType(),template);
|
||||
EntityUtils.getScale(newlySpawnedEntity).set(0.005f);
|
||||
EntityUtils.getPosition(newlySpawnedEntity).set(message.getpositionX(),message.getpositionY(),message.getpositionZ());
|
||||
EntityUtils.setEntityID(newlySpawnedEntity, message.getentityID());
|
||||
break;
|
||||
case DESTROY:
|
||||
break;
|
||||
case MOVE:
|
||||
|
||||
@ -10,7 +10,8 @@ public class CharacterMessage extends NetworkMessage {
|
||||
REQUESTCHARACTERLIST,
|
||||
RESPONSECHARACTERLIST,
|
||||
REQUESTCREATECHARACTER,
|
||||
RESPONSECREATECHARACTER,
|
||||
RESPONSECREATECHARACTERSUCCESS,
|
||||
RESPONSECREATECHARACTERFAILURE,
|
||||
REQUESTSPAWNCHARACTER,
|
||||
RESPONSESPAWNCHARACTER,
|
||||
}
|
||||
@ -51,13 +52,19 @@ public class CharacterMessage extends NetworkMessage {
|
||||
case TypeBytes.CHARACTER_MESSAGE_TYPE_RESPONSECHARACTERLIST:
|
||||
return CharacterMessage.canParseResponseCharacterListMessage(byteStream);
|
||||
case TypeBytes.CHARACTER_MESSAGE_TYPE_REQUESTCREATECHARACTER:
|
||||
if(byteStream.size() >= TypeBytes.CHARACTER_MESSAGE_TYPE_REQUESTCREATECHARACTER_SIZE){
|
||||
return CharacterMessage.canParseRequestCreateCharacterMessage(byteStream);
|
||||
case TypeBytes.CHARACTER_MESSAGE_TYPE_RESPONSECREATECHARACTERSUCCESS:
|
||||
if(byteStream.size() >= TypeBytes.CHARACTER_MESSAGE_TYPE_RESPONSECREATECHARACTERSUCCESS_SIZE){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
case TypeBytes.CHARACTER_MESSAGE_TYPE_RESPONSECREATECHARACTERFAILURE:
|
||||
if(byteStream.size() >= TypeBytes.CHARACTER_MESSAGE_TYPE_RESPONSECREATECHARACTERFAILURE_SIZE){
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
case TypeBytes.CHARACTER_MESSAGE_TYPE_RESPONSECREATECHARACTER:
|
||||
return CharacterMessage.canParseResponseCreateCharacterMessage(byteStream);
|
||||
case TypeBytes.CHARACTER_MESSAGE_TYPE_REQUESTSPAWNCHARACTER:
|
||||
if(byteStream.size() >= TypeBytes.CHARACTER_MESSAGE_TYPE_REQUESTSPAWNCHARACTER_SIZE){
|
||||
return true;
|
||||
@ -115,19 +122,7 @@ public class CharacterMessage extends NetworkMessage {
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static CharacterMessage parseRequestCreateCharacterMessage(List<Byte> byteStream){
|
||||
CharacterMessage rVal = new CharacterMessage(CharacterMessageType.REQUESTCREATECHARACTER);
|
||||
stripPacketHeader(byteStream);
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static CharacterMessage constructRequestCreateCharacterMessage(){
|
||||
CharacterMessage rVal = new CharacterMessage(CharacterMessageType.REQUESTCREATECHARACTER);
|
||||
rVal.serialize();
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static boolean canParseResponseCreateCharacterMessage(List<Byte> byteStream){
|
||||
public static boolean canParseRequestCreateCharacterMessage(List<Byte> byteStream){
|
||||
int currentStreamLength = byteStream.size();
|
||||
List<Byte> temporaryByteQueue = new LinkedList();
|
||||
int dataSize = 0;
|
||||
@ -146,20 +141,44 @@ public class CharacterMessage extends NetworkMessage {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static CharacterMessage parseResponseCreateCharacterMessage(List<Byte> byteStream){
|
||||
CharacterMessage rVal = new CharacterMessage(CharacterMessageType.RESPONSECREATECHARACTER);
|
||||
public static CharacterMessage parseRequestCreateCharacterMessage(List<Byte> byteStream){
|
||||
CharacterMessage rVal = new CharacterMessage(CharacterMessageType.REQUESTCREATECHARACTER);
|
||||
stripPacketHeader(byteStream);
|
||||
rVal.setdata(ByteStreamUtils.popStringFromByteQueue(byteStream));
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static CharacterMessage constructResponseCreateCharacterMessage(String data){
|
||||
CharacterMessage rVal = new CharacterMessage(CharacterMessageType.RESPONSECREATECHARACTER);
|
||||
public static CharacterMessage constructRequestCreateCharacterMessage(String data){
|
||||
CharacterMessage rVal = new CharacterMessage(CharacterMessageType.REQUESTCREATECHARACTER);
|
||||
rVal.setdata(data);
|
||||
rVal.serialize();
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static CharacterMessage parseResponseCreateCharacterSuccessMessage(List<Byte> byteStream){
|
||||
CharacterMessage rVal = new CharacterMessage(CharacterMessageType.RESPONSECREATECHARACTERSUCCESS);
|
||||
stripPacketHeader(byteStream);
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static CharacterMessage constructResponseCreateCharacterSuccessMessage(){
|
||||
CharacterMessage rVal = new CharacterMessage(CharacterMessageType.RESPONSECREATECHARACTERSUCCESS);
|
||||
rVal.serialize();
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static CharacterMessage parseResponseCreateCharacterFailureMessage(List<Byte> byteStream){
|
||||
CharacterMessage rVal = new CharacterMessage(CharacterMessageType.RESPONSECREATECHARACTERFAILURE);
|
||||
stripPacketHeader(byteStream);
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static CharacterMessage constructResponseCreateCharacterFailureMessage(){
|
||||
CharacterMessage rVal = new CharacterMessage(CharacterMessageType.RESPONSECREATECHARACTERFAILURE);
|
||||
rVal.serialize();
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static CharacterMessage parseRequestSpawnCharacterMessage(List<Byte> byteStream){
|
||||
CharacterMessage rVal = new CharacterMessage(CharacterMessageType.REQUESTSPAWNCHARACTER);
|
||||
stripPacketHeader(byteStream);
|
||||
@ -233,18 +252,11 @@ public class CharacterMessage extends NetworkMessage {
|
||||
}
|
||||
break;
|
||||
case REQUESTCREATECHARACTER:
|
||||
rawBytes = new byte[2];
|
||||
//message header
|
||||
rawBytes[0] = TypeBytes.MESSAGE_TYPE_CHARACTER;
|
||||
//entity messaage header
|
||||
rawBytes[1] = TypeBytes.CHARACTER_MESSAGE_TYPE_REQUESTCREATECHARACTER;
|
||||
break;
|
||||
case RESPONSECREATECHARACTER:
|
||||
rawBytes = new byte[2+4+data.length()];
|
||||
//message header
|
||||
rawBytes[0] = TypeBytes.MESSAGE_TYPE_CHARACTER;
|
||||
//entity messaage header
|
||||
rawBytes[1] = TypeBytes.CHARACTER_MESSAGE_TYPE_RESPONSECREATECHARACTER;
|
||||
rawBytes[1] = TypeBytes.CHARACTER_MESSAGE_TYPE_REQUESTCREATECHARACTER;
|
||||
intValues = ByteStreamUtils.serializeIntToBytes(data.length());
|
||||
for(int i = 0; i < 4; i++){
|
||||
rawBytes[2+i] = intValues[i];
|
||||
@ -254,6 +266,20 @@ public class CharacterMessage extends NetworkMessage {
|
||||
rawBytes[6+i] = stringBytes[i];
|
||||
}
|
||||
break;
|
||||
case RESPONSECREATECHARACTERSUCCESS:
|
||||
rawBytes = new byte[2];
|
||||
//message header
|
||||
rawBytes[0] = TypeBytes.MESSAGE_TYPE_CHARACTER;
|
||||
//entity messaage header
|
||||
rawBytes[1] = TypeBytes.CHARACTER_MESSAGE_TYPE_RESPONSECREATECHARACTERSUCCESS;
|
||||
break;
|
||||
case RESPONSECREATECHARACTERFAILURE:
|
||||
rawBytes = new byte[2];
|
||||
//message header
|
||||
rawBytes[0] = TypeBytes.MESSAGE_TYPE_CHARACTER;
|
||||
//entity messaage header
|
||||
rawBytes[1] = TypeBytes.CHARACTER_MESSAGE_TYPE_RESPONSECREATECHARACTERFAILURE;
|
||||
break;
|
||||
case REQUESTSPAWNCHARACTER:
|
||||
rawBytes = new byte[2];
|
||||
//message header
|
||||
|
||||
@ -8,6 +8,7 @@ public class EntityMessage extends NetworkMessage {
|
||||
|
||||
public enum EntityMessageType {
|
||||
CREATE,
|
||||
SPAWNCREATURE,
|
||||
SETPOSITION,
|
||||
SETFACING,
|
||||
MOVEUPDATE,
|
||||
@ -24,6 +25,7 @@ public class EntityMessage extends NetworkMessage {
|
||||
int entityCategory;
|
||||
String entitySubtype;
|
||||
int entityID;
|
||||
String creatureTemplate;
|
||||
double positionX;
|
||||
double positionY;
|
||||
double positionZ;
|
||||
@ -74,6 +76,14 @@ public class EntityMessage extends NetworkMessage {
|
||||
this.entityID = entityID;
|
||||
}
|
||||
|
||||
public String getcreatureTemplate() {
|
||||
return creatureTemplate;
|
||||
}
|
||||
|
||||
public void setcreatureTemplate(String creatureTemplate) {
|
||||
this.creatureTemplate = creatureTemplate;
|
||||
}
|
||||
|
||||
public double getpositionX() {
|
||||
return positionX;
|
||||
}
|
||||
@ -211,6 +221,8 @@ public class EntityMessage extends NetworkMessage {
|
||||
switch(secondByte){
|
||||
case TypeBytes.ENTITY_MESSAGE_TYPE_CREATE:
|
||||
return EntityMessage.canParseCreateMessage(byteStream);
|
||||
case TypeBytes.ENTITY_MESSAGE_TYPE_SPAWNCREATURE:
|
||||
return EntityMessage.canParseSpawnCreatureMessage(byteStream);
|
||||
case TypeBytes.ENTITY_MESSAGE_TYPE_SETPOSITION:
|
||||
if(byteStream.size() >= TypeBytes.ENTITY_MESSAGE_TYPE_SETPOSITION_SIZE){
|
||||
return true;
|
||||
@ -329,6 +341,59 @@ public class EntityMessage extends NetworkMessage {
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static boolean canParseSpawnCreatureMessage(List<Byte> byteStream){
|
||||
int currentStreamLength = byteStream.size();
|
||||
List<Byte> temporaryByteQueue = new LinkedList();
|
||||
if(currentStreamLength < 6){
|
||||
return false;
|
||||
}
|
||||
int creatureTemplateSize = 0;
|
||||
if(currentStreamLength < 10){
|
||||
return false;
|
||||
} else {
|
||||
temporaryByteQueue.add(byteStream.get(6 + 0));
|
||||
temporaryByteQueue.add(byteStream.get(6 + 1));
|
||||
temporaryByteQueue.add(byteStream.get(6 + 2));
|
||||
temporaryByteQueue.add(byteStream.get(6 + 3));
|
||||
creatureTemplateSize = ByteStreamUtils.popIntFromByteQueue(temporaryByteQueue);
|
||||
}
|
||||
if(currentStreamLength < 10 + creatureTemplateSize){
|
||||
return false;
|
||||
}
|
||||
if(currentStreamLength < 14){
|
||||
return false;
|
||||
}
|
||||
if(currentStreamLength < 22){
|
||||
return false;
|
||||
}
|
||||
if(currentStreamLength < 30){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static EntityMessage parseSpawnCreatureMessage(List<Byte> byteStream){
|
||||
EntityMessage rVal = new EntityMessage(EntityMessageType.SPAWNCREATURE);
|
||||
stripPacketHeader(byteStream);
|
||||
rVal.setentityID(ByteStreamUtils.popIntFromByteQueue(byteStream));
|
||||
rVal.setcreatureTemplate(ByteStreamUtils.popStringFromByteQueue(byteStream));
|
||||
rVal.setpositionX(ByteStreamUtils.popDoubleFromByteQueue(byteStream));
|
||||
rVal.setpositionY(ByteStreamUtils.popDoubleFromByteQueue(byteStream));
|
||||
rVal.setpositionZ(ByteStreamUtils.popDoubleFromByteQueue(byteStream));
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static EntityMessage constructSpawnCreatureMessage(int entityID,String creatureTemplate,double positionX,double positionY,double positionZ){
|
||||
EntityMessage rVal = new EntityMessage(EntityMessageType.SPAWNCREATURE);
|
||||
rVal.setentityID(entityID);
|
||||
rVal.setcreatureTemplate(creatureTemplate);
|
||||
rVal.setpositionX(positionX);
|
||||
rVal.setpositionY(positionY);
|
||||
rVal.setpositionZ(positionZ);
|
||||
rVal.serialize();
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static EntityMessage parseSetPositionMessage(List<Byte> byteStream){
|
||||
EntityMessage rVal = new EntityMessage(EntityMessageType.SETPOSITION);
|
||||
stripPacketHeader(byteStream);
|
||||
@ -612,6 +677,37 @@ public class EntityMessage extends NetworkMessage {
|
||||
rawBytes[30+entitySubtype.length()+i] = intValues[i];
|
||||
}
|
||||
break;
|
||||
case SPAWNCREATURE:
|
||||
rawBytes = new byte[2+4+4+creatureTemplate.length()+8+8+8];
|
||||
//message header
|
||||
rawBytes[0] = TypeBytes.MESSAGE_TYPE_ENTITY;
|
||||
//entity messaage header
|
||||
rawBytes[1] = TypeBytes.ENTITY_MESSAGE_TYPE_SPAWNCREATURE;
|
||||
intValues = ByteStreamUtils.serializeIntToBytes(entityID);
|
||||
for(int i = 0; i < 4; i++){
|
||||
rawBytes[2+i] = intValues[i];
|
||||
}
|
||||
intValues = ByteStreamUtils.serializeIntToBytes(creatureTemplate.length());
|
||||
for(int i = 0; i < 4; i++){
|
||||
rawBytes[6+i] = intValues[i];
|
||||
}
|
||||
stringBytes = creatureTemplate.getBytes();
|
||||
for(int i = 0; i < creatureTemplate.length(); i++){
|
||||
rawBytes[10+i] = stringBytes[i];
|
||||
}
|
||||
intValues = ByteStreamUtils.serializeDoubleToBytes(positionX);
|
||||
for(int i = 0; i < 8; i++){
|
||||
rawBytes[10+creatureTemplate.length()+i] = intValues[i];
|
||||
}
|
||||
intValues = ByteStreamUtils.serializeDoubleToBytes(positionY);
|
||||
for(int i = 0; i < 8; i++){
|
||||
rawBytes[18+creatureTemplate.length()+i] = intValues[i];
|
||||
}
|
||||
intValues = ByteStreamUtils.serializeDoubleToBytes(positionZ);
|
||||
for(int i = 0; i < 8; i++){
|
||||
rawBytes[26+creatureTemplate.length()+i] = intValues[i];
|
||||
}
|
||||
break;
|
||||
case SETPOSITION:
|
||||
rawBytes = new byte[2+4+8+8+8+8];
|
||||
//message header
|
||||
|
||||
@ -8,11 +8,11 @@ public abstract class NetworkMessage {
|
||||
public enum MessageType {
|
||||
ENTITY_MESSAGE,
|
||||
LORE_MESSAGE,
|
||||
CHARACTER_MESSAGE,
|
||||
PLAYER_MESSAGE,
|
||||
TERRAIN_MESSAGE,
|
||||
SERVER_MESSAGE,
|
||||
AUTH_MESSAGE,
|
||||
CHARACTER_MESSAGE,
|
||||
}
|
||||
|
||||
MessageType type;
|
||||
@ -42,6 +42,11 @@ AUTH_MESSAGE,
|
||||
rVal = EntityMessage.parseCreateMessage(byteStream);
|
||||
}
|
||||
break;
|
||||
case TypeBytes.ENTITY_MESSAGE_TYPE_SPAWNCREATURE:
|
||||
if(EntityMessage.canParseMessage(byteStream,secondByte)){
|
||||
rVal = EntityMessage.parseSpawnCreatureMessage(byteStream);
|
||||
}
|
||||
break;
|
||||
case TypeBytes.ENTITY_MESSAGE_TYPE_SETPOSITION:
|
||||
if(EntityMessage.canParseMessage(byteStream,secondByte)){
|
||||
rVal = EntityMessage.parseSetPositionMessage(byteStream);
|
||||
@ -129,41 +134,6 @@ AUTH_MESSAGE,
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case TypeBytes.MESSAGE_TYPE_CHARACTER:
|
||||
secondByte = byteStream.get(1);
|
||||
switch(secondByte){
|
||||
case TypeBytes.CHARACTER_MESSAGE_TYPE_REQUESTCHARACTERLIST:
|
||||
if(CharacterMessage.canParseMessage(byteStream,secondByte)){
|
||||
rVal = CharacterMessage.parseRequestCharacterListMessage(byteStream);
|
||||
}
|
||||
break;
|
||||
case TypeBytes.CHARACTER_MESSAGE_TYPE_RESPONSECHARACTERLIST:
|
||||
if(CharacterMessage.canParseMessage(byteStream,secondByte)){
|
||||
rVal = CharacterMessage.parseResponseCharacterListMessage(byteStream);
|
||||
}
|
||||
break;
|
||||
case TypeBytes.CHARACTER_MESSAGE_TYPE_REQUESTCREATECHARACTER:
|
||||
if(CharacterMessage.canParseMessage(byteStream,secondByte)){
|
||||
rVal = CharacterMessage.parseRequestCreateCharacterMessage(byteStream);
|
||||
}
|
||||
break;
|
||||
case TypeBytes.CHARACTER_MESSAGE_TYPE_RESPONSECREATECHARACTER:
|
||||
if(CharacterMessage.canParseMessage(byteStream,secondByte)){
|
||||
rVal = CharacterMessage.parseResponseCreateCharacterMessage(byteStream);
|
||||
}
|
||||
break;
|
||||
case TypeBytes.CHARACTER_MESSAGE_TYPE_REQUESTSPAWNCHARACTER:
|
||||
if(CharacterMessage.canParseMessage(byteStream,secondByte)){
|
||||
rVal = CharacterMessage.parseRequestSpawnCharacterMessage(byteStream);
|
||||
}
|
||||
break;
|
||||
case TypeBytes.CHARACTER_MESSAGE_TYPE_RESPONSESPAWNCHARACTER:
|
||||
if(CharacterMessage.canParseMessage(byteStream,secondByte)){
|
||||
rVal = CharacterMessage.parseResponseSpawnCharacterMessage(byteStream);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case TypeBytes.MESSAGE_TYPE_PLAYER:
|
||||
secondByte = byteStream.get(1);
|
||||
switch(secondByte){
|
||||
@ -264,6 +234,46 @@ AUTH_MESSAGE,
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case TypeBytes.MESSAGE_TYPE_CHARACTER:
|
||||
secondByte = byteStream.get(1);
|
||||
switch(secondByte){
|
||||
case TypeBytes.CHARACTER_MESSAGE_TYPE_REQUESTCHARACTERLIST:
|
||||
if(CharacterMessage.canParseMessage(byteStream,secondByte)){
|
||||
rVal = CharacterMessage.parseRequestCharacterListMessage(byteStream);
|
||||
}
|
||||
break;
|
||||
case TypeBytes.CHARACTER_MESSAGE_TYPE_RESPONSECHARACTERLIST:
|
||||
if(CharacterMessage.canParseMessage(byteStream,secondByte)){
|
||||
rVal = CharacterMessage.parseResponseCharacterListMessage(byteStream);
|
||||
}
|
||||
break;
|
||||
case TypeBytes.CHARACTER_MESSAGE_TYPE_REQUESTCREATECHARACTER:
|
||||
if(CharacterMessage.canParseMessage(byteStream,secondByte)){
|
||||
rVal = CharacterMessage.parseRequestCreateCharacterMessage(byteStream);
|
||||
}
|
||||
break;
|
||||
case TypeBytes.CHARACTER_MESSAGE_TYPE_RESPONSECREATECHARACTERSUCCESS:
|
||||
if(CharacterMessage.canParseMessage(byteStream,secondByte)){
|
||||
rVal = CharacterMessage.parseResponseCreateCharacterSuccessMessage(byteStream);
|
||||
}
|
||||
break;
|
||||
case TypeBytes.CHARACTER_MESSAGE_TYPE_RESPONSECREATECHARACTERFAILURE:
|
||||
if(CharacterMessage.canParseMessage(byteStream,secondByte)){
|
||||
rVal = CharacterMessage.parseResponseCreateCharacterFailureMessage(byteStream);
|
||||
}
|
||||
break;
|
||||
case TypeBytes.CHARACTER_MESSAGE_TYPE_REQUESTSPAWNCHARACTER:
|
||||
if(CharacterMessage.canParseMessage(byteStream,secondByte)){
|
||||
rVal = CharacterMessage.parseRequestSpawnCharacterMessage(byteStream);
|
||||
}
|
||||
break;
|
||||
case TypeBytes.CHARACTER_MESSAGE_TYPE_RESPONSESPAWNCHARACTER:
|
||||
if(CharacterMessage.canParseMessage(byteStream,secondByte)){
|
||||
rVal = CharacterMessage.parseResponseSpawnCharacterMessage(byteStream);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return rVal;
|
||||
|
||||
@ -7,25 +7,26 @@ Message categories
|
||||
*/
|
||||
public static final byte MESSAGE_TYPE_ENTITY = 0;
|
||||
public static final byte MESSAGE_TYPE_LORE = 1;
|
||||
public static final byte MESSAGE_TYPE_CHARACTER = 2;
|
||||
public static final byte MESSAGE_TYPE_PLAYER = 3;
|
||||
public static final byte MESSAGE_TYPE_TERRAIN = 4;
|
||||
public static final byte MESSAGE_TYPE_SERVER = 5;
|
||||
public static final byte MESSAGE_TYPE_AUTH = 6;
|
||||
public static final byte MESSAGE_TYPE_PLAYER = 2;
|
||||
public static final byte MESSAGE_TYPE_TERRAIN = 3;
|
||||
public static final byte MESSAGE_TYPE_SERVER = 4;
|
||||
public static final byte MESSAGE_TYPE_AUTH = 5;
|
||||
public static final byte MESSAGE_TYPE_CHARACTER = 6;
|
||||
/*
|
||||
Entity subcategories
|
||||
*/
|
||||
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_SETFACING = 2;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_MOVEUPDATE = 3;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_ATTACKUPDATE = 4;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_MOVE = 5;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_KILL = 6;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_DESTROY = 7;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_SETBEHAVIORTREE = 8;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_SETPROPERTY = 9;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_ATTACHENTITYTOENTITY = 10;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_SPAWNCREATURE = 1;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_SETPOSITION = 2;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_SETFACING = 3;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_MOVEUPDATE = 4;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_ATTACKUPDATE = 5;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_MOVE = 6;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_KILL = 7;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_DESTROY = 8;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_SETBEHAVIORTREE = 9;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_SETPROPERTY = 10;
|
||||
public static final byte ENTITY_MESSAGE_TYPE_ATTACHENTITYTOENTITY = 11;
|
||||
/*
|
||||
Entity packet sizes
|
||||
*/
|
||||
@ -53,21 +54,6 @@ Message categories
|
||||
public static final byte LORE_MESSAGE_TYPE_REQUESTRACES_SIZE = 2;
|
||||
public static final byte LORE_MESSAGE_TYPE_REQUESTRACEDATA_SIZE = 2;
|
||||
/*
|
||||
Character subcategories
|
||||
*/
|
||||
public static final byte CHARACTER_MESSAGE_TYPE_REQUESTCHARACTERLIST = 0;
|
||||
public static final byte CHARACTER_MESSAGE_TYPE_RESPONSECHARACTERLIST = 1;
|
||||
public static final byte CHARACTER_MESSAGE_TYPE_REQUESTCREATECHARACTER = 2;
|
||||
public static final byte CHARACTER_MESSAGE_TYPE_RESPONSECREATECHARACTER = 3;
|
||||
public static final byte CHARACTER_MESSAGE_TYPE_REQUESTSPAWNCHARACTER = 4;
|
||||
public static final byte CHARACTER_MESSAGE_TYPE_RESPONSESPAWNCHARACTER = 5;
|
||||
/*
|
||||
Character packet sizes
|
||||
*/
|
||||
public static final byte CHARACTER_MESSAGE_TYPE_REQUESTCHARACTERLIST_SIZE = 2;
|
||||
public static final byte CHARACTER_MESSAGE_TYPE_REQUESTCREATECHARACTER_SIZE = 2;
|
||||
public static final byte CHARACTER_MESSAGE_TYPE_REQUESTSPAWNCHARACTER_SIZE = 2;
|
||||
/*
|
||||
Player subcategories
|
||||
*/
|
||||
public static final byte PLAYER_MESSAGE_TYPE_SET_ID = 0;
|
||||
@ -122,5 +108,22 @@ Message categories
|
||||
public static final byte AUTH_MESSAGE_TYPE_AUTHREQUEST_SIZE = 2;
|
||||
public static final byte AUTH_MESSAGE_TYPE_AUTHSUCCESS_SIZE = 2;
|
||||
public static final byte AUTH_MESSAGE_TYPE_AUTHFAILURE_SIZE = 2;
|
||||
/*
|
||||
Character subcategories
|
||||
*/
|
||||
public static final byte CHARACTER_MESSAGE_TYPE_REQUESTCHARACTERLIST = 0;
|
||||
public static final byte CHARACTER_MESSAGE_TYPE_RESPONSECHARACTERLIST = 1;
|
||||
public static final byte CHARACTER_MESSAGE_TYPE_REQUESTCREATECHARACTER = 2;
|
||||
public static final byte CHARACTER_MESSAGE_TYPE_RESPONSECREATECHARACTERSUCCESS = 3;
|
||||
public static final byte CHARACTER_MESSAGE_TYPE_RESPONSECREATECHARACTERFAILURE = 4;
|
||||
public static final byte CHARACTER_MESSAGE_TYPE_REQUESTSPAWNCHARACTER = 5;
|
||||
public static final byte CHARACTER_MESSAGE_TYPE_RESPONSESPAWNCHARACTER = 6;
|
||||
/*
|
||||
Character packet sizes
|
||||
*/
|
||||
public static final byte CHARACTER_MESSAGE_TYPE_REQUESTCHARACTERLIST_SIZE = 2;
|
||||
public static final byte CHARACTER_MESSAGE_TYPE_RESPONSECREATECHARACTERSUCCESS_SIZE = 2;
|
||||
public static final byte CHARACTER_MESSAGE_TYPE_RESPONSECREATECHARACTERFAILURE_SIZE = 2;
|
||||
public static final byte CHARACTER_MESSAGE_TYPE_REQUESTSPAWNCHARACTER_SIZE = 2;
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package electrosphere.net.server;
|
||||
|
||||
import electrosphere.entity.types.creature.CreatureTemplate;
|
||||
import electrosphere.entity.types.creature.CreatureUtils;
|
||||
import electrosphere.entity.Entity;
|
||||
import electrosphere.entity.EntityUtils;
|
||||
@ -56,6 +57,7 @@ public class ServerConnectionHandler implements Runnable {
|
||||
NetworkParser networkParser;
|
||||
int playerID;
|
||||
int playerCharacterID;
|
||||
CreatureTemplate currentCreatureTemplate;
|
||||
|
||||
ServerProtocol serverProtocol;
|
||||
|
||||
@ -175,4 +177,13 @@ public class ServerConnectionHandler implements Runnable {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void setCreatureTemplate(CreatureTemplate currentCreatureTemplate){
|
||||
this.currentCreatureTemplate = currentCreatureTemplate;
|
||||
}
|
||||
|
||||
public CreatureTemplate getCurrentCreatureTemplate(){
|
||||
return this.currentCreatureTemplate;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ import org.joml.Vector3f;
|
||||
import electrosphere.entity.Entity;
|
||||
import electrosphere.entity.state.ironsight.IronSightTree;
|
||||
import electrosphere.entity.types.collision.CollisionObjUtils;
|
||||
import electrosphere.entity.types.creature.CreatureTemplate;
|
||||
import electrosphere.entity.types.creature.CreatureUtils;
|
||||
import electrosphere.main.Globals;
|
||||
import electrosphere.main.Main;
|
||||
@ -14,6 +15,7 @@ import electrosphere.net.parser.net.message.PlayerMessage;
|
||||
import electrosphere.net.parser.net.message.TerrainMessage;
|
||||
import electrosphere.net.server.ServerConnectionHandler;
|
||||
import electrosphere.net.server.player.Player;
|
||||
import electrosphere.util.Utilities;
|
||||
|
||||
public class CharacterProtocol {
|
||||
|
||||
@ -23,17 +25,20 @@ public class CharacterProtocol {
|
||||
//TODO
|
||||
break;
|
||||
case REQUESTCREATECHARACTER:
|
||||
//TODO
|
||||
CreatureTemplate template = Utilities.deserialize(message.getdata(), CreatureTemplate.class);
|
||||
if(template != null){
|
||||
connectionHandler.setCreatureTemplate(Utilities.deserialize(message.getdata(), CreatureTemplate.class));
|
||||
connectionHandler.addMessagetoOutgoingQueue(CharacterMessage.constructResponseCreateCharacterSuccessMessage());
|
||||
} else {
|
||||
connectionHandler.addMessagetoOutgoingQueue(CharacterMessage.constructResponseCreateCharacterFailureMessage());
|
||||
}
|
||||
break;
|
||||
case REQUESTSPAWNCHARACTER:
|
||||
spawnPlayerCharacter(connectionHandler);
|
||||
break;
|
||||
case RESPONSECHARACTERLIST:
|
||||
//silently ignore
|
||||
break;
|
||||
case RESPONSECREATECHARACTER:
|
||||
//silently ignore
|
||||
break;
|
||||
case RESPONSECREATECHARACTERSUCCESS:
|
||||
case RESPONSECREATECHARACTERFAILURE:
|
||||
case RESPONSESPAWNCHARACTER:
|
||||
//silently ignore
|
||||
break;
|
||||
@ -43,7 +48,7 @@ public class CharacterProtocol {
|
||||
static void spawnPlayerCharacter(ServerConnectionHandler connectionHandler){
|
||||
Player playerObject = Globals.playerManager.getPlayerFromId(connectionHandler.getPlayerId());
|
||||
//spawn player in world
|
||||
Entity newPlayerEntity = CreatureUtils.spawnBasicCreature("human");
|
||||
Entity newPlayerEntity = CreatureUtils.spawnBasicCreature("human",connectionHandler.getCurrentCreatureTemplate());
|
||||
int playerCharacterId = newPlayerEntity.getId();
|
||||
connectionHandler.setPlayerCharacterId(playerCharacterId);
|
||||
CreatureUtils.repositionCreature(newPlayerEntity, new Vector3d(Globals.spawnPoint.x,Globals.spawnPoint.y,Globals.spawnPoint.z));
|
||||
|
||||
@ -1312,5 +1312,21 @@ public class RenderingEngine {
|
||||
outputFramebuffer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setFOV(float verticalFOV){
|
||||
Globals.verticalFOV = verticalFOV;
|
||||
calculateProjectionMatrix();
|
||||
}
|
||||
|
||||
public static void setAspectRatio(float aspectRatio){
|
||||
Globals.aspectRatio = aspectRatio;
|
||||
calculateProjectionMatrix();
|
||||
}
|
||||
|
||||
static void calculateProjectionMatrix(){
|
||||
float radVerticalFOV = (float)(Globals.verticalFOV * Math.PI /180.0f);
|
||||
float nearClip = 0.001f;
|
||||
Globals.projectionMatrix.setPerspective(radVerticalFOV, Globals.aspectRatio, nearClip, Globals.userSettings.getGraphicsViewDistance());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -73,6 +73,12 @@ public class ActorStaticMorph {
|
||||
}
|
||||
}
|
||||
|
||||
void setScale(String boneName, float scale){
|
||||
if(boneTransformMap.containsKey(boneName)){
|
||||
boneTransformMap.get(boneName).scale.set(scale);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Instead of having this code be duplicated every time we want to update a static morph, putting it in here
|
||||
*/
|
||||
@ -105,6 +111,9 @@ public class ActorStaticMorph {
|
||||
case "offz":
|
||||
this.setOffsetZ(bone, value);
|
||||
break;
|
||||
case "scale":
|
||||
this.setScale(bone, value);
|
||||
break;
|
||||
case "offl":
|
||||
//TODO
|
||||
break;
|
||||
|
||||
@ -3,10 +3,17 @@ package electrosphere.renderer.ui.elements;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
import static org.lwjgl.opengl.GL11.GL_DEPTH_TEST;
|
||||
import static org.lwjgl.opengl.GL11.GL_LESS;
|
||||
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
|
||||
import static org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT;
|
||||
import static org.lwjgl.opengl.GL11.glDepthFunc;
|
||||
import static org.lwjgl.opengl.GL11.glDepthMask;
|
||||
import static org.lwjgl.opengl.GL11.glClear;
|
||||
import static org.lwjgl.opengl.GL11.glClearColor;
|
||||
import static org.lwjgl.opengl.GL11.glEnable;
|
||||
import static org.lwjgl.opengl.GL11.glDisable;
|
||||
import static org.lwjgl.opengl.GL11.glViewport;
|
||||
import static org.lwjgl.opengl.GL30.GL_FRAMEBUFFER;
|
||||
import static org.lwjgl.opengl.GL30.glBindFramebuffer;
|
||||
|
||||
@ -64,6 +71,11 @@ public class ActorPanel implements DrawableElement, DraggableElement {
|
||||
elementBuffer.bind();
|
||||
// Globals.renderingEngine.setViewportSize(width, height);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_LESS);
|
||||
glDepthMask(true);
|
||||
glViewport(0, 0, width, height);
|
||||
|
||||
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
@ -77,9 +89,14 @@ public class ActorPanel implements DrawableElement, DraggableElement {
|
||||
actor.applyModelMatrix(modelMatrix);
|
||||
actor.draw(true);
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
//this call binds the screen as the "texture" we're rendering to
|
||||
//have to call before actually rendering
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, parentFramebufferPointer);
|
||||
|
||||
//set viewport
|
||||
Globals.renderingEngine.setViewportSize(parentWidth, parentHeight);
|
||||
|
||||
float ndcX = (float)positionX/parentWidth;
|
||||
float ndcY = (float)positionY/parentHeight;
|
||||
|
||||
@ -111,7 +111,7 @@ public class Slider implements ClickableElement, DraggableElement, FocusableElem
|
||||
//actual slider
|
||||
ndcX = (float)(positionX + marginX)/parentWidth;
|
||||
ndcY = (float)(positionY + marginY)/parentHeight;
|
||||
ndcWidth = (float)(width * getValueAsPercentage() - marginX * 2)/parentWidth;
|
||||
ndcWidth = (float)((width - marginX * 2) * getValueAsPercentage())/parentWidth;
|
||||
ndcHeight = (float)(height - marginY * 2)/parentHeight;
|
||||
boxPosition = new Vector3f(ndcX,ndcY,0);
|
||||
boxDimensions = new Vector3f(ndcWidth,ndcHeight,0);
|
||||
|
||||
@ -129,4 +129,8 @@ public class Utilities {
|
||||
return gson.toJson(object);
|
||||
}
|
||||
|
||||
public static <T>T deserialize(String object, Class<T> className){
|
||||
return gson.fromJson(object, className);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -11,7 +11,8 @@
|
||||
"./net/player.json",
|
||||
"./net/terrain.json",
|
||||
"./net/world.json",
|
||||
"./net/server.json"
|
||||
"./net/server.json",
|
||||
"./net/character.json"
|
||||
]
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user