Fixed some multithreading bugs and crashes
This commit is contained in:
@@ -24,7 +24,7 @@ allprojects {
|
|||||||
appName = 'Mindustry'
|
appName = 'Mindustry'
|
||||||
gdxVersion = '1.9.8'
|
gdxVersion = '1.9.8'
|
||||||
aiVersion = '1.8.1'
|
aiVersion = '1.8.1'
|
||||||
uCoreVersion = '629405c'
|
uCoreVersion = 'b42c54e'
|
||||||
|
|
||||||
getVersionString = {
|
getVersionString = {
|
||||||
String buildVersion = getBuildVersion()
|
String buildVersion = getBuildVersion()
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#Autogenerated file. Do not modify.
|
#Autogenerated file. Do not modify.
|
||||||
#Sat Feb 10 11:08:25 EST 2018
|
#Sat Feb 10 12:37:44 EST 2018
|
||||||
version=beta
|
version=beta
|
||||||
androidBuildCode=143
|
androidBuildCode=153
|
||||||
name=Mindustry
|
name=Mindustry
|
||||||
code=3.3
|
code=3.3
|
||||||
build=custom build
|
build=custom build
|
||||||
|
|||||||
@@ -270,11 +270,19 @@ public class NetClient extends Module {
|
|||||||
Net.handleClient(FriendlyFireChangePacket.class, packet -> state.friendlyFire = packet.enabled);
|
Net.handleClient(FriendlyFireChangePacket.class, packet -> state.friendlyFire = packet.enabled);
|
||||||
|
|
||||||
Net.handleClient(ItemTransferPacket.class, packet -> {
|
Net.handleClient(ItemTransferPacket.class, packet -> {
|
||||||
Tile tile = world.tile(packet.position);
|
Runnable r = () -> {
|
||||||
if(tile == null || tile.entity == null) return;
|
Tile tile = world.tile(packet.position);
|
||||||
Tile next = tile.getNearby(packet.rotation);
|
if (tile == null || tile.entity == null) return;
|
||||||
tile.entity.items[packet.itemid] --;
|
Tile next = tile.getNearby(packet.rotation);
|
||||||
next.block().handleItem(Item.getByID(packet.itemid), next, tile);
|
tile.entity.items[packet.itemid]--;
|
||||||
|
next.block().handleItem(Item.getByID(packet.itemid), next, tile);
|
||||||
|
};
|
||||||
|
|
||||||
|
if(threads.isEnabled()){
|
||||||
|
threads.run(r);
|
||||||
|
}else{
|
||||||
|
r.run();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package io.anuke.mindustry.core;
|
package io.anuke.mindustry.core;
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.utils.Array;
|
||||||
import com.badlogic.gdx.utils.TimeUtils;
|
import com.badlogic.gdx.utils.TimeUtils;
|
||||||
import io.anuke.ucore.core.Timers;
|
import io.anuke.ucore.core.Timers;
|
||||||
import io.anuke.ucore.util.Log;
|
import io.anuke.ucore.util.Log;
|
||||||
@@ -8,6 +9,7 @@ import io.anuke.ucore.util.Log;
|
|||||||
import static io.anuke.mindustry.Vars.logic;
|
import static io.anuke.mindustry.Vars.logic;
|
||||||
|
|
||||||
public class ThreadHandler {
|
public class ThreadHandler {
|
||||||
|
private final Array<Runnable> toRun = new Array<>();
|
||||||
private final ThreadProvider impl;
|
private final ThreadProvider impl;
|
||||||
private float delta = 1f;
|
private float delta = 1f;
|
||||||
private long frame = 0;
|
private long frame = 0;
|
||||||
@@ -23,6 +25,12 @@ public class ThreadHandler {
|
|||||||
Timers.setDeltaProvider(() -> impl.isOnThread() ? delta : Gdx.graphics.getDeltaTime()*60f);
|
Timers.setDeltaProvider(() -> impl.isOnThread() ? delta : Gdx.graphics.getDeltaTime()*60f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void run(Runnable r){
|
||||||
|
synchronized (toRun) {
|
||||||
|
toRun.add(r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int getFPS(){
|
public int getFPS(){
|
||||||
return (int)(60/delta);
|
return (int)(60/delta);
|
||||||
}
|
}
|
||||||
@@ -70,6 +78,14 @@ public class ThreadHandler {
|
|||||||
try {
|
try {
|
||||||
while (true) {
|
while (true) {
|
||||||
long time = TimeUtils.millis();
|
long time = TimeUtils.millis();
|
||||||
|
|
||||||
|
synchronized (toRun) {
|
||||||
|
for(Runnable r : toRun){
|
||||||
|
r.run();
|
||||||
|
}
|
||||||
|
toRun.clear();
|
||||||
|
}
|
||||||
|
|
||||||
logic.update();
|
logic.update();
|
||||||
|
|
||||||
long elapsed = TimeUtils.timeSinceMillis(time);
|
long elapsed = TimeUtils.timeSinceMillis(time);
|
||||||
|
|||||||
@@ -255,10 +255,13 @@ public class Player extends SyncEntity{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(ByteBuffer data) {
|
public void write(ByteBuffer data) {
|
||||||
//TODO written angle is always 0
|
if(Net.client()) {
|
||||||
|
data.putFloat(x);
|
||||||
data.putFloat(x);
|
data.putFloat(y);
|
||||||
data.putFloat(y);
|
}else{
|
||||||
|
data.putFloat(interpolator.target.x);
|
||||||
|
data.putFloat(interpolator.target.y);
|
||||||
|
}
|
||||||
data.putFloat(angle);
|
data.putFloat(angle);
|
||||||
data.putShort((short)health);
|
data.putShort((short)health);
|
||||||
data.put((byte)(dashing ? 1 : 0));
|
data.put((byte)(dashing ? 1 : 0));
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import com.badlogic.gdx.utils.ObjectMap;
|
|||||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||||
import io.anuke.mindustry.io.Platform;
|
import io.anuke.mindustry.io.Platform;
|
||||||
import io.anuke.mindustry.net.Packet.ImportantPacket;
|
import io.anuke.mindustry.net.Packet.ImportantPacket;
|
||||||
|
import io.anuke.mindustry.net.Packet.UnimportantPacket;
|
||||||
import io.anuke.mindustry.net.Packets.KickReason;
|
import io.anuke.mindustry.net.Packets.KickReason;
|
||||||
import io.anuke.mindustry.net.Streamable.StreamBegin;
|
import io.anuke.mindustry.net.Streamable.StreamBegin;
|
||||||
import io.anuke.mindustry.net.Streamable.StreamBuilder;
|
import io.anuke.mindustry.net.Streamable.StreamBuilder;
|
||||||
@@ -189,7 +190,7 @@ public class Net{
|
|||||||
if(clientLoaded || object instanceof ImportantPacket){
|
if(clientLoaded || object instanceof ImportantPacket){
|
||||||
if(clientListeners.get(object.getClass()) != null) clientListeners.get(object.getClass()).accept(object);
|
if(clientListeners.get(object.getClass()) != null) clientListeners.get(object.getClass()).accept(object);
|
||||||
if(listeners.get(object.getClass()) != null) listeners.get(object.getClass()).accept(object);
|
if(listeners.get(object.getClass()) != null) listeners.get(object.getClass()).accept(object);
|
||||||
}else{
|
}else if(!(object instanceof UnimportantPacket)){
|
||||||
packetQueue.add(object);
|
packetQueue.add(object);
|
||||||
Log.info("Queuing packet {0}.", ClassReflection.getSimpleName(object.getClass()));
|
Log.info("Queuing packet {0}.", ClassReflection.getSimpleName(object.getClass()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,4 +7,5 @@ public interface Packet {
|
|||||||
void write(ByteBuffer buffer);
|
void write(ByteBuffer buffer);
|
||||||
|
|
||||||
interface ImportantPacket{}
|
interface ImportantPacket{}
|
||||||
|
interface UnimportantPacket{}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import io.anuke.mindustry.entities.Player;
|
|||||||
import io.anuke.mindustry.entities.SyncEntity;
|
import io.anuke.mindustry.entities.SyncEntity;
|
||||||
import io.anuke.mindustry.io.Version;
|
import io.anuke.mindustry.io.Version;
|
||||||
import io.anuke.mindustry.net.Packet.ImportantPacket;
|
import io.anuke.mindustry.net.Packet.ImportantPacket;
|
||||||
|
import io.anuke.mindustry.net.Packet.UnimportantPacket;
|
||||||
import io.anuke.mindustry.resource.Item;
|
import io.anuke.mindustry.resource.Item;
|
||||||
import io.anuke.ucore.entities.Entities;
|
import io.anuke.ucore.entities.Entities;
|
||||||
import io.anuke.ucore.entities.EntityGroup;
|
import io.anuke.ucore.entities.EntityGroup;
|
||||||
@@ -502,7 +503,7 @@ public class Packets {
|
|||||||
public void read(ByteBuffer buffer) { }
|
public void read(ByteBuffer buffer) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ItemTransferPacket implements Packet{
|
public static class ItemTransferPacket implements Packet, UnimportantPacket{
|
||||||
public int position;
|
public int position;
|
||||||
public byte rotation;
|
public byte rotation;
|
||||||
public byte itemid;
|
public byte itemid;
|
||||||
|
|||||||
Reference in New Issue
Block a user