diff --git a/.github/workflows/latest_release.yml b/.github/workflows/latest_release.yml new file mode 100644 index 0000000..8c45142 --- /dev/null +++ b/.github/workflows/latest_release.yml @@ -0,0 +1,41 @@ +name: Package latest release + +on: + push: + branches: [ master ] + tags: + - '*' + +jobs: + build-and-publish: + runs-on: ubuntu-latest + steps: + - name: Checkout source code + uses: actions/checkout@v1 + + - name: Setup java compiler + uses: actions/setup-java@v1 + with: + java-version: 1.8 + + - name: Fix gradlew file permissions + run: chmod +x ./gradlew + + - name: Run gradle script + uses: eskatos/gradle-command-action@v1 + with: + arguments: package + + - name: Assemble package + run: zip -r volynov.zip build/Volynov-0.0.0/* + + - name: It should create a release with assets README.md and LICENCE + uses: Xotl/cool-github-releases@v1 + with: + mode: update + tag_name: latest-build + release_name: "Latest build" + body_mrkdwn: "### Download the volynov.zip file\n Unzip it into a folder, and run the run.bat file" + assets: volynov.zip + replace_assets: true + github_token: ${{ github.token }} diff --git a/build.gradle.kts b/build.gradle.kts index 012e691..c24e841 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,7 +1,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { - kotlin("jvm") version "1.3.41" + kotlin("jvm") version "1.3.72" } group = "blaarkies" @@ -11,7 +11,7 @@ repositories { mavenCentral() } -val kotlinVersion = "1.3.10" +val kotlinVersion = "1.3.72" val lwjglVersion = "3.2.3" val lwjglNatives = "natives-windows" @@ -24,49 +24,53 @@ dependencies { testImplementation("org.junit.jupiter:junit-jupiter:5.5.2") implementation(platform("org.lwjgl:lwjgl-bom:$lwjglVersion")) - val lwjglList = listOf( - arrayOf("lwjgl", true), - // arrayOf("lwjgl-assimp", true), - // arrayOf("lwjgl-bgfx", true), - // arrayOf("lwjgl-cuda", false), - // arrayOf("lwjgl-egl", false), - arrayOf("lwjgl-glfw", true), - arrayOf("lwjgl-jawt", false), - // arrayOf("lwjgl-jemalloc", true), - // arrayOf("lwjgl-libdivide", true), - // arrayOf("lwjgl-llvm", true), - // arrayOf("lwjgl-lmdb", true), - // arrayOf("lwjgl-lz4", true), - // arrayOf("lwjgl-meow", true), - // arrayOf("lwjgl-nanovg", true), - // arrayOf("lwjgl-nfd", true), - // arrayOf("lwjgl-nuklear", true), - // arrayOf("lwjgl-odbc", false), - // arrayOf("lwjgl-openal", true), - // arrayOf("lwjgl-opencl", false), - arrayOf("lwjgl-opengl", true), - // arrayOf("lwjgl-opengles", true), - // arrayOf("lwjgl-openvr", true), - // arrayOf("lwjgl-opus", true), - // arrayOf("lwjgl-ovr", true), - // arrayOf("lwjgl-par", true), - // arrayOf("lwjgl-remotery", true), - // arrayOf("lwjgl-rpmalloc", true), - // arrayOf("lwjgl-shaderc", true), - // arrayOf("lwjgl-sse", true), - arrayOf("lwjgl-stb", true) - // arrayOf("lwjgl-tinyexr", true), - // arrayOf("lwjgl-tinyfd", true), - // arrayOf("lwjgl-tootle", true), - // arrayOf("lwjgl-vma", true), - // arrayOf("lwjgl-vulkan", false), - // arrayOf("lwjgl-xxhash", true), - // arrayOf("lwjgl-yoga", true), - // arrayOf("lwjgl-zstd", true) + listOf( + "lwjgl", "1", + // "lwjgl-assimp", "1", + // "lwjgl-bgfx", "1", + // "lwjgl-cuda", "0", + // "lwjgl-egl", "0", + "lwjgl-glfw", "1", + "lwjgl-jawt", "0", + "lwjgl-jemalloc", "1", + // "lwjgl-libdivide", "1", + // "lwjgl-llvm", "1", + // "lwjgl-lmdb", "1", + // "lwjgl-lz4", "1", + // "lwjgl-meow", "1", + // "lwjgl-nanovg", "1", + // "lwjgl-nfd", "1", + // "lwjgl-nuklear", "1", + // "lwjgl-odbc", "0", + // "lwjgl-openal", "1", + // "lwjgl-opencl", "0", + "lwjgl-opengl", "1", + // "lwjgl-opengles", "1", + // "lwjgl-openvr", "1", + // "lwjgl-opus", "1", + // "lwjgl-ovr", "1", + // "lwjgl-par", "1", + // "lwjgl-remotery", "1", + // "lwjgl-rpmalloc", "1", + // "lwjgl-shaderc", "1", + // "lwjgl-sse", "1", + "lwjgl-stb", "1" + // "lwjgl-tinyexr", "1", + // "lwjgl-tinyfd", "1", + // "lwjgl-tootle", "1", + // "lwjgl-vma", "1", + // "lwjgl-vulkan", "0", + // "lwjgl-xxhash", "1", + // "lwjgl-yoga", "1", + // "lwjgl-zstd", "1) ) - lwjglList.forEach { implementation("org.lwjgl", it[0].toString()) } - lwjglList.filter { it[1] == true } - .forEach { runtimeOnly("org.lwjgl", it[0].toString(), classifier = lwjglNatives) } + .chunked(2) + .forEach { + implementation("org.lwjgl", it[0]) + if (it[1] == "1") { + runtimeOnly("org.lwjgl", it[0], classifier = lwjglNatives) + } + } } sourceSets { @@ -99,9 +103,13 @@ tasks { mustRunAfter("uberJar") doLast { File("$buildDir/libs/run.bat") - .writeText("""|chcp 65001 - |java -Dfile.encoding=UTF-8 -Dorg.lwjgl.util.Debug=true -jar ./volynov-$version-uber.jar - |pause + .writeText("""|java -Dorg.lwjgl.util.Debug=true -jar .\volynov-$version-uber.jar + |pause """.trimMargin()) +// File("$buildDir/libs/run_with_jbr_here.bat") +// .writeText("""|.\jbr\bin\java.exe -Dorg.lwjgl.util.Debug=true -jar .\volynov-$version-uber.jar +// |pause """.trimMargin()) + File("$buildDir/libs/config.txt") + .writeText("""|isDebugMode=0 """.trimMargin()) } } @@ -121,7 +129,6 @@ tasks { from(sourceSets.main.get().output) from({ configurations.runtimeClasspath.get() - .filter { it.name.endsWith("jar") } .map { zipTree(it) } }) } diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index f4ad33a..fabfc94 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -1,12 +1,21 @@ import app.AppLogic +import app.AppRunner import app.IGameLogic import kotlinx.coroutines.runBlocking +import java.io.File import kotlin.system.exitProcess fun main() = runBlocking { try { + val configLine = File("config.txt").let { + if (it.exists()) it.readLines()[0] else "isDebugMode=1" + } + val isDebugMode = (configLine == "isDebugMode=1") + val screenX = if (isDebugMode) 800 else 1920 + val screenY = if (isDebugMode) 800 else 1080 + val gameLogic: IGameLogic = AppLogic() - val gameEngine = AppRunner("Volynov", 1920, 1080, true, gameLogic) + val gameEngine = AppRunner("Volynov", screenX, screenY, true, gameLogic, debugMode = isDebugMode) gameEngine.run() } catch (exception: Exception) { exception.printStackTrace() diff --git a/src/main/kotlin/app/AppLogic.kt b/src/main/kotlin/app/AppLogic.kt index 9a7db9c..7433b0f 100644 --- a/src/main/kotlin/app/AppLogic.kt +++ b/src/main/kotlin/app/AppLogic.kt @@ -1,9 +1,8 @@ package app +import display.Window import display.draw.Drawer -import display.draw.TextureHolder import display.graphic.Renderer -import display.Window import engine.GameState import game.GamePhaseHandler import input.InputHandler diff --git a/src/main/kotlin/app/AppRunner.kt b/src/main/kotlin/app/AppRunner.kt index 6d50813..4aab88b 100644 --- a/src/main/kotlin/app/AppRunner.kt +++ b/src/main/kotlin/app/AppRunner.kt @@ -1,4 +1,5 @@ -import app.IGameLogic +package app + import display.Window import utility.CustomTimer @@ -14,7 +15,8 @@ class AppRunner( width, height, vSync - ) + ), + private val debugMode: Boolean ) : Runnable { private val targetFps = 60 @@ -23,7 +25,7 @@ class AppRunner( override fun run() { try { - init() + init(debugMode = debugMode) gameLoop() } catch (exception: Exception) { exception.printStackTrace() @@ -33,8 +35,8 @@ class AppRunner( } @Throws(Exception::class) - private fun init() { - window.init() + private fun init(debugMode: Boolean) { + window.init(debugMode = debugMode) customTimer.init() gameLogic.init(window) } diff --git a/src/main/kotlin/display/Window.kt b/src/main/kotlin/display/Window.kt index 62140ef..e3467fd 100644 --- a/src/main/kotlin/display/Window.kt +++ b/src/main/kotlin/display/Window.kt @@ -1,13 +1,12 @@ package display +import display.events.KeyboardEvent import display.events.MouseButtonEvent import display.events.MouseScrollEvent import io.reactivex.subjects.PublishSubject import org.jbox2d.common.Vec2 import org.lwjgl.BufferUtils import org.lwjgl.glfw.GLFW -import org.lwjgl.glfw.GLFW.glfwGetKey -import org.lwjgl.glfw.GLFW.glfwGetKeyName import org.lwjgl.glfw.GLFWErrorCallback import org.lwjgl.opengl.GL import org.lwjgl.opengl.GL11 @@ -15,7 +14,6 @@ import org.lwjgl.opengl.GL11.* import org.lwjgl.system.Callback import org.lwjgl.system.MemoryUtil import utility.Common.makeVec2 -import java.nio.DoubleBuffer class Window(private val title: String, var width: Int, var height: Int, private var vSync: Boolean) { @@ -29,7 +27,7 @@ class Window(private val title: String, var width: Int, var height: Int, private val mouseScrollEvent = PublishSubject.create() val textInputEvent = PublishSubject.create() - fun init() { + fun init(debugMode: Boolean) { // Setup an error callback. The default implementation // will print the error message in System.err. GLFW.glfwSetErrorCallback(GLFWErrorCallback.createPrint(System.err)) @@ -46,22 +44,24 @@ class Window(private val title: String, var width: Int, var height: Int, private GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_FORWARD_COMPAT, GL11.GL_TRUE) GLFW.glfwWindowHint(GLFW.GLFW_SAMPLES, 4) // anti-aliasing - // Create the window - windowHandle = GLFW.glfwCreateWindow(width, height, title, GLFW.glfwGetPrimaryMonitor(), MemoryUtil.NULL) - // windowHandle = GLFW.glfwCreateWindow(width, height, title, MemoryUtil.NULL, MemoryUtil.NULL) - // if (windowHandle == MemoryUtil.NULL) { - // throw RuntimeException("Failed to create the GLFW window") - // } - // Setup resize callback - GLFW.glfwSetFramebufferSizeCallback(windowHandle) { _, width, height -> - this.width = width - this.height = height - } + when (debugMode) { + false -> windowHandle = + GLFW.glfwCreateWindow(width, height, title, GLFW.glfwGetPrimaryMonitor(), MemoryUtil.NULL) + true -> { + windowHandle = GLFW.glfwCreateWindow(width, height, title, MemoryUtil.NULL, MemoryUtil.NULL) + if (windowHandle == MemoryUtil.NULL) { + throw RuntimeException("Failed to create the GLFW window") + } + GLFW.glfwSetFramebufferSizeCallback(windowHandle) { _, width, height -> + this.width = width + this.height = height + } - // Get the resolution of the primary monitor - // val videoMode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor())!! - // Center our window - // GLFW.glfwSetWindowPos(windowHandle, (videoMode.width() - width) / 2, (videoMode.height() - height) / 2) + val videoRes = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor())!! + GLFW.glfwSetWindowPos(windowHandle, (videoRes.width() - width) / 2, (videoRes.height() - height) / 2) + } + + } GLFW.glfwMakeContextCurrent(windowHandle) // Make the OpenGL context current if (isVSync()) { // Enable v-sync diff --git a/src/main/kotlin/display/draw/Drawer.kt b/src/main/kotlin/display/draw/Drawer.kt index a2b492b..1f3624b 100644 --- a/src/main/kotlin/display/draw/Drawer.kt +++ b/src/main/kotlin/display/draw/Drawer.kt @@ -12,8 +12,6 @@ import engine.physics.CellLocation import engine.physics.GravityCell import game.GamePlayer import org.jbox2d.common.Vec2 -import org.lwjgl.opengl.GL11 -import org.lwjgl.opengl.GL12 import utility.Common.makeVec2 import utility.Common.makeVec2Circle import utility.Common.vectorUnit diff --git a/src/main/kotlin/display/events/KeyboardEvent.kt b/src/main/kotlin/display/events/KeyboardEvent.kt index aecacf6..9ada253 100644 --- a/src/main/kotlin/display/events/KeyboardEvent.kt +++ b/src/main/kotlin/display/events/KeyboardEvent.kt @@ -1,3 +1,3 @@ -package display +package display.events class KeyboardEvent(val key: Int, val scancode: Int, val action: Int, val mods: Int) diff --git a/src/main/kotlin/display/graphic/Renderer.kt b/src/main/kotlin/display/graphic/Renderer.kt index 8320a4c..bb685e3 100644 --- a/src/main/kotlin/display/graphic/Renderer.kt +++ b/src/main/kotlin/display/graphic/Renderer.kt @@ -1,6 +1,5 @@ package display.graphic -import Matrix4f import display.text.Font import display.text.TextJustify import input.CameraView @@ -14,6 +13,7 @@ import org.lwjgl.system.MemoryUtil import utility.Common import utility.Common.getSafePath import utility.Common.vectorUnit +import utility.math.Matrix4f import java.awt.FontFormatException import java.io.FileInputStream import java.io.IOException @@ -46,9 +46,11 @@ class Renderer { val fontPath = getSafePath("./fonts/ALBMT___.TTF") Font(FileInputStream(fontPath), 80) } catch (ex: FontFormatException) { + ex.printStackTrace() Logger.getLogger(Renderer::class.java.name).log(Level.CONFIG, null, ex) Font() } catch (ex: IOException) { + ex.printStackTrace() Logger.getLogger(Renderer::class.java.name).log(Level.CONFIG, null, ex) Font() } diff --git a/src/main/kotlin/display/graphic/ShaderProgram.kt b/src/main/kotlin/display/graphic/ShaderProgram.kt index 26317f0..b092571 100644 --- a/src/main/kotlin/display/graphic/ShaderProgram.kt +++ b/src/main/kotlin/display/graphic/ShaderProgram.kt @@ -1,14 +1,9 @@ package display.graphic -import Matrix2f -import Matrix3f -import Matrix4f -import Vector2f -import Vector3f -import Vector4f import org.lwjgl.opengl.GL20.* import org.lwjgl.opengl.GL30.glBindFragDataLocation import org.lwjgl.system.MemoryStack +import utility.math.* class ShaderProgram { diff --git a/src/main/kotlin/display/graphic/Texture.kt b/src/main/kotlin/display/graphic/Texture.kt index db28d7f..fc9a0d0 100644 --- a/src/main/kotlin/display/graphic/Texture.kt +++ b/src/main/kotlin/display/graphic/Texture.kt @@ -2,10 +2,9 @@ package display.graphic import org.lwjgl.BufferUtils import org.lwjgl.opengl.GL11.* -import org.lwjgl.stb.STBImage.* +import org.lwjgl.stb.STBImage import org.lwjgl.system.MemoryStack import utility.Common.getSafePath -import java.io.File import java.nio.ByteBuffer class Texture { @@ -75,9 +74,11 @@ class Texture { val h = stack.mallocInt(1) val comp = stack.mallocInt(1) - stbi_set_flip_vertically_on_load(true) - image = stbi_load(safePath, w, h, comp, 0) - ?: throw RuntimeException("Cannot load texture file at $safePath \n${stbi_failure_reason()}") + STBImage.stbi_set_flip_vertically_on_load(true) + image = STBImage.stbi_load(safePath, w, h, comp, 0) + ?: throw RuntimeException(""" + |Cannot load texture file at [$safePath] + |${STBImage.stbi_failure_reason()}""".trimMargin()) width = w.get() height = h.get() diff --git a/src/main/kotlin/display/gui/GuiButton.kt b/src/main/kotlin/display/gui/GuiButton.kt index 6b97b32..4770f08 100644 --- a/src/main/kotlin/display/gui/GuiButton.kt +++ b/src/main/kotlin/display/gui/GuiButton.kt @@ -7,7 +7,6 @@ import display.graphic.Color import display.graphic.SnipRegion import display.text.TextJustify import org.jbox2d.common.Vec2 -import utility.Common.vectorUnit class GuiButton( drawer: Drawer, diff --git a/src/main/kotlin/engine/physics/Gravity.kt b/src/main/kotlin/engine/physics/Gravity.kt index 99e13c6..6526b9c 100644 --- a/src/main/kotlin/engine/physics/Gravity.kt +++ b/src/main/kotlin/engine/physics/Gravity.kt @@ -45,7 +45,7 @@ object Gravity { fun addGravityForces(freeBodies: List): Pair, Float> = runBlocking { val gravityMap = HashMap() - val resolution = 2f + val resolution = 20f//2f freeBodies.forEach { val x = it.worldBody.position.x val y = it.worldBody.position.y diff --git a/src/main/kotlin/game/GamePhaseHandler.kt b/src/main/kotlin/game/GamePhaseHandler.kt index f05c5d0..2df056f 100644 --- a/src/main/kotlin/game/GamePhaseHandler.kt +++ b/src/main/kotlin/game/GamePhaseHandler.kt @@ -1,6 +1,6 @@ package game -import display.KeyboardEvent +import display.events.KeyboardEvent import display.Window import display.draw.Drawer import display.draw.TextureEnum @@ -50,7 +50,6 @@ class GamePhaseHandler(private val gameState: GameState, val drawer: Drawer) { 0 -> setupMainMenu() 1 -> setupMainMenuSelectPlayers() 2 -> { - currentPhase = GamePhases.PLAYERS_PICK_SHIELDS isTransitioning = false gameState.reset() diff --git a/src/main/kotlin/game/PlayerAim.kt b/src/main/kotlin/game/PlayerAim.kt index d133228..108186f 100644 --- a/src/main/kotlin/game/PlayerAim.kt +++ b/src/main/kotlin/game/PlayerAim.kt @@ -1,6 +1,5 @@ package game -import utility.Common import utility.Common.Pi2 import utility.Common.radianToDegree diff --git a/src/main/kotlin/input/CameraView.kt b/src/main/kotlin/input/CameraView.kt index 5217306..723bc73 100644 --- a/src/main/kotlin/input/CameraView.kt +++ b/src/main/kotlin/input/CameraView.kt @@ -1,10 +1,10 @@ package input -import Matrix4f import display.Window import engine.freeBody.FreeBody import org.jbox2d.common.Vec2 import utility.Common.getTimingFunctionSigmoid +import utility.math.Matrix4f import kotlin.math.pow class CameraView(private val window: Window) { diff --git a/src/main/kotlin/input/InputHandler.kt b/src/main/kotlin/input/InputHandler.kt index b1fd179..9aa7235 100644 --- a/src/main/kotlin/input/InputHandler.kt +++ b/src/main/kotlin/input/InputHandler.kt @@ -2,7 +2,6 @@ package input import display.events.MouseButtonEvent import display.Window -import display.events.MouseScrollEvent import game.GamePhaseHandler import io.reactivex.subjects.PublishSubject import org.jbox2d.common.Vec2 diff --git a/src/main/kotlin/utility/Common.kt b/src/main/kotlin/utility/Common.kt index 47dc789..61df47b 100644 --- a/src/main/kotlin/utility/Common.kt +++ b/src/main/kotlin/utility/Common.kt @@ -1,6 +1,5 @@ package utility -import org.jbox2d.common.MathUtils import org.jbox2d.common.Vec2 import java.io.File import java.nio.DoubleBuffer diff --git a/src/main/kotlin/utility/math/Matrix2f.kt b/src/main/kotlin/utility/math/Matrix2f.kt index 85ebf89..a7c6196 100644 --- a/src/main/kotlin/utility/math/Matrix2f.kt +++ b/src/main/kotlin/utility/math/Matrix2f.kt @@ -1,3 +1,5 @@ +package utility.math + import java.nio.FloatBuffer class Matrix2f { diff --git a/src/main/kotlin/utility/math/Matrix3f.kt b/src/main/kotlin/utility/math/Matrix3f.kt index b86d536..a98f49f 100644 --- a/src/main/kotlin/utility/math/Matrix3f.kt +++ b/src/main/kotlin/utility/math/Matrix3f.kt @@ -1,3 +1,5 @@ +package utility.math + import java.nio.FloatBuffer class Matrix3f { diff --git a/src/main/kotlin/utility/math/Matrix4f.kt b/src/main/kotlin/utility/math/Matrix4f.kt index cb79d98..8dd8e4e 100644 --- a/src/main/kotlin/utility/math/Matrix4f.kt +++ b/src/main/kotlin/utility/math/Matrix4f.kt @@ -1,3 +1,5 @@ +package utility.math + import java.nio.FloatBuffer class Matrix4f { diff --git a/src/main/kotlin/utility/math/Vector2f.kt b/src/main/kotlin/utility/math/Vector2f.kt index 76209c4..0162503 100644 --- a/src/main/kotlin/utility/math/Vector2f.kt +++ b/src/main/kotlin/utility/math/Vector2f.kt @@ -1,3 +1,5 @@ +package utility.math + import java.nio.FloatBuffer class Vector2f { diff --git a/src/main/kotlin/utility/math/Vector3f.kt b/src/main/kotlin/utility/math/Vector3f.kt index 1401e82..b4ebcb1 100644 --- a/src/main/kotlin/utility/math/Vector3f.kt +++ b/src/main/kotlin/utility/math/Vector3f.kt @@ -1,3 +1,5 @@ +package utility.math + import java.nio.FloatBuffer class Vector3f { diff --git a/src/main/kotlin/utility/math/Vector4f.kt b/src/main/kotlin/utility/math/Vector4f.kt index cbff08e..330b726 100644 --- a/src/main/kotlin/utility/math/Vector4f.kt +++ b/src/main/kotlin/utility/math/Vector4f.kt @@ -1,3 +1,5 @@ +package utility.math + import java.nio.FloatBuffer class Vector4f {