This commit is contained in:
Anuken
2020-05-03 00:49:34 -04:00
parent dd68241d1f
commit 50e8586dc2
2 changed files with 8 additions and 5 deletions

View File

@@ -7,17 +7,19 @@ import mindustry.game.EventType.*;
import java.util.concurrent.*;
import static mindustry.Vars.state;
public class AsyncLogic{
//all processes to be executed each frame
private Array<AsyncProcess> processes = Array.with(
private final Array<AsyncProcess> processes = Array.with(
new PhysicsProcess(),
Vars.teamIndex = new TeamIndexProcess()
);
//futures to be awaited
private Array<Future<?>> futures = new Array<>();
private final Array<Future<?>> futures = new Array<>();
private ExecutorService executor = Executors.newFixedThreadPool(processes.size, r -> {
private final ExecutorService executor = Executors.newFixedThreadPool(processes.size, r -> {
Thread thread = new Thread(r, "AsyncLogic-Thread");
thread.setDaemon(true);
thread.setUncaughtExceptionHandler((t, e) -> Core.app.post(() -> { throw new RuntimeException(e); }));
@@ -41,7 +43,7 @@ public class AsyncLogic{
}
public void begin(){
if(Vars.state.isPlaying()){
if(state.isPlaying()){
//sync begin
for(AsyncProcess p : processes){
p.begin();
@@ -59,7 +61,7 @@ public class AsyncLogic{
}
public void end(){
if(Vars.state.isPlaying()){
if(state.isPlaying()){
complete();
//sync end (flush data)