Skip to content

Commit

Permalink
Merge pull request #30 from Blaarkies/improve-build-script
Browse files Browse the repository at this point in the history
Improve build script
  • Loading branch information
Blaarkies authored Apr 23, 2020
2 parents f91b25e + 8719644 commit c2b0d56
Show file tree
Hide file tree
Showing 24 changed files with 159 additions and 98 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/latest_release.yml
Original file line number Diff line number Diff line change
@@ -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 }}
103 changes: 55 additions & 48 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"

Expand All @@ -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 {
Expand Down Expand Up @@ -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())
}
}
Expand All @@ -121,7 +129,6 @@ tasks {
from(sourceSets.main.get().output)
from({
configurations.runtimeClasspath.get()
.filter { it.name.endsWith("jar") }
.map { zipTree(it) }
})
}
Expand Down
11 changes: 10 additions & 1 deletion src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
3 changes: 1 addition & 2 deletions src/main/kotlin/app/AppLogic.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 7 additions & 5 deletions src/main/kotlin/app/AppRunner.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import app.IGameLogic
package app

import display.Window
import utility.CustomTimer

Expand All @@ -14,7 +15,8 @@ class AppRunner(
width,
height,
vSync
)
),
private val debugMode: Boolean
) : Runnable {

private val targetFps = 60
Expand All @@ -23,7 +25,7 @@ class AppRunner(

override fun run() {
try {
init()
init(debugMode = debugMode)
gameLoop()
} catch (exception: Exception) {
exception.printStackTrace()
Expand All @@ -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)
}
Expand Down
38 changes: 19 additions & 19 deletions src/main/kotlin/display/Window.kt
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
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
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) {

Expand All @@ -29,7 +27,7 @@ class Window(private val title: String, var width: Int, var height: Int, private
val mouseScrollEvent = PublishSubject.create<MouseScrollEvent>()
val textInputEvent = PublishSubject.create<String>()

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))
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/main/kotlin/display/draw/Drawer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/display/events/KeyboardEvent.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package display
package display.events

class KeyboardEvent(val key: Int, val scancode: Int, val action: Int, val mods: Int)
4 changes: 3 additions & 1 deletion src/main/kotlin/display/graphic/Renderer.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package display.graphic

import Matrix4f
import display.text.Font
import display.text.TextJustify
import input.CameraView
Expand All @@ -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
Expand Down Expand Up @@ -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()
}
Expand Down
7 changes: 1 addition & 6 deletions src/main/kotlin/display/graphic/ShaderProgram.kt
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down
Loading

0 comments on commit c2b0d56

Please sign in to comment.