Skip to content

Commit

Permalink
Refactor (#41)
Browse files Browse the repository at this point in the history
* refactor Vec3 and Bounds

* remove unecessary method getNumberOfPlayers

* remove unecessary condition
  • Loading branch information
vu-luong authored Dec 27, 2022
1 parent f678f43 commit c14890a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
9 changes: 1 addition & 8 deletions src/main/java/com/tvd12/gamebox/entity/MMOGridRoom.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ private void handleNeighboringCells(
}
}

public void addNearbyPlayersInCell(MMOPlayer currentPlayer, Cell cell) {
if (cell == null || cell.getNumberOfPlayers() == 0) {
return;
}
private void addNearbyPlayersInCell(MMOPlayer currentPlayer, Cell cell) {
for (MMOPlayer nearByPlayer : cell.players) {
currentPlayer.addNearbyPlayer(nearByPlayer);
nearByPlayer.addNearbyPlayer(currentPlayer);
Expand Down Expand Up @@ -220,9 +217,5 @@ public void addPlayer(MMOPlayer player) {
public void removePlayer(MMOPlayer player) {
players.remove(player);
}

public int getNumberOfPlayers() {
return players.size();
}
}
}
3 changes: 2 additions & 1 deletion src/main/java/com/tvd12/gamebox/math/Bounds.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public boolean doesOverlap(Bounds other) {
}

public Bounds getOctant(int index) {
OcLocation ocLocation = Bounds.OcLocation.of(index);
OcLocation ocLocation = OcLocation.of(index);
float midX = (leftBottomBack.x + rightTopFront.x) / 2;
float midY = (leftBottomBack.y + rightTopFront.y) / 2;
float midZ = (leftBottomBack.z + rightTopFront.z) / 2;
Expand Down Expand Up @@ -121,6 +121,7 @@ public String toString() {
}

private enum OcLocation {

LEFT_BOTTOM_BACK(0),
LEFT_BOTTOM_FRONT(1),
LEFT_TOP_BACK(2),
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/tvd12/gamebox/math/Vec3.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public class Vec3 {
public float z;

public static final Vec3 ZERO = new Vec3();
public static final Vec3 up = new Vec3(0.0f, 1f, 0.0f);
public static final Vec3 down = new Vec3(0.0f, -1f, 0.0f);
public static final Vec3 left = new Vec3(-1f, 0.0f, 0.0f);
public static final Vec3 right = new Vec3(1f, 0.0f, 0.0f);
public static final Vec3 forward = new Vec3(0.0f, 0.0f, 1f);
public static final Vec3 backward = new Vec3(0.0f, 0.0f, -1f);
public static final Vec3 UP = new Vec3(0.0f, 1f, 0.0f);
public static final Vec3 DOWN = new Vec3(0.0f, -1f, 0.0f);
public static final Vec3 LEFT = new Vec3(-1f, 0.0f, 0.0f);
public static final Vec3 RIGHT = new Vec3(1f, 0.0f, 0.0f);
public static final Vec3 FORWARD = new Vec3(0.0f, 0.0f, 1f);
public static final Vec3 BACKWARD = new Vec3(0.0f, 0.0f, -1f);

public Vec3() {
this(0.0f, 0.0f, 0.0f);
Expand Down

0 comments on commit c14890a

Please sign in to comment.