diff --git a/build.gradle b/build.gradle index f051cf3437..67ab83782b 100644 --- a/build.gradle +++ b/build.gradle @@ -24,6 +24,7 @@ allprojects{ appName = 'Mindustry' gdxVersion = '1.9.10' roboVMVersion = '2.3.7' + steamworksVersion = '1.8.0' arcHash = null debugged = { @@ -171,6 +172,9 @@ project(":desktop-sdl"){ compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop" compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop" + compile "com.code-disaster.steamworks4j:steamworks4j:$steamworksVersion" + compile "com.code-disaster.steamworks4j:steamworks4j-server:$steamworksVersion" + compile arcModule("backends:backend-sdl") compile 'com.github.MinnDevelopment:java-discord-rpc:v2.0.2' } diff --git a/desktop-sdl/src/io/anuke/mindustry/desktopsdl/DesktopPlatform.java b/desktop-sdl/src/io/anuke/mindustry/desktopsdl/DesktopPlatform.java index 420ef0260c..83ccb90c4a 100644 --- a/desktop-sdl/src/io/anuke/mindustry/desktopsdl/DesktopPlatform.java +++ b/desktop-sdl/src/io/anuke/mindustry/desktopsdl/DesktopPlatform.java @@ -1,10 +1,12 @@ package io.anuke.mindustry.desktopsdl; import club.minnced.discord.rpc.*; -import io.anuke.arc.backends.sdl.jni.SDL; +import com.codedisaster.steamworks.*; +import io.anuke.arc.backends.sdl.jni.*; import io.anuke.arc.collection.*; import io.anuke.arc.files.*; import io.anuke.arc.function.*; +import io.anuke.arc.util.Timer; import io.anuke.arc.util.*; import io.anuke.arc.util.serialization.*; import io.anuke.mindustry.core.GameState.*; @@ -19,7 +21,7 @@ import static io.anuke.mindustry.Vars.*; public class DesktopPlatform extends Platform{ - static boolean useDiscord = OS.is64Bit; + static boolean useDiscord = OS.is64Bit, useSteam = true; final static String applicationId = "610508934456934412"; String[] args; @@ -39,6 +41,30 @@ public class DesktopPlatform extends Platform{ Log.err("Failed to initialize discord.", t); } } + + if(useSteam){ + try{ + SteamAPI.loadLibraries(); + if(!SteamAPI.init()){ + Log.info("Steam client not running."); + }else{ + //times per second + float interval = 20f; + //run steam callbacks + Timer.schedule(() -> { + if(SteamAPI.isSteamRunning()){ + SteamAPI.runCallbacks(); + } + }, 1 / interval, 1f / interval); + + //steam shutdown hook + Runtime.getRuntime().addShutdownHook(new Thread(SteamAPI::shutdown)); + } + }catch(Exception e){ + Log.err("Failed to load Steam native libraries."); + e.printStackTrace(); + } + } } static void handleCrash(Throwable e){ @@ -48,10 +74,10 @@ public class DesktopPlatform extends Platform{ if(e.getMessage() != null && (e.getMessage().contains("Couldn't create window") || e.getMessage().contains("OpenGL 2.0 or higher"))){ dialog.accept(() -> message( - e.getMessage().contains("Couldn't create window") ? "A graphics initialization error has occured! Try to update your graphics drivers:\n" + e.getMessage() : - "Your graphics card does not support OpenGL 2.0!\n" + - "Try to update your graphics drivers.\n\n" + - "(If that doesn't work, your computer just doesn't support Mindustry.)")); + e.getMessage().contains("Couldn't create window") ? "A graphics initialization error has occured! Try to update your graphics drivers:\n" + e.getMessage() : + "Your graphics card does not support OpenGL 2.0!\n" + + "Try to update your graphics drivers.\n\n" + + "(If that doesn't work, your computer just doesn't support Mindustry.)")); badGPU = true; } @@ -79,7 +105,7 @@ public class DesktopPlatform extends Platform{ if(!state.is(State.menu)){ String map = world.getMap() == null ? "Unknown Map" : world.isZone() ? world.getZone().localizedName : Strings.capitalize(world.getMap().name()); String mode = state.rules.pvp ? "PvP" : state.rules.attackMode ? "Attack" : "Survival"; - String players = Net.active() && playerGroup.size() > 1 ? " | " + playerGroup.size() + " Players" : ""; + String players = Net.active() && playerGroup.size() > 1 ? " | " + playerGroup.size() + " Players" : ""; presence.state = mode + players; @@ -109,7 +135,7 @@ public class DesktopPlatform extends Platform{ try{ Enumeration e = NetworkInterface.getNetworkInterfaces(); NetworkInterface out; - for(out = e.nextElement(); (out.getHardwareAddress() == null || !validAddress(out.getHardwareAddress())) && e.hasMoreElements(); out = e.nextElement()); + for(out = e.nextElement(); (out.getHardwareAddress() == null || !validAddress(out.getHardwareAddress())) && e.hasMoreElements(); out = e.nextElement()) ; byte[] bytes = out.getHardwareAddress(); byte[] result = new byte[8];