store compressed game states instead of full object graph

This commit is contained in:
BetaSteward 2010-04-16 03:47:19 +00:00
parent 442e127ab7
commit 3b86e421d6

View file

@ -28,19 +28,21 @@
package mage.game; package mage.game;
import java.io.Serializable;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import mage.util.Copier;
/** /**
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
public class GameStates { public class GameStates implements Serializable {
private List<GameState> states = new LinkedList<GameState>(); private List<byte[]> states = new LinkedList<byte[]>();
public void save(GameState gameState) { public void save(GameState gameState) {
states.add(gameState.copy()); states.add(new Copier<GameState>().copyCompressed(gameState));
} }
public int getSize() { public int getSize() {
@ -51,12 +53,12 @@ public class GameStates {
while (states.size() > index) { while (states.size() > index) {
states.remove(index); states.remove(index);
} }
return states.get(index - 1); return new Copier<GameState>().uncompressCopy(states.get(index - 1));
} }
public GameState get(int index) { public GameState get(int index) {
if (index <= states.size()) if (index < states.size())
return states.get(index); return new Copier<GameState>().uncompressCopy(states.get(index));
return null; return null;
} }
} }