From d36fb933be31b1c72f7814538cd7d8bd1fa11f86 Mon Sep 17 00:00:00 2001 From: 0us <35314375+0us@users.noreply.github.com> Date: Tue, 12 Nov 2019 23:00:06 +0100 Subject: [PATCH] add no-args constructor to state classes to satisfy Kryo requirement --- core/src/no/ntnu/trostespel/PlayerActions.java | 1 - core/src/no/ntnu/trostespel/state/MovableState.java | 5 +++++ core/src/no/ntnu/trostespel/state/ObjectState.java | 4 ++++ core/src/no/ntnu/trostespel/state/PlayerState.java | 3 ++- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/core/src/no/ntnu/trostespel/PlayerActions.java b/core/src/no/ntnu/trostespel/PlayerActions.java index fde5925..c6c316d 100644 --- a/core/src/no/ntnu/trostespel/PlayerActions.java +++ b/core/src/no/ntnu/trostespel/PlayerActions.java @@ -25,6 +25,5 @@ public PlayerActions(int pid) { } public PlayerActions() { - pid = new Random().nextInt(); } } diff --git a/core/src/no/ntnu/trostespel/state/MovableState.java b/core/src/no/ntnu/trostespel/state/MovableState.java index a067f65..86dff37 100644 --- a/core/src/no/ntnu/trostespel/state/MovableState.java +++ b/core/src/no/ntnu/trostespel/state/MovableState.java @@ -1,6 +1,7 @@ package no.ntnu.trostespel.state; import com.badlogic.gdx.math.Vector2; +import no.ntnu.trostespel.entity.Movable; import java.util.concurrent.atomic.AtomicLong; @@ -14,6 +15,10 @@ public class MovableState extends ObjectState { private transient int timeAlive; public final transient int damage = 15; + private MovableState() { + // kryo requires a no-args constructor to work properly + } + public MovableState(long pid, double velocity) { super(24f, 24f, Vector2.Zero); this.heading = new Vector2(1, 0); // Unit vector diff --git a/core/src/no/ntnu/trostespel/state/ObjectState.java b/core/src/no/ntnu/trostespel/state/ObjectState.java index 54c6292..5eb0d7e 100644 --- a/core/src/no/ntnu/trostespel/state/ObjectState.java +++ b/core/src/no/ntnu/trostespel/state/ObjectState.java @@ -8,6 +8,10 @@ public class ObjectState { private transient Rectangle hitbox; private volatile Vector2 position; + private ObjectState() { + // kryo requires a no-args constructor to work properly + } + public ObjectState(float x, float y, Vector2 position) { this.hitbox = new Rectangle(0, 0, x, y); this.position = position; diff --git a/core/src/no/ntnu/trostespel/state/PlayerState.java b/core/src/no/ntnu/trostespel/state/PlayerState.java index 8a496c2..32c79d9 100644 --- a/core/src/no/ntnu/trostespel/state/PlayerState.java +++ b/core/src/no/ntnu/trostespel/state/PlayerState.java @@ -21,8 +21,9 @@ public class PlayerState extends ObjectState{ private long timeOfDeath; private String username; - public PlayerState() { + private PlayerState() { super(72, 90, new Vector2(55, 55)); + // kryo requires a no-args constructor to work properly } public PlayerState(long pid) {