Implemented map run-length encoding, updated KO lang

This commit is contained in:
Anuken
2018-01-26 00:08:12 -05:00
parent 5f131723c4
commit 6abbc3eca7
5 changed files with 95 additions and 88 deletions

View File

@@ -8,7 +8,6 @@ import com.badlogic.gdx.utils.TimeUtils;
/**An IndexedAStarPathfinder that uses an OptimizedGraph, and therefore has less allocations.*/
public class OptimizedPathFinder<N> implements PathFinder<N> {
OptimizedGraph<N> graph;
//NodeRecord<N>[] nodeRecords; //TODO remove.
IntMap<NodeRecord<N>> records = new IntMap<>();
BinaryHeap<NodeRecord<N>> openList;
NodeRecord<N> current;
@@ -25,7 +24,6 @@ public class OptimizedPathFinder<N> implements PathFinder<N> {
@SuppressWarnings("unchecked")
public OptimizedPathFinder(OptimizedGraph<N> graph) {
this.graph = graph;
//this.nodeRecords = (NodeRecord<N>[]) new NodeRecord[graph.getNodeCount()];
this.openList = new BinaryHeap<>();
}
@@ -218,20 +216,6 @@ public class OptimizedPathFinder<N> implements PathFinder<N> {
}else{
return records.get(graph.getIndex(node));
}
/*
int index = graph.getIndex(node);
NodeRecord<N> nr = nodeRecords[index];
if (nr != null) {
if (nr.searchId != searchId) {
nr.category = UNVISITED;
nr.searchId = searchId;
}
return nr;
}
nr = nodeRecords[index] = new NodeRecord<>();
nr.node = node;
nr.searchId = searchId;
return nr;*/
}
/**

View File

@@ -15,7 +15,6 @@ import io.anuke.mindustry.entities.effect.Shield;
import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.entities.enemies.EnemyTypes;
import io.anuke.mindustry.game.*;
import io.anuke.mindustry.game.Tutorial;
import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.input.AndroidInput;
import io.anuke.mindustry.input.DesktopInput;
@@ -36,9 +35,9 @@ import io.anuke.ucore.core.Inputs.DeviceType;
import io.anuke.ucore.entities.Entities;
import io.anuke.ucore.entities.EntityGroup;
import io.anuke.ucore.graphics.Lines;
import io.anuke.ucore.util.Atlas;
import io.anuke.ucore.modules.Module;
import io.anuke.ucore.scene.ui.layout.Unit;
import io.anuke.ucore.util.Atlas;
import io.anuke.ucore.util.Input;
import io.anuke.ucore.util.InputProxy;
import io.anuke.ucore.util.Mathf;
@@ -87,7 +86,6 @@ public class Control extends Module{
public Control(){
if(Mindustry.args.contains("-debug", false))
Vars.debug = true;
saves = new Saves();
Inputs.useControllers(!Vars.gwt);

View File

@@ -96,6 +96,7 @@ public class NetClient extends Module {
UCore.log("Recieved world data: " + data.stream.available() + " bytes.");
NetworkIO.loadWorld(data.stream);
Vars.player.set(Vars.control.core.worldx(), Vars.control.core.worldy() - Vars.tilesize * 2);
UCore.log(Vars.control.core);
gotData = true;
@@ -103,6 +104,7 @@ public class NetClient extends Module {
});
Net.handle(CustomMapPacket.class, packet -> {
UCore.log("Recieved custom map: " + packet.stream.available() + " bytes.");
//custom map is always sent before world data
Pixmap pixmap = NetworkIO.loadMap(packet.stream);

View File

@@ -26,17 +26,40 @@ public class NetworkIO {
public static void writeMap(Pixmap map, OutputStream os){
try(DataOutputStream stream = new DataOutputStream(os)){
ByteBuffer buffer = (ByteBuffer) map.getPixels();
UCore.log("Buffer position: " + buffer.position());
stream.writeShort(map.getWidth());
stream.writeShort(map.getHeight());
for(int i = 0; i < map.getWidth() * map.getHeight(); i ++){
int color = buffer.getInt();
int width = map.getWidth();
int cap = map.getWidth() * map.getHeight();
int pos = 0;
while(pos < cap){
int color = map.getPixel(pos % width, pos / width);
byte id = ColorMapper.getColorID(color);
int length = 1;
while(true){
if(pos >= cap || length > 254){
break;
}
pos ++;
int next = map.getPixel(pos % width, pos / width);
if(next != color){
pos --;
break;
}else{
length ++;
}
}
if(id == -1) id = 0;
stream.writeByte((byte)(length > 127 ? length - 256 : length));
stream.writeByte(id);
pos ++;
}
buffer.position(0);
}catch (IOException e){
throw new RuntimeException(e);
}
@@ -47,21 +70,21 @@ public class NetworkIO {
short width = stream.readShort();
short height = stream.readShort();
Pixmap pixmap = new Pixmap(width, height, Format.RGBA8888);
if(!Vars.gwt) {
ByteBuffer buffer = (ByteBuffer) pixmap.getPixels();
buffer.position(0);
for (int i = 0; i < width * height; i++) {
byte id = stream.readByte();
buffer.putInt(ColorMapper.getColorByID(id));
}
}else{
for(int i = 0; i < width * height; i++){
byte id = stream.readByte();
pixmap.drawPixel(i % width, i /width, ColorMapper.getColorByID(id));
int pos = 0;
while(stream.available() > 0){
int length = stream.readByte();
byte id = stream.readByte();
if(length < 0) length += 256;
int color = ColorMapper.getColorByID(id);
for(int p = 0; p < length; p ++){
pixmap.drawPixel(pos % width, pos / width,color);
pos ++;
}
}
return pixmap;
}catch (IOException e){
throw new RuntimeException(e);