change some Tile serialization methods to work with the new TileRawDataContainer interface instead
This commit is contained in:
parent
c8b39965ef
commit
580f199d1f
|
@ -1,20 +1,20 @@
|
|||
package com.blarg.gdx.tilemap3d.serialization;
|
||||
|
||||
import com.blarg.gdx.tilemap3d.Tile;
|
||||
import com.blarg.gdx.tilemap3d.TileChunk;
|
||||
import com.blarg.gdx.tilemap3d.TileRawDataContainer;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class TileChunkSerializer {
|
||||
public class TileDataSerializer {
|
||||
public static final int TILE_SIZE_BYTES = 17; // TODO: is there some kind of java sizeof() type thing?
|
||||
|
||||
public static void serialize(TileChunk chunk, ByteBuffer buffer) {
|
||||
Tile[] tiles = chunk.getData();
|
||||
public static void serialize(TileRawDataContainer tileData, ByteBuffer buffer) {
|
||||
Tile[] tiles = tileData.getData();
|
||||
for (int i = 0; i < tiles.length; ++i)
|
||||
serialize(tiles[i], buffer);
|
||||
}
|
||||
|
||||
public static void deserialize(ByteBuffer buffer, TileChunk out) {
|
||||
public static void deserialize(ByteBuffer buffer, TileRawDataContainer out) {
|
||||
Tile[] tiles = out.getData();
|
||||
for (int i = 0; i < tiles.length; ++i)
|
||||
deserialize(buffer, tiles[i]);
|
|
@ -59,7 +59,7 @@ public class TileMapLoader {
|
|||
byte[] chunkBytes = Base64Coder.decode(encodedChunk);
|
||||
ByteBuffer buffer = ByteBuffer.wrap(chunkBytes);
|
||||
|
||||
TileChunkSerializer.deserialize(buffer, outputChunk);
|
||||
TileDataSerializer.deserialize(buffer, outputChunk);
|
||||
}
|
||||
|
||||
return tileMap;
|
||||
|
@ -81,7 +81,7 @@ public class TileMapLoader {
|
|||
jsonMap.lightingMode = null;
|
||||
|
||||
// each serialized chunk will be the same size in bytes (same number of tiles in each)
|
||||
int chunkSizeInBytes = tileMap.getChunks()[0].getData().length * TileChunkSerializer.TILE_SIZE_BYTES;
|
||||
int chunkSizeInBytes = tileMap.getChunks()[0].getData().length * TileDataSerializer.TILE_SIZE_BYTES;
|
||||
|
||||
jsonMap.chunks = new ArrayList<String>(tileMap.getChunks().length);
|
||||
for (int i = 0; i < tileMap.getChunks().length; ++i) {
|
||||
|
@ -90,7 +90,7 @@ public class TileMapLoader {
|
|||
byte[] chunkBytes = new byte[chunkSizeInBytes];
|
||||
ByteBuffer buffer = ByteBuffer.wrap(chunkBytes);
|
||||
|
||||
TileChunkSerializer.serialize(chunk, buffer);
|
||||
TileDataSerializer.serialize(chunk, buffer);
|
||||
|
||||
jsonMap.chunks.add(new String(Base64Coder.encode(chunkBytes)));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue