Mate libGDX and Jetbrains MPS

148 Views Asked by At

I also posted this question on the LibGDX forums.

Hey there! For my thesis, I'm writing a DSL to describe the look of pictures. These pictures will be painted by libGDX according to the DSL-Input. By now, jetbrains MPS (v. 3.0) and the newest libGDX-version is in use. My actual problem is: how to design the interconnection between my MPS-language and the java-libGDX-picture-generator.

Jetbrains MPS is not widely spread, but I'm sure, my problem can be solved without knowledge of it. In the DSL, a generator is designed to build a class that can be executed (public static void main). Here goes several method calls to start picture-generation. Think of it as generatePicture(200px, 150px, "blue") (it's much more complicated, but I think that's not important for my problem).

In libGDX I have several launchers (especially the DesktopLauncher), these are the programms main classes, the ones that were started. At the moment, the launcher starts another class (I named it "Main") and here are the method calls. The libGDX programm is inserted into MPS via jar artifact, so it's methods can be used in my DSL.

What would be a good solution to make my DSL-code start my libGDX-programm? I have to make all these method calls and start the launcher. I thought about an additional class to initialize the launcher and make the calls, or trying to insert the calls from the DSL into the jar-classes. Are there any comparable problems out there or someone who faced this very issue? I'm sure I will bring it to work somehow, but I'm interested in a nice and smooth solution.

Edit Main classes in mps and libgdx The problem is that I'm somewhot sure I need the DesktopLauncher and its config to run the libGDX stuff inside my PictureGenerator.

Edit 2 - first approach enter image description here This is MPS related again. I thought about generating the Picture class with the MPS generator, but run the Launcher class. Is this somehow possible? To run a class from the solution it need to implement IMainClass, but the Launcher couldn't. The launcher will always look the same. Is there a functionality to run another class than the generated one?

Or on libGDX-site: is it possible to merge launcher and Picture-class to insert the config?

2

There are 2 best solutions below

0
On BEST ANSWER

Ok, I made it, following the idea of my second edit.

  • one file is generated in MPS
  • the generated file can be executed
  • a libgdx jar file is used

In MPS, I generate the following class with an inner class

public class DesktopLauncher {
  public static void main(string[] args) {
    LwjglApplicationConfiguration config = new LwgjlApplicationConfiguration();
    new LwjglApplication(new Picture(), config);
  }

  public static class Picture extends ApplicationAdapter {
    public Picture(){}
    PictureGeneratorImpl generator;

    public void create() {
      generator = new PictureGeneratorImpl();
    }

    public void render() {
      generator.generatePicture();
      generator.exit();
    }

    public void dispose() {
      generator.dispose();
    }
  }
}

As additional information: my libgdx jar contained the whole project (including core and desktop). I hope this might help anyone who got the idea to combine MPS and libGDX.

3
On

Look at robot_Kaja sample (in MPSSamples.3.3\robot_Kaja). The Script concept implements IMainClass interface which makes it possible to run instances of this concept. You can right-click on any script in the jetbrains.mps.samples.Kaja.sandbox solution and you will see a Run option in the popup menu. Clicking on it will run the generated code for this script.

In your case, you probably also have some top-level concept similar to Script, which is generated into the Java (baseLanguage) Main class. Just make this concept implement IMainClass and it should become possible to run it directly from MPS.