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()) {
|
||||
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 movement = npc.prepareMovement(direction);
|
||||
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.internal.object.Placeable;
|
||||
import com.bartlomiejpluta.base.api.internal.render.ShaderManager;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Matrix4fc;
|
||||
|
||||
public interface Camera extends Placeable {
|
||||
Matrix4f computeViewModelMatrix(Matrix4f modelMatrix);
|
||||
Matrix4fc computeViewModelMatrix(Matrix4fc modelMatrix);
|
||||
|
||||
void render(Window window, ShaderManager shaderManager);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.bartlomiejpluta.base.api.game.entity;
|
||||
|
||||
import org.joml.Vector2i;
|
||||
import org.joml.Vector2ic;
|
||||
|
||||
import static java.lang.Math.PI;
|
||||
import static org.joml.Math.atan2;
|
||||
@@ -13,37 +14,29 @@ public enum Direction {
|
||||
|
||||
public final int x;
|
||||
public final int y;
|
||||
public final Vector2ic vector;
|
||||
|
||||
Direction(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public Vector2i asVector() {
|
||||
return new Vector2i(x, y);
|
||||
this.vector = new Vector2i(x, y);
|
||||
}
|
||||
|
||||
public Direction opposite() {
|
||||
switch (this) {
|
||||
case UP:
|
||||
return DOWN;
|
||||
case RIGHT:
|
||||
return LEFT;
|
||||
case DOWN:
|
||||
return UP;
|
||||
case LEFT:
|
||||
return RIGHT;
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException();
|
||||
return switch (this) {
|
||||
case UP -> DOWN;
|
||||
case RIGHT -> LEFT;
|
||||
case DOWN -> UP;
|
||||
case LEFT -> RIGHT;
|
||||
};
|
||||
}
|
||||
|
||||
public static Direction ofVector(Vector2i vector) {
|
||||
public static Direction ofVector(Vector2ic vector) {
|
||||
// X Versor = [1, 0]
|
||||
// dot = 1 * vector.x + 0 * vector.y = vector.x
|
||||
// det = 1 * vector.y - 0 * vector.x = vector.y
|
||||
// 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) {
|
||||
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.object.Placeable;
|
||||
import com.bartlomiejpluta.base.api.internal.render.Renderable;
|
||||
import org.joml.Vector2i;
|
||||
import org.joml.Vector2ic;
|
||||
|
||||
public interface Entity extends Placeable, Renderable, Updatable {
|
||||
void setStepSize(float x, float y);
|
||||
|
||||
Vector2i getCoordinates();
|
||||
Vector2ic getCoordinates();
|
||||
|
||||
void setCoordinates(Vector2i coordinates);
|
||||
void setCoordinates(Vector2ic coordinates);
|
||||
|
||||
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.internal.object.Placeable;
|
||||
import com.bartlomiejpluta.base.api.internal.render.ShaderManager;
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Vector2i;
|
||||
import org.joml.Matrix4fc;
|
||||
import org.joml.Vector2fc;
|
||||
import org.joml.Vector2ic;
|
||||
|
||||
public abstract class EntityDelegate implements Entity {
|
||||
protected final Entity entity;
|
||||
@@ -22,12 +22,12 @@ public abstract class EntityDelegate implements Entity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector2i getCoordinates() {
|
||||
public Vector2ic getCoordinates() {
|
||||
return entity.getCoordinates();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCoordinates(Vector2i coordinates) {
|
||||
public void setCoordinates(Vector2ic coordinates) {
|
||||
entity.setCoordinates(coordinates);
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ public abstract class EntityDelegate implements Entity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector2f getPosition() {
|
||||
public Vector2fc getPosition() {
|
||||
return entity.getPosition();
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ public abstract class EntityDelegate implements Entity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPosition(Vector2f position) {
|
||||
public void setPosition(Vector2fc position) {
|
||||
entity.setPosition(position);
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ public abstract class EntityDelegate implements Entity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void movePosition(Vector2f position) {
|
||||
public void movePosition(Vector2fc position) {
|
||||
entity.movePosition(position);
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ public abstract class EntityDelegate implements Entity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Matrix4f getModelMatrix() {
|
||||
public Matrix4fc getModelMatrix() {
|
||||
return entity.getModelMatrix();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
package com.bartlomiejpluta.base.api.game.entity;
|
||||
|
||||
|
||||
import org.joml.Vector2i;
|
||||
import org.joml.Vector2ic;
|
||||
|
||||
public interface Movement {
|
||||
boolean perform();
|
||||
|
||||
Movement another();
|
||||
|
||||
Vector2i getFrom();
|
||||
Vector2ic getFrom();
|
||||
|
||||
Vector2i getTo();
|
||||
Vector2ic getTo();
|
||||
|
||||
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.map.layer.base.Layer;
|
||||
import com.bartlomiejpluta.base.api.game.rule.Rule;
|
||||
import org.joml.Vector2i;
|
||||
import org.joml.Vector2ic;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -27,7 +27,7 @@ public interface ObjectLayer extends Layer {
|
||||
|
||||
PassageAbility[][] getPassageMap();
|
||||
|
||||
boolean isTileReachable(Vector2i tileCoordinates);
|
||||
boolean isTileReachable(Vector2ic tileCoordinates);
|
||||
|
||||
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.object.ObjectLayer;
|
||||
import com.bartlomiejpluta.base.api.game.map.layer.tile.TileLayer;
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Vector2fc;
|
||||
|
||||
public interface GameMap {
|
||||
float getWidth();
|
||||
@@ -15,7 +15,7 @@ public interface GameMap {
|
||||
|
||||
int getColumns();
|
||||
|
||||
Vector2f getSize();
|
||||
Vector2fc getSize();
|
||||
|
||||
TileLayer getTileLayer(int layerIndex);
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.bartlomiejpluta.base.api.game.window;
|
||||
|
||||
import com.bartlomiejpluta.base.api.game.input.Key;
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Vector2fc;
|
||||
|
||||
public interface Window {
|
||||
void init();
|
||||
@@ -10,7 +10,7 @@ public interface Window {
|
||||
|
||||
int getHeight();
|
||||
|
||||
Vector2f getSize();
|
||||
Vector2fc getSize();
|
||||
|
||||
boolean isResized();
|
||||
|
||||
|
||||
@@ -1,17 +1,23 @@
|
||||
package com.bartlomiejpluta.base.api.internal.object;
|
||||
|
||||
import org.joml.Matrix4f;
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Matrix4fc;
|
||||
import org.joml.Vector2fc;
|
||||
|
||||
public interface Placeable {
|
||||
Vector2f getPosition();
|
||||
Vector2fc getPosition();
|
||||
|
||||
void setPosition(float x, float y);
|
||||
void setPosition(Vector2f position);
|
||||
|
||||
void setPosition(Vector2fc position);
|
||||
|
||||
void movePosition(float x, float y);
|
||||
void movePosition(Vector2f position);
|
||||
|
||||
void movePosition(Vector2fc position);
|
||||
|
||||
float getRotation();
|
||||
|
||||
void setRotation(float rotation);
|
||||
|
||||
void moveRotation(float rotation);
|
||||
|
||||
float getScaleX();
|
||||
@@ -28,5 +34,5 @@ public interface Placeable {
|
||||
|
||||
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, 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);
|
||||
|
||||
|
||||
@@ -18,15 +18,15 @@ public interface ShaderProgram extends Disposable {
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.bartlomiejpluta.base.api.util.pathfinder;
|
||||
|
||||
import com.bartlomiejpluta.base.api.game.map.layer.object.ObjectLayer;
|
||||
import org.joml.Vector2i;
|
||||
import org.joml.Vector2ic;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
@@ -37,7 +38,7 @@ public class AstarPathFinder implements PathFinder {
|
||||
}
|
||||
|
||||
@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 rows = layer.getMap().getRows();
|
||||
|
||||
@@ -158,13 +159,13 @@ public class AstarPathFinder implements PathFinder {
|
||||
return new LinkedList<>();
|
||||
}
|
||||
|
||||
private float manhattanDistance(Vector2i a, Vector2i b) {
|
||||
return (abs(a.x - b.x) + abs(a.y - b.y));
|
||||
private float manhattanDistance(Vector2ic a, Vector2ic b) {
|
||||
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 list = new LinkedList<Vector2i>();
|
||||
var list = new LinkedList<Vector2ic>();
|
||||
|
||||
while (current.parent != null) {
|
||||
list.add(current.position);
|
||||
@@ -176,11 +177,11 @@ public class AstarPathFinder implements PathFinder {
|
||||
|
||||
private static class Node implements Comparable<Node> {
|
||||
public Node parent;
|
||||
public final Vector2i position;
|
||||
public final Vector2ic position;
|
||||
public float g = 0.0f;
|
||||
public float f = 0.0f;
|
||||
|
||||
public Node(Vector2i position) {
|
||||
public Node(Vector2ic position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.bartlomiejpluta.base.api.util.pathfinder;
|
||||
|
||||
import com.bartlomiejpluta.base.api.game.map.layer.object.ObjectLayer;
|
||||
import org.joml.Vector2i;
|
||||
import org.joml.Vector2ic;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
public interface PathFinder {
|
||||
LinkedList<Vector2i> findPath(ObjectLayer layer, Vector2i start, Vector2i end);
|
||||
LinkedList<Vector2ic> findPath(ObjectLayer layer, Vector2ic start, Vector2ic end);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user