Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request / Question #11

Closed
Tomoli75 opened this issue Dec 13, 2020 · 11 comments
Closed

Feature Request / Question #11

Tomoli75 opened this issue Dec 13, 2020 · 11 comments
Labels
enhancement New feature or request

Comments

@Tomoli75
Copy link

Hi,

Would it be possible to add lobby features or networking? I believe they're documented in the Game SDK documentation and would make life a lot easier. If this would take too much time, please could you point me in the direction of adding them - I have tried to compile the library on my own using the latest Game SDK, to no avail.

Thanks! :)

@JnCrMx
Copy link
Owner

JnCrMx commented Dec 13, 2020

That is a really interesting idea, but I am afraid that it will take a lot of time as there are a lot of functions to implement.

So if you want to try it yourself, here is a short guide on how to set up a development environment:

  1. Install a C compiler:
    As the library relies on native code included with JNI, a C compiler is required to build it. On Windows I'd recommend using the one from Visual Studio (but not actually using Visual Studio). On Linux it's a lot easier as you can just use gcc.
  2. Install CMake (https://cmake.org):
    The project uses CMake to build the native libraries (which makes it possible to use mostly the same build process for Windows and Linux). Installing it should be easy on Linux, but might be a bit more difficult on Windows. Mainly make sure that it is in your %PATH%, so you can access it from anywhere.
  3. Install Maven:
    The project is built using Apache Maven. If you are using an IDE, you can probably skip this step tho, as it should provide its own version of Maven.
  4. Download and extract the Discord Game SDK:
    Download the Game SDK and extract it to ./discord-game-sdk (relative from the repository root). After this step the directory structure should look something like this:
    image
  5. Run mvn test:
    This Maven goal will build the native libraries, compile the Java code and also run a few tests. Some tests will probably fail, because I included some hard coded user IDs and stuff like that. Running mvn compile is not enough tho, as it will not copy the native libraries to the right place. But you can skip the tests by doing mvn test -DskipTests.
  6. Now you should have a development environment which should be able to compile the library. I will add a little guide on how I'd recommend getting started with including new features tomorrow.

If you encounter any problems with this setup, please tell me and I will try my best to help you revolve them. I know that this guide is pretty messy, so don't hesitate to ask if you have any questions or something isn't clear :)

@JnCrMx JnCrMx added the enhancement New feature or request label Dec 13, 2020
@Tomoli75
Copy link
Author

I've got it building using cmd, I just couldn't really figure out how to implement new functions - haven't exactly created Java bindings for the Game SDK before.

The files (e.g. this) aren't exactly the easiest to understand at first glance, and so I was having some slight issues in trying to figure out how it was implemented so that I could add the lobby functionality.

@JnCrMx
Copy link
Owner

JnCrMx commented Dec 13, 2020

Ah, I see.

The main idea is that the "normal" Java functions call native C functions which then call the Game SDK.

For callbacks it works exactly the other way around: The SDk calls a provided C function which then calls a Java function. This for example happens in line 35.

Another thing that needs to be done by the native library is converting between C structs and Java objects. That e.g. is what create_java_relationship (line 7) is for. To do so, it first needs to find the corresponding Java classes (FindClass) and their constructors (GetMethodID(..., "<init>", ...)) and then finally create the objects (NewObject). For some objects there is a static method that is called instead of the constructor (e.g. createRelationship), but the overall procedure is similar.

Another confusing thing might be this CallbackData. Those structs are passed to the Discord SDK and then to our callback function. They provide an easy way to tell the C callback which Java method (usually of a Consumer or Predicate) it is supposed to call.

I hope this could help a bit to get a general overview.
I'm sorry if this is a bit confusing, but where I am it's currently 3:45, so I might be a little sleepy already.

@JnCrMx
Copy link
Owner

JnCrMx commented Dec 18, 2020

I made a little example of how I would implement those functions:
You can find it in 27a435d.

If you want to work on it, maybe just fork and use the lobby-stub branch.
I'd even welcome little changes, so if you want to, maybe just implement a few easy functions and make a pull request.

I also hope that this example is a little easier to understand than the messy relationship code.
But if you have any particular questions or need help to understand it, feel free to ask :D

If you don't want to work on it or don't have time to get into my messy code, just tell me, so I will work on implementing the functions.

@JnCrMx
Copy link
Owner

JnCrMx commented Dec 26, 2020

Ok, I've implemented most lobby functions now (see https://github.com/JnCrMx/discord-game-sdk4j/tree/lobby-stub).
I'm currently working on networking (which seems to be a bit complicated, but I was able to set up a minimal working example already).
Sorry if you wanted to work on it, but I just couldn't resist.

@JnCrMx JnCrMx closed this as completed Dec 26, 2020
@JnCrMx JnCrMx reopened this Dec 26, 2020
@JnCrMx
Copy link
Owner

JnCrMx commented Dec 26, 2020

Sorry for closing, it was a misclick. I will keep it open until I'm done with lobby and networking functions.

@Tomoli75
Copy link
Author

Thank you for helping with this - I didn't really understand the conversion, but am incredibly grateful for your continued help in using this SDK.

@JnCrMx
Copy link
Owner

JnCrMx commented Jan 1, 2021

Update:

I'm currently working on the Javadoc for Lobby functions, but I have finished implementation for Lobby as well as Network bindings.
Javadoc is usually one of the less interesting tasks, so I'm not sure how quick I will have it finished.

If you want to test/use the new functions right away, either checkout networking (or lobbies, but networking is mostly built upon lobbies, so you get both when choosing networking) and build the library yourself, or if you don't want to bother with compiling, tell me, so I build it and make some pre-releases or something like that. :D

@JnCrMx
Copy link
Owner

JnCrMx commented Jan 12, 2021

I'm done with the documentation for the Lobby functions now. It took me a lot longer than I expected though.
I merged the Lobby branch into master and will hopefully be able to make a new release today.

@Tomoli75
Copy link
Author

Thank you for helping so much with this - it means a lot, and I hope I can somehow make it up to you in future!

@JnCrMx
Copy link
Owner

JnCrMx commented Jan 15, 2021

networking was merged into master by #15 and 7d91e88.
I will include it in the next release (0.5), which I'm working on at the moment.

@JnCrMx JnCrMx closed this as completed Jan 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants