Giter Club home page Giter Club logo

steamworks4j's Introduction

steamworks4j

A thin wrapper which allows Java applications to access the Steamworks C++ API. It can be easily integrated with other frameworks, such as libGDX.

Introduction

The wrapper is written as minimal as possible without sacrificing ease of use. Its goal is to provide just an accessible Java interface to Valve's C++ interfaces.

In its current state, the wrapper only publishes very few interfaces. In basic, everything we put into use with our own games right now. Feel free to participate to extend it with the many functions and interfaces still missing.

steamworks4j is currently built against Steamworks SDK v1.30.

This project is released under the MIT license. The steamworks4j package does not contain any source/header files owned by Valve. The only files included from the Steamworks SDK are the redistributable steam_api runtime libraries to accompany the prebuilt native libraries.

Implementation overview

Technical concept

The public Java interfaces are more or less 1:1 mapped to their native counterparts, as long as it doesn't impede usability and type safety. In general, each public function does simple type conversion only before calling its native function.

Callbacks are dealt with in a similar manner. Native callbacks are received by package private callback adapters, which only do type conversion, then forward the callback to their public interface.

Proper handling of callbacks

The Steamworks API provides two different mechanics to deal with callbacks: STEAM_CALLBACK() and CCallResult<>. Both are handled internally by steamworks4j for you, but this abstraction imposes one drawback:

It is only guaranteed that, at any time, the user application receives callbacks related to the latest respective API call.

In practice this means that the caller shouldn't "batch-execute" the same API function, then wait for a bunch (of the same type) of callbacks. Instead, only one single API call should be issued. Then the application should wait for the callback, process it, then execute the next API call.

This is actually true for CCallResult<> style callbacks only, but the application will require more knowledge about the inner workings of Steamworks to differentiate, as the Java API doesn't tell.

Implemented interfaces

The following interfaces have been partially implemented so far:

ISteamRemoteStorage
ISteamUGC
ISteamUser
ISteamUserStats
ISteamUtils

Requirements

First of all, you need to be registered with, and have a project set up at Steamworks to use this wrapper.

Technical requirements

Java

The Java code is compiled with JDK 1.6.

Mac OS

OS X 10.6 and above is supported.

Building native libraries

Prebuilt libraries

Building the native libraries yourself isn't required if you only plan to use the wrapper. There are prebuilt versions included in the steamworks4j/natives/libs/ folder. The Maven build packs them all into steamworks4j-natives.jar which is then bundled with the primary JAR file.

Dependencies

To build the native libraries, download the latest Steamworks SDK. Unzip and copy the following folders into the steamworks4j root directory:

  • steamworks4j/
    • sdk/
      • public/
      • redistributable_bin/

We use jnigen to generate parts of the native code, and premake4 to compile native code into dynamic libraries.

Build environments

Windows

  • The Visual Studio 2010 command line environment must be available. It's sufficient to use the VS2010 (or VS2012) Express edition. The default location for the batch file to setup the build environment is c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat
  • premake4.exe must be available in the path, e.g. put into the steamworks4j/build-natives/ folder.

Linux

  • GCC must be installed in a fairly recent version with C++11 support.
  • premake4 needs to be installed. It should be available through your favorite package manager, e.g. per apt-get install premake4.

Mac OS

  • XCode must be installed.
  • premake4 needs to be available. One possible option is to install it as a Mac Ports package.

Build steps

The first step is to let jnigen generate C++ source files for the embedded JNI functions. The com.codedisaster.steamworks.jnigen.JNICodeGenerator class contains the code to do that.

  • The working directory must be the steamworks4j/java-wrapper/ folder.
  • Simply run java -jar /path/to/steamworks4j-${version}-jar-with-dependencies.jar. This will run the JNICodeGenerator.main() application.
  • You can just run this as a plain Java application from inside your favorite IDE. No arguments are required.
  • The generated code is written to steamworks4j/java-wrapper/src/main/native/.

If everything is setup correctly, you now only need to run the right build-[osx|linux|win].[sh|bat] shell script in the steamworks4j/build-natives/ folder to compile and link the native libraries on each target platform.

In case of errors you should be able to open the workspace/project files created by premake4, to open them in the respective IDE for troubleshooting.

Building the Java package

Just use Maven to mvn package in the root directory to compile a jar ready to be used in your application.

Using the wrapper

com.codedisaster.steamworks.SteamAPITestApplication contains some test code which shows basic usage of the Java wrapper.

Debugging

For development you'll need to put a text file steam_appid.txt, which just contains the appID of your Steam application, into the working directory of your application.

steamworks4j's People

Contributors

code-disaster avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.