mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-07-16 02:38:37 +07:00
Physics
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
package mindustry.async;
|
||||
|
||||
import arc.*;
|
||||
import arc.struct.*;
|
||||
import mindustry.game.EventType.*;
|
||||
|
||||
import java.util.concurrent.*;
|
||||
|
||||
@ -12,15 +14,28 @@ public class AsyncLogic{
|
||||
private Array<Future<?>> futures = new Array<>();
|
||||
|
||||
private ExecutorService executor = Executors.newFixedThreadPool(processes.size, r -> {
|
||||
Thread thread = new Thread(r, "AsyncExecutor-Thread");
|
||||
Thread thread = new Thread(r, "AsyncLogic-Thread");
|
||||
thread.setDaemon(true);
|
||||
thread.setUncaughtExceptionHandler((t, e) -> {
|
||||
e.printStackTrace();
|
||||
//TODO crash!
|
||||
});
|
||||
thread.setUncaughtExceptionHandler((t, e) -> Core.app.post(() -> { throw new RuntimeException(e); }));
|
||||
return thread;
|
||||
});
|
||||
|
||||
public AsyncLogic(){
|
||||
Events.on(WorldLoadEvent.class, e -> {
|
||||
complete();
|
||||
for(AsyncProcess p : processes){
|
||||
p.init();
|
||||
}
|
||||
});
|
||||
|
||||
Events.on(ResetEvent.class, e -> {
|
||||
complete();
|
||||
for(AsyncProcess p : processes){
|
||||
p.reset();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void begin(){
|
||||
//sync begin
|
||||
for(AsyncProcess p : processes){
|
||||
@ -36,6 +51,15 @@ public class AsyncLogic{
|
||||
}
|
||||
|
||||
public void end(){
|
||||
complete();
|
||||
|
||||
//sync end (flush data)
|
||||
for(AsyncProcess p : processes){
|
||||
p.end();
|
||||
}
|
||||
}
|
||||
|
||||
private void complete(){
|
||||
//wait for all threads to stop processing
|
||||
for(Future future : futures){
|
||||
try{
|
||||
@ -45,11 +69,7 @@ public class AsyncLogic{
|
||||
}
|
||||
}
|
||||
|
||||
//clear processed futures
|
||||
futures.clear();
|
||||
|
||||
//sync end (flush data)
|
||||
for(AsyncProcess p : processes){
|
||||
p.end();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user