Skip to content

Commit

Permalink
feat(JOML): migrate orientation and Sector (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
pollend authored Jan 13, 2021
1 parent 3419a42 commit 57f8c14
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
16 changes: 13 additions & 3 deletions src/main/java/org/terasology/commonworld/Orientation.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import java.util.EnumMap;

import org.joml.Vector2i;
import org.joml.Vector2ic;
import org.terasology.math.geom.BaseVector2i;
import org.terasology.math.geom.ImmutableVector2i;

Expand Down Expand Up @@ -102,10 +104,10 @@ public enum Orientation {
ROTATE_CCW.put(NORTHEAST, NORTH);
}

private final ImmutableVector2i dir;
private final Vector2ic dir;

Orientation(int dx, int dz) {
this.dir = new ImmutableVector2i(dx, dz);
this.dir = new Vector2i(dx, dz);
}

/**
Expand Down Expand Up @@ -164,8 +166,16 @@ public Orientation getRotated(int degrees) {
/**
* @return the orientation
*/
public Vector2ic direction() {
return dir;
}

/**
* @return the orientation
*/
@Deprecated
public ImmutableVector2i getDir() {
return this.dir;
return new ImmutableVector2i(this.dir.x(), this.dir.y());
}

/**
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/terasology/commonworld/Sector.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.terasology.commonworld;

import org.joml.Vector2ic;
import org.terasology.math.geom.BaseVector2i;
import org.terasology.math.geom.ImmutableVector2i;
import org.terasology.math.geom.Vector2i;
Expand Down Expand Up @@ -64,9 +65,9 @@ public ImmutableVector2i getCoords() {
*/
public Sector getNeighbor(Orientation dir) {

ImmutableVector2i v = dir.getDir();
int x = coords.getX() + v.getX();
int z = coords.getY() + v.getY();
Vector2ic v = dir.direction();
int x = coords.getX() + v.x();
int z = coords.getY() + v.y();

return Sectors.getSector(new Vector2i(x, z));
}
Expand Down

0 comments on commit 57f8c14

Please sign in to comment.