From a04e432aeaee0e8505955d2310a2f1f93c1dcc64 Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 1 Jun 2018 13:11:40 -0400 Subject: [PATCH] Fixed multithreading --- android/AndroidManifest.xml | 2 +- .../anuke/mindustry/core/ThreadHandler.java | 2 + .../src/io/anuke/mindustry/game/TeamInfo.java | 5 +- .../mindustry/ui/fragments/MenuFragment.java | 9 +-- .../mindustry/desktop/DesktopLauncher.java | 70 +++++++++---------- 5 files changed, 40 insertions(+), 48 deletions(-) diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index d52c2b1067..a616fc2e8d 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -37,7 +37,7 @@ - + diff --git a/core/src/io/anuke/mindustry/core/ThreadHandler.java b/core/src/io/anuke/mindustry/core/ThreadHandler.java index d3b753284c..3c60a0ce09 100644 --- a/core/src/io/anuke/mindustry/core/ThreadHandler.java +++ b/core/src/io/anuke/mindustry/core/ThreadHandler.java @@ -105,7 +105,9 @@ public class ThreadHandler { toRun.clear(); } + logic.doUpdate = true; logic.update(); + logic.doUpdate = false; long elapsed = TimeUtils.timeSinceMillis(time); long target = (long) (1000 / 60f); diff --git a/core/src/io/anuke/mindustry/game/TeamInfo.java b/core/src/io/anuke/mindustry/game/TeamInfo.java index bb598f0f3d..bac019798f 100644 --- a/core/src/io/anuke/mindustry/game/TeamInfo.java +++ b/core/src/io/anuke/mindustry/game/TeamInfo.java @@ -5,11 +5,8 @@ import com.badlogic.gdx.utils.ObjectMap; import com.badlogic.gdx.utils.ObjectSet; import io.anuke.mindustry.world.Tile; -/**Wrapper around an ObjectMap for team data.*/ +/**Class for various team-based utilities.*/ public class TeamInfo { - private final static ObjectSet empty = new ObjectSet<>(); - private final static ObjectSet emptyData = new ObjectSet<>(); - private ObjectMap map = new ObjectMap<>(); private ObjectSet allies = new ObjectSet<>(), enemies = new ObjectSet<>(); diff --git a/core/src/io/anuke/mindustry/ui/fragments/MenuFragment.java b/core/src/io/anuke/mindustry/ui/fragments/MenuFragment.java index 4dc92354b8..e38c2b4bd8 100644 --- a/core/src/io/anuke/mindustry/ui/fragments/MenuFragment.java +++ b/core/src/io/anuke/mindustry/ui/fragments/MenuFragment.java @@ -10,7 +10,6 @@ import io.anuke.ucore.scene.Group; import io.anuke.ucore.scene.builders.imagebutton; import io.anuke.ucore.scene.builders.label; import io.anuke.ucore.scene.builders.table; -import io.anuke.ucore.util.OS; import static io.anuke.mindustry.Vars.*; @@ -40,13 +39,7 @@ public class MenuFragment implements Fragment{ add(new MenuButton("icon-info", "$text.about.button", ui.about::show)); - add(new MenuButton("icon-menu", OS.isMac ? "$text.credits" : "$text.changelog.title", () -> { - if(OS.isMac){ - ui.about.showCredits(); - }else { - ui.changelog.show(); - } - })); + add(new MenuButton("icon-tools", "$text.settings", ui.settings::show)); row(); diff --git a/desktop/src/io/anuke/mindustry/desktop/DesktopLauncher.java b/desktop/src/io/anuke/mindustry/desktop/DesktopLauncher.java index b798370b34..b67ceccc2f 100644 --- a/desktop/src/io/anuke/mindustry/desktop/DesktopLauncher.java +++ b/desktop/src/io/anuke/mindustry/desktop/DesktopLauncher.java @@ -33,42 +33,42 @@ public class DesktopLauncher { config.setWindowedMode(960, 540); config.setWindowIcon("sprites/icon.png"); - Application.getApplication().setOpenFileHandler(e -> { - List list = e.getFiles(); - - File target = list.get(0); - - Gdx.app.postRunnable(() -> { - FileHandle file = OS.getAppDataDirectory("Mindustry").child("tmp").child(target.getName()); - - Gdx.files.absolute(target.getAbsolutePath()).copyTo(file); - - if(file.extension().equalsIgnoreCase(saveExtension)){ //open save - - if(SaveIO.isSaveValid(file)){ - try{ - SaveSlot slot = control.getSaves().importSave(file); - ui.load.runLoadSave(slot); - }catch (IOException e2){ - ui.showError(Bundles.format("text.save.import.fail", Strings.parseException(e2, false))); - } - }else{ - ui.showError("$text.save.import.invalid"); - } - - }else if(file.extension().equalsIgnoreCase(mapExtension)){ //open map - Gdx.app.postRunnable(() -> { - if (!ui.editor.isShown()) { - ui.editor.show(); - } - - ui.editor.beginEditMap(file.read()); - }); - } - }); - }); - if(OS.isMac) { + Application.getApplication().setOpenFileHandler(e -> { + List list = e.getFiles(); + + File target = list.get(0); + + Gdx.app.postRunnable(() -> { + FileHandle file = OS.getAppDataDirectory("Mindustry").child("tmp").child(target.getName()); + + Gdx.files.absolute(target.getAbsolutePath()).copyTo(file); + + if(file.extension().equalsIgnoreCase(saveExtension)){ //open save + + if(SaveIO.isSaveValid(file)){ + try{ + SaveSlot slot = control.getSaves().importSave(file); + ui.load.runLoadSave(slot); + }catch (IOException e2){ + ui.showError(Bundles.format("text.save.import.fail", Strings.parseException(e2, false))); + } + }else{ + ui.showError("$text.save.import.invalid"); + } + + }else if(file.extension().equalsIgnoreCase(mapExtension)){ //open map + Gdx.app.postRunnable(() -> { + if (!ui.editor.isShown()) { + ui.editor.show(); + } + + ui.editor.beginEditMap(file.read()); + }); + } + }); + }); + config.setPreferencesConfig(OS.getAppDataDirectoryString("Mindustry"), FileType.Absolute); }