mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-15 10:17:39 +07:00
Save IO fixes
This commit is contained in:
@ -31,7 +31,7 @@ public class BlockIndexer{
|
|||||||
/** Stores all ore quadtrants on the map. */
|
/** Stores all ore quadtrants on the map. */
|
||||||
private ObjectMap<Item, ObjectSet<Tile>> ores;
|
private ObjectMap<Item, ObjectSet<Tile>> ores;
|
||||||
/** Tags all quadrants. */
|
/** Tags all quadrants. */
|
||||||
private Bits[] structQuadrants;
|
private GridBits[] structQuadrants;
|
||||||
/** Stores all damaged tile entities by team. */
|
/** Stores all damaged tile entities by team. */
|
||||||
private ObjectSet<Tile>[] damagedTiles = new ObjectSet[Team.all.length];
|
private ObjectSet<Tile>[] damagedTiles = new ObjectSet[Team.all.length];
|
||||||
/**All ores available on this map.*/
|
/**All ores available on this map.*/
|
||||||
@ -73,9 +73,9 @@ public class BlockIndexer{
|
|||||||
ores = null;
|
ores = null;
|
||||||
|
|
||||||
//create bitset for each team type that contains each quadrant
|
//create bitset for each team type that contains each quadrant
|
||||||
structQuadrants = new Bits[Team.all.length];
|
structQuadrants = new GridBits[Team.all.length];
|
||||||
for(int i = 0; i < Team.all.length; i++){
|
for(int i = 0; i < Team.all.length; i++){
|
||||||
structQuadrants[i] = new Bits(Mathf.ceil(world.width() / (float)structQuadrantSize) * Mathf.ceil(world.height() / (float)structQuadrantSize));
|
structQuadrants[i] = new GridBits(Mathf.ceil(world.width() / (float)structQuadrantSize), Mathf.ceil(world.height() / (float)structQuadrantSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int x = 0; x < world.width(); x++){
|
for(int x = 0; x < world.width(); x++){
|
||||||
@ -282,11 +282,11 @@ public class BlockIndexer{
|
|||||||
|
|
||||||
//fast-set this quadrant to 'occupied' if the tile just placed is already of this team
|
//fast-set this quadrant to 'occupied' if the tile just placed is already of this team
|
||||||
if(tile.getTeam() == data.team && tile.entity != null && tile.block().targetable){
|
if(tile.getTeam() == data.team && tile.entity != null && tile.block().targetable){
|
||||||
structQuadrants[data.team.ordinal()].set(index);
|
structQuadrants[data.team.ordinal()].set(quadrantX, quadrantY);
|
||||||
continue; //no need to process futher
|
continue; //no need to process futher
|
||||||
}
|
}
|
||||||
|
|
||||||
structQuadrants[data.team.ordinal()].clear(index);
|
structQuadrants[data.team.ordinal()].set(quadrantX, quadrantY, false);
|
||||||
|
|
||||||
outer:
|
outer:
|
||||||
for(int x = quadrantX * structQuadrantSize; x < world.width() && x < (quadrantX + 1) * structQuadrantSize; x++){
|
for(int x = quadrantX * structQuadrantSize; x < world.width() && x < (quadrantX + 1) * structQuadrantSize; x++){
|
||||||
@ -294,7 +294,7 @@ public class BlockIndexer{
|
|||||||
Tile result = world.ltile(x, y);
|
Tile result = world.ltile(x, y);
|
||||||
//when a targetable block is found, mark this quadrant as occupied and stop searching
|
//when a targetable block is found, mark this quadrant as occupied and stop searching
|
||||||
if(result.entity != null && result.getTeam() == data.team){
|
if(result.entity != null && result.getTeam() == data.team){
|
||||||
structQuadrants[data.team.ordinal()].set(index);
|
structQuadrants[data.team.ordinal()].set(quadrantX, quadrantY);
|
||||||
break outer;
|
break outer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -303,8 +303,7 @@ public class BlockIndexer{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean getQuad(Team team, int quadrantX, int quadrantY){
|
private boolean getQuad(Team team, int quadrantX, int quadrantY){
|
||||||
int index = quadrantX + quadrantY * Mathf.ceil(world.width() / (float)structQuadrantSize);
|
return structQuadrants[team.ordinal()].get(quadrantX, quadrantY);
|
||||||
return structQuadrants[team.ordinal()].get(index);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int quadWidth(){
|
private int quadWidth(){
|
||||||
|
@ -6,15 +6,11 @@ import io.anuke.arc.util.Time;
|
|||||||
import io.anuke.arc.util.io.CounterInputStream;
|
import io.anuke.arc.util.io.CounterInputStream;
|
||||||
import io.anuke.mindustry.entities.Entities;
|
import io.anuke.mindustry.entities.Entities;
|
||||||
import io.anuke.mindustry.entities.EntityGroup;
|
import io.anuke.mindustry.entities.EntityGroup;
|
||||||
import io.anuke.mindustry.entities.traits.Entity;
|
import io.anuke.mindustry.entities.traits.*;
|
||||||
import io.anuke.mindustry.entities.traits.SaveTrait;
|
|
||||||
import io.anuke.mindustry.entities.traits.TypeTrait;
|
|
||||||
import io.anuke.mindustry.game.*;
|
import io.anuke.mindustry.game.*;
|
||||||
import io.anuke.mindustry.maps.Map;
|
import io.anuke.mindustry.maps.Map;
|
||||||
import io.anuke.mindustry.type.ContentType;
|
import io.anuke.mindustry.type.ContentType;
|
||||||
import io.anuke.mindustry.world.Block;
|
import io.anuke.mindustry.world.*;
|
||||||
import io.anuke.mindustry.world.Tile;
|
|
||||||
import io.anuke.mindustry.world.WorldContext;
|
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
@ -42,8 +38,13 @@ public abstract class SaveVersion extends SaveFileReader{
|
|||||||
public final void read(DataInputStream stream, CounterInputStream counter, WorldContext context) throws IOException{
|
public final void read(DataInputStream stream, CounterInputStream counter, WorldContext context) throws IOException{
|
||||||
region("meta", stream, counter, this::readMeta);
|
region("meta", stream, counter, this::readMeta);
|
||||||
region("content", stream, counter, this::readContentHeader);
|
region("content", stream, counter, this::readContentHeader);
|
||||||
region("map", stream, counter, in -> readMap(in, context));
|
|
||||||
region("entities", stream, counter, this::readEntities);
|
try{
|
||||||
|
region("map", stream, counter, in -> readMap(in, context));
|
||||||
|
region("entities", stream, counter, this::readEntities);
|
||||||
|
}finally{
|
||||||
|
content.setTemporaryMapper(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void write(DataOutputStream stream, StringMap extraTags) throws IOException{
|
public final void write(DataOutputStream stream, StringMap extraTags) throws IOException{
|
||||||
@ -147,56 +148,57 @@ public abstract class SaveVersion extends SaveFileReader{
|
|||||||
boolean generating = context.isGenerating();
|
boolean generating = context.isGenerating();
|
||||||
|
|
||||||
if(!generating) context.begin();
|
if(!generating) context.begin();
|
||||||
|
try{
|
||||||
|
|
||||||
context.resize(width, height);
|
context.resize(width, height);
|
||||||
|
|
||||||
//read floor and create tiles first
|
//read floor and create tiles first
|
||||||
for(int i = 0; i < width * height; i++){
|
for(int i = 0; i < width * height; i++){
|
||||||
int x = i % width, y = i / width;
|
int x = i % width, y = i / width;
|
||||||
short floorid = stream.readShort();
|
short floorid = stream.readShort();
|
||||||
short oreid = stream.readShort();
|
short oreid = stream.readShort();
|
||||||
int consecutives = stream.readUnsignedByte();
|
|
||||||
|
|
||||||
context.create(x, y, floorid, oreid, (short)0);
|
|
||||||
|
|
||||||
for(int j = i + 1; j < i + 1 + consecutives; j++){
|
|
||||||
int newx = j % width, newy = j / width;
|
|
||||||
context.create(newx, newy, floorid, oreid, (short)0);
|
|
||||||
}
|
|
||||||
|
|
||||||
i += consecutives;
|
|
||||||
}
|
|
||||||
|
|
||||||
//read blocks
|
|
||||||
for(int i = 0; i < width * height; i++){
|
|
||||||
int x = i % width, y = i / width;
|
|
||||||
Block block = content.block(stream.readShort());
|
|
||||||
Tile tile = context.tile(x, y);
|
|
||||||
tile.setBlock(block);
|
|
||||||
|
|
||||||
if(tile.entity != null){
|
|
||||||
try{
|
|
||||||
readChunk(stream, true, in -> {
|
|
||||||
byte version = in.readByte();
|
|
||||||
tile.entity.read(in, version);
|
|
||||||
});
|
|
||||||
}catch(Exception e){
|
|
||||||
throw new IOException("Failed to read tile entity of block: " + block, e);
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
int consecutives = stream.readUnsignedByte();
|
int consecutives = stream.readUnsignedByte();
|
||||||
|
|
||||||
|
context.create(x, y, floorid, oreid, (short)0);
|
||||||
|
|
||||||
for(int j = i + 1; j < i + 1 + consecutives; j++){
|
for(int j = i + 1; j < i + 1 + consecutives; j++){
|
||||||
int newx = j % width, newy = j / width;
|
int newx = j % width, newy = j / width;
|
||||||
context.tile(newx, newy).setBlock(block);
|
context.create(newx, newy, floorid, oreid, (short)0);
|
||||||
}
|
}
|
||||||
|
|
||||||
i += consecutives;
|
i += consecutives;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
content.setTemporaryMapper(null);
|
//read blocks
|
||||||
if(!generating) context.end();
|
for(int i = 0; i < width * height; i++){
|
||||||
|
int x = i % width, y = i / width;
|
||||||
|
Block block = content.block(stream.readShort());
|
||||||
|
Tile tile = context.tile(x, y);
|
||||||
|
tile.setBlock(block);
|
||||||
|
|
||||||
|
if(tile.entity != null){
|
||||||
|
try{
|
||||||
|
readChunk(stream, true, in -> {
|
||||||
|
byte version = in.readByte();
|
||||||
|
tile.entity.read(in, version);
|
||||||
|
});
|
||||||
|
}catch(Exception e){
|
||||||
|
throw new IOException("Failed to read tile entity of block: " + block, e);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
int consecutives = stream.readUnsignedByte();
|
||||||
|
|
||||||
|
for(int j = i + 1; j < i + 1 + consecutives; j++){
|
||||||
|
int newx = j % width, newy = j / width;
|
||||||
|
context.tile(newx, newy).setBlock(block);
|
||||||
|
}
|
||||||
|
|
||||||
|
i += consecutives;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}finally{
|
||||||
|
if(!generating) context.end();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeEntities(DataOutput stream) throws IOException{
|
public void writeEntities(DataOutput stream) throws IOException{
|
||||||
|
@ -132,7 +132,7 @@ public class OverflowGate extends Block{
|
|||||||
public void read(DataInput stream, byte revision) throws IOException{
|
public void read(DataInput stream, byte revision) throws IOException{
|
||||||
super.read(stream, revision);
|
super.read(stream, revision);
|
||||||
if(revision == 1){
|
if(revision == 1){
|
||||||
new DirectionalItemBuffer(25, 0f).read(stream);
|
new DirectionalItemBuffer(25, 50f).read(stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
package io.anuke.mindustry.world.blocks.distribution;
|
package io.anuke.mindustry.world.blocks.distribution;
|
||||||
|
|
||||||
import io.anuke.annotations.Annotations.*;
|
import io.anuke.annotations.Annotations.Loc;
|
||||||
|
import io.anuke.annotations.Annotations.Remote;
|
||||||
import io.anuke.arc.Core;
|
import io.anuke.arc.Core;
|
||||||
import io.anuke.arc.graphics.g2d.Draw;
|
import io.anuke.arc.graphics.g2d.Draw;
|
||||||
import io.anuke.arc.math.Mathf;
|
import io.anuke.arc.math.Mathf;
|
||||||
import io.anuke.arc.scene.ui.layout.Table;
|
import io.anuke.arc.scene.ui.layout.Table;
|
||||||
import io.anuke.mindustry.entities.type.*;
|
import io.anuke.mindustry.entities.type.Player;
|
||||||
|
import io.anuke.mindustry.entities.type.TileEntity;
|
||||||
import io.anuke.mindustry.gen.Call;
|
import io.anuke.mindustry.gen.Call;
|
||||||
import io.anuke.mindustry.type.Item;
|
import io.anuke.mindustry.type.Item;
|
||||||
import io.anuke.mindustry.world.*;
|
import io.anuke.mindustry.world.*;
|
||||||
@ -145,6 +147,7 @@ public class Sorter extends Block{
|
|||||||
@Override
|
@Override
|
||||||
public void write(DataOutput stream) throws IOException{
|
public void write(DataOutput stream) throws IOException{
|
||||||
super.write(stream);
|
super.write(stream);
|
||||||
|
stream.writeShort(sortItem == null ? -1 : sortItem.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user