From b761299c2913f94fbd8393d8a286b06733f5c18c Mon Sep 17 00:00:00 2001 From: austin Date: Fri, 13 Sep 2024 09:30:21 -0400 Subject: [PATCH] physics work --- assets/Data/entity/objects/containers.json | 3 + docs/src/progress/renderertodo.md | 2 + .../client/scene/ClientSceneWrapper.java | 5 +- .../collision/CollisionBodyCreation.java | 50 ++++ .../collision/CollisionEngine.java | 127 +++++++-- .../collision/PhysicsEntityUtils.java | 244 +++++++++++++++++- .../electrosphere/collision/PhysicsUtils.java | 29 ++- .../collision/collidable/Collidable.java | 22 ++ .../collision/collidable/SurfaceParams.java | 160 ++++++++++++ src/main/java/electrosphere/engine/Main.java | 1 - .../groundmove/ClientGroundMovementTree.java | 3 + .../groundmove/ServerGroundMovementTree.java | 3 + .../entity/types/creature/CreatureUtils.java | 3 + .../java/electrosphere/game/data/Config.java | 11 - .../data/collidable/CollidableTemplate.java | 46 ++++ .../type/model/CollisionObjectTemplate.java | 73 ------ .../structure/type/model/StructureType.java | 34 --- .../type/model/StructureTypeMap.java | 27 -- .../virtual/VirtualStructureUtils.java | 19 +- .../menu/debug/ImGuiEntityMacros.java | 7 +- 20 files changed, 670 insertions(+), 199 deletions(-) create mode 100644 src/main/java/electrosphere/collision/collidable/SurfaceParams.java delete mode 100644 src/main/java/electrosphere/game/data/structure/type/model/CollisionObjectTemplate.java delete mode 100644 src/main/java/electrosphere/game/data/structure/type/model/StructureType.java delete mode 100644 src/main/java/electrosphere/game/data/structure/type/model/StructureTypeMap.java diff --git a/assets/Data/entity/objects/containers.json b/assets/Data/entity/objects/containers.json index 736d8b6e..c2f3cfb1 100644 --- a/assets/Data/entity/objects/containers.json +++ b/assets/Data/entity/objects/containers.json @@ -12,6 +12,9 @@ ], "collidable": { "type" : "CUBE", + "mass": 10.0, + "rollingFriction": 100.0, + "linearFriction": 100.0, "dimension1" : 2.0, "dimension2" : 2.0, "dimension3" : 2.0, diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index b2c39db9..b0cee678 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -744,6 +744,8 @@ Move AttachUtils package Move Scene package Crate object Data cleanup +Delete Structure entity type +Physics work # TODO diff --git a/src/main/java/electrosphere/client/scene/ClientSceneWrapper.java b/src/main/java/electrosphere/client/scene/ClientSceneWrapper.java index 1e846e3e..e48f8403 100644 --- a/src/main/java/electrosphere/client/scene/ClientSceneWrapper.java +++ b/src/main/java/electrosphere/client/scene/ClientSceneWrapper.java @@ -64,9 +64,12 @@ public class ClientSceneWrapper { /** * Resolves a client ID to the equivalent ID on the server * @param clientId The id provided by the client - * @return The equivalent id on the server + * @return The equivalent id on the server, or -1 if no equivalent is found */ public int mapClientToServerId(int clientId){ + if(clientToServerIdMap.get(clientId) == null){ + return -1; + } return clientToServerIdMap.get(clientId); } diff --git a/src/main/java/electrosphere/collision/CollisionBodyCreation.java b/src/main/java/electrosphere/collision/CollisionBodyCreation.java index 6f8db4f4..da52eaaa 100644 --- a/src/main/java/electrosphere/collision/CollisionBodyCreation.java +++ b/src/main/java/electrosphere/collision/CollisionBodyCreation.java @@ -2,6 +2,7 @@ package electrosphere.collision; import java.nio.IntBuffer; +import org.joml.Quaterniond; import org.joml.Vector3d; import org.lwjgl.PointerBuffer; import org.lwjgl.assimp.AIFace; @@ -14,6 +15,7 @@ import org.ode4j.ode.DBox; import org.ode4j.ode.DCapsule; import org.ode4j.ode.DCylinder; import org.ode4j.ode.DGeom; +import org.ode4j.ode.DMass; import org.ode4j.ode.DSphere; import org.ode4j.ode.DTriMesh; @@ -83,6 +85,18 @@ public class CollisionBodyCreation { return collisionEngine.createDBody(geom); } + /** + * Creates a capsule body in the collision engine + * @param collisionEngine The collision engine + * @param length The length of the capsule (not including round part at ends) + * @param radius The radius of the sphere + * @return The DBody + */ + public static DBody createCapsuleBody(CollisionEngine collisionEngine, double length, double radius, long categoryBits){ + DCapsule geom = collisionEngine.createCapsuleGeom(radius,length,categoryBits); + return collisionEngine.createDBody(geom); + } + /** * Creates a dbody with existing shapes that are provided * @param collisionEngine the collision engine to create it in @@ -116,6 +130,42 @@ public class CollisionBodyCreation { return collisionEngine.createCapsuleGeom(radius, length, categoryBits); } + /** + * Sets the mass on the dbody + * @param collisionEngine The collision engine + * @param body The body + * @param mass The mass value + * @param radius The radius of the cylinder + * @param length The length of the cylinder + * @return The DMass object + */ + public static DMass setCylinderMass(CollisionEngine collisionEngine, DBody body, double mass, double radius, double length, Vector3d offset, Quaterniond rotation){ + return collisionEngine.createCylinderMass(mass, radius, length, body, offset, rotation); + } + + /** + * Sets the mass on the dbody + * @param collisionEngine The collision engine + * @param body The body + * @param mass The mass value + * @param dims The dimensions of the box + * @return The DMass object + */ + public static DMass setBoxMass(CollisionEngine collisionEngine, DBody body, double mass, Vector3d dims, Vector3d offset, Quaterniond rotation){ + return collisionEngine.createBoxMass(mass, dims, body, offset, rotation); + } + + /** + * Sets the damping for the body + * @param collisionEngine The collision engine + * @param body The body + * @param linearDamping The linear damping + * @param angularDamping The angular damping + */ + public static void setDamping(CollisionEngine collisionEngine, DBody body, double linearDamping, double angularDamping){ + collisionEngine.setDamping(body, linearDamping, angularDamping); + } + /** * Sets the provided body to be a kinematic body (no gravity applied) * @param collisionEngine The collision engine diff --git a/src/main/java/electrosphere/collision/CollisionEngine.java b/src/main/java/electrosphere/collision/CollisionEngine.java index c1c40c4f..070cdfda 100644 --- a/src/main/java/electrosphere/collision/CollisionEngine.java +++ b/src/main/java/electrosphere/collision/CollisionEngine.java @@ -19,7 +19,6 @@ import org.joml.Matrix4d; import org.joml.Quaterniond; import org.joml.Vector3d; import org.joml.Vector4d; -import org.ode4j.math.DMatrix3; import org.ode4j.math.DVector3; import org.ode4j.ode.DBody; import org.ode4j.ode.DBox; @@ -40,11 +39,11 @@ import org.ode4j.ode.DSphere; import org.ode4j.ode.DTriMesh; import org.ode4j.ode.DTriMeshData; import org.ode4j.ode.DWorld; -import org.ode4j.ode.OdeConstants; import org.ode4j.ode.OdeHelper; import electrosphere.collision.RayCastCallback.RayCastCallbackData; import electrosphere.collision.collidable.Collidable; +import electrosphere.collision.collidable.SurfaceParams; import electrosphere.engine.Globals; import electrosphere.engine.time.Timekeeper; import electrosphere.entity.Entity; @@ -63,6 +62,21 @@ public class CollisionEngine { //gravity constant public static final float GRAVITY_MAGNITUDE = 9.8f * 2; + + /** + * The damping applied to angular velocity + */ + public static final double DEFAULT_ANGULAR_DAMPING = 0.01; + + /** + * The damping applied to linear velocity + */ + public static final double DEFAULT_LINEAR_DAMPING = 0.01; + + /** + * Default max angular speed + */ + public static final double DEFAULT_MAX_ANGULAR_SPEED = 100; //world data that the collision engine leverages for position correction and the like CollisionWorldData collisionWorldData; @@ -103,6 +117,15 @@ public class CollisionEngine { world = OdeHelper.createWorld(); space = OdeHelper.createBHVSpace(Collidable.TYPE_STATIC_BIT); world.setGravity(0,-GRAVITY_MAGNITUDE,0); + world.setAutoDisableFlag(true); + // world.setContactMaxCorrectingVel(0.1); + world.setContactSurfaceLayer(0.001); + world.setCFM(0.00000001); + + //base plane + OdeHelper.createPlane(space, 0, 1, 0, 0); + + contactgroup = OdeHelper.createJointGroup(); this.nearCallback = new DNearCallback() { @Override @@ -296,33 +319,52 @@ public class CollisionEngine { return; } - //creates a buffer to store potential collisions - DContactBuffer contacts = new DContactBuffer(MAX_CONTACTS); // up to MAX_CONTACTS contacts per box-box - for (int i=0; i impulses = new CopyOnWriteArrayList(); + + /** + * The params for the surface of this collidable when a collision occurs + */ + SurfaceParams surfaceParams; //these should have corresponding category bits along with them public static final String TYPE_STATIC = "static"; @@ -61,6 +66,23 @@ public class Collidable { this.parent = parent; this.type = type; this.parentTracksCollidable = parentTracksCollidable; + this.surfaceParams = new SurfaceParams(); + } + + /** + * Sets the surface params for the collidable + * @param surfaceParams The surface params + */ + public void setSurfaceParams(SurfaceParams surfaceParams){ + this.surfaceParams = surfaceParams; + } + + /** + * Gets the surface params for the collidable + * @return The surface params + */ + public SurfaceParams getSurfaceParams(){ + return this.surfaceParams; } public List getImpulses() { diff --git a/src/main/java/electrosphere/collision/collidable/SurfaceParams.java b/src/main/java/electrosphere/collision/collidable/SurfaceParams.java new file mode 100644 index 00000000..f7caaa75 --- /dev/null +++ b/src/main/java/electrosphere/collision/collidable/SurfaceParams.java @@ -0,0 +1,160 @@ +package electrosphere.collision.collidable; + +import org.ode4j.ode.OdeConstants; + +/** + * The surface params for the collidable + */ +public class SurfaceParams { + + /** + *

The mode flags for the surface

+ *

This must always be set. This is a combination of one or more of the following flags.

+ *

+ * Possible values: + *

    + *
  • dContactMu2 - If not set, use mu for both friction directions. If set, use mu for friction direction 1, use mu2 for friction direction 2.
  • + *
  • dContactFDir1 - If set, take fdir1 as friction direction 1, otherwise automatically compute friction direction 1 to be perpendicular to the contact normal (in which case its resulting orientation is unpredictable).
  • + *
  • dContactBounce - If set, the contact surface is bouncy, in other words the bodies will bounce off each other. The exact amount of bouncyness is controlled by the bounce parameter.
  • + *
  • dContactSoftERP - If set, the error reduction parameter of the contact normal can be set with the soft_erp parameter. This is useful to make surfaces soft.
  • + *
  • dContactSoftCFM - If set, the constraint force mixing parameter of the contact normal can be set with the soft_cfm parameter. This is useful to make surfaces soft.
  • + *
  • dContactMotion1 - If set, the contact surface is assumed to be moving independently of the motion of the bodies. This is kind of like a conveyor belt running over the surface. When this flag is set, motion1 defines the surface velocity in friction direction 1.
  • + *
  • dContactMotion2 - The same thing as above, but for friction direction 2.
  • + *
  • dContactMotionN - The same thing as above, but along the contact normal.
  • + *
  • dContactSlip1 - Force-dependent-slip (FDS) in friction direction 1.
  • + *
  • dContactSlip2 - Force-dependent-slip (FDS) in friction direction 2.
  • + *
  • dContactRolling - Enables rolling/spinning friction.
  • + *
  • dContactApprox1_1 - Use the friction pyramid approximation for friction direction 1. If this is not specified then the constant-force-limit approximation is used (and mu is a force limit).
  • + *
  • dContactApprox1_2 - Use the friction pyramid approximation for friction direction 2. If this is not specified then the constant-force-limit approximation is used (and mu is a force limit).
  • + *
  • dContactApprox1_N - Use the friction pyramid approximation for spinning (rolling around normal).
  • + *
  • dContactApprox1 - Equivalent to dContactApprox1_1, dContactApprox1_2 and dContactApprox1_N.
  • + *
+ *

+ */ + int mode; + + /** + *

Coulomb friction coefficient

+ *

Ranges [0,infinity)

+ *

0 is a frictionless contact, dInfinity results in a contact that never slips.

+ *

Note that frictionless contacts are less time consume to compute than ones with friction.

+ *

This must always be set.

+ */ + Double mu; + + /** + *

Rolling friction coefficient around direction 1.

+ */ + Double rho; + + /** + *

Rolling friction coefficient around direction 2.

+ */ + Double rho2; + + /** + *

Rolling friction coefficient around the normal direction.

+ */ + Double rhoN; + + /** + *

Restitution parameter

+ *

Ranges (0,1)

+ *

0 means the surfaces are not bouncy at all. 1 is maximum bounciness.

+ *

Note that mode must be set with dContactBounce.

+ */ + Double bounce; + + /** + *

Minimum velocity to trigger a bounce

+ *

All velocities below this threshold will effectively have bounce parameter of 0.

+ *

Note that mode must be set with ??put flat here??.

+ */ + Double bounceVel; + + /** + * Constructor + */ + public SurfaceParams(){ + mode = OdeConstants.dContactApprox1 & OdeConstants.dContactRolling & OdeConstants.dContactBounce; + mu = 10.0; + rho = 10.0; + rho2 = 10.0; + rhoN = 10.0; + bounce = 0.001; + bounceVel = 100.0; + } + + /** + * Gets the mode for the surface + * @return The mode + */ + public int getMode(){ + return mode; + } + + /** + * Gets the mu for the surface + * @return The mu + */ + public Double getMu(){ + return mu; + } + + /** + * Gets the rho for the surface; + * @return The rho + */ + public Double getRho(){ + return rho; + } + + /** + * Gets the rho2 for the surface; + * @return The rho2 + */ + public Double getRho2(){ + return rho2; + } + + /** + * Gets the rhoN for the surface; + * @return The rhoN + */ + public Double getRhoN(){ + return rhoN; + } + + /** + * Gets the bounce for the surface; + * @return The bounce + */ + public Double getBounce(){ + return bounce; + } + + /** + * Gets the bounce minimum velocity for the surface; + * @return The bounce minimum velocity + */ + public Double getBounceVel(){ + return bounceVel; + } + + /** + * Sets the rolling friction of the surface params + * @param friction The rolling friction + */ + public void setRollingFriction(double friction){ + this.rho = this.rho2 = this.rhoN = friction; + } + + /** + * Sets the lienar friction + * @param linearFriction The linear friction + */ + public void setLinearFriction(double linearFriction){ + this.mu = linearFriction; + } + +} diff --git a/src/main/java/electrosphere/engine/Main.java b/src/main/java/electrosphere/engine/Main.java index a8121446..9eca8430 100644 --- a/src/main/java/electrosphere/engine/Main.java +++ b/src/main/java/electrosphere/engine/Main.java @@ -5,7 +5,6 @@ import static org.lwjgl.glfw.GLFW.glfwWindowShouldClose; import java.util.concurrent.TimeUnit; import org.graalvm.polyglot.HostAccess.Export; - import org.ode4j.ode.OdeHelper; import electrosphere.audio.AudioEngine; diff --git a/src/main/java/electrosphere/entity/state/movement/groundmove/ClientGroundMovementTree.java b/src/main/java/electrosphere/entity/state/movement/groundmove/ClientGroundMovementTree.java index 004e011b..65ae8414 100644 --- a/src/main/java/electrosphere/entity/state/movement/groundmove/ClientGroundMovementTree.java +++ b/src/main/java/electrosphere/entity/state/movement/groundmove/ClientGroundMovementTree.java @@ -322,6 +322,7 @@ public class ClientGroundMovementTree implements BehaviorTree { } CreatureUtils.setVelocity(parent, velocity); //actually update + PhysicsEntityUtils.getDBody(parent).enable(); body.setLinearVel( movementVector.x * velocity * Globals.timekeeper.getSimFrameTime(), linearVelocity.get1(), @@ -353,6 +354,7 @@ public class ClientGroundMovementTree implements BehaviorTree { this.updateVelocity(); float velocity = this.getModifiedVelocity(); + PhysicsEntityUtils.getDBody(parent).enable(); body.setLinearVel( movementVector.x * velocity * Globals.timekeeper.getSimFrameTime(), linearVelocity.get1(), @@ -400,6 +402,7 @@ public class ClientGroundMovementTree implements BehaviorTree { } CreatureUtils.setVelocity(parent, velocity); } + PhysicsEntityUtils.getDBody(parent).enable(); body.setLinearVel( movementVector.x * velocity * Globals.timekeeper.getSimFrameTime(), linearVelocity.get1(), diff --git a/src/main/java/electrosphere/entity/state/movement/groundmove/ServerGroundMovementTree.java b/src/main/java/electrosphere/entity/state/movement/groundmove/ServerGroundMovementTree.java index b1b8a1ec..c0fbcacb 100644 --- a/src/main/java/electrosphere/entity/state/movement/groundmove/ServerGroundMovementTree.java +++ b/src/main/java/electrosphere/entity/state/movement/groundmove/ServerGroundMovementTree.java @@ -272,6 +272,7 @@ public class ServerGroundMovementTree implements BehaviorTree { state = MovementTreeState.MOVE; CreatureUtils.setVelocity(parent, velocity); } + PhysicsEntityUtils.getDBody(parent).enable(); PhysicsEntityUtils.getDBody(parent).setLinearVel( movementVector.x * velocity * Globals.timekeeper.getSimFrameTime(), linearVelocity.get1(), @@ -317,6 +318,7 @@ public class ServerGroundMovementTree implements BehaviorTree { } this.updateVelocity(); float velocity = this.getModifiedVelocity(); + PhysicsEntityUtils.getDBody(parent).enable(); PhysicsEntityUtils.getDBody(parent).setLinearVel( movementVector.x * velocity * Globals.timekeeper.getSimFrameTime(), linearVelocity.get1(), @@ -383,6 +385,7 @@ public class ServerGroundMovementTree implements BehaviorTree { // linearVelocity.get1(), // movementVector.z * velocity * Globals.timekeeper.getSimFrameTime() // ); + PhysicsEntityUtils.getDBody(parent).enable(); PhysicsEntityUtils.getDBody(parent).setLinearVel( movementVector.x * velocity * Globals.timekeeper.getSimFrameTime(), linearVelocity.get1(), diff --git a/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java b/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java index 79546ff6..135fa56a 100644 --- a/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java +++ b/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java @@ -332,6 +332,9 @@ public class CreatureUtils { } public static float getVelocity(Entity e){ + if(!e.containsKey(EntityDataStrings.DATA_STRING_VELOCITY)){ + return 0; + } return (float)e.getData(EntityDataStrings.DATA_STRING_VELOCITY); } diff --git a/src/main/java/electrosphere/game/data/Config.java b/src/main/java/electrosphere/game/data/Config.java index 67a3e56e..8f78188d 100644 --- a/src/main/java/electrosphere/game/data/Config.java +++ b/src/main/java/electrosphere/game/data/Config.java @@ -15,7 +15,6 @@ import electrosphere.game.data.foliage.type.model.FoliageTypeMap; import electrosphere.game.data.item.type.model.ItemTypeMap; import electrosphere.game.data.particle.ParticleDefinition; import electrosphere.game.data.projectile.ProjectileTypeHolder; -import electrosphere.game.data.structure.type.model.StructureTypeMap; import electrosphere.game.data.tutorial.HintDefinition; import electrosphere.game.data.units.UnitDefinitionFile; import electrosphere.game.data.units.UnitLoader; @@ -30,7 +29,6 @@ import electrosphere.util.FileUtils; public class Config { CreatureTypeLoader creatureTypeLoader; - StructureTypeMap structureTypeMap; ItemTypeMap itemMap; FoliageTypeMap foliageMap; CommonEntityMap objectTypeLoader; @@ -67,7 +65,6 @@ public class Config { Config config = new Config(); config.creatureTypeLoader = loadCreatureTypes("Data/entity/creatures.json"); config.itemMap = FileUtils.loadObjectFromAssetPath("Data/entity/items.json", ItemTypeMap.class); - config.structureTypeMap = FileUtils.loadObjectFromAssetPath("Data/entity/structures.json", StructureTypeMap.class); config.foliageMap = FileUtils.loadObjectFromAssetPath("Data/entity/foliage.json", FoliageTypeMap.class); config.objectTypeLoader = loadCommonEntityTypes("Data/entity/objects.json"); config.symbolMap = FileUtils.loadObjectFromAssetPath("Data/game/symbolism.json", SymbolMap.class); @@ -176,14 +173,6 @@ public class Config { return creatureTypeLoader; } - /** - * Gets the data on all structure entities in memory - * @return The structure definitions - */ - public StructureTypeMap getStructureTypeMap() { - return structureTypeMap; - } - /** * Gets the data on all item types in memory * @return the data on all items diff --git a/src/main/java/electrosphere/game/data/collidable/CollidableTemplate.java b/src/main/java/electrosphere/game/data/collidable/CollidableTemplate.java index 35324de5..325e39bb 100644 --- a/src/main/java/electrosphere/game/data/collidable/CollidableTemplate.java +++ b/src/main/java/electrosphere/game/data/collidable/CollidableTemplate.java @@ -5,6 +5,9 @@ package electrosphere.game.data.collidable; */ public class CollidableTemplate { + /** + * The primitive shape type + */ String type; float dimension1; @@ -20,11 +23,30 @@ public class CollidableTemplate { float offsetY; float offsetZ; + /** + * The mass of the body + */ + Double mass; + + /** + * The linear friction of the body + */ + Double linearFriction; + + /** + * The rolling friction of the body (ie if it's a sphere, what's the friction keeping it from spinning) + */ + Double rollingFriction; + /** * Controls whether the body can rotate or not */ boolean angularlyStatic; + /** + * The primitive shape type + * @return The primitive shape + */ public String getType() { return type; } @@ -69,6 +91,30 @@ public class CollidableTemplate { return offsetZ; } + /** + * Gets the mass of the body + * @return The mass + */ + public Double getMass(){ + return mass; + } + + /** + * Gets the linear friction + * @return The linear friction + */ + public Double getLinearFriction(){ + return linearFriction; + } + + /** + * Gets the rolling friction (ie if it's a sphere, what's the friction keeping it from spinning) + * @return The rolling friction + */ + public Double getRollingFriction(){ + return rollingFriction; + } + /** * Gets if the body should always be allowed to rotate or not * @return true if should always be allowed to rotate, false otherwise diff --git a/src/main/java/electrosphere/game/data/structure/type/model/CollisionObjectTemplate.java b/src/main/java/electrosphere/game/data/structure/type/model/CollisionObjectTemplate.java deleted file mode 100644 index cd219d72..00000000 --- a/src/main/java/electrosphere/game/data/structure/type/model/CollisionObjectTemplate.java +++ /dev/null @@ -1,73 +0,0 @@ -package electrosphere.game.data.structure.type.model; - -/** - * Collidable data - */ -public class CollisionObjectTemplate { - - String type; - public static final String TYPE_CUBE = "CUBE"; - public static final String TYPE_PLANE = "PLANE"; - - - float positionX; - float positionY; - float positionZ; - - float scaleX; - float scaleY; - float scaleZ; - - float rotationW; - float rotationX; - float rotationY; - float rotationZ; - - public String getType() { - return type; - } - - public float getPositionX() { - return positionX; - } - - public float getPositionY() { - return positionY; - } - - public float getPositionZ() { - return positionZ; - } - - public float getScaleX() { - return scaleX; - } - - public float getScaleY() { - return scaleY; - } - - public float getScaleZ() { - return scaleZ; - } - - public float getRotationW() { - return rotationW; - } - - public float getRotationX() { - return rotationX; - } - - public float getRotationY() { - return rotationY; - } - - public float getRotationZ() { - return rotationZ; - } - - - - -} diff --git a/src/main/java/electrosphere/game/data/structure/type/model/StructureType.java b/src/main/java/electrosphere/game/data/structure/type/model/StructureType.java deleted file mode 100644 index 0bcd81a2..00000000 --- a/src/main/java/electrosphere/game/data/structure/type/model/StructureType.java +++ /dev/null @@ -1,34 +0,0 @@ -package electrosphere.game.data.structure.type.model; - -import java.util.List; - -/** - * Structure data - */ -public class StructureType { - - String modelPath; - String name; - float radius; - - List collision; - - public String getModelPath() { - return modelPath; - } - - public List getCollision() { - return collision; - } - - public String getName() { - return name; - } - - public float getRadius() { - return radius; - } - - - -} diff --git a/src/main/java/electrosphere/game/data/structure/type/model/StructureTypeMap.java b/src/main/java/electrosphere/game/data/structure/type/model/StructureTypeMap.java deleted file mode 100644 index 2c7c1226..00000000 --- a/src/main/java/electrosphere/game/data/structure/type/model/StructureTypeMap.java +++ /dev/null @@ -1,27 +0,0 @@ -package electrosphere.game.data.structure.type.model; - -import java.util.List; - -/** - * Map of name of structure to data about said structure - */ -public class StructureTypeMap { - List structures; - - public List getStructures() { - return structures; - } - - public StructureType getType(String name){ - StructureType rVal = null; - for(StructureType type : structures){ - if(type.getName().equals(name)){ - rVal = type; - break; - } - } - return rVal; - } - - -} diff --git a/src/main/java/electrosphere/game/server/structure/virtual/VirtualStructureUtils.java b/src/main/java/electrosphere/game/server/structure/virtual/VirtualStructureUtils.java index a25093f7..97ced4dc 100644 --- a/src/main/java/electrosphere/game/server/structure/virtual/VirtualStructureUtils.java +++ b/src/main/java/electrosphere/game/server/structure/virtual/VirtualStructureUtils.java @@ -1,7 +1,6 @@ package electrosphere.game.server.structure.virtual; import electrosphere.engine.Globals; -import electrosphere.game.data.structure.type.model.StructureType; import electrosphere.game.server.character.Character; import electrosphere.server.datacell.Realm; @@ -41,15 +40,15 @@ public class VirtualStructureUtils { } public static boolean validStructurePlacementPosition(float posX, float posY, String type){ - StructureType toPlaceType = Globals.gameConfigCurrent.getStructureTypeMap().getType(type); - Vector2f toPlacePos = new Vector2f(posX, posY); - for(Structure virtualStruct : Globals.macroData.getStructures()){ - StructureType existantType = Globals.gameConfigCurrent.getStructureTypeMap().getType(virtualStruct.getType()); - Vector2f existantPos = new Vector2f(virtualStruct.getLocationX(),virtualStruct.getLocationY()); - if(existantPos.distance(toPlacePos) < toPlaceType.getRadius() + existantType.getRadius()){ - return false; - } - } + // StructureType toPlaceType = Globals.gameConfigCurrent.getStructureTypeMap().getType(type); + // Vector2f toPlacePos = new Vector2f(posX, posY); + // for(Structure virtualStruct : Globals.macroData.getStructures()){ + // StructureType existantType = Globals.gameConfigCurrent.getStructureTypeMap().getType(virtualStruct.getType()); + // Vector2f existantPos = new Vector2f(virtualStruct.getLocationX(),virtualStruct.getLocationY()); + // if(existantPos.distance(toPlacePos) < toPlaceType.getRadius() + existantType.getRadius()){ + // return false; + // } + // } return true; } diff --git a/src/main/java/electrosphere/menu/debug/ImGuiEntityMacros.java b/src/main/java/electrosphere/menu/debug/ImGuiEntityMacros.java index 9ba57c3c..d85310cb 100644 --- a/src/main/java/electrosphere/menu/debug/ImGuiEntityMacros.java +++ b/src/main/java/electrosphere/menu/debug/ImGuiEntityMacros.java @@ -562,10 +562,13 @@ public class ImGuiEntityMacros { ImGui.text("Velocity: " + CreatureUtils.getVelocity(detailViewEntity)); } //synchronized data - if(Globals.clientSceneWrapper.getScene().getEntityFromId(detailViewEntity.getId()) != null){ + if( + Globals.clientSceneWrapper.getScene().getEntityFromId(detailViewEntity.getId()) != null && + Globals.clientSceneWrapper.mapClientToServerId(detailViewEntity.getId()) != -1 + ){ //detailViewEntity is a client entity //get server entity - int serverIdForClientEntity = Globals .clientSceneWrapper.mapClientToServerId(detailViewEntity.getId()); + int serverIdForClientEntity = Globals.clientSceneWrapper.mapClientToServerId(detailViewEntity.getId()); Entity serverEntity = EntityLookupUtils.getEntityById(serverIdForClientEntity); DBody serverPhysicsBody = PhysicsEntityUtils.getDBody(serverEntity); if(serverPhysicsBody != null){