diff --git a/assets/Data/entity/creatures/human.json b/assets/Data/entity/creatures/human.json index 1f7efcc0..2b402579 100644 --- a/assets/Data/entity/creatures/human.json +++ b/assets/Data/entity/creatures/human.json @@ -530,6 +530,17 @@ "maxHealth" : 100, "onDamageIFrames" : 30 }, + "pointLight" : { + "const": 1.0, + "linear": 0.7, + "quadratic": 0.35, + "radius": 1.0, + "color": { + "x": 0.3, + "y": 0.3, + "z": 0.3 + } + }, "idleData": { "animation": { "nameFirstPerson" : "Idle", diff --git a/assets/Data/entity/creatures/skeleton.json b/assets/Data/entity/creatures/skeleton.json index e79cb6f1..b8d5110e 100644 --- a/assets/Data/entity/creatures/skeleton.json +++ b/assets/Data/entity/creatures/skeleton.json @@ -414,6 +414,17 @@ "maxHealth" : 60, "onDamageIFrames" : 30 }, + "pointLight" : { + "const": 1.0, + "linear": 0.7, + "quadratic": 0.35, + "radius": 1.0, + "color": { + "x": 0.3, + "y": 0.3, + "z": 0.3 + } + }, "idleData": { "animation": { "nameFirstPerson" : "Idle", diff --git a/src/main/java/electrosphere/entity/ClientEntityUtils.java b/src/main/java/electrosphere/entity/ClientEntityUtils.java index 57f817fd..a006930e 100644 --- a/src/main/java/electrosphere/entity/ClientEntityUtils.java +++ b/src/main/java/electrosphere/entity/ClientEntityUtils.java @@ -27,6 +27,8 @@ public class ClientEntityUtils { * @param entity the entity to destroy */ public static void destroyEntity(Entity entity){ + //check for client-specific stuff + //deregister all behavior trees EntityUtils.cleanUpEntity(entity); } diff --git a/src/main/java/electrosphere/entity/EntityDataStrings.java b/src/main/java/electrosphere/entity/EntityDataStrings.java index 14a0337e..5a56ecf4 100644 --- a/src/main/java/electrosphere/entity/EntityDataStrings.java +++ b/src/main/java/electrosphere/entity/EntityDataStrings.java @@ -259,6 +259,11 @@ public class EntityDataStrings { public static final String EQUIP_INVENTORY = "equipInventory"; public static final String TREE_SERVEREQUIPSTATE = "treeServerEquipState"; + /* + Light state + */ + public static final String TREE_CLIENTLIGHTSTATE = "treeClientLightState"; + /* Inventory in general */ diff --git a/src/main/java/electrosphere/entity/state/light/ClientPointLightComponent.java b/src/main/java/electrosphere/entity/state/light/ClientPointLightComponent.java new file mode 100644 index 00000000..edbf3375 --- /dev/null +++ b/src/main/java/electrosphere/entity/state/light/ClientPointLightComponent.java @@ -0,0 +1,90 @@ +package electrosphere.entity.state.light; + +import org.joml.Vector3d; +import org.joml.Vector3f; + +import electrosphere.engine.Globals; +import electrosphere.entity.Entity; +import electrosphere.entity.EntityDataStrings; +import electrosphere.entity.EntityUtils; +import electrosphere.entity.btree.BehaviorTree; +import electrosphere.entity.state.equip.ClientEquipState; +import electrosphere.game.data.common.light.PointLightDescription; +import electrosphere.renderer.light.PointLight; + +/** + * Keeps the point light attached to the entity + */ +public class ClientPointLightComponent implements BehaviorTree { + + + /** + * The parent entity + */ + Entity parent; + + /** + * The description of the point light + */ + PointLightDescription description; + + /** + * The point light itself + */ + PointLight light; + + @Override + public void simulate(float deltaTime) { + Vector3d entityPos = EntityUtils.getPosition(parent); + light.setPosition(new Vector3f((float)entityPos.x,(float)entityPos.y,(float)entityPos.z)); + } + + /** + * Private constructor + * @param parent + * @param params + */ + private ClientPointLightComponent(Entity parent, Object ... params){ + this.parent = parent; + description = (PointLightDescription)params[0]; + light = Globals.renderingEngine.getLightManager().createPointLight(parent, description); + } + + + /** + *
+ * Attaches this tree to the entity. + *
+ * @param entity The entity to attach to + * @param tree The behavior tree to attach + * @param params Optional parameters that will be provided to the constructor + */ + public static ClientPointLightComponent attachTree(Entity parent, Object ... params){ + ClientPointLightComponent rVal = new ClientPointLightComponent(parent,params); + //!!WARNING!! from here below should not be touched + //This was generated automatically to properly alert various systems that the btree exists and should be tracked + parent.putData(EntityDataStrings.TREE_CLIENTLIGHTSTATE, rVal); + Globals.clientSceneWrapper.getScene().registerBehaviorTree(rVal); + return rVal; + } + /** + *+ * Detatches this tree from the entity. + *
+ * @param entity The entity to detach to + * @param tree The behavior tree to detach + */ + public static void detachTree(Entity entity, BehaviorTree tree){ + } + /** + *+ * Gets the ClientEquipState of the entity + *
+ * @param entity the entity + * @return The ClientEquipState + */ + public static ClientEquipState getClientEquipState(Entity entity){ + return (ClientEquipState)entity.getData(EntityDataStrings.TREE_CLIENTEQUIPSTATE); + } + +} diff --git a/src/main/java/electrosphere/entity/types/common/CommonEntityUtils.java b/src/main/java/electrosphere/entity/types/common/CommonEntityUtils.java index d1e952fd..7909f81c 100644 --- a/src/main/java/electrosphere/entity/types/common/CommonEntityUtils.java +++ b/src/main/java/electrosphere/entity/types/common/CommonEntityUtils.java @@ -34,6 +34,7 @@ import electrosphere.entity.state.inventory.ServerInventoryState; import electrosphere.entity.state.inventory.UnrelationalInventoryState; import electrosphere.entity.state.life.ClientLifeTree; import electrosphere.entity.state.life.ServerLifeTree; +import electrosphere.entity.state.light.ClientPointLightComponent; import electrosphere.entity.state.movement.fall.ClientFallTree; import electrosphere.entity.state.movement.fall.ServerFallTree; import electrosphere.entity.state.movement.groundmove.ClientGroundMovementTree; @@ -246,6 +247,16 @@ public class CommonEntityUtils { } } } + + // + // + // Light generation + // + // + if(rawType.getPointLight() != null){ + ClientPointLightComponent.attachTree(entity, rawType.getPointLight()); + } + if(rawType.getEquipPoints() != null && rawType.getEquipPoints().size() > 0){ ClientEquipState.attachTree(entity, rawType.getEquipPoints()); entity.putData(EntityDataStrings.EQUIP_INVENTORY, RelationalInventoryState.buildRelationalInventoryStateFromEquipList(rawType.getEquipPoints())); diff --git a/src/main/java/electrosphere/game/data/common/CommonEntityType.java b/src/main/java/electrosphere/game/data/common/CommonEntityType.java index 3b629026..00df8acc 100644 --- a/src/main/java/electrosphere/game/data/common/CommonEntityType.java +++ b/src/main/java/electrosphere/game/data/common/CommonEntityType.java @@ -4,6 +4,7 @@ import java.util.List; import electrosphere.game.data.collidable.CollidableTemplate; import electrosphere.game.data.collidable.HitboxData; +import electrosphere.game.data.common.light.PointLightDescription; import electrosphere.game.data.creature.type.HealthSystem; import electrosphere.game.data.creature.type.IdleData; import electrosphere.game.data.creature.type.LookAtSystem; @@ -131,6 +132,11 @@ public class CommonEntityType { */ GraphicsTemplate graphicsTemplate; + /** + * The point light assigned to the entity + */ + PointLightDescription pointLight; + /** * Gets the id for this creature type * @return The id @@ -307,4 +313,12 @@ public class CommonEntityType { return ambientAudio; } + /** + * Gets the point light data + * @return The point light data + */ + public PointLightDescription getPointLight(){ + return pointLight; + } + } diff --git a/src/main/java/electrosphere/game/data/common/light/PointLightDescription.java b/src/main/java/electrosphere/game/data/common/light/PointLightDescription.java new file mode 100644 index 00000000..ab0aedfb --- /dev/null +++ b/src/main/java/electrosphere/game/data/common/light/PointLightDescription.java @@ -0,0 +1,115 @@ +package electrosphere.game.data.common.light; + +import org.joml.Vector3f; + +/** + * Description of a point light + */ +public class PointLightDescription { + + /** + * The constant attenuation factor + */ + float constant; + + /** + * The linear attenuation factor + */ + float linear; + + /** + * The quadratic attenuation factor + */ + float quadratic; + + /** + * The radius of the light + */ + float radius; + + /** + * The color of the light + */ + Vector3f color; + + /** + * Sets the constant attenuation factor + * @param constant The constant attenuation factor + */ + public void setConstant(float constant) { + this.constant = constant; + } + + /** + * Sets the linear attenuation factor + * @param linear The linear attenuation factor + */ + public void setLinear(float linear) { + this.linear = linear; + } + + /** + * Sets the quadratic attenuation factor + * @param quadratic The quadratic attenuation factor + */ + public void setQuadratic(float quadratic) { + this.quadratic = quadratic; + } + + /** + * Sets the radius of the light + * @param radius The radius of the light + */ + public void setRadius(float radius){ + this.radius = radius; + } + + /** + * Sets the color of the light + * @param color The color of the light + */ + public void setColor(Vector3f color){ + this.color = color; + } + + /** + * Gets the constant attenuation factor + * @return The constant attenuation factor + */ + public float getConstant() { + return constant; + } + + /** + * Gets the linear attenuation factor + * @return The linear attenuation factor + */ + public float getLinear() { + return linear; + } + + /** + * Gets the quadratic attenuation factor + * @return The quadratic attenuation factor + */ + public float getQuadratic() { + return quadratic; + } + + /** + * Gets the color of the light + * @return The color of the light + */ + public Vector3f getColor(){ + return color; + } + + /** + * Gets the radius of the light + * @return The radius of the light + */ + public float getRadius(){ + return radius; + } + +} diff --git a/src/main/java/electrosphere/renderer/light/LightManager.java b/src/main/java/electrosphere/renderer/light/LightManager.java index 90e8b895..74611f1f 100644 --- a/src/main/java/electrosphere/renderer/light/LightManager.java +++ b/src/main/java/electrosphere/renderer/light/LightManager.java @@ -3,7 +3,6 @@ package electrosphere.renderer.light; import java.nio.ByteBuffer; import java.util.HashMap; import java.util.Map; -import java.util.Random; import org.joml.Matrix4d; import org.joml.Vector3f; @@ -13,7 +12,7 @@ import electrosphere.client.entity.camera.CameraEntityUtils; import electrosphere.engine.Globals; import electrosphere.engine.assetmanager.AssetDataStrings; import electrosphere.entity.Entity; -import electrosphere.entity.EntityCreationUtils; +import electrosphere.game.data.common.light.PointLightDescription; import electrosphere.logger.LoggerInterface; import electrosphere.renderer.OpenGLState; import electrosphere.renderer.RenderPipelineState; @@ -175,15 +174,6 @@ public class LightManager { rVal.entityPointLightMap = new HashMap+ * Note: If there is a light already assigned to the entity, it will be overwritten by the new light + *
+ * @param entity The entity to assign the light to + * @param description The description + * @return The light + */ + public PointLight createPointLight(Entity entity, PointLightDescription description){ + PointLight light = new PointLight(description); + this.entityPointLightMap.put(entity, light); + return light; + } + } \ No newline at end of file diff --git a/src/main/java/electrosphere/renderer/light/PointLight.java b/src/main/java/electrosphere/renderer/light/PointLight.java index beeddbf6..600b6618 100644 --- a/src/main/java/electrosphere/renderer/light/PointLight.java +++ b/src/main/java/electrosphere/renderer/light/PointLight.java @@ -2,6 +2,8 @@ package electrosphere.renderer.light; import org.joml.Vector3f; +import electrosphere.game.data.common.light.PointLightDescription; + /** * Data about a point light */ @@ -61,7 +63,7 @@ public class PointLight { return radius; } - public PointLight(Vector3f position){ + protected PointLight(Vector3f position){ this.position = position; radius = 1; constant = 1.0f; @@ -70,7 +72,7 @@ public class PointLight { color = new Vector3f(1.0f); } - public PointLight(Vector3f position, Vector3f color){ + protected PointLight(Vector3f position, Vector3f color){ this.position = position; radius = 1; constant = 1.0f; @@ -78,4 +80,16 @@ public class PointLight { quadratic = 1.8f; this.color = color; } + + /** + * Creates a point light from a light description + * @param description The description + */ + protected PointLight(PointLightDescription description){ + this.radius = description.getRadius(); + this.constant = description.getConstant(); + this.linear = description.getLinear(); + this.quadratic = description.getQuadratic(); + this.color = description.getColor(); + } } \ No newline at end of file