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