Archived
0

Serialization/Deserialization of world

This commit is contained in:
Forwolk
2018-08-02 10:34:55 +03:00
parent 7115da905b
commit aa44d70897
13 changed files with 174 additions and 97 deletions

View File

@@ -0,0 +1,10 @@
package mc.core.serialization;
import mc.core.world.Chunk;
import mc.core.world.Region;
import java.io.IOException;
public interface IChunkReader {
Chunk read (Region region, int x, int y, int z) throws IOException;
}

View File

@@ -0,0 +1,12 @@
package mc.core.serialization;
import mc.core.world.Region;
import mc.core.world.World;
import java.io.IOException;
public interface IRegionReaderWriter {
Region read (int x, int z, World world) throws IOException;
void write (Region region) throws IOException;
}

View File

@@ -43,4 +43,8 @@ public enum Biome {
this.name = name;
this.color = color;
}
public static Biome getById(int id) {
return Biome.values()[id];
}
}

View File

@@ -14,15 +14,11 @@ import java.io.Serializable;
* +-------------+----------------+------------+
* | param | range | bits |
* +-------------+----------------+------------+
* | | | 3 |
* +-------------+----------------+------------+
* | block_count | 0:4096 | 13 |
* +-------------+----------------+------------+
* | blocks | array | 24*count |
* +-------------+----------------+------------+
*
* Total: 16 bits header (2 bytes) + 24 * block_count bits (3 * block_count bytes)
* Max size: 12290 bytes (~12 Kb per chunk)
* Total: 24 * block_count bits (3 * block_count bytes)
* Max size: 12288 bytes (~12 Kb per chunk)
*
*/
/* 16x16x16 */

View File

@@ -1,5 +1,6 @@
package mc.core.world;
import mc.core.serialization.IRegionReaderWriter;
import mc.core.serialization.Serializer;
import java.io.IOException;
@@ -29,5 +30,5 @@ public interface Region extends Serializable{
Biome getBiomeAt (int x, int z);
void setBiome (int x, int z, Biome biome);
void save(Serializer<Chunk> chunkSerializer, Serializer<Region> regionSerializer) throws IOException;
void save(Serializer<Chunk> chunkSerializer, IRegionReaderWriter regionReaderWritter) throws IOException;
}