Web compilation fix, new logging, cleanup

This commit is contained in:
Anuken
2018-01-24 18:48:59 -05:00
parent 3900258b6c
commit 8b2f63ecb6
15 changed files with 43 additions and 35 deletions

View File

@@ -41,6 +41,7 @@ public class Mindustry extends ModuleCore {
@Override
public void dispose() {
GameState.set(State.menu);
platforms.onGameExit();
Net.dispose();
super.dispose();
@@ -73,7 +74,7 @@ public class Mindustry extends ModuleCore {
Locale locale = Locale.ENGLISH;
Core.bundle = I18NBundle.createBundle(handle, locale);
}catch (Exception e){
e.printStackTrace();
UCore.error(e);
platforms.showError("Failed to find bundle!\nMake sure you have bundle.properties in the same directory\nas the jar file.\n\nIf the problem persists, try running it through the command prompt:\n" +
"Hold left-shift, then right click and select 'open command prompt here'.\nThen, type in 'java -jar mindustry.jar' without quotes.");
Gdx.app.exit();

View File

@@ -103,6 +103,7 @@ public class NetClient extends Module {
});
Net.handle(CustomMapPacket.class, packet -> {
//custom map is always sent before world data
Pixmap pixmap = NetworkIO.loadMap(packet.stream);
@@ -242,7 +243,7 @@ public class NetClient extends Module {
} catch (IOException e) {
throw new RuntimeException(e);
} catch (Exception e) {
e.printStackTrace();
UCore.error(e);
//do nothing else...
//TODO fix
}

View File

@@ -217,7 +217,7 @@ public class NetServer extends Module{
p.android = player.isAndroid;
Net.sendTo(dest, p, SendMode.tcp);
Gdx.app.error("Mindustry", "Replying to entity request (" + id + "): player, " + id);
log("Replying to entity request (" + id + "): player, " + id);
} else if (Vars.control.enemyGroup.getByID(id) != null) {
Enemy enemy = Vars.control.enemyGroup.getByID(id);
EnemySpawnPacket e = new EnemySpawnPacket();
@@ -229,7 +229,7 @@ public class NetServer extends Module{
e.type = enemy.type.id;
e.health = (short) enemy.health;
Net.sendTo(dest, e, SendMode.tcp);
Gdx.app.error("Mindustry", "Replying to entity request(" + id + "): enemy, " + id);
log("Replying to entity request(" + id + "): enemy, " + id);
} else {
Gdx.app.error("Mindustry", "Entity request target not found!");
}

View File

@@ -107,9 +107,9 @@ public class World extends Module{
}
public Tile tile(int x, int y){
//if(tiles == null){
// return null;
//}
if(tiles == null){
return null;
}
if(!Mathf.inBounds(x, y, tiles)) return null;
return tiles[x][y];
}

View File

@@ -8,9 +8,9 @@ import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.utils.*;
import com.badlogic.gdx.utils.Json.Serializer;
import com.badlogic.gdx.utils.JsonWriter.OutputType;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.world.Map;
import io.anuke.ucore.UCore;
import io.anuke.ucore.core.Settings;
import io.anuke.ucore.graphics.Pixmaps;
@@ -154,7 +154,7 @@ public class Maps implements Disposable{
}
return true;
}catch(Exception e){
if(!Vars.android) e.printStackTrace();
if(!Vars.android) UCore.error(e);
Gdx.app.error("Mindustry-Maps", "Failed loading map file: " + file);
return false;
}

View File

@@ -13,6 +13,7 @@ import io.anuke.mindustry.world.ColorMapper.BlockPair;
import io.anuke.mindustry.world.Map;
import io.anuke.mindustry.world.blocks.Blocks;
import io.anuke.mindustry.world.blocks.SpecialBlocks;
import io.anuke.ucore.UCore;
import io.anuke.ucore.core.Core;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.core.Timers;
@@ -61,7 +62,7 @@ public class MapEditorDialog extends Dialog{
}
}catch (Exception e){
Vars.ui.showError(Bundles.format("text.editor.errorimageload", Strings.parseException(e, false)));
e.printStackTrace();
UCore.error(e);
}
Vars.ui.loadfrag.hide();
});
@@ -78,7 +79,7 @@ public class MapEditorDialog extends Dialog{
Pixmaps.write(editor.pixmap(), result);
}catch (Exception e){
Vars.ui.showError(Bundles.format("text.editor.errorimagesave", Strings.parseException(e, false)));
if(!Vars.android) e.printStackTrace();
if(!Vars.android) UCore.error(e);
}
Vars.ui.loadfrag.hide();
});

View File

@@ -8,7 +8,10 @@ import io.anuke.mindustry.Vars;
import io.anuke.mindustry.game.GameMode;
import io.anuke.mindustry.resource.Upgrade;
import io.anuke.mindustry.resource.Weapon;
import io.anuke.mindustry.world.*;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.ColorMapper;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.WorldGenerator;
import io.anuke.mindustry.world.blocks.Blocks;
import io.anuke.mindustry.world.blocks.types.BlockPart;
import io.anuke.mindustry.world.blocks.types.Rock;
@@ -23,7 +26,7 @@ public class NetworkIO {
public static void writeMap(Pixmap map, OutputStream os){
try(DataOutputStream stream = new DataOutputStream(os)){
ByteBuffer buffer = map.getPixels();
ByteBuffer buffer = (ByteBuffer) map.getPixels();
UCore.log("Buffer position: " + buffer.position());
stream.writeShort(map.getWidth());
stream.writeShort(map.getHeight());
@@ -44,12 +47,19 @@ public class NetworkIO {
short width = stream.readShort();
short height = stream.readShort();
Pixmap pixmap = new Pixmap(width, height, Format.RGBA8888);
ByteBuffer buffer = pixmap.getPixels();
buffer.position(0);
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));
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));
}
}
return pixmap;

View File

@@ -5,6 +5,7 @@ import io.anuke.mindustry.Mindustry;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.net.Host;
import io.anuke.mindustry.net.Net;
import io.anuke.ucore.UCore;
import io.anuke.ucore.core.Settings;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.scene.style.Drawable;
@@ -235,7 +236,7 @@ public class JoinDialog extends FloatingDialog {
Vars.ui.showError(Bundles.format("text.connectfail", error));
Vars.ui.loadfrag.hide();
e.printStackTrace();
UCore.error(e);
}
});
}

View File

@@ -6,6 +6,7 @@ import io.anuke.mindustry.core.GameState;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.io.SaveIO;
import io.anuke.mindustry.io.Saves.SaveSlot;
import io.anuke.ucore.UCore;
import io.anuke.ucore.core.Core;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.scene.ui.ScrollPane;
@@ -173,7 +174,7 @@ public class LoadDialog extends FloatingDialog{
GameState.set(State.playing);
Vars.ui.paused.hide();
}catch(Exception e){
e.printStackTrace();
UCore.error(e);
Vars.ui.paused.hide();
GameState.set(State.menu);
Vars.control.reset();

View File

@@ -3,6 +3,7 @@ package io.anuke.mindustry.world.blocks.types.distribution;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.UCore;
import io.anuke.ucore.core.Timers;
public class TunnelConveyor extends Block{
@@ -34,7 +35,7 @@ public class TunnelConveyor extends Block{
try {
to.block().handleItem(item, to, tunnel);
}catch (NullPointerException e){
e.printStackTrace();
UCore.error(e);
}
});
}