From: fred-boy Date: Tue, 24 Apr 2018 18:45:09 +0000 (+0700) Subject: Read with DataInputStream X-Git-Tag: alpha0.3~4 X-Git-Url: https://deadsoftware.ru/gitweb?p=cavedroid.git;a=commitdiff_plain;h=9bc9e7fc15cb9c4bdde3c5c7e0c93097c7395d0a Read with DataInputStream --- diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameSaver.java b/core/src/ru/deadsoftware/cavecraft/game/GameSaver.java index 1bf6684..aab81f5 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameSaver.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameSaver.java @@ -4,26 +4,13 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.files.FileHandle; import ru.deadsoftware.cavecraft.CaveGame; -import java.io.BufferedOutputStream; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; +import java.io.*; import java.nio.ByteBuffer; public class GameSaver { private static final int VERSION = 0; - private static int[][] fMap, bMap; - private static int readIndex; - - private static int bytesToInt(byte[] bytes) { - ByteBuffer wrapped = ByteBuffer.wrap(bytes); - int res = wrapped.getInt(readIndex); - readIndex+=4; - return res; - } - private static byte[] intToBytes(int i) { return ByteBuffer.allocate(4).putInt(i).array(); } @@ -56,44 +43,27 @@ public class GameSaver { } private static int[][] loadMap(FileHandle file) throws Exception { - int[][] map = null; + int[][] map; int ver, width, height; int rl,bl; - byte[] data = file.readBytes(); - readIndex = 0; - ver = bytesToInt(data); + DataInputStream in = new DataInputStream(file.read()); + ver = in.readInt(); if (VERSION == ver) { - width = bytesToInt(data); - height = bytesToInt(data); + width = in.readInt(); + height = in.readInt(); map = new int[width][height]; for (int y=0; y