Add foliage!
This commit is contained in:
parent
3a1924f8f4
commit
952f9e30a0
23
assets/Data/foliage.json
Normal file
23
assets/Data/foliage.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"foliageList" : [
|
||||
{
|
||||
"name" : "FallOak1",
|
||||
"tokens" : [
|
||||
"BLENDER_ROTATION"
|
||||
],
|
||||
"physicsObjects" : [
|
||||
{
|
||||
"type" : "CYLINDER",
|
||||
"dimension1" : 0.1,
|
||||
"dimension2" : 0.45,
|
||||
"dimension3" : 0.1,
|
||||
"offsetX" : 0,
|
||||
"offsetY" : 0.45,
|
||||
"offsetZ" : 0
|
||||
}
|
||||
],
|
||||
"modelPath" : "Models/falloak1.fbx"
|
||||
}
|
||||
|
||||
]
|
||||
}
|
||||
@ -19,6 +19,7 @@ import electrosphere.game.server.world.ServerWorldData;
|
||||
import electrosphere.entity.types.attach.AttachUtils;
|
||||
import electrosphere.entity.types.particle.ParticleUtils;
|
||||
import electrosphere.entity.types.collision.CollisionObjUtils;
|
||||
import electrosphere.entity.types.foliage.FoliageUtils;
|
||||
import electrosphere.entity.types.structure.StructureUtils;
|
||||
import electrosphere.game.collision.PhysicsUtils;
|
||||
import electrosphere.game.collision.collidable.Collidable;
|
||||
@ -345,7 +346,8 @@ public class LoadingThread extends Thread {
|
||||
Vector2i townLoc = Town.findValidTownLocation();
|
||||
if(townLoc != null){
|
||||
int chunkSize = Globals.serverTerrainManager.getChunkWidth();
|
||||
Globals.spawnPoint = new Vector3f((townLoc.x - 3) * chunkSize, Globals.serverTerrainManager.getHeightAtPosition(townLoc.x * chunkSize,townLoc.y * chunkSize), townLoc.y * chunkSize);
|
||||
Globals.spawnPoint = new Vector3f(townLoc.x * chunkSize, Globals.serverTerrainManager.getHeightAtPosition(townLoc.x * chunkSize,townLoc.y * chunkSize), townLoc.y * chunkSize);
|
||||
// System.out.println("Setting spawn point @ " + Globals.spawnPoint);
|
||||
Town.createTown(townLoc.x,townLoc.y);
|
||||
}
|
||||
}
|
||||
@ -522,14 +524,14 @@ public class LoadingThread extends Thread {
|
||||
//// EntityUtils.getEntityRotation(tree).rotateAxis((float)-Math.PI/2.0f, new Vector3f(1,0,0));
|
||||
// }
|
||||
|
||||
for(int i = 0; i < 250; i++){
|
||||
Random rand = new Random();
|
||||
String treePath = "Models/falloak1.fbx";
|
||||
Entity tree = EntityUtils.spawnDrawableEntity(treePath);
|
||||
EntityUtils.getPosition(tree).set(rand.nextFloat() * 105 + 1, 0, rand.nextFloat() * 105 + 1);
|
||||
EntityUtils.getRotation(tree).rotateLocalX(-(float)Math.PI/2.0f).rotateZ(rand.nextFloat());
|
||||
// EntityUtils.getEntityRotation(tree).rotateAxis((float)-Math.PI/2.0f, new Vector3f(1,0,0));
|
||||
}
|
||||
// for(int i = 0; i < 250; i++){
|
||||
// Random rand = new Random();
|
||||
// String treePath = "Models/falloak1.fbx";
|
||||
// Entity tree = EntityUtils.spawnDrawableEntity(treePath);
|
||||
// EntityUtils.getPosition(tree).set(rand.nextFloat() * 105 + 1, 0, rand.nextFloat() * 105 + 1);
|
||||
// EntityUtils.getRotation(tree).rotateLocalX(-(float)Math.PI/2.0f).rotateZ(rand.nextFloat());
|
||||
//// EntityUtils.getEntityRotation(tree).rotateAxis((float)-Math.PI/2.0f, new Vector3f(1,0,0));
|
||||
// }
|
||||
|
||||
// Random rand = new Random();
|
||||
// for(int i = 0; i < 1000; i++){
|
||||
@ -548,14 +550,18 @@ public class LoadingThread extends Thread {
|
||||
// ActorUtils.applyBlenderTransformer(building);
|
||||
|
||||
//spawn evil goblin
|
||||
Entity goblin = CreatureUtils.spawnBasicCreature("Goblin");
|
||||
CreatureUtils.positionCharacter(goblin, new Vector3f(30, 0, 30));
|
||||
EntityUtils.getScale(goblin).set(0.005f);
|
||||
//give evil goblin sword
|
||||
Entity goblinSword = ItemUtils.spawnBasicItem("Katana");
|
||||
AttachUtils.attachEntityToEntityAtBone(goblin, goblinSword, "Bone.031");
|
||||
//attach ai to evil goblin
|
||||
MindlessAttacker.attachToCreature(goblin);
|
||||
// Entity goblin = CreatureUtils.spawnBasicCreature("Goblin");
|
||||
// CollisionObjUtils.positionCharacter(goblin, new Vector3f(30, 0, 30));
|
||||
// EntityUtils.getScale(goblin).set(0.005f);
|
||||
// //give evil goblin sword
|
||||
// Entity goblinSword = ItemUtils.spawnBasicItem("Katana");
|
||||
// AttachUtils.attachEntityToEntityAtBone(goblin, goblinSword, "Bone.031");
|
||||
// //attach ai to evil goblin
|
||||
// MindlessAttacker.attachToCreature(goblin);
|
||||
|
||||
Entity fallOak = FoliageUtils.spawnBasicFoliage("FallOak1");
|
||||
EntityUtils.getPosition(fallOak).set(1,0,3);
|
||||
// CollisionObjUtils.positionCharacter(fallOak, new Vector3f(1, 0, 3));
|
||||
//
|
||||
//
|
||||
// Entity testHomie = CreatureUtils.spawnBasicCreature("Human");
|
||||
|
||||
@ -104,6 +104,7 @@ public class EntityDataStrings {
|
||||
|
||||
public static final String COLLISION_ENTITY_TYPE_PLANE = "collisionTypePlane";
|
||||
public static final String COLLISION_ENTITY_TYPE_CUBE = "collisionTypeCube";
|
||||
public static final String COLLISION_ENTITY_TYPE_CYLINDER = "collisionTypeCylinder";
|
||||
|
||||
|
||||
public static final String COLLISION_ENTITY_DATA_TYPE_HIT = "collisionDataTypeHit";
|
||||
@ -162,7 +163,11 @@ public class EntityDataStrings {
|
||||
public static final String STRUCTURE_IS_STRUCTURE = "structureIsStructure";
|
||||
public static final String STRUCTURE_TYPE = "structureType";
|
||||
|
||||
|
||||
/*
|
||||
Foliage entity
|
||||
*/
|
||||
public static final String FOLIAGE_IS_FOLIAGE = "foliageIsFoliage";
|
||||
public static final String FOLIAGE_TYPE = "foliageType";
|
||||
|
||||
/*
|
||||
Entity categories
|
||||
|
||||
@ -54,19 +54,19 @@ public class IdleTree {
|
||||
}
|
||||
|
||||
public void simulate(){
|
||||
float velocity = CreatureUtils.getVelocity(parent);
|
||||
float acceleration = CreatureUtils.getAcceleration(parent);
|
||||
float maxNaturalVelocity = CreatureUtils.getMaxNaturalVelocity(parent);
|
||||
Actor entityActor = EntityUtils.getActor(parent);
|
||||
Vector3f position = EntityUtils.getPosition(parent);
|
||||
Vector3f movementVector = CreatureUtils.getMovementVector(parent);
|
||||
Vector3f newPosition;
|
||||
|
||||
boolean hasMovementTree = parent.getDataKeys().contains(EntityDataStrings.DATA_STRING_MOVEMENT_BT);
|
||||
MovementTree movementTree = CreatureUtils.getEntityMovementTree(parent);
|
||||
MovementTree movementTree = null;
|
||||
if(hasMovementTree){
|
||||
movementTree = CreatureUtils.getEntityMovementTree(parent);
|
||||
}
|
||||
|
||||
boolean hasAttackTree = parent.getDataKeys().contains(EntityDataStrings.ATTACK_TREE);
|
||||
AttackTree attackTree = CreatureUtils.getAttackTree(parent);
|
||||
AttackTree attackTree = null;
|
||||
if(hasAttackTree){
|
||||
attackTree = CreatureUtils.getAttackTree(parent);
|
||||
}
|
||||
|
||||
//parse attached network messages
|
||||
for(EntityMessage message : networkMessageQueue){
|
||||
|
||||
@ -4,6 +4,7 @@ import electrosphere.collision.dispatch.CollisionObject;
|
||||
import electrosphere.collision.shapes.CylinderShape;
|
||||
import electrosphere.entity.Entity;
|
||||
import electrosphere.entity.EntityDataStrings;
|
||||
import electrosphere.entity.EntityUtils;
|
||||
import electrosphere.entity.types.attach.AttachUtils;
|
||||
import electrosphere.game.collision.PhysicsUtils;
|
||||
import electrosphere.game.collision.collidable.Collidable;
|
||||
@ -66,6 +67,30 @@ public class CollisionObjUtils {
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static Entity spawnCollisionCylinder(Vector3f scale, Vector3f position, Quaternionf rotation){
|
||||
Entity rVal = new Entity();
|
||||
|
||||
CollisionObject cubeObject = PhysicsUtils.getCylinderObject(scale);
|
||||
javax.vecmath.Matrix4f planeTransform = new javax.vecmath.Matrix4f(
|
||||
PhysicsUtils.jomlToVecmathQuaternionf(rotation),
|
||||
PhysicsUtils.jomlToVecmathVector3f(position),
|
||||
1.0f);
|
||||
cubeObject.setWorldTransform(new electrosphere.linearmath.Transform(planeTransform));
|
||||
Collidable collidable = new Collidable(rVal, Collidable.TYPE_STRUCTURE);
|
||||
Globals.collisionEngine.registerCollisionObject(cubeObject, collidable);
|
||||
Globals.collisionEngine.registerStructurePhysicsEntity(rVal);
|
||||
|
||||
rVal.putData(EntityDataStrings.COLLISION_ENTITY_TYPE_CYLINDER, true);
|
||||
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, position);
|
||||
rVal.putData(EntityDataStrings.DATA_STRING_ROTATION, rotation);
|
||||
rVal.putData(EntityDataStrings.DATA_STRING_SCALE, scale);
|
||||
rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLISION_OBJECT, cubeObject);
|
||||
rVal.putData(EntityDataStrings.COLLISION_ENTITY_COLLIDABLE, collidable);
|
||||
|
||||
Globals.entityManager.registerEntity(rVal);
|
||||
return rVal;
|
||||
}
|
||||
|
||||
|
||||
public static Entity attachCollisionPlane(Vector3f scale, Vector3f position, Quaternionf rotation, Entity parent){
|
||||
Entity rVal = spawnCollisionPlane(scale, position, rotation);
|
||||
@ -83,5 +108,23 @@ public class CollisionObjUtils {
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static Entity attachCollisionCylinder(Vector3f scale, Vector3f position, Quaternionf rotation, Entity parent){
|
||||
Entity rVal = spawnCollisionCylinder(scale, position, rotation);
|
||||
|
||||
AttachUtils.attachEntityToEntity(parent, rVal);
|
||||
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public static CollisionObject getCollisionBody(Entity e){
|
||||
return (CollisionObject)e.getData(EntityDataStrings.PHYSICS_COLLISION_BODY);
|
||||
}
|
||||
|
||||
public static void positionCharacter(Entity e, Vector3f position){
|
||||
EntityUtils.getPosition(e).set(position);
|
||||
Quaternionf rotation = EntityUtils.getRotation(e);
|
||||
CollisionObject body = getCollisionBody(e);
|
||||
PhysicsUtils.setRigidBodyTransform(position, rotation, body);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -83,7 +83,7 @@ public class CreatureUtils {
|
||||
PhysicsObject physicsTemplate = rawType.getPhysicsObject();
|
||||
switch(physicsTemplate.getType()){
|
||||
case "CYLINDER":
|
||||
CollisionObject rigidBody = PhysicsUtils.getCylinderBody(1f, new Vector3f(physicsTemplate.getDimension1(),physicsTemplate.getDimension2(),physicsTemplate.getDimension3()));
|
||||
CollisionObject rigidBody = PhysicsUtils.getCylinderObject(new Vector3f(physicsTemplate.getDimension1(),physicsTemplate.getDimension2(),physicsTemplate.getDimension3()));
|
||||
Collidable collidable = new Collidable(rVal, Collidable.TYPE_CREATURE);
|
||||
rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY, rigidBody);
|
||||
rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY_OFFSET, new Vector3f(physicsTemplate.getOffsetX(),physicsTemplate.getOffsetY(),physicsTemplate.getOffsetZ()));
|
||||
@ -228,14 +228,7 @@ public class CreatureUtils {
|
||||
return (IdleTree)e.getData(EntityDataStrings.IDLE_TREE);
|
||||
}
|
||||
|
||||
public static CollisionObject getCreatureRigidBody(Entity e){
|
||||
return (CollisionObject)e.getData(EntityDataStrings.PHYSICS_COLLISION_BODY);
|
||||
}
|
||||
|
||||
public static void positionCharacter(Entity e, Vector3f position){
|
||||
EntityUtils.getPosition(e).set(position);
|
||||
Quaternionf rotation = EntityUtils.getRotation(e);
|
||||
CollisionObject body = getCreatureRigidBody(e);
|
||||
PhysicsUtils.setRigidBodyTransform(position, rotation, body);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,64 @@
|
||||
package electrosphere.entity.types.foliage;
|
||||
|
||||
import electrosphere.collision.dispatch.CollisionObject;
|
||||
import electrosphere.entity.Entity;
|
||||
import electrosphere.entity.EntityDataStrings;
|
||||
import electrosphere.entity.EntityUtils;
|
||||
import electrosphere.entity.state.IdleTree;
|
||||
import electrosphere.entity.types.collision.CollisionObjUtils;
|
||||
import electrosphere.game.collision.PhysicsUtils;
|
||||
import electrosphere.game.collision.collidable.Collidable;
|
||||
import electrosphere.game.config.foliage.type.FoliageType;
|
||||
import electrosphere.game.config.foliage.type.PhysicsObject;
|
||||
import electrosphere.main.Globals;
|
||||
import electrosphere.renderer.ActorUtils;
|
||||
import java.util.List;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
import org.joml.Vector4f;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author amaterasu
|
||||
*/
|
||||
public class FoliageUtils {
|
||||
|
||||
|
||||
public static Entity spawnBasicFoliage(String type){
|
||||
FoliageType rawType = Globals.gameConfigCurrent.getFoliageMap().getFoliage(type);
|
||||
Entity rVal = EntityUtils.spawnDrawableEntity(rawType.getModelPath());
|
||||
// if(rawType.getPhysicsObjects() != null){
|
||||
// List<PhysicsObject> physicsObjects = rawType.getPhysicsObjects();
|
||||
// for(PhysicsObject physicsTemplate : physicsObjects){
|
||||
// switch(physicsTemplate.getType()){
|
||||
// case "CYLINDER":
|
||||
//// Matrix4f rotationTransform = new Matrix4f().rotate(rotation);
|
||||
//// Vector4f rotatedPosition = rotationTransform.transform(new Vector4f(physicsTemplate.(),physicsTemplate.getPositionY(),physicsTemplate.getPositionZ(),1.0f));
|
||||
//// Vector3f cubePosition = new Vector3f(position).add(rotatedPosition.x,rotatedPosition.y,rotatedPosition.z);
|
||||
//// Quaternionf cubeRotation = new Quaternionf(rotation).mul(new Quaternionf(physicsTemplate.getRotationX(),template.getRotationY(),physicsTemplate.getRotationZ(),physicsTemplate.getRotationW())).normalize();
|
||||
// CollisionObjUtils.attachCollisionCube(new Vector3f(1,1,1), position, rotation, rVal);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
for(String token : rawType.getTokens()){
|
||||
switch(token){
|
||||
case "BLENDER_TRANSFORM":
|
||||
ActorUtils.applyBlenderTransformer(rVal);
|
||||
break;
|
||||
case "BLENDER_ROTATION":
|
||||
ActorUtils.applyBlenderRotation(rVal);
|
||||
break;
|
||||
}
|
||||
}
|
||||
//idle tree & generic stuff all creatures have
|
||||
// rVal.putData(EntityDataStrings.IDLE_TREE, new IdleTree(rVal));
|
||||
// Globals.entityManager.registerCreatureEntity(rVal);
|
||||
rVal.putData(EntityDataStrings.FOLIAGE_IS_FOLIAGE, true);
|
||||
rVal.putData(EntityDataStrings.FOLIAGE_TYPE, type);
|
||||
return rVal;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -306,15 +306,10 @@ public class PhysicsUtils {
|
||||
// return cylinderRigidBody;
|
||||
// }
|
||||
|
||||
public static CollisionObject getCylinderBody(float mass, Vector3f dimensions){
|
||||
public static CollisionObject getCylinderObject(Vector3f dimensions){
|
||||
CylinderShape cylinderShape = new CylinderShape(jomlToVecmathVector3f(dimensions));
|
||||
// DefaultMotionState defaultMotionState = new DefaultMotionState(new Transform(new javax.vecmath.Matrix4f(new javax.vecmath.Quat4f(0,1,0,1),new javax.vecmath.Vector3f(0,0,0),1.0f)));
|
||||
// RigidBodyConstructionInfo cylinderRigidBodyCI = new RigidBodyConstructionInfo(mass, defaultMotionState, cylinderShape);
|
||||
// RigidBody cylinderRigidBody = new RigidBody(cylinderRigidBodyCI);
|
||||
CollisionObject cylinderCollisionObject = new CollisionObject();
|
||||
cylinderCollisionObject.setCollisionShape(cylinderShape);
|
||||
// cylinderRigidBody.setAngularFactor(1.0f);
|
||||
// cylinderRigidBody.setFriction(0.8f);
|
||||
return cylinderCollisionObject;
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package electrosphere.game.config;
|
||||
|
||||
import electrosphere.game.config.creature.type.model.CreatureTypeMap;
|
||||
import electrosphere.game.config.foliage.type.model.FoliageTypeMap;
|
||||
import electrosphere.game.config.item.type.model.ItemTypeMap;
|
||||
import electrosphere.game.config.structure.type.model.StructureTypeMap;
|
||||
import electrosphere.util.FileLoadingUtils;
|
||||
@ -14,12 +15,14 @@ public class Config {
|
||||
CreatureTypeMap creatureMap;
|
||||
StructureTypeMap structureTypeMap;
|
||||
ItemTypeMap itemMap;
|
||||
FoliageTypeMap foliageMap;
|
||||
|
||||
public static Config loadDefaultConfig(){
|
||||
Config config = new Config();
|
||||
config.creatureMap = FileLoadingUtils.loadObjectFromAssetPath("Data/creatures.json", CreatureTypeMap.class);
|
||||
config.itemMap = FileLoadingUtils.loadObjectFromAssetPath("Data/items.json", ItemTypeMap.class);
|
||||
config.structureTypeMap = FileLoadingUtils.loadObjectFromAssetPath("Data/structures.json", StructureTypeMap.class);
|
||||
config.foliageMap = FileLoadingUtils.loadObjectFromAssetPath("Data/foliage.json", FoliageTypeMap.class);
|
||||
return config;
|
||||
}
|
||||
|
||||
@ -34,5 +37,9 @@ public class Config {
|
||||
public ItemTypeMap getItemMap() {
|
||||
return itemMap;
|
||||
}
|
||||
|
||||
public FoliageTypeMap getFoliageMap() {
|
||||
return foliageMap;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,32 @@
|
||||
package electrosphere.game.config.foliage.type;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author amaterasu
|
||||
*/
|
||||
public class FoliageType {
|
||||
|
||||
String name;
|
||||
String modelPath;
|
||||
List<PhysicsObject> physicsObjects;
|
||||
List<String> tokens;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getModelPath() {
|
||||
return modelPath;
|
||||
}
|
||||
|
||||
public List<PhysicsObject> getPhysicsObjects() {
|
||||
return physicsObjects;
|
||||
}
|
||||
|
||||
public List<String> getTokens() {
|
||||
return tokens;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,51 @@
|
||||
package electrosphere.game.config.foliage.type;
|
||||
|
||||
import electrosphere.game.config.creature.type.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author amaterasu
|
||||
*/
|
||||
public class PhysicsObject {
|
||||
|
||||
String type;
|
||||
|
||||
float dimension1;
|
||||
float dimension2;
|
||||
float dimension3;
|
||||
|
||||
float offsetX;
|
||||
float offsetY;
|
||||
float offsetZ;
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public float getDimension1() {
|
||||
return dimension1;
|
||||
}
|
||||
|
||||
public float getDimension2() {
|
||||
return dimension2;
|
||||
}
|
||||
|
||||
public float getDimension3() {
|
||||
return dimension3;
|
||||
}
|
||||
|
||||
public float getOffsetX() {
|
||||
return offsetX;
|
||||
}
|
||||
|
||||
public float getOffsetY() {
|
||||
return offsetY;
|
||||
}
|
||||
|
||||
public float getOffsetZ() {
|
||||
return offsetZ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
package electrosphere.game.config.foliage.type.model;
|
||||
|
||||
import electrosphere.game.config.foliage.type.FoliageType;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author amaterasu
|
||||
*/
|
||||
public class FoliageTypeMap {
|
||||
|
||||
List<FoliageType> foliageList;
|
||||
|
||||
public List<FoliageType> getFoliageList() {
|
||||
return foliageList;
|
||||
}
|
||||
|
||||
public FoliageType getFoliage(String name){
|
||||
for(FoliageType foliage : foliageList){
|
||||
if(foliage.getName().matches(name)){
|
||||
return foliage;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@ -317,4 +317,8 @@ public class ServerTerrainManager {
|
||||
}
|
||||
}
|
||||
|
||||
public long getRandomizerAtPoint(int worldX, int worldY){
|
||||
return model.getRad5RandomizerValuesAtPosition(worldX, worldY)[2][2];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -42,6 +42,7 @@ public class ServerWorldData {
|
||||
int worldSizeDiscrete;
|
||||
int dynamicInterpolationRatio;
|
||||
float randomDampener;
|
||||
boolean isArena = false;
|
||||
|
||||
public static ServerWorldData createArenaWorld(){
|
||||
ServerWorldData rVal = new ServerWorldData();
|
||||
@ -51,6 +52,7 @@ public class ServerWorldData {
|
||||
rVal.dynamicInterpolationRatio = 100;
|
||||
rVal.worldSizeDiscrete = 2;
|
||||
rVal.randomDampener = 0.0f;
|
||||
rVal.isArena = true;
|
||||
return rVal;
|
||||
}
|
||||
|
||||
@ -97,6 +99,10 @@ public class ServerWorldData {
|
||||
public float getRelativeLocation(float real, int world){
|
||||
return real - (world * dynamicInterpolationRatio);
|
||||
}
|
||||
|
||||
public boolean isArena() {
|
||||
return isArena;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -4,6 +4,7 @@ import electrosphere.entity.Entity;
|
||||
import electrosphere.entity.EntityUtils;
|
||||
import electrosphere.game.collision.CommonWorldData;
|
||||
import electrosphere.game.server.world.ServerWorldData;
|
||||
import electrosphere.logger.LoggerInterface;
|
||||
import electrosphere.main.Globals;
|
||||
import electrosphere.net.parser.net.message.NetworkMessage;
|
||||
import electrosphere.net.server.Player;
|
||||
@ -40,12 +41,12 @@ public class DataCellManager {
|
||||
x >= 0 && x < discreteWorldSize &&
|
||||
y >= 0 && y < discreteWorldSize
|
||||
){
|
||||
System.out.println("Add player to " + x + " " + y);
|
||||
LoggerInterface.loggerEngine.DEBUG("DataCellManager: Add player to " + x + " " + y);
|
||||
if(dataCells[x][y] != null){
|
||||
dataCells[x][y].addPlayer(player);
|
||||
} else {
|
||||
//create data cell
|
||||
dataCells[x][y] = new ServerDataCell();
|
||||
dataCells[x][y] = ServerDataCell.loadCellAtWorldCoord(x, y);
|
||||
//add player
|
||||
dataCells[x][y].addPlayer(player);
|
||||
}
|
||||
@ -91,7 +92,7 @@ public class DataCellManager {
|
||||
dataCells[x][y].addPlayer(player);
|
||||
} else {
|
||||
//create data cell
|
||||
dataCells[x][y] = new ServerDataCell();
|
||||
dataCells[x][y] = ServerDataCell.loadCellAtWorldCoord(x, y);
|
||||
//add player
|
||||
dataCells[x][y].addPlayer(player);
|
||||
}
|
||||
|
||||
@ -0,0 +1,34 @@
|
||||
package electrosphere.game.server.world.datacell;
|
||||
|
||||
import electrosphere.entity.Entity;
|
||||
import electrosphere.entity.EntityUtils;
|
||||
import electrosphere.entity.types.collision.CollisionObjUtils;
|
||||
import electrosphere.entity.types.foliage.FoliageUtils;
|
||||
import electrosphere.main.Globals;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author amaterasu
|
||||
*/
|
||||
public class EnvironmentGenerator {
|
||||
|
||||
|
||||
public static void generatePlains(List<Entity> entityList, int worldX, int worldY, long randomizer){
|
||||
Random rand = new Random(randomizer);
|
||||
int targetNum = (int)(rand.nextFloat() * 10) + 10;
|
||||
for(int i = 0; i < targetNum; i++){
|
||||
Entity newTree = FoliageUtils.spawnBasicFoliage("FallOak1");
|
||||
entityList.add(newTree);
|
||||
float posX = worldX * Globals.serverWorldData.getDynamicInterpolationRatio() + (float)(rand.nextFloat() * Globals.serverWorldData.getDynamicInterpolationRatio());
|
||||
float posZ = worldY * Globals.serverWorldData.getDynamicInterpolationRatio() + (float)(rand.nextFloat() * Globals.serverWorldData.getDynamicInterpolationRatio());
|
||||
float posY = Globals.serverTerrainManager.getHeightAtPosition(posX, posZ);
|
||||
// System.out.println("Spawning tree at: " + posX + "," + posY + "," + posZ);
|
||||
// CollisionObjUtils.positionCharacter(newTree, new Vector3f(posX,posY,posZ));
|
||||
EntityUtils.getPosition(newTree).set(posX,posY,posZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6,7 +6,6 @@ import electrosphere.entity.types.item.ItemUtils;
|
||||
import electrosphere.entity.types.structure.StructureUtils;
|
||||
import electrosphere.net.server.Player;
|
||||
import electrosphere.game.server.character.Character;
|
||||
import electrosphere.game.server.world.virtualcell.VirtualCell;
|
||||
import electrosphere.main.Globals;
|
||||
import electrosphere.net.parser.net.message.NetworkMessage;
|
||||
import java.util.LinkedList;
|
||||
@ -30,10 +29,21 @@ public class ServerDataCell {
|
||||
* first comes into range of the cell.
|
||||
* @param virtualCell
|
||||
*/
|
||||
public ServerDataCell(){
|
||||
ServerDataCell(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static ServerDataCell loadCellAtWorldCoord(int worldX, int worldY){
|
||||
ServerDataCell rVal = new ServerDataCell();
|
||||
if(!Globals.serverWorldData.isArena()){ //in other words, if not arena mode
|
||||
//if on disk (has already been generated)
|
||||
//else create from scratch
|
||||
EnvironmentGenerator.generatePlains(rVal.loadedEntities, worldX, worldY, Globals.serverTerrainManager.getRandomizerAtPoint(worldX, worldY));
|
||||
}
|
||||
return rVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a player to the current datacell. This should be done if a player moves
|
||||
* into close enough proximity with the cell that they are concerned with
|
||||
|
||||
@ -1,31 +0,0 @@
|
||||
package electrosphere.game.server.world.virtualcell;
|
||||
|
||||
import java.util.List;
|
||||
import electrosphere.game.server.character.Character;
|
||||
import java.util.LinkedList;
|
||||
|
||||
/**
|
||||
* Container of virtual character data related to a position. The intention isn't
|
||||
* to have it perform simulation itself.
|
||||
*/
|
||||
public class VirtualCell {
|
||||
|
||||
List<Character> characterList = new LinkedList();
|
||||
|
||||
|
||||
public void addCharacter(Character c){
|
||||
if(!characterList.contains(c)){
|
||||
characterList.add(c);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeCharacter(Character c){
|
||||
characterList.remove(c);
|
||||
}
|
||||
|
||||
public List<Character> getCharacters(){
|
||||
return characterList;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,15 +0,0 @@
|
||||
package electrosphere.game.server.world.virtualcell;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author amaterasu
|
||||
*/
|
||||
public class VirtualCellManager {
|
||||
|
||||
VirtualCell[][] virtualCells;
|
||||
|
||||
public VirtualCellManager() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -29,7 +29,6 @@ import electrosphere.game.server.terrain.manager.ServerTerrainManager;
|
||||
import electrosphere.game.server.town.Town;
|
||||
import electrosphere.game.server.world.ServerWorldData;
|
||||
import electrosphere.game.server.world.datacell.DataCellManager;
|
||||
import electrosphere.game.server.world.virtualcell.VirtualCellManager;
|
||||
import electrosphere.game.state.MicroSimulation;
|
||||
import electrosphere.menu.Menu;
|
||||
import electrosphere.net.client.ClientNetworking;
|
||||
@ -114,7 +113,6 @@ public class Globals {
|
||||
//current world
|
||||
//
|
||||
public static ServerWorldData serverWorldData;
|
||||
public static VirtualCellManager virtualCellManager;
|
||||
public static DataCellManager dataCellManager;
|
||||
|
||||
//
|
||||
|
||||
@ -5,6 +5,7 @@ import electrosphere.entity.Entity;
|
||||
import electrosphere.entity.EntityUtils;
|
||||
import electrosphere.entity.types.item.ItemUtils;
|
||||
import electrosphere.entity.types.attach.AttachUtils;
|
||||
import electrosphere.entity.types.collision.CollisionObjUtils;
|
||||
import electrosphere.logger.LoggerInterface;
|
||||
import electrosphere.main.Globals;
|
||||
import electrosphere.main.Main;
|
||||
@ -98,7 +99,7 @@ public class ServerConnectionHandler implements Runnable {
|
||||
//spawn player in world
|
||||
Entity newPlayerCharacter = CreatureUtils.spawnBasicCreature("Human");
|
||||
playerCharacterID = newPlayerCharacter.getId();
|
||||
CreatureUtils.positionCharacter(newPlayerCharacter, new Vector3f(Globals.spawnPoint.x,Globals.spawnPoint.y,Globals.spawnPoint.z));
|
||||
CollisionObjUtils.positionCharacter(newPlayerCharacter, new Vector3f(Globals.spawnPoint.x,Globals.spawnPoint.y,Globals.spawnPoint.z));
|
||||
//attach player object to player character
|
||||
newPlayerObject.setPlayerEntity(newPlayerCharacter);
|
||||
newPlayerObject.setWorldX(Globals.serverWorldData.convertRealToChunkSpace(Globals.spawnPoint.x));
|
||||
|
||||
@ -23,5 +23,9 @@ public class ActorUtils {
|
||||
EntityUtils.getScale(actorEntity).set(0.005f);
|
||||
}
|
||||
|
||||
public static void applyBlenderRotation(Entity actorEntity){
|
||||
EntityUtils.getRotation(actorEntity).rotateLocalX((float)-Math.PI/2);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user