Overhaul spawning / creatures / items data

This commit is contained in:
austin 2021-06-29 23:32:53 -04:00
parent 1c01ab1868
commit ef6116646a
24 changed files with 516 additions and 281 deletions

View File

@ -1,39 +1,197 @@
{
"creatures" : [
{
"name" : "Human",
"bodyParts" : [
{
"name" : "Head",
"type" : "Head",
"size" : 1
"type" : "Head"
},
{
"name" : "Torso",
"type" : "Torso",
"size" : 1
"type" : "Torso"
},
{
"name" : "ArmLeft",
"type" : "Arm",
"size" : 1
"type" : "Arm"
},
{
"name" : "ArmRight",
"type" : "Arm",
"size" : 1
"type" : "Arm"
},
{
"name" : "LegLeft",
"type" : "Leg",
"size" : 1
"type" : "Leg"
},
{
"name" : "LegRight",
"type" : "Leg",
"size" : 1
"type" : "Leg"
}
]
],
"hitboxes" : [
{
"type": "hurt",
"bone": "Bone.031",
"radius": 0.04
},
{
"type": "hurt",
"bone": "Bone.012",
"radius": 0.04
},
{
"type": "hurt",
"bone": "Bone.003",
"radius": 0.04
},
{
"type": "hurt",
"bone": "Bone.010",
"radius": 0.06
},
{
"type": "hurt",
"bone": "Bone.001",
"radius": 0.06
},
{
"type": "hurt",
"bone": "Bone.014",
"radius": 0.06
},
{
"type": "hurt",
"bone": "Bone",
"radius": 0.08
},
{
"type": "hurt",
"bone": "Bone.014",
"radius": 0.06
},
{
"type": "hurt",
"bone": "Bone.019",
"radius": 0.04
}
],
"tokens" : [
"BLENDER_TRANSFORM",
"SENTIENT"
],
"movementSystems" : [
{
"type" : "GROUND",
"acceleration" : 0.001,
"maxVelocity" : 0.025
}
],
"modelPath" : "/Models/person1walkanim.fbx"
},
{
"name" : "Goblin",
"bodyParts" : [
{
"name" : "Head",
"type" : "Head"
},
{
"name" : "Torso",
"type" : "Torso"
},
{
"name" : "ArmLeft",
"type" : "Arm"
},
{
"name" : "ArmRight",
"type" : "Arm"
},
{
"name" : "LegLeft",
"type" : "Leg"
},
{
"name" : "LegRight",
"type" : "Leg"
}
],
"hitboxes" : [
{
"type": "hurt",
"bone": "Bone.031",
"radius": 0.04
},
{
"type": "hurt",
"bone": "Bone.012",
"radius": 0.04
},
{
"type": "hurt",
"bone": "Bone.003",
"radius": 0.04
},
{
"type": "hurt",
"bone": "Bone.010",
"radius": 0.06
},
{
"type": "hurt",
"bone": "Bone.001",
"radius": 0.06
},
{
"type": "hurt",
"bone": "Bone.014",
"radius": 0.06
},
{
"type": "hurt",
"bone": "Bone",
"radius": 0.08
},
{
"type": "hurt",
"bone": "Bone.014",
"radius": 0.06
},
{
"type": "hurt",
"bone": "Bone.019",
"radius": 0.04
}
],
"tokens" : [
"BLENDER_TRANSFORM",
"SENTIENT"
],
"movementSystems" : [
{
"type" : "GROUND",
"acceleration" : 0.001,
"maxVelocity" : 0.025
}
],
"modelPath" : "Models/goblin1.fbx"
}
]
}

View File

@ -1,96 +0,0 @@
{
"types": [
{
"id" : 0,
"isCreature" : true,
"isItem" : false,
"modelPath" : "/Models/person1walkanim.fbx",
"hitboxes" : [
{
"type": "hurt",
"bone": "Bone.031",
"radius": 0.04
},
{
"type": "hurt",
"bone": "Bone.012",
"radius": 0.04
},
{
"type": "hurt",
"bone": "Bone.003",
"radius": 0.04
},
{
"type": "hurt",
"bone": "Bone.010",
"radius": 0.06
},
{
"type": "hurt",
"bone": "Bone.001",
"radius": 0.06
},
{
"type": "hurt",
"bone": "Bone.014",
"radius": 0.06
},
{
"type": "hurt",
"bone": "Bone",
"radius": 0.08
},
{
"type": "hurt",
"bone": "Bone.014",
"radius": 0.06
},
{
"type": "hurt",
"bone": "Bone.019",
"radius": 0.04
}
]
},
{
"id" : 1,
"isCreature" : true,
"isItem" : false,
"modelPath" : "",
"hitboxes" : []
},
{
"id" : 2,
"isCreature" : false,
"isItem" : true,
"modelPath" : "/Models/katana1alt.fbx",
"hitboxes" : [
{
"type": "hit",
"bone": "Blade1",
"radius": 0.04
},
{
"type": "hit",
"bone": "Blade2",
"radius": 0.04
},
{
"type": "hit",
"bone": "Blade3",
"radius": 0.04
}
]
},
{
"id" : 3,
"isCreature" : true,
"isItem" : false,
"modelPath" : "Models/goblin1.fbx",
"hitboxes" : [
]
}
]
}

37
assets/Data/items.json Normal file
View File

@ -0,0 +1,37 @@
{
"items" : [
{
"name" : "Katana",
"modelPath" : "/Models/katana1alt.fbx",
"hitboxes" : [
{
"type": "hit",
"bone": "Blade1",
"radius": 0.04
},
{
"type": "hit",
"bone": "Blade2",
"radius": 0.04
},
{
"type": "hit",
"bone": "Blade3",
"radius": 0.04
}
],
"tokens" : [
"BLENDER_TRANSFORM",
"WEAPON",
"MELEE"
]
}
]
}

View File

@ -469,12 +469,12 @@ public class LoadingThread extends Thread {
// EntityUtils.getEntityRotation(tree).rotateAxis((float)-Math.PI/2.0f, new Vector3f(1,0,0));
}
Entity goblin = EntityUtils.spawnEntityFromEntityMap(3);
Entity goblin = CreatureUtils.spawnBasicCreature("Goblin");
EntityUtils.getPosition(goblin).set(5, 0, 3);
EntityUtils.getScale(goblin).set(0.005f);
Entity sword = ItemUtils.spawnBasicItem(2);
Entity testHomie = CreatureUtils.spawnBasicCreature(0, 0.1f, 0.5f);
Entity sword = ItemUtils.spawnBasicItem("Katana");
Entity testHomie = CreatureUtils.spawnBasicCreature("Human");
EntityUtils.getScale(testHomie).set(0.005f);
EntityUtils.getPosition(testHomie).set(2,0,2);
AttachUtils.attachEntityToEntityAtBone(testHomie, sword, "Bone.020");

View File

@ -7,7 +7,6 @@ package electrosphere.entity;
import electrosphere.entity.state.MovementTree;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.entity.types.creature.creaturemap.CreatureType;
import electrosphere.entity.types.item.ItemUtils;
import electrosphere.renderer.Model;
import electrosphere.main.Globals;
@ -88,21 +87,4 @@ public class EntityUtils {
return (Actor)e.getData(EntityDataStrings.DATA_STRING_ACTOR);
}
public static Entity spawnEntityFromEntityMap(int type){
Entity rVal = null;
CreatureType entityType = Globals.entityTypeMap.get(type);
if(entityType.isIsCreature()){
rVal = CreatureUtils.spawnBasicCreature(type, 0.001f, 0.05f);
}
if(entityType.isIsItem()){
rVal = ItemUtils.spawnBasicItem(type);
}
if(rVal == null){
System.err.println("ERROR!");
System.err.println("The entity you are trying to spawn (type=" + type + ") is neither a creature nor an item in the entity type map!");
System.err.println("Error occurred in spawnEntityFromEntityMap in EntityUtils");
}
return rVal;
}
}

View File

@ -4,12 +4,15 @@ import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.MovementTree;
import electrosphere.entity.types.creature.creaturemap.CreatureType;
import electrosphere.entity.types.creature.creaturemap.HitboxData;
import electrosphere.entity.types.hitbox.HitboxData;
import electrosphere.entity.types.hitbox.HitboxUtils;
import electrosphere.game.server.creature.type.CreatureType;
import electrosphere.game.server.creature.type.MovementSystem;
import electrosphere.main.Globals;
import electrosphere.main.Main;
import electrosphere.net.parser.net.message.EntityMessage;
import electrosphere.renderer.Actor;
import electrosphere.renderer.ActorUtils;
import electrosphere.renderer.Model;
import electrosphere.util.ModelLoader;
import org.joml.Quaternionf;
@ -40,8 +43,8 @@ public class CreatureUtils {
// return rVal;
// }
public static Entity spawnBasicCreature(int creatureId, float acceleration, float maxVelocity){
CreatureType rawType = Globals.entityTypeMap.get(creatureId);
public static Entity spawnBasicCreature(String type){
CreatureType rawType = Globals.creatureMap.getCreature(type);
Entity rVal = EntityUtils.spawnDrawableEntity(rawType.getModelPath());
for(HitboxData hitboxdata : rawType.getHitboxes()){
if(hitboxdata.getType().equals("hit")){
@ -50,14 +53,29 @@ public class CreatureUtils {
Globals.hitboxManager.registerHitbox(HitboxUtils.spawnRegularHurtbox(rVal, hitboxdata.getBone(), hitboxdata.getRadius()));
}
}
for(MovementSystem movementSystem : rawType.getMovementSystems()){
switch(movementSystem.getType()){
case "GROUND":
rVal.putData(EntityDataStrings.DATA_STRING_MOVEMENT_BT, new MovementTree(rVal));
rVal.putData(EntityDataStrings.DATA_STRING_MOVEMENT_VECTOR, new Vector3f(0,0,0));
rVal.putData(EntityDataStrings.DATA_STRING_MAX_NATURAL_VELOCITY, movementSystem.getMaxVelocity());
rVal.putData(EntityDataStrings.DATA_STRING_ACCELERATION, movementSystem.getAcceleration());
rVal.putData(EntityDataStrings.DATA_STRING_VELOCITY, 0f);
Globals.entityManager.registerMoveableEntity(rVal);
break;
}
}
for(String token : rawType.getTokens()){
switch(token){
case "BLENDER_TRANSFORM":
Actor entityActor = EntityUtils.getActor(rVal);
entityActor.setAnimationScalar(0.4f);
EntityUtils.getScale(rVal).set(0.005f);
break;
}
}
rVal.putData(EntityDataStrings.DATA_STRING_CREATURE_IS_CREATURE, true);
rVal.putData(EntityDataStrings.DATA_STRING_CREATURE_TYPE, creatureId);
rVal.putData(EntityDataStrings.DATA_STRING_MOVEMENT_BT, new MovementTree(rVal));
rVal.putData(EntityDataStrings.DATA_STRING_MOVEMENT_VECTOR, new Vector3f(0,0,0));
rVal.putData(EntityDataStrings.DATA_STRING_MAX_NATURAL_VELOCITY, maxVelocity);
rVal.putData(EntityDataStrings.DATA_STRING_ACCELERATION, acceleration);
rVal.putData(EntityDataStrings.DATA_STRING_VELOCITY, 0f);
Globals.entityManager.registerMoveableEntity(rVal);
rVal.putData(EntityDataStrings.DATA_STRING_CREATURE_TYPE, type);
return rVal;
}
@ -101,8 +119,8 @@ public class CreatureUtils {
getEntityMovementTree(e).addNetworkMessage(em);
}
public static int getCreatureType(Entity e){
return (int)e.getData(EntityDataStrings.DATA_STRING_CREATURE_TYPE);
public static String getType(Entity e){
return (String)e.getData(EntityDataStrings.DATA_STRING_CREATURE_TYPE);
}
public static int getControllerPlayerId(Entity e){

View File

@ -1,58 +0,0 @@
package electrosphere.entity.types.creature.creaturemap;
import java.util.List;
/**
*
* @author amaterasu
*/
public class CreatureType {
int id;
boolean isCreature;
boolean isItem;
String modelPath;
List<HitboxData> hitboxes;
public int getId() {
return id;
}
public String getModelPath() {
return modelPath;
}
public void setId(int id) {
this.id = id;
}
public void setModelPath(String modelPath) {
this.modelPath = modelPath;
}
public List<HitboxData> getHitboxes() {
return hitboxes;
}
public void setHitboxes(List<HitboxData> hitboxes) {
this.hitboxes = hitboxes;
}
public boolean isIsCreature() {
return isCreature;
}
public boolean isIsItem() {
return isItem;
}
public void setIsCreature(boolean isCreature) {
this.isCreature = isCreature;
}
public void setIsItem(boolean isItem) {
this.isItem = isItem;
}
}

View File

@ -1,16 +0,0 @@
package electrosphere.entity.types.creature.creaturemap;
import java.util.List;
/**
*
* @author amaterasu
*/
public class CreatureTypeList {
List<CreatureType> types;
public List<CreatureType> getTypes() {
return types;
}
}

View File

@ -1,9 +1,6 @@
package electrosphere.entity.types.creature.creaturemap;
package electrosphere.entity.types.hitbox;
/**
*
* @author amaterasu
*/
public class HitboxData {
String type;
String bone;

View File

@ -4,9 +4,10 @@ import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.MovementTree;
import electrosphere.entity.types.creature.creaturemap.CreatureType;
import electrosphere.entity.types.creature.creaturemap.HitboxData;
import electrosphere.entity.types.hitbox.HitboxData;
import electrosphere.entity.types.hitbox.HitboxUtils;
import electrosphere.game.server.creature.type.CreatureType;
import electrosphere.game.server.item.type.Item;
import electrosphere.main.Globals;
import electrosphere.renderer.Actor;
import electrosphere.renderer.Model;
@ -18,17 +19,25 @@ import org.joml.Vector3f;
* @author amaterasu
*/
public class ItemUtils {
public static Entity spawnBasicItem(int itemId){
CreatureType rawType = Globals.entityTypeMap.get(itemId);
Entity rVal = EntityUtils.spawnDrawableEntity(rawType.getModelPath());
for(HitboxData hitboxdata : rawType.getHitboxes()){
public static Entity spawnBasicItem(String name){
Item item = Globals.itemMap.getItem(name);
Entity rVal = EntityUtils.spawnDrawableEntity(item.getModelPath());
for(HitboxData hitboxdata : item.getHitboxes()){
Globals.hitboxManager.registerHitbox(HitboxUtils.spawnRegularHitbox(rVal, hitboxdata.getBone(), hitboxdata.getRadius()));
}
for(String token : item.getTokens()){
switch(token){
case "BLENDER_TRANSFORM":
Actor entityActor = EntityUtils.getActor(rVal);
entityActor.setAnimationScalar(0.4f);
EntityUtils.getScale(rVal).set(0.005f);
break;
}
}
rVal.putData(EntityDataStrings.ITEM_IS_ITEM, true);
rVal.putData(EntityDataStrings.ITEM_TYPE, itemId);
rVal.putData(EntityDataStrings.DATA_STRING_CREATURE_TYPE, itemId);
rVal.putData(EntityDataStrings.DATA_STRING_SCALE, new Vector3f(0.005f,0.005f,0.005f));
rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, new Quaternionf().identity().rotateY((float)(-Math.PI/2)).rotateZ(-(float)(Math.PI/2)));
rVal.putData(EntityDataStrings.ITEM_TYPE, name);
// rVal.putData(EntityDataStrings.DATA_STRING_SCALE, new Vector3f(0.005f,0.005f,0.005f));
// rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, new Quaternionf().identity().rotateY((float)(-Math.PI/2)).rotateZ(-(float)(Math.PI/2)));
Globals.entityManager.registerItemEntity(rVal);
return rVal;
}
@ -47,4 +56,8 @@ public class ItemUtils {
public static boolean isItem(Entity item){
return item.getDataKeys().contains(EntityDataStrings.ITEM_IS_ITEM);
}
public static String getType(Entity item){
return (String)item.getData(EntityDataStrings.ITEM_TYPE);
}
}

View File

@ -1,5 +1,41 @@
package electrosphere.game.server.creature.type;
import electrosphere.entity.types.hitbox.HitboxData;
import java.util.List;
public class CreatureType {
String name;
List<BodyPart> bodyParts;
List<HitboxData> hitboxes;
List<String> tokens;
List<MovementSystem> movementSystems;
String modelPath;
public String getName() {
return name;
}
public List<BodyPart> getBodyParts() {
return bodyParts;
}
public List<HitboxData> getHitboxes() {
return hitboxes;
}
public List<String> getTokens() {
return tokens;
}
public String getModelPath() {
return modelPath;
}
public List<MovementSystem> getMovementSystems() {
return movementSystems;
}
}

View File

@ -0,0 +1,21 @@
package electrosphere.game.server.creature.type;
public class MovementSystem {
String type;
float acceleration;
float maxVelocity;
public String getType() {
return type;
}
public float getAcceleration() {
return acceleration;
}
public float getMaxVelocity() {
return maxVelocity;
}
}

View File

@ -1,6 +1,21 @@
package electrosphere.game.server.creature.type.model;
import electrosphere.game.server.creature.type.CreatureType;
import java.util.List;
public class CreatureTypeMap {
List<CreatureType> creatures;
public CreatureType getCreature(String name){
CreatureType rVal = null;
for(CreatureType type : creatures){
if(type.getName().equals(name)){
rVal = type;
break;
}
}
return rVal;
}
}

View File

@ -0,0 +1,29 @@
package electrosphere.game.server.item.type;
import electrosphere.entity.types.hitbox.HitboxData;
import java.util.List;
public class Item {
String name;
String modelPath;
List<HitboxData> hitboxes;
List<String> tokens;
public String getName() {
return name;
}
public String getModelPath() {
return modelPath;
}
public List<HitboxData> getHitboxes() {
return hitboxes;
}
public List<String> getTokens() {
return tokens;
}
}

View File

@ -0,0 +1,24 @@
package electrosphere.game.server.item.type.model;
import electrosphere.game.server.item.type.Item;
import java.util.List;
public class ItemTypeMap {
List<Item> items;
public List<Item> getItems() {
return items;
}
public Item getItem(String name){
Item rVal = null;
for(Item item : items){
if(item.getName().equals(name)){
rVal = item;
break;
}
}
return rVal;
}
}

View File

@ -11,8 +11,6 @@ import electrosphere.controls.ControlHandler;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityManager;
import electrosphere.game.collision.CollisionEngine;
import electrosphere.entity.types.creature.creaturemap.CreatureType;
import electrosphere.entity.types.creature.creaturemap.CreatureTypeList;
import electrosphere.entity.types.hitbox.HitboxManager;
import electrosphere.game.client.drawcell.DrawCellManager;
import electrosphere.game.client.player.ClientPlayerData;
@ -21,6 +19,8 @@ import electrosphere.game.client.world.ClientWorldData;
import electrosphere.game.collision.CommonWorldData;
import electrosphere.entity.types.life.AliveManager;
import electrosphere.engine.LoadingThread;
import electrosphere.game.server.creature.type.model.CreatureTypeMap;
import electrosphere.game.server.item.type.model.ItemTypeMap;
import electrosphere.game.state.MacroSimulation;
import electrosphere.game.server.terrain.manager.ServerTerrainManager;
import electrosphere.game.server.world.ServerWorldData;
@ -99,12 +99,8 @@ public class Globals {
//current world
//
public static ServerWorldData serverWorldData;
//
//Entity Types Map
//
public static HashMap<Integer,CreatureType> entityTypeMap = new HashMap();
public static CreatureTypeMap creatureMap;
public static ItemTypeMap itemMap;
@ -245,8 +241,10 @@ public class Globals {
textureMapDefault = FileLoadingUtils.loadObjectFromAssetPath("Textures/default_texture_map.json", TextureMap.class);
// textureMapDefault = gson.fromJson(Files.newBufferedReader(new File(Thread.currentThread().getContextClassLoader().getResource("Textures/default_texture_map.json").getFile()).toPath()), TextureMap.class); //only the best of coding practices :)
// } catch (IOException ex) { ex.printStackTrace(); } //TODO: handle better :tm:
//entity type map
initEntityTypeMap();
//init creature type map
initCreatureTypeMap();
//init item type map
initItemTypeMap();
//create entity manager
entityManager = new EntityManager();
//temporary hold for skybox colors
@ -294,10 +292,11 @@ public class Globals {
Globals.assetManager.loadAssetsInQueue();
}
static void initEntityTypeMap(){
CreatureTypeList typeList = FileLoadingUtils.loadObjectFromAssetPath("Data/entity_map.json", CreatureTypeList.class);
for(CreatureType type : typeList.getTypes()){
entityTypeMap.put(type.getId(), type);
}
static void initCreatureTypeMap(){
creatureMap = FileLoadingUtils.loadObjectFromAssetPath("Data/creatures.json", CreatureTypeMap.class);
}
static void initItemTypeMap(){
itemMap = FileLoadingUtils.loadObjectFromAssetPath("Data/items.json", ItemTypeMap.class);
}
}

View File

@ -132,7 +132,6 @@ public class Main {
//main loop
while (running) {

View File

@ -5,6 +5,7 @@ import electrosphere.entity.EntityUtils;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.game.client.world.ClientWorldData;
import electrosphere.entity.types.attach.AttachUtils;
import electrosphere.entity.types.item.ItemUtils;
import electrosphere.logger.LoggerInterface;
import electrosphere.main.Globals;
import electrosphere.main.Main;
@ -51,11 +52,22 @@ public class ClientProtocol {
LoggerInterface.loggerNetworking.DEBUG("Parse entity message of type " + message.getMessageSubtype());
switch(message.getMessageSubtype()){
case CREATE:
LoggerInterface.loggerNetworking.DEBUG("Spawn ID " + message.getentityID() + " of type " + message.getcreatureType());
Entity newlySpawnedEntity = EntityUtils.spawnEntityFromEntityMap(message.getcreatureType());;
EntityUtils.getScale(newlySpawnedEntity).set(0.005f);
EntityUtils.getPosition(newlySpawnedEntity).set(message.getpositionX(),message.getpositionY(),message.getpositionZ());
EntityUtils.setEntityID(newlySpawnedEntity, message.getentityID());
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());
break;
case 1:
newlySpawnedEntity = ItemUtils.spawnBasicItem(message.getentitySubtype());
EntityUtils.getScale(newlySpawnedEntity).set(0.005f);
EntityUtils.getPosition(newlySpawnedEntity).set(message.getpositionX(),message.getpositionY(),message.getpositionZ());
EntityUtils.setEntityID(newlySpawnedEntity, message.getentityID());
break;
}
break;
case DESTROY:
break;

View File

@ -19,7 +19,8 @@ public class EntityMessage extends NetworkMessage {
}
EntityMessageType messageType;
int creatureType;
int entityCategory;
String entitySubtype;
int entityID;
float positionX;
float positionY;
@ -47,12 +48,20 @@ public class EntityMessage extends NetworkMessage {
return this.messageType;
}
public int getcreatureType() {
return creatureType;
public int getentityCategory() {
return entityCategory;
}
public void setcreatureType(int creatureType) {
this.creatureType = creatureType;
public void setentityCategory(int entityCategory) {
this.entityCategory = entityCategory;
}
public String getentitySubtype() {
return entitySubtype;
}
public void setentitySubtype(String entitySubtype) {
this.entitySubtype = entitySubtype;
}
public int getentityID() {
@ -199,11 +208,7 @@ public class EntityMessage extends NetworkMessage {
public static boolean canParseMessage(List<Byte> byteStream, byte secondByte){
switch(secondByte){
case TypeBytes.ENTITY_MESSAGE_TYPE_CREATE:
if(byteStream.size() >= TypeBytes.ENTITY_MESSAGE_TYPE_CREATE_SIZE){
return true;
} else {
return false;
}
return EntityMessage.canParseCreateMessage(byteStream);
case TypeBytes.ENTITY_MESSAGE_TYPE_SETPOSITION:
if(byteStream.size() >= TypeBytes.ENTITY_MESSAGE_TYPE_SETPOSITION_SIZE){
return true;
@ -252,21 +257,57 @@ public class EntityMessage extends NetworkMessage {
return false;
}
public static boolean canParseCreateMessage(List<Byte> byteStream){
int currentStreamLength = byteStream.size();
List<Byte> temporaryByteQueue = new LinkedList();
if(currentStreamLength < 6){
return false;
}
if(currentStreamLength < 10){
return false;
}
int entitySubtypeSize = 0;
if(currentStreamLength < 14){
return false;
} else {
temporaryByteQueue.add(byteStream.get(10 + 0));
temporaryByteQueue.add(byteStream.get(10 + 1));
temporaryByteQueue.add(byteStream.get(10 + 2));
temporaryByteQueue.add(byteStream.get(10 + 3));
entitySubtypeSize = ByteStreamUtils.popIntFromByteQueue(temporaryByteQueue);
}
if(currentStreamLength < 14 + entitySubtypeSize){
return false;
}
if(currentStreamLength < 14){
return false;
}
if(currentStreamLength < 18){
return false;
}
if(currentStreamLength < 22){
return false;
}
return true;
}
public static EntityMessage parseCreateMessage(List<Byte> byteStream){
EntityMessage rVal = new EntityMessage(EntityMessageType.CREATE);
stripPacketHeader(byteStream);
rVal.setentityID(ByteStreamUtils.popIntFromByteQueue(byteStream));
rVal.setcreatureType(ByteStreamUtils.popIntFromByteQueue(byteStream));
rVal.setentityCategory(ByteStreamUtils.popIntFromByteQueue(byteStream));
rVal.setentitySubtype(ByteStreamUtils.popStringFromByteQueue(byteStream));
rVal.setpositionX(ByteStreamUtils.popFloatFromByteQueue(byteStream));
rVal.setpositionY(ByteStreamUtils.popFloatFromByteQueue(byteStream));
rVal.setpositionZ(ByteStreamUtils.popFloatFromByteQueue(byteStream));
return rVal;
}
public static EntityMessage constructCreateMessage(int entityID,int creatureType,float positionX,float positionY,float positionZ){
public static EntityMessage constructCreateMessage(int entityID,int entityCategory,String entitySubtype,float positionX,float positionY,float positionZ){
EntityMessage rVal = new EntityMessage(EntityMessageType.CREATE);
rVal.setentityID(entityID);
rVal.setcreatureType(creatureType);
rVal.setentityCategory(entityCategory);
rVal.setentitySubtype(entitySubtype);
rVal.setpositionX(positionX);
rVal.setpositionY(positionY);
rVal.setpositionZ(positionZ);
@ -475,7 +516,7 @@ public class EntityMessage extends NetworkMessage {
byte[] stringBytes;
switch(this.messageType){
case CREATE:
rawBytes = new byte[2+4+4+4+4+4];
rawBytes = new byte[2+4+4+4+entitySubtype.length()+4+4+4];
//message header
rawBytes[0] = TypeBytes.MESSAGE_TYPE_ENTITY;
//entity messaage header
@ -484,19 +525,27 @@ public class EntityMessage extends NetworkMessage {
for(int i = 0; i < 4; i++){
rawBytes[2+i] = intValues[i];
}
intValues = ByteStreamUtils.serializeIntToBytes(creatureType);
intValues = ByteStreamUtils.serializeIntToBytes(entityCategory);
for(int i = 0; i < 4; i++){
rawBytes[6+i] = intValues[i];
}
intValues = ByteStreamUtils.serializeFloatToBytes(positionX);
intValues = ByteStreamUtils.serializeIntToBytes(entitySubtype.length());
for(int i = 0; i < 4; i++){
rawBytes[10+i] = intValues[i];
}
stringBytes = entitySubtype.getBytes();
for(int i = 0; i < entitySubtype.length(); i++){
rawBytes[14+i] = stringBytes[i];
}
intValues = ByteStreamUtils.serializeFloatToBytes(positionX);
for(int i = 0; i < 4; i++){
rawBytes[14+entitySubtype.length()+i] = intValues[i];
} intValues = ByteStreamUtils.serializeFloatToBytes(positionY);
for(int i = 0; i < 4; i++){
rawBytes[14+i] = intValues[i];
rawBytes[18+entitySubtype.length()+i] = intValues[i];
} intValues = ByteStreamUtils.serializeFloatToBytes(positionZ);
for(int i = 0; i < 4; i++){
rawBytes[18+i] = intValues[i];
rawBytes[22+entitySubtype.length()+i] = intValues[i];
} break;
case SETPOSITION:
rawBytes = new byte[2+4+8+4+4+4];

View File

@ -58,7 +58,6 @@ Message categories
/*
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;

View File

@ -93,13 +93,12 @@ public class ServerConnectionHandler implements Runnable {
System.exit(1);
}
//spawn player in world
Entity newPlayerCharacter = CreatureUtils.spawnBasicCreature(0, 0.001f, 0.05f);
Entity newPlayerCharacter = CreatureUtils.spawnBasicCreature("Goblin");
playerCharacterID = newPlayerCharacter.getId();
EntityUtils.getScale(newPlayerCharacter).set(0.005f);
EntityUtils.getPosition(newPlayerCharacter).set(Globals.spawnPoint.x,0,Globals.spawnPoint.z);
//spawn player sword
Entity sword = ItemUtils.spawnBasicItem(2);
AttachUtils.attachEntityToEntityAtBone(newPlayerCharacter, sword, "Bone.020");
// Entity sword = ItemUtils.spawnBasicItem("Katana");
// AttachUtils.attachEntityToEntityAtBone(newPlayerCharacter, sword, "Bone.020");
//set controller id
CreatureUtils.setControllerPlayerId(newPlayerCharacter, playerID);
if(Globals.RUN_SERVER && Main.playerId == -1){
@ -140,7 +139,8 @@ public class ServerConnectionHandler implements Runnable {
networkParser.addOutgoingMessage(
EntityMessage.constructCreateMessage(
currentEntity.getId(),
CreatureUtils.getCreatureType(currentEntity),
0, //0 for creatures
CreatureUtils.getType(currentEntity),
EntityUtils.getPosition(currentEntity).x,
EntityUtils.getPosition(currentEntity).y,
EntityUtils.getPosition(currentEntity).z
@ -157,7 +157,8 @@ public class ServerConnectionHandler implements Runnable {
networkParser.addOutgoingMessage(
EntityMessage.constructCreateMessage(
currentEntity.getId(),
CreatureUtils.getCreatureType(currentEntity),
1, //1 for items
ItemUtils.getType(currentEntity),
EntityUtils.getPosition(currentEntity).x,
EntityUtils.getPosition(currentEntity).y,
EntityUtils.getPosition(currentEntity).z

View File

@ -15,6 +15,7 @@ public class Actor {
String animation;
double animationTime;
boolean playingAnimation;
float animationScalar = 1.0f;
public Actor(String modelPath){
playingAnimation = false;
@ -24,7 +25,7 @@ public class Actor {
public void incrementAnimationTime(double deltaTime){
Model model = Globals.assetManager.fetchModel(modelPath);
if(playingAnimation){
animationTime = animationTime + deltaTime;
animationTime = animationTime + deltaTime * animationScalar;
}
if(model != null){
if(animation != null){
@ -54,6 +55,10 @@ public class Actor {
public boolean isPlayingAnimation(){
return playingAnimation;
}
public void setAnimationScalar(float animationScalar) {
this.animationScalar = animationScalar;
}
public void applyModelMatrix(Matrix4f modelMatrix){
Model model = Globals.assetManager.fetchModel(modelPath);

View File

@ -14,4 +14,10 @@ public class ActorUtils {
Globals.assetManager.addModelPathToQueue(modelPath);
return rVal;
}
public static void applyBlenderTransformer(Actor a){
}
}

View File

@ -276,9 +276,13 @@
"categoryName" : "Entity",
"data" : [
{
"name" : "creatureType",
"name" : "entityCategory",
"type" : "FIXED_INT"
},
{
"name" : "entitySubtype",
"type" : "VAR_STRING"
},
{
"name" : "entityID",
"type" : "FIXED_INT"
@ -353,7 +357,8 @@
"messageName" : "Create",
"data" : [
"entityID",
"creatureType",
"entityCategory",
"entitySubtype",
"positionX",
"positionY",
"positionZ"