Targeting Crosshair

This commit is contained in:
austin 2021-11-06 16:39:59 -04:00
parent e506dc9aa0
commit 1cfeb5c173
38 changed files with 179 additions and 64 deletions

View File

@ -83,7 +83,8 @@
"BLENDER_TRANSFORM",
"SENTIENT",
"ATTACKER",
"GRAVITY"
"GRAVITY",
"TARGETABLE"
],
"movementSystems" : [
{
@ -207,7 +208,8 @@
"BLENDER_TRANSFORM",
"SENTIENT",
"ATTACKER",
"GRAVITY"
"GRAVITY",
"TARGETABLE"
],
"movementSystems" : [
{

View File

@ -35,7 +35,8 @@
"tokens" : [
"GRAVITY",
"WEAPON",
"RANGED"
"RANGED",
"TARGETABLE"
],
"collidable": {
"type" : "CUBE",

Binary file not shown.

View File

@ -125,6 +125,12 @@
"/Textures/arrow1.png",
"/Textures/arrow1.png"
]
},
"Models/lockoncrosshair1.fbx" : {
"Cube" : [
"/Textures/w1.png",
"/Textures/w1.png"
]
}
}
}

View File

@ -13,7 +13,7 @@ import electrosphere.game.client.player.ClientPlayerData;
import electrosphere.game.client.terrain.manager.ClientTerrainManager;
import electrosphere.game.client.world.ClientWorldData;
import electrosphere.game.collision.CommonWorldData;
import electrosphere.game.state.MacroSimulation;
import electrosphere.game.simulation.MacroSimulation;
import electrosphere.game.server.terrain.manager.ServerTerrainManager;
import electrosphere.game.server.world.ServerWorldData;
import electrosphere.entity.types.attach.AttachUtils;
@ -30,7 +30,7 @@ import electrosphere.game.server.terrain.models.TerrainModification;
import electrosphere.game.server.town.Town;
import electrosphere.game.server.world.MacroData;
import electrosphere.game.server.datacell.DataCellManager;
import electrosphere.game.state.MicroSimulation;
import electrosphere.game.simulation.MicroSimulation;
import electrosphere.logger.LoggerInterface;
import electrosphere.main.Globals;
import static electrosphere.main.Globals.loadingBox;
@ -42,6 +42,7 @@ import electrosphere.renderer.ActorUtils;
import electrosphere.renderer.Model;
import electrosphere.renderer.RenderUtils;
import electrosphere.engine.assetmanager.AssetDataStrings;
import electrosphere.game.client.targeting.crosshair.Crosshair;
import electrosphere.game.server.pathfinding.NavMeshPathfinder;
import electrosphere.game.server.pathfinding.navmesh.NavCube;
import electrosphere.game.server.pathfinding.navmesh.NavMesh;
@ -486,6 +487,12 @@ public class LoadingThread extends Thread {
Globals.playerCamera = CameraEntityUtils.spawnBasicCameraEntity(new Vector3f(1,0,1), new Vector3f(0,0,0));
/*
Targeting crosshair
*/
Crosshair.initCrossHairEntity();
}
static void initMacroSimulation(){

View File

@ -31,6 +31,7 @@ public class EntityManager {
static CopyOnWriteArrayList<Entity> particleList = new CopyOnWriteArrayList();
static CopyOnWriteArrayList<Entity> gravityList = new CopyOnWriteArrayList();
static CopyOnWriteArrayList<Entity> collidableList = new CopyOnWriteArrayList();
static CopyOnWriteArrayList<Entity> targetableList = new CopyOnWriteArrayList();
public EntityManager(){
@ -137,6 +138,14 @@ public class EntityManager {
return collidableList;
}
public void registerTargetableEntity(Entity e){
targetableList.add(e);
}
public CopyOnWriteArrayList<Entity> getTargetables(){
return targetableList;
}
public void deregisterEntity(Entity e){
if(lightList.contains(e)){
lightList.remove(e);
@ -175,6 +184,9 @@ public class EntityManager {
if(collidableList.contains(e)){
collidableList.remove(e);
}
if(targetableList.contains(e)){
targetableList.remove(e);
}
}
public void recursiveDeregister(Entity target){

View File

@ -95,4 +95,8 @@ public class EntityUtils {
return (CollidableTree)e.getData(EntityDataStrings.COLLIDABLE_TREE);
}
public static void setVisible(Entity entity, boolean visible){
entity.putData(EntityDataStrings.DATA_STRING_DRAW, visible);
}
}

View File

@ -5,7 +5,7 @@ import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.entity.types.hitbox.HitboxUtils;
import electrosphere.game.config.creature.type.AttackMove;
import electrosphere.game.data.creature.type.AttackMove;
import electrosphere.main.Globals;
import electrosphere.net.parser.net.message.EntityMessage;
import electrosphere.renderer.Actor;

View File

@ -8,8 +8,8 @@ import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.movement.GroundMovementTree;
import electrosphere.entity.types.hitbox.HitboxData;
import electrosphere.entity.types.hitbox.HitboxUtils;
import electrosphere.game.config.creature.type.CreatureType;
import electrosphere.game.config.creature.type.MovementSystem;
import electrosphere.game.data.creature.type.CreatureType;
import electrosphere.game.data.creature.type.MovementSystem;
import electrosphere.entity.state.AttackTree;
import electrosphere.entity.state.GravityTree;
import electrosphere.entity.state.IdleTree;
@ -18,8 +18,8 @@ import electrosphere.entity.types.collision.CollisionObjUtils;
import electrosphere.entity.types.life.LifeState;
import electrosphere.game.collision.PhysicsUtils;
import electrosphere.game.collision.collidable.Collidable;
import electrosphere.game.config.creature.type.AttackMove;
import electrosphere.game.config.creature.type.CollidableTemplate;
import electrosphere.game.data.creature.type.AttackMove;
import electrosphere.game.data.creature.type.CollidableTemplate;
import electrosphere.logger.LoggerInterface;
import electrosphere.main.Globals;
import electrosphere.main.Main;
@ -123,6 +123,9 @@ public class CreatureUtils {
rVal.putData(EntityDataStrings.GRAVITY_TREE, gravityTree);
Globals.entityManager.registerGravityEntity(rVal);
break;
case "TARGETABLE":
Globals.entityManager.registerTargetableEntity(rVal);
break;
}
}
//add all attack moves

View File

@ -8,8 +8,8 @@ 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.game.data.foliage.type.FoliageType;
import electrosphere.game.data.foliage.type.PhysicsObject;
import electrosphere.main.Globals;
import electrosphere.renderer.ActorUtils;
import java.util.List;

View File

@ -12,9 +12,9 @@ import electrosphere.entity.types.hitbox.HitboxData;
import electrosphere.entity.types.hitbox.HitboxUtils;
import electrosphere.game.collision.PhysicsUtils;
import electrosphere.game.collision.collidable.Collidable;
import electrosphere.game.config.creature.type.CollidableTemplate;
import electrosphere.game.config.creature.type.CreatureType;
import electrosphere.game.config.item.type.Item;
import electrosphere.game.data.creature.type.CollidableTemplate;
import electrosphere.game.data.creature.type.CreatureType;
import electrosphere.game.data.item.type.Item;
import electrosphere.main.Globals;
import electrosphere.net.parser.net.message.EntityMessage;
import electrosphere.net.parser.net.message.NetworkMessage;
@ -86,6 +86,9 @@ public class ItemUtils {
rVal.putData(EntityDataStrings.GRAVITY_TREE, gravityTree);
Globals.entityManager.registerGravityEntity(rVal);
break;
case "TARGETABLE":
Globals.entityManager.registerTargetableEntity(rVal);
break;
}
}
rVal.putData(EntityDataStrings.ITEM_IS_ITEM, true);

View File

@ -1,7 +1,7 @@
package electrosphere.entity.types.life;
import electrosphere.entity.Entity;
import electrosphere.game.config.creature.type.HealthSystem;
import electrosphere.game.data.creature.type.HealthSystem;
public class LifeState {

View File

@ -5,8 +5,8 @@ import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.types.collision.CollisionObjUtils;
import electrosphere.game.collision.collidable.Collidable;
import electrosphere.game.config.structure.type.model.CollisionObjectTemplate;
import electrosphere.game.config.structure.type.model.StructureType;
import electrosphere.game.data.structure.type.model.CollisionObjectTemplate;
import electrosphere.game.data.structure.type.model.StructureType;
import electrosphere.main.Globals;
import electrosphere.net.parser.net.message.EntityMessage;
import electrosphere.net.parser.net.message.NetworkMessage;

View File

@ -0,0 +1,73 @@
package electrosphere.game.client.targeting.crosshair;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityUtils;
import electrosphere.main.Globals;
import org.joml.Vector3d;
/**
*
* @author amaterasu
*/
public class Crosshair {
static Entity crossHairEntity;
static float rotationTheta = 0;
static float bobTheta = 0;
static float bobMagnitude = 0.1f;
static float offsetVertical = 1;
static Entity currentTarget = null;
public static void initCrossHairEntity(){
crossHairEntity = EntityUtils.spawnDrawableEntity("/Models/lockoncrosshair1.fbx");
EntityUtils.setVisible(crossHairEntity, false);
}
static final float TARGET_MAX_DIST = 1;
public static void checkTargetable(){
if(crossHairEntity != null && Globals.playerCharacter != null){
Vector3d parentPos = EntityUtils.getPosition(Globals.playerCharacter);
if(currentTarget == null){
Entity target = null;
double dist = 100;
for(Entity entity : Globals.entityManager.getTargetables()){
double currentDist = parentPos.distance(EntityUtils.getPosition(entity));
if(currentDist < dist && currentDist <= TARGET_MAX_DIST && entity != Globals.playerCharacter){
target = entity;
dist = currentDist;
}
}
if(target != null){
// System.out.println("Found target!");
currentTarget = target;
EntityUtils.setVisible(crossHairEntity, true);
}
} else {
if(parentPos.distance(EntityUtils.getPosition(currentTarget)) > TARGET_MAX_DIST){
currentTarget = null;
EntityUtils.setVisible(crossHairEntity, false);
}
}
}
}
public static void updateTargetCrosshairPosition(){
if(crossHairEntity != null && currentTarget != null){
rotationTheta += 0.01;
if(rotationTheta > Math.PI * 2){
rotationTheta = 0;
}
bobTheta += 0.01;
if(bobTheta > Math.PI * 2){
bobTheta = 0;
}
Vector3d crosshairPos = EntityUtils.getPosition(crossHairEntity);
crosshairPos.set(new Vector3d(EntityUtils.getPosition(currentTarget)).add(0,offsetVertical + Math.sin(bobTheta) * bobMagnitude,0));
// EntityUtils.getRotation(crossHairEntity).rotationZ(rotationTheta);
EntityUtils.getRotation(crossHairEntity).rotationXYZ((float)-Math.PI/2.0f, 0, rotationTheta);
}
}
}

View File

@ -1,9 +1,9 @@
package electrosphere.game.config;
package electrosphere.game.data;
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.game.data.creature.type.model.CreatureTypeMap;
import electrosphere.game.data.foliage.type.model.FoliageTypeMap;
import electrosphere.game.data.item.type.model.ItemTypeMap;
import electrosphere.game.data.structure.type.model.StructureTypeMap;
import electrosphere.game.server.race.model.RaceMap;
import electrosphere.game.server.symbolism.model.SymbolMap;
import electrosphere.util.FileUtils;

View File

@ -1,4 +1,4 @@
package electrosphere.game.config.creature.type;
package electrosphere.game.data.creature.type;
/**
*

View File

@ -1,4 +1,4 @@
package electrosphere.game.config.creature.type;
package electrosphere.game.data.creature.type;
public class BodyPart {
int bodyPartClass;

View File

@ -1,4 +1,4 @@
package electrosphere.game.config.creature.type;
package electrosphere.game.data.creature.type;
/**
*

View File

@ -1,4 +1,4 @@
package electrosphere.game.config.creature.type;
package electrosphere.game.data.creature.type;
import electrosphere.entity.types.hitbox.HitboxData;
import java.util.List;

View File

@ -1,4 +1,4 @@
package electrosphere.game.config.creature.type;
package electrosphere.game.data.creature.type;
/**
*

View File

@ -1,4 +1,4 @@
package electrosphere.game.config.creature.type;
package electrosphere.game.data.creature.type;
public class MovementSystem {
String type;

View File

@ -1,6 +1,6 @@
package electrosphere.game.config.creature.type.model;
package electrosphere.game.data.creature.type.model;
import electrosphere.game.config.creature.type.CreatureType;
import electrosphere.game.data.creature.type.CreatureType;
import java.util.List;
public class CreatureTypeMap {

View File

@ -1,4 +1,4 @@
package electrosphere.game.config.foliage.type;
package electrosphere.game.data.foliage.type;
import java.util.List;

View File

@ -1,6 +1,4 @@
package electrosphere.game.config.foliage.type;
import electrosphere.game.config.creature.type.*;
package electrosphere.game.data.foliage.type;
/**
*

View File

@ -1,6 +1,6 @@
package electrosphere.game.config.foliage.type.model;
package electrosphere.game.data.foliage.type.model;
import electrosphere.game.config.foliage.type.FoliageType;
import electrosphere.game.data.foliage.type.FoliageType;
import java.util.List;
/**

View File

@ -1,7 +1,7 @@
package electrosphere.game.config.item.type;
package electrosphere.game.data.item.type;
import electrosphere.entity.types.hitbox.HitboxData;
import electrosphere.game.config.creature.type.CollidableTemplate;
import electrosphere.game.data.creature.type.CollidableTemplate;
import java.util.List;
public class Item {

View File

@ -1,6 +1,6 @@
package electrosphere.game.config.item.type.model;
package electrosphere.game.data.item.type.model;
import electrosphere.game.config.item.type.Item;
import electrosphere.game.data.item.type.Item;
import java.util.List;
public class ItemTypeMap {

View File

@ -1,4 +1,4 @@
package electrosphere.game.config.structure.type.model;
package electrosphere.game.data.structure.type.model;
/**
*

View File

@ -1,4 +1,4 @@
package electrosphere.game.config.structure.type.model;
package electrosphere.game.data.structure.type.model;
import java.util.List;

View File

@ -1,4 +1,4 @@
package electrosphere.game.config.structure.type.model;
package electrosphere.game.data.structure.type.model;
import java.util.List;

View File

@ -1,7 +1,7 @@
package electrosphere.game.server.structure.virtual;
import electrosphere.entity.types.structure.StructureUtils;
import electrosphere.game.config.structure.type.model.StructureType;
import electrosphere.game.data.structure.type.model.StructureType;
import electrosphere.main.Globals;
import electrosphere.game.server.character.Character;
import java.util.LinkedList;

View File

@ -1,9 +1,9 @@
package electrosphere.game.state;
package electrosphere.game.simulation;
import electrosphere.game.server.civilization.Civilization;
import electrosphere.game.server.civilization.model.CivilizationMap;
import electrosphere.game.config.creature.type.CreatureType;
import electrosphere.game.config.creature.type.model.CreatureTypeMap;
import electrosphere.game.data.creature.type.CreatureType;
import electrosphere.game.data.creature.type.model.CreatureTypeMap;
import electrosphere.game.server.culture.Culture;
import electrosphere.game.server.culture.religion.Religion;
import electrosphere.game.server.structure.virtual.Structure;

View File

@ -1,4 +1,4 @@
package electrosphere.game.state;
package electrosphere.game.simulation;
import electrosphere.entity.types.attach.AttachUtils;
import electrosphere.entity.Entity;
@ -16,6 +16,7 @@ import electrosphere.entity.types.item.ItemUtils;
import electrosphere.entity.types.life.LifeState;
import electrosphere.entity.types.life.LifeUtils;
import electrosphere.entity.types.particle.ParticleUtils;
import electrosphere.game.client.targeting.crosshair.Crosshair;
import electrosphere.main.Globals;
import static electrosphere.main.Main.deltaTime;
import electrosphere.renderer.Actor;
@ -103,6 +104,11 @@ public class MicroSimulation {
CollidableTree tree = EntityUtils.getCollidableTree(currentCollidable);
tree.simulate();
}
//targeting crosshair
if(Globals.RUN_CLIENT){
Crosshair.checkTargetable();
Crosshair.updateTargetCrosshairPosition();
}
//clear collidable impulse lists
Globals.collisionEngine.clearCollidableImpulseLists();
//delete all client side entities that aren't in visible chunks

View File

@ -17,7 +17,7 @@ public class LoggerInterface {
public static Logger loggerEngine;
public static void initLoggers(){
loggerNetworking = new Logger(LogLevel.DEBUG);
loggerNetworking = new Logger(LogLevel.WARNING);
loggerFileIO = new Logger(LogLevel.WARNING);
loggerGameLogic = new Logger(LogLevel.WARNING);
loggerRenderer = new Logger(LogLevel.WARNING);

View File

@ -22,19 +22,19 @@ import electrosphere.engine.LoadingThread;
import electrosphere.game.config.UserSettings;
import electrosphere.game.server.ai.AIManager;
import electrosphere.game.server.character.Character;
import electrosphere.game.config.creature.type.model.CreatureTypeMap;
import electrosphere.game.config.item.type.model.ItemTypeMap;
import electrosphere.game.config.structure.type.model.StructureTypeMap;
import electrosphere.game.data.creature.type.model.CreatureTypeMap;
import electrosphere.game.data.item.type.model.ItemTypeMap;
import electrosphere.game.data.structure.type.model.StructureTypeMap;
import electrosphere.game.server.db.DatabaseController;
import electrosphere.game.server.structure.virtual.Structure;
import electrosphere.game.server.structure.virtual.StructureManager;
import electrosphere.game.state.MacroSimulation;
import electrosphere.game.simulation.MacroSimulation;
import electrosphere.game.server.terrain.manager.ServerTerrainManager;
import electrosphere.game.server.town.Town;
import electrosphere.game.server.world.ServerWorldData;
import electrosphere.game.server.world.MacroData;
import electrosphere.game.server.datacell.DataCellManager;
import electrosphere.game.state.MicroSimulation;
import electrosphere.game.simulation.MicroSimulation;
import electrosphere.menu.Menu;
import electrosphere.net.client.ClientNetworking;
import electrosphere.net.server.Player;
@ -127,8 +127,8 @@ public class Globals {
//
// Game config
//
public static electrosphere.game.config.Config gameConfigDefault;
public static electrosphere.game.config.Config gameConfigCurrent;
public static electrosphere.game.data.Config gameConfigDefault;
public static electrosphere.game.data.Config gameConfigCurrent;
//
// Database stuff
@ -300,8 +300,8 @@ public class Globals {
public static boolean RENDER_FLAG_RENDER_SHADOW_MAP = false;
public static boolean RENDER_FLAG_RENDER_SCREEN_FRAMEBUFFER_CONTENT = false;
public static boolean RENDER_FLAG_RENDER_SCREEN_FRAMEBUFFER = false;
public static boolean RENDER_FLAG_RENDER_BLACK_BACKGROUND = false;
public static boolean RENDER_FLAG_RENDER_WHITE_BACKGROUND = true;
public static boolean RENDER_FLAG_RENDER_BLACK_BACKGROUND = true;
public static boolean RENDER_FLAG_RENDER_WHITE_BACKGROUND = false;
public static boolean RENDER_FLAG_RENDER_UI = true;
@ -333,7 +333,7 @@ public class Globals {
//nav mesh manager
navMeshManager = new NavMeshManager();
//game config
gameConfigDefault = electrosphere.game.config.Config.loadDefaultConfig();
gameConfigDefault = electrosphere.game.data.Config.loadDefaultConfig();
gameConfigCurrent = gameConfigDefault;
//player manager
playerManager = new PlayerManager();

View File

@ -23,8 +23,8 @@ import electrosphere.game.server.saves.SaveUtils;
import electrosphere.game.server.terrain.manager.ServerTerrainManager;
import electrosphere.game.server.world.MacroData;
import electrosphere.game.server.world.ServerWorldData;
import electrosphere.game.state.MacroSimulation;
import electrosphere.game.state.MicroSimulation;
import electrosphere.game.simulation.MacroSimulation;
import electrosphere.game.simulation.MicroSimulation;
import electrosphere.logger.LoggerInterface;
import electrosphere.renderer.RenderingEngine;
import electrosphere.util.FileUtils;

View File

@ -6,7 +6,7 @@ import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.types.hitbox.HitboxData;
import electrosphere.entity.types.hitbox.HitboxUtils;
import electrosphere.game.config.creature.type.CollidableTemplate;
import electrosphere.game.data.creature.type.CollidableTemplate;
import electrosphere.game.server.pathfinding.navmesh.NavCube;
import electrosphere.game.server.pathfinding.navmesh.NavMesh;
import electrosphere.game.server.pathfinding.navmesh.NavShape;

View File

@ -1,7 +1,7 @@
package electrosphere.util.worldviewer;
import com.google.gson.Gson;
import electrosphere.game.state.MacroSimulation;
import electrosphere.game.simulation.MacroSimulation;
import electrosphere.game.server.terrain.manager.ServerTerrainManager;
import electrosphere.game.server.terrain.models.TerrainModel;
import electrosphere.main.Globals;