Merge branches 'master' and 'mnet' of https://github.com/Anuken/Mindustry

This commit is contained in:
Anuken
2019-08-23 14:29:53 -04:00
15 changed files with 399 additions and 70 deletions

View File

@@ -67,6 +67,6 @@ public class Mindustry extends ApplicationCore{
super.init();
Log.info("Time to load [total]: {0}", Time.elapsed());
Events.fire(new GameLoadEvent());
Events.fire(new ClientLoadEvent());
}
}

View File

@@ -1,7 +1,7 @@
package io.anuke.mindustry;
import io.anuke.arc.*;
import io.anuke.arc.Application.ApplicationType;
import io.anuke.arc.Core;
import io.anuke.arc.files.FileHandle;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.util.Structs;
@@ -15,6 +15,7 @@ import io.anuke.mindustry.entities.traits.DrawTrait;
import io.anuke.mindustry.entities.traits.SyncTrait;
import io.anuke.mindustry.entities.type.*;
import io.anuke.mindustry.game.*;
import io.anuke.mindustry.game.EventType.*;
import io.anuke.mindustry.gen.Serialization;
import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.world.blocks.defense.ForceProjector.ShieldEntity;
@@ -222,5 +223,7 @@ public class Vars{
customMapDirectory = dataDirectory.child("maps/");
saveDirectory = dataDirectory.child("saves/");
tmpDirectory = dataDirectory.child("tmp/");
Events.fire(new AppLoadEvent());
}
}

View File

@@ -27,8 +27,13 @@ public class EventType{
}
}
/** Called when the game is first loaded. */
public static class GameLoadEvent{
/** Called when the client game is first loaded. */
public static class ClientLoadEvent{
}
/** Called when the core app is first loaded. */
public static class AppLoadEvent{
}

View File

@@ -1,19 +1,18 @@
package io.anuke.mindustry.net;
import io.anuke.arc.Core;
import io.anuke.arc.*;
import io.anuke.arc.collection.*;
import io.anuke.arc.function.BiConsumer;
import io.anuke.arc.function.Consumer;
import io.anuke.arc.function.*;
import io.anuke.arc.util.*;
import io.anuke.arc.util.pooling.Pools;
import io.anuke.mindustry.core.Platform;
import io.anuke.mindustry.gen.Call;
import io.anuke.arc.util.pooling.*;
import io.anuke.mindustry.core.*;
import io.anuke.mindustry.gen.*;
import io.anuke.mindustry.net.Packets.*;
import io.anuke.mindustry.net.Streamable.StreamBuilder;
import io.anuke.mindustry.net.Streamable.*;
import net.jpountz.lz4.*;
import java.io.IOException;
import java.nio.BufferOverflowException;
import java.nio.BufferUnderflowException;
import java.io.*;
import java.nio.*;
import static io.anuke.mindustry.Vars.*;
@@ -28,6 +27,8 @@ public class Net{
private static ClientProvider clientProvider;
private static ServerProvider serverProvider;
private static IntMap<StreamBuilder> streams = new IntMap<>();
private static final LZ4FastDecompressor decompressor = LZ4Factory.fastestInstance().fastDecompressor();
private static final LZ4Compressor compressor = LZ4Factory.fastestInstance().fastCompressor();
/** Display a network error. Call on the graphics thread. */
public static void showError(Throwable e){
@@ -144,11 +145,11 @@ public class Net{
}
public static byte[] compressSnapshot(byte[] input){
return serverProvider.compressSnapshot(input);
return compressor.compress(input);
}
public static byte[] decompressSnapshot(byte[] input, int size){
return clientProvider.decompressSnapshot(input, size);
return decompressor.decompress(input, size);
}
/**
@@ -354,9 +355,6 @@ public class Net{
/** Disconnect from the server. */
void disconnect();
/** Decompress an input snapshot byte array. */
byte[] decompressSnapshot(byte[] input, int size);
/**
* Discover servers. This should run the callback regardless of whether any servers are found. Should not block.
* Callback should be run on libGDX main thread.
@@ -428,9 +426,6 @@ public class Net{
/** Close the server connection. */
void close();
/** Compress an input snapshot byte array. */
byte[] compressSnapshot(byte[] input);
/** Return all connected users. */
Iterable<? extends NetConnection> getConnections();