Part 1 of entitymanager->scene refactor

This commit is contained in:
austin 2023-04-06 23:19:01 -04:00
parent a895289eb2
commit 5574d9caed
54 changed files with 648 additions and 467 deletions

View File

@ -19,7 +19,7 @@ import electrosphere.controls.MouseCallback;
import electrosphere.engine.assetmanager.AssetDataStrings;
import electrosphere.engine.assetmanager.AssetManager;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityManager;
import electrosphere.entity.Scene;
import electrosphere.entity.types.hitbox.HitboxManager;
import electrosphere.game.client.cells.DrawCellManager;
import electrosphere.game.client.player.ClientPlayerData;
@ -229,7 +229,7 @@ public class Globals {
//Engine - Main managers/variables
//
//keeps track of all entities in game
public static EntityManager entityManager;
public static Scene entityManager;
//terrain manager
// public static boolean LOAD_TERRAIN = true;
@ -336,7 +336,7 @@ public class Globals {
shaderOptionMap = FileUtils.loadObjectFromAssetPath("Shaders/shaderoptions.json", ShaderOptionMap.class);
shaderOptionMap.debug();
//create entity manager
entityManager = new EntityManager();
entityManager = new Scene();
//temporary hold for skybox colors
skyboxColors = new ArrayList<Vector3f>();
//load asset manager

View File

@ -15,6 +15,7 @@ import electrosphere.auth.AuthenticationManager;
import electrosphere.controls.ControlHandler;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.Scene;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.scene.SceneLoader;
import electrosphere.entity.state.movement.ApplyRotationTree;
@ -43,6 +44,7 @@ import electrosphere.net.client.ClientNetworking;
import electrosphere.net.server.Server;
import electrosphere.net.server.player.Player;
import electrosphere.renderer.ui.Window;
import electrosphere.server.ai.creature.adventurer.SeekTown;
import electrosphere.server.datacell.DataCellManager;
import electrosphere.server.saves.SaveUtils;
import electrosphere.server.simulation.MacroSimulation;
@ -264,18 +266,20 @@ public class LoadingThread extends Thread {
WindowUtils.replaceMainMenuContents(MenuGenerators.createEmptyMainMenu());
loadingWindow.setVisible(true);
//
//the juicy server GENERATION part
//
//init save structure
SaveUtils.createOrOverwriteSave("random_sp_world");
//create terrain
Globals.serverTerrainManager = new ServerTerrainManager(2000,50,100,0.0f,0);
Globals.serverTerrainManager.generate();
Globals.serverTerrainManager.save(SaveUtils.deriveSaveDirectoryPath("random_sp_world"));
//create world.json
Globals.serverWorldData = ServerWorldData.createGameWorld(Globals.serverTerrainManager);
FileUtils.serializeObjectToSavePath("random_sp_world", "./world.json", Globals.serverWorldData);
if(!SaveUtils.getSaves().contains("random_sp_world")){
//
//the juicy server GENERATION part
//
//init save structure
SaveUtils.createOrOverwriteSave("random_sp_world");
//create terrain
Globals.serverTerrainManager.generate();
Globals.serverTerrainManager.save(SaveUtils.deriveSaveDirectoryPath("random_sp_world"));
//create world.json
Globals.serverWorldData = ServerWorldData.createGameWorld(Globals.serverTerrainManager);
FileUtils.serializeObjectToSavePath("random_sp_world", "./world.json", Globals.serverWorldData);
}
//load just-created save
SaveUtils.loadSave("random_sp_world");
//start initializing game datastructures
@ -313,11 +317,12 @@ public class LoadingThread extends Thread {
} catch (InterruptedException ex) {}
}
initWorldBaseGraphicalEntities();
spawnLocalPlayerTestEntity();
initWorldBaseGraphicalEntities();
// SeekTown.attachToCreature(Globals.playerEntity);
//hide cursor
Globals.controlHandler.hideMouse();
@ -430,8 +435,10 @@ public class LoadingThread extends Thread {
if(Globals.macroSimulation != null){
Town startTown = Globals.macroData.getTowns().get(0);
Vector2i firstPos = startTown.getPositions().get(0);
double startX = firstPos.x * Globals.serverTerrainManager.getChunkWidth();
double startZ = firstPos.y * Globals.serverTerrainManager.getChunkWidth();
// double startX = firstPos.x * Globals.serverTerrainManager.getChunkWidth();
// double startZ = firstPos.y * Globals.serverTerrainManager.getChunkWidth();
double startX = Globals.commonWorldData.convertWorldToReal(firstPos.x);
double startZ = Globals.commonWorldData.convertWorldToReal(firstPos.y);
Globals.spawnPoint.set((float)startX,(float)Globals.commonWorldData.getElevationAtPoint(new Vector3d(startX,0,startZ)),(float)startZ);
}
} else {
@ -622,7 +629,8 @@ public class LoadingThread extends Thread {
Player Camera
*/
Globals.playerCamera = CameraEntityUtils.spawnPlayerEntityAirplaneTrackingCameraEntity(new Vector3f(1,0,1), new Vector3f(0,0,1));
Globals.playerCamera = CameraEntityUtils.spawnPlayerEntityTrackingCameraEntity(new Vector3f(1,0,1), new Vector3f(0,0,1));
// Globals.playerCamera = CameraEntityUtils.spawnPlayerEntityAirplaneTrackingCameraEntity(new Vector3f(1,0,1), new Vector3f(0,0,1));
@ -973,8 +981,10 @@ public class LoadingThread extends Thread {
Player playerObject = Globals.playerManager.getPlayerFromId(0);
playerObject.setWorldX(Globals.serverWorldData.convertRealToChunkSpace(Globals.spawnPoint.x));
playerObject.setWorldY(Globals.serverWorldData.convertRealToChunkSpace(Globals.spawnPoint.z));
//set client entity data
Globals.clientPlayerData.setWorldPosition(playerObject.getWorldX(), playerObject.getWorldY());
//initially position entity
EntityUtils.initiallyPositionEntity(newPlayerEntity, new Vector3d(Globals.spawnPoint.x,Globals.spawnPoint.y,Globals.spawnPoint.z));
EntityUtils.initiallyPositionEntity(newPlayerEntity, new Vector3d(Globals.spawnPoint.x + 1,Globals.spawnPoint.y + 5,Globals.spawnPoint.z + 1));
//add entity to correct cells
Globals.dataCellManager.addPlayerToGroundCells(playerObject);
Globals.dataCellManager.movePlayerGroundCells(playerObject, Globals.serverWorldData.convertRealToChunkSpace(Globals.spawnPoint.x), Globals.serverWorldData.convertRealToChunkSpace(Globals.spawnPoint.z));

View File

@ -0,0 +1,20 @@
package electrosphere.entity;
public class EntityTags {
public static final String BONE_ATTACHED = "boneAttached";
public static final String COLLIDABLE = "collidable";
public static final String SPRINTABLE = "sprintable";
public static final String MOVEABLE = "moveable";
public static final String ATTACKER = "attacker";
public static final String TARGETABLE = "targetable";
public static final String LIFE_STATE = "lifeState";
public static final String CREATURE = "creature";
public static final String UI = "ui";
public static final String DRAWABLE = "drawable";
public static final String LIGHT = "light";
public static final String ITEM = "item";
public static final String GRAVITY = "gravity";
public static final String PARTICLE = "particle";
}

View File

@ -52,7 +52,7 @@ public class EntityUtils {
rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true);
rVal.putData(EntityDataStrings.DRAW_SOLID_PASS, true);
Globals.entityManager.registerEntity(rVal);
Globals.entityManager.registerDrawableEntity(rVal);
Globals.entityManager.registerEntityToTag(rVal, EntityTags.DRAWABLE);
return rVal;
}
@ -65,7 +65,7 @@ public class EntityUtils {
rVal.putData(EntityDataStrings.DATA_STRING_DRAW, true);
rVal.putData(EntityDataStrings.DRAW_SOLID_PASS, true);
Globals.entityManager.registerEntity(rVal);
Globals.entityManager.registerDrawableEntity(rVal);
Globals.entityManager.registerEntityToTag(rVal, EntityTags.DRAWABLE);
return rVal;
}
@ -77,7 +77,7 @@ public class EntityUtils {
rVal.putData(EntityDataStrings.DATA_STRING_SCALE, new Vector3f(1,1,1));
rVal.putData(EntityDataStrings.DATA_STRING_UI_ELEMENT, true);
Globals.entityManager.registerEntity(rVal);
Globals.entityManager.registerUIEntity(rVal);
Globals.entityManager.registerEntityToTag(rVal, EntityTags.UI);
return rVal;
}
@ -141,6 +141,12 @@ public class EntityUtils {
//initialize server datacell tracking of this entity
Globals.dataCellManager.initializeServerSideEntity(entity, newDataCell);
}
//if the server is also a client, update the drawcell manager to know to pull new chunks
if(Globals.RUN_CLIENT){
Globals.drawCellManager.invalidateAllCells();
Globals.drawCellManager.setCellX(Globals.clientPlayerData.getWorldPositionX());
Globals.drawCellManager.setCellY(Globals.clientPlayerData.getWorldPositionY());
}
}
//reposition entity
CollisionObjUtils.positionCharacter(entity, position);
@ -165,6 +171,12 @@ public class EntityUtils {
ServerDataCell.moveEntityFromCellToCell(entity, oldDataCell, newDataCell);
}
}
//if the server is also a client, update the drawcell manager to know to pull new chunks
if(Globals.RUN_CLIENT){
Globals.drawCellManager.invalidateAllCells();
Globals.drawCellManager.setCellX(Globals.clientPlayerData.getWorldPositionX());
Globals.drawCellManager.setCellY(Globals.clientPlayerData.getWorldPositionY());
}
}
//reposition entity
CollisionObjUtils.positionCharacter(entity, Globals.spawnPoint);

View File

@ -5,7 +5,9 @@ import electrosphere.entity.state.BehaviorTree;
import electrosphere.entity.types.attach.AttachUtils;
import electrosphere.logger.LoggerInterface;
import java.lang.reflect.Field;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@ -17,211 +19,79 @@ import org.joml.Vector3f;
*
* @author satellite
*/
public class EntityManager {
public class Scene {
static Map<Integer,Entity> entityIdMap = new ConcurrentHashMap<Integer,Entity>();
static Map<Integer,Integer> clientToServerIdMap = new ConcurrentHashMap<Integer,Integer>();
static Map<Integer,Integer> serverToClientIdMap = new ConcurrentHashMap<Integer,Integer>();
static List<Entity> entityList = new CopyOnWriteArrayList<Entity>();
static List<Entity> drawableList = new CopyOnWriteArrayList<Entity>();
static List<Entity> moveableList = new CopyOnWriteArrayList<Entity>();
static List<Entity> lightList = new CopyOnWriteArrayList<Entity>();
static List<Entity> uiList = new CopyOnWriteArrayList<Entity>();
static List<Entity> itemList = new CopyOnWriteArrayList<Entity>();
static List<Entity> boneAttachedList = new CopyOnWriteArrayList<Entity>();
static List<Entity> attackerList = new CopyOnWriteArrayList<Entity>();
static List<Entity> creatureList = new CopyOnWriteArrayList<Entity>();
static List<Entity> lifeStateList = new CopyOnWriteArrayList<Entity>();
static List<Entity> particleList = new CopyOnWriteArrayList<Entity>();
static List<Entity> gravityList = new CopyOnWriteArrayList<Entity>();
static List<Entity> collidableList = new CopyOnWriteArrayList<Entity>();
static List<Entity> targetableList = new CopyOnWriteArrayList<Entity>();
static List<Entity> sprintableList = new CopyOnWriteArrayList<Entity>();
Map<Integer,Entity> entityIdMap = new ConcurrentHashMap<Integer,Entity>();
Map<Integer,Integer> clientToServerIdMap = new ConcurrentHashMap<Integer,Integer>();
Map<Integer,Integer> serverToClientIdMap = new ConcurrentHashMap<Integer,Integer>();
Map<String,List<Entity>> tagEntityMap = new ConcurrentHashMap<String,List<Entity>>();
List<Entity> entityList = new CopyOnWriteArrayList<Entity>();
static List<BehaviorTree> behaviorTreeList = new CopyOnWriteArrayList<BehaviorTree>();
List<BehaviorTree> behaviorTreeList = new CopyOnWriteArrayList<BehaviorTree>();
public EntityManager(){
public Scene(){
tagEntityMap.put(EntityTags.BONE_ATTACHED, new LinkedList<Entity>());
tagEntityMap.put(EntityTags.COLLIDABLE, new LinkedList<Entity>());
tagEntityMap.put(EntityTags.SPRINTABLE, new LinkedList<Entity>());
tagEntityMap.put(EntityTags.MOVEABLE, new LinkedList<Entity>());
tagEntityMap.put(EntityTags.ATTACKER, new LinkedList<Entity>());
tagEntityMap.put(EntityTags.TARGETABLE, new LinkedList<Entity>());
tagEntityMap.put(EntityTags.LIFE_STATE, new LinkedList<Entity>());
tagEntityMap.put(EntityTags.CREATURE, new LinkedList<Entity>());
tagEntityMap.put(EntityTags.UI, new LinkedList<Entity>());
tagEntityMap.put(EntityTags.DRAWABLE, new LinkedList<Entity>());
tagEntityMap.put(EntityTags.LIGHT, new LinkedList<Entity>());
tagEntityMap.put(EntityTags.ITEM, new LinkedList<Entity>());
tagEntityMap.put(EntityTags.GRAVITY, new LinkedList<Entity>());
tagEntityMap.put(EntityTags.PARTICLE, new LinkedList<Entity>());
}
public void registerEntity(Entity e){
entityIdMap.put(e.getId(), e);
entityList.add(e);
}
public void registerDrawableEntity(Entity e){
drawableList.add(e);
}
public List<Entity> getDrawable(){
return drawableList;
}
public void registerMoveableEntity(Entity e){
moveableList.add(e);
}
public List<Entity> getMoveable(){
return moveableList;
}
public void registerLightEntity(Entity e){
lightList.add(e);
}
public List<Entity> getLights(){
return lightList;
}
public void registerUIEntity(Entity e){
uiList.add(e);
}
public List<Entity> getUIElements(){
return uiList;
}
public void registerItemEntity(Entity e){
itemList.add(e);
}
public List<Entity> getItemEntities(){
return itemList;
}
public void registerBoneAttachedEntity(Entity e){
boneAttachedList.add(e);
}
public List<Entity> getBoneAttachedEntities(){
return boneAttachedList;
}
public void registerAttackerEntity(Entity e){
attackerList.add(e);
}
public List<Entity> getAttackerEntities(){
return attackerList;
}
public void registerCreatureEntity(Entity e){
creatureList.add(e);
}
public List<Entity> getCreatureEntities(){
return creatureList;
}
public void registerLifeStateEntity(Entity e){
lifeStateList.add(e);
}
public List<Entity> getLifeStateEntities(){
return lifeStateList;
}
public void registerParticle(Entity e){
particleList.add(e);
}
public List<Entity> getParticles(){
return particleList;
}
public void registerGravityEntity(Entity e){
gravityList.add(e);
}
public List<Entity> getGravityEntities(){
return gravityList;
}
public void registerCollidableEntity(Entity e){
collidableList.add(e);
}
public List<Entity> getCollidables(){
return collidableList;
}
public void deregisterCollidableEntity(Entity e){
collidableList.remove(e);
}
public void registerTargetableEntity(Entity e){
targetableList.add(e);
}
public List<Entity> getTargetables(){
return targetableList;
}
public void registerSprintableEntity(Entity e){
sprintableList.add(e);
}
public List<Entity> getSprintables(){
return sprintableList;
}
public void registerBehaviorTree(BehaviorTree tree){
behaviorTreeList.add(tree);
}
public void removeBehaviorTree(BehaviorTree tree){
behaviorTreeList.remove(tree);
}
public void simulateBehaviorTrees(){
for(BehaviorTree tree : behaviorTreeList){
tree.simulate();
/**
* Registers an entity to a given tag
* @param e The entity
* @param tag The tag
*/
public void registerEntityToTag(Entity e, String tag){
if(tagEntityMap.containsKey(tag)){
tagEntityMap.get(tag).add(e);
} else {
List<Entity> newEntityList = new LinkedList<Entity>();
newEntityList.add(e);
tagEntityMap.put(tag,newEntityList);
}
}
/**
* Gets all entities registered to a tag
* @param tag The tag
* @return A list of all entities with the tag, or null if no entities have been added to the tag yet
*/
public List<Entity> getEntitiesWithTag(String tag){
return tagEntityMap.get(tag);
}
/**
* Removes an entity from a tag
* @param e The entity
* @param tag The tag
*/
public void removeEntityFromTag(Entity e, String tag){
tagEntityMap.get(tag).remove(e);
}
/**
* Deregisters an entity from an entity manager
* @param e
*/
public void deregisterEntity(Entity e){
if(lightList.contains(e)){
lightList.remove(e);
}
if(moveableList.contains(e)){
moveableList.remove(e);
}
if(drawableList.contains(e)){
drawableList.remove(e);
}
if(entityList.contains(e)){
entityList.remove(e);
}
if(uiList.contains(e)){
uiList.remove(e);
}
if(itemList.contains(e)){
itemList.remove(e);
}
if(attackerList.contains(e)){
attackerList.remove(e);
}
if(creatureList.contains(e)){
creatureList.remove(e);
}
if(lifeStateList.contains(e)){
lifeStateList.remove(e);
}
if(particleList.contains(e)){
particleList.remove(e);
}
if(gravityList.contains(e)){
gravityList.remove(e);
}
if(collidableList.contains(e)){
collidableList.remove(e);
}
if(targetableList.contains(e)){
targetableList.remove(e);
}
if(sprintableList.contains(e)){
sprintableList.remove(e);
for(String key : tagEntityMap.keySet()){
tagEntityMap.get(key).remove(e);
}
}
@ -347,13 +217,21 @@ public class EntityManager {
}
}
}
public void setTargetable(Entity target, boolean status){
if(status){
targetableList.add(target);
} else {
targetableList.remove(target);
public void registerBehaviorTree(BehaviorTree tree){
behaviorTreeList.add(tree);
}
public void deregisterBehaviorTree(BehaviorTree tree){
behaviorTreeList.remove(tree);
}
/**
* Simulates all behavior trees stored in the entity manager
*/
public void simulateBehaviorTrees(float deltaTime){
for(BehaviorTree tree : behaviorTreeList){
tree.simulate(deltaTime);
}
}

View File

@ -2,6 +2,6 @@ package electrosphere.entity.state;
public interface BehaviorTree {
public void simulate();
public void simulate(float deltaTime);
}

View File

@ -0,0 +1,14 @@
package electrosphere.entity.state;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface BehaviorTreeAnnotation {
public String name() default "";
}

View File

@ -17,6 +17,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
import org.joml.Vector3d;
import org.joml.Vector3f;
@BehaviorTreeAnnotation(name="idle")
public class IdleTree {
public static enum IdleTreeState {
@ -57,7 +58,7 @@ public class IdleTree {
state = IdleTreeState.NOT_IDLE;
}
public void simulate(){
public void simulate(float deltaTime){
Actor entityActor = EntityUtils.getActor(parent);
boolean movementTreeIsIdle = movementTreeIsIdle();
@ -94,6 +95,9 @@ public class IdleTree {
case SETFACING:
case SETPOSITION:
case SETPROPERTY:
case SPAWNCREATURE:
case SPAWNITEM:
case KILL:
//silently ignore
break;
}

View File

@ -11,7 +11,7 @@ import org.joml.Vector3f;
*
* @author amaterasu
*/
public class ParticleTree {
public class ParticleTree implements BehaviorTree {
Entity parent;
boolean hasLife = true;
int maxLife;
@ -50,7 +50,7 @@ public class ParticleTree {
return acceleration;
}
public void simulate(){
public void simulate(float deltaTime){
Vector3d parentPosition = EntityUtils.getPosition(parent);
parentPosition.add(new Vector3f(destination).mul(velocity));
velocity = velocity - acceleration;

View File

@ -31,7 +31,7 @@ import org.joml.Quaternionfc;
import org.joml.Vector3d;
import org.joml.Vector3f;
public class AttackTree {
public class AttackTree implements BehaviorTree {
public static enum AttackTreeState {
WINDUP,
@ -147,7 +147,8 @@ public class AttackTree {
state = AttackTreeState.COOLDOWN;
}
public void simulate(){
@Override
public void simulate(float deltaTime){
frameCurrent = frameCurrent + Main.deltaFrames;
float velocity = CreatureUtils.getVelocity(parent);
Actor entityActor = EntityUtils.getActor(parent);

View File

@ -33,7 +33,7 @@ public class ShooterTree implements BehaviorTree {
}
@Override
public void simulate() {
public void simulate(float deltaTime) {
// TODO Auto-generated method stub
switch(state){
case ATTACK: {

View File

@ -5,6 +5,7 @@ import electrosphere.engine.Globals;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.BehaviorTree;
import electrosphere.entity.state.gravity.GravityTree;
import electrosphere.entity.types.collision.CollisionObjUtils;
import electrosphere.entity.types.creature.CreatureUtils;
@ -26,7 +27,7 @@ import org.joml.Vector4f;
*
* @author amaterasu
*/
public class CollidableTree {
public class CollidableTree implements BehaviorTree {
Entity parent;
CollisionObject body;
@ -53,7 +54,7 @@ public class CollidableTree {
static int incrementer = 0;
public void simulate(){
public void simulate(float deltaTime){
Vector3d position = EntityUtils.getPosition(parent);
Quaternionf rotation = EntityUtils.getRotation(parent);
Matrix4f inverseInertiaTensor = CollisionObjUtils.getInverseInertiaTensor(parent);

View File

@ -12,6 +12,7 @@ import electrosphere.dynamics.RigidBody;
import electrosphere.engine.Globals;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityTags;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.gravity.GravityUtils;
import electrosphere.entity.state.inventory.InventoryUtils;
@ -118,7 +119,7 @@ public class EquipState {
//hide toEquip actor
EntityUtils.setDraw(inWorldItem, false);
//make untargetable
Globals.entityManager.setTargetable(inWorldItem, false);
Globals.entityManager.removeEntityFromTag(inWorldItem, EntityTags.TARGETABLE);
break;
}
}
@ -130,7 +131,7 @@ public class EquipState {
CollisionObject rigidBody = (CollisionObject)inWorldItem.getData(EntityDataStrings.PHYSICS_COLLISION_BODY);
Globals.collisionEngine.deregisterPhysicsObject(rigidBody);
}
Globals.entityManager.setTargetable(inWorldItem, false);
Globals.entityManager.removeEntityFromTag(inWorldItem, EntityTags.TARGETABLE);
GravityUtils.attemptDeactivateGravity(inWorldItem);
}
//we need to send two packets
@ -214,7 +215,7 @@ public class EquipState {
//hide toEquip actor
EntityUtils.setDraw(toEquip, false);
//make untargetable
Globals.entityManager.setTargetable(toEquip, false);
Globals.entityManager.removeEntityFromTag(toEquip, EntityTags.TARGETABLE);
break;
}
}
@ -226,7 +227,7 @@ public class EquipState {
CollisionObject rigidBody = (CollisionObject)toEquip.getData(EntityDataStrings.PHYSICS_COLLISION_BODY);
Globals.collisionEngine.deregisterPhysicsObject(rigidBody);
}
Globals.entityManager.setTargetable(toEquip, false);
Globals.entityManager.removeEntityFromTag(toEquip, EntityTags.TARGETABLE);
GravityUtils.attemptDeactivateGravity(toEquip);
}
}

View File

@ -11,6 +11,7 @@ import electrosphere.collision.dispatch.CollisionObject;
import electrosphere.engine.Globals;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.BehaviorTree;
import electrosphere.entity.state.collidable.CollidableTree;
import electrosphere.entity.state.collidable.Impulse;
import electrosphere.entity.state.movement.FallTree;
@ -22,7 +23,7 @@ import electrosphere.net.parser.net.message.EntityMessage;
*
* @author amaterasu
*/
public class GravityTree {
public class GravityTree implements BehaviorTree {
public static enum GravityTreeState {
ACTIVE,

View File

@ -34,7 +34,7 @@ public class InventoryState implements BehaviorTree {
}
@Override
public void simulate() {
public void simulate(float deltaTime) {
if(Globals.RUN_SERVER){
for(InventoryMessage message : networkMessageQueue){
networkMessageQueue.remove(message);

View File

@ -32,7 +32,7 @@ public class IronSightTree implements BehaviorTree {
}
@Override
public void simulate() {
public void simulate(float deltaTime) {
switch(state){
case ACTIVE:
if(!cameraZoomedIn){

View File

@ -135,7 +135,7 @@ public class LifeState implements BehaviorTree {
lifeCurrent = lifeMax;
}
public void simulate(){
public void simulate(float deltaTime){
for(EntityMessage message : networkMessageQueue){
networkMessageQueue.remove(message);
long updateTime = message.gettime();

View File

@ -70,7 +70,7 @@ public class AirplaneMovementTree implements BehaviorTree {
/**
* Simulates a step of the behavior tree
*/
public void simulate(){
public void simulate(float deltaTime){
//
//Get important initial values
//

View File

@ -33,7 +33,7 @@ public class ApplyRotationTree implements BehaviorTree {
}
@Override
public void simulate(){
public void simulate(float deltaTime){
switch(state){
case ROTATE:
EntityUtils.getRotation(parent).mul(rotationToApply).normalize();

View File

@ -27,7 +27,7 @@ public class FallTree implements BehaviorTree {
}
@Override
public void simulate() {
public void simulate(float deltaTime) {
Actor entityActor = EntityUtils.getActor(parent);
switch(state){
case ACTIVE:

View File

@ -153,7 +153,7 @@ public class GroundMovementTree implements BehaviorTree {
}
}
public void simulate(){
public void simulate(float deltaTime){
float velocity = CreatureUtils.getVelocity(parent);
float acceleration = CreatureUtils.getAcceleration(parent);
float maxNaturalVelocity = sprintTree != null && sprintTree.state == SprintTreeState.SPRINTING ? sprintTree.maxVelocity : CreatureUtils.getMaxNaturalVelocity(parent);

View File

@ -49,7 +49,7 @@ public class JumpTree implements BehaviorTree {
}
@Override
public void simulate() {
public void simulate(float deltaTime) {
Actor entityActor = EntityUtils.getActor(parent);
switch(state){
case ACTIVE:

View File

@ -40,12 +40,12 @@ public class ProjectileTree implements BehaviorTree {
}
@Override
public void simulate() {
public void simulate(float deltaTime) {
lifeCurrent++;
if(lifeCurrent >= maxLife){
Globals.entityManager.deregisterEntity(parent);
Globals.entityManager.removeBehaviorTree(this);
Globals.entityManager.deregisterBehaviorTree(this);
}
Vector3d positionCurrent = EntityUtils.getPosition(parent);

View File

@ -1,13 +1,14 @@
package electrosphere.entity.state.movement;
import electrosphere.entity.Entity;
import electrosphere.entity.state.BehaviorTree;
import electrosphere.entity.state.movement.GroundMovementTree.MovementTreeState;
/**
*
* @author amaterasu
*/
public class SprintTree {
public class SprintTree implements BehaviorTree {
public static enum SprintTreeState {
SPRINTING,
@ -47,7 +48,8 @@ public class SprintTree {
state = SprintTreeState.NOT_SPRINTING;
}
public void simulate(){
@Override
public void simulate(float deltaTime){
switch(state){
case SPRINTING:
if(groundMovementTree != null && groundMovementTree.getState() != MovementTreeState.IDLE){

View File

@ -49,7 +49,7 @@ public class RotatorTree implements BehaviorTree{
}
}
public void simulate(){
public void simulate(float deltaTime){
if(entityActor.modelIsLoaded() && this.state == RotatorTreeState.ACTIVE){
for(RotatorHierarchyNode node : nodes){
applyRotatorNode(node);

View File

@ -3,6 +3,7 @@ package electrosphere.entity.types.attach;
import electrosphere.engine.Globals;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityTags;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.renderer.Model;
@ -24,7 +25,7 @@ public class AttachUtils {
public static void attachEntityToEntityAtBone(Entity parent, Entity toAttach, String boneName, Quaternionf rotation){
Globals.entityManager.registerBoneAttachedEntity(toAttach);
Globals.entityManager.registerEntityToTag(toAttach, EntityTags.BONE_ATTACHED);
toAttach.putData(EntityDataStrings.ATTACH_ENTITY_IS_ATTACHED, true);
toAttach.putData(EntityDataStrings.ATTACH_PARENT, parent);
toAttach.putData(EntityDataStrings.ATTACH_TARGET_BONE, boneName);
@ -39,7 +40,7 @@ public class AttachUtils {
}
public static void updateAttachedEntityPositions(){
for(Entity currentEntity : Globals.entityManager.getBoneAttachedEntities()){
for(Entity currentEntity : Globals.entityManager.getEntitiesWithTag(EntityTags.BONE_ATTACHED)){
Entity parent;
if((parent = (Entity)currentEntity.getData(EntityDataStrings.ATTACH_PARENT))!=null){
String targetBone;
@ -72,7 +73,7 @@ public class AttachUtils {
}
public static void detatchEntityFromEntityAtBone(Entity parent, Entity toAttach){
Globals.entityManager.registerBoneAttachedEntity(toAttach);
Globals.entityManager.registerEntityToTag(toAttach, EntityTags.BONE_ATTACHED);
toAttach.removeData(EntityDataStrings.ATTACH_ENTITY_IS_ATTACHED);
toAttach.removeData(EntityDataStrings.ATTACH_PARENT);
toAttach.removeData(EntityDataStrings.ATTACH_TARGET_BONE);

View File

@ -43,7 +43,7 @@ public class CameraEntityUtils {
rVal.putData(EntityDataStrings.CAMERA_YAW, 0.0f);
BehaviorTree entityTrackingTree = new BehaviorTree() {
@Override
public void simulate() {
public void simulate(float deltaTime) {
if(toTrack != null){
Vector3d entityPos = EntityUtils.getPosition(toTrack);
CameraEntityUtils.setCameraCenter(rVal, new Vector3f((float)entityPos.x,(float)entityPos.y,(float)entityPos.z).add(getOrbitalCameraRadialOffset(rVal)));
@ -66,7 +66,7 @@ public class CameraEntityUtils {
rVal.putData(EntityDataStrings.CAMERA_YAW, 0.0f);
BehaviorTree entityTrackingTree = new BehaviorTree() {
@Override
public void simulate() {
public void simulate(float deltaTime) {
if(Globals.playerEntity != null){
Vector3d entityPos = EntityUtils.getPosition(Globals.playerEntity);
CameraEntityUtils.setCameraCenter(rVal, new Vector3f((float)entityPos.x,(float)entityPos.y,(float)entityPos.z).add(getOrbitalCameraRadialOffset(rVal)));
@ -89,7 +89,7 @@ public class CameraEntityUtils {
rVal.putData(EntityDataStrings.CAMERA_YAW, 0.0f);
BehaviorTree entityTrackingTree = new BehaviorTree() {
@Override
public void simulate() {
public void simulate(float deltaTime) {
if(Globals.playerEntity != null){
Vector3d entityPos = EntityUtils.getPosition(Globals.playerEntity);
CameraEntityUtils.setCameraCenter(rVal, new Vector3f((float)entityPos.x,(float)entityPos.y,(float)entityPos.z).add(getOrbitalCameraRadialOffset(rVal)));

View File

@ -6,6 +6,7 @@ import electrosphere.engine.Globals;
import electrosphere.engine.Main;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityTags;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.movement.AirplaneMovementTree;
import electrosphere.entity.state.movement.FallTree;
@ -121,14 +122,15 @@ public class CreatureUtils {
Matrix4f inertiaTensor;
Vector3f scale;
switch(physicsTemplate.getType()){
case "CYLINDER":
case "CYLINDER": {
rigidBody = PhysicsUtils.getCylinderObject(new Vector3f(physicsTemplate.getDimension1(),physicsTemplate.getDimension2(),physicsTemplate.getDimension3()));
collidable = new Collidable(rVal, Collidable.TYPE_CREATURE);
CollidableTree tree = new CollidableTree(rVal,collidable,rigidBody);
rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY, rigidBody);
rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY_OFFSET, new Vector3f(physicsTemplate.getOffsetX(),physicsTemplate.getOffsetY(),physicsTemplate.getOffsetZ()));
rVal.putData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE, physicsTemplate);
rVal.putData(EntityDataStrings.PHYSICS_COLLIDABLE, collidable);
rVal.putData(EntityDataStrings.COLLIDABLE_TREE, new CollidableTree(rVal,collidable,rigidBody));
rVal.putData(EntityDataStrings.COLLIDABLE_TREE, tree);
scale = new Vector3f(physicsTemplate.getDimension1(),physicsTemplate.getDimension2(),physicsTemplate.getDimension3());
rVal.putData(EntityDataStrings.PHYSICS_MASS, mass);
@ -143,16 +145,17 @@ public class CreatureUtils {
Globals.collisionEngine.registerPhysicsEntity(rVal);
Globals.collisionEngine.registerDynamicPhysicsEntity(rVal);
Globals.collisionEngine.registerCollisionObject(rigidBody, collidable);
Globals.entityManager.registerCollidableEntity(rVal);
break;
case "CUBE":
Globals.entityManager.registerEntityToTag(rVal, EntityTags.COLLIDABLE);
} break;
case "CUBE": {
rigidBody = PhysicsUtils.getCubeObject(new Vector3f(physicsTemplate.getDimension1(),physicsTemplate.getDimension2(),physicsTemplate.getDimension3()));
collidable = new Collidable(rVal, Collidable.TYPE_CREATURE);
CollidableTree tree = new CollidableTree(rVal,collidable,rigidBody);
rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY, rigidBody);
rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY_OFFSET, new Vector3f(physicsTemplate.getOffsetX(),physicsTemplate.getOffsetY(),physicsTemplate.getOffsetZ()));
rVal.putData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE, physicsTemplate);
rVal.putData(EntityDataStrings.PHYSICS_COLLIDABLE, collidable);
rVal.putData(EntityDataStrings.COLLIDABLE_TREE, new CollidableTree(rVal,collidable,rigidBody));
rVal.putData(EntityDataStrings.COLLIDABLE_TREE, tree);
scale = new Vector3f(physicsTemplate.getDimension1(),physicsTemplate.getDimension2(),physicsTemplate.getDimension3());
rVal.putData(EntityDataStrings.PHYSICS_MASS, mass);
@ -164,8 +167,8 @@ public class CreatureUtils {
Globals.collisionEngine.registerPhysicsEntity(rVal);
Globals.collisionEngine.registerDynamicPhysicsEntity(rVal);
Globals.collisionEngine.registerCollisionObject(rigidBody, collidable);
Globals.entityManager.registerCollidableEntity(rVal);
break;
Globals.entityManager.registerEntityToTag(rVal, EntityTags.COLLIDABLE);
} break;
}
}
//
@ -205,7 +208,8 @@ public class CreatureUtils {
sprintTree.setGroundMovementTree(moveTree);
moveTree.setSprintTree(sprintTree);
rVal.putData(EntityDataStrings.SPRINT_TREE,sprintTree);
Globals.entityManager.registerSprintableEntity(rVal);
Globals.entityManager.registerBehaviorTree(sprintTree);
Globals.entityManager.registerEntityToTag(rVal, EntityTags.SPRINTABLE);
}
//round out end of move system
rVal.putData(EntityDataStrings.DATA_STRING_MOVEMENT_BT, moveTree);
@ -213,7 +217,8 @@ public class CreatureUtils {
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);
Globals.entityManager.registerMoveableEntity(rVal);
Globals.entityManager.registerBehaviorTree(moveTree);
Globals.entityManager.registerEntityToTag(rVal, EntityTags.MOVEABLE);
break;
//
// Jump
@ -267,7 +272,8 @@ public class CreatureUtils {
//register misc stuff
rVal.putData(EntityDataStrings.DATA_STRING_MOVEMENT_BT, airplaneMovementTree);
CreatureUtils.setFacingVector(rVal, new Vector3d(0,0,0));
Globals.entityManager.registerMoveableEntity(rVal);
Globals.entityManager.registerBehaviorTree(airplaneMovementTree);
Globals.entityManager.registerEntityToTag(rVal, EntityTags.MOVEABLE);
} break;
}
}
@ -284,7 +290,8 @@ public class CreatureUtils {
AttackTree attackTree = new AttackTree(rVal);
rVal.putData(EntityDataStrings.ATTACK_TREE, attackTree);
rVal.putData(EntityDataStrings.ATTACK_MOVE_TYPE_ACTIVE, null);
Globals.entityManager.registerAttackerEntity(rVal);
Globals.entityManager.registerBehaviorTree(attackTree);
Globals.entityManager.registerEntityToTag(rVal, EntityTags.ATTACKER);
//add all attack moves
if(rawType.getAttackMoves() != null && rawType.getAttackMoves().size() > 0){
for(AttackMove attackMove : rawType.getAttackMoves()){
@ -312,10 +319,10 @@ public class CreatureUtils {
// gravityTree.setCollisionObject(collisionObject, collidable);
rVal.putData(EntityDataStrings.GRAVITY_ENTITY, true);
rVal.putData(EntityDataStrings.GRAVITY_TREE, gravityTree);
Globals.entityManager.registerGravityEntity(rVal);
Globals.entityManager.registerBehaviorTree(gravityTree);
break;
case "TARGETABLE":
Globals.entityManager.registerTargetableEntity(rVal);
Globals.entityManager.registerEntityToTag(rVal, EntityTags.TARGETABLE);
break;
case "INVENTORY":
rVal.putData(EntityDataStrings.NATURAL_INVENTORY,UnrelationalInventoryState.createUnrelationalInventory(10));
@ -416,10 +423,10 @@ public class CreatureUtils {
}
//add health system
rVal.putData(EntityDataStrings.LIFE_STATE, new LifeState(rVal, rawType.getHealthSystem()));
Globals.entityManager.registerLifeStateEntity(rVal);
Globals.entityManager.registerEntityToTag(rVal, EntityTags.LIFE_STATE);
//idle tree & generic stuff all creatures have
rVal.putData(EntityDataStrings.IDLE_TREE, new IdleTree(rVal));
Globals.entityManager.registerCreatureEntity(rVal);
Globals.entityManager.registerEntityToTag(rVal, EntityTags.CREATURE);
rVal.putData(EntityDataStrings.DATA_STRING_CREATURE_IS_CREATURE, true);
rVal.putData(EntityDataStrings.DATA_STRING_CREATURE_TYPE, type);
CreatureUtils.setFacingVector(rVal, new Vector3d(0,0,1));

View File

@ -4,6 +4,7 @@ import electrosphere.collision.dispatch.CollisionObject;
import electrosphere.engine.Globals;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityTags;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.collidable.CollidableTree;
import electrosphere.entity.state.gravity.GravityTree;
@ -90,7 +91,7 @@ public class ItemUtils {
Globals.collisionEngine.registerPhysicsEntity(rVal);
Globals.collisionEngine.registerDynamicPhysicsEntity(rVal);
Globals.collisionEngine.registerCollisionObject(rigidBody, collidable);
Globals.entityManager.registerCollidableEntity(rVal);
Globals.entityManager.registerEntityToTag(rVal, EntityTags.COLLIDABLE);
break;
case "CUBE":
rigidBody = PhysicsUtils.getCubeObject(new Vector3f(physicsTemplate.getDimension1(),physicsTemplate.getDimension2(),physicsTemplate.getDimension3()));
@ -111,7 +112,7 @@ public class ItemUtils {
Globals.collisionEngine.registerPhysicsEntity(rVal);
Globals.collisionEngine.registerDynamicPhysicsEntity(rVal);
Globals.collisionEngine.registerCollisionObject(rigidBody, collidable);
Globals.entityManager.registerCollidableEntity(rVal);
Globals.entityManager.registerEntityToTag(rVal, EntityTags.COLLIDABLE);
break;
}
}
@ -127,10 +128,10 @@ public class ItemUtils {
// gravityTree.setCollisionObject(collisionObject, collidable);
rVal.putData(EntityDataStrings.GRAVITY_ENTITY, true);
rVal.putData(EntityDataStrings.GRAVITY_TREE, gravityTree);
Globals.entityManager.registerGravityEntity(rVal);
Globals.entityManager.registerBehaviorTree(gravityTree);
break;
case "TARGETABLE":
Globals.entityManager.registerTargetableEntity(rVal);
Globals.entityManager.registerEntityToTag(rVal, EntityTags.TARGETABLE);
break;
case "OUTLINE":
rVal.putData(EntityDataStrings.DRAW_OUTLINE, true);
@ -157,7 +158,7 @@ public class ItemUtils {
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);
Globals.entityManager.registerEntityToTag(rVal, EntityTags.ITEM);
return rVal;
}

View File

@ -7,6 +7,7 @@ import electrosphere.collision.dispatch.CollisionObject;
import electrosphere.engine.Globals;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityTags;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.BehaviorTree;
import electrosphere.entity.state.IdleTree;
@ -39,20 +40,20 @@ public class ObjectUtils {
} break;
case "GENERATE_COLLISION_OBJECT": {
Globals.assetManager.addCollisionMeshToQueue(rawType.getModelPath());
Globals.entityManager.registerBehaviorTree(new BehaviorTree() {public void simulate() {
Globals.entityManager.registerBehaviorTree(new BehaviorTree() {public void simulate(float deltaTime) {
CollisionObject collisionObject = Globals.assetManager.fetchCollisionObject(rawType.getModelPath());
if(collisionObject != null){
Globals.entityManager.removeBehaviorTree(this);
Globals.entityManager.deregisterBehaviorTree(this);
CollisionObjUtils.attachCollisionObjectToEntity(rVal, collisionObject, 0, Collidable.TYPE_OBJECT);
}
}});
} break;
case "GENERATE_COLLISION_TERRAIN": {
Globals.assetManager.addCollisionMeshToQueue(rawType.getModelPath());
Globals.entityManager.registerBehaviorTree(new BehaviorTree() {public void simulate() {
Globals.entityManager.registerBehaviorTree(new BehaviorTree() {public void simulate(float deltaTime) {
CollisionObject collisionObject = Globals.assetManager.fetchCollisionObject(rawType.getModelPath());
if(collisionObject != null){
Globals.entityManager.removeBehaviorTree(this);
Globals.entityManager.deregisterBehaviorTree(this);
CollisionObjUtils.attachCollisionObjectToEntity(rVal, collisionObject, 0, Collidable.TYPE_TERRAIN);
}
}});
@ -68,14 +69,15 @@ public class ObjectUtils {
Matrix4f inertiaTensor;
Vector3f scale;
switch(physicsTemplate.getType()){
case "CYLINDER":
case "CYLINDER": {
rigidBody = PhysicsUtils.getCylinderObject(new Vector3f(physicsTemplate.getDimension1(),physicsTemplate.getDimension2(),physicsTemplate.getDimension3()));
collidable = new Collidable(rVal, Collidable.TYPE_OBJECT);
rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY, rigidBody);
rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY_OFFSET, new Vector3f(physicsTemplate.getOffsetX(),physicsTemplate.getOffsetY(),physicsTemplate.getOffsetZ()));
rVal.putData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE, physicsTemplate);
rVal.putData(EntityDataStrings.PHYSICS_COLLIDABLE, collidable);
rVal.putData(EntityDataStrings.COLLIDABLE_TREE, new CollidableTree(rVal,collidable,rigidBody, collisionMakeDynamic));
CollidableTree tree = new CollidableTree(rVal,collidable,rigidBody, collisionMakeDynamic);
rVal.putData(EntityDataStrings.COLLIDABLE_TREE, tree);
scale = new Vector3f(physicsTemplate.getDimension1(),physicsTemplate.getDimension2(),physicsTemplate.getDimension3());
rVal.putData(EntityDataStrings.PHYSICS_MASS, mass);
@ -88,16 +90,18 @@ public class ObjectUtils {
rVal.putData(EntityDataStrings.PHYSICS_INVERSE_INERTIA_TENSOR, inertiaTensor.invert());
Globals.collisionEngine.registerPhysicsEntity(rVal);
Globals.entityManager.registerBehaviorTree(tree);
Globals.collisionEngine.registerCollisionObject(rigidBody, collidable);
break;
case "CUBE":
} break;
case "CUBE": {
rigidBody = PhysicsUtils.getCubeObject(new Vector3f(physicsTemplate.getDimension1(),physicsTemplate.getDimension2(),physicsTemplate.getDimension3()));
collidable = new Collidable(rVal, Collidable.TYPE_OBJECT);
rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY, rigidBody);
rVal.putData(EntityDataStrings.PHYSICS_COLLISION_BODY_OFFSET, new Vector3f(physicsTemplate.getOffsetX(),physicsTemplate.getOffsetY(),physicsTemplate.getOffsetZ()));
rVal.putData(EntityDataStrings.PHYSICS_MODEL_TEMPLATE, physicsTemplate);
rVal.putData(EntityDataStrings.PHYSICS_COLLIDABLE, collidable);
rVal.putData(EntityDataStrings.COLLIDABLE_TREE, new CollidableTree(rVal,collidable,rigidBody, collisionMakeDynamic));
CollidableTree tree = new CollidableTree(rVal,collidable,rigidBody, collisionMakeDynamic);
rVal.putData(EntityDataStrings.COLLIDABLE_TREE, tree);
scale = new Vector3f(physicsTemplate.getDimension1(),physicsTemplate.getDimension2(),physicsTemplate.getDimension3());
rVal.putData(EntityDataStrings.PHYSICS_MASS, mass);
@ -107,11 +111,12 @@ public class ObjectUtils {
rVal.putData(EntityDataStrings.PHYSICS_INVERSE_INERTIA_TENSOR, inertiaTensor.invert());
Globals.collisionEngine.registerPhysicsEntity(rVal);
Globals.entityManager.registerBehaviorTree(tree);
Globals.collisionEngine.registerCollisionObject(rigidBody, collidable);
break;
} break;
}
Globals.collisionEngine.registerDynamicPhysicsEntity(rVal);
Globals.entityManager.registerCollidableEntity(rVal);
Globals.entityManager.registerEntityToTag(rVal, EntityTags.COLLIDABLE);
}
for(String token : rawType.getTokens()){
switch(token){
@ -125,10 +130,10 @@ public class ObjectUtils {
// gravityTree.setCollisionObject(collisionObject, collidable);
rVal.putData(EntityDataStrings.GRAVITY_ENTITY, true);
rVal.putData(EntityDataStrings.GRAVITY_TREE, gravityTree);
Globals.entityManager.registerGravityEntity(rVal);
Globals.entityManager.registerBehaviorTree(gravityTree);
break;
case "TARGETABLE":
Globals.entityManager.registerTargetableEntity(rVal);
Globals.entityManager.registerEntityToTag(rVal, EntityTags.TARGETABLE);
break;
case "INVENTORY":
rVal.putData(EntityDataStrings.NATURAL_INVENTORY,UnrelationalInventoryState.createUnrelationalInventory(10));

View File

@ -3,6 +3,7 @@ package electrosphere.entity.types.particle;
import electrosphere.engine.Globals;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityTags;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.ParticleTree;
import electrosphere.entity.types.camera.CameraEntityUtils;
@ -28,7 +29,7 @@ public class ParticleUtils {
ParticleTree particleTree = new ParticleTree(rVal, maxLife, destination, velocity, acceleration, true);
rVal.putData(EntityDataStrings.PARTICLE_TREE, particleTree);
rVal.putData(EntityDataStrings.IS_PARTICLE, true);
Globals.entityManager.registerParticle(rVal);
Globals.entityManager.registerEntityToTag(rVal, EntityTags.PARTICLE);
return rVal;
}
@ -37,7 +38,7 @@ public class ParticleUtils {
ParticleTree particleTree = new ParticleTree(rVal, 10, new Vector3f(0,0,0), 0, 0, false);
rVal.putData(EntityDataStrings.PARTICLE_TREE, particleTree);
rVal.putData(EntityDataStrings.IS_PARTICLE, true);
Globals.entityManager.registerParticle(rVal);
Globals.entityManager.registerEntityToTag(rVal, EntityTags.PARTICLE);
return rVal;
}

View File

@ -44,8 +44,8 @@ public class DrawCell {
CollisionObject physicsObject;
static Texture groundTextureOne = new Texture("/Textures/Ground/tileableSlabstone.png");
static Texture groundTextureTwo = new Texture("/Textures/Ground/tileableSlabstone.png");
static Texture groundTextureOne = new Texture("/Textures/Ground/Dirt1.png");
static Texture groundTextureTwo = new Texture("/Textures/Ground/Dirt1.png");
static Texture groundTextureThree = new Texture("/Textures/Ground/Dirt1.png");
static Texture groundTextureFour = new Texture("/Textures/Ground/Dirt1.png");

View File

@ -10,6 +10,8 @@ import electrosphere.net.parser.net.message.TerrainMessage;
import electrosphere.renderer.ShaderProgram;
import java.util.Arrays;
import java.util.HashMap;
import org.joml.Vector2i;
import org.joml.Vector3d;
import org.joml.Vector3f;
@ -127,6 +129,11 @@ public class DrawCellManager {
public void setCellY(int y){
cellY = y;
}
public void setCell(Vector2i cellPos){
cellX = cellPos.x;
cellY = cellPos.y;
}
void updateInvalidCell(){
int targetX = 0;
@ -170,6 +177,8 @@ public class DrawCellManager {
drawable[targetX][targetY] = false;
updateable[targetX][targetY] = false;
hasRequested[targetX][targetY] = false;
hasPhysics[targetX][targetY] = false;
needsPhysics[targetX][targetY] = true;
// if(Math.abs(physicsRadius + 1 - targetX) < physicsRadius && Math.abs(physicsRadius + 1 - targetY) < physicsRadius){
// needsPhysics[targetX][targetY] = true;
// }
@ -185,6 +194,8 @@ public class DrawCellManager {
drawable[targetX][targetY] = false;
updateable[targetX][targetY] = false;
hasRequested[targetX][targetY] = false;
hasPhysics[targetX][targetY] = false;
needsPhysics[targetX][targetY] = true;
}
}
}
@ -361,7 +372,7 @@ public class DrawCellManager {
// stride = stride + 1;
// }
// if(cells[targetX][targetY + drawRadius] != null){
// System.out.println(targetX + " - " + targetY);
// System.out.println(targetX + " - " + targetY);
cells[targetX + drawRadius - physicsRadius][targetY + drawRadius - physicsRadius].generatePhysics();
// } else {
// System.out.println("Current cell is null: " + currentCellX + " - " + currentCellY);
@ -396,7 +407,9 @@ public class DrawCellManager {
//retire physics of cells
for(int x = 0; x < physicsRadius * 2 + 1; x++){
if(hasPhysics[x][physicsRadius * 2]){
cells[x + drawRadius - physicsRadius][physicsRadius * 2 + drawRadius - physicsRadius].destroyPhysics();
if(cells[x + drawRadius - physicsRadius][physicsRadius * 2 + drawRadius - physicsRadius] != null){
cells[x + drawRadius - physicsRadius][physicsRadius * 2 + drawRadius - physicsRadius].destroyPhysics();
}
}
}
//shift physics array
@ -436,7 +449,9 @@ public class DrawCellManager {
//retire physics of cells
for(int x = 0; x < physicsRadius * 2 + 1; x++){
if(hasPhysics[x][physicsRadius * 2]){
cells[x + drawRadius - physicsRadius][physicsRadius * 2 + drawRadius - physicsRadius].destroyPhysics();
if(cells[x + drawRadius - physicsRadius][physicsRadius * 2 + drawRadius - physicsRadius] != null){
cells[x + drawRadius - physicsRadius][physicsRadius * 2 + drawRadius - physicsRadius].destroyPhysics();
}
}
}
//shift physics array
@ -476,7 +491,9 @@ public class DrawCellManager {
//retire physics of cells
for(int x = 0; x < physicsRadius * 2 + 1; x++){
if(hasPhysics[x][physicsRadius * 2]){
cells[x + drawRadius - physicsRadius][physicsRadius * 2 + drawRadius - physicsRadius].destroyPhysics();
if(cells[x + drawRadius - physicsRadius][physicsRadius * 2 + drawRadius - physicsRadius] != null){
cells[x + drawRadius - physicsRadius][physicsRadius * 2 + drawRadius - physicsRadius].destroyPhysics();
}
}
}
//shift physics array
@ -516,7 +533,9 @@ public class DrawCellManager {
//retire physics of cells
for(int x = 0; x < physicsRadius * 2 + 1; x++){
if(hasPhysics[x][0]){
cells[x + drawRadius - physicsRadius][0 + drawRadius - physicsRadius].destroyPhysics();
if(cells[x + drawRadius - physicsRadius][0 + drawRadius - physicsRadius] != null){
cells[x + drawRadius - physicsRadius][0 + drawRadius - physicsRadius].destroyPhysics();
}
}
}
//shift physics array

View File

@ -2,6 +2,7 @@ package electrosphere.game.client.targeting.crosshair;
import electrosphere.engine.Globals;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityTags;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.types.camera.CameraEntityUtils;
@ -35,7 +36,7 @@ public class Crosshair {
if(!crosshairActive){
Entity target = null;
double dist = 100;
for(Entity entity : Globals.entityManager.getTargetables()){
for(Entity entity : Globals.entityManager.getEntitiesWithTag(EntityTags.TARGETABLE)){
Vector3d entityPos = EntityUtils.getPosition(entity);
double currentDist = parentPos.distance(entityPos);
double currentAngleDiff = new Vector3d(entityPos).sub(parentPos).normalize().dot(new Vector3d(CameraEntityUtils.getCameraEye(Globals.playerCamera)));

View File

@ -80,4 +80,8 @@ public class ClientWorldData {
return (int)Math.floor(real / dynamicInterpolationRatio);
}
public float convertChunkToRealSpace(int chunk){
return chunk * dynamicInterpolationRatio;
}
}

View File

@ -80,6 +80,14 @@ public class CommonWorldData {
}
}
public double convertWorldToReal(int world){
if(clientWorldData != null){
return clientWorldData.convertChunkToRealSpace(world);
} else {
return serverWorldData.convertChunkToRealSpace(world);
}
}
public int getDynamicInterpolationRatio(){
if(clientWorldData != null){
return clientWorldData.getDynamicInterpolationRatio();

View File

@ -307,7 +307,7 @@ public class ServerTerrainManager {
}
public void deformTerrainAtLocationToValue(int worldX, int worldY, int locationX, int locationY, float value){
// System.out.println("Add modification at " + worldX + "," + worldY + " subloc " + locationX + "," + locationY);
System.out.println("Add modification at " + worldX + "," + worldY + " subloc " + locationX + "," + locationY);
TerrainModification modification = new TerrainModification(worldX,worldY,locationX,locationY,value);
model.addModification(modification);
String key = getKey(worldX,worldY);
@ -316,6 +316,17 @@ public class ServerTerrainManager {
chunk.addModification(modification);
chunk.heightMap = modification.applyToHeightfield(chunk.heightMap);
}
if(locationX == 0){
if(locationY == 0){
deformTerrainAtLocationToValue(worldX - 1, worldY - 1, Globals.serverTerrainManager.dynamicInterpolationRatio, Globals.serverTerrainManager.dynamicInterpolationRatio, value);
deformTerrainAtLocationToValue(worldX - 1, worldY, Globals.serverTerrainManager.dynamicInterpolationRatio, locationY, value);
deformTerrainAtLocationToValue(worldX, worldY - 1, locationX, Globals.serverTerrainManager.dynamicInterpolationRatio, value);
} else {
deformTerrainAtLocationToValue(worldX - 1, worldY, Globals.serverTerrainManager.dynamicInterpolationRatio, locationY, value);
}
} else if(locationY == 0){
deformTerrainAtLocationToValue(worldX, worldY - 1, locationX, Globals.serverTerrainManager.dynamicInterpolationRatio, value);
}
}
public long getRandomizerAtPoint(int worldX, int worldY){

View File

@ -96,6 +96,10 @@ public class ServerWorldData {
public int convertRealToChunkSpace(double real){
return (int)Math.floor(real / dynamicInterpolationRatio);
}
public float convertChunkToRealSpace(int chunk){
return chunk * dynamicInterpolationRatio;
}
public double getRelativeLocation(double real, int world){
return real - (world * dynamicInterpolationRatio);

View File

@ -20,14 +20,14 @@ public class LoggerInterface {
public static Logger loggerDB;
public static void initLoggers(){
loggerStartup = new Logger(LogLevel.WARNING);
loggerNetworking = new Logger(LogLevel.DEBUG);
loggerFileIO = new Logger(LogLevel.WARNING);
loggerGameLogic = new Logger(LogLevel.WARNING);
loggerStartup = new Logger(LogLevel.INFO);
loggerNetworking = new Logger(LogLevel.INFO);
loggerFileIO = new Logger(LogLevel.INFO);
loggerGameLogic = new Logger(LogLevel.INFO);
loggerRenderer = new Logger(LogLevel.WARNING);
loggerEngine = new Logger(LogLevel.WARNING);
loggerEngine = new Logger(LogLevel.INFO);
loggerAuth = new Logger(LogLevel.INFO);
loggerDB = new Logger(LogLevel.WARNING);
loggerDB = new Logger(LogLevel.INFO);
loggerStartup.INFO("Initialized loggers");
}
}

View File

@ -16,6 +16,7 @@ import electrosphere.entity.types.camera.CameraEntityUtils;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.game.data.creature.type.CreatureType;
import electrosphere.game.data.creature.type.visualattribute.VisualAttribute;
import electrosphere.game.server.terrain.manager.ServerTerrainManager;
import electrosphere.net.NetUtils;
import electrosphere.renderer.Model;
import electrosphere.renderer.RenderingEngine;
@ -46,97 +47,6 @@ import electrosphere.server.saves.SaveUtils;
* @author amaterasu
*/
public class MenuGenerators {
public static Element createTitleMenu(){
FormElement rVal = new FormElement();
//label (title)
Label titleLabel = new Label(100,150,1.0f);
titleLabel.setText("ORPG");
rVal.addChild(titleLabel);
//button (multiplayer)
Button singleplayerButton = new Button();
Label singleplayerLabel = new Label(100,275,1.0f);
singleplayerLabel.setText("Singleplayer");
singleplayerButton.addChild(singleplayerLabel);
rVal.addChild(singleplayerButton);
singleplayerButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
LoadingThread clientThread = new LoadingThread(LoadingThread.LOAD_MAIN_GAME);
Globals.loadingThreadsList.add(clientThread);
Globals.RUN_CLIENT = true;
Globals.RUN_SERVER = true;
clientThread.start();
return false;
}});
//button (multiplayer)
Button multiplayerButton = new Button();
Label multiplayerLabel = new Label(100,350,1.0f);
multiplayerLabel.setText("Multiplayer");
multiplayerButton.addChild(multiplayerLabel);
rVal.addChild(multiplayerButton);
multiplayerButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
WindowUtils.replaceMainMenuContents(MenuGenerators.createMultiplayerMenu());
return false;
}});
//button (arena)
Button arenaButton = new Button();
Label arenaLabel = new Label(100,425,1.0f);
arenaLabel.setText("Arena");
arenaButton.addChild(arenaLabel);
rVal.addChild(arenaButton);
arenaButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
LoadingThread serverThread = new LoadingThread(LoadingThread.LOAD_ARENA);
Globals.loadingThreadsList.add(serverThread);
Globals.RUN_CLIENT = true;
Globals.RUN_SERVER = true;
serverThread.start();
WindowUtils.replaceMainMenuContents(MenuGeneratorsArena.createArenaHostLoginMenu());
return false;
}});
//button (options)
Button optionsButton = new Button();
Label optionsLabel = new Label(100,500,1.0f);
optionsLabel.setText("Options");
optionsButton.addChild(optionsLabel);
rVal.addChild(optionsButton);
optionsButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
WindowUtils.replaceMainMenuContents(MenuGenerators.createOptionsMainMenu());
return false;
}});
//button (sp debug)
Button uiDebugSPQuickstartButton = new Button();
Label uiDebugSPQuickstartLabel = new Label(100,575,1.0f);
uiDebugSPQuickstartLabel.setText("Debug SP Quickstart");
uiDebugSPQuickstartButton.addChild(uiDebugSPQuickstartLabel);
rVal.addChild(uiDebugSPQuickstartButton);
uiDebugSPQuickstartButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
LoadingThread loadingThread = new LoadingThread(LoadingThread.LOAD_DEBUG_RANDOM_SP_WORLD);
Globals.loadingThreadsList.add(loadingThread);
Globals.RUN_CLIENT = true;
Globals.RUN_SERVER = true;
loadingThread.start();
return false;
}});
//button (ui testing)
Button uiTestingButton = new Button();
Label uiTestingLabel = new Label(100,650,1.0f);
uiTestingLabel.setText("UI Testing");
uiTestingButton.addChild(uiTestingLabel);
rVal.addChild(uiTestingButton);
uiTestingButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
WindowUtils.replaceMainMenuContents(MenuGenerators.createUITestMenu());
return false;
}});
return rVal;
}
//Used when we're displaying loading window to make main menu invisible
public static Element createEmptyMainMenu(){
@ -160,14 +70,17 @@ public class MenuGenerators {
rVal.addChild(selectButton);
selectButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
if(SaveUtils.worldHasSave(saveName.toLowerCase())){
//need to log client in
Globals.clientUsername = "username";
Globals.clientPassword = AuthenticationManager.getHashedString("password");
LoadingThread clientThread = new LoadingThread(LoadingThread.LOAD_CHARACTER_SERVER);
Globals.loadingThreadsList.add(clientThread);
LoadingThread serverThread = new LoadingThread(LoadingThread.LOAD_MAIN_GAME);
Globals.loadingThreadsList.add(serverThread);
Globals.RUN_CLIENT = true;
Globals.RUN_SERVER = true;
clientThread.start();
serverThread.start();
clientThread.start();
} else {
Globals.currentSaveName = saveName.toLowerCase();
SaveUtils.loadTerrainAndCreateWorldData();
@ -201,15 +114,26 @@ public class MenuGenerators {
int verticalPosition = 125;
//TODO: add text input to name world
//text entry (address)
TextInput worldNameInput = new TextInput(100,screenTop + 125,1.0f);
worldNameInput.setText("World name");
rVal.addChild(worldNameInput);
//button (create)
Button createButton = new Button();
Label createLabel = new Label(100,screenTop + verticalPosition,1.0f);
createLabel.setText("Not implemented");
createLabel.setText("Create");
createButton.addChild(createLabel);
rVal.addChild(createButton);
createButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
WindowUtils.replaceMainMenuContents(MenuGenerators.createWorldCreationMenu());
String saveName = worldNameInput.getText();
//create save dir
SaveUtils.createOrOverwriteSave(saveName);
//create and save terrain
ServerTerrainManager terrainManager = new ServerTerrainManager(2000,50,100,0.0f,0);
terrainManager.generate();
terrainManager.save(SaveUtils.deriveSaveDirectoryPath(saveName));
WindowUtils.replaceMainMenuContents(MenuGenerators.createWorldSelectMenu());
return false;
}});
@ -324,7 +248,7 @@ public class MenuGenerators {
connectButton.addChild(connectLabel);
rVal.addChild(connectButton);
connectButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
WindowUtils.replaceMainMenuContents(MenuGenerators.createTitleMenu());
WindowUtils.replaceMainMenuContents(MenuGeneratorsTitleMenu.createTitleMenu());
return false;
}});
@ -424,7 +348,7 @@ public class MenuGenerators {
backButton.addChild(backLabel);
rVal.addChild(backButton);
backButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
WindowUtils.replaceMainMenuContents(MenuGenerators.createTitleMenu());
WindowUtils.replaceMainMenuContents(MenuGeneratorsTitleMenu.createTitleMenu());
return false;
}});
@ -442,7 +366,7 @@ public class MenuGenerators {
backButton.addChild(backLabel);
rVal.addChild(backButton);
backButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
WindowUtils.replaceMainMenuContents(MenuGenerators.createTitleMenu());
WindowUtils.replaceMainMenuContents(MenuGeneratorsTitleMenu.createTitleMenu());
return false;
}});
@ -538,7 +462,7 @@ public class MenuGenerators {
}});
//checking macro data is a poor man's check for whether we're arena or full gamemode
if(Globals.server != null && Globals.macroData == null){
// if(Globals.server != null && Globals.macroData == null){
//label 3 (debug)
Button debugButton = new Button();
Label debugLabel = new Label(100,250,1.0f);
@ -549,7 +473,7 @@ public class MenuGenerators {
WindowUtils.replaceWindow(WindowStrings.WINDOW_MENU_INGAME_MAIN, createInGameDebugMainMenu());
return false;
}});
}
// }
return rVal;
}

View File

@ -0,0 +1,103 @@
package electrosphere.menu;
import electrosphere.engine.Globals;
import electrosphere.engine.LoadingThread;
import electrosphere.renderer.ui.ClickableElement;
import electrosphere.renderer.ui.Element;
import electrosphere.renderer.ui.elements.Button;
import electrosphere.renderer.ui.elements.Label;
import electrosphere.renderer.ui.events.ClickEvent;
import electrosphere.renderer.ui.form.FormElement;
public class MenuGeneratorsTitleMenu {
public static Element createTitleMenu(){
FormElement rVal = new FormElement();
//label (title)
Label titleLabel = new Label(100,150,1.0f);
titleLabel.setText("ORPG");
rVal.addChild(titleLabel);
//button (multiplayer)
Button singleplayerButton = new Button();
Label singleplayerLabel = new Label(100,275,1.0f);
singleplayerLabel.setText("Singleplayer");
singleplayerButton.addChild(singleplayerLabel);
rVal.addChild(singleplayerButton);
singleplayerButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
WindowUtils.replaceMainMenuContents(MenuGenerators.createWorldSelectMenu());
// LoadingThread clientThread = new LoadingThread(LoadingThread.LOAD_MAIN_GAME);
// Globals.loadingThreadsList.add(clientThread);
// Globals.RUN_CLIENT = true;
// Globals.RUN_SERVER = true;
// clientThread.start();
return false;
}});
//button (multiplayer)
Button multiplayerButton = new Button();
Label multiplayerLabel = new Label(100,350,1.0f);
multiplayerLabel.setText("Multiplayer");
multiplayerButton.addChild(multiplayerLabel);
rVal.addChild(multiplayerButton);
multiplayerButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
WindowUtils.replaceMainMenuContents(MenuGenerators.createMultiplayerMenu());
return false;
}});
//button (arena)
Button arenaButton = new Button();
Label arenaLabel = new Label(100,425,1.0f);
arenaLabel.setText("Arena");
arenaButton.addChild(arenaLabel);
rVal.addChild(arenaButton);
arenaButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
LoadingThread serverThread = new LoadingThread(LoadingThread.LOAD_ARENA);
Globals.loadingThreadsList.add(serverThread);
Globals.RUN_CLIENT = true;
Globals.RUN_SERVER = true;
serverThread.start();
WindowUtils.replaceMainMenuContents(MenuGeneratorsArena.createArenaHostLoginMenu());
return false;
}});
//button (options)
Button optionsButton = new Button();
Label optionsLabel = new Label(100,500,1.0f);
optionsLabel.setText("Options");
optionsButton.addChild(optionsLabel);
rVal.addChild(optionsButton);
optionsButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
WindowUtils.replaceMainMenuContents(MenuGenerators.createOptionsMainMenu());
return false;
}});
//button (sp debug)
Button uiDebugSPQuickstartButton = new Button();
Label uiDebugSPQuickstartLabel = new Label(100,575,1.0f);
uiDebugSPQuickstartLabel.setText("Debug SP Quickstart");
uiDebugSPQuickstartButton.addChild(uiDebugSPQuickstartLabel);
rVal.addChild(uiDebugSPQuickstartButton);
uiDebugSPQuickstartButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
LoadingThread loadingThread = new LoadingThread(LoadingThread.LOAD_DEBUG_RANDOM_SP_WORLD);
Globals.loadingThreadsList.add(loadingThread);
Globals.RUN_CLIENT = true;
Globals.RUN_SERVER = true;
loadingThread.start();
return false;
}});
//button (ui testing)
Button uiTestingButton = new Button();
Label uiTestingLabel = new Label(100,650,1.0f);
uiTestingLabel.setText("UI Testing");
uiTestingButton.addChild(uiTestingLabel);
rVal.addChild(uiTestingButton);
uiTestingButton.setOnClick(new ClickableElement.ClickEventCallback(){public boolean execute(ClickEvent event){
WindowUtils.replaceMainMenuContents(MenuGenerators.createUITestMenu());
return false;
}});
return rVal;
}
}

View File

@ -116,7 +116,7 @@ public class WindowUtils {
static void initMainMenuWindow(){
Window mainMenuWindow = new Window(0, 0, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT);
Globals.elementManager.registerWindow(WindowStrings.WINDOW_MENU_MAIN, mainMenuWindow);
WindowUtils.replaceMainMenuContents(MenuGenerators.createTitleMenu());
WindowUtils.replaceMainMenuContents(MenuGeneratorsTitleMenu.createTitleMenu());
}
static void initItemDropWindow(){

View File

@ -1077,7 +1077,7 @@ public class RenderUtils {
}
static float MINIMIZATION_DIFF_MAX = 0.1f;
static float MINIMIZATION_DIFF_MAX = 0.001f;
public static Model createMinimizedTerrainModelPrecomputedShader(float[][] heightfield, float[][] texturemap, ShaderProgram program, int stride){
@ -1189,7 +1189,7 @@ public class RenderUtils {
}
boolean textureMatch = false;
float texture = -1;
if(x+stride < width - 1 && y+stride < height -1 &&
if(x+stride < width - 1 && y+stride < height - 1 &&
texturemap[x][y] == texturemap[x+stride][y] &&
texturemap[x][y] == texturemap[x][y+stride] &&
texturemap[x][y] == texturemap[x+stride][y+stride]){
@ -1257,9 +1257,13 @@ public class RenderUtils {
quadCurrent.min = newMax;
quadCurrent.max = newMax;
} else {
//push quad
//push quad that we were building
firstPhaseQuads.add(quadCurrent);
quadCurrent = null;
// quadCurrent = null;
//create new quad from what we were just analyzing
boolean textureMatch = false;
float texture = -1;
quadCurrent = new QuadToGenerate(x,y,x+stride,y+stride,maxVal - minVal,minVal,maxVal,textureMatch,texture);
// System.out.println("Push");
}
}
@ -1286,7 +1290,7 @@ public class RenderUtils {
if(toSkip.contains(currentQuad)){
continue;
}
for(QuadToGenerate currentPotentialMatch : firstPhaseQuads){
for(QuadToGenerate currentPotentialMatch : firstPhaseQuads){
if(currentPotentialMatch.startX <= currentQuad.startX){
continue;
}
@ -1332,7 +1336,7 @@ public class RenderUtils {
}
toSkip.add(currentPotentialMatch);
}
}
}
finalQuads.add(currentQuad);
}
// for(QuadToGenerate currentIteration : firstPhaseQuads){

View File

@ -75,6 +75,7 @@ import electrosphere.controls.MouseCallback;
import electrosphere.engine.Globals;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityTags;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.types.camera.CameraEntityUtils;
import electrosphere.entity.types.hitbox.HitboxData;
@ -549,7 +550,7 @@ public class RenderingEngine {
//
Vector3f cameraPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera);
modelTransformMatrix = new Matrix4f();
for(Entity currentEntity : Globals.entityManager.getDrawable()){
for(Entity currentEntity : Globals.entityManager.getEntitiesWithTag(EntityTags.DRAWABLE)){
Vector3d position = EntityUtils.getPosition(currentEntity);
if(
(boolean)currentEntity.getData(EntityDataStrings.DATA_STRING_DRAW) &&
@ -614,7 +615,7 @@ public class RenderingEngine {
//
Vector3f cameraPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera);
modelTransformMatrix = new Matrix4f();
for(Entity currentEntity : Globals.entityManager.getDrawable()){
for(Entity currentEntity : Globals.entityManager.getEntitiesWithTag(EntityTags.DRAWABLE)){
Vector3d position = EntityUtils.getPosition(currentEntity);
if(
(boolean)currentEntity.getData(EntityDataStrings.DATA_STRING_DRAW) &&
@ -653,7 +654,7 @@ public class RenderingEngine {
glClearBufferfv(GL_COLOR,1,transparencyRevealageClear);
for(Entity currentEntity : Globals.entityManager.getDrawable()){
for(Entity currentEntity : Globals.entityManager.getEntitiesWithTag(EntityTags.DRAWABLE)){
Vector3d position = EntityUtils.getPosition(currentEntity);
if(
(boolean)currentEntity.getData(EntityDataStrings.DATA_STRING_DRAW) &&
@ -709,7 +710,7 @@ public class RenderingEngine {
//
Vector3f cameraPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera);
modelTransformMatrix = new Matrix4f();
for(Entity currentEntity : Globals.entityManager.getDrawable()){
for(Entity currentEntity : Globals.entityManager.getEntitiesWithTag(EntityTags.DRAWABLE)){
Vector3d position = EntityUtils.getPosition(currentEntity);
if(
(boolean)currentEntity.getData(EntityDataStrings.DATA_STRING_DRAW) &&
@ -926,7 +927,7 @@ public class RenderingEngine {
Vector3f cameraPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera);
modelTransformMatrix = new Matrix4f();
for(Entity currentEntity : Globals.entityManager.getDrawable()){
for(Entity currentEntity : Globals.entityManager.getEntitiesWithTag(EntityTags.DRAWABLE)){
Vector3d position = EntityUtils.getPosition(currentEntity);
if(
(boolean)currentEntity.getData(EntityDataStrings.DATA_STRING_DRAW) &&
@ -1158,7 +1159,7 @@ public class RenderingEngine {
// D R A W A L L E N T I T I E S
//
Vector3f cameraPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera);
for(Entity currentEntity : Globals.entityManager.getDrawable()){
for(Entity currentEntity : Globals.entityManager.getEntitiesWithTag(EntityTags.DRAWABLE)){
Vector3d position = EntityUtils.getPosition(currentEntity);
if(
(boolean)currentEntity.getData(EntityDataStrings.DATA_STRING_DRAW) &&
@ -1196,7 +1197,7 @@ public class RenderingEngine {
//Draw front faces of all non-volumetrics
//
cameraPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera);
for(Entity currentEntity : Globals.entityManager.getDrawable()){
for(Entity currentEntity : Globals.entityManager.getEntitiesWithTag(EntityTags.DRAWABLE)){
Vector3d position = EntityUtils.getPosition(currentEntity);
if(
(boolean)currentEntity.getData(EntityDataStrings.DATA_STRING_DRAW) &&
@ -1245,7 +1246,7 @@ public class RenderingEngine {
//
// D R A W A L L E N T I T I E S
//
for(Entity currentEntity : Globals.entityManager.getDrawable()){
for(Entity currentEntity : Globals.entityManager.getEntitiesWithTag(EntityTags.DRAWABLE)){
Vector3d position = EntityUtils.getPosition(currentEntity);
if(
(boolean)currentEntity.getData(EntityDataStrings.DATA_STRING_DRAW) &&

View File

@ -3,6 +3,7 @@ package electrosphere.renderer.light;
import electrosphere.engine.Globals;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityTags;
import org.joml.Vector3d;
import org.joml.Vector3f;
@ -16,7 +17,7 @@ public class LightEntityUtils {
public static Entity createDirectionalLight(Vector3f position, Vector3f ambient, Vector3f diffuse, Vector3f specular){
Entity rVal = new Entity();
Globals.entityManager.registerEntity(rVal);
Globals.entityManager.registerLightEntity(rVal);
Globals.entityManager.registerEntityToTag(rVal, EntityTags.LIGHT);
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_TYPE, EntityDataStrings.DATA_STRING_LIGHT_TYPE_DIRECTIONAL);
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3d(position.x,position.y,position.z));
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_AMBIENT, ambient);
@ -28,7 +29,7 @@ public class LightEntityUtils {
public static Entity createPointLight(Vector3f position, Vector3f ambient, Vector3f diffuse, Vector3f specular, float constant, float linear, float quadratic){
Entity rVal = new Entity();
Globals.entityManager.registerEntity(rVal);
Globals.entityManager.registerLightEntity(rVal);
Globals.entityManager.registerEntityToTag(rVal, EntityTags.LIGHT);
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_TYPE, EntityDataStrings.DATA_STRING_LIGHT_TYPE_POINT);
rVal.putData(EntityDataStrings.DATA_STRING_POSITION, new Vector3d(position.x,position.y,position.z));
rVal.putData(EntityDataStrings.DATA_STRING_LIGHT_AMBIENT, ambient);

View File

@ -3,6 +3,7 @@ package electrosphere.server.ai.creature;
import electrosphere.engine.Globals;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityTags;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.attack.AttackTree;
import electrosphere.entity.state.movement.GroundMovementTree;
@ -101,7 +102,7 @@ public class MindlessAttacker extends AI{
void searchForTarget(){
Vector3d position = EntityUtils.getPosition(character);
for(Entity current : Globals.entityManager.getLifeStateEntities()){
for(Entity current : Globals.entityManager.getEntitiesWithTag(EntityTags.LIFE_STATE)){
if(current != character){
Vector3d potentialTargetPosition = EntityUtils.getPosition(current);
if(position.distance(potentialTargetPosition) < aggroRange){

View File

@ -3,6 +3,7 @@ package electrosphere.server.ai.creature;
import electrosphere.engine.Globals;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityTags;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.attack.AttackTree;
import electrosphere.entity.state.equip.EquipState;
@ -192,7 +193,7 @@ public class OpportunisticAttacker extends AI {
void searchForTarget(){
Vector3d position = EntityUtils.getPosition(character);
for(Entity current : Globals.entityManager.getLifeStateEntities()){
for(Entity current : Globals.entityManager.getEntitiesWithTag(EntityTags.LIFE_STATE)){
if(current != character){
Vector3d potentialTargetPosition = EntityUtils.getPosition(current);
if(position.distance(potentialTargetPosition) < aggroRange){
@ -219,7 +220,7 @@ public class OpportunisticAttacker extends AI {
boolean weaponInRange(){
boolean rVal = false;
Vector3d position = EntityUtils.getPosition(character);
for(Entity current : Globals.entityManager.getItemEntities()){
for(Entity current : Globals.entityManager.getEntitiesWithTag(EntityTags.ITEM)){
if(current != character && ItemUtils.isItem(current) && ItemUtils.isWeapon(current)){
Vector3d potentialTargetPosition = EntityUtils.getPosition(current);
if(position.distance(potentialTargetPosition) < weaponSeekRange){

View File

@ -0,0 +1,58 @@
package electrosphere.server.ai.creature.adventurer;
import org.joml.Vector3d;
import electrosphere.engine.Globals;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.movement.GroundMovementTree;
import electrosphere.entity.state.movement.GroundMovementTree.MovementRelativeFacing;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.game.server.town.Town;
import electrosphere.server.ai.AI;
public class SeekTown extends AI {
Entity character;
Town target = null;
Vector3d targetPos = null;
public SeekTown(Entity character){
this.character = character;
}
public static void attachToCreature(Entity creature){
SeekTown ai = new SeekTown(creature);
Globals.aiManager.registerAI(ai);
}
@Override
public void simulate() {
if(target == null){
if(Globals.macroData.getTowns().size() > 0){
target = Globals.macroData.getTowns().get(0);
targetPos = new Vector3d(
Globals.commonWorldData.convertWorldToReal(target.getPositions().get(0).x),
0,
Globals.commonWorldData.convertWorldToReal(target.getPositions().get(0).y)
);
targetPos.y = Globals.commonWorldData.getElevationAtPoint(targetPos);
System.out.println("Target pos: " + targetPos);
}
}
moveToTarget();
}
void moveToTarget(){
Vector3d targetPosition = targetPos;
Vector3d characterPosition = EntityUtils.getPosition(character);
Vector3d moveVector = new Vector3d(targetPosition).sub(characterPosition).normalize();
CreatureUtils.setFacingVector(character, new Vector3d((float)moveVector.x,(float)moveVector.y,(float)moveVector.z));
GroundMovementTree characterMoveTree = (GroundMovementTree)CreatureUtils.getEntityMovementTree(character);
if(characterMoveTree.getState()==GroundMovementTree.MovementTreeState.IDLE || characterMoveTree.getState()==GroundMovementTree.MovementTreeState.SLOWDOWN){
characterMoveTree.start(MovementRelativeFacing.FORWARD);
}
}
}

View File

@ -0,0 +1,51 @@
package electrosphere.server.ai.creature.party;
import org.joml.Vector3d;
import electrosphere.engine.Globals;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.movement.GroundMovementTree;
import electrosphere.entity.state.movement.GroundMovementTree.MovementRelativeFacing;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.server.ai.AI;
public class PartyFollower extends AI {
Entity character;
Entity target;
double threshold = 0;
public PartyFollower(Entity character, Entity target, double threshold){
this.character = character;
this.target = target;
this.threshold = threshold;
}
public static void attachToCreature(Entity creature, Entity target, double threshold){
PartyFollower ai = new PartyFollower(creature, target, threshold);
Globals.aiManager.registerAI(ai);
}
@Override
public void simulate() {
if(target == null){
Vector3d characterPosition = EntityUtils.getPosition(character);
Vector3d targetPosition = EntityUtils.getPosition(target);
if(targetPosition.distance(characterPosition) > threshold){
moveToTarget();
}
}
}
void moveToTarget(){
Vector3d targetPosition = EntityUtils.getPosition(target);
Vector3d characterPosition = EntityUtils.getPosition(character);
Vector3d moveVector = new Vector3d(targetPosition).sub(characterPosition).normalize();
CreatureUtils.setFacingVector(character, new Vector3d((float)moveVector.x,(float)moveVector.y,(float)moveVector.z));
GroundMovementTree characterMoveTree = (GroundMovementTree)CreatureUtils.getEntityMovementTree(character);
if(characterMoveTree.getState()==GroundMovementTree.MovementTreeState.IDLE || characterMoveTree.getState()==GroundMovementTree.MovementTreeState.SLOWDOWN){
characterMoveTree.start(MovementRelativeFacing.FORWARD);
}
}
}

View File

@ -19,7 +19,9 @@ import java.util.List;
* Container for entities loaded into memory. This isn't intended to be in charge
* of simulation. It just acts as an object to relate players and entities by location.
* This SHOULD be used for networking purposes. This is the mechanism to scope
* network messages by location.
* network messages by location. If you are looking for something closer to a scene from
* a traditional game engine, EntityManager is effectively a scene for all intents and
* purposes.
*
*/
public class ServerDataCell {

View File

@ -0,0 +1,24 @@
package electrosphere.server.entitygroup;
import java.util.LinkedList;
import java.util.List;
import electrosphere.entity.Entity;
public class EntityGroup {
List<Entity> members;
public EntityGroup(){
members = new LinkedList<Entity>();
}
public void addMember(Entity newMember){
members.add(newMember);
}
public List<Entity> getMemebers(){
return members;
}
}

View File

@ -1,4 +1,4 @@
package electrosphere.game.server.region;
package electrosphere.server.region;
import java.util.List;

View File

@ -1,4 +1,4 @@
package electrosphere.game.server.region;
package electrosphere.server.region;
import java.util.List;

View File

@ -5,6 +5,7 @@ import electrosphere.engine.Globals;
import electrosphere.engine.Main;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityTags;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.BehaviorTree;
import electrosphere.entity.state.IdleTree;
@ -49,7 +50,7 @@ public class MicroSimulation {
//simulate ai
Globals.aiManager.simulate();
//update actor animations
for(Entity currentEntity : Globals.entityManager.getDrawable()){
for(Entity currentEntity : Globals.entityManager.getEntitiesWithTag(EntityTags.DRAWABLE)){
//fetch actor
Actor currentActor = EntityUtils.getActor(currentEntity);
//increment animations
@ -58,43 +59,43 @@ public class MicroSimulation {
}
}
//make items play idle animation
for(Entity item : Globals.entityManager.getItemEntities()){
for(Entity item : Globals.entityManager.getEntitiesWithTag(EntityTags.ITEM)){
ItemUtils.updateItemActorAnimation(item);
}
//simulate creature behavior trees
for(Entity currentMoveable : Globals.entityManager.getMoveable()){
BehaviorTree behaviorTree = CreatureUtils.getEntityMovementTree(currentMoveable);
behaviorTree.simulate();
}
//sprint tree
for(Entity currentSprint : Globals.entityManager.getSprintables()){
SprintTree sprintTree = CreatureUtils.getSprintTree(currentSprint);
sprintTree.simulate();
}
//simulate creature gravity trees
for(Entity currentGravity : Globals.entityManager.getGravityEntities()){
GravityTree gravityTree = (GravityTree)currentGravity.getData(EntityDataStrings.GRAVITY_TREE);
gravityTree.simulate(Main.deltaFrames);
}
//attacker behavior tree
for(Entity currentAttacker : Globals.entityManager.getAttackerEntities()){
AttackTree attackTree = CreatureUtils.getAttackTree(currentAttacker);
attackTree.simulate();
}
//idle behavior tree
for(Entity currentIdler : Globals.entityManager.getCreatureEntities()){
IdleTree idleTree = CreatureUtils.getIdleTree(currentIdler);
idleTree.simulate();
}
//life state updates
for(Entity lifeStateEntity : Globals.entityManager.getLifeStateEntities()){
LifeState lifeState = LifeUtils.getLifeState(lifeStateEntity);
lifeState.simulate();
}
// for(Entity currentMoveable : Globals.entityManager.getEntitiesWithTag(EntityTags.MOVEABLE)){
// BehaviorTree behaviorTree = CreatureUtils.getEntityMovementTree(currentMoveable);
// behaviorTree.simulate(Main.deltaFrames);
// }
// //sprint tree
// for(Entity currentSprint : Globals.entityManager.getEntitiesWithTag(EntityTags.SPRINTABLE)){
// SprintTree sprintTree = CreatureUtils.getSprintTree(currentSprint);
// sprintTree.simulate(Main.deltaFrames);
// }
// //simulate creature gravity trees
// for(Entity currentGravity : Globals.entityManager.getEntitiesWithTag(EntityTags.GRAVITY)){
// GravityTree gravityTree = (GravityTree)currentGravity.getData(EntityDataStrings.GRAVITY_TREE);
// gravityTree.simulate(Main.deltaFrames);
// }
// //attacker behavior tree
// for(Entity currentAttacker : Globals.entityManager.getEntitiesWithTag(EntityTags.ATTACKER)){
// AttackTree attackTree = CreatureUtils.getAttackTree(currentAttacker);
// attackTree.simulate(Main.deltaFrames);
// }
// //idle behavior tree
// for(Entity currentIdler : Globals.entityManager.getEntitiesWithTag(EntityTags.CREATURE)){
// IdleTree idleTree = CreatureUtils.getIdleTree(currentIdler);
// idleTree.simulate(Main.deltaFrames);
// }
// //life state updates
// for(Entity lifeStateEntity : Globals.entityManager.getEntitiesWithTag(EntityTags.LIFE_STATE)){
// LifeState lifeState = LifeUtils.getLifeState(lifeStateEntity);
// lifeState.simulate(Main.deltaFrames);
// }
//particle state updates
for(Entity particle : Globals.entityManager.getParticles()){
ParticleTree tree = ParticleUtils.getParticleTree(particle);
tree.simulate();
for(Entity particle : Globals.entityManager.getEntitiesWithTag(EntityTags.PARTICLE)){
// ParticleTree tree = ParticleUtils.getParticleTree(particle);
// tree.simulate(Main.deltaFrames);
ParticleUtils.makeParticleBillboardFaceCamera(particle);
}
//update attached entity positions
@ -110,23 +111,27 @@ public class MicroSimulation {
}
}
//tally collidables and offset position accordingly
for(Entity currentCollidable : Globals.entityManager.getCollidables()){
CollidableTree tree = CollidableTree.getCollidableTree(currentCollidable);
tree.simulate();
}
// for(Entity currentCollidable : Globals.entityManager.getEntitiesWithTag(EntityTags.COLLIDABLE)){
// CollidableTree tree = CollidableTree.getCollidableTree(currentCollidable);
// tree.simulate(Main.deltaFrames);
// }
//targeting crosshair
if(Globals.RUN_CLIENT){
Crosshair.checkTargetable();
Crosshair.updateTargetCrosshairPosition();
}
//simulate behavior trees
Globals.entityManager.simulateBehaviorTrees(Main.deltaFrames);
//sum collidable impulses
for(Entity collidable : Globals.entityManager.getEntitiesWithTag(EntityTags.COLLIDABLE)){
CollidableTree.getCollidableTree(collidable).simulate(Main.deltaFrames);
}
//clear collidable impulse lists
Globals.collisionEngine.clearCollidableImpulseLists();
//delete all client side entities that aren't in visible chunks
if(Globals.RUN_CLIENT){
Globals.entityManager.clearOutOfBoundsEntities();
}
//simulate behavior trees
Globals.entityManager.simulateBehaviorTrees();
//data cell manager update
if(Globals.dataCellManager != null){
boolean playerHasChangedChunk = Globals.dataCellManager.updatePlayerGroundCellPositions();