Skip to content

Commit

Permalink
Add destroyable
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiyotoko committed May 12, 2023
1 parent 386ba3f commit b408799
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 26 deletions.
3 changes: 2 additions & 1 deletion src/main/java/io/scvis/game/Children.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package io.scvis.game;

public interface Children extends Entity {
public interface Children extends Entity, Destroyable {

@Override
default void destroy() {
getParent().getChildren().remove(this);
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/io/scvis/game/Destroyable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.scvis.game;

public interface Destroyable {

void destroy();
}
4 changes: 2 additions & 2 deletions src/main/java/io/scvis/game/FixedBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class FixedBoard<R, C, V> implements Board<R, C, V> {
private final Set<R> rows;
private final Set<C> columns;

private final V fields[][];
private final V[][] fields;

public FixedBoard(Set<R> rows, Set<C> columns) {
this.rowsToIndex = mapToIndex(rows);
Expand All @@ -23,7 +23,7 @@ public FixedBoard(Set<R> rows, Set<C> columns) {
this.rows = rows;
this.columns = columns;
@SuppressWarnings("unchecked")
V array[][] = (V[][]) new Object[rows.size()][columns.size()];
V[][] array = (V[][]) new Object[rows.size()][columns.size()];
this.fields = array;
}

Expand Down
24 changes: 8 additions & 16 deletions src/main/java/io/scvis/geometry/Kinetic3D.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ public abstract class Kinetic3D extends Layout3D implements Kinetic, Identifiabl
private double acceleration = 0.0;
@JsonProperty(value = "velocity", index = 18)
private double velocity = 0.0;
@JsonProperty(value = "circularSpeed", index = 19)
private double circularSpeed = 5;

@JsonCreator
protected Kinetic3D(@JsonProperty("local") @Nonnull Border3D local,
Expand All @@ -38,9 +36,10 @@ public boolean hasDestination() {

@Nonnull
public Vector3D getDestination() {
final Vector3D destination = this.destination;
if (destination != null)
return destination;
// Check for nonnull
final Vector3D checked = this.destination;
if (checked != null)
return checked;
return getPosition();
}

Expand All @@ -58,9 +57,10 @@ public boolean hasTarget() {

@Nonnull
public Border3D getTarget() {
final Border3D target = this.target;
if (target != null)
return target;
// Check for nonnull
final Border3D checked = this.target;
if (checked != null)
return checked;
return this;
}

Expand All @@ -83,12 +83,4 @@ public double getVelocity() {
public void setVelocity(double velocity) {
this.velocity = velocity;
}

public double getCircularSpeed() {
return circularSpeed;
}

public void setCircularSpeed(double circularSpeed) {
this.circularSpeed = circularSpeed;
}
}
6 changes: 4 additions & 2 deletions src/main/java/io/scvis/geometry/Layout2D.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
@JsonSerialize
@JsonDeserialize
public class Layout2D implements Border2D, Cloneable {

@JsonProperty(value = "local", index = 5)
@Nonnull
private final Border2D local;

@JsonIgnore
@CheckForNull
private transient Border2D parent;
private Border2D parent;

@JsonProperty(value = "position", index = 6)
@Nonnull
Expand Down Expand Up @@ -65,7 +67,7 @@ public boolean intersects(@Nonnull Border2D border2D) {
}

@JsonIgnore
protected transient boolean changed;
protected boolean changed;

@Override
@Nonnull
Expand Down
18 changes: 16 additions & 2 deletions src/main/java/io/scvis/geometry/Vector2D.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.scvis.geometry;

import java.io.Serializable;

import javax.annotation.Nonnull;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
Expand All @@ -13,7 +15,10 @@
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
@JsonSerialize
@JsonDeserialize
public class Vector2D implements Corresponding<io.scvis.grpc.geometry.Vector2D> {
public class Vector2D implements Corresponding<io.scvis.grpc.geometry.Vector2D>, Serializable {

private static final long serialVersionUID = -9019588241960612260L;

public static final @Nonnull Vector2D ZERO = new Vector2D(0.0, 0.0);

/**
Expand Down Expand Up @@ -131,9 +136,18 @@ public boolean equals(Object obj) {
return x == vec.x && y == vec.y;
}

private transient int hash;

@Override
public int hashCode() {
if (hash == 0)
hash = super.hashCode();
return hash;
}

@Override
public String toString() {
return "Vector [x = " + x + ", y = " + y + "]";
return "Vector2D [x = " + x + ", y = " + y + "]";
}

@Override
Expand Down
27 changes: 24 additions & 3 deletions src/main/java/io/scvis/geometry/Vector3D.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.scvis.geometry;

import java.io.Serializable;

import javax.annotation.Nonnull;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
Expand All @@ -8,10 +10,15 @@
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import io.scvis.proto.Corresponding;

@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
@JsonSerialize
@JsonDeserialize
public class Vector3D {
public class Vector3D implements Corresponding<io.scvis.grpc.geometry.Vector3D>, Serializable {

private static final long serialVersionUID = -4200231978633862588L;

public static final @Nonnull Vector3D ZERO = new Vector3D(0.0, 0.0, 0.0);

/**
Expand Down Expand Up @@ -112,16 +119,30 @@ public double getZ() {

@Override
public boolean equals(Object obj) {
if (!(obj instanceof Vector2D))
if (!(obj instanceof Vector3D))
return false;
if (obj == this)
return true;
Vector3D vec = (Vector3D) obj;
return x == vec.x && y == vec.y && z == vec.z;
}

private transient int hash;

@Override
public int hashCode() {
if (hash == 0)
hash = super.hashCode();
return hash;
}

@Override
public String toString() {
return "Vector [x = " + x + ", y = " + y + ", z = " + z + "]";
return "Vector3D [x = " + x + ", y = " + y + ", z = " + z + "]";
}

@Override
public io.scvis.grpc.geometry.Vector3D associated() {
return io.scvis.grpc.geometry.Vector3D.newBuilder().setX(x).setY(y).setZ(z).build();
}
}

0 comments on commit b408799

Please sign in to comment.