Fixes to many multithreading crashes and freezes
This commit is contained in:
@@ -227,7 +227,7 @@ public class NetServer extends Module{
|
||||
if(timer.get(timerEntitySync, serverSyncTime)){
|
||||
//scan through all groups with syncable entities
|
||||
for(EntityGroup<?> group : Entities.getAllGroups()) {
|
||||
if(group.size() == 0 || !(group.all().first() instanceof SyncEntity)) continue;
|
||||
if(group.size() == 0 || !(group.all().iterator().next() instanceof SyncEntity)) continue;
|
||||
|
||||
//get write size for one entity (adding 4, as you need to write the ID as well)
|
||||
int writesize = SyncEntity.getWriteSize((Class<? extends SyncEntity>)group.getType()) + 4;
|
||||
|
||||
@@ -241,16 +241,16 @@ public class Renderer extends RendererModule{
|
||||
Mathf.round(camera.position.y - ch/2, tilesize),
|
||||
(cw - vw) /2,
|
||||
ch + tilesize,
|
||||
0, ch / tilesize + 1,
|
||||
((cw - vw) / 2 / tilesize), 0);
|
||||
0, 0,
|
||||
((cw - vw) / 2 / tilesize), -ch / tilesize + 1);
|
||||
|
||||
batch.draw(background,
|
||||
camera.position.x - vw/2,
|
||||
Mathf.round(camera.position.y - ch/2, tilesize),
|
||||
-(cw - vw) /2,
|
||||
ch + tilesize,
|
||||
0, ch / tilesize + 1,
|
||||
-((cw - vw) / 2 / tilesize), 0);
|
||||
0, 0,
|
||||
-((cw - vw) / 2 / tilesize), -ch / tilesize + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -539,7 +539,7 @@ public class Renderer extends RendererModule{
|
||||
}
|
||||
|
||||
public void clampScale(){
|
||||
targetscale = Mathf.clamp(targetscale, Math.round(Unit.dp.scl(1)), Math.round(Unit.dp.scl((5))));
|
||||
targetscale = Mathf.clamp(targetscale, Math.round(Unit.dp.scl(2)), Math.round(Unit.dp.scl((5))));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,10 @@ import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.entities.Entities;
|
||||
import io.anuke.ucore.entities.Entity;
|
||||
import io.anuke.ucore.entities.EntityGroup;
|
||||
import io.anuke.ucore.entities.EntityGroup.ArrayContainer;
|
||||
import io.anuke.ucore.util.Log;
|
||||
|
||||
import static io.anuke.mindustry.Vars.logic;
|
||||
@@ -57,6 +61,9 @@ public class ThreadHandler {
|
||||
public void setEnabled(boolean enabled){
|
||||
if(enabled){
|
||||
logic.doUpdate = false;
|
||||
for(EntityGroup<?> group : Entities.getAllGroups()){
|
||||
impl.switchContainer(group);
|
||||
}
|
||||
Timers.runTask(2f, () -> {
|
||||
impl.start(this::runLogic);
|
||||
this.enabled = true;
|
||||
@@ -64,6 +71,9 @@ public class ThreadHandler {
|
||||
}else{
|
||||
this.enabled = false;
|
||||
impl.stop();
|
||||
for(EntityGroup<?> group : Entities.getAllGroups()){
|
||||
group.setContainer(new ArrayContainer<>());
|
||||
}
|
||||
Timers.runTask(2f, () -> {
|
||||
logic.doUpdate = true;
|
||||
});
|
||||
@@ -110,7 +120,7 @@ public class ThreadHandler {
|
||||
} catch (InterruptedException ex) {
|
||||
Log.info("Stopping logic thread.");
|
||||
} catch (Exception ex) {
|
||||
Gdx.app.postRunnable(() -> {
|
||||
Timers.run(0f, () -> {
|
||||
throw new RuntimeException(ex);
|
||||
});
|
||||
}
|
||||
@@ -123,5 +133,6 @@ public class ThreadHandler {
|
||||
void stop();
|
||||
void wait(Object object) throws InterruptedException;
|
||||
void notify(Object object);
|
||||
<T extends Entity> void switchContainer(EntityGroup<T> group);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package io.anuke.mindustry.io;
|
||||
|
||||
import io.anuke.mindustry.core.ThreadHandler.ThreadProvider;
|
||||
import io.anuke.ucore.entities.Entity;
|
||||
import io.anuke.ucore.entities.EntityGroup;
|
||||
import io.anuke.ucore.scene.ui.TextField;
|
||||
|
||||
import java.util.Date;
|
||||
@@ -36,6 +38,7 @@ public abstract class Platform {
|
||||
@Override public void stop() {}
|
||||
@Override public void notify(Object object) {}
|
||||
@Override public void wait(Object object) {}
|
||||
@Override public <T extends Entity> void switchContainer(EntityGroup<T> group) {}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.Blocks;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.entities.Entities;
|
||||
import io.anuke.ucore.entities.EntityGroup.EntityContainer;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
@@ -216,11 +217,11 @@ public class Save12 extends SaveFileVersion {
|
||||
|
||||
//--ENEMIES--
|
||||
|
||||
Array<Enemy> enemies = enemyGroup.all();
|
||||
EntityContainer<Enemy> enemies = enemyGroup.all();
|
||||
|
||||
stream.writeInt(enemies.size); //enemy amount
|
||||
stream.writeInt(enemies.size()); //enemy amount
|
||||
|
||||
for(int i = 0; i < enemies.size; i ++){
|
||||
for(int i = 0; i < enemies.size(); i ++){
|
||||
Enemy enemy = enemies.get(i);
|
||||
stream.writeByte(enemy.type.id); //type
|
||||
stream.writeByte(enemy.lane); //lane
|
||||
|
||||
@@ -19,6 +19,7 @@ import io.anuke.mindustry.world.blocks.types.BlockPart;
|
||||
import io.anuke.mindustry.world.blocks.types.Rock;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.entities.Entities;
|
||||
import io.anuke.ucore.entities.EntityGroup.EntityContainer;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
@@ -229,11 +230,11 @@ public class Save13 extends SaveFileVersion {
|
||||
}
|
||||
|
||||
//--ENEMIES--
|
||||
Array<Enemy> enemies = enemyGroup.all();
|
||||
EntityContainer<Enemy> enemies = enemyGroup.all();
|
||||
|
||||
stream.writeInt(enemies.size); //enemy amount
|
||||
stream.writeInt(enemies.size()); //enemy amount
|
||||
|
||||
for(int i = 0; i < enemies.size; i ++){
|
||||
for(int i = 0; i < enemies.size(); i ++){
|
||||
Enemy enemy = enemies.get(i);
|
||||
stream.writeByte(enemy.type.id); //type
|
||||
stream.writeByte(enemy.lane); //lane
|
||||
|
||||
@@ -19,6 +19,7 @@ import io.anuke.mindustry.world.blocks.types.BlockPart;
|
||||
import io.anuke.mindustry.world.blocks.types.Rock;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.entities.Entities;
|
||||
import io.anuke.ucore.entities.EntityGroup.EntityContainer;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
@@ -255,11 +256,11 @@ public class Save14 extends SaveFileVersion{
|
||||
|
||||
//--ENEMIES--
|
||||
|
||||
Array<Enemy> enemies = enemyGroup.all();
|
||||
EntityContainer<Enemy> enemies = enemyGroup.all();
|
||||
|
||||
stream.writeInt(enemies.size); //enemy amount
|
||||
stream.writeInt(enemies.size()); //enemy amount
|
||||
|
||||
for(int i = 0; i < enemies.size; i ++){
|
||||
for(int i = 0; i < enemies.size(); i ++){
|
||||
Enemy enemy = enemies.get(i);
|
||||
stream.writeByte(enemy.type.id); //type
|
||||
stream.writeByte(enemy.lane); //lane
|
||||
|
||||
@@ -19,6 +19,7 @@ import io.anuke.mindustry.world.blocks.Blocks;
|
||||
import io.anuke.mindustry.world.blocks.types.BlockPart;
|
||||
import io.anuke.mindustry.world.blocks.types.Rock;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.entities.EntityGroup.EntityContainer;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
@@ -280,11 +281,11 @@ public class Save15 extends SaveFileVersion {
|
||||
|
||||
//--ENEMIES--
|
||||
|
||||
Array<Enemy> enemies = enemyGroup.all();
|
||||
EntityContainer<Enemy> enemies = enemyGroup.all();
|
||||
|
||||
stream.writeInt(enemies.size); //enemy amount
|
||||
stream.writeInt(enemies.size()); //enemy amount
|
||||
|
||||
for(int i = 0; i < enemies.size; i ++){
|
||||
for(int i = 0; i < enemies.size(); i ++){
|
||||
Enemy enemy = enemies.get(i);
|
||||
stream.writeByte(enemy.type.id); //type
|
||||
stream.writeByte(enemy.lane); //lane
|
||||
|
||||
Reference in New Issue
Block a user