Create working lighting system
This commit is contained in:
@@ -11,6 +11,7 @@ import com.bartlomiejpluta.base.api.gui.GUI;
|
||||
import com.bartlomiejpluta.base.api.icon.Icon;
|
||||
import com.bartlomiejpluta.base.api.image.Image;
|
||||
import com.bartlomiejpluta.base.api.input.Input;
|
||||
import com.bartlomiejpluta.base.api.light.Light;
|
||||
import com.bartlomiejpluta.base.api.map.model.GameMap;
|
||||
import com.bartlomiejpluta.base.api.runner.GameRunner;
|
||||
import com.bartlomiejpluta.base.api.screen.Screen;
|
||||
@@ -47,6 +48,8 @@ public interface Context extends Updatable, Renderable, Disposable {
|
||||
|
||||
Entity createAbstractEntity();
|
||||
|
||||
Light createLight();
|
||||
|
||||
Icon createIcon(String iconSetUid, int row, int column);
|
||||
|
||||
Image getImage(String imageUid);
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.bartlomiejpluta.base.api.light;
|
||||
|
||||
import com.bartlomiejpluta.base.api.location.Locationable;
|
||||
import com.bartlomiejpluta.base.internal.logic.Updatable;
|
||||
import com.bartlomiejpluta.base.internal.render.Renderable;
|
||||
import org.joml.Vector3fc;
|
||||
|
||||
public interface Light extends Locationable, Updatable, Renderable {
|
||||
boolean isLuminescent();
|
||||
|
||||
void setLuminescent(boolean luminescent);
|
||||
|
||||
default void enableLuminescent() {
|
||||
setLuminescent(true);
|
||||
}
|
||||
|
||||
default void disableLuminescent() {
|
||||
setLuminescent(false);
|
||||
}
|
||||
|
||||
default void toggleLuminescent() {
|
||||
setLuminescent(!isLuminescent());
|
||||
}
|
||||
|
||||
Vector3fc getIntensity();
|
||||
|
||||
default void setIntensity(Vector3fc intensity) {
|
||||
setIntensity(intensity.x(), intensity.y(), intensity.z());
|
||||
}
|
||||
|
||||
void setIntensity(float red, float green, float blue);
|
||||
|
||||
float getConstantAttenuation();
|
||||
|
||||
float getLinearAttenuation();
|
||||
|
||||
float getQuadraticAttenuation();
|
||||
|
||||
void setConstantAttenuation(float attenuation);
|
||||
|
||||
void setLinearAttenuation(float attenuation);
|
||||
|
||||
void setQuadraticAttenuation(float attenuation);
|
||||
|
||||
default void setAttenuation(float constant, float linear, float quadratic) {
|
||||
setConstantAttenuation(constant);
|
||||
setLinearAttenuation(linear);
|
||||
setQuadraticAttenuation(quadratic);
|
||||
}
|
||||
|
||||
default void setAttenuation(Vector3fc attenuation) {
|
||||
setConstantAttenuation(attenuation.x());
|
||||
setLinearAttenuation(attenuation.y());
|
||||
setQuadraticAttenuation(attenuation.z());
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,23 @@ package com.bartlomiejpluta.base.api.map.layer.base;
|
||||
|
||||
import com.bartlomiejpluta.base.api.animation.Animation;
|
||||
import com.bartlomiejpluta.base.api.event.Reactive;
|
||||
import com.bartlomiejpluta.base.api.light.Light;
|
||||
import com.bartlomiejpluta.base.api.map.model.GameMap;
|
||||
import com.bartlomiejpluta.base.internal.logic.Updatable;
|
||||
import com.bartlomiejpluta.base.internal.render.Renderable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface Layer extends Renderable, Updatable, Reactive {
|
||||
GameMap getMap();
|
||||
|
||||
void pushAnimation(Animation animation);
|
||||
|
||||
void addLight(Light light);
|
||||
|
||||
void removeLight(Light light);
|
||||
|
||||
void clearLights();
|
||||
|
||||
List<Light> getLights();
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package com.bartlomiejpluta.base.api.map.model;
|
||||
|
||||
import com.bartlomiejpluta.base.api.event.Reactive;
|
||||
import com.bartlomiejpluta.base.api.map.layer.base.Layer;
|
||||
import com.bartlomiejpluta.base.api.map.layer.color.ColorLayer;
|
||||
import com.bartlomiejpluta.base.api.map.layer.image.ImageLayer;
|
||||
import com.bartlomiejpluta.base.api.map.layer.object.ObjectLayer;
|
||||
import com.bartlomiejpluta.base.api.map.layer.tile.TileLayer;
|
||||
import org.joml.Vector2fc;
|
||||
import org.joml.Vector3fc;
|
||||
|
||||
public interface GameMap extends Reactive {
|
||||
float getWidth();
|
||||
@@ -20,6 +22,8 @@ public interface GameMap extends Reactive {
|
||||
|
||||
Vector2fc getStepSize();
|
||||
|
||||
Layer getLayer(int layerIndex);
|
||||
|
||||
TileLayer getTileLayer(int layerIndex);
|
||||
|
||||
ImageLayer getImageLayer(int layerIndex);
|
||||
@@ -27,4 +31,12 @@ public interface GameMap extends Reactive {
|
||||
ColorLayer getColorLayer(int layerIndex);
|
||||
|
||||
ObjectLayer getObjectLayer(int layerIndex);
|
||||
|
||||
Vector3fc getAmbientColor();
|
||||
|
||||
default void setAmbientColor(Vector3fc color) {
|
||||
setAmbientColor(color.x(), color.y(), color.z());
|
||||
}
|
||||
|
||||
void setAmbientColor(float red, float green, float blue);
|
||||
}
|
||||
|
||||
@@ -41,4 +41,14 @@ public interface ShaderManager extends Cleanable {
|
||||
ShaderManager setUniform(String uniformName, int index, Uniform uniform);
|
||||
|
||||
ShaderManager setUniforms(String uniformName, Uniform[] uniforms);
|
||||
|
||||
ShaderManager createCounter(String counterName);
|
||||
|
||||
int nextNumber(String counterName);
|
||||
|
||||
int topNumber(String counterName);
|
||||
|
||||
ShaderManager setUniformCounter(String uniformName, String counterName);
|
||||
|
||||
ShaderManager resetCounters();
|
||||
}
|
||||
@@ -0,0 +1,233 @@
|
||||
package com.bartlomiejpluta.base.lib.light;
|
||||
|
||||
import com.bartlomiejpluta.base.api.camera.Camera;
|
||||
import com.bartlomiejpluta.base.api.light.Light;
|
||||
import com.bartlomiejpluta.base.api.location.Locationable;
|
||||
import com.bartlomiejpluta.base.api.move.Direction;
|
||||
import com.bartlomiejpluta.base.api.screen.Screen;
|
||||
import com.bartlomiejpluta.base.internal.object.Placeable;
|
||||
import com.bartlomiejpluta.base.internal.render.ShaderManager;
|
||||
import lombok.NonNull;
|
||||
import org.joml.Matrix4fc;
|
||||
import org.joml.Vector2fc;
|
||||
import org.joml.Vector2ic;
|
||||
import org.joml.Vector3fc;
|
||||
|
||||
public class LightDelegate implements Light {
|
||||
protected final Light light;
|
||||
|
||||
protected LightDelegate(@NonNull Light light) {
|
||||
this.light = light;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStepSize(float x, float y) {
|
||||
light.setStepSize(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector2ic getCoordinates() {
|
||||
return light.getCoordinates();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCoordinates(Vector2ic coordinates) {
|
||||
light.setCoordinates(coordinates);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCoordinates(int x, int y) {
|
||||
light.setCoordinates(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector2fc getPositionOffset() {
|
||||
return light.getPositionOffset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPositionOffset(Vector2fc offset) {
|
||||
light.setPositionOffset(offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPositionOffset(float offsetX, float offsetY) {
|
||||
light.setPositionOffset(offsetX, offsetY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int chebyshevDistance(Locationable other) {
|
||||
return light.chebyshevDistance(other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int manhattanDistance(Locationable other) {
|
||||
return light.manhattanDistance(other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double euclideanDistance(Locationable other) {
|
||||
return light.euclideanDistance(other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Direction getDirectionTowards(Locationable target) {
|
||||
return light.getDirectionTowards(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector2fc getPosition() {
|
||||
return light.getPosition();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPosition(Vector2fc position) {
|
||||
light.setPosition(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPosition(float x, float y) {
|
||||
light.setPosition(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void movePosition(float x, float y) {
|
||||
light.movePosition(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void movePosition(Vector2fc position) {
|
||||
light.movePosition(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getRotation() {
|
||||
return light.getRotation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRotation(float rotation) {
|
||||
light.setRotation(rotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveRotation(float rotation) {
|
||||
light.moveRotation(rotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getScaleX() {
|
||||
return light.getScaleX();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScaleX(float scale) {
|
||||
light.setScaleX(scale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getScaleY() {
|
||||
return light.getScaleY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScaleY(float scale) {
|
||||
light.setScaleY(scale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScale(float scale) {
|
||||
light.setScale(scale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScale(float scaleX, float scaleY) {
|
||||
light.setScale(scaleX, scaleY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float euclideanDistance(Placeable other) {
|
||||
return light.euclideanDistance(other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double euclideanDistance(Vector2ic coordinates) {
|
||||
return light.euclideanDistance(coordinates);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int chebyshevDistance(Vector2ic coordinates) {
|
||||
return light.chebyshevDistance(coordinates);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int manhattanDistance(Vector2ic coordinates) {
|
||||
return light.manhattanDistance(coordinates);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Matrix4fc getModelMatrix() {
|
||||
return light.getModelMatrix();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLuminescent() {
|
||||
return light.isLuminescent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLuminescent(boolean luminescent) {
|
||||
light.setLuminescent(luminescent);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Vector3fc getIntensity() {
|
||||
return light.getIntensity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIntensity(float red, float green, float blue) {
|
||||
light.setIntensity(red, green, blue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getConstantAttenuation() {
|
||||
return light.getConstantAttenuation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getLinearAttenuation() {
|
||||
return light.getLinearAttenuation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getQuadraticAttenuation() {
|
||||
return light.getQuadraticAttenuation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConstantAttenuation(float attenuation) {
|
||||
light.setConstantAttenuation(attenuation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLinearAttenuation(float attenuation) {
|
||||
light.setLinearAttenuation(attenuation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setQuadraticAttenuation(float attenuation) {
|
||||
light.setQuadraticAttenuation(attenuation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float dt) {
|
||||
light.update(dt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Screen screen, Camera camera, ShaderManager shaderManager) {
|
||||
light.render(screen, camera, shaderManager);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user