Skip to content

Commit

Permalink
improved fix for the serialization of the MainGrid
Browse files Browse the repository at this point in the history
  • Loading branch information
paulwedeck committed Oct 9, 2022
1 parent 46d1384 commit 7ffcfea
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.BitSet;
import java.util.Date;
Expand Down Expand Up @@ -141,7 +142,7 @@
* @author Andreas Eberle
*/
public final class MainGrid implements Serializable {
private static final long serialVersionUID = 3824511313693431423L;
private static final long serialVersionUID = 3824511313693431424L;

final String mapId;
final String mapName;
Expand Down Expand Up @@ -233,10 +234,20 @@ public void initForPlayer(byte playerId, FogOfWar fogOfWar) {

private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
ois.defaultReadObject();

short width = ois.readShort();
short height = ois.readShort();

initAdditional();
this.bordersThread.checkArea(0, 0, width, height);
}

private void writeObject(ObjectOutputStream oos) throws IOException {
oos.defaultWriteObject();
oos.writeShort(width);
oos.writeShort(height);
}

public void startThreads() {
bordersThread.start();
if (fogOfWar != null) {
Expand Down Expand Up @@ -1220,7 +1231,7 @@ public boolean isInBounds(int x, int y) {
}

final class MovablePathfinderGrid extends AbstractMovableGrid {
private static final long serialVersionUID = 4006228724969442801L;
private static final long serialVersionUID = 4006228724969442802L;

private transient PathfinderGrid pathfinderGrid;
private transient AbstractAStar aStar;
Expand All @@ -1229,9 +1240,19 @@ final class MovablePathfinderGrid extends AbstractMovableGrid {

private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
ois.defaultReadObject();

short width = ois.readShort();
short height = ois.readShort();

initPathfinders(width, height);
}

private void writeObject(ObjectOutputStream oos) throws IOException {
oos.defaultWriteObject();
oos.writeShort(width);
oos.writeShort(height);
}

public MovablePathfinderGrid() {
initPathfinders(width, height);
}
Expand Down

0 comments on commit 7ffcfea

Please sign in to comment.