From 9bc9e7fc15cb9c4bdde3c5c7e0c93097c7395d0a Mon Sep 17 00:00:00 2001 From: fred-boy Date: Wed, 25 Apr 2018 01:45:09 +0700 Subject: [PATCH] Read with DataInputStream --- .../cavecraft/game/GameSaver.java | 62 +++++-------------- .../cavecraft/game/GameWorld.java | 7 +-- 2 files changed, 20 insertions(+), 49 deletions(-) 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