Use Vector2*c read-only interfaces where possible
This commit is contained in:
@@ -33,7 +33,7 @@ public class FollowEntityAI implements AI {
|
|||||||
if (!path.isEmpty()) {
|
if (!path.isEmpty()) {
|
||||||
accumulator = recalculateInterval;
|
accumulator = recalculateInterval;
|
||||||
|
|
||||||
var node = new Vector2i(path.getLast()).sub(npc.getCoordinates());
|
var node = path.getLast().sub(npc.getCoordinates(), new Vector2i());
|
||||||
var direction = Direction.ofVector(node);
|
var direction = Direction.ofVector(node);
|
||||||
var movement = npc.prepareMovement(direction);
|
var movement = npc.prepareMovement(direction);
|
||||||
layer.pushMovement(movement);
|
layer.pushMovement(movement);
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ package com.bartlomiejpluta.base.api.game.camera;
|
|||||||
import com.bartlomiejpluta.base.api.game.window.Window;
|
import com.bartlomiejpluta.base.api.game.window.Window;
|
||||||
import com.bartlomiejpluta.base.api.internal.object.Placeable;
|
import com.bartlomiejpluta.base.api.internal.object.Placeable;
|
||||||
import com.bartlomiejpluta.base.api.internal.render.ShaderManager;
|
import com.bartlomiejpluta.base.api.internal.render.ShaderManager;
|
||||||
import org.joml.Matrix4f;
|
import org.joml.Matrix4fc;
|
||||||
|
|
||||||
public interface Camera extends Placeable {
|
public interface Camera extends Placeable {
|
||||||
Matrix4f computeViewModelMatrix(Matrix4f modelMatrix);
|
Matrix4fc computeViewModelMatrix(Matrix4fc modelMatrix);
|
||||||
|
|
||||||
void render(Window window, ShaderManager shaderManager);
|
void render(Window window, ShaderManager shaderManager);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.bartlomiejpluta.base.api.game.entity;
|
package com.bartlomiejpluta.base.api.game.entity;
|
||||||
|
|
||||||
import org.joml.Vector2i;
|
import org.joml.Vector2i;
|
||||||
|
import org.joml.Vector2ic;
|
||||||
|
|
||||||
import static java.lang.Math.PI;
|
import static java.lang.Math.PI;
|
||||||
import static org.joml.Math.atan2;
|
import static org.joml.Math.atan2;
|
||||||
@@ -13,37 +14,29 @@ public enum Direction {
|
|||||||
|
|
||||||
public final int x;
|
public final int x;
|
||||||
public final int y;
|
public final int y;
|
||||||
|
public final Vector2ic vector;
|
||||||
|
|
||||||
Direction(int x, int y) {
|
Direction(int x, int y) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
}
|
this.vector = new Vector2i(x, y);
|
||||||
|
|
||||||
public Vector2i asVector() {
|
|
||||||
return new Vector2i(x, y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Direction opposite() {
|
public Direction opposite() {
|
||||||
switch (this) {
|
return switch (this) {
|
||||||
case UP:
|
case UP -> DOWN;
|
||||||
return DOWN;
|
case RIGHT -> LEFT;
|
||||||
case RIGHT:
|
case DOWN -> UP;
|
||||||
return LEFT;
|
case LEFT -> RIGHT;
|
||||||
case DOWN:
|
};
|
||||||
return UP;
|
|
||||||
case LEFT:
|
|
||||||
return RIGHT;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Direction ofVector(Vector2i vector) {
|
public static Direction ofVector(Vector2ic vector) {
|
||||||
// X Versor = [1, 0]
|
// X Versor = [1, 0]
|
||||||
// dot = 1 * vector.x + 0 * vector.y = vector.x
|
// dot = 1 * vector.x + 0 * vector.y = vector.x
|
||||||
// det = 1 * vector.y - 0 * vector.x = vector.y
|
// det = 1 * vector.y - 0 * vector.x = vector.y
|
||||||
// angle = atan2(det, dot) = atan2(vector.y, vector.x)
|
// angle = atan2(det, dot) = atan2(vector.y, vector.x)
|
||||||
float angle = atan2(vector.y, vector.x);
|
float angle = atan2(vector.y(), vector.x());
|
||||||
|
|
||||||
if (-PI / 4 < angle && angle < PI / 4) {
|
if (-PI / 4 < angle && angle < PI / 4) {
|
||||||
return RIGHT;
|
return RIGHT;
|
||||||
|
|||||||
@@ -4,14 +4,14 @@ import com.bartlomiejpluta.base.api.game.map.layer.object.ObjectLayer;
|
|||||||
import com.bartlomiejpluta.base.api.internal.logic.Updatable;
|
import com.bartlomiejpluta.base.api.internal.logic.Updatable;
|
||||||
import com.bartlomiejpluta.base.api.internal.object.Placeable;
|
import com.bartlomiejpluta.base.api.internal.object.Placeable;
|
||||||
import com.bartlomiejpluta.base.api.internal.render.Renderable;
|
import com.bartlomiejpluta.base.api.internal.render.Renderable;
|
||||||
import org.joml.Vector2i;
|
import org.joml.Vector2ic;
|
||||||
|
|
||||||
public interface Entity extends Placeable, Renderable, Updatable {
|
public interface Entity extends Placeable, Renderable, Updatable {
|
||||||
void setStepSize(float x, float y);
|
void setStepSize(float x, float y);
|
||||||
|
|
||||||
Vector2i getCoordinates();
|
Vector2ic getCoordinates();
|
||||||
|
|
||||||
void setCoordinates(Vector2i coordinates);
|
void setCoordinates(Vector2ic coordinates);
|
||||||
|
|
||||||
void setCoordinates(int x, int y);
|
void setCoordinates(int x, int y);
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import com.bartlomiejpluta.base.api.game.map.layer.object.ObjectLayer;
|
|||||||
import com.bartlomiejpluta.base.api.game.window.Window;
|
import com.bartlomiejpluta.base.api.game.window.Window;
|
||||||
import com.bartlomiejpluta.base.api.internal.object.Placeable;
|
import com.bartlomiejpluta.base.api.internal.object.Placeable;
|
||||||
import com.bartlomiejpluta.base.api.internal.render.ShaderManager;
|
import com.bartlomiejpluta.base.api.internal.render.ShaderManager;
|
||||||
import org.joml.Matrix4f;
|
import org.joml.Matrix4fc;
|
||||||
import org.joml.Vector2f;
|
import org.joml.Vector2fc;
|
||||||
import org.joml.Vector2i;
|
import org.joml.Vector2ic;
|
||||||
|
|
||||||
public abstract class EntityDelegate implements Entity {
|
public abstract class EntityDelegate implements Entity {
|
||||||
protected final Entity entity;
|
protected final Entity entity;
|
||||||
@@ -22,12 +22,12 @@ public abstract class EntityDelegate implements Entity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Vector2i getCoordinates() {
|
public Vector2ic getCoordinates() {
|
||||||
return entity.getCoordinates();
|
return entity.getCoordinates();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCoordinates(Vector2i coordinates) {
|
public void setCoordinates(Vector2ic coordinates) {
|
||||||
entity.setCoordinates(coordinates);
|
entity.setCoordinates(coordinates);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ public abstract class EntityDelegate implements Entity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Vector2f getPosition() {
|
public Vector2fc getPosition() {
|
||||||
return entity.getPosition();
|
return entity.getPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ public abstract class EntityDelegate implements Entity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPosition(Vector2f position) {
|
public void setPosition(Vector2fc position) {
|
||||||
entity.setPosition(position);
|
entity.setPosition(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +107,7 @@ public abstract class EntityDelegate implements Entity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void movePosition(Vector2f position) {
|
public void movePosition(Vector2fc position) {
|
||||||
entity.movePosition(position);
|
entity.movePosition(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,7 +162,7 @@ public abstract class EntityDelegate implements Entity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Matrix4f getModelMatrix() {
|
public Matrix4fc getModelMatrix() {
|
||||||
return entity.getModelMatrix();
|
return entity.getModelMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
package com.bartlomiejpluta.base.api.game.entity;
|
package com.bartlomiejpluta.base.api.game.entity;
|
||||||
|
|
||||||
|
import org.joml.Vector2ic;
|
||||||
import org.joml.Vector2i;
|
|
||||||
|
|
||||||
public interface Movement {
|
public interface Movement {
|
||||||
boolean perform();
|
boolean perform();
|
||||||
|
|
||||||
Movement another();
|
Movement another();
|
||||||
|
|
||||||
Vector2i getFrom();
|
Vector2ic getFrom();
|
||||||
|
|
||||||
Vector2i getTo();
|
Vector2ic getTo();
|
||||||
|
|
||||||
Direction getDirection();
|
Direction getDirection();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import com.bartlomiejpluta.base.api.game.entity.Entity;
|
|||||||
import com.bartlomiejpluta.base.api.game.entity.Movement;
|
import com.bartlomiejpluta.base.api.game.entity.Movement;
|
||||||
import com.bartlomiejpluta.base.api.game.map.layer.base.Layer;
|
import com.bartlomiejpluta.base.api.game.map.layer.base.Layer;
|
||||||
import com.bartlomiejpluta.base.api.game.rule.Rule;
|
import com.bartlomiejpluta.base.api.game.rule.Rule;
|
||||||
import org.joml.Vector2i;
|
import org.joml.Vector2ic;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ public interface ObjectLayer extends Layer {
|
|||||||
|
|
||||||
PassageAbility[][] getPassageMap();
|
PassageAbility[][] getPassageMap();
|
||||||
|
|
||||||
boolean isTileReachable(Vector2i tileCoordinates);
|
boolean isTileReachable(Vector2ic tileCoordinates);
|
||||||
|
|
||||||
void pushMovement(Movement movement);
|
void pushMovement(Movement movement);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import com.bartlomiejpluta.base.api.game.map.layer.color.ColorLayer;
|
|||||||
import com.bartlomiejpluta.base.api.game.map.layer.image.ImageLayer;
|
import com.bartlomiejpluta.base.api.game.map.layer.image.ImageLayer;
|
||||||
import com.bartlomiejpluta.base.api.game.map.layer.object.ObjectLayer;
|
import com.bartlomiejpluta.base.api.game.map.layer.object.ObjectLayer;
|
||||||
import com.bartlomiejpluta.base.api.game.map.layer.tile.TileLayer;
|
import com.bartlomiejpluta.base.api.game.map.layer.tile.TileLayer;
|
||||||
import org.joml.Vector2f;
|
import org.joml.Vector2fc;
|
||||||
|
|
||||||
public interface GameMap {
|
public interface GameMap {
|
||||||
float getWidth();
|
float getWidth();
|
||||||
@@ -15,7 +15,7 @@ public interface GameMap {
|
|||||||
|
|
||||||
int getColumns();
|
int getColumns();
|
||||||
|
|
||||||
Vector2f getSize();
|
Vector2fc getSize();
|
||||||
|
|
||||||
TileLayer getTileLayer(int layerIndex);
|
TileLayer getTileLayer(int layerIndex);
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.bartlomiejpluta.base.api.game.window;
|
package com.bartlomiejpluta.base.api.game.window;
|
||||||
|
|
||||||
import com.bartlomiejpluta.base.api.game.input.Key;
|
import com.bartlomiejpluta.base.api.game.input.Key;
|
||||||
import org.joml.Vector2f;
|
import org.joml.Vector2fc;
|
||||||
|
|
||||||
public interface Window {
|
public interface Window {
|
||||||
void init();
|
void init();
|
||||||
@@ -10,7 +10,7 @@ public interface Window {
|
|||||||
|
|
||||||
int getHeight();
|
int getHeight();
|
||||||
|
|
||||||
Vector2f getSize();
|
Vector2fc getSize();
|
||||||
|
|
||||||
boolean isResized();
|
boolean isResized();
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,23 @@
|
|||||||
package com.bartlomiejpluta.base.api.internal.object;
|
package com.bartlomiejpluta.base.api.internal.object;
|
||||||
|
|
||||||
import org.joml.Matrix4f;
|
import org.joml.Matrix4fc;
|
||||||
import org.joml.Vector2f;
|
import org.joml.Vector2fc;
|
||||||
|
|
||||||
public interface Placeable {
|
public interface Placeable {
|
||||||
Vector2f getPosition();
|
Vector2fc getPosition();
|
||||||
|
|
||||||
void setPosition(float x, float y);
|
void setPosition(float x, float y);
|
||||||
void setPosition(Vector2f position);
|
|
||||||
|
void setPosition(Vector2fc position);
|
||||||
|
|
||||||
void movePosition(float x, float y);
|
void movePosition(float x, float y);
|
||||||
void movePosition(Vector2f position);
|
|
||||||
|
void movePosition(Vector2fc position);
|
||||||
|
|
||||||
float getRotation();
|
float getRotation();
|
||||||
|
|
||||||
void setRotation(float rotation);
|
void setRotation(float rotation);
|
||||||
|
|
||||||
void moveRotation(float rotation);
|
void moveRotation(float rotation);
|
||||||
|
|
||||||
float getScaleX();
|
float getScaleX();
|
||||||
@@ -28,5 +34,5 @@ public interface Placeable {
|
|||||||
|
|
||||||
float euclideanDistance(Placeable other);
|
float euclideanDistance(Placeable other);
|
||||||
|
|
||||||
Matrix4f getModelMatrix();
|
Matrix4fc getModelMatrix();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,15 +26,15 @@ public interface ShaderManager extends Cleanable {
|
|||||||
|
|
||||||
ShaderManager setUniform(String uniformName, float value);
|
ShaderManager setUniform(String uniformName, float value);
|
||||||
|
|
||||||
ShaderManager setUniform(String uniformName, Vector2f value);
|
ShaderManager setUniform(String uniformName, Vector2fc value);
|
||||||
|
|
||||||
ShaderManager setUniform(String uniformName, Vector3f value);
|
ShaderManager setUniform(String uniformName, Vector3fc value);
|
||||||
|
|
||||||
ShaderManager setUniform(String uniformName, Vector4f value);
|
ShaderManager setUniform(String uniformName, Vector4fc value);
|
||||||
|
|
||||||
ShaderManager setUniform(String uniformName, Matrix3f value);
|
ShaderManager setUniform(String uniformName, Matrix3fc value);
|
||||||
|
|
||||||
ShaderManager setUniform(String uniformName, Matrix4f value);
|
ShaderManager setUniform(String uniformName, Matrix4fc value);
|
||||||
|
|
||||||
ShaderManager setUniform(String uniformName, Uniform uniform);
|
ShaderManager setUniform(String uniformName, Uniform uniform);
|
||||||
|
|
||||||
|
|||||||
@@ -18,15 +18,15 @@ public interface ShaderProgram extends Disposable {
|
|||||||
|
|
||||||
void setUniform(String uniformName, float value);
|
void setUniform(String uniformName, float value);
|
||||||
|
|
||||||
void setUniform(String uniformName, Vector2f value);
|
void setUniform(String uniformName, Vector2fc value);
|
||||||
|
|
||||||
void setUniform(String uniformName, Vector3f value);
|
void setUniform(String uniformName, Vector3fc value);
|
||||||
|
|
||||||
void setUniform(String uniformName, Vector4f value);
|
void setUniform(String uniformName, Vector4fc value);
|
||||||
|
|
||||||
void setUniform(String uniformName, Matrix3f value);
|
void setUniform(String uniformName, Matrix3fc value);
|
||||||
|
|
||||||
void setUniform(String uniformName, Matrix4f value);
|
void setUniform(String uniformName, Matrix4fc value);
|
||||||
|
|
||||||
void setUniform(String uniformName, Uniform uniform);
|
void setUniform(String uniformName, Uniform uniform);
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.bartlomiejpluta.base.api.util.pathfinder;
|
|||||||
|
|
||||||
import com.bartlomiejpluta.base.api.game.map.layer.object.ObjectLayer;
|
import com.bartlomiejpluta.base.api.game.map.layer.object.ObjectLayer;
|
||||||
import org.joml.Vector2i;
|
import org.joml.Vector2i;
|
||||||
|
import org.joml.Vector2ic;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
@@ -37,7 +38,7 @@ public class AstarPathFinder implements PathFinder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LinkedList<Vector2i> findPath(ObjectLayer layer, Vector2i start, Vector2i end) {
|
public LinkedList<Vector2ic> findPath(ObjectLayer layer, Vector2ic start, Vector2ic end) {
|
||||||
var columns = layer.getMap().getColumns();
|
var columns = layer.getMap().getColumns();
|
||||||
var rows = layer.getMap().getRows();
|
var rows = layer.getMap().getRows();
|
||||||
|
|
||||||
@@ -158,13 +159,13 @@ public class AstarPathFinder implements PathFinder {
|
|||||||
return new LinkedList<>();
|
return new LinkedList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private float manhattanDistance(Vector2i a, Vector2i b) {
|
private float manhattanDistance(Vector2ic a, Vector2ic b) {
|
||||||
return (abs(a.x - b.x) + abs(a.y - b.y));
|
return (abs(a.x() - b.x()) + abs(a.y() - b.y()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private LinkedList<Vector2i> recreatePath(Node node) {
|
private LinkedList<Vector2ic> recreatePath(Node node) {
|
||||||
var current = node;
|
var current = node;
|
||||||
var list = new LinkedList<Vector2i>();
|
var list = new LinkedList<Vector2ic>();
|
||||||
|
|
||||||
while (current.parent != null) {
|
while (current.parent != null) {
|
||||||
list.add(current.position);
|
list.add(current.position);
|
||||||
@@ -176,11 +177,11 @@ public class AstarPathFinder implements PathFinder {
|
|||||||
|
|
||||||
private static class Node implements Comparable<Node> {
|
private static class Node implements Comparable<Node> {
|
||||||
public Node parent;
|
public Node parent;
|
||||||
public final Vector2i position;
|
public final Vector2ic position;
|
||||||
public float g = 0.0f;
|
public float g = 0.0f;
|
||||||
public float f = 0.0f;
|
public float f = 0.0f;
|
||||||
|
|
||||||
public Node(Vector2i position) {
|
public Node(Vector2ic position) {
|
||||||
this.position = position;
|
this.position = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package com.bartlomiejpluta.base.api.util.pathfinder;
|
package com.bartlomiejpluta.base.api.util.pathfinder;
|
||||||
|
|
||||||
import com.bartlomiejpluta.base.api.game.map.layer.object.ObjectLayer;
|
import com.bartlomiejpluta.base.api.game.map.layer.object.ObjectLayer;
|
||||||
import org.joml.Vector2i;
|
import org.joml.Vector2ic;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
public interface PathFinder {
|
public interface PathFinder {
|
||||||
LinkedList<Vector2i> findPath(ObjectLayer layer, Vector2i start, Vector2i end);
|
LinkedList<Vector2ic> findPath(ObjectLayer layer, Vector2ic start, Vector2ic end);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,14 +7,13 @@ import com.bartlomiejpluta.base.api.internal.render.ShaderManager;
|
|||||||
import com.bartlomiejpluta.base.engine.core.gl.object.texture.Texture;
|
import com.bartlomiejpluta.base.engine.core.gl.object.texture.Texture;
|
||||||
import com.bartlomiejpluta.base.engine.core.gl.shader.constant.UniformName;
|
import com.bartlomiejpluta.base.engine.core.gl.shader.constant.UniformName;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.joml.Vector2f;
|
import org.joml.*;
|
||||||
import org.joml.Vector3f;
|
|
||||||
import org.joml.Vector4f;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
public class Material implements Renderable {
|
public class Material implements Renderable {
|
||||||
private final Vector4f color = new Vector4f();
|
private final Vector4f color = new Vector4f();
|
||||||
private final Vector2f spritePosition = new Vector2f(0, 0);
|
private final Vector2f spritePosition = new Vector2f(0, 0);
|
||||||
|
|
||||||
|
@Getter
|
||||||
private final Texture texture;
|
private final Texture texture;
|
||||||
|
|
||||||
private Material(Texture texture, float red, float green, float blue, float alpha) {
|
private Material(Texture texture, float red, float green, float blue, float alpha) {
|
||||||
@@ -37,17 +36,21 @@ public class Material implements Renderable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setColor(Vector4f color) {
|
public Vector4fc getColor() {
|
||||||
this.color.x = color.x;
|
return color;
|
||||||
this.color.y = color.y;
|
|
||||||
this.color.z = color.z;
|
|
||||||
this.color.w = color.w;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setColor(Vector3f color) {
|
public void setColor(Vector4fc color) {
|
||||||
this.color.x = color.x;
|
this.color.x = color.x();
|
||||||
this.color.y = color.y;
|
this.color.y = color.y();
|
||||||
this.color.z = color.z;
|
this.color.z = color.z();
|
||||||
|
this.color.w = color.w();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColor(Vector3fc color) {
|
||||||
|
this.color.x = color.x();
|
||||||
|
this.color.y = color.y();
|
||||||
|
this.color.z = color.z();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setColor(float red, float green, float blue, float alpha) {
|
public void setColor(float red, float green, float blue, float alpha) {
|
||||||
@@ -79,19 +82,23 @@ public class Material implements Renderable {
|
|||||||
this.color.w = alpha;
|
this.color.w = alpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSpritePosition(Vector2f spritePosition) {
|
public Vector2fc getSpritePosition() {
|
||||||
|
return spritePosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSpritePosition(Vector2fc spritePosition) {
|
||||||
if (texture != null) {
|
if (texture != null) {
|
||||||
var size = texture.getSpriteFragment();
|
var size = texture.getSpriteFragment();
|
||||||
this.spritePosition.x = size.x * spritePosition.x;
|
this.spritePosition.x = size.x() * spritePosition.x();
|
||||||
this.spritePosition.y = size.y * spritePosition.y;
|
this.spritePosition.y = size.y() * spritePosition.y();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSpritePosition(float x, float y) {
|
public void setSpritePosition(float x, float y) {
|
||||||
if (texture != null) {
|
if (texture != null) {
|
||||||
var size = texture.getSpriteFragment();
|
var size = texture.getSpriteFragment();
|
||||||
this.spritePosition.x = size.x * x;
|
this.spritePosition.x = size.x() * x;
|
||||||
this.spritePosition.y = size.y * y;
|
this.spritePosition.y = size.y() * y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.bartlomiejpluta.base.api.internal.gc.Disposable;
|
|||||||
import com.bartlomiejpluta.base.engine.error.AppException;
|
import com.bartlomiejpluta.base.engine.error.AppException;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.joml.Vector2f;
|
import org.joml.Vector2f;
|
||||||
|
import org.joml.Vector2fc;
|
||||||
import org.lwjgl.system.MemoryStack;
|
import org.lwjgl.system.MemoryStack;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
@@ -35,10 +36,10 @@ public class Texture implements Disposable {
|
|||||||
private final int columns;
|
private final int columns;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final Vector2f spriteFragment;
|
private final Vector2fc spriteFragment;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final Vector2f spriteSize;
|
private final Vector2fc spriteSize;
|
||||||
|
|
||||||
|
|
||||||
Texture(String textureFilename, ByteBuffer buffer, int rows, int columns) {
|
Texture(String textureFilename, ByteBuffer buffer, int rows, int columns) {
|
||||||
|
|||||||
@@ -95,31 +95,31 @@ public class DefaultShaderManager implements ShaderManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ShaderManager setUniform(String uniformName, Vector2f value) {
|
public ShaderManager setUniform(String uniformName, Vector2fc value) {
|
||||||
current.setUniform(uniformName, value);
|
current.setUniform(uniformName, value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ShaderManager setUniform(String uniformName, Vector3f value) {
|
public ShaderManager setUniform(String uniformName, Vector3fc value) {
|
||||||
current.setUniform(uniformName, value);
|
current.setUniform(uniformName, value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ShaderManager setUniform(String uniformName, Vector4f value) {
|
public ShaderManager setUniform(String uniformName, Vector4fc value) {
|
||||||
current.setUniform(uniformName, value);
|
current.setUniform(uniformName, value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ShaderManager setUniform(String uniformName, Matrix3f value) {
|
public ShaderManager setUniform(String uniformName, Matrix3fc value) {
|
||||||
current.setUniform(uniformName, value);
|
current.setUniform(uniformName, value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ShaderManager setUniform(String uniformName, Matrix4f value) {
|
public ShaderManager setUniform(String uniformName, Matrix4fc value) {
|
||||||
current.setUniform(uniformName, value);
|
current.setUniform(uniformName, value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,22 +117,22 @@ public class GLShaderProgram implements ShaderProgram {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUniform(String uniformName, Vector2f value) {
|
public void setUniform(String uniformName, Vector2fc value) {
|
||||||
glUniform2f(uniforms.get(uniformName), value.x, value.y);
|
glUniform2f(uniforms.get(uniformName), value.x(), value.y());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUniform(String uniformName, Vector3f value) {
|
public void setUniform(String uniformName, Vector3fc value) {
|
||||||
glUniform3f(uniforms.get(uniformName), value.x, value.y, value.z);
|
glUniform3f(uniforms.get(uniformName), value.x(), value.y(), value.z());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUniform(String uniformName, Vector4f value) {
|
public void setUniform(String uniformName, Vector4fc value) {
|
||||||
glUniform4f(uniforms.get(uniformName), value.x, value.y, value.z, value.w);
|
glUniform4f(uniforms.get(uniformName), value.x(), value.y(), value.z(), value.w());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUniform(String uniformName, Matrix3f value) {
|
public void setUniform(String uniformName, Matrix3fc value) {
|
||||||
try (var stack = MemoryStack.stackPush()) {
|
try (var stack = MemoryStack.stackPush()) {
|
||||||
var buffer = stack.mallocFloat(3 * 3);
|
var buffer = stack.mallocFloat(3 * 3);
|
||||||
value.get(buffer);
|
value.get(buffer);
|
||||||
@@ -141,7 +141,7 @@ public class GLShaderProgram implements ShaderProgram {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUniform(String uniformName, Matrix4f value) {
|
public void setUniform(String uniformName, Matrix4fc value) {
|
||||||
try (var stack = MemoryStack.stackPush()) {
|
try (var stack = MemoryStack.stackPush()) {
|
||||||
var buffer = stack.mallocFloat(4 * 4);
|
var buffer = stack.mallocFloat(4 * 4);
|
||||||
value.get(buffer);
|
value.get(buffer);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import lombok.Getter;
|
|||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.joml.Vector2f;
|
import org.joml.Vector2f;
|
||||||
|
import org.joml.Vector2fc;
|
||||||
import org.lwjgl.glfw.GLFWErrorCallback;
|
import org.lwjgl.glfw.GLFWErrorCallback;
|
||||||
import org.lwjgl.glfw.GLFWVidMode;
|
import org.lwjgl.glfw.GLFWVidMode;
|
||||||
import org.lwjgl.opengl.GL;
|
import org.lwjgl.opengl.GL;
|
||||||
@@ -31,10 +32,13 @@ public class GLFWWindow implements Window {
|
|||||||
|
|
||||||
private boolean initialized = false;
|
private boolean initialized = false;
|
||||||
|
|
||||||
|
private final Vector2f size;
|
||||||
|
|
||||||
public GLFWWindow(@NonNull String title, int width, int height) {
|
public GLFWWindow(@NonNull String title, int width, int height) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
|
this.size = new Vector2f(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -73,6 +77,8 @@ public class GLFWWindow implements Window {
|
|||||||
GLFWWindow.this.width = width;
|
GLFWWindow.this.width = width;
|
||||||
GLFWWindow.this.height = height;
|
GLFWWindow.this.height = height;
|
||||||
GLFWWindow.this.resized = true;
|
GLFWWindow.this.resized = true;
|
||||||
|
GLFWWindow.this.size.x = width;
|
||||||
|
GLFWWindow.this.size.y = height;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Setup a key callback. It will be called every time a key is pressed, repeated or released.
|
// Setup a key callback. It will be called every time a key is pressed, repeated or released.
|
||||||
@@ -92,7 +98,7 @@ public class GLFWWindow implements Window {
|
|||||||
glfwMakeContextCurrent(windowHandle);
|
glfwMakeContextCurrent(windowHandle);
|
||||||
|
|
||||||
// Enable V-Sync
|
// Enable V-Sync
|
||||||
// glfwSwapInterval(1);
|
// glfwSwapInterval(1);
|
||||||
|
|
||||||
// Make the window visible
|
// Make the window visible
|
||||||
glfwShowWindow(windowHandle);
|
glfwShowWindow(windowHandle);
|
||||||
@@ -104,7 +110,7 @@ public class GLFWWindow implements Window {
|
|||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
// Set the clear color
|
// Set the clear color
|
||||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
clear(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -129,8 +135,8 @@ public class GLFWWindow implements Window {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Vector2f getSize() {
|
public Vector2fc getSize() {
|
||||||
return new Vector2f(width, height);
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Window create(String title, int width, int height) {
|
public static Window create(String title, int width, int height) {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import com.bartlomiejpluta.base.engine.core.gl.object.material.Material;
|
|||||||
import com.bartlomiejpluta.base.engine.core.gl.object.mesh.Mesh;
|
import com.bartlomiejpluta.base.engine.core.gl.object.mesh.Mesh;
|
||||||
import com.bartlomiejpluta.base.engine.world.object.Sprite;
|
import com.bartlomiejpluta.base.engine.world.object.Sprite;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import org.joml.Vector2f;
|
import org.joml.Vector2fc;
|
||||||
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public abstract class AnimatedSprite extends Sprite {
|
public abstract class AnimatedSprite extends Sprite {
|
||||||
@@ -21,7 +21,7 @@ public abstract class AnimatedSprite extends Sprite {
|
|||||||
|
|
||||||
public abstract boolean shouldAnimate();
|
public abstract boolean shouldAnimate();
|
||||||
|
|
||||||
public abstract Vector2f[] getSpriteAnimationFramesPositions();
|
public abstract Vector2fc[] getSpriteAnimationFramesPositions();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(Window window, Camera camera, ShaderManager shaderManager) {
|
public void render(Window window, Camera camera, ShaderManager shaderManager) {
|
||||||
|
|||||||
@@ -6,13 +6,14 @@ import com.bartlomiejpluta.base.api.internal.render.ShaderManager;
|
|||||||
import com.bartlomiejpluta.base.engine.core.gl.shader.constant.UniformName;
|
import com.bartlomiejpluta.base.engine.core.gl.shader.constant.UniformName;
|
||||||
import com.bartlomiejpluta.base.engine.world.object.Model;
|
import com.bartlomiejpluta.base.engine.world.object.Model;
|
||||||
import org.joml.Matrix4f;
|
import org.joml.Matrix4f;
|
||||||
|
import org.joml.Matrix4fc;
|
||||||
|
|
||||||
public class DefaultCamera extends Model implements Camera {
|
public class DefaultCamera extends Model implements Camera {
|
||||||
private final Matrix4f projectionMatrix = new Matrix4f();
|
private final Matrix4f projectionMatrix = new Matrix4f();
|
||||||
private final Matrix4f viewMatrix = new Matrix4f();
|
private final Matrix4f viewMatrix = new Matrix4f();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Matrix4f computeViewModelMatrix(Matrix4f modelMatrix) {
|
public Matrix4fc computeViewModelMatrix(Matrix4fc modelMatrix) {
|
||||||
return new Matrix4f(viewMatrix).mul(modelMatrix);
|
return new Matrix4f(viewMatrix).mul(modelMatrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.bartlomiejpluta.base.engine.world.entity.config;
|
|||||||
import com.bartlomiejpluta.base.api.game.entity.Direction;
|
import com.bartlomiejpluta.base.api.game.entity.Direction;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.joml.Vector2i;
|
import org.joml.Vector2i;
|
||||||
|
import org.joml.Vector2ic;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
@@ -16,13 +17,19 @@ public class EntitySpriteConfiguration {
|
|||||||
private int defaultSpriteColumn;
|
private int defaultSpriteColumn;
|
||||||
private Map<Direction, Integer> spriteDirectionRows;
|
private Map<Direction, Integer> spriteDirectionRows;
|
||||||
|
|
||||||
@Data
|
|
||||||
public static class EntitySpriteDimensionConfiguration {
|
public static class EntitySpriteDimensionConfiguration {
|
||||||
private int rows;
|
private final Vector2i vector = new Vector2i();
|
||||||
private int cols;
|
|
||||||
|
|
||||||
public Vector2i asVector() {
|
public Vector2ic asVector() {
|
||||||
return new Vector2i(rows, cols);
|
return vector;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRows(int rows) {
|
||||||
|
this.vector.y = rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCols(int cols) {
|
||||||
|
this.vector.x = cols;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,9 +28,9 @@ public class DefaultEntityManager implements EntityManager {
|
|||||||
private Mesh buildMesh(Material material) {
|
private Mesh buildMesh(Material material) {
|
||||||
var texture = material.getTexture();
|
var texture = material.getTexture();
|
||||||
var dimension = configuration.getDimension().asVector();
|
var dimension = configuration.getDimension().asVector();
|
||||||
var spriteWidth = texture.getWidth() / (float) dimension.y;
|
var spriteWidth = texture.getWidth() / (float) dimension.x();
|
||||||
var spriteHeight = texture.getHeight() / (float) dimension.x;
|
var spriteHeight = texture.getHeight() / (float) dimension.y();
|
||||||
return meshManager.createQuad(spriteWidth, spriteHeight, spriteWidth / 2, spriteHeight*0.9f);
|
return meshManager.createQuad(spriteWidth, spriteHeight, spriteWidth / 2, spriteHeight * 0.9f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -13,14 +13,17 @@ import lombok.EqualsAndHashCode;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.joml.Vector2f;
|
import org.joml.Vector2f;
|
||||||
|
import org.joml.Vector2fc;
|
||||||
import org.joml.Vector2i;
|
import org.joml.Vector2i;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static java.util.stream.Collectors.toUnmodifiableMap;
|
||||||
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public class DefaultEntity extends MovableSprite implements Entity {
|
public class DefaultEntity extends MovableSprite implements Entity {
|
||||||
private final Map<Direction, Integer> spriteDirectionRows;
|
private final Map<Direction, Integer> spriteDirectionRows;
|
||||||
private final int defaultSpriteColumn;
|
private final Map<Direction, Vector2fc> defaultAnimationFrames;
|
||||||
|
|
||||||
private int animationSpeed = 100;
|
private int animationSpeed = 100;
|
||||||
|
|
||||||
@@ -42,7 +45,7 @@ public class DefaultEntity extends MovableSprite implements Entity {
|
|||||||
private boolean blocking;
|
private boolean blocking;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Vector2f[] getSpriteAnimationFramesPositions() {
|
public Vector2fc[] getSpriteAnimationFramesPositions() {
|
||||||
var row = spriteDirectionRows.get(faceDirection);
|
var row = spriteDirectionRows.get(faceDirection);
|
||||||
var frames = material.getTexture().getRows();
|
var frames = material.getTexture().getRows();
|
||||||
var array = new Vector2f[frames];
|
var array = new Vector2f[frames];
|
||||||
@@ -56,7 +59,7 @@ public class DefaultEntity extends MovableSprite implements Entity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setDefaultAnimationFrame() {
|
protected void setDefaultAnimationFrame() {
|
||||||
material.setSpritePosition(new Vector2f(defaultSpriteColumn, spriteDirectionRows.get(faceDirection)));
|
material.setSpritePosition(defaultAnimationFrames.get(faceDirection));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -97,7 +100,7 @@ public class DefaultEntity extends MovableSprite implements Entity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Direction getDirectionTowards(Entity target) {
|
public Direction getDirectionTowards(Entity target) {
|
||||||
return Direction.ofVector(new Vector2i(target.getCoordinates()).sub(getCoordinates()));
|
return Direction.ofVector(target.getCoordinates().sub(getCoordinates(), new Vector2i()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -112,8 +115,14 @@ public class DefaultEntity extends MovableSprite implements Entity {
|
|||||||
|
|
||||||
public DefaultEntity(Mesh mesh, Material material, EntitySpriteConfiguration configuration) {
|
public DefaultEntity(Mesh mesh, Material material, EntitySpriteConfiguration configuration) {
|
||||||
super(mesh, material);
|
super(mesh, material);
|
||||||
this.defaultSpriteColumn = configuration.getDefaultSpriteColumn();
|
|
||||||
this.spriteDirectionRows = configuration.getSpriteDirectionRows();
|
this.spriteDirectionRows = configuration.getSpriteDirectionRows();
|
||||||
this.faceDirection = Direction.DOWN;
|
this.faceDirection = Direction.DOWN;
|
||||||
|
|
||||||
|
var defaultColumn = configuration.getDefaultSpriteColumn();
|
||||||
|
|
||||||
|
defaultAnimationFrames = spriteDirectionRows
|
||||||
|
.entrySet()
|
||||||
|
.stream()
|
||||||
|
.collect(toUnmodifiableMap(Map.Entry::getKey, entry -> new Vector2f(defaultColumn, entry.getValue())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,6 @@ public class DefaultImage extends Sprite implements Image {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getOpacity() {
|
public float getOpacity() {
|
||||||
return material.getColor().w;
|
return material.getColor().w();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ public class DefaultImageLayer implements ImageLayer {
|
|||||||
if (image != null) {
|
if (image != null) {
|
||||||
if (parallax) {
|
if (parallax) {
|
||||||
var cameraPosition = camera.getPosition();
|
var cameraPosition = camera.getPosition();
|
||||||
image.setPosition(cameraPosition.x + x, cameraPosition.y + y);
|
image.setPosition(cameraPosition.x() + x, cameraPosition.y() + y);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode == ImageLayerMode.FIT_SCREEN) {
|
if (mode == ImageLayerMode.FIT_SCREEN) {
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ import com.bartlomiejpluta.base.api.game.window.Window;
|
|||||||
import com.bartlomiejpluta.base.api.internal.render.ShaderManager;
|
import com.bartlomiejpluta.base.api.internal.render.ShaderManager;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import org.joml.Vector2f;
|
import org.joml.Vector2fc;
|
||||||
import org.joml.Vector2i;
|
import org.joml.Vector2ic;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
@@ -36,9 +36,9 @@ public class DefaultObjectLayer implements ObjectLayer {
|
|||||||
|
|
||||||
private final int rows;
|
private final int rows;
|
||||||
private final int columns;
|
private final int columns;
|
||||||
private final Vector2f stepSize;
|
private final Vector2fc stepSize;
|
||||||
|
|
||||||
public DefaultObjectLayer(@NonNull GameMap map, int rows, int columns, @NonNull Vector2f stepSize, List<Entity> entities, PassageAbility[][] passageMap) {
|
public DefaultObjectLayer(@NonNull GameMap map, int rows, int columns, @NonNull Vector2fc stepSize, List<Entity> entities, PassageAbility[][] passageMap) {
|
||||||
this.map = map;
|
this.map = map;
|
||||||
this.rows = rows;
|
this.rows = rows;
|
||||||
this.columns = columns;
|
this.columns = columns;
|
||||||
@@ -65,7 +65,7 @@ public class DefaultObjectLayer implements ObjectLayer {
|
|||||||
@Override
|
@Override
|
||||||
public void addEntity(Entity entity) {
|
public void addEntity(Entity entity) {
|
||||||
entity.onAdd(this);
|
entity.onAdd(this);
|
||||||
entity.setStepSize(stepSize.x, stepSize.y);
|
entity.setStepSize(stepSize.x(), stepSize.y());
|
||||||
entities.add(entity);
|
entities.add(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,13 +86,13 @@ public class DefaultObjectLayer implements ObjectLayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isTileReachable(Vector2i tileCoordinates) {
|
public boolean isTileReachable(Vector2ic tileCoordinates) {
|
||||||
// Is trying to go beyond the map
|
// Is trying to go beyond the map
|
||||||
if (tileCoordinates.x < 0 || tileCoordinates.y < 0 || tileCoordinates.x >= columns || tileCoordinates.y >= rows) {
|
if (tileCoordinates.x() < 0 || tileCoordinates.y() < 0 || tileCoordinates.x() >= columns || tileCoordinates.y() >= rows) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (passageMap[tileCoordinates.y][tileCoordinates.x] != PassageAbility.ALLOW) {
|
if (passageMap[tileCoordinates.y()][tileCoordinates.x()] != PassageAbility.ALLOW) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,6 +159,6 @@ public class DefaultObjectLayer implements ObjectLayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int compareObjects(Entity a, Entity b) {
|
private int compareObjects(Entity a, Entity b) {
|
||||||
return Float.compare(a.getPosition().y, b.getPosition().y);
|
return Float.compare(a.getPosition().y(), b.getPosition().y());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import com.bartlomiejpluta.base.engine.world.tileset.model.TileSet;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import org.joml.Vector2f;
|
import org.joml.Vector2f;
|
||||||
|
import org.joml.Vector2fc;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -49,7 +50,10 @@ public class DefaultGameMap implements Renderable, Updatable, GameMap {
|
|||||||
private final float height;
|
private final float height;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final Vector2f stepSize;
|
private final Vector2fc stepSize;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final Vector2fc size;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final String handler;
|
private final String handler;
|
||||||
@@ -59,8 +63,9 @@ public class DefaultGameMap implements Renderable, Updatable, GameMap {
|
|||||||
this.rows = rows;
|
this.rows = rows;
|
||||||
this.columns = columns;
|
this.columns = columns;
|
||||||
this.stepSize = new Vector2f(tileSet.getTileSet().getSpriteSize());
|
this.stepSize = new Vector2f(tileSet.getTileSet().getSpriteSize());
|
||||||
this.width = columns * stepSize.x;
|
this.width = columns * stepSize.x();
|
||||||
this.height = rows * stepSize.y;
|
this.height = rows * stepSize.y();
|
||||||
|
this.size = new Vector2f(columns * stepSize.x(), rows * stepSize.y());
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,11 +83,6 @@ public class DefaultGameMap implements Renderable, Updatable, GameMap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Vector2f getSize() {
|
|
||||||
return new Vector2f(columns * stepSize.x, rows * stepSize.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TileLayer getTileLayer(int layerIndex) {
|
public TileLayer getTileLayer(int layerIndex) {
|
||||||
return (TileLayer) layers.get(layerIndex);
|
return (TileLayer) layers.get(layerIndex);
|
||||||
|
|||||||
@@ -2,23 +2,25 @@ package com.bartlomiejpluta.base.engine.world.movement;
|
|||||||
|
|
||||||
import com.bartlomiejpluta.base.api.game.entity.Direction;
|
import com.bartlomiejpluta.base.api.game.entity.Direction;
|
||||||
import com.bartlomiejpluta.base.api.game.entity.Movement;
|
import com.bartlomiejpluta.base.api.game.entity.Movement;
|
||||||
import lombok.Data;
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.Getter;
|
||||||
import org.joml.Vector2i;
|
import org.joml.Vector2i;
|
||||||
|
import org.joml.Vector2ic;
|
||||||
|
|
||||||
@Data
|
@Getter
|
||||||
|
@EqualsAndHashCode
|
||||||
public class DefaultMovement implements Movement {
|
public class DefaultMovement implements Movement {
|
||||||
private final MovableSprite object;
|
private final MovableSprite object;
|
||||||
private final Direction direction;
|
private final Direction direction;
|
||||||
private final Vector2i from;
|
private final Vector2ic from;
|
||||||
private final Vector2i to;
|
private final Vector2ic to;
|
||||||
private boolean performed = false;
|
|
||||||
|
|
||||||
DefaultMovement(MovableSprite object, Direction direction) {
|
DefaultMovement(MovableSprite object, Direction direction) {
|
||||||
this.object = object;
|
this.object = object;
|
||||||
this.direction = direction;
|
this.direction = direction;
|
||||||
|
|
||||||
this.from = object.getCoordinates();
|
this.from = object.getCoordinates();
|
||||||
this.to = direction.asVector().add(object.getCoordinates());
|
this.to = direction.vector.add(object.getCoordinates(), new Vector2i());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -30,14 +32,4 @@ public class DefaultMovement implements Movement {
|
|||||||
public Movement another() {
|
public Movement another() {
|
||||||
return object.prepareMovement(direction);
|
return object.prepareMovement(direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Vector2i getFrom() {
|
|
||||||
return from;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Vector2i getTo() {
|
|
||||||
return to;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -10,6 +10,7 @@ import lombok.EqualsAndHashCode;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.joml.Vector2f;
|
import org.joml.Vector2f;
|
||||||
import org.joml.Vector2i;
|
import org.joml.Vector2i;
|
||||||
|
import org.joml.Vector2ic;
|
||||||
|
|
||||||
import static java.lang.Math.abs;
|
import static java.lang.Math.abs;
|
||||||
import static java.lang.Math.max;
|
import static java.lang.Math.max;
|
||||||
@@ -21,7 +22,6 @@ public abstract class MovableSprite extends AnimatedSprite implements Updatable
|
|||||||
private int moveTime = 0;
|
private int moveTime = 0;
|
||||||
private Vector2f movementVector;
|
private Vector2f movementVector;
|
||||||
|
|
||||||
@Getter
|
|
||||||
private final Vector2i coordinates = new Vector2i(0, 0);
|
private final Vector2i coordinates = new Vector2i(0, 0);
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@@ -29,6 +29,10 @@ public abstract class MovableSprite extends AnimatedSprite implements Updatable
|
|||||||
|
|
||||||
protected int framesToCrossOneTile = 1;
|
protected int framesToCrossOneTile = 1;
|
||||||
|
|
||||||
|
public Vector2ic getCoordinates() {
|
||||||
|
return coordinates;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isMoving() {
|
public boolean isMoving() {
|
||||||
return movement != null;
|
return movement != null;
|
||||||
}
|
}
|
||||||
@@ -67,9 +71,11 @@ public abstract class MovableSprite extends AnimatedSprite implements Updatable
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var direction = movement.getDirection().vector;
|
||||||
|
|
||||||
this.movement = movement;
|
this.movement = movement;
|
||||||
var speed = new Vector2f(coordinateStepSize).div(framesToCrossOneTile);
|
var speed = new Vector2f(coordinateStepSize).div(framesToCrossOneTile);
|
||||||
movementVector = new Vector2f(movement.getDirection().x, movement.getDirection().y).mul(speed);
|
movementVector = new Vector2f(speed.x * direction.x(), speed.y * direction.y());
|
||||||
moveTime = framesToCrossOneTile;
|
moveTime = framesToCrossOneTile;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -81,8 +87,8 @@ public abstract class MovableSprite extends AnimatedSprite implements Updatable
|
|||||||
setPosition((x + 0.5f) * coordinateStepSize.x, (y + 0.5f) * coordinateStepSize.y);
|
setPosition((x + 0.5f) * coordinateStepSize.x, (y + 0.5f) * coordinateStepSize.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCoordinates(Vector2i coordinates) {
|
public void setCoordinates(Vector2ic coordinates) {
|
||||||
setCoordinates(coordinates.x, coordinates.y);
|
setCoordinates(coordinates.x(), coordinates.y());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStepSize(float x, float y) {
|
public void setStepSize(float x, float y) {
|
||||||
@@ -91,12 +97,12 @@ public abstract class MovableSprite extends AnimatedSprite implements Updatable
|
|||||||
setCoordinates(coordinates);
|
setCoordinates(coordinates);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int chebyshevDistance(Vector2i coordinates) {
|
public int chebyshevDistance(Vector2ic coordinates) {
|
||||||
return max(abs(this.coordinates.x - coordinates.x), abs(this.coordinates.y - coordinates.y));
|
return max(abs(this.coordinates.x - coordinates.x()), abs(this.coordinates.y - coordinates.y()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public int manhattanDistance(Vector2i coordinates) {
|
public int manhattanDistance(Vector2ic coordinates) {
|
||||||
return abs(this.coordinates.x - coordinates.x) + abs(this.coordinates.y - coordinates.y);
|
return abs(this.coordinates.x - coordinates.x()) + abs(this.coordinates.y - coordinates.y());
|
||||||
}
|
}
|
||||||
|
|
||||||
public MovableSprite(Mesh mesh, Material material) {
|
public MovableSprite(Mesh mesh, Material material) {
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ import lombok.EqualsAndHashCode;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.joml.Matrix4f;
|
import org.joml.Matrix4f;
|
||||||
|
import org.joml.Matrix4fc;
|
||||||
import org.joml.Vector2f;
|
import org.joml.Vector2f;
|
||||||
|
import org.joml.Vector2fc;
|
||||||
|
|
||||||
import static java.lang.Math.toRadians;
|
import static java.lang.Math.toRadians;
|
||||||
|
|
||||||
@@ -13,7 +15,6 @@ import static java.lang.Math.toRadians;
|
|||||||
public abstract class Model implements Placeable {
|
public abstract class Model implements Placeable {
|
||||||
private final Matrix4f modelMatrix = new Matrix4f();
|
private final Matrix4f modelMatrix = new Matrix4f();
|
||||||
|
|
||||||
@Getter
|
|
||||||
protected final Vector2f position = new Vector2f(0, 0);
|
protected final Vector2f position = new Vector2f(0, 0);
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@@ -28,6 +29,11 @@ public abstract class Model implements Placeable {
|
|||||||
@Setter
|
@Setter
|
||||||
protected float scaleY = 1.0f;
|
protected float scaleY = 1.0f;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Vector2fc getPosition() {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPosition(float x, float y) {
|
public void setPosition(float x, float y) {
|
||||||
position.x = x;
|
position.x = x;
|
||||||
@@ -35,9 +41,9 @@ public abstract class Model implements Placeable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPosition(Vector2f position) {
|
public void setPosition(Vector2fc position) {
|
||||||
this.position.x = position.x;
|
this.position.x = position.x();
|
||||||
this.position.y = position.y;
|
this.position.y = position.y();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -47,9 +53,9 @@ public abstract class Model implements Placeable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void movePosition(Vector2f position) {
|
public void movePosition(Vector2fc position) {
|
||||||
this.position.x += position.x;
|
this.position.x += position.x();
|
||||||
this.position.y += position.y;
|
this.position.y += position.y();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -75,7 +81,7 @@ public abstract class Model implements Placeable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Matrix4f getModelMatrix() {
|
public Matrix4fc getModelMatrix() {
|
||||||
return modelMatrix
|
return modelMatrix
|
||||||
.identity()
|
.identity()
|
||||||
.translate(position.x, position.y, 0)
|
.translate(position.x, position.y, 0)
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public class DefaultTileSetManager implements TileSetManager {
|
|||||||
var source = configuration.projectFile("tilesets", asset.getSource());
|
var source = configuration.projectFile("tilesets", asset.getSource());
|
||||||
var texture = textureManager.loadTexture(source, asset.getRows(), asset.getColumns());
|
var texture = textureManager.loadTexture(source, asset.getRows(), asset.getColumns());
|
||||||
var size = texture.getSpriteSize();
|
var size = texture.getSpriteSize();
|
||||||
var mesh = meshManager.createQuad(size.x, size.y, 0, 0);
|
var mesh = meshManager.createQuad(size.x(), size.y(), 0, 0);
|
||||||
tileset = new TileSet(texture, mesh);
|
tileset = new TileSet(texture, mesh);
|
||||||
log.info("Loading tile set from assets to cache under the key: [{}]", uid);
|
log.info("Loading tile set from assets to cache under the key: [{}]", uid);
|
||||||
tileSets.put(uid, tileset);
|
tileSets.put(uid, tileset);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public class Tile extends Sprite {
|
|||||||
|
|
||||||
public Tile setCoordinates(int row, int column) {
|
public Tile setCoordinates(int row, int column) {
|
||||||
var stepSize = material.getTexture().getSpriteSize();
|
var stepSize = material.getTexture().getSpriteSize();
|
||||||
setPosition(column * stepSize.x, row * stepSize.y);
|
setPosition(column * stepSize.x(), row * stepSize.y());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user