diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameSaver.java b/core/src/ru/deadsoftware/cavedroid/game/GameSaver.java
index 53d147228f96a334a31ce9cd2e575c14b154e55e..cb52b3c76b126812e355c43d9ce076c7d5749140 100644 (file)
BufferedOutputStream out = new BufferedOutputStream(file.write(false));
- out.write(intToBytes(SAVE_VERSION));
+ out.write(SAVE_VERSION);
out.write(intToBytes(width));
out.write(intToBytes(height));
run = 0;
for (Block[] blocks : map) {
int newValue = dict.get(blocks[y].getParams().getKey());
- if (newValue != block) {
- out.write(intToBytes(run));
- out.write(intToBytes(block));
+ if (run >= 0xFF || newValue != block) {
+ out.write(run);
+ out.write(block);
run = 0;
block = dict.get(blocks[y].getParams().getKey());
}
run++;
}
- out.write(intToBytes(run));
- out.write(intToBytes(block));
+ out.write(run);
+ out.write(block);
}
out.flush();
DataInputStream in = new DataInputStream(file.read());
- version = in.readInt();
+ version = in.readByte();
if (SAVE_VERSION == version) {
width = in.readInt();
map = new Block[width][height];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x += run) {
- run = in.readInt();
- block = in.readInt();
+ run = in.readUnsignedByte();
+ block = in.readUnsignedByte();
for (int i = x; i < x + run; i++) {
map[i][y] = gameItemsHolder.getBlock(dict[block]);
}