mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 10:40:06 -08:00
store compressed game states instead of full object graph
This commit is contained in:
parent
442e127ab7
commit
3b86e421d6
1 changed files with 8 additions and 6 deletions
|
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue