mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-12 03:37:27 +07:00
Formatting / Removed mobile map screenshots due to crashes
This commit is contained in:
parent
b24770629e
commit
94665e8055
@ -375,7 +375,7 @@ public class Control extends Module{
|
||||
}
|
||||
}
|
||||
|
||||
if(Inputs.keyTap("screenshot") && !ui.chatfrag.chatOpen()){
|
||||
if(!mobile && Inputs.keyTap("screenshot") && !ui.chatfrag.chatOpen()){
|
||||
renderer.takeMapScreenshot();
|
||||
}
|
||||
|
||||
|
@ -165,26 +165,17 @@ public class Saves{
|
||||
|
||||
public void save(){
|
||||
long time = totalPlaytime;
|
||||
renderer.fog.writeFog();
|
||||
long prev = totalPlaytime;
|
||||
totalPlaytime = time;
|
||||
|
||||
threads.runGraphics(() -> {
|
||||
//Renderer fog needs to be written on graphics thread, but save() can run on logic thread
|
||||
//thus, runGraphics is required here
|
||||
renderer.fog.writeFog();
|
||||
SaveIO.saveToSlot(index);
|
||||
meta = SaveIO.getData(index);
|
||||
if(!state.is(State.menu)){
|
||||
current = this;
|
||||
}
|
||||
|
||||
//save on the logic thread
|
||||
threads.run(() -> {
|
||||
long prev = totalPlaytime;
|
||||
totalPlaytime = time;
|
||||
|
||||
SaveIO.saveToSlot(index);
|
||||
meta = SaveIO.getData(index);
|
||||
if(!state.is(State.menu)){
|
||||
current = this;
|
||||
}
|
||||
|
||||
totalPlaytime = prev;
|
||||
});
|
||||
});
|
||||
totalPlaytime = prev;
|
||||
}
|
||||
|
||||
public boolean isHidden(){
|
||||
|
@ -1,4 +1,4 @@
|
||||
apply plugin: "java"
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
sourceSets.main.java.srcDirs = [ "src/" ]
|
||||
sourceSets.main.java.srcDirs = ["src/"]
|
||||
|
@ -10,18 +10,18 @@ import io.anuke.ucore.util.Pooling;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class ByteSerializer implements Serialization {
|
||||
public class ByteSerializer implements Serialization{
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer byteBuffer, Object o) {
|
||||
public void write(ByteBuffer byteBuffer, Object o){
|
||||
if(o instanceof FrameworkMessage){
|
||||
byteBuffer.put((byte)-2); //code for framework message
|
||||
FrameworkSerializer.write(byteBuffer, (FrameworkMessage)o);
|
||||
}else {
|
||||
if (!(o instanceof Packet))
|
||||
byteBuffer.put((byte) -2); //code for framework message
|
||||
FrameworkSerializer.write(byteBuffer, (FrameworkMessage) o);
|
||||
}else{
|
||||
if(!(o instanceof Packet))
|
||||
throw new RuntimeException("All sent objects must implement be Packets! Class: " + o.getClass());
|
||||
byte id = Registrator.getID(o.getClass());
|
||||
if (id == -1)
|
||||
if(id == -1)
|
||||
throw new RuntimeException("Unregistered class: " + o.getClass());
|
||||
byteBuffer.put(id);
|
||||
((Packet) o).write(byteBuffer);
|
||||
@ -29,10 +29,10 @@ public class ByteSerializer implements Serialization {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object read(ByteBuffer byteBuffer) {
|
||||
public Object read(ByteBuffer byteBuffer){
|
||||
byte id = byteBuffer.get();
|
||||
if(id == -2){
|
||||
return FrameworkSerializer.read(byteBuffer);
|
||||
return FrameworkSerializer.read(byteBuffer);
|
||||
}else{
|
||||
Packet packet = Pooling.obtain((Class<Packet>) Registrator.getByID(id).type, (Supplier<Packet>) Registrator.getByID(id).constructor);
|
||||
packet.read(byteBuffer);
|
||||
@ -41,17 +41,17 @@ public class ByteSerializer implements Serialization {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLengthLength() {
|
||||
public int getLengthLength(){
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeLength(ByteBuffer byteBuffer, int i) {
|
||||
byteBuffer.putShort((short)i);
|
||||
public void writeLength(ByteBuffer byteBuffer, int i){
|
||||
byteBuffer.putShort((short) i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readLength(ByteBuffer byteBuffer) {
|
||||
public int readLength(ByteBuffer byteBuffer){
|
||||
return byteBuffer.getShort();
|
||||
}
|
||||
}
|
||||
|
@ -5,32 +5,32 @@ import com.esotericsoftware.kryonet.FrameworkMessage.*;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class FrameworkSerializer {
|
||||
public class FrameworkSerializer{
|
||||
|
||||
public static void write(ByteBuffer buffer, FrameworkMessage message){
|
||||
if(message instanceof Ping){
|
||||
Ping p = (Ping)message;
|
||||
Ping p = (Ping) message;
|
||||
|
||||
buffer.put((byte)0);
|
||||
buffer.put((byte) 0);
|
||||
buffer.putInt(p.id);
|
||||
buffer.put(p.isReply ? 1 : (byte)0);
|
||||
buffer.put(p.isReply ? 1 : (byte) 0);
|
||||
}else if(message instanceof DiscoverHost){
|
||||
DiscoverHost p = (DiscoverHost)message;
|
||||
DiscoverHost p = (DiscoverHost) message;
|
||||
|
||||
buffer.put((byte)1);
|
||||
buffer.put((byte) 1);
|
||||
}else if(message instanceof KeepAlive){
|
||||
KeepAlive p = (KeepAlive)message;
|
||||
KeepAlive p = (KeepAlive) message;
|
||||
|
||||
buffer.put((byte)2);
|
||||
buffer.put((byte) 2);
|
||||
}else if(message instanceof RegisterUDP){
|
||||
RegisterUDP p = (RegisterUDP)message;
|
||||
RegisterUDP p = (RegisterUDP) message;
|
||||
|
||||
buffer.put((byte)3);
|
||||
buffer.put((byte) 3);
|
||||
buffer.putInt(p.connectionID);
|
||||
}else if(message instanceof RegisterTCP){
|
||||
RegisterTCP p = (RegisterTCP)message;
|
||||
RegisterTCP p = (RegisterTCP) message;
|
||||
|
||||
buffer.put((byte)4);
|
||||
buffer.put((byte) 4);
|
||||
buffer.putInt(p.connectionID);
|
||||
}
|
||||
}
|
||||
|
@ -35,14 +35,14 @@ public class KryoClient implements ClientProvider{
|
||||
public KryoClient(){
|
||||
KryoCore.init();
|
||||
|
||||
handler = new ClientDiscoveryHandler() {
|
||||
handler = new ClientDiscoveryHandler(){
|
||||
@Override
|
||||
public DatagramPacket onRequestNewDatagramPacket() {
|
||||
public DatagramPacket onRequestNewDatagramPacket(){
|
||||
return new DatagramPacket(new byte[128], 128);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDiscoveredHost(DatagramPacket datagramPacket) {
|
||||
public void onDiscoveredHost(DatagramPacket datagramPacket){
|
||||
ByteBuffer buffer = ByteBuffer.wrap(datagramPacket.getData());
|
||||
Host host = NetworkIO.readServerData(datagramPacket.getAddress().getHostAddress(), buffer);
|
||||
for(InetAddress address : foundAddresses){
|
||||
@ -55,7 +55,7 @@ public class KryoClient implements ClientProvider{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinally() {
|
||||
public void onFinally(){
|
||||
|
||||
}
|
||||
};
|
||||
@ -65,7 +65,7 @@ public class KryoClient implements ClientProvider{
|
||||
|
||||
Listener listener = new Listener(){
|
||||
@Override
|
||||
public void connected (Connection connection) {
|
||||
public void connected(Connection connection){
|
||||
Connect c = new Connect();
|
||||
c.addressTCP = connection.getRemoteAddressTCP().getAddress().getHostAddress();
|
||||
c.id = connection.getID();
|
||||
@ -75,7 +75,7 @@ public class KryoClient implements ClientProvider{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnected (Connection connection) {
|
||||
public void disconnected(Connection connection){
|
||||
if(connection.getLastProtocolError() != null){
|
||||
netClient.setQuiet();
|
||||
}
|
||||
@ -85,13 +85,13 @@ public class KryoClient implements ClientProvider{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received (Connection connection, Object object) {
|
||||
public void received(Connection connection, Object object){
|
||||
if(object instanceof FrameworkMessage) return;
|
||||
|
||||
threads.runDelay(() -> {
|
||||
try{
|
||||
Net.handleClientReceived(object);
|
||||
}catch (Exception e){
|
||||
}catch(Exception e){
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
@ -106,12 +106,12 @@ public class KryoClient implements ClientProvider{
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isLocal(InetAddress addr) {
|
||||
if (addr.isAnyLocalAddress() || addr.isLoopbackAddress()) return true;
|
||||
private static boolean isLocal(InetAddress addr){
|
||||
if(addr.isAnyLocalAddress() || addr.isLoopbackAddress()) return true;
|
||||
|
||||
try {
|
||||
try{
|
||||
return NetworkInterface.getByInetAddress(addr) != null;
|
||||
} catch (Exception e) {
|
||||
}catch(Exception e){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -150,12 +150,12 @@ public class KryoClient implements ClientProvider{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect() {
|
||||
public void disconnect(){
|
||||
client.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Object object, SendMode mode) {
|
||||
public void send(Object object, SendMode mode){
|
||||
if(mode == SendMode.tcp){
|
||||
client.sendTCP(object);
|
||||
}else{
|
||||
@ -166,12 +166,12 @@ public class KryoClient implements ClientProvider{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePing() {
|
||||
public void updatePing(){
|
||||
client.updateReturnTripTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPing() {
|
||||
public int getPing(){
|
||||
return client.getReturnTripTime();
|
||||
}
|
||||
|
||||
@ -218,7 +218,7 @@ public class KryoClient implements ClientProvider{
|
||||
public void dispose(){
|
||||
try{
|
||||
client.dispose();
|
||||
}catch (IOException e){
|
||||
}catch(IOException e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
@ -10,8 +10,8 @@ import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
import static io.anuke.mindustry.Vars.headless;
|
||||
|
||||
/**Utilities and configs for kryo module.*/
|
||||
public class KryoCore {
|
||||
/** Utilities and configs for kryo module. */
|
||||
public class KryoCore{
|
||||
public static boolean fakeLag = false;
|
||||
public static final int fakeLagMax = 500;
|
||||
public static final int fakeLagMin = 0;
|
||||
@ -26,7 +26,7 @@ public class KryoCore {
|
||||
Log.set(fakeLag ? Log.LEVEL_DEBUG : Log.LEVEL_WARN);
|
||||
|
||||
Log.setLogger(new Logger(){
|
||||
public void log (int level, String category, String message, Throwable ex) {
|
||||
public void log(int level, String category, String message, Throwable ex){
|
||||
if(fakeLag){
|
||||
if(message.contains("UDP")){
|
||||
lastUDP = true;
|
||||
@ -45,7 +45,7 @@ public class KryoCore {
|
||||
|
||||
builder.append(message);
|
||||
|
||||
if (ex != null) {
|
||||
if(ex != null){
|
||||
StringWriter writer = new StringWriter(256);
|
||||
ex.printStackTrace(new PrintWriter(writer));
|
||||
builder.append('\n');
|
||||
@ -60,7 +60,7 @@ public class KryoCore {
|
||||
});
|
||||
}
|
||||
|
||||
private static int calculateLag() {
|
||||
return fakeLagMin + (int)(Math.random() * (fakeLagMax - fakeLagMin));
|
||||
private static int calculateLag(){
|
||||
return fakeLagMin + (int) (Math.random() * (fakeLagMax - fakeLagMin));
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
import static io.anuke.mindustry.Vars.threads;
|
||||
|
||||
public class KryoServer implements ServerProvider {
|
||||
public class KryoServer implements ServerProvider{
|
||||
final Server server;
|
||||
final CopyOnWriteArrayList<KryoConnection> connections = new CopyOnWriteArrayList<>();
|
||||
final CopyOnWriteArraySet<Integer> missing = new CopyOnWriteArraySet<>();
|
||||
@ -42,7 +42,7 @@ public class KryoServer implements ServerProvider {
|
||||
public KryoServer(){
|
||||
KryoCore.init();
|
||||
|
||||
server = new Server(4096*2, 4096, connection -> new ByteSerializer());
|
||||
server = new Server(4096 * 2, 4096, connection -> new ByteSerializer());
|
||||
server.setDiscoveryHandler((datagramChannel, fromAddress) -> {
|
||||
ByteBuffer buffer = NetworkIO.writeServerData();
|
||||
buffer.position(0);
|
||||
@ -53,10 +53,10 @@ public class KryoServer implements ServerProvider {
|
||||
Listener listener = new Listener(){
|
||||
|
||||
@Override
|
||||
public void connected (Connection connection) {
|
||||
public void connected(Connection connection){
|
||||
String ip = connection.getRemoteAddressTCP().getAddress().getHostAddress();
|
||||
|
||||
KryoConnection kn = new KryoConnection(lastconnection ++, ip, connection);
|
||||
KryoConnection kn = new KryoConnection(lastconnection++, ip, connection);
|
||||
|
||||
Connect c = new Connect();
|
||||
c.id = kn.id;
|
||||
@ -69,7 +69,7 @@ public class KryoServer implements ServerProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnected (Connection connection) {
|
||||
public void disconnected(Connection connection){
|
||||
KryoConnection k = getByKryoID(connection.getID());
|
||||
if(k == null) return;
|
||||
|
||||
@ -83,14 +83,14 @@ public class KryoServer implements ServerProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received (Connection connection, Object object) {
|
||||
public void received(Connection connection, Object object){
|
||||
KryoConnection k = getByKryoID(connection.getID());
|
||||
if(object instanceof FrameworkMessage || k == null) return;
|
||||
|
||||
threads.runDelay(() -> {
|
||||
try{
|
||||
Net.handleServerReceived(k.id, object);
|
||||
}catch (Exception e){
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
@ -110,7 +110,7 @@ public class KryoServer implements ServerProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Array<KryoConnection> getConnections() {
|
||||
public Array<KryoConnection> getConnections(){
|
||||
array.clear();
|
||||
for(KryoConnection c : connections){
|
||||
array.add(c);
|
||||
@ -120,7 +120,7 @@ public class KryoServer implements ServerProvider {
|
||||
|
||||
@Override
|
||||
public KryoConnection getByID(int id){
|
||||
for(int i = 0; i < connections.size(); i ++){
|
||||
for(int i = 0; i < connections.size(); i++){
|
||||
KryoConnection con = connections.get(i);
|
||||
if(con.id == id){
|
||||
return con;
|
||||
@ -131,7 +131,7 @@ public class KryoServer implements ServerProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void host(int port) throws IOException {
|
||||
public void host(int port) throws IOException{
|
||||
//attempt to open default ports if they're not already open
|
||||
//this only opens the default port due to security concerns (?)
|
||||
if(port == Vars.port){
|
||||
@ -139,7 +139,8 @@ public class KryoServer implements ServerProvider {
|
||||
try{
|
||||
if(!UPnP.isMappedTCP(port)) UPnP.openPortTCP(port);
|
||||
if(!UPnP.isMappedUDP(port)) UPnP.openPortUDP(port);
|
||||
}catch(Throwable ignored){}
|
||||
}catch(Throwable ignored){
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -151,7 +152,7 @@ public class KryoServer implements ServerProvider {
|
||||
serverThread = new Thread(() -> {
|
||||
try{
|
||||
server.run();
|
||||
}catch (Throwable e){
|
||||
}catch(Throwable e){
|
||||
if(!(e instanceof ClosedSelectorException)) handleException(e);
|
||||
}
|
||||
}, "Kryonet Server");
|
||||
@ -160,7 +161,7 @@ public class KryoServer implements ServerProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
public void close(){
|
||||
connections.clear();
|
||||
lastconnection = 0;
|
||||
|
||||
@ -168,17 +169,17 @@ public class KryoServer implements ServerProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendStream(int id, Streamable stream) {
|
||||
public void sendStream(int id, Streamable stream){
|
||||
KryoConnection connection = getByID(id);
|
||||
if(connection == null) return;
|
||||
try {
|
||||
try{
|
||||
|
||||
if (connection.connection != null) {
|
||||
if(connection.connection != null){
|
||||
|
||||
connection.connection.addListener(new InputStreamSender(stream.stream, 512) {
|
||||
connection.connection.addListener(new InputStreamSender(stream.stream, 512){
|
||||
int id;
|
||||
|
||||
protected void start() {
|
||||
protected void start(){
|
||||
//send an object so the receiving side knows how to handle the following chunks
|
||||
StreamBegin begin = new StreamBegin();
|
||||
begin.total = stream.stream.available();
|
||||
@ -187,14 +188,14 @@ public class KryoServer implements ServerProvider {
|
||||
id = begin.id;
|
||||
}
|
||||
|
||||
protected Object next(byte[] bytes) {
|
||||
protected Object next(byte[] bytes){
|
||||
StreamChunk chunk = new StreamChunk();
|
||||
chunk.id = id;
|
||||
chunk.data = bytes;
|
||||
return chunk; //wrap the byte[] with an object so the receiving side knows how to handle it.
|
||||
}
|
||||
});
|
||||
} else {
|
||||
}else{
|
||||
int cid;
|
||||
StreamBegin begin = new StreamBegin();
|
||||
begin.total = stream.stream.available();
|
||||
@ -202,7 +203,7 @@ public class KryoServer implements ServerProvider {
|
||||
connection.send(begin, SendMode.tcp);
|
||||
cid = begin.id;
|
||||
|
||||
while (stream.stream.available() > 0) {
|
||||
while(stream.stream.available() > 0){
|
||||
byte[] bytes = new byte[Math.min(512, stream.stream.available())];
|
||||
stream.stream.read(bytes);
|
||||
|
||||
@ -212,20 +213,20 @@ public class KryoServer implements ServerProvider {
|
||||
connection.send(chunk, SendMode.tcp);
|
||||
}
|
||||
}
|
||||
}catch (IOException e){
|
||||
}catch(IOException e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Object object, SendMode mode) {
|
||||
for(int i = 0; i < connections.size(); i ++){
|
||||
public void send(Object object, SendMode mode){
|
||||
for(int i = 0; i < connections.size(); i++){
|
||||
connections.get(i).send(object, mode);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTo(int id, Object object, SendMode mode) {
|
||||
public void sendTo(int id, Object object, SendMode mode){
|
||||
NetConnection conn = getByID(id);
|
||||
if(conn == null){
|
||||
if(!missing.contains(id))
|
||||
@ -237,8 +238,8 @@ public class KryoServer implements ServerProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendExcept(int id, Object object, SendMode mode) {
|
||||
for(int i = 0; i < connections.size(); i ++){
|
||||
public void sendExcept(int id, Object object, SendMode mode){
|
||||
for(int i = 0; i < connections.size(); i++){
|
||||
KryoConnection conn = connections.get(i);
|
||||
if(conn.id != id) conn.send(object, mode);
|
||||
}
|
||||
@ -251,11 +252,13 @@ public class KryoServer implements ServerProvider {
|
||||
}
|
||||
|
||||
private void handleException(Throwable e){
|
||||
Timers.run(0f, () -> { throw new RuntimeException(e);});
|
||||
Timers.run(0f, () -> {
|
||||
throw new RuntimeException(e);
|
||||
});
|
||||
}
|
||||
|
||||
KryoConnection getByKryoID(int id){
|
||||
for(int i = 0; i < connections.size(); i ++){
|
||||
for(int i = 0; i < connections.size(); i++){
|
||||
KryoConnection con = connections.get(i);
|
||||
if(con.connection != null && con.connection.getID() == id){
|
||||
return con;
|
||||
@ -274,7 +277,7 @@ public class KryoServer implements ServerProvider {
|
||||
class KryoConnection extends NetConnection{
|
||||
public final Connection connection;
|
||||
|
||||
public KryoConnection(int id, String address, Connection connection) {
|
||||
public KryoConnection(int id, String address, Connection connection){
|
||||
super(id, address);
|
||||
this.connection = connection;
|
||||
}
|
||||
@ -286,13 +289,13 @@ public class KryoServer implements ServerProvider {
|
||||
|
||||
@Override
|
||||
public void send(Object object, SendMode mode){
|
||||
try {
|
||||
if (mode == SendMode.tcp) {
|
||||
try{
|
||||
if(mode == SendMode.tcp){
|
||||
connection.sendTCP(object);
|
||||
} else {
|
||||
}else{
|
||||
connection.sendUDP(object);
|
||||
}
|
||||
}catch (Exception e){
|
||||
}catch(Exception e){
|
||||
Log.err(e);
|
||||
Log.info("Disconnecting invalid client!");
|
||||
connection.close();
|
||||
|
Loading…
Reference in New Issue
Block a user