Refactored build scripts and removed unused dependencies
- Added the following Gradle tasks: - buildLocal (alias for build) - buildCrossPlatform (builds with all natives) - packageDebian - packageWindows - Gradle no longer downloads or packages natives for wrong platforms (unless buildCrossPlatform or require*Dependencies is run) - Gradle should no longer complain about deprecated features - buildPackages.sh is now a lot more robust - Removed the following dependencies: - Apache Commons Math - Everything in LWJGL except OpenGL/AL, GLFW, STB and core
This commit is contained in:
parent
eb82c96390
commit
e389d2ad67
282
build.gradle
282
build.gradle
@ -1,31 +1,90 @@
|
||||
/*
|
||||
* build.gradle for Progressia
|
||||
*/
|
||||
|
||||
plugins {
|
||||
// Apply the java-library plugin to add support for Java Library
|
||||
id 'java-library'
|
||||
|
||||
/*
|
||||
* Uncomment the following line to enable the Eclipse plugin.
|
||||
* This is only necessary if you don't use Buildship plugin from the IDE
|
||||
*/
|
||||
//id 'eclipse'
|
||||
}
|
||||
|
||||
java {
|
||||
/*
|
||||
* We're Java 8 for now.
|
||||
* Why? As of 2020, most users have Oracle Java, which only supports Java 8.
|
||||
*/
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
compileJava {
|
||||
/*
|
||||
* We want to compile for Java 8.
|
||||
* If we are using JDK 8, no further action is required.
|
||||
* However, on JDK 9 and later versions, '--release' option is required,
|
||||
* which is missing on JDK 8.
|
||||
*/
|
||||
if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
|
||||
options.compilerArgs.addAll(['--release', '8'])
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Dependencies
|
||||
*/
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
jcenter()
|
||||
|
||||
maven { url 'http://windcorp.ru/./maven' }
|
||||
/*
|
||||
* Specify Windcorp Maven repository
|
||||
* Currently used by:
|
||||
* - ru.windcorp.fork.io.github.java-graphics:glm:1.0.1
|
||||
*/
|
||||
maven { url 'https://windcorp.ru/./maven' }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.apache.commons:commons-math3:3.6.1'
|
||||
// Google Guava
|
||||
// A generic utilities library
|
||||
implementation 'com.google.guava:guava:30.0-jre'
|
||||
|
||||
// Trove4j
|
||||
// Provides optimized Collections for primitive types
|
||||
implementation 'net.sf.trove4j:trove4j:3.0.3'
|
||||
|
||||
// java-graphics
|
||||
// A GLM (OpenGL Mathematics) port to Java
|
||||
// Unfortunately, Maven Central Repository provides an outdated version of this library, which contains several critical bugs
|
||||
implementation 'ru.windcorp.fork.io.github.java-graphics:glm:1.0.1'
|
||||
|
||||
// log4j
|
||||
// Log4j
|
||||
// A logging library
|
||||
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.13.3'
|
||||
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.13.3'
|
||||
|
||||
// JUnit
|
||||
// A unit-testing library
|
||||
testImplementation 'junit:junit:4.12'
|
||||
|
||||
// See also LWJGL dependencies below
|
||||
// See LWJGL dependencies below
|
||||
}
|
||||
|
||||
/*
|
||||
* Progressia uses the following LWJGL libraries:
|
||||
* - Core libraries
|
||||
* - OpenGL
|
||||
* - OpenAL
|
||||
* - GLFW
|
||||
* - STB
|
||||
*/
|
||||
|
||||
/*
|
||||
* LWJGL
|
||||
* (auto-generated script)
|
||||
@ -55,94 +114,169 @@ dependencies {
|
||||
implementation platform("org.lwjgl:lwjgl-bom:$lwjglVersion")
|
||||
|
||||
implementation "org.lwjgl:lwjgl"
|
||||
implementation "org.lwjgl:lwjgl-assimp"
|
||||
implementation "org.lwjgl:lwjgl-bgfx"
|
||||
implementation "org.lwjgl:lwjgl-glfw"
|
||||
implementation "org.lwjgl:lwjgl-nanovg"
|
||||
implementation "org.lwjgl:lwjgl-nuklear"
|
||||
implementation "org.lwjgl:lwjgl-openal"
|
||||
implementation "org.lwjgl:lwjgl-opengl"
|
||||
implementation "org.lwjgl:lwjgl-par"
|
||||
implementation "org.lwjgl:lwjgl-stb"
|
||||
implementation "org.lwjgl:lwjgl-vulkan"
|
||||
runtimeOnly "org.lwjgl:lwjgl::$lwjglNatives"
|
||||
runtimeOnly "org.lwjgl:lwjgl-assimp::$lwjglNatives"
|
||||
runtimeOnly "org.lwjgl:lwjgl-bgfx::$lwjglNatives"
|
||||
runtimeOnly "org.lwjgl:lwjgl-glfw::$lwjglNatives"
|
||||
runtimeOnly "org.lwjgl:lwjgl-nanovg::$lwjglNatives"
|
||||
runtimeOnly "org.lwjgl:lwjgl-nuklear::$lwjglNatives"
|
||||
runtimeOnly "org.lwjgl:lwjgl-openal::$lwjglNatives"
|
||||
runtimeOnly "org.lwjgl:lwjgl-opengl::$lwjglNatives"
|
||||
runtimeOnly "org.lwjgl:lwjgl-par::$lwjglNatives"
|
||||
runtimeOnly "org.lwjgl:lwjgl-stb::$lwjglNatives"
|
||||
if (lwjglNatives == "natives-macos") runtimeOnly "org.lwjgl:lwjgl-vulkan::$lwjglNatives"
|
||||
|
||||
// Not adding runtimeOnly native libraries because natives are handled by addNativeDependencies
|
||||
}
|
||||
|
||||
// LWJGL END
|
||||
|
||||
configurations {
|
||||
packageOnly
|
||||
packageLibraries.extendsFrom runtimeClasspath
|
||||
packageLibraries.extendsFrom packageOnly
|
||||
}
|
||||
|
||||
dependencies {
|
||||
def archs = ['natives-linux', 'natives-linux-arm64', 'natives-linux-arm32', 'natives-macos', 'natives-windows', 'natives-windows-x86']
|
||||
|
||||
archs.each { arch ->
|
||||
packageOnly "org.lwjgl:lwjgl::$arch"
|
||||
packageOnly "org.lwjgl:lwjgl-assimp::$arch"
|
||||
packageOnly "org.lwjgl:lwjgl-bgfx::$arch"
|
||||
packageOnly "org.lwjgl:lwjgl-glfw::$arch"
|
||||
packageOnly "org.lwjgl:lwjgl-nanovg::$arch"
|
||||
packageOnly "org.lwjgl:lwjgl-nuklear::$arch"
|
||||
packageOnly "org.lwjgl:lwjgl-openal::$arch"
|
||||
packageOnly "org.lwjgl:lwjgl-opengl::$arch"
|
||||
packageOnly "org.lwjgl:lwjgl-par::$arch"
|
||||
packageOnly "org.lwjgl:lwjgl-stb::$arch"
|
||||
}
|
||||
|
||||
packageOnly "org.lwjgl:lwjgl-vulkan::natives-macos"
|
||||
}
|
||||
|
||||
jar {
|
||||
manifest {
|
||||
attributes(
|
||||
"Main-Class": "ru.windcorp.progressia.client.ProgressiaClientMain",
|
||||
"Class-Path": configurations.packageLibraries.collect { "lib/" + it.getName() }.join(' ')
|
||||
)
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Tasks
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copies runtime dependencies to a prespecified location so they can be packaged properly.
|
||||
* Additional native libraries specification
|
||||
*/
|
||||
|
||||
project.ext.platforms = new ArrayList<>()
|
||||
|
||||
task addNativeDependencies {
|
||||
doFirst {
|
||||
def archs = project.ext.platforms
|
||||
|
||||
switch (archs.size()) {
|
||||
case 0:
|
||||
println "Adding LWJGL native dependencies for local platform only:\n\t$lwjglNatives"
|
||||
archs.add project.ext.lwjglNatives
|
||||
break
|
||||
case 1:
|
||||
println "Adding LWJGL native dependencies for platform\n\t" + archs.get(0)
|
||||
break
|
||||
default:
|
||||
println "Adding LWJGL native dependencies for platforms:\n\t" + archs.join("\n\t")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
archs.each { arch ->
|
||||
runtimeOnly "org.lwjgl:lwjgl::$arch"
|
||||
runtimeOnly "org.lwjgl:lwjgl-glfw::$arch"
|
||||
runtimeOnly "org.lwjgl:lwjgl-openal::$arch"
|
||||
runtimeOnly "org.lwjgl:lwjgl-opengl::$arch"
|
||||
runtimeOnly "org.lwjgl:lwjgl-stb::$arch"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
compileJava.mustRunAfter addNativeDependencies // Make sure runtimeOnly has not been resolved
|
||||
|
||||
task requireLinuxDependencies {
|
||||
description 'Adds linux, linux-arm64 and linux-arm32 native libraries to built artifacts.'
|
||||
doFirst {
|
||||
project.ext.platforms.addAll(['natives-linux', 'natives-linux-arm64', 'natives-linux-arm32'])
|
||||
}
|
||||
}
|
||||
task requireWindowsDependencies {
|
||||
description 'Adds windows and windows-x86 native libraries to built artifacts.'
|
||||
doFirst {
|
||||
project.ext.platforms.addAll(['natives-windows', 'natives-windows-x86'])
|
||||
}
|
||||
}
|
||||
task requireMacOSDependencies {
|
||||
description 'Adds macos native libraries to built artifacts.'
|
||||
doFirst {
|
||||
project.ext.platforms.addAll(['natives-macos'])
|
||||
}
|
||||
}
|
||||
|
||||
def dependencySpecificationTasks = tasks.findAll { task -> task.name.startsWith('require') && task.name.endsWith('Dependencies') }
|
||||
|
||||
task requireCrossPlatformDependencies {
|
||||
description 'Adds native libraries for all available platforms to built artifacts.'
|
||||
dependsOn dependencySpecificationTasks
|
||||
}
|
||||
|
||||
addNativeDependencies.mustRunAfter dependencySpecificationTasks
|
||||
|
||||
/*
|
||||
* Manifest specification
|
||||
*/
|
||||
|
||||
task specifyLocalManifest {
|
||||
dependsOn addNativeDependencies // Make sure all native dependencies are specified
|
||||
|
||||
doFirst {
|
||||
jar {
|
||||
manifest {
|
||||
attributes(
|
||||
"Main-Class": "ru.windcorp.progressia.client.ProgressiaClientMain",
|
||||
"Class-Path": configurations.runtimeClasspath.collect { "lib/" + it.getName() } .join(' ')
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
build.dependsOn specifyLocalManifest
|
||||
|
||||
/*
|
||||
* Library export
|
||||
*/
|
||||
|
||||
task copyLibs(type: Copy) {
|
||||
into "${libsDir}/lib"
|
||||
mustRunAfter addNativeDependencies
|
||||
|
||||
into libsDirectory.get().getAsFile().getPath() + "/lib"
|
||||
from configurations.runtimeClasspath
|
||||
}
|
||||
|
||||
build.dependsOn(copyLibs)
|
||||
|
||||
task copyLibsForPackaging(type: Copy) {
|
||||
into "${libsDir}/lib"
|
||||
from configurations.packageLibraries
|
||||
}
|
||||
/*
|
||||
* Packaging
|
||||
*/
|
||||
|
||||
task createPackages(type: Exec) {
|
||||
commandLine './buildPackages.sh'
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
compileJava {
|
||||
if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
|
||||
options.compilerArgs.addAll(['--release', '8'])
|
||||
task packageDebian(type: Exec) {
|
||||
description 'Builds the project and creates a Debain package.'
|
||||
group 'Progressia'
|
||||
|
||||
dependsOn build
|
||||
dependsOn requireLinuxDependencies
|
||||
|
||||
commandLine './buildPackages.sh', 'debian'
|
||||
|
||||
doLast {
|
||||
println "Debian package available in build_packages/"
|
||||
}
|
||||
}
|
||||
|
||||
createPackages.dependsOn(build)
|
||||
createPackages.dependsOn(copyLibsForPackaging)
|
||||
task packageWindows(type: Exec) {
|
||||
description 'Builds the project and creates a Windows installer.'
|
||||
group 'Progressia'
|
||||
|
||||
dependsOn build
|
||||
dependsOn requireWindowsDependencies
|
||||
|
||||
commandLine './buildPackages.sh', 'windows'
|
||||
|
||||
doLast {
|
||||
println "Windows installer available in build_packages/"
|
||||
}
|
||||
}
|
||||
|
||||
task buildCrossPlatform {
|
||||
description 'Builds the project including native libraries for all available platforms.'
|
||||
group 'Progressia'
|
||||
|
||||
dependsOn requireCrossPlatformDependencies
|
||||
dependsOn build
|
||||
|
||||
doLast {
|
||||
println "Native libraries for all platforms have been added"
|
||||
}
|
||||
}
|
||||
|
||||
task buildLocal {
|
||||
description "Builds the project including only native libraries for current platform ($lwjglNatives)."
|
||||
group 'Progressia'
|
||||
|
||||
dependsOn build
|
||||
|
||||
doLast {
|
||||
println "Native libraries only for platform $lwjglNatives have been added"
|
||||
}
|
||||
}
|
||||
|
177
buildPackages.sh
177
buildPackages.sh
@ -1,38 +1,159 @@
|
||||
#!/bin/bash
|
||||
|
||||
lst="nsis"
|
||||
echoerr() { echo "$@" 1>&2; }
|
||||
|
||||
user=`whoami`
|
||||
buildDebianPackage() {
|
||||
|
||||
dpkg -l 2>/dev/null > ls.tmp
|
||||
# Commands that must be available to execute this action
|
||||
requiredCommands='dpkg-deb fakeroot'
|
||||
|
||||
# Version that the package will receive
|
||||
version='0.1_all'
|
||||
|
||||
directory="build_packages/DEB/progressia-$version"
|
||||
|
||||
# .deb control file that must be present
|
||||
configurationFile="$directory/DEBIAN/control"
|
||||
|
||||
outputFile="build_packages/DEB/progressia-$version.deb"
|
||||
|
||||
for items in $lst
|
||||
do
|
||||
cmd=$(grep "\ $items\ " ls.tmp)
|
||||
if [ $? == 0 ]
|
||||
then
|
||||
echo "$items installed!"
|
||||
echo "Building..."
|
||||
echo "Checking environment to build Debian package"
|
||||
|
||||
for item in $requiredCommands; do
|
||||
if command -v "$item" &> /dev/null; then
|
||||
echo "- $item found"
|
||||
else
|
||||
echoerr "Command $item not found, cannot package"
|
||||
exit 100
|
||||
fi
|
||||
done
|
||||
|
||||
if ! [ -r "$configurationFile" ]; then
|
||||
echoerr "$configurationFile is missing or not readable, cannot package"
|
||||
exit 101
|
||||
else
|
||||
echo "Package $items not found! Please install $items."
|
||||
rm ls.tmp
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
rm ls.tmp
|
||||
echo "- $configurationFile is present and readable"
|
||||
fi
|
||||
|
||||
echo "Environment OK; packaging Debian package"
|
||||
exitCode=0
|
||||
|
||||
{
|
||||
user=`whoami`
|
||||
homeDir="$directory/home/$user/Progressia/"
|
||||
|
||||
mkdir -p "$homeDir" &&
|
||||
cp -r 'build/libs/lib' "$homeDir/lib" &&
|
||||
cp 'build/libs/Progressia.jar' "$homeDir/Progressia.jar" &&
|
||||
echo "------ DPKG-DEB ------" &&
|
||||
fakeroot dpkg-deb --build "$directory" &&
|
||||
echo "---- DPKG-DEB END ----" &&
|
||||
mv "$outputFile" build_packages
|
||||
} || {
|
||||
echoerr "Could not create Debian package"
|
||||
exitCode=1
|
||||
}
|
||||
|
||||
{
|
||||
if [ -d "$homeDir" ]; then
|
||||
rm -r "$homeDir"
|
||||
fi
|
||||
echo "Cleaned up"
|
||||
} || {
|
||||
echoerr "Could not clean up after packaging Debian package"
|
||||
exitCode=2
|
||||
}
|
||||
}
|
||||
|
||||
cd build_packages/DEB/progressia-0.1_all/
|
||||
mkdir -p home/$user/Progressia
|
||||
buildWindowsInstaller() {
|
||||
|
||||
cd ../../..
|
||||
# Commands that must be available to execute this action
|
||||
requiredCommands='makensis'
|
||||
|
||||
# NSIS configuration file that must be present
|
||||
configurationFile='build_packages/NSIS/ProgressiaInstaller.nsi'
|
||||
|
||||
# File that will be output
|
||||
outputFile='build_packages/NSIS/ProgressiaInstaller.exe'
|
||||
|
||||
cp -r build/libs/lib build_packages/DEB/progressia-0.1_all/home/$user/Progressia/
|
||||
cp build/libs/Progressia.jar build_packages/DEB/progressia-0.1_all/home/$user/Progressia/
|
||||
cp -r build/libs/lib build_packages/NSIS
|
||||
cp build/libs/Progressia.jar build_packages/NSIS
|
||||
echo "Checking environment to build Windows installer"
|
||||
|
||||
for item in $requiredCommands; do
|
||||
if command -v "$item" &> /dev/null; then
|
||||
echo "- $item found"
|
||||
else
|
||||
echoerr "Command $item not found, cannot build"
|
||||
exit 100
|
||||
fi
|
||||
done
|
||||
|
||||
if ! [ -r "$configurationFile" ]; then
|
||||
echoerr "$configurationFile is missing or not readable, cannot build"
|
||||
exit 101
|
||||
else
|
||||
echo "- $configurationFile is present and readable"
|
||||
fi
|
||||
|
||||
echo "Environment OK; building Windows installer"
|
||||
exitCode=0
|
||||
|
||||
{
|
||||
cp -r 'build/libs/lib' 'build_packages/NSIS/lib' &&
|
||||
cp 'build/libs/Progressia.jar' 'build_packages/NSIS/Progressia.jar' &&
|
||||
echo "------ NSIS ------" &&
|
||||
makensis "$configurationFile" &&
|
||||
echo "---- NSIS END ----" &&
|
||||
mv "$outputFile" build_packages
|
||||
} || {
|
||||
echoerr "Could not build Windows installer"
|
||||
exitCode=1
|
||||
}
|
||||
|
||||
{
|
||||
if [ -d 'build_packages/NSIS/lib' ]; then
|
||||
rm -r 'build_packages/NSIS/lib'
|
||||
fi
|
||||
if [ -e 'build_packages/NSIS/Progressia.jar' ]; then
|
||||
rm 'build_packages/NSIS/Progressia.jar'
|
||||
fi
|
||||
echo "Cleaned up"
|
||||
} || {
|
||||
echoerr "Could not clean up after building Windows installer"
|
||||
exitCode=2
|
||||
}
|
||||
|
||||
exit "$exitCode"
|
||||
}
|
||||
|
||||
makensis build_packages/NSIS/ProgressiaInstaller.nsi
|
||||
mv build_packages/NSIS/ProgressiaInstaller.exe build_packages/Progressia.exe
|
||||
fakeroot dpkg-deb --build build_packages/DEB/progressia-0.1_all
|
||||
mv build_packages/DEB/progressia-0.1_all.deb build_packages/progressia-0.1_all.deb
|
||||
echo "Build done!"
|
||||
printUsage() {
|
||||
echoerr "Usage: $0 TARGET"
|
||||
echoerr " where TARGET is 'debian' or 'windows'"
|
||||
}
|
||||
|
||||
if [ -n "$2" ]; then
|
||||
echoerr "Too many arguments."
|
||||
printUsage
|
||||
exit 202
|
||||
fi
|
||||
|
||||
case "$1" in
|
||||
"debian")
|
||||
buildDebianPackage
|
||||
;;
|
||||
"windows")
|
||||
buildWindowsInstaller
|
||||
;;
|
||||
"")
|
||||
echoerr "No action specified"
|
||||
printUsage
|
||||
exit 200
|
||||
;;
|
||||
"--help" | "-help" | "help" | "?")
|
||||
printUsage
|
||||
;;
|
||||
*)
|
||||
echoerr "Unknown action '$1'"
|
||||
printUsage
|
||||
exit 201
|
||||
;;
|
||||
esac
|
||||
|
@ -1,13 +1,11 @@
|
||||
package ru.windcorp.progressia.common.util;
|
||||
|
||||
import org.apache.commons.math3.util.FastMath;
|
||||
|
||||
public class FloatMathUtils {
|
||||
|
||||
public static final float PI_F = (float) Math.PI;
|
||||
|
||||
public static float floor(float x) {
|
||||
return (float) FastMath.floor(x);
|
||||
return (float) Math.floor(x);
|
||||
}
|
||||
|
||||
public static float normalizeAngle(float a) {
|
||||
|
Reference in New Issue
Block a user