From 8b2f63ecb6df960f4195d05717e2f895166c5933 Mon Sep 17 00:00:00 2001 From: Anuken Date: Wed, 24 Jan 2018 18:48:59 -0500 Subject: [PATCH] Web compilation fix, new logging, cleanup --- build.gradle | 2 +- core/assets/bundles/bundle.properties | 1 + core/src/io/anuke/mindustry/Mindustry.java | 3 ++- .../io/anuke/mindustry/core/NetClient.java | 3 ++- .../io/anuke/mindustry/core/NetServer.java | 4 ++-- core/src/io/anuke/mindustry/core/World.java | 6 ++--- core/src/io/anuke/mindustry/io/Maps.java | 4 ++-- .../mindustry/mapeditor/MapEditorDialog.java | 5 ++-- .../src/io/anuke/mindustry/net/NetworkIO.java | 24 +++++++++++++------ .../mindustry/ui/dialogs/JoinDialog.java | 3 ++- .../mindustry/ui/dialogs/LoadDialog.java | 3 ++- .../types/distribution/TunnelConveyor.java | 3 ++- html/webapp/soundmanager2-jsmin.js | 4 ++-- kryonet/src/io/anuke/kryonet/KryoServer.java | 2 ++ kryonet/src/io/anuke/kryonet/SSLGen.java | 11 --------- 15 files changed, 43 insertions(+), 35 deletions(-) delete mode 100644 kryonet/src/io/anuke/kryonet/SSLGen.java diff --git a/build.gradle b/build.gradle index e4ccc3dd26..8f52837553 100644 --- a/build.gradle +++ b/build.gradle @@ -21,7 +21,7 @@ allprojects { appName = "Mindustry" gdxVersion = '1.9.8' aiVersion = '1.8.1' - uCoreVersion = 'ee4b46a'; + uCoreVersion = '0eb75cc'; } repositories { diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index 2d2729a960..a21877439f 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -16,6 +16,7 @@ text.about.button=About text.name=Name: text.public=Public text.players={0} players online +text.server.nomap=Loading custom maps not supported on web. text.server.player.host={0} (host) text.players.single={0} player online text.server.mismatch=Packet error: possible client/server version mismatch.\nMake sure you and the host have the\nlatest version of Mindustry! diff --git a/core/src/io/anuke/mindustry/Mindustry.java b/core/src/io/anuke/mindustry/Mindustry.java index 2ef9424df6..571f125284 100644 --- a/core/src/io/anuke/mindustry/Mindustry.java +++ b/core/src/io/anuke/mindustry/Mindustry.java @@ -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(); diff --git a/core/src/io/anuke/mindustry/core/NetClient.java b/core/src/io/anuke/mindustry/core/NetClient.java index 42efa894d5..dba4b0ffa8 100644 --- a/core/src/io/anuke/mindustry/core/NetClient.java +++ b/core/src/io/anuke/mindustry/core/NetClient.java @@ -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 } diff --git a/core/src/io/anuke/mindustry/core/NetServer.java b/core/src/io/anuke/mindustry/core/NetServer.java index 6544f646f8..5a96884e78 100644 --- a/core/src/io/anuke/mindustry/core/NetServer.java +++ b/core/src/io/anuke/mindustry/core/NetServer.java @@ -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!"); } diff --git a/core/src/io/anuke/mindustry/core/World.java b/core/src/io/anuke/mindustry/core/World.java index ec58dc94fa..1d98b3acdd 100644 --- a/core/src/io/anuke/mindustry/core/World.java +++ b/core/src/io/anuke/mindustry/core/World.java @@ -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]; } diff --git a/core/src/io/anuke/mindustry/io/Maps.java b/core/src/io/anuke/mindustry/io/Maps.java index bd4ced809c..cbac09284a 100644 --- a/core/src/io/anuke/mindustry/io/Maps.java +++ b/core/src/io/anuke/mindustry/io/Maps.java @@ -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; } diff --git a/core/src/io/anuke/mindustry/mapeditor/MapEditorDialog.java b/core/src/io/anuke/mindustry/mapeditor/MapEditorDialog.java index 6c005a18cd..4a7bb352be 100644 --- a/core/src/io/anuke/mindustry/mapeditor/MapEditorDialog.java +++ b/core/src/io/anuke/mindustry/mapeditor/MapEditorDialog.java @@ -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(); }); diff --git a/core/src/io/anuke/mindustry/net/NetworkIO.java b/core/src/io/anuke/mindustry/net/NetworkIO.java index cec5e3e8e9..fdc4e5c25a 100644 --- a/core/src/io/anuke/mindustry/net/NetworkIO.java +++ b/core/src/io/anuke/mindustry/net/NetworkIO.java @@ -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; diff --git a/core/src/io/anuke/mindustry/ui/dialogs/JoinDialog.java b/core/src/io/anuke/mindustry/ui/dialogs/JoinDialog.java index f73a876715..7e6b59c576 100644 --- a/core/src/io/anuke/mindustry/ui/dialogs/JoinDialog.java +++ b/core/src/io/anuke/mindustry/ui/dialogs/JoinDialog.java @@ -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); } }); } diff --git a/core/src/io/anuke/mindustry/ui/dialogs/LoadDialog.java b/core/src/io/anuke/mindustry/ui/dialogs/LoadDialog.java index d8c7483b62..dfbe7faa68 100644 --- a/core/src/io/anuke/mindustry/ui/dialogs/LoadDialog.java +++ b/core/src/io/anuke/mindustry/ui/dialogs/LoadDialog.java @@ -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(); diff --git a/core/src/io/anuke/mindustry/world/blocks/types/distribution/TunnelConveyor.java b/core/src/io/anuke/mindustry/world/blocks/types/distribution/TunnelConveyor.java index e372c5efd1..0b525e9946 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/distribution/TunnelConveyor.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/distribution/TunnelConveyor.java @@ -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); } }); } diff --git a/html/webapp/soundmanager2-jsmin.js b/html/webapp/soundmanager2-jsmin.js index 2077360f86..ed5bf17df4 100644 --- a/html/webapp/soundmanager2-jsmin.js +++ b/html/webapp/soundmanager2-jsmin.js @@ -11,7 +11,7 @@ V2.97a.20150601 */ -(function(h,g){function K(sb,K){function ha(b){return c.preferFlash&&H&&!c.ignoreFlash&&c.flash[b]!==g&&c.flash[b]}function r(b){return function(d){var e=this._s;e&&e._a?d=b.call(this,d):(e&&e.id?c._wD(e.id+": Ignoring "+d.type):c._wD("HTML5::Ignoring "+d.type),d=null);return d}}this.setupOptions={url:sb||null,flashVersion:8,debugMode:!0,debugFlash:!1,useConsole:!0,consoleOnly:!0,waitForWindowLoad:!1,bgColor:"#ffffff",useHighPerformance:!1,flashPollingInterval:null,html5PollingInterval:null,flashLoadTimeout:1E3, +(function(h,g){function K(sb,K){function ha(b){return c.preferFlash&&H&&!c.ignoreFlash&&c.flash[b]!==g&&c.flash[b]}function r(b){return function(d){var e=this._s;e&&e._a?d=b.call(this,d):(e&&e.id?c._wD(e.id+": Ignoring "+d.type):c._wD("HTML5::Ignoring "+d.type),d=null);return d}}this.setupOptions={url:sb||null,flashVersion:8,debugMode:!1,debugFlash:!1,useConsole:!0,consoleOnly:!0,waitForWindowLoad:!1,bgColor:"#ffffff",useHighPerformance:!1,flashPollingInterval:null,html5PollingInterval:null,flashLoadTimeout:1E3, wmode:null,allowScriptAccess:"always",useFlashBlock:!1,useHTML5Audio:!0,forceUseGlobalHTML5Audio:!1,ignoreMobileRestrictions:!1,html5Test:/^(probably|maybe)$/i,preferFlash:!1,noSWFCache:!1,idPrefix:"sound"};this.defaultOptions={autoLoad:!1,autoPlay:!1,from:null,loops:1,onid3:null,onload:null,whileloading:null,onplay:null,onpause:null,onresume:null,whileplaying:null,onposition:null,onstop:null,onfailure:null,onfinish:null,multiShot:!0,multiShotEvents:!1,position:null,pan:0,stream:!0,to:null,type:null, usePolicyFile:!1,volume:100};this.flash9Options={isMovieStar:null,usePeakData:!1,useWaveformData:!1,useEQData:!1,onbufferchange:null,ondataerror:null};this.movieStarOptions={bufferTime:3,serverURL:null,onconnect:null,duration:null};this.audioFormats={mp3:{type:['audio/mpeg; codecs="mp3"',"audio/mpeg","audio/mp3","audio/MPA","audio/mpa-robust"],required:!0},mp4:{related:["aac","m4a","m4b"],type:['audio/mp4; codecs="mp4a.40.2"',"audio/aac","audio/x-m4a","audio/MP4A-LATM","audio/mpeg4-generic"],required:!1}, ogg:{type:["audio/ogg; codecs=vorbis"],required:!1},opus:{type:["audio/ogg; codecs=opus","audio/opus"],required:!1},wav:{type:['audio/wav; codecs="1"',"audio/wav","audio/wave","audio/x-wav"],required:!1}};this.movieID="sm2-container";this.id=K||"sm2movie";this.debugID="soundmanager-debug";this.debugURLParam=/([#?&])debug=1/i;this.versionNumber="V2.97a.20150601";this.altURL=this.movieURL=this.version=null;this.enabled=this.swfLoaded=!1;this.oMC=null;this.sounds={};this.soundIDs=[];this.didFlashBlock= @@ -110,4 +110,4 @@ V()+" "+(null===c.getMoviePercent()?"swf_timedout":"swf_error")),P({type:"ontime c.enabled=!0,Z()),!0;la();try{l._externalInterfaceTest(!1),ab(!0,c.flashPollingInterval||(c.useHighPerformance?10:50)),c.debugMode||l._disableDebug(),c.enabled=!0,D("jstoflash",!0),c.html5Only||x.add(h,"unload",ya)}catch(b){return c._wD("js/flash exception: "+b.toString()),D("jstoflash",!1),U({type:"JS_TO_FLASH_EXCEPTION",fatal:!0}),Ha(!0),Z(),!1}Z();x.remove(h,"load",c.beginDelayedInit);return!0};Q=function(){if(aa)return!1;aa=!0;Za();Ga();!H&&c.hasHTML5&&(c._wD("SoundManager 2: No Flash detected"+ (c.useHTML5Audio?". Trying HTML5-only mode.":", enabling HTML5."),1),c.setup({useHTML5Audio:!0,preferFlash:!1}));jb();!H&&u&&(M.push(z.needFlash),c.setup({flashLoadTimeout:1}));m.removeEventListener&&m.removeEventListener("DOMContentLoaded",Q,!1);la();return!0};La=function(){"complete"===m.readyState&&(Q(),m.detachEvent("onreadystatechange",La));return!0};Fa=function(){ja=!0;Q();x.remove(h,"load",Fa)};Na();x.add(h,"focus",ka);x.add(h,"load",T);x.add(h,"load",Fa);m.addEventListener?m.addEventListener("DOMContentLoaded", Q,!1):m.attachEvent?m.attachEvent("onreadystatechange",La):(D("onload",!1),U({type:"NO_DOM2_EVENTS",fatal:!0}))}if(!h||!h.document)throw Error("SoundManager requires a browser with window and document objects.");var W=null;h.SM2_DEFER!==g&&SM2_DEFER||(W=new K);"object"===typeof module&&module&&"object"===typeof module.exports?(module.exports.SoundManager=K,module.exports.soundManager=W):"function"===typeof define&&define.amd&&define(function(){return{constructor:K,getInstance:function(g){!h.soundManager&& -g instanceof Function&&(g=g(K),g instanceof K&&(h.soundManager=g));return h.soundManager}}});h.SoundManager=K;h.soundManager=W})(window); \ No newline at end of file +g instanceof Function&&(g=g(K),g instanceof K&&(h.soundManager=g));return h.soundManager}}});h.SoundManager=K;h.soundManager=W})(window); diff --git a/kryonet/src/io/anuke/kryonet/KryoServer.java b/kryonet/src/io/anuke/kryonet/KryoServer.java index c4a1a618d3..8abc755f58 100644 --- a/kryonet/src/io/anuke/kryonet/KryoServer.java +++ b/kryonet/src/io/anuke/kryonet/KryoServer.java @@ -156,6 +156,7 @@ public class KryoServer implements ServerProvider { Thread thread = new Thread(() ->{ try { server.close(); + UCore.log("Killing web server..."); try { if (webServer != null) webServer.stop(1); //please die, right now }catch(Exception e){ @@ -167,6 +168,7 @@ public class KryoServer implements ServerProvider { worker.interrupt(); } } + UCore.log("Killed web server."); }catch (Exception e){ Gdx.app.postRunnable(() -> {throw new RuntimeException(e);}); } diff --git a/kryonet/src/io/anuke/kryonet/SSLGen.java b/kryonet/src/io/anuke/kryonet/SSLGen.java deleted file mode 100644 index 41644f464f..0000000000 --- a/kryonet/src/io/anuke/kryonet/SSLGen.java +++ /dev/null @@ -1,11 +0,0 @@ -package io.anuke.kryonet; - -import org.java_websocket.WebSocketServerFactory; - -public class SSLGen { - - public static WebSocketServerFactory getFactory(){ - //TODO implement - return null; - } -}