Centralized executor
This commit is contained in:
@@ -31,6 +31,7 @@ import mindustry.world.*;
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.charset.*;
|
import java.nio.charset.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.*;
|
||||||
|
|
||||||
import static arc.Core.*;
|
import static arc.Core.*;
|
||||||
|
|
||||||
@@ -210,6 +211,9 @@ public class Vars implements Loadable{
|
|||||||
/** list of all locales that can be switched to */
|
/** list of all locales that can be switched to */
|
||||||
public static Locale[] locales;
|
public static Locale[] locales;
|
||||||
|
|
||||||
|
//the main executor will only have at most [cores] number of threads active
|
||||||
|
public static ExecutorService mainExecutor = Threads.cachedExecutor(1, OS.cores, true);
|
||||||
|
|
||||||
public static FileTree tree = new FileTree();
|
public static FileTree tree = new FileTree();
|
||||||
public static Net net;
|
public static Net net;
|
||||||
public static ContentLoader content;
|
public static ContentLoader content;
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ public class MapGenerateDialog extends BaseDialog{
|
|||||||
int scaling = mobile ? 3 : 1;
|
int scaling = mobile ? 3 : 1;
|
||||||
Table filterTable;
|
Table filterTable;
|
||||||
|
|
||||||
ExecutorService executor = Threads.executor(1);
|
|
||||||
Future<?> result;
|
Future<?> result;
|
||||||
boolean generating;
|
boolean generating;
|
||||||
|
|
||||||
@@ -397,7 +396,7 @@ public class MapGenerateDialog extends BaseDialog{
|
|||||||
|
|
||||||
var copy = filters.copy();
|
var copy = filters.copy();
|
||||||
|
|
||||||
result = executor.submit(() -> {
|
result = mainExecutor.submit(() -> {
|
||||||
try{
|
try{
|
||||||
int w = pixmap.width;
|
int w = pixmap.width;
|
||||||
world.setGenerating(true);
|
world.setGenerating(true);
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import mindustry.type.*;
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.text.*;
|
import java.text.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.*;
|
|
||||||
|
|
||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
|
|
||||||
@@ -25,7 +24,6 @@ public class Saves{
|
|||||||
Seq<SaveSlot> saves = new Seq<>();
|
Seq<SaveSlot> saves = new Seq<>();
|
||||||
@Nullable SaveSlot current;
|
@Nullable SaveSlot current;
|
||||||
private @Nullable SaveSlot lastSectorSave;
|
private @Nullable SaveSlot lastSectorSave;
|
||||||
ExecutorService previewExecutor = Threads.executor(1);
|
|
||||||
private boolean saving;
|
private boolean saving;
|
||||||
private float time;
|
private float time;
|
||||||
|
|
||||||
@@ -223,7 +221,7 @@ public class Saves{
|
|||||||
if(Core.assets.isLoaded(loadPreviewFile().path())){
|
if(Core.assets.isLoaded(loadPreviewFile().path())){
|
||||||
Core.assets.unload(loadPreviewFile().path());
|
Core.assets.unload(loadPreviewFile().path());
|
||||||
}
|
}
|
||||||
previewExecutor.submit(() -> {
|
mainExecutor.submit(() -> {
|
||||||
try{
|
try{
|
||||||
previewFile().writePng(renderer.minimap.getPixmap());
|
previewFile().writePng(renderer.minimap.getPixmap());
|
||||||
requestedPreview = false;
|
requestedPreview = false;
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import mindustry.world.*;
|
|||||||
import mindustry.world.blocks.storage.*;
|
import mindustry.world.blocks.storage.*;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.concurrent.*;
|
|
||||||
|
|
||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
|
|
||||||
@@ -46,7 +45,6 @@ public class Maps{
|
|||||||
private ShuffleMode shuffleMode = ShuffleMode.all;
|
private ShuffleMode shuffleMode = ShuffleMode.all;
|
||||||
private @Nullable MapProvider shuffler;
|
private @Nullable MapProvider shuffler;
|
||||||
|
|
||||||
private ExecutorService executor = Threads.executor(3);
|
|
||||||
private ObjectSet<Map> previewList = new ObjectSet<>();
|
private ObjectSet<Map> previewList = new ObjectSet<>();
|
||||||
|
|
||||||
public ShuffleMode getShuffleMode(){
|
public ShuffleMode getShuffleMode(){
|
||||||
@@ -223,7 +221,7 @@ public class Maps{
|
|||||||
}
|
}
|
||||||
|
|
||||||
Pixmap pix = MapIO.generatePreview(world.tiles);
|
Pixmap pix = MapIO.generatePreview(world.tiles);
|
||||||
executor.submit(() -> map.previewFile().writePng(pix));
|
mainExecutor.submit(() -> map.previewFile().writePng(pix));
|
||||||
writeCache(map);
|
writeCache(map);
|
||||||
|
|
||||||
map.texture = new Texture(pix);
|
map.texture = new Texture(pix);
|
||||||
@@ -390,7 +388,7 @@ public class Maps{
|
|||||||
//this has to be done synchronously!
|
//this has to be done synchronously!
|
||||||
Pixmap pix = MapIO.generatePreview(map);
|
Pixmap pix = MapIO.generatePreview(map);
|
||||||
map.texture = new Texture(pix);
|
map.texture = new Texture(pix);
|
||||||
executor.submit(() -> {
|
mainExecutor.submit(() -> {
|
||||||
try{
|
try{
|
||||||
map.previewFile().writePng(pix);
|
map.previewFile().writePng(pix);
|
||||||
writeCache(map);
|
writeCache(map);
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ import static mindustry.Vars.*;
|
|||||||
public class Mods implements Loadable{
|
public class Mods implements Loadable{
|
||||||
private static final String[] metaFiles = {"mod.json", "mod.hjson", "plugin.json", "plugin.hjson"};
|
private static final String[] metaFiles = {"mod.json", "mod.hjson", "plugin.json", "plugin.hjson"};
|
||||||
|
|
||||||
private ExecutorService async = Threads.executor();
|
|
||||||
private Json json = new Json();
|
private Json json = new Json();
|
||||||
private @Nullable Scripts scripts;
|
private @Nullable Scripts scripts;
|
||||||
private ContentParser parser = new ContentParser();
|
private ContentParser parser = new ContentParser();
|
||||||
@@ -184,7 +183,7 @@ public class Mods implements Loadable{
|
|||||||
|
|
||||||
for(Fi file : sprites){
|
for(Fi file : sprites){
|
||||||
//read and bleed pixmaps in parallel
|
//read and bleed pixmaps in parallel
|
||||||
tasks.add(async.submit(() -> {
|
tasks.add(mainExecutor.submit(() -> {
|
||||||
try{
|
try{
|
||||||
Pixmap pix = new Pixmap(file.readBytes());
|
Pixmap pix = new Pixmap(file.readBytes());
|
||||||
//only bleeds when linear filtering is on at startup
|
//only bleeds when linear filtering is on at startup
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import static mindustry.Vars.*;
|
|||||||
public class ArcNetProvider implements NetProvider{
|
public class ArcNetProvider implements NetProvider{
|
||||||
final Client client;
|
final Client client;
|
||||||
final Prov<DatagramPacket> packetSupplier = () -> new DatagramPacket(new byte[512], 512);
|
final Prov<DatagramPacket> packetSupplier = () -> new DatagramPacket(new byte[512], 512);
|
||||||
final ExecutorService executor = Threads.executor(1);
|
|
||||||
|
|
||||||
final Server server;
|
final Server server;
|
||||||
final CopyOnWriteArrayList<ArcConnection> connections = new CopyOnWriteArrayList<>();
|
final CopyOnWriteArrayList<ArcConnection> connections = new CopyOnWriteArrayList<>();
|
||||||
@@ -263,7 +262,7 @@ public class ArcNetProvider implements NetProvider{
|
|||||||
@Override
|
@Override
|
||||||
public void closeServer(){
|
public void closeServer(){
|
||||||
connections.clear();
|
connections.clear();
|
||||||
executor.submit(server::stop);
|
mainExecutor.submit(server::stop);
|
||||||
}
|
}
|
||||||
|
|
||||||
ArcConnection getByArcID(int id){
|
ArcConnection getByArcID(int id){
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import mindustry.ui.dialogs.*;
|
|||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.util.concurrent.*;
|
|
||||||
|
|
||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
|
|
||||||
@@ -25,7 +24,6 @@ import static mindustry.Vars.*;
|
|||||||
public class BeControl{
|
public class BeControl{
|
||||||
private static final int updateInterval = 60;
|
private static final int updateInterval = 60;
|
||||||
|
|
||||||
private ExecutorService executor = Threads.executor(1);
|
|
||||||
private boolean checkUpdates = true;
|
private boolean checkUpdates = true;
|
||||||
private boolean updateAvailable;
|
private boolean updateAvailable;
|
||||||
private String updateUrl;
|
private String updateUrl;
|
||||||
@@ -168,7 +166,7 @@ public class BeControl{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void download(String furl, Fi dest, Intc length, Floatc progressor, Boolp canceled, Runnable done, Cons<Throwable> error){
|
private void download(String furl, Fi dest, Intc length, Floatc progressor, Boolp canceled, Runnable done, Cons<Throwable> error){
|
||||||
executor.submit(() -> {
|
mainExecutor.submit(() -> {
|
||||||
try{
|
try{
|
||||||
HttpURLConnection con = (HttpURLConnection)new URL(furl).openConnection();
|
HttpURLConnection con = (HttpURLConnection)new URL(furl).openConnection();
|
||||||
BufferedInputStream in = new BufferedInputStream(con.getInputStream());
|
BufferedInputStream in = new BufferedInputStream(con.getInputStream());
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public class Net{
|
|||||||
private final ObjectMap<Class<?>, Cons> clientListeners = new ObjectMap<>();
|
private final ObjectMap<Class<?>, Cons> clientListeners = new ObjectMap<>();
|
||||||
private final ObjectMap<Class<?>, Cons2<NetConnection, Object>> serverListeners = new ObjectMap<>();
|
private final ObjectMap<Class<?>, Cons2<NetConnection, Object>> serverListeners = new ObjectMap<>();
|
||||||
private final IntMap<StreamBuilder> streams = new IntMap<>();
|
private final IntMap<StreamBuilder> streams = new IntMap<>();
|
||||||
private final ExecutorService pingExecutor = Threads.cachedExecutor();
|
private final ExecutorService pingExecutor = Threads.unboundedExecutor();
|
||||||
|
|
||||||
private final NetProvider provider;
|
private final NetProvider provider;
|
||||||
|
|
||||||
|
|||||||
@@ -25,4 +25,4 @@ org.gradle.caching=true
|
|||||||
#used for slow jitpack builds; TODO see if this actually works
|
#used for slow jitpack builds; TODO see if this actually works
|
||||||
org.gradle.internal.http.socketTimeout=100000
|
org.gradle.internal.http.socketTimeout=100000
|
||||||
org.gradle.internal.http.connectionTimeout=100000
|
org.gradle.internal.http.connectionTimeout=100000
|
||||||
archash=2fd232cbb5
|
archash=532ce72d37
|
||||||
|
|||||||
Reference in New Issue
Block a user