hitboxes - refactoring work, documentation

This commit is contained in:
austin 2024-05-26 13:28:11 -04:00
parent 29f5496e23
commit b1d79dbc16
25 changed files with 175 additions and 42 deletions

View File

@ -9,6 +9,7 @@
- @subpage timekeeper
- @subpage archimprovementtargets
- @subpage savesindex
- @subpage hitboxesindex
# What is this section

View File

@ -0,0 +1,29 @@
@page hitboxesindex Hitboxes
# Architecture Highest Level
New architecture needs to be something like
Per realm/client scene, we have a collision engine that has a whole bunch of capsules.
We update those collision engines at the top of the frame.
On collision, run collision logic
# Design Notes
We want to have one collision per "object" per frame. IE, lets say you have a sword with two hitboxes on it that both collide with an enemy.
This would technically generate two collision events per frame. Need to condense this to one collision "event".
Going to have one body per object, ie one body per sword, but then multiple shapes per body.
Then drop the collision engine down to 1 collision per body per frame.

View File

@ -310,9 +310,15 @@ Attaching items to hands in first person
Fix grass placement
(05/25/2024)
VERY rudimentary first person documentation to give basic navigation to relevant files.
# TODO
Redo hitboxes to have capsules and also chaining between frames (but not between swinging the camera around)
Fix being able to walk off far side of the world (ie in level editor)
Grass System properly LOD

View File

@ -6,4 +6,5 @@
- @subpage staticmorph
- @subpage shadermask
- @subpage animationmask
- @subpage meshmask
- @subpage meshmask
- @subpage firstpersonviewmodel

View File

@ -0,0 +1,10 @@
@page firstpersonviewmodel First Person Viewmodel
# The pipeline
There is a separate render pipeline for first person elements. It is composited ontop the main render in the composite pipeline.
# The actor
There is a global entity, firstPersonEntity, that is rendered in the first person pipeline. This is the source of the visuals in that render.
The animations for this actor are controlled via the `FirstPersonTree`. It provides a convenient function where you give it the entity and the name of an animation and it will play it.

View File

@ -8,6 +8,7 @@ import electrosphere.client.targeting.crosshair.Crosshair;
import electrosphere.client.terrain.manager.ClientTerrainManager;
import electrosphere.collision.PhysicsEntityUtils;
import electrosphere.collision.PhysicsUtils;
import electrosphere.collision.hitbox.HitboxUtils;
import electrosphere.engine.Globals;
import electrosphere.engine.Main;
import electrosphere.entity.Entity;
@ -15,7 +16,6 @@ import electrosphere.entity.EntityTags;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.collidable.ClientCollidableTree;
import electrosphere.entity.types.attach.AttachUtils;
import electrosphere.entity.types.hitbox.HitboxUtils;
import electrosphere.entity.types.item.ItemUtils;
import electrosphere.entity.types.particle.ParticleUtils;
import electrosphere.renderer.actor.Actor;

View File

@ -54,8 +54,8 @@ import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.collidable.Impulse;
import electrosphere.entity.types.hitbox.HitboxData;
import electrosphere.game.data.collidable.CollidableTemplate;
import electrosphere.game.data.collidable.HitboxData;
import electrosphere.logger.LoggerInterface;
/**

View File

@ -1,34 +1,53 @@
package electrosphere.entity.types.hitbox;
package electrosphere.collision.hitbox;
import electrosphere.collision.CollisionEngine;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
/**
*
* @author amaterasu
* Manages all hitboxes on either the server or client
*/
public class HitboxManager {
//the list of all hitboxes
CopyOnWriteArrayList<Entity> hitboxes = new CopyOnWriteArrayList<Entity>();
//the collision engine for this hitbox manager
CollisionEngine collisionEngine;
//an id incrementer for hitboxes
long idIncrementer = 0;
/**
* Constructor
*/
public HitboxManager(){
collisionEngine = new CollisionEngine();
}
/**
* Registers a hitbox to the manager
* @param hitbox the hitbox to register
*/
public void registerHitbox(Entity hitbox){
hitboxes.add(hitbox);
idIncrementer++;
hitbox.putData(EntityDataStrings.COLLISION_ENTITY_ID, idIncrementer);
}
/**
* Gets all hitboxes in the manager
* @return all hitboxes in the manager
*/
public CopyOnWriteArrayList<Entity> getAllHitboxes(){
return hitboxes;
}
/**
* Deregisters a hitbox from the manager
* @param hitbox the hitbox to deregister
*/
public void deregisterHitbox(Entity hitbox){
hitboxes.remove(hitbox);
}

View File

@ -1,4 +1,4 @@
package electrosphere.entity.types.hitbox;
package electrosphere.collision.hitbox;
import electrosphere.engine.Globals;
import electrosphere.entity.Entity;
@ -8,25 +8,21 @@ import electrosphere.entity.EntityUtils;
import electrosphere.entity.types.attach.AttachUtils;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.entity.types.item.ItemUtils;
import electrosphere.entity.state.attack.ShooterTree;
import electrosphere.entity.state.life.LifeState;
import electrosphere.entity.state.life.LifeUtils;
import electrosphere.entity.state.movement.ProjectileTree;
import electrosphere.game.data.collidable.HitboxData;
import electrosphere.game.server.effects.ParticleEffects;
import electrosphere.server.datacell.Realm;
import java.util.List;
import org.joml.Matrix4f;
import org.joml.Quaterniond;
import org.joml.Quaternionf;
import org.joml.Vector3d;
import org.joml.Vector3f;
import org.joml.Vector4f;
/**
*
* @author amaterasu
* Utilities for working with hitboxes
*/
public class HitboxUtils {
@ -205,6 +201,10 @@ public class HitboxUtils {
}
}
/**
* Updates the position of a hitbox
* @param hitbox the hitbox to update
*/
public static void serverUpdatePosition(Entity hitbox){
Entity parent = ((Entity)hitbox.getData(EntityDataStrings.COLLISION_ENTITY_DATA_PARENT));
HitboxData hitboxData = getHitboxData(hitbox);
@ -232,6 +232,10 @@ public class HitboxUtils {
}
}
/**
* Collides entities on the client
* @param generatorHitbox the hitbox generating the collision
*/
public static void clientCollideEntities(Entity generatorHitbox){
// long generatorId = (Long)generatorHitbox.getData(EntityDataStrings.COLLISION_ENTITY_ID);
@ -279,6 +283,10 @@ public class HitboxUtils {
}
}
/**
* Handles collision between two hitboxes on the server
* @param generatorHitbox the hitbox generating the collision
*/
public static void serverCollideEntities(Entity generatorHitbox){
// long generatorId = (Long)generatorHitbox.getData(EntityDataStrings.COLLISION_ENTITY_ID);
@ -332,6 +340,11 @@ public class HitboxUtils {
}
}
/**
* Handles a damage collision on the client
* @param hitbox the hitbox
* @param hurtbox the hurtbox
*/
public static void clientDamageHitboxColision(Entity hitbox, Entity hurtbox){
Entity hitboxParent = (Entity)hitbox.getData(EntityDataStrings.COLLISION_ENTITY_DATA_PARENT);
@ -376,6 +389,11 @@ public class HitboxUtils {
}
}
/**
* Handles a damage hitbox collision on the server
* @param hitbox the hitbox
* @param hurtbox the hurtbox
*/
public static void serverDamageHitboxColision(Entity hitbox, Entity hurtbox){
Entity hitboxParent = (Entity)hitbox.getData(EntityDataStrings.COLLISION_ENTITY_DATA_PARENT);
@ -420,15 +438,29 @@ public class HitboxUtils {
}
}
/**
* Gets the data for a hitbox
* @param e the entity encapsulating the hitbox
* @return the hitbox data
*/
public static HitboxData getHitboxData(Entity e){
return (HitboxData)e.getData(EntityDataStrings.HITBOX_DATA);
}
/**
* Gets the hitbox associated list
* @param e The entity that has hitboxes
* @return the list of hitboxes associated with the entity
*/
public static List<Entity> getHitboxAssociatedList(Entity e){
return (List<Entity>)e.getData(EntityDataStrings.HITBOX_ASSOCIATED_LIST);
}
/**
* Gets the hurtbox associated list
* @param e the entity that has hurtboxes
* @return the list of hurtboxes associated with the entity
*/
public static List<Entity> getHurtboxAssociatedList(Entity e){
return (List<Entity>)e.getData(EntityDataStrings.HURTBOX_ASSOCIATED_LIST);
}

View File

@ -222,7 +222,7 @@ public class ControlHandler {
boolean shouldRecaptureScreen = false;
//controls whether the camera is first or third person
boolean cameraIsThirdPerson = false;
boolean cameraIsThirdPerson = true;
/*

View File

@ -24,6 +24,7 @@ import electrosphere.client.terrain.cells.VoxelTextureAtlas;
import electrosphere.client.terrain.manager.ClientTerrainManager;
import electrosphere.collision.CollisionEngine;
import electrosphere.collision.CollisionWorldData;
import electrosphere.collision.hitbox.HitboxManager;
import electrosphere.controls.CameraHandler;
import electrosphere.controls.ControlCallback;
import electrosphere.controls.ControlHandler;
@ -37,7 +38,6 @@ import electrosphere.engine.profiler.Profiler;
import electrosphere.engine.time.Timekeeper;
import electrosphere.entity.Entity;
import electrosphere.entity.Scene;
import electrosphere.entity.types.hitbox.HitboxManager;
import electrosphere.game.config.UserSettings;
import electrosphere.game.data.voxel.VoxelType;
import electrosphere.game.server.structure.virtual.StructureManager;

View File

@ -4,6 +4,7 @@ package electrosphere.entity.state.attack;
import electrosphere.net.synchronization.BehaviorTreeIdEnums;
import electrosphere.collision.collidable.Collidable;
import electrosphere.collision.hitbox.HitboxUtils;
import electrosphere.engine.Globals;
import electrosphere.engine.Main;
import electrosphere.entity.Entity;
@ -19,7 +20,6 @@ import electrosphere.entity.state.rotator.RotatorTree;
import electrosphere.entity.types.attach.AttachUtils;
import electrosphere.entity.types.collision.CollisionObjUtils;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.entity.types.hitbox.HitboxUtils;
import electrosphere.entity.types.item.ItemUtils;
import electrosphere.entity.types.projectile.ProjectileUtils;
import electrosphere.game.data.creature.type.attack.AttackMove;

View File

@ -10,6 +10,7 @@ import electrosphere.net.parser.net.message.SynchronizationMessage;
import electrosphere.server.datacell.utils.DataCellSearchUtils;
import electrosphere.collision.collidable.Collidable;
import electrosphere.collision.hitbox.HitboxUtils;
import electrosphere.engine.Globals;
import electrosphere.engine.Main;
import electrosphere.entity.Entity;
@ -28,7 +29,6 @@ import electrosphere.entity.state.rotator.ServerRotatorTree;
import electrosphere.entity.types.attach.AttachUtils;
import electrosphere.entity.types.collision.CollisionObjUtils;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.entity.types.hitbox.HitboxUtils;
import electrosphere.entity.types.item.ItemUtils;
import electrosphere.entity.types.projectile.ProjectileUtils;
import electrosphere.game.data.creature.type.attack.AttackMove;

View File

@ -12,6 +12,7 @@ import electrosphere.collision.CollisionBodyCreation;
import electrosphere.collision.PhysicsEntityUtils;
import electrosphere.collision.PhysicsUtils;
import electrosphere.collision.collidable.Collidable;
import electrosphere.collision.hitbox.HitboxUtils;
import electrosphere.engine.Globals;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityCreationUtils;
@ -50,9 +51,8 @@ import electrosphere.entity.state.rotator.RotatorHierarchyNode;
import electrosphere.entity.state.rotator.RotatorTree;
import electrosphere.entity.state.rotator.ServerRotatorTree;
import electrosphere.entity.types.collision.CollisionObjUtils;
import electrosphere.entity.types.hitbox.HitboxData;
import electrosphere.entity.types.hitbox.HitboxUtils;
import electrosphere.game.data.collidable.CollidableTemplate;
import electrosphere.game.data.collidable.HitboxData;
import electrosphere.game.data.creature.type.CreatureType;
import electrosphere.game.data.creature.type.SprintSystem;
import electrosphere.game.data.creature.type.attack.AttackMove;

View File

@ -14,6 +14,7 @@ import electrosphere.collision.CollisionBodyCreation;
import electrosphere.collision.PhysicsEntityUtils;
import electrosphere.collision.PhysicsUtils;
import electrosphere.collision.collidable.Collidable;
import electrosphere.collision.hitbox.HitboxUtils;
import electrosphere.engine.Globals;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityCreationUtils;
@ -25,9 +26,8 @@ import electrosphere.entity.state.collidable.ClientCollidableTree;
import electrosphere.entity.state.collidable.ServerCollidableTree;
import electrosphere.entity.state.gravity.ClientGravityTree;
import electrosphere.entity.state.gravity.ServerGravityTree;
import electrosphere.entity.types.hitbox.HitboxData;
import electrosphere.entity.types.hitbox.HitboxUtils;
import electrosphere.game.data.collidable.CollidableTemplate;
import electrosphere.game.data.collidable.HitboxData;
import electrosphere.game.data.item.type.EquipWhitelist;
import electrosphere.game.data.item.type.Item;
import electrosphere.game.data.item.type.WeaponData;

View File

@ -9,14 +9,14 @@ import org.joml.Quaternionfc;
import org.joml.Vector3d;
import org.joml.Vector3f;
import electrosphere.collision.hitbox.HitboxUtils;
import electrosphere.collision.hitbox.HitboxUtils.HitboxPositionCallback;
import electrosphere.engine.Globals;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityCreationUtils;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.ServerEntityUtils;
import electrosphere.entity.state.movement.ProjectileTree;
import electrosphere.entity.types.hitbox.HitboxUtils;
import electrosphere.entity.types.hitbox.HitboxUtils.HitboxPositionCallback;
import electrosphere.game.data.projectile.ProjectileType;
import electrosphere.server.datacell.Realm;
import electrosphere.server.datacell.utils.ServerBehaviorTreeUtils;

View File

@ -1,40 +1,77 @@
package electrosphere.entity.types.hitbox;
package electrosphere.game.data.collidable;
import java.util.List;
import electrosphere.collision.hitbox.HitboxUtils.HitboxPositionCallback;
import electrosphere.entity.Entity;
import electrosphere.entity.types.hitbox.HitboxUtils.HitboxPositionCallback;
/**
* Data about a hitbox
*/
public class HitboxData {
//the type of hitbox
String type;
//the bone it is attached to
String bone;
//the radius of the hitbox
float radius;
//controls whether the hitbox is active or not
boolean active = false;
//used for more advanced hitbox spawning to find hitbox position on frame update
HitboxPositionCallback positionCallback;
//used to filter this hitbox to hitting only certain parent entities
List<Entity> filter;
/**
* Gets the type of hitbox
* @return the type of hitbox
*/
public String getType() {
return type;
}
/**
* Gets the type of bone
* @return the type of bone
*/
public String getBone() {
return bone;
}
/**
* Gets the radius of the hitbox
* @return the radius of the hitbox
*/
public float getRadius() {
return radius;
}
/**
* Returns whether the hitbox is active or not
* @return true if the hitbox is active, false otherwise
*/
public boolean isActive() {
return active;
}
/**
* Toggles the active status
* @param active if true, the hitbox will be active, if false the hitbox will be inactive
*/
public void setActive(boolean active) {
this.active = active;
}
/**
* Sets the bone this hitbox is attached to
* @param bone the bone to attach the hitbox to
*/
public void setBone(String bone) {
this.bone = bone;
}

View File

@ -1,7 +1,7 @@
package electrosphere.game.data.creature.type;
import electrosphere.entity.types.hitbox.HitboxData;
import electrosphere.game.data.collidable.CollidableTemplate;
import electrosphere.game.data.collidable.HitboxData;
import electrosphere.game.data.creature.type.attack.AttackMove;
import electrosphere.game.data.creature.type.attack.AttackMoveResolver;
import electrosphere.game.data.creature.type.equip.EquipPoint;

View File

@ -2,7 +2,7 @@ package electrosphere.game.data.item.type;
import java.util.List;
import electrosphere.entity.types.hitbox.HitboxData;
import electrosphere.game.data.collidable.HitboxData;
public class WeaponData {

View File

@ -1,7 +1,7 @@
package electrosphere.game.data.object.type;
import electrosphere.entity.types.hitbox.HitboxData;
import electrosphere.game.data.collidable.CollidableTemplate;
import electrosphere.game.data.collidable.HitboxData;
import electrosphere.game.data.graphics.GraphicsTemplate;
import java.util.List;

View File

@ -81,15 +81,15 @@ import org.lwjgl.opengl.GL20;
import org.lwjgl.opengl.GL30;
import electrosphere.collision.collidable.Collidable;
import electrosphere.collision.hitbox.HitboxUtils;
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;
import electrosphere.entity.types.hitbox.HitboxUtils;
import electrosphere.game.data.collidable.CollidableTemplate;
import electrosphere.game.data.collidable.HitboxData;
import electrosphere.logger.LoggerInterface;
import electrosphere.renderer.RenderPipelineState.SelectedShaderEnum;
import electrosphere.renderer.actor.Actor;

View File

@ -8,14 +8,14 @@ import org.joml.Vector3f;
import org.lwjgl.opengl.GL40;
import electrosphere.collision.collidable.Collidable;
import electrosphere.collision.hitbox.HitboxUtils;
import electrosphere.engine.Globals;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
import electrosphere.entity.EntityUtils;
import electrosphere.entity.types.camera.CameraEntityUtils;
import electrosphere.entity.types.hitbox.HitboxData;
import electrosphere.entity.types.hitbox.HitboxUtils;
import electrosphere.game.data.collidable.CollidableTemplate;
import electrosphere.game.data.collidable.HitboxData;
import electrosphere.renderer.OpenGLState;
import electrosphere.renderer.RenderPipelineState;
import electrosphere.renderer.RenderingEngine;

View File

@ -1,12 +1,10 @@
package electrosphere.server.datacell;
import electrosphere.collision.CollisionEngine;
import electrosphere.collision.hitbox.HitboxManager;
import electrosphere.engine.Globals;
import electrosphere.engine.Main;
import electrosphere.entity.Entity;
import electrosphere.entity.Scene;
import electrosphere.entity.types.hitbox.HitboxManager;
import electrosphere.menu.debug.ImGuiWindowMacros;
import electrosphere.net.parser.net.message.NetworkMessage;
import electrosphere.server.datacell.interfaces.DataCellManager;

View File

@ -7,9 +7,9 @@ import java.util.concurrent.CopyOnWriteArraySet;
import electrosphere.collision.CollisionEngine;
import electrosphere.collision.CollisionWorldData;
import electrosphere.collision.hitbox.HitboxManager;
import electrosphere.engine.Globals;
import electrosphere.entity.Entity;
import electrosphere.entity.types.hitbox.HitboxManager;
import electrosphere.game.server.world.ServerWorldData;
import electrosphere.net.server.player.Player;

View File

@ -2,6 +2,8 @@ package electrosphere.server.simulation;
import electrosphere.entity.types.attach.AttachUtils;
import electrosphere.client.targeting.crosshair.Crosshair;
import electrosphere.collision.hitbox.HitboxManager;
import electrosphere.collision.hitbox.HitboxUtils;
import electrosphere.engine.Globals;
import electrosphere.engine.Main;
import electrosphere.entity.Entity;
@ -16,8 +18,6 @@ import electrosphere.entity.state.collidable.ClientCollidableTree;
import electrosphere.entity.state.collidable.ServerCollidableTree;
import electrosphere.entity.state.idle.IdleTree;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.entity.types.hitbox.HitboxManager;
import electrosphere.entity.types.hitbox.HitboxUtils;
import electrosphere.entity.types.item.ItemUtils;
import electrosphere.entity.state.life.LifeState;
import electrosphere.entity.state.life.LifeUtils;