From 0bcc1c1ffd4fdb5e73490a3ba7fdafc20339cfcd Mon Sep 17 00:00:00 2001 From: String Date: Mon, 23 Feb 2026 06:29:29 -0600 Subject: [PATCH] Complete FlixelGDX refactor for library prepping --- .gitignore | 17 +- android/build.gradle | 27 +-- .../polyverse/android/AndroidLauncher.java | 5 +- assets/another_test.groovy | 4 +- assets/test.groovy | 4 +- build.gradle | 2 +- flixelgdx/android/build.gradle | 48 +++++ .../android/FlixelAndroidLauncher.java | 19 ++ flixelgdx/build.gradle | 28 +-- flixelgdx/core/build.gradle | 24 +++ .../me/stringdotjar/flixelgdx/Flixel.java | 52 +++-- .../me/stringdotjar/flixelgdx/FlixelGame.java | 197 +++++++++++++----- .../flixelgdx/graphics/FlixelBasic.java | 4 +- .../flixelgdx/graphics/FlixelCamera.java | 34 ++- .../flixelgdx/graphics/FlixelObject.java | 0 .../flixelgdx/graphics/FlixelState.java | 0 .../graphics/sprite/FlixelSprite.java | 0 .../graphics/text/FlixelFontRegistry.java | 0 .../flixelgdx/graphics/text/FlixelText.java | 0 .../flixelgdx/group/FlixelGroup.java | 0 .../flixelgdx/group/FlixelGroupable.java | 0 .../flixelgdx/group/FlixelSpriteGroup.java | 0 .../flixelgdx/input/FlixelKey.java | 0 .../flixelgdx/signal/FlixelSignal.java | 0 .../flixelgdx/signal/FlixelSignalData.java | 0 .../flixelgdx/tween/FlixelEase.java | 0 .../flixelgdx/tween/FlixelTween.java | 0 .../flixelgdx/tween/FlixelTweenManager.java | 0 .../tween/settings/FlixelTweenSettings.java | 0 .../tween/settings/FlixelTweenType.java | 0 .../flixelgdx/tween/type/FlixelNumTween.java | 0 .../flixelgdx/tween/type/FlixelVarTween.java | 0 .../flixelgdx/util/FlixelConstants.java | 0 .../flixelgdx/util/FlixelMathUtil.java | 0 .../flixelgdx/util/FlixelPathsUtil.java} | 8 +- .../flixelgdx/util/FlixelReflectUtil.java | 0 .../flixelgdx/util/FlixelRuntimeUtil.java | 0 flixelgdx/lwjgl3/build.gradle | 18 ++ .../backend/lwjgl3/FlixelLwjgl3Launcher.java | 55 +++++ gradle.properties | 1 - lwjgl3/build.gradle | 8 +- .../polyverse/lwjgl3/Lwjgl3Launcher.java | 59 +----- polyverse/build.gradle | 14 +- .../me/stringdotjar/polyverse/InitState.java | 6 +- .../stringdotjar/polyverse/PolyverseApp.java | 12 +- .../polyverse/menus/TitleState.java | 18 +- .../polyverse/util/PolyverseConstants.java | 15 ++ settings.gradle | 7 +- 48 files changed, 446 insertions(+), 240 deletions(-) create mode 100644 flixelgdx/android/build.gradle create mode 100644 flixelgdx/android/src/main/java/me/stringdotjar/flixelgdx/backend/android/FlixelAndroidLauncher.java create mode 100644 flixelgdx/core/build.gradle rename flixelgdx/{ => core}/src/main/java/me/stringdotjar/flixelgdx/Flixel.java (91%) rename flixelgdx/{ => core}/src/main/java/me/stringdotjar/flixelgdx/FlixelGame.java (82%) rename flixelgdx/{ => core}/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelBasic.java (94%) rename flixelgdx/{ => core}/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelCamera.java (98%) rename flixelgdx/{ => core}/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelObject.java (100%) rename flixelgdx/{ => core}/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelState.java (100%) rename flixelgdx/{ => core}/src/main/java/me/stringdotjar/flixelgdx/graphics/sprite/FlixelSprite.java (100%) rename flixelgdx/{ => core}/src/main/java/me/stringdotjar/flixelgdx/graphics/text/FlixelFontRegistry.java (100%) rename flixelgdx/{ => core}/src/main/java/me/stringdotjar/flixelgdx/graphics/text/FlixelText.java (100%) rename flixelgdx/{ => core}/src/main/java/me/stringdotjar/flixelgdx/group/FlixelGroup.java (100%) rename flixelgdx/{ => core}/src/main/java/me/stringdotjar/flixelgdx/group/FlixelGroupable.java (100%) rename flixelgdx/{ => core}/src/main/java/me/stringdotjar/flixelgdx/group/FlixelSpriteGroup.java (100%) rename flixelgdx/{ => core}/src/main/java/me/stringdotjar/flixelgdx/input/FlixelKey.java (100%) rename flixelgdx/{ => core}/src/main/java/me/stringdotjar/flixelgdx/signal/FlixelSignal.java (100%) rename flixelgdx/{ => core}/src/main/java/me/stringdotjar/flixelgdx/signal/FlixelSignalData.java (100%) rename flixelgdx/{ => core}/src/main/java/me/stringdotjar/flixelgdx/tween/FlixelEase.java (100%) rename flixelgdx/{ => core}/src/main/java/me/stringdotjar/flixelgdx/tween/FlixelTween.java (100%) rename flixelgdx/{ => core}/src/main/java/me/stringdotjar/flixelgdx/tween/FlixelTweenManager.java (100%) rename flixelgdx/{ => core}/src/main/java/me/stringdotjar/flixelgdx/tween/settings/FlixelTweenSettings.java (100%) rename flixelgdx/{ => core}/src/main/java/me/stringdotjar/flixelgdx/tween/settings/FlixelTweenType.java (100%) rename flixelgdx/{ => core}/src/main/java/me/stringdotjar/flixelgdx/tween/type/FlixelNumTween.java (100%) rename flixelgdx/{ => core}/src/main/java/me/stringdotjar/flixelgdx/tween/type/FlixelVarTween.java (100%) rename flixelgdx/{ => core}/src/main/java/me/stringdotjar/flixelgdx/util/FlixelConstants.java (100%) rename flixelgdx/{ => core}/src/main/java/me/stringdotjar/flixelgdx/util/FlixelMathUtil.java (100%) rename flixelgdx/{src/main/java/me/stringdotjar/flixelgdx/backend/FlixelPaths.java => core/src/main/java/me/stringdotjar/flixelgdx/util/FlixelPathsUtil.java} (92%) rename flixelgdx/{ => core}/src/main/java/me/stringdotjar/flixelgdx/util/FlixelReflectUtil.java (100%) rename flixelgdx/{ => core}/src/main/java/me/stringdotjar/flixelgdx/util/FlixelRuntimeUtil.java (100%) create mode 100644 flixelgdx/lwjgl3/build.gradle create mode 100644 flixelgdx/lwjgl3/src/main/java/me/stringdotjar/flixelgdx/backend/lwjgl3/FlixelLwjgl3Launcher.java diff --git a/.gitignore b/.gitignore index 2096da3..b05d696 100644 --- a/.gitignore +++ b/.gitignore @@ -1,19 +1,10 @@ ## Gradle: .gradle/ gradle-app.setting -/build/ -/funkin/build/ -/flixelgdx/build/ -/polyverse/build/ -/android/build/ -/lwjgl3/build/ -/html/build/ -/teavm/build/ -/ios/build/ -/ios-moe/build/ -/headless/build/ -/server/build/ -/shared/build/ +**/build/ +**/nbbuild/ +**/dist/ +**/nbdist/ ## Java: *.class diff --git a/android/build.gradle b/android/build.gradle index c4215d7..f819286 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -53,30 +53,21 @@ android { } } -repositories { - // needed for AAPT2, may be needed for other tools - google() -} - configurations { natives } dependencies { coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.5' - implementation "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion" implementation project(':polyverse') + implementation project(':flixelgdx:android') +} - api "games.rednblack.miniaudio:gdx-miniaudio-platform:$miniaudioVersion:natives-armeabi-v7a" - api "games.rednblack.miniaudio:gdx-miniaudio-platform:$miniaudioVersion:natives-arm64-v8a" - api "games.rednblack.miniaudio:gdx-miniaudio-platform:$miniaudioVersion:natives-x86" - api "games.rednblack.miniaudio:gdx-miniaudio-platform:$miniaudioVersion:natives-x86_64" - natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-arm64-v8a" - natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi-v7a" - natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86" - natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86_64" - natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a" - natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a" - natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86" - natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64" +configurations { + coreLibraryDesugaring +} + +repositories { + // needed for AAPT2, may be needed for other tools + google() } // Called every time gradle gets executed, takes the native dependencies of diff --git a/android/src/main/java/me/stringdotjar/polyverse/android/AndroidLauncher.java b/android/src/main/java/me/stringdotjar/polyverse/android/AndroidLauncher.java index 1ead2b3..b5485e5 100644 --- a/android/src/main/java/me/stringdotjar/polyverse/android/AndroidLauncher.java +++ b/android/src/main/java/me/stringdotjar/polyverse/android/AndroidLauncher.java @@ -17,7 +17,10 @@ protected void onCreate(Bundle savedInstanceState) { PolyverseConstants.WINDOW_TITLE, PolyverseConstants.WINDOW_WIDTH, PolyverseConstants.WINDOW_HEIGHT, - new InitState() + new InitState(), + PolyverseConstants.FRAMERATE, + PolyverseConstants.VSYNC, + PolyverseConstants.FULLSCREEN ); AndroidApplicationConfiguration configuration = new AndroidApplicationConfiguration(); configuration.useImmersiveMode = true; // Recommended, but not required. diff --git a/assets/another_test.groovy b/assets/another_test.groovy index e379d50..9461c7f 100644 --- a/assets/another_test.groovy +++ b/assets/another_test.groovy @@ -1,7 +1,7 @@ import com.badlogic.gdx.Gdx import com.badlogic.gdx.Input import me.stringdotjar.flixelgdx.Flixel -import me.stringdotjar.flixelgdx.backend.FlixelPaths +import me.stringdotjar.flixelgdx.util.FlixelPathsUtil import me.stringdotjar.flixelgdx.graphics.sprite.FlixelSprite import me.stringdotjar.polyverse.util.PolyverseConstants import me.stringdotjar.polyverse.script.type.Script @@ -26,7 +26,7 @@ class AnotherTestClass extends Script { super.onUpdate(delta) if (Gdx.input.isKeyJustPressed(Input.Keys.SPACE)) { - var sprite = new FlixelSprite().loadGraphic(FlixelPaths.sharedImageAsset("pauseAlt/bfLol")) + var sprite = new FlixelSprite().loadGraphic(FlixelPathsUtil.sharedImageAsset("pauseAlt/bfLol")) var randomPosX = new Random().nextInt(PolyverseConstants.WINDOW_WIDTH) var randomPosY = new Random().nextInt(PolyverseConstants.WINDOW_HEIGHT) diff --git a/assets/test.groovy b/assets/test.groovy index c677497..e532843 100644 --- a/assets/test.groovy +++ b/assets/test.groovy @@ -3,7 +3,7 @@ import com.badlogic.gdx.Input import com.badlogic.gdx.graphics.Color import me.stringdotjar.flixelgdx.Flixel import me.stringdotjar.flixelgdx.graphics.FlixelState -import me.stringdotjar.flixelgdx.backend.FlixelPaths +import me.stringdotjar.flixelgdx.util.FlixelPathsUtil import me.stringdotjar.flixelgdx.graphics.sprite.FlixelSprite import me.stringdotjar.polyverse.script.type.SystemScript @@ -55,7 +55,7 @@ class TestState extends FlixelState { // test.changeX(-30) - test = new FlixelSprite().loadGraphic(FlixelPaths.sharedImageAsset('NOTE_hold_assets')) + test = new FlixelSprite().loadGraphic(FlixelPathsUtil.sharedImageAsset('NOTE_hold_assets')) add(test) } diff --git a/build.gradle b/build.gradle index d4a54ad..e22e156 100644 --- a/build.gradle +++ b/build.gradle @@ -26,7 +26,7 @@ allprojects { } } -configure(subprojects - project(':android')) { +configure(subprojects.findAll { !it.path.contains('android') }) { apply plugin: 'java-library' sourceCompatibility = 17 diff --git a/flixelgdx/android/build.gradle b/flixelgdx/android/build.gradle new file mode 100644 index 0000000..e2c423e --- /dev/null +++ b/flixelgdx/android/build.gradle @@ -0,0 +1,48 @@ +eclipse.project.name = appName + '-flixelgdx-android' + +apply plugin: 'com.android.library' + +android { + namespace "me.stringdotjar.flixelgdx" + compileSdk 36 + + defaultConfig { + multiDexEnabled = true + minSdkVersion 34 + targetSdkVersion 35 + } + compileOptions { + coreLibraryDesugaringEnabled = true + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 + } +} + +repositories { + // needed for AAPT2, may be needed for other tools + google() +} + +configurations { + coreLibraryDesugaring +} + +dependencies { + coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.5' + + api project(":flixelgdx:core") + api "androidx.multidex:multidex:2.0.1" + api "games.rednblack.miniaudio:gdx-miniaudio-platform:$miniaudioVersion:natives-armeabi-v7a" + api "games.rednblack.miniaudio:gdx-miniaudio-platform:$miniaudioVersion:natives-arm64-v8a" + api "games.rednblack.miniaudio:gdx-miniaudio-platform:$miniaudioVersion:natives-x86" + api "games.rednblack.miniaudio:gdx-miniaudio-platform:$miniaudioVersion:natives-x86_64" + api "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-arm64-v8a" + api "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi-v7a" + api "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86" + api "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86_64" + api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a" + api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a" + api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86" + api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64" + api "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion" +} diff --git a/flixelgdx/android/src/main/java/me/stringdotjar/flixelgdx/backend/android/FlixelAndroidLauncher.java b/flixelgdx/android/src/main/java/me/stringdotjar/flixelgdx/backend/android/FlixelAndroidLauncher.java new file mode 100644 index 0000000..bb43052 --- /dev/null +++ b/flixelgdx/android/src/main/java/me/stringdotjar/flixelgdx/backend/android/FlixelAndroidLauncher.java @@ -0,0 +1,19 @@ +package me.stringdotjar.flixelgdx.backend.android; + +import me.stringdotjar.flixelgdx.FlixelGame; + +/** + * Launches the Android version of a FlixelGDX game. + */ +public class FlixelAndroidLauncher { + + /** + * Launches the Android version of the game with the given game instance. + * + *

This should be called from the onCreate method of the Android launcher class, and the + * game instance should be created in the same general area. + * + * @param game The game instance to launch. This should already be initialized with the desired configuration values. + */ + public static void launch (FlixelGame game) {} +} diff --git a/flixelgdx/build.gradle b/flixelgdx/build.gradle index f706a5c..40479df 100644 --- a/flixelgdx/build.gradle +++ b/flixelgdx/build.gradle @@ -1,18 +1,18 @@ -[compileJava, compileTestJava]*.options*.encoding = 'UTF-8' -eclipse.project.name = appName + '-flixelgdx' +subprojects { -dependencies { - api "com.badlogicgames.gdx:gdx-freetype:$gdxVersion" - api "com.badlogicgames.gdx:gdx:$gdxVersion" - api "com.github.tommyettinger:anim8-gdx:$anim8Version" - api "com.github.tommyettinger:libgdx-utils:$utilsVersion" - api "io.github.libktx:ktx-freetype:$ktxVersion" - api "games.rednblack.miniaudio:miniaudio:$miniaudioVersion" - api "org.fusesource.jansi:jansi:$jansiVersion" + group = 'me.stringdotjar.flixelgdx' + version = '1.0.0' - implementation "org.jetbrains:annotations:26.0.2-1" - - if (enableGraalNative == 'true') { - implementation "io.github.berstanio:gdx-svmhelper-annotations:$graalHelperVersion" + // Force Java 17 for the entire framework. + if (!project.path.contains('android')) { + plugins.withType(JavaPlugin).tap { + configureEach { + java { + toolchain { + languageVersion = JavaLanguageVersion.of(17) + } + } + } + } } } diff --git a/flixelgdx/core/build.gradle b/flixelgdx/core/build.gradle new file mode 100644 index 0000000..aaf9188 --- /dev/null +++ b/flixelgdx/core/build.gradle @@ -0,0 +1,24 @@ +[compileJava, compileTestJava]*.options*.encoding = 'UTF-8' +eclipse.project.name = appName + '-flixelgdx-core' + +apply plugin: "java-library" + +java { + sourceCompatibility = 17 + targetCompatibility = 17 +} + +dependencies { + api "com.badlogicgames.gdx:gdx:$gdxVersion" + api "com.badlogicgames.gdx:gdx-freetype:$gdxVersion" + api "com.github.tommyettinger:anim8-gdx:$anim8Version" + api "com.github.tommyettinger:libgdx-utils:$utilsVersion" + api "games.rednblack.miniaudio:miniaudio:$miniaudioVersion" + api "org.fusesource.jansi:jansi:$jansiVersion" + + implementation "org.jetbrains:annotations:26.1.0" + + if (enableGraalNative == 'true') { + implementation "io.github.berstanio:gdx-svmhelper-annotations:$graalHelperVersion" + } +} diff --git a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/Flixel.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/Flixel.java similarity index 91% rename from flixelgdx/src/main/java/me/stringdotjar/flixelgdx/Flixel.java rename to flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/Flixel.java index dba6a01..1515e93 100644 --- a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/Flixel.java +++ b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/Flixel.java @@ -9,7 +9,7 @@ import games.rednblack.miniaudio.MASound; import games.rednblack.miniaudio.MiniAudio; import games.rednblack.miniaudio.loader.MASoundLoader; -import me.stringdotjar.flixelgdx.backend.FlixelPaths; +import me.stringdotjar.flixelgdx.util.FlixelPathsUtil; import me.stringdotjar.flixelgdx.graphics.FlixelState; import me.stringdotjar.flixelgdx.graphics.FlixelCamera; import me.stringdotjar.flixelgdx.signal.FlixelSignal; @@ -111,8 +111,8 @@ public static void switchState(FlixelState newState) { * FileHandle} like so: * *

{@code
-   * // Notice how it uses the FlixelPaths class provided by Flixel'.
-   * Flixel.playSound(FlixelPaths.external("your/path/here").path());
+   * // Notice how it uses the FlixelPathsUtil class provided by Flixel'.
+   * Flixel.playSound(FlixelPathsUtil.external("your/path/here").path());
    * }
* * @param path The path to load the sound from. Note that if you're loading an external sound @@ -131,8 +131,8 @@ public static MASound playSound(String path) { * FileHandle} like so: * *
{@code
-   * // Notice how it uses the FlixelPaths class provided by Flixel'.
-   * Flixel.playSound(FlixelPaths.external("your/path/here").path(), 1);
+   * // Notice how it uses the FlixelPathsUtil class provided by Flixel'.
+   * Flixel.playSound(FlixelPathsUtil.external("your/path/here").path(), 1);
    * }
* * @param path The path to load the sound from. Note that if you're loading an external sound @@ -152,8 +152,8 @@ public static MASound playSound(String path, float volume) { * FileHandle} like so: * *
{@code
-   * // Notice how it uses the FlixelPaths class provided by Flixel'.
-   * Flixel.playSound(FlixelPaths.external("your/path/here").path(), 1, false);
+   * // Notice how it uses the FlixelPathsUtil class provided by Flixel'.
+   * Flixel.playSound(FlixelPathsUtil.external("your/path/here").path(), 1, false);
    * }
* * @param path The path to load the sound from. Note that if you're loading an external sound @@ -174,9 +174,9 @@ public static MASound playSound(String path, float volume, boolean looping) { * FileHandle} like so: * *
{@code
-   * // Notice how it uses the FlixelPaths class provided by Flixel'.
+   * // Notice how it uses the FlixelPathsUtil class provided by Flixel'.
    * // If null is passed down for the group, then the default sound group will be used.
-   * Flixel.playSound(FlixelPaths.external("your/path/here").path(), 1, false, null);
+   * Flixel.playSound(FlixelPathsUtil.external("your/path/here").path(), 1, false, null);
    * }
* * @param path The path to load the sound from. Note that if you're loading an external sound @@ -199,11 +199,11 @@ public static MASound playSound(String path, float volume, boolean looping, MAGr * FileHandle} like so: * *
{@code
-   * // Notice how it uses the FlixelPaths class provided by Flixel'.
+   * // Notice how it uses the FlixelPathsUtil class provided by Flixel'.
    * // If null is passed down for the group, then the default sound group will be used.
    * // For the boolean attribute "external", you only should make it true for mobile builds,
    * // otherwise just simply leave it be or make it "false" for other platforms like desktop.
-   * Flixel.playSound(FlixelPaths.external("your/path/here").path(), 1, false, null, true);
+   * Flixel.playSound(FlixelPathsUtil.external("your/path/here").path(), 1, false, null, true);
    * }
* * @param path The path to load the sound from. Note that if you're loading an external sound @@ -217,7 +217,7 @@ public static MASound playSound(String path, float volume, boolean looping, MAGr * @return The new sound instance. */ public static MASound playSound(@NotNull String path, float volume, boolean looping, MAGroup group, boolean external) { - String resolvedPath = external ? path : FlixelPaths.resolveAudioPath(path); + String resolvedPath = external ? path : FlixelPathsUtil.resolveAudioPath(path); MASound sound = engine.createSound(resolvedPath, (short) 0, (group != null) ? group : soundsGroup, external); Signals.preSoundPlayed.dispatch(new SoundPlayedSignalData(sound)); sound.setVolume(volume); @@ -234,8 +234,8 @@ public static MASound playSound(@NotNull String path, float volume, boolean loop * {@link FileHandle} like so: * *
{@code
-   * // Notice how it uses the FlixelPaths class provided by Flixel'.
-   * Flixel.playMusic(FlixelPaths.external("your/path/here").path());
+   * // Notice how it uses the FlixelPathsUtil class provided by Flixel'.
+   * Flixel.playMusic(FlixelPathsUtil.external("your/path/here").path());
    * }
* * @param path The path to load the music from. Note that if you're loading an external sound file @@ -253,8 +253,8 @@ public static void playMusic(String path) { * {@link FileHandle} like so: * *
{@code
-   * // Notice how it uses the FlixelPaths class provided by Flixel'.
-   * Flixel.playMusic(FlixelPaths.external("your/path/here").path(), 1);
+   * // Notice how it uses the FlixelPathsUtil class provided by Flixel'.
+   * Flixel.playMusic(FlixelPathsUtil.external("your/path/here").path(), 1);
    * }
* * @param path The path to load the music from. Note that if you're loading an external sound file @@ -273,8 +273,8 @@ public static void playMusic(String path, float volume) { * {@link FileHandle} like so: * *
{@code
-   * // Notice how it uses the FlixelPaths class provided by Flixel'.
-   * Flixel.playMusic(FlixelPaths.external("your/path/here").path(), 1, false);
+   * // Notice how it uses the FlixelPathsUtil class provided by Flixel'.
+   * Flixel.playMusic(FlixelPathsUtil.external("your/path/here").path(), 1, false);
    * }
* * @param path The path to load the music from. Note that if you're loading an external sound file @@ -294,10 +294,10 @@ public static void playMusic(String path, float volume, boolean looping) { * {@link FileHandle} like so: * *
{@code
-   * // Notice how it uses the FlixelPaths class provided by Flixel'.
+   * // Notice how it uses the FlixelPathsUtil class provided by Flixel'.
    * // For the boolean attribute "external", you only should make it true for mobile builds,
    * // otherwise just simply leave it be or make it "false" for other platforms like desktop.
-   * Flixel.playMusic(FlixelPaths.external("your/path/here").path(), 1, false, true);
+   * Flixel.playMusic(FlixelPathsUtil.external("your/path/here").path(), 1, false, true);
    * }
* * @param path The path to load the music from. Note that if you're loading an external sound file @@ -312,7 +312,7 @@ public static void playMusic(String path, float volume, boolean looping, boolean if (music != null) { music.stop(); } - String resolvedPath = external ? path : FlixelPaths.resolveAudioPath(path); + String resolvedPath = external ? path : FlixelPathsUtil.resolveAudioPath(path); music = engine.createSound(resolvedPath, (short) 0, soundsGroup, external); music.setVolume(volume); music.setLooping(looping); @@ -391,6 +391,14 @@ public static Vector2 getWindowSize() { return game.viewSize; } + public static int getWindowWidth() { + return (int) game.viewSize.x; + } + + public static int getWindowHeight() { + return (int) game.viewSize.y; + } + public static MiniAudio getAudioEngine() { return engine; } @@ -420,7 +428,7 @@ public static boolean isFullscreen() { } public static void setLogMode(@NotNull FlixelLogMode mode) { - logMode = (mode != null) ? mode : FlixelLogMode.SIMPLE; + logMode = mode; } /** diff --git a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/FlixelGame.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/FlixelGame.java similarity index 82% rename from flixelgdx/src/main/java/me/stringdotjar/flixelgdx/FlixelGame.java rename to flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/FlixelGame.java index bb34886..6e56bad 100644 --- a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/FlixelGame.java +++ b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/FlixelGame.java @@ -32,9 +32,9 @@ * *

Use this for changing the core logic of the game's behavior. To actually use this properly, you * need to create a subclass of this and override the methods you want to change. - * + * *

It is recommended for using this in the following way: - * + * *

{@code
  * // Create a new subclass of FlixelGame.
  * // Remember that you can override any methods to add extra functionality
@@ -45,9 +45,9 @@
  *   }
  * }
  * }
- * + * * Then, in a platform-specific launcher, you can create a new instance of your game and run it: - * + * *
{@code
  * // Example of how to create a new game instance and run it using the LWJGL3 launcher.
  * public class Lwjgl3Launcher {
@@ -55,19 +55,15 @@
  *     if (StartupHelper.startNewJvmIfRequired()) { // This handles macOS support and helps on Windows.
  *       return;
  *     }
- *     createApplication();
- *   }
- * 
- *   private static void createApplication() {
+ *
  *     MyGame game = new MyGame(
  *       "My Game",
  *       800,
  *       600,
  *       new InitialScreen() // The initial screen the game enters when it starts!
  *     );
- *     Flixel.initialize(game); // This is VERY important to do before creating the application!
- *     Vector2 size = game.getWindowSize();
- *     new Lwjgl3Application(game, createWindowConfiguration("My Game", (int) size.x, (int) size.y));
+ *
+ *     FlixelLwjgl3Launcher.launch(game);
  *   }
  * }
  * }
@@ -86,6 +82,15 @@ public abstract class FlixelGame implements ApplicationListener {
   /** The entry point screen the game starts in (which becomes null after the game is done setting up!). */
   protected FlixelState initialScreen;
 
+  /** The framerate of how fast the game should update and render. */
+  private int framerate;
+
+  /** Should the game use VSync to limit the framerate to the monitor's refresh rate? */
+  private boolean vsync;
+
+  /** Should the game start in fullscreen mode? */
+  protected boolean fullscreen;
+
   /** Is the game's window currently focused? */
   private boolean isFocused = true;
 
@@ -129,8 +134,17 @@ public abstract class FlixelGame implements ApplicationListener {
   private Thread logThread;
 
   /**
-   * Creates a new game instance with the specified title, window width/height, and initial screen. This configures
-   * the game's core parts, such as the camera, stage, etc.
+   * Creates a new game instance with the details specified.
+   *
+   * @param title The title of the game's window.
+   * @param initialScreen The initial screen to load when the game starts.
+   */
+  public FlixelGame(String title, FlixelState initialScreen) {
+    this(title, 640, 360, initialScreen, 60, true, false);
+  }
+
+  /**
+   * Creates a new game instance with the details specified.
    *
    * @param title The title of the game's window.
    * @param width The starting width of the game's window and how wide the camera should be.
@@ -138,10 +152,55 @@ public abstract class FlixelGame implements ApplicationListener {
    * @param initialScreen The initial screen to load when the game starts.
    */
   public FlixelGame(String title, int width, int height, FlixelState initialScreen) {
+    this(title, width, height, initialScreen, 60, true, false);
+  }
+
+  /**
+   * Creates a new game instance with the details specified.
+   *
+   * @param title The title of the game's window.
+   * @param width The starting width of the game's window and how wide the camera should be.
+   * @param height The starting height of the game's window and how tall the camera should be.
+   * @param initialScreen The initial screen to load when the game starts.
+   * @param framerate The framerate of how fast the game should update and render.
+   */
+  public FlixelGame(String title, int width, int height, FlixelState initialScreen, int framerate) {
+    this(title, width, height, initialScreen, framerate, true, false);
+  }
+
+  /**
+   * Creates a new game instance with the details specified.
+   *
+   * @param title The title of the game's window.
+   * @param width The starting width of the game's window and how wide the camera should be.
+   * @param height The starting height of the game's window and how tall the camera should be.
+   * @param initialScreen The initial screen to load when the game starts.
+   * @param framerate The framerate of how fast the game should update and render.
+   * @param vsync Should the game use VSync to limit the framerate to the monitor's refresh rate?
+   */
+  public FlixelGame(String title, int width, int height, FlixelState initialScreen, int framerate, boolean vsync) {
+    this(title, width, height, initialScreen, framerate, vsync, false);
+  }
+
+  /**
+   * Creates a new game instance with the details specified.
+   *
+   * @param title The title of the game's window.
+   * @param width The starting width of the game's window and how wide the camera should be.
+   * @param height The starting height of the game's window and how tall the camera should be.
+   * @param initialScreen The initial screen to load when the game starts.
+   * @param framerate The framerate of how fast the game should update and render.
+   * @param vsync Should the game use VSync to limit the framerate to the monitor's refresh rate?
+   * @param fullscreen Should the game start in fullscreen mode?
+   */
+  public FlixelGame(String title, int width, int height, FlixelState initialScreen, int framerate, boolean vsync, boolean fullscreen) {
     this.title = title;
     this.viewSize = new Vector2(width, height);
     this.windowSize = new Vector2(width, height);
     this.initialScreen = initialScreen;
+    this.framerate = framerate;
+    this.vsync = vsync;
+    this.fullscreen = fullscreen;
   }
 
   @Override
@@ -160,14 +219,14 @@ public void create() {
     cameras.add(new FlixelCamera((int) viewSize.x, (int) viewSize.y));
     stage = new Stage(getCamera().getViewport(), batch);
 
-    // Setup the background color for the game.
+    // Set up the background color for the game.
     Pixmap pixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
     pixmap.setColor(Color.WHITE);
     pixmap.fill();
     bgTexture = new Texture(pixmap);
     pixmap.dispose();
 
-    // Setup the log thread to write logs to a file.
+    // Set up the log thread to write logs to a file.
     setupLogWriterThread();
 
     Flixel.switchState(initialScreen);
@@ -200,7 +259,6 @@ public void update(float elapsed) {
     FlixelState state = Flixel.getState();
     state.update(elapsed);
 
-    // Update all members contained in the current state.
     state.getMembers().forEach(member -> member.update(elapsed));
 
     // Update all cameras.
@@ -275,6 +333,9 @@ public final void render() {
     windowSize.x = Gdx.graphics.getWidth();
     windowSize.y = Gdx.graphics.getHeight();
 
+    framerate = Gdx.graphics.getFramesPerSecond();
+    fullscreen = Gdx.graphics.isFullscreen();
+
     update(delta);
     draw();
   }
@@ -435,7 +496,7 @@ protected void setupLogWriterThread() {
           LocalDateTime now = LocalDateTime.now();
           DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss");
           String date = now.format(formatter);
-  
+
           // Create/get the path to the logs folder, which is inside the game's working directory.
           Gdx.files.absolute(logsFolder).mkdirs();
 
@@ -444,11 +505,11 @@ protected void setupLogWriterThread() {
           if (logFiles != null && logFiles.length > maxLogFiles - 1) {
             for (int i = 0; i < logFiles.length - maxLogFiles - 1; i++) {
               logFiles[i].delete();
-            } 
+            }
           }
 
           FileHandle logFile = Gdx.files.absolute(logsFolder + "/flixel-" + date + ".log");
-  
+
           // Keep running until shutdown is requested AND the queue is fully drained.
           // This ensures logs added during dispose() (e.g. "Disposing...") are written.
           while (true) {
@@ -486,38 +547,6 @@ protected void setupLogWriterThread() {
     }
   }
 
-  public String getTitle() {
-    return title;
-  }
-
-  public Vector2 getViewSize() {
-    return viewSize;
-  }
-
-  public Vector2 getWindowSize() {
-    return windowSize;
-  }
-
-  public boolean isFocused() {
-    return isFocused;
-  }
-
-  public Stage getStage() {
-    return stage;
-  }
-
-  public boolean canStoreLogs() {
-    return canStoreLogs;
-  }
-
-  public void setCanStoreLogs(boolean canStoreLogs) {
-    this.canStoreLogs = canStoreLogs;
-  }
-
-  public ConcurrentLinkedQueue getLogQueue() {
-    return logQueue;
-  }
-
   /**
    * Adds a log entry to the queue and notifies the log writer thread. Prefer this over
    * {@link #getLogQueue()} when adding logs so the writer wakes immediately instead of polling.
@@ -531,7 +560,7 @@ public void enqueueLog(String log) {
 
   /**
    * Gets the first camera that is part of the list. If the list is {@code null} or empty, then a new list (with a
-   * default camera accordingly).
+   * default camera accordingly) is created.
    *
    * @return The first camera in the list.
    */
@@ -559,6 +588,46 @@ public void resetCameras() {
     stage.setViewport(camera.getViewport());
   }
 
+  public String getTitle() {
+    return title;
+  }
+
+  public Vector2 getViewSize() {
+    return viewSize;
+  }
+
+  public Vector2 getWindowSize() {
+    return windowSize;
+  }
+
+  public int getWindowWidth() {
+    return (int) windowSize.x;
+  }
+
+  public  int getWindowHeight() {
+    return (int) windowSize.y;
+  }
+
+  public boolean isFocused() {
+    return isFocused;
+  }
+
+  public Stage getStage() {
+    return stage;
+  }
+
+  public boolean canStoreLogs() {
+    return canStoreLogs;
+  }
+
+  public void setCanStoreLogs(boolean canStoreLogs) {
+    this.canStoreLogs = canStoreLogs;
+  }
+
+  public ConcurrentLinkedQueue getLogQueue() {
+    return logQueue;
+  }
+
   public SnapshotArray getCameras() {
     return cameras;
   }
@@ -578,11 +647,33 @@ public boolean isMinimized() {
   public boolean isClosing() {
     return isClosing;
   }
-  
+
   public boolean isClosed() {
     return isClosed;
   }
 
+  public int getFramerate() {
+    return framerate;
+  }
+
+  public void setFramerate(int framerate) {
+    this.framerate = framerate;
+    Gdx.graphics.setForegroundFPS(framerate);
+  }
+
+  public boolean isVsync() {
+    return vsync;
+  }
+
+  public void setVsync(boolean vsync) {
+    this.vsync = vsync;
+    Gdx.graphics.setVSync(vsync);
+  }
+
+  public boolean isFullscreen() {
+    return fullscreen;
+  }
+
   public void setWindowSize(Vector2 newSize) {
     viewSize = newSize;
     Gdx.graphics.setWindowedMode((int) newSize.x, (int) newSize.y);
diff --git a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelBasic.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelBasic.java
similarity index 94%
rename from flixelgdx/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelBasic.java
rename to flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelBasic.java
index 623fa42..deef829 100644
--- a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelBasic.java
+++ b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelBasic.java
@@ -36,7 +36,9 @@ public FlixelBasic() {
   }
 
   /**
-   * Override this function to update your object's position and appearance.
+   * Updates the logic of {@code this} FlixelBasic.
+   *
+   * 

Override this function to update your object's position and appearance. * This is where most game rules and behavioral code will go. * * @param elapsed Seconds elapsed since the last frame. diff --git a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelCamera.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelCamera.java similarity index 98% rename from flixelgdx/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelCamera.java rename to flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelCamera.java index 5bc2ae3..575d215 100644 --- a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelCamera.java +++ b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelCamera.java @@ -10,8 +10,7 @@ import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.viewport.FitViewport; import com.badlogic.gdx.utils.viewport.Viewport; - -import static me.stringdotjar.flixelgdx.Flixel.getWindowSize; +import me.stringdotjar.flixelgdx.Flixel; /** * The camera class is used to display the game's visuals. @@ -34,7 +33,7 @@ public class FlixelCamera extends FlixelBasic { /** - * Any {@code FlixelCamera} with a zoom of 0 (the default constructor value) + * Any {@code FlixelCamera} with a zoom of 0 (the default constructor value) * will receive this zoom level instead. */ public static float defaultZoom = 1.0f; @@ -75,13 +74,13 @@ public class FlixelCamera extends FlixelBasic { * The X position of this camera's display in native screen pixels. * {@link #zoom} does NOT affect this value. */ - public float x = 0f; + public float x; /** * The Y position of this camera's display in native screen pixels. * {@link #zoom} does NOT affect this value. */ - public float y = 0f; + public float y; /** How wide the camera display is, in game pixels. */ public int width; @@ -118,10 +117,8 @@ public class FlixelCamera extends FlixelBasic { public Float maxScrollY; /** - * The dead zone rectangle, measured from the camera's upper left corner in game - * pixels. - * The camera will always keep the focus object inside this zone unless bumping - * against + * The dead zone rectangle, measured from the camera's upper left corner in game pixels. + * The camera will always keep the focus object inside this zone unless bumping against * scroll bounds. For rapid prototyping, use the preset styles with * {@link #follow(FlixelObject, FollowStyle, float)}. */ @@ -184,7 +181,7 @@ public class FlixelCamera extends FlixelBasic { * {@link OrthographicCamera} and {@link FitViewport}. */ public FlixelCamera() { - this(0f, 0f, (int) getWindowSize().x, (int) getWindowSize().y, 0f); + this(0f, 0f, Flixel.getWindowWidth(), Flixel.getWindowHeight(), 0f); } /** @@ -245,10 +242,8 @@ public FlixelCamera(float x, float y, int width, int height, float zoom) { * {@link Viewport} types. * *

- * If {@code viewport} is provided, its camera is used (the {@code camera} - * parameter is ignored). - * If only {@code camera} is provided, it is wrapped in a new - * {@link FitViewport}. + * If {@code viewport} is provided, its camera is used (the {@code camera} parameter is ignored). + * If only {@code camera} is provided, it is wrapped in a new {@link FitViewport}. * If neither is provided, an {@link OrthographicCamera} and {@link FitViewport} * are created. * @@ -264,8 +259,8 @@ public FlixelCamera(float x, float y, int width, int height, float zoom, Camera super(); this.x = x; this.y = y; - this.width = (width <= 0) ? (int) getWindowSize().x : width; - this.height = (height <= 0) ? (int) getWindowSize().y : height; + this.width = (width <= 0) ? Flixel.getWindowWidth() : width; + this.height = (height <= 0) ? Flixel.getWindowHeight() : height; if (viewport != null) { this.viewport = viewport; @@ -403,8 +398,7 @@ public void focusOn(Vector2 point) { /** * Snaps the camera to the current {@link #target} position with no easing, then - * clamps - * scroll to bounds. Useful after teleporting the target. + * clamps scroll to bounds. Useful after teleporting the target. */ public void snapToTarget() { if (target == null) { @@ -1080,8 +1074,8 @@ public FlixelCamera copyFrom(FlixelCamera other) { */ public void onResize() { viewport.update( - (int) getWindowSize().x, - (int) getWindowSize().y, + Flixel.getWindowWidth(), + Flixel.getWindowHeight(), true ); } diff --git a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelObject.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelObject.java similarity index 100% rename from flixelgdx/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelObject.java rename to flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelObject.java diff --git a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelState.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelState.java similarity index 100% rename from flixelgdx/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelState.java rename to flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelState.java diff --git a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/graphics/sprite/FlixelSprite.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/graphics/sprite/FlixelSprite.java similarity index 100% rename from flixelgdx/src/main/java/me/stringdotjar/flixelgdx/graphics/sprite/FlixelSprite.java rename to flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/graphics/sprite/FlixelSprite.java diff --git a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/graphics/text/FlixelFontRegistry.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/graphics/text/FlixelFontRegistry.java similarity index 100% rename from flixelgdx/src/main/java/me/stringdotjar/flixelgdx/graphics/text/FlixelFontRegistry.java rename to flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/graphics/text/FlixelFontRegistry.java diff --git a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/graphics/text/FlixelText.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/graphics/text/FlixelText.java similarity index 100% rename from flixelgdx/src/main/java/me/stringdotjar/flixelgdx/graphics/text/FlixelText.java rename to flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/graphics/text/FlixelText.java diff --git a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/group/FlixelGroup.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/group/FlixelGroup.java similarity index 100% rename from flixelgdx/src/main/java/me/stringdotjar/flixelgdx/group/FlixelGroup.java rename to flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/group/FlixelGroup.java diff --git a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/group/FlixelGroupable.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/group/FlixelGroupable.java similarity index 100% rename from flixelgdx/src/main/java/me/stringdotjar/flixelgdx/group/FlixelGroupable.java rename to flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/group/FlixelGroupable.java diff --git a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/group/FlixelSpriteGroup.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/group/FlixelSpriteGroup.java similarity index 100% rename from flixelgdx/src/main/java/me/stringdotjar/flixelgdx/group/FlixelSpriteGroup.java rename to flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/group/FlixelSpriteGroup.java diff --git a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/input/FlixelKey.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/input/FlixelKey.java similarity index 100% rename from flixelgdx/src/main/java/me/stringdotjar/flixelgdx/input/FlixelKey.java rename to flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/input/FlixelKey.java diff --git a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/signal/FlixelSignal.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/signal/FlixelSignal.java similarity index 100% rename from flixelgdx/src/main/java/me/stringdotjar/flixelgdx/signal/FlixelSignal.java rename to flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/signal/FlixelSignal.java diff --git a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/signal/FlixelSignalData.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/signal/FlixelSignalData.java similarity index 100% rename from flixelgdx/src/main/java/me/stringdotjar/flixelgdx/signal/FlixelSignalData.java rename to flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/signal/FlixelSignalData.java diff --git a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/tween/FlixelEase.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/tween/FlixelEase.java similarity index 100% rename from flixelgdx/src/main/java/me/stringdotjar/flixelgdx/tween/FlixelEase.java rename to flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/tween/FlixelEase.java diff --git a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/tween/FlixelTween.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/tween/FlixelTween.java similarity index 100% rename from flixelgdx/src/main/java/me/stringdotjar/flixelgdx/tween/FlixelTween.java rename to flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/tween/FlixelTween.java diff --git a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/tween/FlixelTweenManager.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/tween/FlixelTweenManager.java similarity index 100% rename from flixelgdx/src/main/java/me/stringdotjar/flixelgdx/tween/FlixelTweenManager.java rename to flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/tween/FlixelTweenManager.java diff --git a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/tween/settings/FlixelTweenSettings.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/tween/settings/FlixelTweenSettings.java similarity index 100% rename from flixelgdx/src/main/java/me/stringdotjar/flixelgdx/tween/settings/FlixelTweenSettings.java rename to flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/tween/settings/FlixelTweenSettings.java diff --git a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/tween/settings/FlixelTweenType.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/tween/settings/FlixelTweenType.java similarity index 100% rename from flixelgdx/src/main/java/me/stringdotjar/flixelgdx/tween/settings/FlixelTweenType.java rename to flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/tween/settings/FlixelTweenType.java diff --git a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/tween/type/FlixelNumTween.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/tween/type/FlixelNumTween.java similarity index 100% rename from flixelgdx/src/main/java/me/stringdotjar/flixelgdx/tween/type/FlixelNumTween.java rename to flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/tween/type/FlixelNumTween.java diff --git a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/tween/type/FlixelVarTween.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/tween/type/FlixelVarTween.java similarity index 100% rename from flixelgdx/src/main/java/me/stringdotjar/flixelgdx/tween/type/FlixelVarTween.java rename to flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/tween/type/FlixelVarTween.java diff --git a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/util/FlixelConstants.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/util/FlixelConstants.java similarity index 100% rename from flixelgdx/src/main/java/me/stringdotjar/flixelgdx/util/FlixelConstants.java rename to flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/util/FlixelConstants.java diff --git a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/util/FlixelMathUtil.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/util/FlixelMathUtil.java similarity index 100% rename from flixelgdx/src/main/java/me/stringdotjar/flixelgdx/util/FlixelMathUtil.java rename to flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/util/FlixelMathUtil.java diff --git a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/backend/FlixelPaths.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/util/FlixelPathsUtil.java similarity index 92% rename from flixelgdx/src/main/java/me/stringdotjar/flixelgdx/backend/FlixelPaths.java rename to flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/util/FlixelPathsUtil.java index 0612bd2..8764ac7 100644 --- a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/backend/FlixelPaths.java +++ b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/util/FlixelPathsUtil.java @@ -1,4 +1,4 @@ -package me.stringdotjar.flixelgdx.backend; +package me.stringdotjar.flixelgdx.util; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.files.FileHandle; @@ -9,7 +9,7 @@ import java.util.concurrent.ConcurrentHashMap; /** Utility class for simplifying asset paths and libGDX {@link FileHandle}s. */ -public final class FlixelPaths { +public final class FlixelPathsUtil { private static final Map audioPathCache = new ConcurrentHashMap<>(); @@ -51,7 +51,7 @@ public static FileHandle external(String path) { * @return An absolute filesystem path that MiniAudio can open. */ public static String resolveAudioPath(String path) { - return audioPathCache.computeIfAbsent(path, FlixelPaths::extractAudioPath); + return audioPathCache.computeIfAbsent(path, FlixelPathsUtil::extractAudioPath); } private static String extractAudioPath(String path) { @@ -71,5 +71,5 @@ private static String extractAudioPath(String path) { } } - private FlixelPaths() {} + private FlixelPathsUtil() {} } diff --git a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/util/FlixelReflectUtil.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/util/FlixelReflectUtil.java similarity index 100% rename from flixelgdx/src/main/java/me/stringdotjar/flixelgdx/util/FlixelReflectUtil.java rename to flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/util/FlixelReflectUtil.java diff --git a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/util/FlixelRuntimeUtil.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/util/FlixelRuntimeUtil.java similarity index 100% rename from flixelgdx/src/main/java/me/stringdotjar/flixelgdx/util/FlixelRuntimeUtil.java rename to flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/util/FlixelRuntimeUtil.java diff --git a/flixelgdx/lwjgl3/build.gradle b/flixelgdx/lwjgl3/build.gradle new file mode 100644 index 0000000..4e8bcd5 --- /dev/null +++ b/flixelgdx/lwjgl3/build.gradle @@ -0,0 +1,18 @@ +[compileJava, compileTestJava]*.options*.encoding = 'UTF-8' +eclipse.project.name = appName + '-flixelgdx-lwjgl3' + +apply plugin: "java-library" + +java { + sourceCompatibility = 17 + targetCompatibility = 17 +} + +dependencies { + api project(":flixelgdx:core") + + api "games.rednblack.miniaudio:gdx-miniaudio-platform:$miniaudioVersion:natives-desktop" + api "com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion" + api "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop" + api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop" +} diff --git a/flixelgdx/lwjgl3/src/main/java/me/stringdotjar/flixelgdx/backend/lwjgl3/FlixelLwjgl3Launcher.java b/flixelgdx/lwjgl3/src/main/java/me/stringdotjar/flixelgdx/backend/lwjgl3/FlixelLwjgl3Launcher.java new file mode 100644 index 0000000..4d27fea --- /dev/null +++ b/flixelgdx/lwjgl3/src/main/java/me/stringdotjar/flixelgdx/backend/lwjgl3/FlixelLwjgl3Launcher.java @@ -0,0 +1,55 @@ +package me.stringdotjar.flixelgdx.backend.lwjgl3; + +import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application; +import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration; +import com.badlogic.gdx.backends.lwjgl3.Lwjgl3WindowAdapter; +import me.stringdotjar.flixelgdx.Flixel; +import me.stringdotjar.flixelgdx.FlixelGame; + +/** + * Launches the desktop (LWJGL3) version of the Flixel game. + */ +public class FlixelLwjgl3Launcher { + + /** + * Launches the LWJGL3 version of the Flixel game with the given game instance. This should be called from the main + * method of the libGDX LWJGL3 launcher class, and the game instance should be created in the same general area. + * + * @param game The game instance to launch. This should already be initialized with the desired configuration values. + */ + public static void launch(FlixelGame game, String... icons) { + Flixel.initialize(game); + + Lwjgl3ApplicationConfiguration configuration = new Lwjgl3ApplicationConfiguration(); + configuration.setTitle(game.getTitle()); + configuration.useVsync(game.isVsync()); + configuration.setForegroundFPS(game.getFramerate()); + if (game.isFullscreen()) { + configuration.setFullscreenMode(Lwjgl3ApplicationConfiguration.getDisplayMode()); + } else { + configuration.setWindowedMode(game.getWindowWidth(), game.getWindowHeight()); + } + configuration.setWindowIcon(icons); + configuration.setWindowListener(new Lwjgl3WindowAdapter() { + @Override + public void focusGained() { + super.focusGained(); + Flixel.getGame().onWindowFocused(); + } + + @Override + public void focusLost() { + super.focusLost(); + Flixel.getGame().onWindowUnfocused(); + } + + @Override + public void iconified(boolean isIconified) { + super.iconified(isIconified); + Flixel.getGame().onWindowMinimized(isIconified); + } + }); + + new Lwjgl3Application(game, configuration); + } +} diff --git a/gradle.properties b/gradle.properties index 10c6471..1b2cd49 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,6 @@ org.gradle.configureondemand=false # Documented at: https://docs.gradle.org/current/userguide/command_line_interface.html#sec:command_line_logging org.gradle.logging.level=quiet anim8Version=0.5.3 -ktxVersion=1.13.1-rc1 utilsVersion=0.13.7 graalHelperVersion=2.0.1 android.useAndroidX=true diff --git a/lwjgl3/build.gradle b/lwjgl3/build.gradle index 533f910..bcd9bd5 100644 --- a/lwjgl3/build.gradle +++ b/lwjgl3/build.gradle @@ -25,12 +25,8 @@ if (JavaVersion.current().isJava9Compatible()) { } dependencies { - api "games.rednblack.miniaudio:gdx-miniaudio-platform:$miniaudioVersion:natives-desktop" - implementation "com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion" - implementation "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop" - implementation "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop" - implementation project(':polyverse') - implementation project(":flixelgdx") + implementation project(':polyverse') + implementation project(":flixelgdx:lwjgl3") if (enableGraalNative == 'true') { implementation "io.github.berstanio:gdx-svmhelper-backend-lwjgl3:$graalHelperVersion" diff --git a/lwjgl3/src/main/java/me/stringdotjar/polyverse/lwjgl3/Lwjgl3Launcher.java b/lwjgl3/src/main/java/me/stringdotjar/polyverse/lwjgl3/Lwjgl3Launcher.java index d5487df..92cc3df 100644 --- a/lwjgl3/src/main/java/me/stringdotjar/polyverse/lwjgl3/Lwjgl3Launcher.java +++ b/lwjgl3/src/main/java/me/stringdotjar/polyverse/lwjgl3/Lwjgl3Launcher.java @@ -1,9 +1,6 @@ package me.stringdotjar.polyverse.lwjgl3; -import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application; -import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration; -import com.badlogic.gdx.backends.lwjgl3.Lwjgl3WindowAdapter; -import me.stringdotjar.flixelgdx.Flixel; +import me.stringdotjar.flixelgdx.backend.lwjgl3.FlixelLwjgl3Launcher; import me.stringdotjar.polyverse.PolyverseApp; import me.stringdotjar.polyverse.InitState; import me.stringdotjar.polyverse.util.PolyverseConstants; @@ -15,61 +12,17 @@ public static void main(String[] args) { if (StartupHelper.startNewJvmIfRequired()) { // This handles macOS support and helps on Windows. return; } - createApplication(); - } - private static void createApplication() { PolyverseApp app = new PolyverseApp( PolyverseConstants.WINDOW_TITLE, PolyverseConstants.WINDOW_WIDTH, PolyverseConstants.WINDOW_HEIGHT, - new InitState() + new InitState(), + PolyverseConstants.FRAMERATE, + PolyverseConstants.VSYNC, + PolyverseConstants.FULLSCREEN ); - Flixel.initialize(app); // This is VERY important to do before creating the application! - var size = app.getWindowSize(); - new Lwjgl3Application(app, createWindowConfiguration(app.getTitle(), (int) size.x, (int) size.y)); - } - - private static Lwjgl3ApplicationConfiguration createWindowConfiguration(String title, int width, int height) { - Lwjgl3ApplicationConfiguration configuration = new Lwjgl3ApplicationConfiguration(); - configuration.setTitle(title); - // Vsync limits the frames per second to what your hardware can display, and helps eliminate - // screen tearing. This setting doesn't always work on Linux, so the line after is a safeguard. - configuration.useVsync(true); - // Limits FPS to the refresh rate of the currently active monitor, plus 1 to try to match - // fractional refresh rates. The Vsync setting above should limit the actual FPS to match the monitor. - configuration.setForegroundFPS(Lwjgl3ApplicationConfiguration.getDisplayMode().refreshRate + 1); - // If you remove the above line and set Vsync to false, you can get unlimited FPS, which can be - // useful for testing performance, but can also be very stressful to some hardware. - // You may also need to configure GPU drivers to fully disable Vsync; this can cause screen tearing. - configuration.setWindowedMode(width, height); - // You can change these files; they are in lwjgl3/src/main/resources/ . - // They can also be loaded from the root of assets/ . - configuration.setWindowIcon("icon128.png", "icon64.png", "icon32.png", "icon16.png"); - - // Add listeners for window focus and minimization events. - // Only add or change code here if you MUST change something pre-config wise that simply - // cannot be done in the core folder! - configuration.setWindowListener(new Lwjgl3WindowAdapter() { - @Override - public void focusGained() { - super.focusGained(); - Flixel.getGame().onWindowFocused(); - } - - @Override - public void focusLost() { - super.focusLost(); - Flixel.getGame().onWindowUnfocused(); - } - - @Override - public void iconified(boolean isIconified) { - super.iconified(isIconified); - Flixel.getGame().onWindowMinimized(isIconified); - } - }); - return configuration; + FlixelLwjgl3Launcher.launch(app, "icon128.png", "icon64.png", "icon32.png", "icon16.png"); } } diff --git a/polyverse/build.gradle b/polyverse/build.gradle index f0f4d2e..983a7e0 100644 --- a/polyverse/build.gradle +++ b/polyverse/build.gradle @@ -2,16 +2,10 @@ eclipse.project.name = appName + '-polyverse' dependencies { - api "com.badlogicgames.gdx:gdx-freetype:$gdxVersion" - api "com.badlogicgames.gdx:gdx:$gdxVersion" - api "com.github.tommyettinger:anim8-gdx:$anim8Version" - api "com.github.tommyettinger:libgdx-utils:$utilsVersion" - api "io.github.libktx:ktx-freetype:$ktxVersion" - api "games.rednblack.miniaudio:miniaudio:$miniaudioVersion" - api project(":flixelgdx") - - implementation "org.apache.groovy:groovy:5.0.3" - implementation "org.jetbrains:annotations:26.0.2-1" + implementation project(":flixelgdx:core") + + implementation "org.apache.groovy:groovy:5.0.4" + implementation "org.jetbrains:annotations:26.1.0" if (enableGraalNative == 'true') { implementation "io.github.berstanio:gdx-svmhelper-annotations:$graalHelperVersion" diff --git a/polyverse/src/main/java/me/stringdotjar/polyverse/InitState.java b/polyverse/src/main/java/me/stringdotjar/polyverse/InitState.java index a5844dd..a2d2cbe 100644 --- a/polyverse/src/main/java/me/stringdotjar/polyverse/InitState.java +++ b/polyverse/src/main/java/me/stringdotjar/polyverse/InitState.java @@ -3,7 +3,7 @@ import me.stringdotjar.flixelgdx.graphics.FlixelState; import me.stringdotjar.flixelgdx.graphics.text.FlixelFontRegistry; import me.stringdotjar.flixelgdx.Flixel; -import me.stringdotjar.flixelgdx.backend.FlixelPaths; +import me.stringdotjar.flixelgdx.util.FlixelPathsUtil; import me.stringdotjar.polyverse.menus.TitleState; public class InitState extends FlixelState { @@ -12,8 +12,8 @@ public class InitState extends FlixelState { public void create() { super.create(); - FlixelFontRegistry.register("vcr", FlixelPaths.fontAsset("vcr")); - FlixelFontRegistry.register("5by7", FlixelPaths.fontAsset("5by7")); + FlixelFontRegistry.register("vcr", FlixelPathsUtil.fontAsset("vcr")); + FlixelFontRegistry.register("5by7", FlixelPathsUtil.fontAsset("5by7")); Flixel.switchState(new TitleState()); } diff --git a/polyverse/src/main/java/me/stringdotjar/polyverse/PolyverseApp.java b/polyverse/src/main/java/me/stringdotjar/polyverse/PolyverseApp.java index fb526f8..e26d838 100644 --- a/polyverse/src/main/java/me/stringdotjar/polyverse/PolyverseApp.java +++ b/polyverse/src/main/java/me/stringdotjar/polyverse/PolyverseApp.java @@ -3,7 +3,7 @@ import com.badlogic.gdx.Input; import me.stringdotjar.flixelgdx.Flixel; import me.stringdotjar.flixelgdx.FlixelGame; -import me.stringdotjar.flixelgdx.backend.FlixelPaths; +import me.stringdotjar.flixelgdx.util.FlixelPathsUtil; import me.stringdotjar.flixelgdx.graphics.FlixelState; import me.stringdotjar.polyverse.script.type.Script; import me.stringdotjar.polyverse.script.type.SystemScript; @@ -15,8 +15,8 @@ public class PolyverseApp extends FlixelGame { private float lastVolume = 1.0f; - public PolyverseApp(String title, int width, int height, FlixelState initialScreen) { - super(title, width, height, initialScreen); + public PolyverseApp(String title, int width, int height, FlixelState initialScreen, int framerate, boolean vsync, boolean fullscreen) { + super(title, width, height, initialScreen, framerate, vsync, fullscreen); } @Override @@ -70,8 +70,8 @@ private void configureScriptSystem() { Polyverse.registerScriptType(Script.class); // Master type, DO NOT REMOVE THIS! Polyverse.registerScriptType(SystemScript.class); - Polyverse.registerScript(FlixelPaths.asset("test.groovy")); - Polyverse.registerScript(FlixelPaths.asset("another_test.groovy")); - Polyverse.registerScript(FlixelPaths.asset("oml.groovy")); + Polyverse.registerScript(FlixelPathsUtil.asset("test.groovy")); + Polyverse.registerScript(FlixelPathsUtil.asset("another_test.groovy")); + Polyverse.registerScript(FlixelPathsUtil.asset("oml.groovy")); } } diff --git a/polyverse/src/main/java/me/stringdotjar/polyverse/menus/TitleState.java b/polyverse/src/main/java/me/stringdotjar/polyverse/menus/TitleState.java index 8d07549..d0b83e6 100644 --- a/polyverse/src/main/java/me/stringdotjar/polyverse/menus/TitleState.java +++ b/polyverse/src/main/java/me/stringdotjar/polyverse/menus/TitleState.java @@ -5,7 +5,7 @@ import games.rednblack.miniaudio.MASound; import me.stringdotjar.flixelgdx.Flixel; -import me.stringdotjar.flixelgdx.backend.FlixelPaths; +import me.stringdotjar.flixelgdx.util.FlixelPathsUtil; import me.stringdotjar.flixelgdx.graphics.FlixelCamera; import me.stringdotjar.flixelgdx.graphics.FlixelState; import me.stringdotjar.flixelgdx.graphics.FlixelCamera.FollowStyle; @@ -37,8 +37,8 @@ public class TitleState extends FlixelState { public void create() { super.create(); - var t = FlixelPaths.sharedImageAsset("noteStrumline"); - var xml = FlixelPaths.shared("images/noteStrumline.xml"); + var t = FlixelPathsUtil.sharedImageAsset("noteStrumline"); + var xml = FlixelPathsUtil.shared("images/noteStrumline.xml"); logo = new FlixelSprite().loadSparrowFrames(t, xml); logo.addAnimationByPrefix("test", "confirmDown", 24, false); // add(logo); @@ -47,10 +47,10 @@ public void create() { // Flixel.playMusic("preload/music/freakyMenu/freakyMenu.ogg", 0.5f); spriteGroup = new FlixelSpriteGroup(0, 200f, 0f); - s1 = new FlixelSprite().loadGraphic(FlixelPaths.sharedImageAsset("transitionSwag/stickers-set-1/bfSticker1")); - s2 = new FlixelSprite().loadGraphic(FlixelPaths.sharedImageAsset("transitionSwag/stickers-set-1/bfSticker2")); - s3 = new FlixelSprite().loadGraphic(FlixelPaths.sharedImageAsset("transitionSwag/stickers-set-1/bfSticker3")); - s4 = new FlixelSprite().loadGraphic(FlixelPaths.sharedImageAsset("transitionSwag/stickers-set-1/gfSticker1")); + s1 = new FlixelSprite().loadGraphic(FlixelPathsUtil.sharedImageAsset("transitionSwag/stickers-set-1/bfSticker1")); + s2 = new FlixelSprite().loadGraphic(FlixelPathsUtil.sharedImageAsset("transitionSwag/stickers-set-1/bfSticker2")); + s3 = new FlixelSprite().loadGraphic(FlixelPathsUtil.sharedImageAsset("transitionSwag/stickers-set-1/bfSticker3")); + s4 = new FlixelSprite().loadGraphic(FlixelPathsUtil.sharedImageAsset("transitionSwag/stickers-set-1/gfSticker1")); s1.setX(200); s2.setX(-200); s3.setX(200); @@ -204,8 +204,8 @@ public void update(float elapsed) { } Flixel.getCamera().setZoom(MathUtils.lerp( - FlixelCamera.defaultZoom, - Flixel.getCamera().getZoom(), + FlixelCamera.defaultZoom, + Flixel.getCamera().getZoom(), (float) Math.exp(-elapsed * 3.125))); if (Flixel.keyJustPressed(FlixelKey.T)) { diff --git a/polyverse/src/main/java/me/stringdotjar/polyverse/util/PolyverseConstants.java b/polyverse/src/main/java/me/stringdotjar/polyverse/util/PolyverseConstants.java index e1fd85e..0f0642a 100644 --- a/polyverse/src/main/java/me/stringdotjar/polyverse/util/PolyverseConstants.java +++ b/polyverse/src/main/java/me/stringdotjar/polyverse/util/PolyverseConstants.java @@ -22,5 +22,20 @@ public final class PolyverseConstants { */ public static final int WINDOW_HEIGHT = 720; + /** + * The framerate of the engine's game loop. + */ + public static final int FRAMERATE = 60; + + /** + * Whether the engine should use VSync to limit the framerate to the monitor's refresh rate. + */ + public static final boolean VSYNC = true; + + /** + * Whether the engine should start in fullscreen mode. + */ + public static final boolean FULLSCREEN = false; + private PolyverseConstants() {} } diff --git a/settings.gradle b/settings.gradle index f46f132..0684d9f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -5,4 +5,9 @@ plugins { // A list of which subprojects to load as part of the same larger project. // You can remove Strings from the list and reload the Gradle project // if you want to temporarily disable a subproject. -include 'polyverse', 'flixelgdx', 'lwjgl3', 'android' + +// Polyverse and libGDX projects. +include 'polyverse', 'lwjgl3', 'android' + +// FlixelGDX projects. +include 'flixelgdx:core', 'flixelgdx:lwjgl3', 'flixelgdx:android'