Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

New Frontend with KTX #214

Draft
wants to merge 38 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
3537359
Added terrain graphics
Baret Sep 11, 2023
7a2fed7
Trying texture packing
Baret Sep 11, 2023
53e1a2b
renamed files and packed into an atlas
Baret Sep 11, 2023
480b469
puzzled together some basics from the gdx-liftoff
Baret Sep 15, 2023
f6e171c
added missing platform natives
Baret Sep 15, 2023
22b65b6
stole some more default files :P
Baret Sep 15, 2023
c8cb136
fixed runtime error regarding sealed package of lwjgl
Baret Oct 8, 2023
5cfcc2f
Drawing stuff! Terrain and element icons
Baret Oct 8, 2023
f65fcf8
playing around with filters, atlas creation and so on
Baret Oct 9, 2023
419a6b7
trying upscaled element icons
Baret Oct 9, 2023
65f00c8
optimized texture packing settings
Baret Oct 9, 2023
37f9cd0
Also packing element icons into an atlas
Baret Oct 9, 2023
9c736ca
playing around with tinting
Baret Oct 12, 2023
a8fc457
Writing own actors and encapsulating texture loading
Baret Oct 14, 2023
59eb856
removed colorful for now (not (yet?) needed)
Baret Oct 14, 2023
25cc8e0
Started to write text with a skin
Baret Oct 26, 2023
1c9fb9d
moved FirstScreen to screens package
Baret Oct 26, 2023
4bfe3ec
starting to try out tiledmap
Baret Oct 26, 2023
8ed7f56
tried to go back to mouse over coordinates
Baret Oct 27, 2023
ab6646d
manually rendering the world by drawing
Baret Dec 26, 2023
6af26e7
scrollable map
Baret Dec 26, 2023
1bae93e
Drawing grid lines
Baret Dec 26, 2023
29c9de8
Render known world that can be revealed by clicking, improved scrolling
Baret Dec 27, 2023
956628a
trying to highlight right-clicked coordinate
Baret Dec 27, 2023
b238675
Merge remote-tracking branch 'refs/remotes/origin/master' into try-ktx
Baret Jun 5, 2024
f31982c
bump ktx from 1.12.0-rc1 to 1.12.1-rc1
Baret Jun 5, 2024
25ede74
added NeighborBitmap and DrawableWorldTile
Baret Jun 6, 2024
04a6b5b
added NeighborBitmap.all()
Baret Jun 8, 2024
2b66b0b
on the way to contour lines (and not using potato units)
Baret Jun 8, 2024
8d2a7a5
no camera! At least for now
Baret Jun 27, 2024
6b91193
fixed tile scaling
Baret Jun 27, 2024
bc601ac
very basic contour lines
Baret Jun 30, 2024
2d265c3
display height of selected tile
Baret Jul 1, 2024
3762d9e
draw a triangle on single top tiles
Baret Jul 3, 2024
454a71a
properly drawing hilltops
Baret Jul 3, 2024
5998ab0
added FPS display
Baret Jul 7, 2024
634e21d
caching fully revealed tiles, no performance improvement (still 28 fps)
Baret Jul 7, 2024
10ca2c5
moved contour line calculations, still 28 frames
Baret Jul 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions game/application-ktx/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>de.gleex.pltcmd.game</groupId>
<artifactId>game</artifactId>
<version>0.2.0-SNAPSHOT</version>
</parent>

<artifactId>application-ktx</artifactId>

<name>Application with KTX</name>
<description>A frontend for the game built with KTX</description>

<properties>
<gdx.version>1.12.1</gdx.version>
<ktx.version>1.12.1-rc1</ktx.version>
</properties>

<dependencies>
<!-- internal dependencies -->
<dependency>
<groupId>de.gleex.pltcmd.game</groupId>
<artifactId>graphics</artifactId>
<exclusions>
<exclusion>
<groupId>com.badlogicgames.gdx</groupId>
<artifactId>gdx-tools</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>de.gleex.pltcmd.model</groupId>
<artifactId>world</artifactId>
</dependency>
<dependency>
<groupId>de.gleex.pltcmd.model</groupId>
<artifactId>mapgeneration</artifactId>
</dependency>
<dependency>
<groupId>de.gleex.pltcmd.game</groupId>
<artifactId>engine</artifactId>
</dependency>

<!-- gdx -->
<dependency>
<groupId>com.badlogicgames.gdx</groupId>
<artifactId>gdx</artifactId>
<version>${gdx.version}</version>
</dependency>
<dependency>
<groupId>com.badlogicgames.gdx</groupId>
<artifactId>gdx-backend-lwjgl3</artifactId>
<version>${gdx.version}</version>
</dependency>
<dependency>
<groupId>com.badlogicgames.gdx</groupId>
<artifactId>gdx-platform</artifactId>
<version>${gdx.version}</version>
<classifier>natives-desktop</classifier>
</dependency>

<!-- ktx -->
<dependency>
<groupId>io.github.libktx</groupId>
<artifactId>ktx-app</artifactId>
<version>${ktx.version}</version>
</dependency>
<dependency>
<groupId>io.github.libktx</groupId>
<artifactId>ktx-assets</artifactId>
<version>${ktx.version}</version>
</dependency>
<dependency>
<groupId>io.github.libktx</groupId>
<artifactId>ktx-graphics</artifactId>
<version>${ktx.version}</version>
</dependency>
<dependency>
<groupId>io.github.libktx</groupId>
<artifactId>ktx-vis-style</artifactId>
<version>${ktx.version}</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package de.gleex.pltcmd.game.application

import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration

fun main() {
// This handles macOS support and helps on Windows.
if (StartupHelper.startNewJvmIfRequired()) {
return
}
Lwjgl3Application(Pltcmd(), Lwjgl3ApplicationConfiguration().apply {
setTitle("pltcmd")
setWindowedMode(1800, 990)
setWindowIcon(*(arrayOf(128, 64, 32, 16).map { "libgdx$it.png" }.toTypedArray()))
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package de.gleex.pltcmd.game.application

import com.kotcrab.vis.ui.VisUI
import de.gleex.pltcmd.game.application.screens.FirstScreen
import de.gleex.pltcmd.game.application.screens.MainGameScreen
import de.gleex.pltcmd.game.engine.attributes.memory.KnownWorld
import de.gleex.pltcmd.model.mapgeneration.mapgenerators.WorldMapGenerator
import de.gleex.pltcmd.model.world.WorldMap
import ktx.app.KtxGame
import ktx.app.KtxScreen
import mu.KotlinLogging
import kotlin.time.DurationUnit
import kotlin.time.measureTimedValue

private val log = KotlinLogging.logger { }

class Pltcmd : KtxGame<KtxScreen>() {
override fun create() {
log.info { "loading VisUI" }
VisUI.load(VisUI.SkinScale.X1)

addScreen(FirstScreen())
val worldMap: WorldMap = generateWorld()
val screen = MainGameScreen(KnownWorld(worldMap))
log.info { "Adding $screen" }
addScreen(screen)
log.info { "Loading screen" }
setScreen<MainGameScreen>()
// setScreen<FirstScreen>()
}

private fun generateWorld(): WorldMap {
val seed: Long = 1720015570753 // System.currentTimeMillis() // another seed with a long plane area: 1720014618599
log.info { "Generating world with seed $seed" }
val worldMapGenerator = WorldMapGenerator(seed, 100, 100)
val (worldMap, duration) = measureTimedValue { worldMapGenerator.generateWorld() }
log.info { "Generated world in ${duration.toString(DurationUnit.SECONDS, decimals = 3)}" }
return worldMap
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@

/*
* Copyright 2020 damios
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//Note, the above license and copyright applies to this file only.
package de.gleex.pltcmd.game.application

import org.lwjgl.system.macosx.LibC
import java.io.BufferedReader
import java.io.File
import java.io.InputStreamReader
import java.lang.management.ManagementFactory
import java.util.*

/**
* Adds some utilities to ensure that the JVM was started with the
* `-XstartOnFirstThread` argument, which is required on macOS for LWJGL 3
* to function. Also helps on Windows when users have names with characters from
* outside the Latin alphabet, a common cause of startup crashes.
*
* [Based on this java-gaming.org post by kappa](https://jvm-gaming.org/t/starting-jvm-on-mac-with-xstartonfirstthread-programmatically/57547)
* @author damios
*/
class StartupHelper private constructor() {
init {
throw UnsupportedOperationException()
}

companion object {
private const val JVM_RESTARTED_ARG = "jvmIsRestarted"
/**
* Starts a new JVM if the application was started on macOS without the
* `-XstartOnFirstThread` argument. This also includes some code for
* Windows, for the case where the user's home directory includes certain
* non-Latin-alphabet characters (without this code, most LWJGL3 apps fail
* immediately for those users). Returns whether a new JVM was started and
* thus no code should be executed.
*
* **Usage:**
*
* ```
* fun main() {
* if (StartupHelper.startNewJvmIfRequired(true)) return // This handles macOS support and helps on Windows.
* // after this is the actual main method code
* }
* ```
*
* @param redirectOutput
* whether the output of the new JVM should be rerouted to the
* old JVM, so it can be accessed in the same place; keeps the
* old JVM running if enabled
* @return whether a new JVM was started and thus no code should be executed
* in this one
*/
@JvmOverloads
fun startNewJvmIfRequired(redirectOutput: Boolean = true): Boolean {
val osName = System.getProperty("os.name").lowercase(Locale.getDefault())
if (!osName.contains("mac")) {
if (osName.contains("windows")) {
// Here, we are trying to work around an issue with how LWJGL3 loads its extracted .dll files.
// By default, LWJGL3 extracts to the directory specified by "java.io.tmpdir", which is usually the user's home.
// If the user's name has non-ASCII (or some non-alphanumeric) characters in it, that would fail.
// By extracting to the relevant "ProgramData" folder, which is usually "C:\ProgramData", we avoid this.
System.setProperty("java.io.tmpdir", System.getenv("ProgramData") + "/libGDX-temp")
}
return false
}
val pid = LibC.getpid()

// check whether -XstartOnFirstThread is enabled
if ("1" == System.getenv("JAVA_STARTED_ON_FIRST_THREAD_$pid")) {
return false
}

// check whether the JVM was previously restarted
// avoids looping, but most certainly leads to a crash
if ("true" == System.getProperty(JVM_RESTARTED_ARG)) {
System.err.println(
"There was a problem evaluating whether the JVM was started with the -XstartOnFirstThread argument."
)
return false
}

// Restart the JVM with -XstartOnFirstThread
val jvmArgs = ArrayList<String?>()
val separator = System.getProperty("file.separator")
// The following line is used assuming you target Java 8, the minimum for LWJGL3.
val javaExecPath = System.getProperty("java.home") + separator + "bin" + separator + "java"
// If targeting Java 9 or higher, you could use the following instead of the above line:
//String javaExecPath = ProcessHandle.current().info().command().orElseThrow();
if (!File(javaExecPath).exists()) {
System.err.println(
"A Java installation could not be found. If you are distributing this app with a bundled JRE, be sure to set the -XstartOnFirstThread argument manually!"
)
return false
}
jvmArgs.add(javaExecPath)
jvmArgs.add("-XstartOnFirstThread")
jvmArgs.add("-D$JVM_RESTARTED_ARG=true")
jvmArgs.addAll(ManagementFactory.getRuntimeMXBean().inputArguments)
jvmArgs.add("-cp")
jvmArgs.add(System.getProperty("java.class.path"))
var mainClass = System.getenv("JAVA_MAIN_CLASS_$pid")
if (mainClass == null) {
val trace = Thread.currentThread().stackTrace
mainClass = if (trace.isNotEmpty()) {
trace[trace.size - 1].className
} else {
System.err.println("The main class could not be determined.")
return false
}
}
jvmArgs.add(mainClass)
try {
if (!redirectOutput) {
val processBuilder = ProcessBuilder(jvmArgs)
processBuilder.start()
} else {
val process = ProcessBuilder(jvmArgs)
.redirectErrorStream(true).start()
val processOutput = BufferedReader(
InputStreamReader(process.inputStream)
)
var line: String?
while (processOutput.readLine().also { line = it } != null) {
println(line)
}
process.waitFor()
}
} catch (e: Exception) {
System.err.println("There was a problem restarting the JVM")
e.printStackTrace()
}
return true
}
}
}
Loading