mirror of
https://github.com/Anuken/Mindustry.git
synced 2026-01-28 07:22:21 -08:00
Steam cleanup
This commit is contained in:
parent
7aafa8b150
commit
4e2d2ee378
5 changed files with 42 additions and 42 deletions
|
|
@ -10,8 +10,7 @@ import io.anuke.mindustry.net.Net;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import static io.anuke.mindustry.Vars.player;
|
||||
import static io.anuke.mindustry.Vars.ui;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class HostDialog extends FloatingDialog{
|
||||
float w = 300;
|
||||
|
|
@ -50,23 +49,29 @@ public class HostDialog extends FloatingDialog{
|
|||
return;
|
||||
}
|
||||
|
||||
ui.loadfrag.show("$hosting");
|
||||
Time.runTask(5f, () -> {
|
||||
try{
|
||||
Net.host(Vars.port);
|
||||
player.isAdmin = true;
|
||||
}catch(IOException e){
|
||||
ui.showError(Core.bundle.format("server.error", Strings.parseException(e, true)));
|
||||
}
|
||||
ui.loadfrag.hide();
|
||||
hide();
|
||||
});
|
||||
runHost();
|
||||
}).width(w).height(70f);
|
||||
|
||||
cont.addButton("?", () -> ui.showInfo("$host.info")).size(65f, 70f).padLeft(6f);
|
||||
|
||||
shown(() -> {
|
||||
Core.app.post(() -> Core.settings.getBoolOnce("hostinfo", () -> ui.showInfo("$host.info")));
|
||||
if(!steam){
|
||||
Core.app.post(() -> Core.settings.getBoolOnce("hostinfo", () -> ui.showInfo("$host.info")));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void runHost(){
|
||||
ui.loadfrag.show("$hosting");
|
||||
Time.runTask(5f, () -> {
|
||||
try{
|
||||
Net.host(Vars.port);
|
||||
player.isAdmin = true;
|
||||
}catch(IOException e){
|
||||
ui.showError(Core.bundle.format("server.error", Strings.parseException(e, true)));
|
||||
}
|
||||
ui.loadfrag.hide();
|
||||
hide();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,7 +57,13 @@ public class PausedDialog extends FloatingDialog{
|
|||
|
||||
cont.row();
|
||||
|
||||
cont.addButton("$hostserver", ui.host::show).disabled(b -> Net.active()).colspan(2).width(dw * 2 + 20f);
|
||||
cont.addButton("$hostserver", () -> {
|
||||
if(steam){
|
||||
ui.host.runHost();
|
||||
}else{
|
||||
ui.host.show();
|
||||
}
|
||||
}).disabled(b -> Net.active()).colspan(2).width(dw * 2 + 20f);
|
||||
}
|
||||
|
||||
cont.row();
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public class DesktopLauncher{
|
|||
Platform.instance = new DesktopPlatform(arg);
|
||||
|
||||
if(SteamAPI.isSteamRunning()){
|
||||
SteamNetImpl net = new SteamNetImpl();
|
||||
SteamCoreNetImpl net = DesktopPlatform.steamCore = new SteamCoreNetImpl();
|
||||
Net.setClientProvider(net);
|
||||
Net.setServerProvider(net);
|
||||
}else{
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import io.anuke.arc.util.serialization.*;
|
|||
import io.anuke.mindustry.*;
|
||||
import io.anuke.mindustry.core.GameState.*;
|
||||
import io.anuke.mindustry.core.*;
|
||||
import io.anuke.mindustry.desktop.steam.*;
|
||||
import io.anuke.mindustry.game.EventType.*;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.*;
|
||||
|
|
@ -27,7 +28,8 @@ import static io.anuke.mindustry.Vars.*;
|
|||
|
||||
|
||||
public class DesktopPlatform extends Platform{
|
||||
static boolean useDiscord = OS.is64Bit, useSteam = true, showConsole = false;
|
||||
static boolean useDiscord = OS.is64Bit, useSteam = true, showConsole = true;
|
||||
static SteamCoreNetImpl steamCore;
|
||||
final static String applicationId = "610508934456934412";
|
||||
String[] args;
|
||||
|
||||
|
|
@ -50,8 +52,9 @@ public class DesktopPlatform extends Platform{
|
|||
}
|
||||
|
||||
if(useSteam){
|
||||
|
||||
if(showConsole){
|
||||
Events.on(GameLoadEvent.class, event -> {
|
||||
Events.on(ClientLoadEvent.class, event -> {
|
||||
Label[] label = {null};
|
||||
Core.scene.table(t -> {
|
||||
t.touchable(Touchable.disabled);
|
||||
|
|
@ -79,15 +82,15 @@ public class DesktopPlatform extends Platform{
|
|||
});
|
||||
}
|
||||
|
||||
Vars.steam = true;
|
||||
try{
|
||||
SteamAPI.loadLibraries();
|
||||
if(!SteamAPI.init()){
|
||||
Log.info("Steam client not running. Make sure Steam is running!");
|
||||
}else{
|
||||
|
||||
Vars.steam = true;
|
||||
//run steam callbacks
|
||||
Events.on(GameLoadEvent.class, event -> {
|
||||
Events.on(ClientLoadEvent.class, event -> {
|
||||
Core.settings.defaults("name", steamCore.friends.getPersonaName());
|
||||
//update callbacks
|
||||
Core.app.addListener(new ApplicationListener(){
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import io.anuke.mindustry.net.Net;
|
|||
import io.anuke.mindustry.net.*;
|
||||
import io.anuke.mindustry.net.Net.*;
|
||||
import io.anuke.mindustry.net.Packets.*;
|
||||
import net.jpountz.lz4.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.*;
|
||||
|
|
@ -23,16 +22,14 @@ import java.util.concurrent.*;
|
|||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class SteamNetImpl implements SteamNetworkingCallback, SteamMatchmakingCallback, SteamFriendsCallback, ClientProvider, ServerProvider{
|
||||
final SteamNetworking snet = new SteamNetworking(this);
|
||||
final SteamMatchmaking smat = new SteamMatchmaking(this);
|
||||
final SteamFriends friends = new SteamFriends(this);
|
||||
public class SteamCoreNetImpl implements SteamNetworkingCallback, SteamMatchmakingCallback, SteamFriendsCallback, ClientProvider, ServerProvider{
|
||||
public final SteamNetworking snet = new SteamNetworking(this);
|
||||
public final SteamMatchmaking smat = new SteamMatchmaking(this);
|
||||
public final SteamFriends friends = new SteamFriends(this);
|
||||
|
||||
final PacketSerializer serializer = new PacketSerializer();
|
||||
final ByteBuffer writeBuffer = ByteBuffer.allocateDirect(1024 * 4);
|
||||
final ByteBuffer readBuffer = ByteBuffer.allocateDirect(1024 * 4);
|
||||
final LZ4FastDecompressor decompressor = LZ4Factory.fastestInstance().fastDecompressor();
|
||||
final LZ4Compressor compressor = LZ4Factory.fastestInstance().fastCompressor();
|
||||
|
||||
final CopyOnWriteArrayList<SteamConnection> connections = new CopyOnWriteArrayList<>();
|
||||
final IntMap<SteamConnection> steamConnections = new IntMap<>(); //maps steam ID -> valid net connection
|
||||
|
|
@ -42,8 +39,8 @@ public class SteamNetImpl implements SteamNetworkingCallback, SteamMatchmakingCa
|
|||
Consumer<Host> lobbyCallback;
|
||||
Runnable lobbyDoneCallback, joinCallback;
|
||||
|
||||
public SteamNetImpl(){
|
||||
Events.on(GameLoadEvent.class, e -> Core.app.addListener(new ApplicationListener(){
|
||||
public SteamCoreNetImpl(){
|
||||
Events.on(ClientLoadEvent.class, e -> Core.app.addListener(new ApplicationListener(){
|
||||
//read packets
|
||||
int length;
|
||||
SteamID from = new SteamID();
|
||||
|
|
@ -135,11 +132,6 @@ public class SteamNetImpl implements SteamNetworkingCallback, SteamMatchmakingCa
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] decompressSnapshot(byte[] input, int size){
|
||||
return decompressor.decompress(input, size);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void discover(Consumer<Host> callback, Runnable done){
|
||||
smat.addRequestLobbyListResultCountFilter(32);
|
||||
|
|
@ -171,11 +163,6 @@ public class SteamNetImpl implements SteamNetworkingCallback, SteamMatchmakingCa
|
|||
steamConnections.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] compressSnapshot(byte[] input){
|
||||
return compressor.compress(input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<? extends NetConnection> getConnections(){
|
||||
return connections;
|
||||
|
|
@ -443,13 +430,12 @@ public class SteamNetImpl implements SteamNetworkingCallback, SteamMatchmakingCa
|
|||
@Override
|
||||
public boolean isConnected(){
|
||||
snet.getP2PSessionState(sid, state);
|
||||
return state.isConnectionActive() || state.isConnecting();
|
||||
return state.isConnectionActive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close(){
|
||||
snet.closeP2PSessionWithUser(sid);
|
||||
//smat.
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue