Compare commits
88 Commits
falling-sa
...
add-items
Author | SHA1 | Date | |
---|---|---|---|
38021852d0
|
|||
9c85164ed1
|
|||
ce573b51ce
|
|||
92f9639c4b
|
|||
f350467942
|
|||
a028f6f3c7
|
|||
23b0af1731 | |||
0389f97e59 | |||
706800218c
|
|||
ca2c7b58d8
|
|||
359879b0fe
|
|||
a06d8ee056
|
|||
c8138faabe
|
|||
49d283e7a3
|
|||
c93f0df30d
|
|||
75ea7baf9c
|
|||
c4a9a17c7c | |||
b4ff5114bd
|
|||
9b67897896
|
|||
efc6a8ecd0
|
|||
3641c4130b
|
|||
4b10dc82ed
|
|||
be6203719a
|
|||
c04894a0c9 | |||
9885a1ca42
|
|||
c6e6dc6851
|
|||
28b19c8f35
|
|||
eb5aa59941
|
|||
409bbdb680
|
|||
0c41350ae7 | |||
a633c8324e
|
|||
6b33f231b4 | |||
e2308b825d
|
|||
30464febf6 | |||
e0f6a08740 | |||
2820e01974 | |||
782b3ef553
|
|||
46bcb85044 | |||
05b1c73fbc
|
|||
c5dfe3d0b7 | |||
bd6442318d
|
|||
6cd812f7c3 | |||
73ee339dcc
|
|||
4749be6c60
|
|||
a85fc27f8b
|
|||
a4b731e8a5
|
|||
e7d0e8fe40
|
|||
711e4a2bb4
|
|||
0100c8791d
|
|||
040a4f7fd7
|
|||
e967a64401 | |||
d2ffe1fe0e
|
|||
f4300558d5
|
|||
cd16334db8
|
|||
41a2909f7c
|
|||
a222ea8f67
|
|||
b3ac7b6afe
|
|||
2fe84dc59e
|
|||
00ea4a6281
|
|||
98250cd524 | |||
f74c731a3d
|
|||
f186fc602d
|
|||
98c383bf7d
|
|||
dd80df2cf2
|
|||
9dcb3a7748 | |||
1727a2a4a1
|
|||
20fb8f0597
|
|||
1d28f32865
|
|||
0ccc108ddd
|
|||
c7e7d3bdac
|
|||
62729f5873
|
|||
84864f8947
|
|||
d01ef3654f
|
|||
fae09edb16 | |||
e4ced6507e | |||
b7dcbb0f30 | |||
9c26418354 | |||
6891d3a095 | |||
8167c40f64 | |||
8bc23acb61 | |||
254faca0a5 | |||
0c66f1751e | |||
c88dea6030 | |||
6521cb5749 | |||
94db44e443 | |||
53f72b068a | |||
a9ca5f6b17 | |||
4ab7cb738e |
248
build.gradle
248
build.gradle
@ -3,14 +3,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
// Apply the java-library plugin to add support for Java Library
|
// Apply the java-library plugin to add support for Java Library
|
||||||
id 'java-library'
|
id 'java-library'
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Uncomment the following line to enable the Eclipse plugin.
|
* Uncomment the following line to enable the Eclipse plugin.
|
||||||
* This is only necessary if you don't use Buildship plugin from the IDE
|
* This is only necessary if you don't use Buildship plugin from the IDE
|
||||||
*/
|
*/
|
||||||
//id 'eclipse'
|
//id 'eclipse'
|
||||||
}
|
}
|
||||||
|
|
||||||
java {
|
java {
|
||||||
@ -18,8 +18,8 @@ java {
|
|||||||
* We're Java 8 for now.
|
* We're Java 8 for now.
|
||||||
* Why? As of 2020, most users have Oracle Java, which only supports Java 8.
|
* Why? As of 2020, most users have Oracle Java, which only supports Java 8.
|
||||||
*/
|
*/
|
||||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||||
targetCompatibility = JavaVersion.VERSION_1_8
|
targetCompatibility = JavaVersion.VERSION_1_8
|
||||||
}
|
}
|
||||||
|
|
||||||
compileJava {
|
compileJava {
|
||||||
@ -29,9 +29,9 @@ compileJava {
|
|||||||
* However, on JDK 9 and later versions, '--release' option is required,
|
* However, on JDK 9 and later versions, '--release' option is required,
|
||||||
* which is missing on JDK 8.
|
* which is missing on JDK 8.
|
||||||
*/
|
*/
|
||||||
if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
|
if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
|
||||||
options.compilerArgs.addAll(['--release', '8'])
|
options.compilerArgs.addAll(['--release', '8'])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -40,39 +40,38 @@ compileJava {
|
|||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
jcenter()
|
|
||||||
|
/*
|
||||||
/*
|
* Specify Windcorp Maven repository
|
||||||
* Specify Windcorp Maven repository
|
* Currently used by:
|
||||||
* Currently used by:
|
* - ru.windcorp.fork.io.github.java-graphics:glm:1.0.1
|
||||||
* - ru.windcorp.fork.io.github.java-graphics:glm:1.0.1
|
*/
|
||||||
*/
|
maven { url 'https://windcorp.ru/./maven' }
|
||||||
maven { url 'https://windcorp.ru/./maven' }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// Google Guava
|
// Google Guava
|
||||||
// A generic utilities library
|
// A generic utilities library
|
||||||
implementation 'com.google.guava:guava:30.0-jre'
|
implementation 'com.google.guava:guava:30.0-jre'
|
||||||
|
|
||||||
// Trove4j
|
// Trove4j
|
||||||
// Provides optimized Collections for primitive types
|
// Provides optimized Collections for primitive types
|
||||||
implementation 'net.sf.trove4j:trove4j:3.0.3'
|
implementation 'net.sf.trove4j:trove4j:3.0.3'
|
||||||
|
|
||||||
// java-graphics
|
// java-graphics
|
||||||
// A GLM (OpenGL Mathematics) port to Java
|
// A GLM (OpenGL Mathematics) port to Java
|
||||||
// Unfortunately, Maven Central Repository provides an outdated version of this library, which contains several critical bugs
|
// 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'
|
implementation 'ru.windcorp.fork.io.github.java-graphics:glm:1.0.1'
|
||||||
|
|
||||||
// Log4j
|
// Log4j
|
||||||
// A logging library
|
// A logging library
|
||||||
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.13.3'
|
implementation 'org.apache.logging.log4j:log4j-api:2.17.0'
|
||||||
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.13.3'
|
implementation 'org.apache.logging.log4j:log4j-core:2.17.0'
|
||||||
|
|
||||||
// JUnit
|
// JUnit
|
||||||
// A unit-testing library
|
// A unit-testing library
|
||||||
testImplementation 'junit:junit:4.12'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
|
|
||||||
// See LWJGL dependencies below
|
// See LWJGL dependencies below
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,8 +98,8 @@ switch (OperatingSystem.current()) {
|
|||||||
case OperatingSystem.LINUX:
|
case OperatingSystem.LINUX:
|
||||||
def osArch = System.getProperty("os.arch")
|
def osArch = System.getProperty("os.arch")
|
||||||
project.ext.lwjglNatives = osArch.startsWith("arm") || osArch.startsWith("aarch64")
|
project.ext.lwjglNatives = osArch.startsWith("arm") || osArch.startsWith("aarch64")
|
||||||
? "natives-linux-${osArch.contains("64") || osArch.startsWith("armv8") ? "arm64" : "arm32"}"
|
? "natives-linux-${osArch.contains("64") || osArch.startsWith("armv8") ? "arm64" : "arm32"}"
|
||||||
: "natives-linux"
|
: "natives-linux"
|
||||||
break
|
break
|
||||||
case OperatingSystem.MAC_OS:
|
case OperatingSystem.MAC_OS:
|
||||||
project.ext.lwjglNatives = "natives-macos"
|
project.ext.lwjglNatives = "natives-macos"
|
||||||
@ -118,12 +117,12 @@ dependencies {
|
|||||||
implementation "org.lwjgl:lwjgl-openal"
|
implementation "org.lwjgl:lwjgl-openal"
|
||||||
implementation "org.lwjgl:lwjgl-opengl"
|
implementation "org.lwjgl:lwjgl-opengl"
|
||||||
implementation "org.lwjgl:lwjgl-stb"
|
implementation "org.lwjgl:lwjgl-stb"
|
||||||
|
|
||||||
runtimeOnly "org.lwjgl:lwjgl::$lwjglNatives"
|
runtimeOnly "org.lwjgl:lwjgl::$lwjglNatives"
|
||||||
runtimeOnly "org.lwjgl:lwjgl-glfw::$lwjglNatives"
|
runtimeOnly "org.lwjgl:lwjgl-glfw::$lwjglNatives"
|
||||||
runtimeOnly "org.lwjgl:lwjgl-openal::$lwjglNatives"
|
runtimeOnly "org.lwjgl:lwjgl-openal::$lwjglNatives"
|
||||||
runtimeOnly "org.lwjgl:lwjgl-opengl::$lwjglNatives"
|
runtimeOnly "org.lwjgl:lwjgl-opengl::$lwjglNatives"
|
||||||
runtimeOnly "org.lwjgl:lwjgl-stb::$lwjglNatives"
|
runtimeOnly "org.lwjgl:lwjgl-stb::$lwjglNatives"
|
||||||
}
|
}
|
||||||
|
|
||||||
// LWJGL END
|
// LWJGL END
|
||||||
@ -141,49 +140,56 @@ project.ext.platforms = new HashSet<>()
|
|||||||
task addNativeDependencies {
|
task addNativeDependencies {
|
||||||
doFirst {
|
doFirst {
|
||||||
def archs = project.ext.platforms
|
def archs = project.ext.platforms
|
||||||
|
|
||||||
switch (archs.size()) {
|
switch (archs.size()) {
|
||||||
case 0:
|
case 0:
|
||||||
println "Adding LWJGL native dependencies for local platform only:\n\t$lwjglNatives"
|
println "Adding LWJGL native dependencies for local platform only:\n\t$lwjglNatives"
|
||||||
archs.add project.ext.lwjglNatives
|
archs.add project.ext.lwjglNatives
|
||||||
break
|
break
|
||||||
case 1:
|
case 1:
|
||||||
println "Adding LWJGL native dependencies for platform\n\t" + archs.get(0)
|
println "Adding LWJGL native dependencies for platform\n\t" + archs.get(0)
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
println "Adding LWJGL native dependencies for platforms:\n\t" + archs.join("\n\t")
|
println "Adding LWJGL native dependencies for platforms:\n\t" + archs.join("\n\t")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (project.ext.lwjglNatives.isEmpty()) println "WTF"
|
if (project.ext.lwjglNatives.isEmpty()) println "WTF"
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
archs.each { arch ->
|
archs.each { arch ->
|
||||||
runtimeOnly "org.lwjgl:lwjgl::$arch"
|
runtimeOnly "org.lwjgl:lwjgl::$arch"
|
||||||
runtimeOnly "org.lwjgl:lwjgl-glfw::$arch"
|
runtimeOnly "org.lwjgl:lwjgl-glfw::$arch"
|
||||||
runtimeOnly "org.lwjgl:lwjgl-openal::$arch"
|
runtimeOnly "org.lwjgl:lwjgl-openal::$arch"
|
||||||
runtimeOnly "org.lwjgl:lwjgl-opengl::$arch"
|
runtimeOnly "org.lwjgl:lwjgl-opengl::$arch"
|
||||||
runtimeOnly "org.lwjgl:lwjgl-stb::$arch"
|
runtimeOnly "org.lwjgl:lwjgl-stb::$arch"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
compileJava.mustRunAfter addNativeDependencies // Make sure runtimeOnly has not been resolved
|
compileJava.mustRunAfter addNativeDependencies // Make sure runtimeOnly has not been resolved
|
||||||
|
|
||||||
task requestLinuxDependencies {
|
task requestLinuxDependencies {
|
||||||
description 'Adds linux, linux-arm64 and linux-arm32 native libraries to built artifacts.'
|
description 'Adds linux, linux-arm64 and linux-arm32 native libraries to built artifacts.'
|
||||||
doFirst {
|
doFirst {
|
||||||
project.ext.platforms.addAll(['natives-linux', 'natives-linux-arm64', 'natives-linux-arm32'])
|
project.ext.platforms.addAll([
|
||||||
|
'natives-linux',
|
||||||
|
'natives-linux-arm64',
|
||||||
|
'natives-linux-arm32'
|
||||||
|
])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
task requestWindowsDependencies {
|
task requestWindowsDependencies {
|
||||||
description 'Adds windows and windows-x86 native libraries to built artifacts.'
|
description 'Adds windows and windows-x86 native libraries to built artifacts.'
|
||||||
doFirst {
|
doFirst {
|
||||||
project.ext.platforms.addAll(['natives-windows', 'natives-windows-x86'])
|
project.ext.platforms.addAll([
|
||||||
|
'natives-windows',
|
||||||
|
'natives-windows-x86'
|
||||||
|
])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
task requestMacOSDependencies {
|
task requestMacOSDependencies {
|
||||||
description 'Adds macos native libraries to built artifacts.'
|
description 'Adds macos native libraries to built artifacts.'
|
||||||
doFirst {
|
doFirst {
|
||||||
project.ext.platforms.addAll(['natives-macos'])
|
project.ext.platforms.addAll(['natives-macos'])
|
||||||
}
|
}
|
||||||
@ -192,7 +198,7 @@ task requestMacOSDependencies {
|
|||||||
def dependencySpecificationTasks = tasks.findAll { task -> task.name.startsWith('request') && task.name.endsWith('Dependencies') }
|
def dependencySpecificationTasks = tasks.findAll { task -> task.name.startsWith('request') && task.name.endsWith('Dependencies') }
|
||||||
|
|
||||||
task requestCrossPlatformDependencies {
|
task requestCrossPlatformDependencies {
|
||||||
description 'Adds native libraries for all available platforms to built artifacts.'
|
description 'Adds native libraries for all available platforms to built artifacts.'
|
||||||
dependsOn dependencySpecificationTasks
|
dependsOn dependencySpecificationTasks
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,7 +211,7 @@ def isDependencyRequested(String dep) {
|
|||||||
if (dep.endsWith(".jar")) {
|
if (dep.endsWith(".jar")) {
|
||||||
dep = dep.substring(0, dep.length() - ".jar".length())
|
dep = dep.substring(0, dep.length() - ".jar".length())
|
||||||
}
|
}
|
||||||
|
|
||||||
return !dep.contains("natives-") ||
|
return !dep.contains("natives-") ||
|
||||||
project.ext.platforms.contains(dep.substring(dep.indexOf("natives-"), dep.length()))
|
project.ext.platforms.contains(dep.substring(dep.indexOf("natives-"), dep.length()))
|
||||||
}
|
}
|
||||||
@ -219,7 +225,7 @@ task specifyLocalManifest {
|
|||||||
|
|
||||||
doFirst {
|
doFirst {
|
||||||
def classPath = []
|
def classPath = []
|
||||||
|
|
||||||
configurations.runtimeClasspath.each {
|
configurations.runtimeClasspath.each {
|
||||||
if (isDependencyRequested(it.getName())) {
|
if (isDependencyRequested(it.getName())) {
|
||||||
classPath.add("lib/" + it.getName())
|
classPath.add("lib/" + it.getName())
|
||||||
@ -227,18 +233,18 @@ task specifyLocalManifest {
|
|||||||
println "\tRemoving from JAR classpath (not requested): " + it.getName()
|
println "\tRemoving from JAR classpath (not requested): " + it.getName()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (classPath.size() == configurations.runtimeClasspath.size()) {
|
if (classPath.size() == configurations.runtimeClasspath.size()) {
|
||||||
println "Nothing removed from JAR classpath"
|
println "Nothing removed from JAR classpath"
|
||||||
}
|
}
|
||||||
|
|
||||||
jar {
|
jar {
|
||||||
manifest {
|
manifest {
|
||||||
attributes(
|
attributes(
|
||||||
"Main-Class": "ru.windcorp.progressia.client.ProgressiaClientMain",
|
"Main-Class": "ru.windcorp.progressia.client.ProgressiaClientMain",
|
||||||
"Class-Path": configurations.runtimeClasspath.collect { "lib/" + it.getName() } .findAll { isDependencyRequested(it) } .join(' ')
|
"Class-Path": configurations.runtimeClasspath.collect { "lib/" + it.getName() } .findAll { isDependencyRequested(it) } .join(' ')
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -248,13 +254,13 @@ jar.dependsOn specifyLocalManifest
|
|||||||
/*
|
/*
|
||||||
* Library export
|
* Library export
|
||||||
*/
|
*/
|
||||||
|
|
||||||
task exportLibs(type: Sync) {
|
task exportLibs(type: Sync) {
|
||||||
mustRunAfter addNativeDependencies
|
mustRunAfter addNativeDependencies
|
||||||
|
|
||||||
into libsDirectory.get().getAsFile().getPath() + "/lib"
|
into libsDirectory.get().getAsFile().getPath() + "/lib"
|
||||||
exclude { !isDependencyRequested(it.getName()) }
|
exclude { !isDependencyRequested(it.getName()) }
|
||||||
from configurations.runtimeClasspath
|
from configurations.runtimeClasspath
|
||||||
}
|
}
|
||||||
|
|
||||||
jar.dependsOn(exportLibs)
|
jar.dependsOn(exportLibs)
|
||||||
@ -264,52 +270,52 @@ jar.dependsOn(exportLibs)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
task packageDebian(type: Exec) {
|
task packageDebian(type: Exec) {
|
||||||
description 'Builds the project and creates a Debain package.'
|
description 'Builds the project and creates a Debain package.'
|
||||||
group 'Progressia'
|
group 'Progressia'
|
||||||
|
|
||||||
dependsOn build
|
dependsOn build
|
||||||
dependsOn requestLinuxDependencies
|
dependsOn requestLinuxDependencies
|
||||||
|
|
||||||
commandLine './buildPackages.sh', 'debian'
|
commandLine './buildPackages.sh', 'debian'
|
||||||
|
|
||||||
doLast {
|
doLast {
|
||||||
println "Debian package available in build_packages/"
|
println "Debian package available in build_packages/"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
task packageWindows(type: Exec) {
|
task packageWindows(type: Exec) {
|
||||||
description 'Builds the project and creates a Windows installer.'
|
description 'Builds the project and creates a Windows installer.'
|
||||||
group 'Progressia'
|
group 'Progressia'
|
||||||
|
|
||||||
dependsOn build
|
dependsOn build
|
||||||
dependsOn requestWindowsDependencies
|
dependsOn requestWindowsDependencies
|
||||||
|
|
||||||
commandLine './buildPackages.sh', 'windows'
|
commandLine './buildPackages.sh', 'windows'
|
||||||
|
|
||||||
doLast {
|
doLast {
|
||||||
println "Windows installer available in build_packages/"
|
println "Windows installer available in build_packages/"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
task buildCrossPlatform {
|
task buildCrossPlatform {
|
||||||
description 'Builds the project including native libraries for all available platforms.'
|
description 'Builds the project including native libraries for all available platforms.'
|
||||||
group 'Progressia'
|
group 'Progressia'
|
||||||
|
|
||||||
dependsOn requestCrossPlatformDependencies
|
dependsOn requestCrossPlatformDependencies
|
||||||
dependsOn build
|
dependsOn build
|
||||||
|
|
||||||
doLast {
|
doLast {
|
||||||
println "Native libraries for all platforms have been added"
|
println "Native libraries for all platforms have been added"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
task buildLocal {
|
task buildLocal {
|
||||||
description "Builds the project including only native libraries for current platform ($lwjglNatives)."
|
description "Builds the project including only native libraries for current platform ($lwjglNatives)."
|
||||||
group 'Progressia'
|
group 'Progressia'
|
||||||
|
|
||||||
dependsOn build
|
dependsOn build
|
||||||
|
|
||||||
doLast {
|
doLast {
|
||||||
println "Native libraries only for platform $lwjglNatives have been added"
|
println "Native libraries only for platform $lwjglNatives have been added"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
12
docs/ProgressiaRegion.md
Normal file
12
docs/ProgressiaRegion.md
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# Progressia Region File
|
||||||
|
## Description
|
||||||
|
The `.progressia_region` file type is used for all region files in the game Progressia. Each region file contains a cube of 16x16x16 chunks.
|
||||||
|
## Header
|
||||||
|
The header of the file is 16 400 bytes. Every file starts with the string byte sequence `\x50\x52\x4F\x47` (UTF-8 for `PROG`), followed with the three integer values of the region position, in region coordinates. After this, there is exactly 16KiB of space in the header, which stores the offsets to the chunks' data. This space holds an integer, 4 bytes, for each chunk in the region. The integer value starts at 0 for every chunk, and is changed to the location of the chunk data once created. These are indexed in order by flattening the 3D in-chunk coordinates into a number between 0 and 4095 according to the formula `offset = 256*x+ 16*y + z` for chunk at (x, y, z). To convert from this offset value to the offset in bytes, use `byte_offset = 16400 + 64*n`.
|
||||||
|
## Sectors
|
||||||
|
Sectors are what is used to store chunk data, and are not linear, but are followed until they reach an ending block. Each is 64 bytes, which is used in the header section to find the byte offset. Each sector starts with a identification byte, followed by the sector data.
|
||||||
|
|
||||||
|
0. Ending - This sector is empty, and marks the end of the chunk data (This may change in the future.
|
||||||
|
1. Data - This sector contains chunk data for a single chunk. The second byte of this sector contains a counter byte, which is a form of "checksum" to make sure that the program is reading the proper sectors in order. This starts at 0 for the first data sector and increments by one for each new data sector.
|
||||||
|
2. Partition Link - This sector only contains another offset value, which is where the next sector is. This allows for infinite chunk size, avoiding "chunk dupes" as were present in Minecraft without reverting any chunks.
|
||||||
|
3. Bulk Data - These would be used for many chunks in the same region that contain exactly the same data, e.g. all solid chunks underground. Exists so the program knows not to overwrite them, and just make new chunk data if modified. Not yet implemented.
|
@ -41,4 +41,17 @@ Run configurations are used by Intellij IDEA to specify how a project must be ru
|
|||||||
8. Append `\run` to the 'Working directory' field. Alternatively, specify another location outside of the project's root directory.
|
8. Append `\run` to the 'Working directory' field. Alternatively, specify another location outside of the project's root directory.
|
||||||
9. Click 'Apply' to save changes.
|
9. Click 'Apply' to save changes.
|
||||||
|
|
||||||
Step 8 is required to specify that the game must run in some directory other than the project root, which is the default in Intellij IDEA.
|
Step 8 is required to specify that the game must run in some directory other than the project root, which is the default in Intellij IDEA.
|
||||||
|
|
||||||
|
### Applying formatting templates
|
||||||
|
|
||||||
|
Windcorp's Progressia repository is formatted with a style defined for Eclipse IDE (sic) in
|
||||||
|
`templates_and_presets/eclipse_ide`.
|
||||||
|
Please apply these templates to the project to automatically format the source in a similar fashion.
|
||||||
|
|
||||||
|
1. In project context menu, click 'File->Properties'. (`Ctrl+Alt+S`)
|
||||||
|
2. In 'Editor' > 'Code Style' > 'Java', press gear icon, then click 'Import Scheme' > 'Eclipse code style'
|
||||||
|
3. In Scheme select 'Project'
|
||||||
|
4. Open the file `templates_and_presets/eclipse_ide/FormatterProfile.xml` in 'Select Path'.
|
||||||
|
5. Inside 'Import Scheme' widow click 'Current Scheme' check box after press OK
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil;
|
package ru.windcorp.jputil;
|
||||||
|
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
@ -611,7 +611,8 @@ public class ArrayUtil {
|
|||||||
int end = offset + length;
|
int end = offset + length;
|
||||||
if (end > arrayLength || offset < 0)
|
if (end > arrayLength || offset < 0)
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Array contains [0; " + arrayLength + "), requested [" + offset + "; " + end + ")");
|
"Array contains [0; " + arrayLength + "), requested [" + offset + "; " + end + ")"
|
||||||
|
);
|
||||||
|
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
@ -627,7 +628,8 @@ public class ArrayUtil {
|
|||||||
|
|
||||||
if (end > arrayLength || start < 0)
|
if (end > arrayLength || start < 0)
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Array contains [0; " + arrayLength + "), requested [" + start + "; " + end + ")");
|
"Array contains [0; " + arrayLength + "), requested [" + start + "; " + end + ")"
|
||||||
|
);
|
||||||
|
|
||||||
return end;
|
return end;
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil;
|
package ru.windcorp.jputil;
|
||||||
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil;
|
package ru.windcorp.jputil;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -30,8 +30,18 @@ public class PrimitiveUtil {
|
|||||||
private static final Map<Class<?>, Object> PRIMITIVE_TO_NULL = new HashMap<>();
|
private static final Map<Class<?>, Object> PRIMITIVE_TO_NULL = new HashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
for (Class<?> boxed : new Class<?>[] { Boolean.class, Byte.class, Short.class, Character.class, Integer.class,
|
for (
|
||||||
Long.class, Float.class, Double.class }) {
|
Class<?> boxed : new Class<?>[] {
|
||||||
|
Boolean.class,
|
||||||
|
Byte.class,
|
||||||
|
Short.class,
|
||||||
|
Character.class,
|
||||||
|
Integer.class,
|
||||||
|
Long.class,
|
||||||
|
Float.class,
|
||||||
|
Double.class
|
||||||
|
}
|
||||||
|
) {
|
||||||
try {
|
try {
|
||||||
PRIMITIVE_TO_BOXED.put((Class<?>) boxed.getField("TYPE").get(null), boxed);
|
PRIMITIVE_TO_BOXED.put((Class<?>) boxed.getField("TYPE").get(null), boxed);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil;
|
package ru.windcorp.jputil;
|
||||||
|
|
||||||
import java.util.function.*;
|
import java.util.function.*;
|
||||||
@ -40,7 +40,8 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains static methods to create {@link Stream Streams} that synchronize
|
* Contains static methods to create {@link Stream Streams} that synchronize
|
||||||
* their <a href=
|
* their
|
||||||
|
* <a href=
|
||||||
* "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
|
* "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
|
||||||
* terminal operations</a> on a given monitor.
|
* terminal operations</a> on a given monitor.
|
||||||
*
|
*
|
||||||
@ -49,7 +50,7 @@ import java.util.stream.Stream;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// SonarLint: "Stream.peek" should be used with caution (java:S3864)
|
// SonarLint: "Stream.peek" should be used with caution (java:S3864)
|
||||||
// We are implementing Stream, so peek() is required.
|
// We are implementing Stream, so peek() is required.
|
||||||
@SuppressWarnings("squid:S3864")
|
@SuppressWarnings("squid:S3864")
|
||||||
|
|
||||||
public class SyncStreams {
|
public class SyncStreams {
|
||||||
@ -1069,18 +1070,21 @@ public class SyncStreams {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps the given {@link Stream} to make all <a href=
|
* Wraps the given {@link Stream} to make all
|
||||||
|
* <a href=
|
||||||
* "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
|
* "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
|
||||||
* terminal operations</a> acquire the provided monitor's lock before
|
* terminal operations</a> acquire the provided monitor's lock before
|
||||||
* execution. Intermediate operations return streams that are also
|
* execution. Intermediate operations
|
||||||
* synchronized on the same object. The created stream will behave
|
* return streams that are also synchronized on the same object. The created
|
||||||
* identically to the provided stream in all other aspects. Use this to
|
* stream will behave identically
|
||||||
* synchronize access to stream's source.
|
* to the provided stream in all other aspects. Use this to synchronize
|
||||||
|
* access to stream's source.
|
||||||
* <p>
|
* <p>
|
||||||
* <i>The returned {@code Stream}'s {@link Stream#iterator() iterator()} and
|
* <i>The returned {@code Stream}'s {@link Stream#iterator() iterator()} and
|
||||||
* {@link Stream#spliterator() spliterator()} methods return regular
|
* {@link Stream#spliterator()
|
||||||
* non-synchronized iterators and spliterators respectively</i>. It is the
|
* spliterator()} methods return regular non-synchronized iterators and
|
||||||
* user's responsibility to avoid concurrency issues:
|
* spliterators respectively</i>. It
|
||||||
|
* is the user's responsibility to avoid concurrency issues:
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* synchronized (stream.getMonitor()) {
|
* synchronized (stream.getMonitor()) {
|
||||||
@ -1099,17 +1103,14 @@ public class SyncStreams {
|
|||||||
* stream.forEach(System.out::println); // Should never throw a ConcurrentModificationException
|
* stream.forEach(System.out::println); // Should never throw a ConcurrentModificationException
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param <T>
|
* @param <T> the class of objects in the Stream
|
||||||
* the class of objects in the Stream
|
* @param stream the stream to wrap.
|
||||||
* @param stream
|
* @param monitor the object that the stream will use for synchronization.
|
||||||
* the stream to wrap.
|
* When {@code null}, the stream
|
||||||
* @param monitor
|
* will synchronize on itself.
|
||||||
* the object that the stream will use for synchronization. When
|
|
||||||
* {@code null}, the stream will synchronize on itself.
|
|
||||||
* @return a {@link SyncStream SyncStream<T>} synchronized on
|
* @return a {@link SyncStream SyncStream<T>} synchronized on
|
||||||
* {@code monitor} and backed by {@code stream}.
|
* {@code monitor} and backed by {@code stream}.
|
||||||
* @throws NullPointerException
|
* @throws NullPointerException if {@code stream == null}.
|
||||||
* if {@code stream == null}.
|
|
||||||
*/
|
*/
|
||||||
public static <T> SyncStream<T> synchronizedStream(Stream<T> stream, Object monitor) {
|
public static <T> SyncStream<T> synchronizedStream(Stream<T> stream, Object monitor) {
|
||||||
Objects.requireNonNull(stream, "stream cannot be null");
|
Objects.requireNonNull(stream, "stream cannot be null");
|
||||||
@ -1117,19 +1118,22 @@ public class SyncStreams {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps the given {@link IntStream} to make all <a href=
|
* Wraps the given {@link IntStream} to make all
|
||||||
|
* <a href=
|
||||||
* "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
|
* "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
|
||||||
* terminal operations</a> acquire the provided monitor's lock before
|
* terminal operations</a> acquire the provided monitor's lock before
|
||||||
* execution. Intermediate operations return streams that are also
|
* execution. Intermediate operations
|
||||||
* synchronized on the same object. The created stream will behave
|
* return streams that are also synchronized on the same object. The created
|
||||||
* identically to the provided stream in all other aspects. Use this to
|
* stream will behave identically
|
||||||
* synchronize access to stream's source.
|
* to the provided stream in all other aspects. Use this to synchronize
|
||||||
|
* access to stream's source.
|
||||||
* <p>
|
* <p>
|
||||||
* <i>The returned {@code IntStream}'s {@link IntStream#iterator()
|
* <i>The returned {@code IntStream}'s {@link IntStream#iterator()
|
||||||
* iterator()} and {@link IntStream#spliterator() spliterator()} methods
|
* iterator()} and
|
||||||
* return regular non-synchronized iterators and spliterators
|
* {@link IntStream#spliterator() spliterator()} methods return regular
|
||||||
* respectively</i>. It is the user's responsibility to avoid concurrency
|
* non-synchronized iterators and
|
||||||
* issues:
|
* spliterators respectively</i>. It is the user's responsibility to avoid
|
||||||
|
* concurrency issues:
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* synchronized (stream.getMonitor()) {
|
* synchronized (stream.getMonitor()) {
|
||||||
@ -1148,15 +1152,13 @@ public class SyncStreams {
|
|||||||
* stream.forEach(System.out::println); // Should never throw a ConcurrentModificationException
|
* stream.forEach(System.out::println); // Should never throw a ConcurrentModificationException
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param stream
|
* @param stream the stream to wrap.
|
||||||
* the stream to wrap.
|
* @param monitor the object that the stream will use for synchronization.
|
||||||
* @param monitor
|
* When {@code null}, the stream
|
||||||
* the object that the stream will use for synchronization. When
|
* will synchronize on itself.
|
||||||
* {@code null}, the stream will synchronize on itself.
|
|
||||||
* @return a {@link SyncIntStream} synchronized on {@code monitor} and
|
* @return a {@link SyncIntStream} synchronized on {@code monitor} and
|
||||||
* backed by {@code stream}.
|
* backed by {@code stream}.
|
||||||
* @throws NullPointerException
|
* @throws NullPointerException if {@code stream == null}.
|
||||||
* if {@code stream == null}.
|
|
||||||
*/
|
*/
|
||||||
public static SyncIntStream synchronizedStream(IntStream stream, Object monitor) {
|
public static SyncIntStream synchronizedStream(IntStream stream, Object monitor) {
|
||||||
Objects.requireNonNull(stream, "stream cannot be null");
|
Objects.requireNonNull(stream, "stream cannot be null");
|
||||||
@ -1164,19 +1166,22 @@ public class SyncStreams {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps the given {@link LongStream} to make all <a href=
|
* Wraps the given {@link LongStream} to make all
|
||||||
|
* <a href=
|
||||||
* "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
|
* "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
|
||||||
* terminal operations</a> acquire the provided monitor's lock before
|
* terminal operations</a> acquire the provided monitor's lock before
|
||||||
* execution. Intermediate operations return streams that are also
|
* execution. Intermediate operations
|
||||||
* synchronized on the same object. The created stream will behave
|
* return streams that are also synchronized on the same object. The created
|
||||||
* identically to the provided stream in all other aspects. Use this to
|
* stream will behave identically
|
||||||
* synchronize access to stream's source.
|
* to the provided stream in all other aspects. Use this to synchronize
|
||||||
|
* access to stream's source.
|
||||||
* <p>
|
* <p>
|
||||||
* <i>The returned {@code LongStream}'s {@link LongStream#iterator()
|
* <i>The returned {@code LongStream}'s {@link LongStream#iterator()
|
||||||
* iterator()} and {@link LongStream#spliterator() spliterator()} methods
|
* iterator()} and
|
||||||
* return regular non-synchronized iterators and spliterators
|
* {@link LongStream#spliterator() spliterator()} methods return regular
|
||||||
* respectively</i>. It is the user's responsibility to avoid concurrency
|
* non-synchronized iterators and
|
||||||
* issues:
|
* spliterators respectively</i>. It is the user's responsibility to avoid
|
||||||
|
* concurrency issues:
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* synchronized (stream.getMonitor()) {
|
* synchronized (stream.getMonitor()) {
|
||||||
@ -1195,15 +1200,13 @@ public class SyncStreams {
|
|||||||
* stream.forEach(System.out::println); // Should never throw a ConcurrentModificationException
|
* stream.forEach(System.out::println); // Should never throw a ConcurrentModificationException
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param stream
|
* @param stream the stream to wrap.
|
||||||
* the stream to wrap.
|
* @param monitor the object that the stream will use for synchronization.
|
||||||
* @param monitor
|
* When {@code null}, the stream
|
||||||
* the object that the stream will use for synchronization. When
|
* will synchronize on itself.
|
||||||
* {@code null}, the stream will synchronize on itself.
|
|
||||||
* @return a {@link SyncLongStream} synchronized on {@code monitor} and
|
* @return a {@link SyncLongStream} synchronized on {@code monitor} and
|
||||||
* backed by {@code stream}.
|
* backed by {@code stream}.
|
||||||
* @throws NullPointerException
|
* @throws NullPointerException if {@code stream == null}.
|
||||||
* if {@code stream == null}.
|
|
||||||
*/
|
*/
|
||||||
public static SyncLongStream synchronizedStream(LongStream stream, Object monitor) {
|
public static SyncLongStream synchronizedStream(LongStream stream, Object monitor) {
|
||||||
Objects.requireNonNull(stream, "stream cannot be null");
|
Objects.requireNonNull(stream, "stream cannot be null");
|
||||||
@ -1211,19 +1214,22 @@ public class SyncStreams {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps the given {@link DoubleStream} to make all <a href=
|
* Wraps the given {@link DoubleStream} to make all
|
||||||
|
* <a href=
|
||||||
* "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
|
* "https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
|
||||||
* terminal operations</a> acquire the provided monitor's lock before
|
* terminal operations</a> acquire the provided monitor's lock before
|
||||||
* execution. Intermediate operations return streams that are also
|
* execution. Intermediate operations
|
||||||
* synchronized on the same object. The created stream will behave
|
* return streams that are also synchronized on the same object. The created
|
||||||
* identically to the provided stream in all other aspects. Use this to
|
* stream will behave identically
|
||||||
* synchronize access to stream's source.
|
* to the provided stream in all other aspects. Use this to synchronize
|
||||||
|
* access to stream's source.
|
||||||
* <p>
|
* <p>
|
||||||
* <i>The returned {@code DoubleStream}'s {@link DoubleStream#iterator()
|
* <i>The returned {@code DoubleStream}'s {@link DoubleStream#iterator()
|
||||||
* iterator()} and {@link DoubleStream#spliterator() spliterator()} methods
|
* iterator()} and
|
||||||
* return regular non-synchronized iterators and spliterators
|
* {@link DoubleStream#spliterator() spliterator()} methods return regular
|
||||||
* respectively</i>. It is the user's responsibility to avoid concurrency
|
* non-synchronized iterators and
|
||||||
* issues:
|
* spliterators respectively</i>. It is the user's responsibility to avoid
|
||||||
|
* concurrency issues:
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* synchronized (stream.getMonitor()) {
|
* synchronized (stream.getMonitor()) {
|
||||||
@ -1242,15 +1248,13 @@ public class SyncStreams {
|
|||||||
* stream.forEach(System.out::println); // Should never throw a ConcurrentModificationException
|
* stream.forEach(System.out::println); // Should never throw a ConcurrentModificationException
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param stream
|
* @param stream the stream to wrap.
|
||||||
* the stream to wrap.
|
* @param monitor the object that the stream will use for synchronization.
|
||||||
* @param monitor
|
* When {@code null}, the stream
|
||||||
* the object that the stream will use for synchronization. When
|
* will synchronize on itself.
|
||||||
* {@code null}, the stream will synchronize on itself.
|
|
||||||
* @return a {@link SyncDoubleStream} synchronized on {@code monitor} and
|
* @return a {@link SyncDoubleStream} synchronized on {@code monitor} and
|
||||||
* backed by {@code stream}.
|
* backed by {@code stream}.
|
||||||
* @throws NullPointerException
|
* @throws NullPointerException if {@code stream == null}.
|
||||||
* if {@code stream == null}.
|
|
||||||
*/
|
*/
|
||||||
public static SyncDoubleStream synchronizedStream(DoubleStream stream, Object monitor) {
|
public static SyncDoubleStream synchronizedStream(DoubleStream stream, Object monitor) {
|
||||||
Objects.requireNonNull(stream, "stream cannot be null");
|
Objects.requireNonNull(stream, "stream cannot be null");
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil;
|
package ru.windcorp.jputil;
|
||||||
|
|
||||||
public class SyntaxException extends Exception {
|
public class SyntaxException extends Exception {
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars;
|
package ru.windcorp.jputil.chars;
|
||||||
|
|
||||||
import java.text.CharacterIterator;
|
import java.text.CharacterIterator;
|
||||||
@ -108,7 +108,7 @@ public class CharArrayIterator implements CharacterIterator {
|
|||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @SuppressWarnings("all") Just STFU, this _is_ terrific
|
// @SuppressWarnings("all") Just STFU, this _is_ terrific
|
||||||
|
|
||||||
// SonarLint: "clone" should not be overridden (java:S2975)
|
// SonarLint: "clone" should not be overridden (java:S2975)
|
||||||
// And I wouldn't have done that if only CharacterIterator had not required
|
// And I wouldn't have done that if only CharacterIterator had not required
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars;
|
package ru.windcorp.jputil.chars;
|
||||||
|
|
||||||
import java.util.function.IntConsumer;
|
import java.util.function.IntConsumer;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars;
|
package ru.windcorp.jputil.chars;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars;
|
package ru.windcorp.jputil.chars;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars;
|
package ru.windcorp.jputil.chars;
|
||||||
|
|
||||||
import java.util.function.IntSupplier;
|
import java.util.function.IntSupplier;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars;
|
package ru.windcorp.jputil.chars;
|
||||||
|
|
||||||
public class EscapeException extends Exception {
|
public class EscapeException extends Exception {
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars;
|
package ru.windcorp.jputil.chars;
|
||||||
|
|
||||||
import java.text.CharacterIterator;
|
import java.text.CharacterIterator;
|
||||||
@ -103,8 +103,14 @@ public class Escaper {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Escaper JAVA = new Escaper('\\', 'u', "tbnrf'\"".toCharArray(), "\t\b\n\r\f\'\"".toCharArray(),
|
public static final Escaper JAVA = new Escaper(
|
||||||
true, true);
|
'\\',
|
||||||
|
'u',
|
||||||
|
"tbnrf'\"".toCharArray(),
|
||||||
|
"\t\b\n\r\f\'\"".toCharArray(),
|
||||||
|
true,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
private final char escapeChar;
|
private final char escapeChar;
|
||||||
private final char unicodeEscapeChar;
|
private final char unicodeEscapeChar;
|
||||||
@ -114,8 +120,14 @@ public class Escaper {
|
|||||||
private final boolean preferUnicode;
|
private final boolean preferUnicode;
|
||||||
private final boolean strict;
|
private final boolean strict;
|
||||||
|
|
||||||
protected Escaper(char escapeChar, char unicodeEscapeChar, char[] safes, char[] unsafes, boolean preferUnicode,
|
protected Escaper(
|
||||||
boolean strict) {
|
char escapeChar,
|
||||||
|
char unicodeEscapeChar,
|
||||||
|
char[] safes,
|
||||||
|
char[] unsafes,
|
||||||
|
boolean preferUnicode,
|
||||||
|
boolean strict
|
||||||
|
) {
|
||||||
this.escapeChar = escapeChar;
|
this.escapeChar = escapeChar;
|
||||||
this.unicodeEscapeChar = unicodeEscapeChar;
|
this.unicodeEscapeChar = unicodeEscapeChar;
|
||||||
this.safes = safes;
|
this.safes = safes;
|
||||||
@ -140,7 +152,8 @@ public class Escaper {
|
|||||||
for (char c : unsafes) {
|
for (char c : unsafes) {
|
||||||
if (c == escapeChar)
|
if (c == escapeChar)
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Unsafe characters contain escape chatacter (escape character is escaped automatically)");
|
"Unsafe characters contain escape chatacter (escape character is escaped automatically)"
|
||||||
|
);
|
||||||
if (c == unicodeEscapeChar)
|
if (c == unicodeEscapeChar)
|
||||||
throw new IllegalArgumentException("Unsafe characters contain Unicode escape chatacter");
|
throw new IllegalArgumentException("Unsafe characters contain Unicode escape chatacter");
|
||||||
}
|
}
|
||||||
@ -160,7 +173,11 @@ public class Escaper {
|
|||||||
end = Integer.MAX_VALUE;
|
end = Integer.MAX_VALUE;
|
||||||
else
|
else
|
||||||
end = src.getPosition() + length;
|
end = src.getPosition() + length;
|
||||||
while (src.has() && src.getPosition() < end && (until == null || !until.test(src.current())))
|
while (
|
||||||
|
src.has() &&
|
||||||
|
src.getPosition() < end &&
|
||||||
|
(until == null || !until.test(src.current()))
|
||||||
|
)
|
||||||
escape(src.consume(), output);
|
escape(src.consume(), output);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,7 +225,11 @@ public class Escaper {
|
|||||||
|
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
while (src.has() && src.getPosition() < end && (until == null || !until.test(src.current()))) {
|
while (
|
||||||
|
src.has() &&
|
||||||
|
src.getPosition() < end &&
|
||||||
|
(until == null || !until.test(src.current()))
|
||||||
|
) {
|
||||||
result += getEscapedLength(src.consume());
|
result += getEscapedLength(src.consume());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,7 +257,11 @@ public class Escaper {
|
|||||||
end = Integer.MAX_VALUE;
|
end = Integer.MAX_VALUE;
|
||||||
else
|
else
|
||||||
end = src.getPosition() + length;
|
end = src.getPosition() + length;
|
||||||
while (src.has() && src.getPosition() < end && (until == null || !until.test(src.current()))) {
|
while (
|
||||||
|
src.has() &&
|
||||||
|
src.getPosition() < end &&
|
||||||
|
(until == null || !until.test(src.current()))
|
||||||
|
) {
|
||||||
output.accept(unescapeOneSequence(src));
|
output.accept(unescapeOneSequence(src));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -257,8 +282,10 @@ public class Escaper {
|
|||||||
|
|
||||||
if (src.current() == unicodeEscapeChar) {
|
if (src.current() == unicodeEscapeChar) {
|
||||||
src.next();
|
src.next();
|
||||||
return (char) (hexValue(src.consume()) << (4 * 3) | hexValue(src.consume()) << (4 * 2)
|
return (char) (hexValue(src.consume()) << (4 * 3) |
|
||||||
| hexValue(src.consume()) << (4 * 1) | hexValue(src.consume()) << (4 * 0));
|
hexValue(src.consume()) << (4 * 2) |
|
||||||
|
hexValue(src.consume()) << (4 * 1) |
|
||||||
|
hexValue(src.consume()) << (4 * 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
int index = ArrayUtil.firstIndexOf(safes, src.current());
|
int index = ArrayUtil.firstIndexOf(safes, src.current());
|
||||||
@ -288,7 +315,11 @@ public class Escaper {
|
|||||||
|
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
while (src.has() && src.getPosition() < end && (until == null || !until.test(src.current()))) {
|
while (
|
||||||
|
src.has() &&
|
||||||
|
src.getPosition() < end &&
|
||||||
|
(until == null || !until.test(src.current()))
|
||||||
|
) {
|
||||||
skipOneSequence(src);
|
skipOneSequence(src);
|
||||||
result++;
|
result++;
|
||||||
}
|
}
|
||||||
@ -297,7 +328,11 @@ public class Escaper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void skipOneSequence(CharReader src) {
|
public void skipOneSequence(CharReader src) {
|
||||||
if (src.current() == escapeChar && src.next() == unicodeEscapeChar) {
|
if (
|
||||||
|
src.current() == escapeChar
|
||||||
|
&&
|
||||||
|
src.next() == unicodeEscapeChar
|
||||||
|
) {
|
||||||
src.advance(4);
|
src.advance(4);
|
||||||
}
|
}
|
||||||
src.next();
|
src.next();
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars;
|
package ru.windcorp.jputil.chars;
|
||||||
|
|
||||||
import java.text.CharacterIterator;
|
import java.text.CharacterIterator;
|
||||||
@ -86,7 +86,7 @@ public class FancyCharacterIterator implements CharacterIterator {
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// @SuppressWarnings("all") Just STFU, this _is_ terrific
|
// @SuppressWarnings("all") Just STFU, this _is_ terrific
|
||||||
|
|
||||||
// SonarLint: "clone" should not be overridden (java:S2975)
|
// SonarLint: "clone" should not be overridden (java:S2975)
|
||||||
// And I wouldn't have done that if only CharacterIterator had not required
|
// And I wouldn't have done that if only CharacterIterator had not required
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars;
|
package ru.windcorp.jputil.chars;
|
||||||
|
|
||||||
public class IndentedStringBuilder {
|
public class IndentedStringBuilder {
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars;
|
package ru.windcorp.jputil.chars;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -41,8 +41,13 @@ public class StringUtil {
|
|||||||
private static final String EMPTY_PLACEHOLDER = "[empty]";
|
private static final String EMPTY_PLACEHOLDER = "[empty]";
|
||||||
private static final String DEFAULT_SEPARATOR = "; ";
|
private static final String DEFAULT_SEPARATOR = "; ";
|
||||||
|
|
||||||
public static <T> String arrayToString(T[] array, String separator, String empty, String nullPlaceholder,
|
public static <T> String arrayToString(
|
||||||
String nullArray) {
|
T[] array,
|
||||||
|
String separator,
|
||||||
|
String empty,
|
||||||
|
String nullPlaceholder,
|
||||||
|
String nullArray
|
||||||
|
) {
|
||||||
|
|
||||||
if (separator == null) {
|
if (separator == null) {
|
||||||
throw new IllegalArgumentException(new NullPointerException());
|
throw new IllegalArgumentException(new NullPointerException());
|
||||||
@ -74,8 +79,13 @@ public class StringUtil {
|
|||||||
return arrayToString(array, DEFAULT_SEPARATOR);
|
return arrayToString(array, DEFAULT_SEPARATOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String iteratorToString(Iterator<?> iterator, String separator, String empty, String nullPlaceholder,
|
public static String iteratorToString(
|
||||||
String nullIterator) {
|
Iterator<?> iterator,
|
||||||
|
String separator,
|
||||||
|
String empty,
|
||||||
|
String nullPlaceholder,
|
||||||
|
String nullIterator
|
||||||
|
) {
|
||||||
|
|
||||||
if (separator == null) {
|
if (separator == null) {
|
||||||
throw new IllegalArgumentException(new NullPointerException());
|
throw new IllegalArgumentException(new NullPointerException());
|
||||||
@ -109,8 +119,13 @@ public class StringUtil {
|
|||||||
return iteratorToString(iterator, DEFAULT_SEPARATOR);
|
return iteratorToString(iterator, DEFAULT_SEPARATOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String iterableToString(Iterable<?> iterable, String separator, String empty, String nullPlaceholder,
|
public static String iterableToString(
|
||||||
String nullIterable) {
|
Iterable<?> iterable,
|
||||||
|
String separator,
|
||||||
|
String empty,
|
||||||
|
String nullPlaceholder,
|
||||||
|
String nullIterable
|
||||||
|
) {
|
||||||
|
|
||||||
if (separator == null) {
|
if (separator == null) {
|
||||||
throw new IllegalArgumentException(new NullPointerException());
|
throw new IllegalArgumentException(new NullPointerException());
|
||||||
@ -131,8 +146,14 @@ public class StringUtil {
|
|||||||
return iterableToString(iterable, DEFAULT_SEPARATOR);
|
return iterableToString(iterable, DEFAULT_SEPARATOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> String supplierToString(IntFunction<T> supplier, int length, String separator, String empty,
|
public static <T> String supplierToString(
|
||||||
String nullPlaceholder, String nullSupplier) {
|
IntFunction<T> supplier,
|
||||||
|
int length,
|
||||||
|
String separator,
|
||||||
|
String empty,
|
||||||
|
String nullPlaceholder,
|
||||||
|
String nullSupplier
|
||||||
|
) {
|
||||||
|
|
||||||
if (separator == null)
|
if (separator == null)
|
||||||
throw new IllegalArgumentException(new NullPointerException());
|
throw new IllegalArgumentException(new NullPointerException());
|
||||||
@ -142,15 +163,28 @@ public class StringUtil {
|
|||||||
return empty;
|
return empty;
|
||||||
|
|
||||||
if (length > 0) {
|
if (length > 0) {
|
||||||
return supplierToStringExactly(supplier, length, separator, nullPlaceholder);
|
return supplierToStringExactly(
|
||||||
|
supplier,
|
||||||
|
length,
|
||||||
|
separator,
|
||||||
|
nullPlaceholder
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
return supplierToStringUntilNull(supplier, separator, empty);
|
return supplierToStringUntilNull(
|
||||||
|
supplier,
|
||||||
|
separator,
|
||||||
|
empty
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T> String supplierToStringExactly(IntFunction<T> supplier, int length, String separator,
|
private static <T> String supplierToStringExactly(
|
||||||
String nullPlaceholder) {
|
IntFunction<T> supplier,
|
||||||
|
int length,
|
||||||
|
String separator,
|
||||||
|
String nullPlaceholder
|
||||||
|
) {
|
||||||
T element = supplier.apply(0);
|
T element = supplier.apply(0);
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder(element == null ? nullPlaceholder : element.toString());
|
StringBuilder sb = new StringBuilder(element == null ? nullPlaceholder : element.toString());
|
||||||
@ -164,7 +198,11 @@ public class StringUtil {
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T> String supplierToStringUntilNull(IntFunction<T> supplier, String separator, String empty) {
|
private static <T> String supplierToStringUntilNull(
|
||||||
|
IntFunction<T> supplier,
|
||||||
|
String separator,
|
||||||
|
String empty
|
||||||
|
) {
|
||||||
T element = supplier.apply(0);
|
T element = supplier.apply(0);
|
||||||
|
|
||||||
if (element == null) {
|
if (element == null) {
|
||||||
@ -328,7 +366,11 @@ public class StringUtil {
|
|||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
charLoop: for (char c : src.toCharArray()) {
|
charLoop: for (char c : src.toCharArray()) {
|
||||||
if ((resultIndex + 1) < arrayLength && test.test(c)) {
|
if (
|
||||||
|
(resultIndex + 1) < arrayLength
|
||||||
|
&&
|
||||||
|
test.test(c)
|
||||||
|
) {
|
||||||
result[resultIndex] = resetStringBuilder(sb);
|
result[resultIndex] = resetStringBuilder(sb);
|
||||||
++resultIndex;
|
++resultIndex;
|
||||||
continue charLoop;
|
continue charLoop;
|
||||||
@ -347,17 +389,17 @@ public class StringUtil {
|
|||||||
* index.
|
* index.
|
||||||
* <p>
|
* <p>
|
||||||
* Indices {@code 0} and {@code src.length() - 1} produce {@code str}
|
* Indices {@code 0} and {@code src.length() - 1} produce {@code str}
|
||||||
* excluding the specified character and {@code ""}.
|
* excluding
|
||||||
|
* the specified character and {@code ""}.
|
||||||
* <p>
|
* <p>
|
||||||
*
|
*
|
||||||
* @param src
|
* @param src the String to split
|
||||||
* the String to split
|
* @param at index to split at
|
||||||
* @param at
|
* @throws IllegalArgumentException if the index is out of bounds for
|
||||||
* index to split at
|
* {@code src}
|
||||||
* @throws IllegalArgumentException
|
|
||||||
* if the index is out of bounds for {@code src}
|
|
||||||
* @return an array containing the substrings, in order of encounter in
|
* @return an array containing the substrings, in order of encounter in
|
||||||
* {@code src}. Its length is always 2.
|
* {@code src}.
|
||||||
|
* Its length is always 2.
|
||||||
*/
|
*/
|
||||||
public static String[] splitAt(String src, int at) {
|
public static String[] splitAt(String src, int at) {
|
||||||
Objects.requireNonNull(src, "src");
|
Objects.requireNonNull(src, "src");
|
||||||
@ -374,7 +416,10 @@ public class StringUtil {
|
|||||||
return new String[] { src.substring(0, src.length() - 1), "" };
|
return new String[] { src.substring(0, src.length() - 1), "" };
|
||||||
}
|
}
|
||||||
|
|
||||||
return new String[] { src.substring(0, at), src.substring(at + 1) };
|
return new String[] {
|
||||||
|
src.substring(0, at),
|
||||||
|
src.substring(at + 1)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -382,7 +427,8 @@ public class StringUtil {
|
|||||||
* indices.
|
* indices.
|
||||||
* <p>
|
* <p>
|
||||||
* Indices {@code 0} and {@code src.length() - 1} produce extra zero-length
|
* Indices {@code 0} and {@code src.length() - 1} produce extra zero-length
|
||||||
* outputs. Duplicate indices produce extra zero-length outputs.
|
* outputs.
|
||||||
|
* Duplicate indices produce extra zero-length outputs.
|
||||||
* <p>
|
* <p>
|
||||||
* Examples:
|
* Examples:
|
||||||
*
|
*
|
||||||
@ -393,14 +439,13 @@ public class StringUtil {
|
|||||||
* splitAt("a.b", 1, 1, 1) -> {"a", "", "", "b"}
|
* splitAt("a.b", 1, 1, 1) -> {"a", "", "", "b"}
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param src
|
* @param src the String to split
|
||||||
* the String to split
|
* @param at indices to split at, in any order
|
||||||
* @param at
|
* @throws IllegalArgumentException if some index is out of bounds for
|
||||||
* indices to split at, in any order
|
* {@code src}
|
||||||
* @throws IllegalArgumentException
|
|
||||||
* if some index is out of bounds for {@code src}
|
|
||||||
* @return an array containing the substrings, in order of encounter in
|
* @return an array containing the substrings, in order of encounter in
|
||||||
* {@code src}. Its length is always {@code at.length + 1}.
|
* {@code src}.
|
||||||
|
* Its length is always {@code at.length + 1}.
|
||||||
*/
|
*/
|
||||||
public static String[] splitAt(String src, int... at) {
|
public static String[] splitAt(String src, int... at) {
|
||||||
Objects.requireNonNull(src, "src");
|
Objects.requireNonNull(src, "src");
|
||||||
@ -508,8 +553,10 @@ public class StringUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (endPos < beginPos) {
|
if (endPos < beginPos) {
|
||||||
throw new IllegalArgumentException("endPos must be greater than or equal to beginPos (endPos=" + endPos
|
throw new IllegalArgumentException(
|
||||||
+ ", beginPos=" + beginPos + ")");
|
"endPos must be greater than or equal to beginPos (endPos="
|
||||||
|
+ endPos + ", beginPos=" + beginPos + ")"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (endPos >= Math.min(a.length, b.length)) {
|
if (endPos >= Math.min(a.length, b.length)) {
|
||||||
@ -545,7 +592,8 @@ public class StringUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds and returns the index of the specified appearance of the specified
|
* Finds and returns the index of the specified appearance of the specified
|
||||||
* character in the given array. The search starts at index 0.
|
* character
|
||||||
|
* in the given array. The search starts at index 0.
|
||||||
* <p>
|
* <p>
|
||||||
* Examples:
|
* Examples:
|
||||||
* <p>
|
* <p>
|
||||||
@ -582,12 +630,10 @@ public class StringUtil {
|
|||||||
* </tr>
|
* </tr>
|
||||||
* </table>
|
* </table>
|
||||||
*
|
*
|
||||||
* @param src
|
* @param src - the array to search in.
|
||||||
* - the array to search in.
|
* @param target - the character to search for.
|
||||||
* @param target
|
* @param skip - the amount of <code>target</code> characters to be
|
||||||
* - the character to search for.
|
* skipped.
|
||||||
* @param skip
|
|
||||||
* - the amount of <code>target</code> characters to be skipped.
|
|
||||||
* @return The index of the <code>skip+1</code>th <code>target</code>
|
* @return The index of the <code>skip+1</code>th <code>target</code>
|
||||||
* character or -1, if none found.
|
* character or -1, if none found.
|
||||||
* @see StringUtil#indexFromEnd(char[], char, int)
|
* @see StringUtil#indexFromEnd(char[], char, int)
|
||||||
@ -607,7 +653,8 @@ public class StringUtil {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds and returns the index of the specified appearance of the specified
|
* Finds and returns the index of the specified appearance of the specified
|
||||||
* character in the given array. The search starts at index
|
* character
|
||||||
|
* in the given array. The search starts at index
|
||||||
* <code>src.length - 1</code>.
|
* <code>src.length - 1</code>.
|
||||||
* <p>
|
* <p>
|
||||||
* Examples:
|
* Examples:
|
||||||
@ -645,15 +692,13 @@ public class StringUtil {
|
|||||||
* </tr>
|
* </tr>
|
||||||
* </table>
|
* </table>
|
||||||
*
|
*
|
||||||
* @param src
|
* @param src - the array to search in.
|
||||||
* - the array to search in.
|
* @param target - the character to search for.
|
||||||
* @param target
|
* @param skip - the amount of <code>target</code> characters to be
|
||||||
* - the character to search for.
|
* skipped.
|
||||||
* @param skip
|
|
||||||
* - the amount of <code>target</code> characters to be skipped.
|
|
||||||
* @return The index of the <code>skip+1</code>th
|
* @return The index of the <code>skip+1</code>th
|
||||||
* <code>target</code>character from the end of the array or -1, if
|
* <code>target</code>character
|
||||||
* none found.
|
* from the end of the array or -1, if none found.
|
||||||
* @see StringUtil#indexFromBeginning(char[], char, int)
|
* @see StringUtil#indexFromBeginning(char[], char, int)
|
||||||
*/
|
*/
|
||||||
public static int indexFromEnd(char[] src, char target, int skip) {
|
public static int indexFromEnd(char[] src, char target, int skip) {
|
||||||
@ -828,8 +873,12 @@ public class StringUtil {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void buildCombinations(StringBuilder sb, Collection<String> result, Iterable<String>[] parts,
|
private static void buildCombinations(
|
||||||
int index) {
|
StringBuilder sb,
|
||||||
|
Collection<String> result,
|
||||||
|
Iterable<String>[] parts,
|
||||||
|
int index
|
||||||
|
) {
|
||||||
if (index >= parts.length) {
|
if (index >= parts.length) {
|
||||||
result.add(sb.toString());
|
result.add(sb.toString());
|
||||||
} else {
|
} else {
|
||||||
@ -855,8 +904,13 @@ public class StringUtil {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void buildCombinations(StringBuilder sb, String[] result, int[] resultIndex, String[][] parts,
|
private static void buildCombinations(
|
||||||
int index) {
|
StringBuilder sb,
|
||||||
|
String[] result,
|
||||||
|
int[] resultIndex,
|
||||||
|
String[][] parts,
|
||||||
|
int index
|
||||||
|
) {
|
||||||
if (index >= parts.length) {
|
if (index >= parts.length) {
|
||||||
result[resultIndex[0]++] = sb.toString();
|
result[resultIndex[0]++] = sb.toString();
|
||||||
} else {
|
} else {
|
||||||
@ -931,7 +985,10 @@ public class StringUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static char hexDigit(long value, int digit) {
|
private static char hexDigit(long value, int digit) {
|
||||||
return hexDigit((int) (value >>> (4 * digit)) & 0xF);
|
return hexDigit(
|
||||||
|
(int) (value >>> (4 * digit))
|
||||||
|
& 0xF
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static char hexDigit(int value) {
|
public static char hexDigit(int value) {
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars;
|
package ru.windcorp.jputil.chars;
|
||||||
|
|
||||||
public class UncheckedEscapeException extends RuntimeException {
|
public class UncheckedEscapeException extends RuntimeException {
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars;
|
package ru.windcorp.jputil.chars;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars.reader;
|
package ru.windcorp.jputil.chars.reader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,9 +27,10 @@ public abstract class AbstractCharReader implements CharReader {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Current position of this CharReader. The reader maps its input to
|
* Current position of this CharReader. The reader maps its input to
|
||||||
* positions starting from 0. Positions that are negative or lower than 0
|
* positions starting from 0.
|
||||||
* are invalid. {@link #current()} will throw an exception if position is
|
* Positions that are negative or lower than 0 are invalid.
|
||||||
* invalid.
|
* {@link #current()}
|
||||||
|
* will throw an exception if position is invalid.
|
||||||
*/
|
*/
|
||||||
protected int position = 0;
|
protected int position = 0;
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars.reader;
|
package ru.windcorp.jputil.chars.reader;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars.reader;
|
package ru.windcorp.jputil.chars.reader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,12 +51,9 @@ public abstract class BufferedCharReader extends AbstractCharReader {
|
|||||||
/**
|
/**
|
||||||
* Acquires next characters and stores them in the array.
|
* Acquires next characters and stores them in the array.
|
||||||
*
|
*
|
||||||
* @param buffer
|
* @param buffer the output array
|
||||||
* the output array
|
* @param offset index of the first character
|
||||||
* @param offset
|
* @param length maximum amount of characters to be pulled
|
||||||
* index of the first character
|
|
||||||
* @param length
|
|
||||||
* maximum amount of characters to be pulled
|
|
||||||
* @return the amount of characters actually pulled
|
* @return the amount of characters actually pulled
|
||||||
*/
|
*/
|
||||||
protected int pullChars(char[] buffer, int offset, int length) {
|
protected int pullChars(char[] buffer, int offset, int length) {
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars.reader;
|
package ru.windcorp.jputil.chars.reader;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -30,7 +30,7 @@ import ru.windcorp.jputil.chars.Escaper;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// SonarLint: Constants should not be defined in interfaces (java:S1214)
|
// SonarLint: Constants should not be defined in interfaces (java:S1214)
|
||||||
// DONE is an essential part of the interface
|
// DONE is an essential part of the interface
|
||||||
@SuppressWarnings("squid:S1214")
|
@SuppressWarnings("squid:S1214")
|
||||||
|
|
||||||
public interface CharReader {
|
public interface CharReader {
|
||||||
@ -179,7 +179,8 @@ public interface CharReader {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Skips to the end of the current line. Both <code>"\n"</code>,
|
* Skips to the end of the current line. Both <code>"\n"</code>,
|
||||||
* <code>"\r"</code> and <code>"\r\n"</code> are considered line separators.
|
* <code>"\r"</code>
|
||||||
|
* and <code>"\r\n"</code> are considered line separators.
|
||||||
*
|
*
|
||||||
* @return the amount of characters in the skipped line
|
* @return the amount of characters in the skipped line
|
||||||
*/
|
*/
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars.reader;
|
package ru.windcorp.jputil.chars.reader;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars.reader;
|
package ru.windcorp.jputil.chars.reader;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.chars.reader;
|
package ru.windcorp.jputil.chars.reader;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -38,7 +38,8 @@ public class StringCharReader extends AbstractCharReader {
|
|||||||
int end = offset + length;
|
int end = offset + length;
|
||||||
if (end > str.length() || offset < 0)
|
if (end > str.length() || offset < 0)
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"String contains [0; " + str.length() + "), requested [" + offset + "; " + end + ")");
|
"String contains [0; " + str.length() + "), requested [" + offset + "; " + end + ")"
|
||||||
|
);
|
||||||
|
|
||||||
this.offset = offset;
|
this.offset = offset;
|
||||||
this.length = length;
|
this.length = length;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.functions;
|
package ru.windcorp.jputil.functions;
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.functions;
|
package ru.windcorp.jputil.functions;
|
||||||
|
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
@ -44,16 +44,9 @@ public interface ThrowingBiConsumer<T, U, E extends Exception> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static <T, U, E extends Exception> ThrowingBiConsumer<T, U, E> concat(
|
public static <T, U, E extends Exception> ThrowingBiConsumer<T, U, E> concat(
|
||||||
ThrowingBiConsumer<? super T, ? super U, ? extends E> first,
|
ThrowingBiConsumer<? super T, ? super U, ? extends E> first,
|
||||||
ThrowingBiConsumer<? super T, ? super U, ? extends E> second) {
|
ThrowingBiConsumer<? super T, ? super U, ? extends E> second
|
||||||
return (t, u) -> {
|
) {
|
||||||
first.accept(t, u);
|
|
||||||
second.accept(t, u);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T, U, E extends Exception> ThrowingBiConsumer<T, U, E> concat(BiConsumer<? super T, ? super U> first,
|
|
||||||
ThrowingBiConsumer<? super T, ? super U, E> second) {
|
|
||||||
return (t, u) -> {
|
return (t, u) -> {
|
||||||
first.accept(t, u);
|
first.accept(t, u);
|
||||||
second.accept(t, u);
|
second.accept(t, u);
|
||||||
@ -61,7 +54,19 @@ public interface ThrowingBiConsumer<T, U, E extends Exception> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static <T, U, E extends Exception> ThrowingBiConsumer<T, U, E> concat(
|
public static <T, U, E extends Exception> ThrowingBiConsumer<T, U, E> concat(
|
||||||
ThrowingBiConsumer<? super T, ? super U, E> first, BiConsumer<? super T, ? super U> second) {
|
BiConsumer<? super T, ? super U> first,
|
||||||
|
ThrowingBiConsumer<? super T, ? super U, E> second
|
||||||
|
) {
|
||||||
|
return (t, u) -> {
|
||||||
|
first.accept(t, u);
|
||||||
|
second.accept(t, u);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T, U, E extends Exception> ThrowingBiConsumer<T, U, E> concat(
|
||||||
|
ThrowingBiConsumer<? super T, ? super U, E> first,
|
||||||
|
BiConsumer<? super T, ? super U> second
|
||||||
|
) {
|
||||||
return (t, u) -> {
|
return (t, u) -> {
|
||||||
first.accept(t, u);
|
first.accept(t, u);
|
||||||
second.accept(t, u);
|
second.accept(t, u);
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.functions;
|
package ru.windcorp.jputil.functions;
|
||||||
|
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
@ -39,24 +39,30 @@ public interface ThrowingConsumer<T, E extends Exception> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T, E extends Exception> ThrowingConsumer<T, E> concat(ThrowingConsumer<? super T, ? extends E> first,
|
public static <T, E extends Exception> ThrowingConsumer<T, E> concat(
|
||||||
ThrowingConsumer<? super T, ? extends E> second) {
|
ThrowingConsumer<? super T, ? extends E> first,
|
||||||
|
ThrowingConsumer<? super T, ? extends E> second
|
||||||
|
) {
|
||||||
return t -> {
|
return t -> {
|
||||||
first.accept(t);
|
first.accept(t);
|
||||||
second.accept(t);
|
second.accept(t);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T, E extends Exception> ThrowingConsumer<T, E> concat(Consumer<? super T> first,
|
public static <T, E extends Exception> ThrowingConsumer<T, E> concat(
|
||||||
ThrowingConsumer<? super T, ? extends E> second) {
|
Consumer<? super T> first,
|
||||||
|
ThrowingConsumer<? super T, ? extends E> second
|
||||||
|
) {
|
||||||
return t -> {
|
return t -> {
|
||||||
first.accept(t);
|
first.accept(t);
|
||||||
second.accept(t);
|
second.accept(t);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T, E extends Exception> ThrowingConsumer<T, E> concat(ThrowingConsumer<? super T, ? extends E> first,
|
public static <T, E extends Exception> ThrowingConsumer<T, E> concat(
|
||||||
Consumer<? super T> second) {
|
ThrowingConsumer<? super T, ? extends E> first,
|
||||||
|
Consumer<? super T> second
|
||||||
|
) {
|
||||||
return t -> {
|
return t -> {
|
||||||
first.accept(t);
|
first.accept(t);
|
||||||
second.accept(t);
|
second.accept(t);
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.functions;
|
package ru.windcorp.jputil.functions;
|
||||||
|
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
@ -28,8 +28,10 @@ public interface ThrowingFunction<T, R, E extends Exception> {
|
|||||||
R apply(T t) throws E;
|
R apply(T t) throws E;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
default Function<T, R> withHandler(BiConsumer<? super T, ? super E> handler,
|
default Function<T, R> withHandler(
|
||||||
Function<? super T, ? extends R> value) {
|
BiConsumer<? super T, ? super E> handler,
|
||||||
|
Function<? super T, ? extends R> value
|
||||||
|
) {
|
||||||
return t -> {
|
return t -> {
|
||||||
try {
|
try {
|
||||||
return apply(t);
|
return apply(t);
|
||||||
@ -56,18 +58,23 @@ public interface ThrowingFunction<T, R, E extends Exception> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static <T, R, I, E extends Exception> ThrowingFunction<T, R, E> compose(
|
public static <T, R, I, E extends Exception> ThrowingFunction<T, R, E> compose(
|
||||||
ThrowingFunction<? super T, I, ? extends E> first,
|
ThrowingFunction<? super T, I, ? extends E> first,
|
||||||
ThrowingFunction<? super I, ? extends R, ? extends E> second) {
|
ThrowingFunction<? super I, ? extends R, ? extends E> second
|
||||||
return t -> second.apply(first.apply(t));
|
) {
|
||||||
}
|
|
||||||
|
|
||||||
public static <T, R, I, E extends Exception> ThrowingFunction<T, R, E> compose(Function<? super T, I> first,
|
|
||||||
ThrowingFunction<? super I, ? extends R, E> second) {
|
|
||||||
return t -> second.apply(first.apply(t));
|
return t -> second.apply(first.apply(t));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T, R, I, E extends Exception> ThrowingFunction<T, R, E> compose(
|
public static <T, R, I, E extends Exception> ThrowingFunction<T, R, E> compose(
|
||||||
ThrowingFunction<? super T, I, E> first, Function<? super I, ? extends R> second) {
|
Function<? super T, I> first,
|
||||||
|
ThrowingFunction<? super I, ? extends R, E> second
|
||||||
|
) {
|
||||||
|
return t -> second.apply(first.apply(t));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T, R, I, E extends Exception> ThrowingFunction<T, R, E> compose(
|
||||||
|
ThrowingFunction<? super T, I, E> first,
|
||||||
|
Function<? super I, ? extends R> second
|
||||||
|
) {
|
||||||
return t -> second.apply(first.apply(t));
|
return t -> second.apply(first.apply(t));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.functions;
|
package ru.windcorp.jputil.functions;
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
@ -38,8 +38,10 @@ public interface ThrowingRunnable<E extends Exception> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <E extends Exception> ThrowingRunnable<E> concat(ThrowingRunnable<? extends E> first,
|
public static <E extends Exception> ThrowingRunnable<E> concat(
|
||||||
ThrowingRunnable<? extends E> second) {
|
ThrowingRunnable<? extends E> first,
|
||||||
|
ThrowingRunnable<? extends E> second
|
||||||
|
) {
|
||||||
return () -> {
|
return () -> {
|
||||||
first.run();
|
first.run();
|
||||||
second.run();
|
second.run();
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.functions;
|
package ru.windcorp.jputil.functions;
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.iterators;
|
package ru.windcorp.jputil.iterators;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.iterators;
|
package ru.windcorp.jputil.iterators;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.iterators;
|
package ru.windcorp.jputil.iterators;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.iterators;
|
package ru.windcorp.jputil.iterators;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -49,8 +49,10 @@ public class RangeIterator<E> implements Iterator<E> {
|
|||||||
public E next() {
|
public E next() {
|
||||||
update();
|
update();
|
||||||
if (nextIndex >= from + amount) {
|
if (nextIndex >= from + amount) {
|
||||||
throw new NoSuchElementException("RangeIterator about to retrieve element " + nextIndex
|
throw new NoSuchElementException(
|
||||||
+ " which exceeds upper boundary " + (from + amount));
|
"RangeIterator about to retrieve element " + nextIndex
|
||||||
|
+ " which exceeds upper boundary " + (from + amount)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
E result = parent.next();
|
E result = parent.next();
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.iterators;
|
package ru.windcorp.jputil.iterators;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.selectors;
|
package ru.windcorp.jputil.selectors;
|
||||||
|
|
||||||
public abstract class AbstractSelectorOperator implements SelectorOperator {
|
public abstract class AbstractSelectorOperator implements SelectorOperator {
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.selectors;
|
package ru.windcorp.jputil.selectors;
|
||||||
|
|
||||||
import ru.windcorp.jputil.SyntaxException;
|
import ru.windcorp.jputil.SyntaxException;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.selectors;
|
package ru.windcorp.jputil.selectors;
|
||||||
|
|
||||||
import ru.windcorp.jputil.SyntaxException;
|
import ru.windcorp.jputil.SyntaxException;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.selectors;
|
package ru.windcorp.jputil.selectors;
|
||||||
|
|
||||||
import java.util.Deque;
|
import java.util.Deque;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.selectors;
|
package ru.windcorp.jputil.selectors;
|
||||||
|
|
||||||
import java.util.Deque;
|
import java.util.Deque;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.selectors;
|
package ru.windcorp.jputil.selectors;
|
||||||
|
|
||||||
import java.util.Deque;
|
import java.util.Deque;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.selectors;
|
package ru.windcorp.jputil.selectors;
|
||||||
|
|
||||||
import java.util.Deque;
|
import java.util.Deque;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.selectors;
|
package ru.windcorp.jputil.selectors;
|
||||||
|
|
||||||
import java.util.Deque;
|
import java.util.Deque;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.selectors;
|
package ru.windcorp.jputil.selectors;
|
||||||
|
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.selectors;
|
package ru.windcorp.jputil.selectors;
|
||||||
|
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.selectors;
|
package ru.windcorp.jputil.selectors;
|
||||||
|
|
||||||
import java.util.Deque;
|
import java.util.Deque;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.jputil.selectors;
|
package ru.windcorp.jputil.selectors;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -37,7 +37,7 @@ public class SelectorSystem<T> {
|
|||||||
private final Collection<Selector<T>> selectors = Collections.synchronizedCollection(new ArrayList<Selector<T>>());
|
private final Collection<Selector<T>> selectors = Collections.synchronizedCollection(new ArrayList<Selector<T>>());
|
||||||
|
|
||||||
private final Collection<SelectorOperator> operators = Collections
|
private final Collection<SelectorOperator> operators = Collections
|
||||||
.synchronizedCollection(new ArrayList<SelectorOperator>());
|
.synchronizedCollection(new ArrayList<SelectorOperator>());
|
||||||
|
|
||||||
private String stackPrefix = null;
|
private String stackPrefix = null;
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia;
|
package ru.windcorp.progressia;
|
||||||
|
|
||||||
public class Progressia {
|
public class Progressia {
|
||||||
|
@ -18,18 +18,28 @@
|
|||||||
|
|
||||||
package ru.windcorp.progressia;
|
package ru.windcorp.progressia;
|
||||||
|
|
||||||
|
import ru.windcorp.progressia.client.graphics.GUI;
|
||||||
import ru.windcorp.progressia.common.util.crash.CrashReports;
|
import ru.windcorp.progressia.common.util.crash.CrashReports;
|
||||||
import ru.windcorp.progressia.common.util.crash.analyzers.OutOfMemoryAnalyzer;
|
import ru.windcorp.progressia.common.util.crash.analyzers.OutOfMemoryAnalyzer;
|
||||||
import ru.windcorp.progressia.common.util.crash.providers.*;
|
import ru.windcorp.progressia.common.util.crash.providers.*;
|
||||||
|
import ru.windcorp.progressia.test.LayerTitle;
|
||||||
|
|
||||||
public class ProgressiaLauncher {
|
public class ProgressiaLauncher {
|
||||||
|
|
||||||
public static String[] arguments;
|
public static String[] arguments;
|
||||||
|
private static Proxy proxy;
|
||||||
|
|
||||||
public static void launch(String[] args, Proxy proxy) {
|
public static void launch(String[] args, Proxy proxy) {
|
||||||
arguments = args.clone();
|
arguments = args.clone();
|
||||||
setupCrashReports();
|
setupCrashReports();
|
||||||
|
|
||||||
proxy.initialize();
|
proxy.initialize();
|
||||||
|
ProgressiaLauncher.proxy = proxy;
|
||||||
|
GUI.addTopLayer(new LayerTitle("Title"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Proxy getProxy() {
|
||||||
|
return proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setupCrashReports() {
|
private static void setupCrashReports() {
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia;
|
package ru.windcorp.progressia;
|
||||||
|
|
||||||
public interface Proxy {
|
public interface Proxy {
|
||||||
|
@ -15,24 +15,45 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client;
|
package ru.windcorp.progressia.client;
|
||||||
|
|
||||||
|
import com.google.common.eventbus.EventBus;
|
||||||
|
import com.google.common.eventbus.Subscribe;
|
||||||
|
|
||||||
import ru.windcorp.progressia.client.comms.DefaultClientCommsListener;
|
import ru.windcorp.progressia.client.comms.DefaultClientCommsListener;
|
||||||
import ru.windcorp.progressia.client.comms.ServerCommsChannel;
|
import ru.windcorp.progressia.client.comms.ServerCommsChannel;
|
||||||
|
import ru.windcorp.progressia.client.events.ClientEvent;
|
||||||
|
import ru.windcorp.progressia.client.events.NewLocalEntityEvent;
|
||||||
|
import ru.windcorp.progressia.client.graphics.GUI;
|
||||||
import ru.windcorp.progressia.client.graphics.world.Camera;
|
import ru.windcorp.progressia.client.graphics.world.Camera;
|
||||||
import ru.windcorp.progressia.client.graphics.world.EntityAnchor;
|
import ru.windcorp.progressia.client.graphics.world.EntityAnchor;
|
||||||
|
import ru.windcorp.progressia.client.graphics.world.LayerWorld;
|
||||||
import ru.windcorp.progressia.client.graphics.world.LocalPlayer;
|
import ru.windcorp.progressia.client.graphics.world.LocalPlayer;
|
||||||
|
import ru.windcorp.progressia.client.graphics.world.hud.HUDManager;
|
||||||
import ru.windcorp.progressia.client.world.WorldRender;
|
import ru.windcorp.progressia.client.world.WorldRender;
|
||||||
|
import ru.windcorp.progressia.common.util.crash.ReportingEventBus;
|
||||||
import ru.windcorp.progressia.common.world.DefaultWorldData;
|
import ru.windcorp.progressia.common.world.DefaultWorldData;
|
||||||
import ru.windcorp.progressia.common.world.entity.EntityData;
|
import ru.windcorp.progressia.test.LayerAbout;
|
||||||
|
import ru.windcorp.progressia.test.LayerDebug;
|
||||||
|
import ru.windcorp.progressia.test.LayerTestUI;
|
||||||
|
|
||||||
public class Client {
|
public class Client {
|
||||||
|
|
||||||
private final WorldRender world;
|
private final WorldRender world;
|
||||||
|
|
||||||
|
private final LayerWorld layerWorld = new LayerWorld(this);
|
||||||
|
private final LayerTestUI layerTestUI = new LayerTestUI();
|
||||||
|
private final LayerAbout layerAbout = new LayerAbout();
|
||||||
|
private final LayerDebug layerDebug = new LayerDebug();
|
||||||
|
|
||||||
private final LocalPlayer localPlayer = new LocalPlayer(this);
|
private final LocalPlayer localPlayer = new LocalPlayer(this);
|
||||||
|
|
||||||
private final Camera camera = new Camera((float) Math.toRadians(70));
|
private final Camera camera = new Camera((float) Math.toRadians(70));
|
||||||
|
|
||||||
|
private final EventBus eventBus = ReportingEventBus.create("ClientEvents");
|
||||||
|
|
||||||
|
private final HUDManager hudManager = new HUDManager(this);
|
||||||
|
|
||||||
private final ServerCommsChannel comms;
|
private final ServerCommsChannel comms;
|
||||||
|
|
||||||
@ -41,6 +62,22 @@ public class Client {
|
|||||||
this.comms = comms;
|
this.comms = comms;
|
||||||
|
|
||||||
comms.addListener(new DefaultClientCommsListener(this));
|
comms.addListener(new DefaultClientCommsListener(this));
|
||||||
|
subscribe(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void install() {
|
||||||
|
GUI.addBottomLayer(layerWorld);
|
||||||
|
GUI.addTopLayer(layerTestUI);
|
||||||
|
hudManager.install();
|
||||||
|
GUI.addTopLayer(layerAbout);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove() {
|
||||||
|
GUI.removeLayer(layerWorld);
|
||||||
|
GUI.removeLayer(layerTestUI);
|
||||||
|
hudManager.remove();
|
||||||
|
GUI.removeLayer(layerAbout);
|
||||||
|
GUI.removeLayer(layerDebug);
|
||||||
}
|
}
|
||||||
|
|
||||||
public WorldRender getWorld() {
|
public WorldRender getWorld() {
|
||||||
@ -62,14 +99,45 @@ public class Client {
|
|||||||
public ServerCommsChannel getComms() {
|
public ServerCommsChannel getComms() {
|
||||||
return comms;
|
return comms;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HUDManager getHUD() {
|
||||||
|
return hudManager;
|
||||||
|
}
|
||||||
|
|
||||||
public void onLocalPlayerEntityChanged(EntityData entity, EntityData lastKnownEntity) {
|
public void toggleDebugLayer() {
|
||||||
if (entity == null) {
|
if (GUI.getLayers().contains(layerDebug)) {
|
||||||
|
GUI.removeLayer(layerDebug);
|
||||||
|
} else {
|
||||||
|
GUI.addTopLayer(layerDebug);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
private void onLocalPlayerEntityChanged(NewLocalEntityEvent e) {
|
||||||
|
if (e.getNewEntity() == null) {
|
||||||
getCamera().setAnchor(null);
|
getCamera().setAnchor(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
getCamera().setAnchor(new EntityAnchor(getWorld().getEntityRenderable(entity)));
|
getCamera().setAnchor(
|
||||||
|
new EntityAnchor(
|
||||||
|
getWorld().getEntityRenderable(e.getNewEntity())
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void subscribe(Object object) {
|
||||||
|
eventBus.register(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unsubscribe(Object object) {
|
||||||
|
eventBus.unregister(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void postEvent(ClientEvent event) {
|
||||||
|
event.setClient(this);
|
||||||
|
eventBus.post(event);
|
||||||
|
event.setClient(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,10 +27,10 @@ import ru.windcorp.progressia.client.graphics.font.GNUUnifontLoader;
|
|||||||
import ru.windcorp.progressia.client.graphics.font.Typefaces;
|
import ru.windcorp.progressia.client.graphics.font.Typefaces;
|
||||||
import ru.windcorp.progressia.client.graphics.texture.Atlases;
|
import ru.windcorp.progressia.client.graphics.texture.Atlases;
|
||||||
import ru.windcorp.progressia.client.graphics.world.WorldRenderProgram;
|
import ru.windcorp.progressia.client.graphics.world.WorldRenderProgram;
|
||||||
|
import ru.windcorp.progressia.client.graphics.world.hud.HUDTextures;
|
||||||
import ru.windcorp.progressia.client.localization.Localizer;
|
import ru.windcorp.progressia.client.localization.Localizer;
|
||||||
import ru.windcorp.progressia.common.resource.ResourceManager;
|
import ru.windcorp.progressia.common.resource.ResourceManager;
|
||||||
import ru.windcorp.progressia.common.util.crash.CrashReports;
|
import ru.windcorp.progressia.common.util.crash.CrashReports;
|
||||||
import ru.windcorp.progressia.server.ServerState;
|
|
||||||
import ru.windcorp.progressia.test.TestContent;
|
import ru.windcorp.progressia.test.TestContent;
|
||||||
import ru.windcorp.progressia.test.TestMusicPlayer;
|
import ru.windcorp.progressia.test.TestMusicPlayer;
|
||||||
|
|
||||||
@ -38,12 +38,17 @@ public class ClientProxy implements Proxy {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
|
|
||||||
GraphicsBackend.initialize();
|
GraphicsBackend.initialize();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
RenderTaskQueue.waitAndInvoke(FlatRenderProgram::init);
|
RenderTaskQueue.waitAndInvoke(FlatRenderProgram::init);
|
||||||
RenderTaskQueue.waitAndInvoke(WorldRenderProgram::init);
|
RenderTaskQueue.waitAndInvoke(WorldRenderProgram::init);
|
||||||
RenderTaskQueue.waitAndInvoke(() -> Typefaces
|
RenderTaskQueue.waitAndInvoke(
|
||||||
.setDefault(GNUUnifontLoader.load(ResourceManager.getResource("assets/unifont-13.0.03.hex.gz"))));
|
() -> Typefaces
|
||||||
|
.setDefault(GNUUnifontLoader.load(ResourceManager.getResource("assets/unifont-13.0.03.hex.gz")))
|
||||||
|
);
|
||||||
|
RenderTaskQueue.waitAndInvoke(HUDTextures::loadItemAmountTypeface);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
throw CrashReports.report(e, "ClientProxy failed");
|
throw CrashReports.report(e, "ClientProxy failed");
|
||||||
}
|
}
|
||||||
@ -56,10 +61,6 @@ public class ClientProxy implements Proxy {
|
|||||||
|
|
||||||
AudioSystem.initialize();
|
AudioSystem.initialize();
|
||||||
|
|
||||||
ServerState.startServer();
|
|
||||||
ClientState.connectToLocalServer();
|
|
||||||
|
|
||||||
TestMusicPlayer.start();
|
TestMusicPlayer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,11 +20,10 @@ package ru.windcorp.progressia.client;
|
|||||||
|
|
||||||
import ru.windcorp.progressia.client.comms.localhost.LocalServerCommsChannel;
|
import ru.windcorp.progressia.client.comms.localhost.LocalServerCommsChannel;
|
||||||
import ru.windcorp.progressia.client.graphics.GUI;
|
import ru.windcorp.progressia.client.graphics.GUI;
|
||||||
import ru.windcorp.progressia.client.graphics.world.LayerWorld;
|
|
||||||
import ru.windcorp.progressia.common.world.DefaultWorldData;
|
import ru.windcorp.progressia.common.world.DefaultWorldData;
|
||||||
|
import ru.windcorp.progressia.client.localization.MutableStringLocalized;
|
||||||
import ru.windcorp.progressia.server.ServerState;
|
import ru.windcorp.progressia.server.ServerState;
|
||||||
import ru.windcorp.progressia.test.LayerAbout;
|
import ru.windcorp.progressia.test.LayerTestText;
|
||||||
import ru.windcorp.progressia.test.LayerTestUI;
|
|
||||||
import ru.windcorp.progressia.test.TestContent;
|
import ru.windcorp.progressia.test.TestContent;
|
||||||
|
|
||||||
public class ClientState {
|
public class ClientState {
|
||||||
@ -43,18 +42,38 @@ public class ClientState {
|
|||||||
|
|
||||||
DefaultWorldData world = new DefaultWorldData();
|
DefaultWorldData world = new DefaultWorldData();
|
||||||
|
|
||||||
LocalServerCommsChannel channel = new LocalServerCommsChannel(ServerState.getInstance());
|
LocalServerCommsChannel channel = new LocalServerCommsChannel(
|
||||||
|
ServerState.getInstance()
|
||||||
|
);
|
||||||
|
|
||||||
Client client = new Client(world, channel);
|
Client client = new Client(world, channel);
|
||||||
|
|
||||||
channel.connect(TestContent.PLAYER_LOGIN);
|
channel.connect(TestContent.PLAYER_LOGIN);
|
||||||
|
|
||||||
setInstance(client);
|
setInstance(client);
|
||||||
|
displayLoadingScreen();
|
||||||
|
|
||||||
GUI.addBottomLayer(new LayerWorld(client));
|
}
|
||||||
GUI.addTopLayer(new LayerTestUI());
|
|
||||||
GUI.addTopLayer(new LayerAbout());
|
|
||||||
|
|
||||||
|
private static void displayLoadingScreen() {
|
||||||
|
GUI.addTopLayer(new LayerTestText("Text", new MutableStringLocalized("LayerText.Load"), layer -> {
|
||||||
|
Client client = ClientState.getInstance();
|
||||||
|
|
||||||
|
// TODO refacetor and remove
|
||||||
|
if (client != null) {
|
||||||
|
client.getComms().processPackets();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (client != null && client.getLocalPlayer().hasEntity()) {
|
||||||
|
GUI.removeLayer(layer);
|
||||||
|
client.install();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void disconnectFromLocalServer() {
|
||||||
|
getInstance().getComms().disconnect();
|
||||||
|
getInstance().remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ClientState() {
|
private ClientState() {
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client;
|
package ru.windcorp.progressia.client;
|
||||||
|
|
||||||
import ru.windcorp.progressia.ProgressiaLauncher;
|
import ru.windcorp.progressia.ProgressiaLauncher;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.audio;
|
package ru.windcorp.progressia.client.audio;
|
||||||
|
|
||||||
public enum AudioFormat {
|
public enum AudioFormat {
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.audio;
|
package ru.windcorp.progressia.client.audio;
|
||||||
|
|
||||||
import org.lwjgl.openal.*;
|
import org.lwjgl.openal.*;
|
||||||
@ -43,7 +43,10 @@ public class AudioManager {
|
|||||||
private static Speaker musicSpeaker;
|
private static Speaker musicSpeaker;
|
||||||
|
|
||||||
public static void initAL() {
|
public static void initAL() {
|
||||||
String defaultDeviceName = alcGetString(0, ALC_DEFAULT_DEVICE_SPECIFIER);
|
String defaultDeviceName = alcGetString(
|
||||||
|
0,
|
||||||
|
ALC_DEFAULT_DEVICE_SPECIFIER
|
||||||
|
);
|
||||||
|
|
||||||
device = alcOpenDevice(defaultDeviceName);
|
device = alcOpenDevice(defaultDeviceName);
|
||||||
|
|
||||||
@ -72,7 +75,10 @@ public class AudioManager {
|
|||||||
lastSoundIndex = 0;
|
lastSoundIndex = 0;
|
||||||
}
|
}
|
||||||
speaker = soundSpeakers.get(lastSoundIndex);
|
speaker = soundSpeakers.get(lastSoundIndex);
|
||||||
} while (speaker.getState().equals(Speaker.State.PLAYING_LOOP));
|
} while (
|
||||||
|
speaker.getState()
|
||||||
|
.equals(Speaker.State.PLAYING_LOOP)
|
||||||
|
);
|
||||||
return speaker;
|
return speaker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,9 +21,9 @@ import ru.windcorp.progressia.client.audio.backend.SoundType;
|
|||||||
import ru.windcorp.progressia.common.util.namespaces.NamespacedInstanceRegistry;
|
import ru.windcorp.progressia.common.util.namespaces.NamespacedInstanceRegistry;
|
||||||
|
|
||||||
public class AudioRegistry extends NamespacedInstanceRegistry<SoundType> {
|
public class AudioRegistry extends NamespacedInstanceRegistry<SoundType> {
|
||||||
|
|
||||||
private static final AudioRegistry INSTANCE = new AudioRegistry();
|
private static final AudioRegistry INSTANCE = new AudioRegistry();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the instance
|
* @return the instance
|
||||||
*/
|
*/
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.audio;
|
package ru.windcorp.progressia.client.audio;
|
||||||
|
|
||||||
import ru.windcorp.progressia.common.resource.ResourceManager;
|
import ru.windcorp.progressia.common.resource.ResourceManager;
|
||||||
@ -29,7 +29,10 @@ public class AudioSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void loadAudioData() {
|
static void loadAudioData() {
|
||||||
AudioManager.loadSound(ResourceManager.getResource("assets/sounds/block_destroy_clap.ogg"),
|
AudioManager.loadSound(
|
||||||
"Progressia:BlockDestroy", AudioFormat.MONO);
|
ResourceManager.getResource("assets/sounds/block_destroy_clap.ogg"),
|
||||||
|
"Progressia:BlockDestroy",
|
||||||
|
AudioFormat.MONO
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,15 +15,18 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.audio;
|
package ru.windcorp.progressia.client.audio;
|
||||||
|
|
||||||
import glm.vec._3.Vec3;
|
import glm.vec._3.Vec3;
|
||||||
import ru.windcorp.progressia.client.audio.backend.SoundType;
|
import ru.windcorp.progressia.client.audio.backend.SoundType;
|
||||||
import ru.windcorp.progressia.client.audio.backend.Speaker;
|
import ru.windcorp.progressia.client.audio.backend.Speaker;
|
||||||
|
|
||||||
public class Music extends Sound {
|
public class Music
|
||||||
|
extends Sound {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public Music(SoundType soundType, int timeLength, float pitch, float gain) {
|
public Music(SoundType soundType, int timeLength, float pitch, float gain) {
|
||||||
super(soundType, timeLength, new Vec3(), new Vec3(), pitch, gain);
|
super(soundType, timeLength, new Vec3(), new Vec3(), pitch, gain);
|
||||||
}
|
}
|
||||||
@ -44,7 +47,7 @@ public class Music extends Sound {
|
|||||||
protected Speaker initSpeaker() {
|
protected Speaker initSpeaker() {
|
||||||
return AudioManager.initMusicSpeaker(soundType);
|
return AudioManager.initMusicSpeaker(soundType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPosition(Vec3 position) {
|
public void setPosition(Vec3 position) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.audio;
|
package ru.windcorp.progressia.client.audio;
|
||||||
|
|
||||||
import glm.vec._3.Vec3;
|
import glm.vec._3.Vec3;
|
||||||
@ -29,9 +29,9 @@ public class Sound {
|
|||||||
protected float pitch = 1.0f;
|
protected float pitch = 1.0f;
|
||||||
protected float gain = 1.0f;
|
protected float gain = 1.0f;
|
||||||
protected int timeLength = 0;
|
protected int timeLength = 0;
|
||||||
|
|
||||||
protected SoundType soundType;
|
protected SoundType soundType;
|
||||||
|
|
||||||
public Sound(SoundType soundType) {
|
public Sound(SoundType soundType) {
|
||||||
this.soundType = soundType;
|
this.soundType = soundType;
|
||||||
}
|
}
|
||||||
@ -39,23 +39,37 @@ public class Sound {
|
|||||||
public Sound(String id) {
|
public Sound(String id) {
|
||||||
this(AudioRegistry.getInstance().get(id));
|
this(AudioRegistry.getInstance().get(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Sound(String id, int timeLength, Vec3 position, Vec3 velocity, float pitch, float gain) {
|
public Sound(
|
||||||
|
String id,
|
||||||
|
int timeLength,
|
||||||
|
Vec3 position,
|
||||||
|
Vec3 velocity,
|
||||||
|
float pitch,
|
||||||
|
float gain
|
||||||
|
) {
|
||||||
this(id);
|
this(id);
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this.velocity = velocity;
|
this.velocity = velocity;
|
||||||
this.pitch = pitch;
|
this.pitch = pitch;
|
||||||
this.gain = gain;
|
this.gain = gain;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Sound(SoundType soundType, int timeLength, Vec3 position, Vec3 velocity, float pitch, float gain) {
|
public Sound(
|
||||||
|
SoundType soundType,
|
||||||
|
int timeLength,
|
||||||
|
Vec3 position,
|
||||||
|
Vec3 velocity,
|
||||||
|
float pitch,
|
||||||
|
float gain
|
||||||
|
) {
|
||||||
this(soundType);
|
this(soundType);
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this.velocity = velocity;
|
this.velocity = velocity;
|
||||||
this.pitch = pitch;
|
this.pitch = pitch;
|
||||||
this.gain = gain;
|
this.gain = gain;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Speaker initSpeaker() {
|
protected Speaker initSpeaker() {
|
||||||
return AudioManager.initSpeaker(soundType);
|
return AudioManager.initSpeaker(soundType);
|
||||||
}
|
}
|
||||||
@ -105,7 +119,7 @@ public class Sound {
|
|||||||
public float getPitch() {
|
public float getPitch() {
|
||||||
return pitch;
|
return pitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getDuration() {
|
public double getDuration() {
|
||||||
return soundType.getDuration();
|
return soundType.getDuration();
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.audio.backend;
|
package ru.windcorp.progressia.client.audio.backend;
|
||||||
|
|
||||||
import org.lwjgl.BufferUtils;
|
import org.lwjgl.BufferUtils;
|
||||||
@ -39,7 +39,12 @@ public class AudioReader {
|
|||||||
|
|
||||||
ShortBuffer rawAudio = decodeVorbis(resource, channelBuffer, rateBuffer);
|
ShortBuffer rawAudio = decodeVorbis(resource, channelBuffer, rateBuffer);
|
||||||
|
|
||||||
return new SoundType(id, rawAudio, format, rateBuffer.get(0));
|
return new SoundType(
|
||||||
|
id,
|
||||||
|
rawAudio,
|
||||||
|
format,
|
||||||
|
rateBuffer.get(0)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SoundType readAsMono(Resource resource, String id) {
|
public static SoundType readAsMono(Resource resource, String id) {
|
||||||
@ -50,7 +55,15 @@ public class AudioReader {
|
|||||||
return readAsSpecified(resource, id, AL_FORMAT_STEREO16);
|
return readAsSpecified(resource, id, AL_FORMAT_STEREO16);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ShortBuffer decodeVorbis(Resource dataToDecode, IntBuffer channelsBuffer, IntBuffer rateBuffer) {
|
private static ShortBuffer decodeVorbis(
|
||||||
return stb_vorbis_decode_memory(dataToDecode.readAsBytes(), channelsBuffer, rateBuffer);
|
Resource dataToDecode,
|
||||||
|
IntBuffer channelsBuffer,
|
||||||
|
IntBuffer rateBuffer
|
||||||
|
) {
|
||||||
|
return stb_vorbis_decode_memory(
|
||||||
|
dataToDecode.readAsBytes(),
|
||||||
|
channelsBuffer,
|
||||||
|
rateBuffer
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.audio.backend;
|
package ru.windcorp.progressia.client.audio.backend;
|
||||||
|
|
||||||
import glm.vec._3.Vec3;
|
import glm.vec._3.Vec3;
|
||||||
@ -55,8 +55,9 @@ public class Listener {
|
|||||||
if (isInWorld) {
|
if (isInWorld) {
|
||||||
|
|
||||||
if (wasInWorld) {
|
if (wasInWorld) {
|
||||||
velocity.set(camera.getLastAnchorPosition()).sub(position)
|
velocity.set(camera.getLastAnchorPosition()).sub(position).div(
|
||||||
.div((float) GraphicsInterface.getFrameLength());
|
(float) GraphicsInterface.getFrameLength()
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
// If !wasInWorld, previous position is nonsence. Assume 0.
|
// If !wasInWorld, previous position is nonsence. Assume 0.
|
||||||
velocity.set(0);
|
velocity.set(0);
|
||||||
@ -71,9 +72,9 @@ public class Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Only apply if there is a chance that params changed. This can only
|
* Only apply if there is a chance that params changed.
|
||||||
* happen if we are in world now (isInWorld) or we just left world
|
* This can only happen if we are in world now (isInWorld) or we just
|
||||||
* (wasInWorld, then we need to reset).
|
* left world (wasInWorld, then we need to reset).
|
||||||
*/
|
*/
|
||||||
if (isInWorld || wasInWorld) {
|
if (isInWorld || wasInWorld) {
|
||||||
applyParams();
|
applyParams();
|
||||||
@ -90,7 +91,17 @@ public class Listener {
|
|||||||
private void applyParams() {
|
private void applyParams() {
|
||||||
alListener3f(AL_POSITION, position.x, position.y, position.z);
|
alListener3f(AL_POSITION, position.x, position.y, position.z);
|
||||||
alListener3f(AL_VELOCITY, velocity.x, velocity.y, velocity.z);
|
alListener3f(AL_VELOCITY, velocity.x, velocity.y, velocity.z);
|
||||||
alListenerfv(AL_ORIENTATION, new float[] { oriAt.x, oriAt.y, oriAt.z, oriUp.x, oriUp.y, oriUp.z });
|
alListenerfv(
|
||||||
|
AL_ORIENTATION,
|
||||||
|
new float[] {
|
||||||
|
oriAt.x,
|
||||||
|
oriAt.y,
|
||||||
|
oriAt.z,
|
||||||
|
oriUp.x,
|
||||||
|
oriUp.y,
|
||||||
|
oriUp.z
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.audio.backend;
|
package ru.windcorp.progressia.client.audio.backend;
|
||||||
|
|
||||||
import ru.windcorp.progressia.common.util.namespaces.Namespaced;
|
import ru.windcorp.progressia.common.util.namespaces.Namespaced;
|
||||||
@ -34,7 +34,12 @@ public class SoundType extends Namespaced {
|
|||||||
private int audioBuffer;
|
private int audioBuffer;
|
||||||
private double duration;
|
private double duration;
|
||||||
|
|
||||||
public SoundType(String id, ShortBuffer rawAudio, int format, int sampleRate) {
|
public SoundType(
|
||||||
|
String id,
|
||||||
|
ShortBuffer rawAudio,
|
||||||
|
int format,
|
||||||
|
int sampleRate
|
||||||
|
) {
|
||||||
super(id);
|
super(id);
|
||||||
this.rawAudio = rawAudio;
|
this.rawAudio = rawAudio;
|
||||||
this.sampleRate = sampleRate;
|
this.sampleRate = sampleRate;
|
||||||
@ -51,7 +56,7 @@ public class SoundType extends Namespaced {
|
|||||||
public void initSpeaker(Speaker speaker) {
|
public void initSpeaker(Speaker speaker) {
|
||||||
speaker.setAudioData(audioBuffer);
|
speaker.setAudioData(audioBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getDuration() {
|
public double getDuration() {
|
||||||
return duration;
|
return duration;
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.audio.backend;
|
package ru.windcorp.progressia.client.audio.backend;
|
||||||
|
|
||||||
import glm.vec._3.Vec3;
|
import glm.vec._3.Vec3;
|
||||||
@ -24,7 +24,9 @@ import static org.lwjgl.openal.AL11.*;
|
|||||||
public class Speaker {
|
public class Speaker {
|
||||||
|
|
||||||
public enum State {
|
public enum State {
|
||||||
NOT_PLAYING, PLAYING, PLAYING_LOOP
|
NOT_PLAYING,
|
||||||
|
PLAYING,
|
||||||
|
PLAYING_LOOP
|
||||||
}
|
}
|
||||||
|
|
||||||
// Buffers
|
// Buffers
|
||||||
@ -47,7 +49,13 @@ public class Speaker {
|
|||||||
setAudioData(audioData);
|
setAudioData(audioData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Speaker(int audioData, Vec3 position, Vec3 velocity, float pitch, float gain) {
|
public Speaker(
|
||||||
|
int audioData,
|
||||||
|
Vec3 position,
|
||||||
|
Vec3 velocity,
|
||||||
|
float pitch,
|
||||||
|
float gain
|
||||||
|
) {
|
||||||
setAudioData(audioData);
|
setAudioData(audioData);
|
||||||
setPosition(position);
|
setPosition(position);
|
||||||
setVelocity(velocity);
|
setVelocity(velocity);
|
||||||
@ -55,7 +63,12 @@ public class Speaker {
|
|||||||
setGain(gain);
|
setGain(gain);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Speaker(Vec3 position, Vec3 velocity, float pitch, float gain) {
|
public Speaker(
|
||||||
|
Vec3 position,
|
||||||
|
Vec3 velocity,
|
||||||
|
float pitch,
|
||||||
|
float gain
|
||||||
|
) {
|
||||||
setPosition(position);
|
setPosition(position);
|
||||||
setVelocity(velocity);
|
setVelocity(velocity);
|
||||||
setPitch(pitch);
|
setPitch(pitch);
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.comms;
|
package ru.windcorp.progressia.client.comms;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -39,7 +39,9 @@ public class DefaultClientCommsListener implements CommsListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onPacketReceived(Packet packet) {
|
public void onPacketReceived(Packet packet) {
|
||||||
if (packet instanceof PacketAffectWorld) {
|
if (packet instanceof PacketAffectWorld) {
|
||||||
((PacketAffectWorld) packet).apply(getClient().getWorld().getData());
|
((PacketAffectWorld) packet).apply(
|
||||||
|
getClient().getWorld().getData()
|
||||||
|
);
|
||||||
} else if (packet instanceof PacketSetLocalPlayer) {
|
} else if (packet instanceof PacketSetLocalPlayer) {
|
||||||
setLocalPlayer((PacketSetLocalPlayer) packet);
|
setLocalPlayer((PacketSetLocalPlayer) packet);
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.comms;
|
package ru.windcorp.progressia.client.comms;
|
||||||
|
|
||||||
import ru.windcorp.progressia.common.comms.CommsChannel;
|
import ru.windcorp.progressia.common.comms.CommsChannel;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.comms.controls;
|
package ru.windcorp.progressia.client.comms.controls;
|
||||||
|
|
||||||
import ru.windcorp.progressia.common.util.namespaces.Namespaced;
|
import ru.windcorp.progressia.common.util.namespaces.Namespaced;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.comms.controls;
|
package ru.windcorp.progressia.client.comms.controls;
|
||||||
|
|
||||||
import ru.windcorp.progressia.client.graphics.input.InputEvent;
|
import ru.windcorp.progressia.client.graphics.input.InputEvent;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.comms.controls;
|
package ru.windcorp.progressia.client.comms.controls;
|
||||||
|
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
@ -33,12 +33,17 @@ public class ControlTriggerLambda extends ControlTriggerInputBased {
|
|||||||
private final Predicate<InputEvent> predicate;
|
private final Predicate<InputEvent> predicate;
|
||||||
private final BiConsumer<InputEvent, ControlData> dataWriter;
|
private final BiConsumer<InputEvent, ControlData> dataWriter;
|
||||||
|
|
||||||
public ControlTriggerLambda(String id, Predicate<InputEvent> predicate,
|
public ControlTriggerLambda(
|
||||||
BiConsumer<InputEvent, ControlData> dataWriter) {
|
String id,
|
||||||
|
Predicate<InputEvent> predicate,
|
||||||
|
BiConsumer<InputEvent, ControlData> dataWriter
|
||||||
|
) {
|
||||||
super(id);
|
super(id);
|
||||||
|
|
||||||
this.packetId = NamespacedUtil.getId(NamespacedUtil.getNamespace(id),
|
this.packetId = NamespacedUtil.getId(
|
||||||
"ControlKeyPress" + NamespacedUtil.getName(id));
|
NamespacedUtil.getNamespace(id),
|
||||||
|
"ControlKeyPress" + NamespacedUtil.getName(id)
|
||||||
|
);
|
||||||
|
|
||||||
this.predicate = predicate;
|
this.predicate = predicate;
|
||||||
this.dataWriter = dataWriter;
|
this.dataWriter = dataWriter;
|
||||||
@ -49,7 +54,10 @@ public class ControlTriggerLambda extends ControlTriggerInputBased {
|
|||||||
if (!predicate.test(event))
|
if (!predicate.test(event))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
PacketControl packet = new PacketControl(packetId, ControlDataRegistry.getInstance().create(getId()));
|
PacketControl packet = new PacketControl(
|
||||||
|
packetId,
|
||||||
|
ControlDataRegistry.getInstance().create(getId())
|
||||||
|
);
|
||||||
|
|
||||||
dataWriter.accept(event, packet.getControl());
|
dataWriter.accept(event, packet.getControl());
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.comms.controls;
|
package ru.windcorp.progressia.client.comms.controls;
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
@ -29,7 +29,11 @@ public class ControlTriggerLocalLambda extends ControlTriggerInputBased {
|
|||||||
private final Predicate<InputEvent> predicate;
|
private final Predicate<InputEvent> predicate;
|
||||||
private final Consumer<InputEvent> action;
|
private final Consumer<InputEvent> action;
|
||||||
|
|
||||||
public ControlTriggerLocalLambda(String id, Predicate<InputEvent> predicate, Consumer<InputEvent> action) {
|
public ControlTriggerLocalLambda(
|
||||||
|
String id,
|
||||||
|
Predicate<InputEvent> predicate,
|
||||||
|
Consumer<InputEvent> action
|
||||||
|
) {
|
||||||
super(id);
|
super(id);
|
||||||
|
|
||||||
this.predicate = predicate;
|
this.predicate = predicate;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.comms.controls;
|
package ru.windcorp.progressia.client.comms.controls;
|
||||||
|
|
||||||
import ru.windcorp.progressia.common.util.namespaces.NamespacedInstanceRegistry;
|
import ru.windcorp.progressia.common.util.namespaces.NamespacedInstanceRegistry;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.comms.controls;
|
package ru.windcorp.progressia.client.comms.controls;
|
||||||
|
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
@ -27,119 +27,216 @@ import ru.windcorp.progressia.common.comms.controls.ControlData;
|
|||||||
|
|
||||||
public class ControlTriggers {
|
public class ControlTriggers {
|
||||||
|
|
||||||
public static ControlTriggerInputBased of(String id, BiConsumer<InputEvent, ControlData> dataWriter,
|
public static ControlTriggerInputBased of(
|
||||||
Predicate<InputEvent> predicate) {
|
String id,
|
||||||
|
BiConsumer<InputEvent, ControlData> dataWriter,
|
||||||
|
Predicate<InputEvent> predicate
|
||||||
|
) {
|
||||||
return new ControlTriggerLambda(id, predicate, dataWriter);
|
return new ControlTriggerLambda(id, predicate, dataWriter);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ControlTriggerInputBased of(String id, Consumer<ControlData> dataWriter,
|
public static ControlTriggerInputBased of(
|
||||||
Predicate<InputEvent> predicate) {
|
String id,
|
||||||
return of(id, (input, control) -> dataWriter.accept(control), predicate);
|
Consumer<ControlData> dataWriter,
|
||||||
|
Predicate<InputEvent> predicate
|
||||||
|
) {
|
||||||
|
return of(
|
||||||
|
id,
|
||||||
|
(input, control) -> dataWriter.accept(control),
|
||||||
|
predicate
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ControlTriggerInputBased of(String id, Predicate<InputEvent> predicate) {
|
public static ControlTriggerInputBased of(
|
||||||
return of(id, (input, control) -> {
|
String id,
|
||||||
}, predicate);
|
Predicate<InputEvent> predicate
|
||||||
|
) {
|
||||||
|
return of(
|
||||||
|
id,
|
||||||
|
(input, control) -> {
|
||||||
|
},
|
||||||
|
predicate
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public static <I extends InputEvent> ControlTriggerInputBased of(String id, Class<I> inputType,
|
public static <I extends InputEvent> ControlTriggerInputBased of(
|
||||||
BiConsumer<I, ControlData> dataWriter, Predicate<I>... predicates) {
|
String id,
|
||||||
return of(id, createCheckedDataWriter(inputType, dataWriter),
|
Class<I> inputType,
|
||||||
createCheckedCompoundPredicate(inputType, predicates));
|
BiConsumer<I, ControlData> dataWriter,
|
||||||
|
Predicate<I>... predicates
|
||||||
|
) {
|
||||||
|
return of(
|
||||||
|
id,
|
||||||
|
createCheckedDataWriter(inputType, dataWriter),
|
||||||
|
createCheckedCompoundPredicate(inputType, predicates)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public static <I extends InputEvent> ControlTriggerInputBased of(String id, Class<I> inputType,
|
public static <I extends InputEvent> ControlTriggerInputBased of(
|
||||||
Consumer<ControlData> dataWriter, Predicate<I>... predicates) {
|
String id,
|
||||||
return of(id, inputType, (input, control) -> dataWriter.accept(control), predicates);
|
Class<I> inputType,
|
||||||
|
Consumer<ControlData> dataWriter,
|
||||||
|
Predicate<I>... predicates
|
||||||
|
) {
|
||||||
|
return of(
|
||||||
|
id,
|
||||||
|
inputType,
|
||||||
|
(input, control) -> dataWriter.accept(control),
|
||||||
|
predicates
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public static <I extends InputEvent> ControlTriggerInputBased of(String id, Class<I> inputType,
|
public static <I extends InputEvent> ControlTriggerInputBased of(
|
||||||
Predicate<I>... predicates) {
|
String id,
|
||||||
return of(id, (input, control) -> {
|
Class<I> inputType,
|
||||||
}, createCheckedCompoundPredicate(inputType, predicates));
|
Predicate<I>... predicates
|
||||||
|
) {
|
||||||
|
return of(
|
||||||
|
id,
|
||||||
|
(input, control) -> {
|
||||||
|
},
|
||||||
|
createCheckedCompoundPredicate(inputType, predicates)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public static ControlTriggerInputBased of(String id, BiConsumer<InputEvent, ControlData> dataWriter,
|
public static ControlTriggerInputBased of(
|
||||||
Predicate<InputEvent>... predicates) {
|
String id,
|
||||||
return of(id, InputEvent.class, dataWriter, predicates);
|
BiConsumer<InputEvent, ControlData> dataWriter,
|
||||||
|
Predicate<InputEvent>... predicates
|
||||||
|
) {
|
||||||
|
return of(
|
||||||
|
id,
|
||||||
|
InputEvent.class,
|
||||||
|
dataWriter,
|
||||||
|
predicates
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public static <I extends InputEvent> ControlTriggerInputBased of(String id, Consumer<ControlData> dataWriter,
|
public static <I extends InputEvent> ControlTriggerInputBased of(
|
||||||
Predicate<InputEvent>... predicates) {
|
String id,
|
||||||
return of(id, (input, control) -> dataWriter.accept(control), predicates);
|
Consumer<ControlData> dataWriter,
|
||||||
|
Predicate<InputEvent>... predicates
|
||||||
|
) {
|
||||||
|
return of(
|
||||||
|
id,
|
||||||
|
(input, control) -> dataWriter.accept(control),
|
||||||
|
predicates
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public static ControlTriggerInputBased of(String id, Predicate<InputEvent>... predicates) {
|
public static ControlTriggerInputBased of(
|
||||||
return of(id, InputEvent.class, (input, control) -> {
|
String id,
|
||||||
}, predicates);
|
Predicate<InputEvent>... predicates
|
||||||
|
) {
|
||||||
|
return of(
|
||||||
|
id,
|
||||||
|
InputEvent.class,
|
||||||
|
(input, control) -> {
|
||||||
|
},
|
||||||
|
predicates
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
public static ControlTriggerInputBased localOf(
|
||||||
//
|
String id,
|
||||||
///
|
Consumer<InputEvent> action,
|
||||||
///
|
Predicate<InputEvent> predicate
|
||||||
//
|
) {
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
|
|
||||||
public static ControlTriggerInputBased localOf(String id, Consumer<InputEvent> action,
|
|
||||||
Predicate<InputEvent> predicate) {
|
|
||||||
return new ControlTriggerLocalLambda(id, predicate, action);
|
return new ControlTriggerLocalLambda(id, predicate, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ControlTriggerInputBased localOf(String id, Runnable action, Predicate<InputEvent> predicate) {
|
public static ControlTriggerInputBased localOf(
|
||||||
return localOf(id, input -> action.run(), predicate);
|
String id,
|
||||||
|
Runnable action,
|
||||||
|
Predicate<InputEvent> predicate
|
||||||
|
) {
|
||||||
|
return localOf(
|
||||||
|
id,
|
||||||
|
input -> action.run(),
|
||||||
|
predicate
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public static <I extends InputEvent> ControlTriggerInputBased localOf(String id, Class<I> inputType,
|
public static <I extends InputEvent> ControlTriggerInputBased localOf(
|
||||||
Consumer<I> action, Predicate<I>... predicates) {
|
String id,
|
||||||
return localOf(id, createCheckedAction(inputType, action),
|
Class<I> inputType,
|
||||||
createCheckedCompoundPredicate(inputType, predicates));
|
Consumer<I> action,
|
||||||
|
Predicate<I>... predicates
|
||||||
|
) {
|
||||||
|
return localOf(
|
||||||
|
id,
|
||||||
|
createCheckedAction(inputType, action),
|
||||||
|
createCheckedCompoundPredicate(inputType, predicates)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public static <I extends InputEvent> ControlTriggerInputBased localOf(String id, Class<I> inputType,
|
public static <I extends InputEvent> ControlTriggerInputBased localOf(
|
||||||
Runnable action, Predicate<I>... predicates) {
|
String id,
|
||||||
return localOf(id, inputType, input -> action.run(), predicates);
|
Class<I> inputType,
|
||||||
|
Runnable action,
|
||||||
|
Predicate<I>... predicates
|
||||||
|
) {
|
||||||
|
return localOf(
|
||||||
|
id,
|
||||||
|
inputType,
|
||||||
|
input -> action.run(),
|
||||||
|
predicates
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public static ControlTriggerInputBased localOf(String id, Consumer<InputEvent> action,
|
public static ControlTriggerInputBased localOf(
|
||||||
Predicate<InputEvent>... predicates) {
|
String id,
|
||||||
return localOf(id, InputEvent.class, action, predicates);
|
Consumer<InputEvent> action,
|
||||||
|
Predicate<InputEvent>... predicates
|
||||||
|
) {
|
||||||
|
return localOf(
|
||||||
|
id,
|
||||||
|
InputEvent.class,
|
||||||
|
action,
|
||||||
|
predicates
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public static <I extends InputEvent> ControlTriggerInputBased localOf(String id, Runnable action,
|
public static <I extends InputEvent> ControlTriggerInputBased localOf(
|
||||||
Predicate<InputEvent>... predicates) {
|
String id,
|
||||||
return of(id, input -> action.run(), predicates);
|
Runnable action,
|
||||||
|
Predicate<InputEvent>... predicates
|
||||||
|
) {
|
||||||
|
return of(
|
||||||
|
id,
|
||||||
|
input -> action.run(),
|
||||||
|
predicates
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <I extends InputEvent> BiConsumer<InputEvent, ControlData> createCheckedDataWriter(
|
private static <I extends InputEvent> BiConsumer<InputEvent, ControlData> createCheckedDataWriter(
|
||||||
Class<I> inputType, BiConsumer<I, ControlData> dataWriter) {
|
Class<I> inputType,
|
||||||
|
BiConsumer<I, ControlData> dataWriter
|
||||||
|
) {
|
||||||
return (inputEvent, control) -> dataWriter.accept(inputType.cast(inputEvent), control);
|
return (inputEvent, control) -> dataWriter.accept(inputType.cast(inputEvent), control);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <I extends InputEvent> Consumer<InputEvent> createCheckedAction(Class<I> inputType,
|
private static <I extends InputEvent> Consumer<InputEvent> createCheckedAction(
|
||||||
Consumer<I> action) {
|
Class<I> inputType,
|
||||||
|
Consumer<I> action
|
||||||
|
) {
|
||||||
return inputEvent -> action.accept(inputType.cast(inputEvent));
|
return inputEvent -> action.accept(inputType.cast(inputEvent));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <I extends InputEvent> Predicate<InputEvent> createCheckedCompoundPredicate(Class<I> inputType,
|
private static <I extends InputEvent> Predicate<InputEvent> createCheckedCompoundPredicate(
|
||||||
Predicate<I>[] predicates) {
|
Class<I> inputType,
|
||||||
|
Predicate<I>[] predicates
|
||||||
|
) {
|
||||||
return new CompoundCastPredicate<>(inputType, predicates);
|
return new CompoundCastPredicate<>(inputType, predicates);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,11 +15,11 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.comms.controls;
|
package ru.windcorp.progressia.client.comms.controls;
|
||||||
|
|
||||||
import ru.windcorp.progressia.client.Client;
|
import ru.windcorp.progressia.client.Client;
|
||||||
import ru.windcorp.progressia.client.graphics.input.bus.Input;
|
import ru.windcorp.progressia.client.graphics.input.InputEvent;
|
||||||
import ru.windcorp.progressia.common.comms.packets.Packet;
|
import ru.windcorp.progressia.common.comms.packets.Packet;
|
||||||
|
|
||||||
public class InputBasedControls {
|
public class InputBasedControls {
|
||||||
@ -32,15 +32,16 @@ public class InputBasedControls {
|
|||||||
this.client = client;
|
this.client = client;
|
||||||
|
|
||||||
this.controls = ControlTriggerRegistry.getInstance().values().stream()
|
this.controls = ControlTriggerRegistry.getInstance().values().stream()
|
||||||
.filter(ControlTriggerInputBased.class::isInstance).toArray(ControlTriggerInputBased[]::new);
|
.filter(ControlTriggerInputBased.class::isInstance)
|
||||||
|
.toArray(ControlTriggerInputBased[]::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleInput(Input input) {
|
public void handleInput(InputEvent event) {
|
||||||
for (ControlTriggerInputBased c : controls) {
|
for (ControlTriggerInputBased c : controls) {
|
||||||
Packet packet = c.onInputEvent(input.getEvent());
|
Packet packet = c.onInputEvent(event);
|
||||||
|
|
||||||
if (packet != null) {
|
if (packet != null) {
|
||||||
input.consume();
|
event.consume();
|
||||||
client.getComms().sendPacket(packet);
|
client.getComms().sendPacket(packet);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ package ru.windcorp.progressia.client.comms.localhost;
|
|||||||
import ru.windcorp.progressia.client.comms.ServerCommsChannel;
|
import ru.windcorp.progressia.client.comms.ServerCommsChannel;
|
||||||
import ru.windcorp.progressia.common.comms.packets.Packet;
|
import ru.windcorp.progressia.common.comms.packets.Packet;
|
||||||
import ru.windcorp.progressia.server.Server;
|
import ru.windcorp.progressia.server.Server;
|
||||||
|
import ru.windcorp.progressia.server.ServerState;
|
||||||
|
|
||||||
public class LocalServerCommsChannel extends ServerCommsChannel {
|
public class LocalServerCommsChannel extends ServerCommsChannel {
|
||||||
|
|
||||||
@ -34,7 +35,11 @@ public class LocalServerCommsChannel extends ServerCommsChannel {
|
|||||||
public void connect(String login) {
|
public void connect(String login) {
|
||||||
setState(State.CONNECTED);
|
setState(State.CONNECTED);
|
||||||
|
|
||||||
this.localClient = new LocalClient(server.getClientManager().grabClientId(), login, this);
|
this.localClient = new LocalClient(
|
||||||
|
server.getClientManager().grabClientId(),
|
||||||
|
login,
|
||||||
|
this
|
||||||
|
);
|
||||||
|
|
||||||
server.getClientManager().addClient(localClient);
|
server.getClientManager().addClient(localClient);
|
||||||
}
|
}
|
||||||
@ -50,7 +55,7 @@ public class LocalServerCommsChannel extends ServerCommsChannel {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disconnect() {
|
public void disconnect() {
|
||||||
// Do nothing
|
ServerState.getInstance().getClientManager().disconnectClient(localClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Progressia
|
||||||
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package ru.windcorp.progressia.client.events;
|
||||||
|
|
||||||
|
import ru.windcorp.progressia.client.Client;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An interface for all events issued by a {@link Client}.
|
||||||
|
*/
|
||||||
|
public interface ClientEvent {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the client instance that this event happened on.
|
||||||
|
*
|
||||||
|
* @return the client
|
||||||
|
*/
|
||||||
|
Client getClient();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the client instance that the event is posted on. The value provided
|
||||||
|
* to this method must be returned by subsequent calls to
|
||||||
|
* {@link #getClient()}. Do not call this method when handling the event.
|
||||||
|
*
|
||||||
|
* @param client the client dispatching the event or {@code null} to unbind
|
||||||
|
* any previously bound client
|
||||||
|
*/
|
||||||
|
void setClient(Client client);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A default implementation of {@link ClientEvent}. This is not necessarily
|
||||||
|
* extended by client events.
|
||||||
|
*/
|
||||||
|
public static abstract class Default implements ClientEvent {
|
||||||
|
|
||||||
|
private Client client;
|
||||||
|
|
||||||
|
public Default(Client client) {
|
||||||
|
this.client = client;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Client getClient() {
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setClient(Client client) {
|
||||||
|
this.client = client;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Progressia
|
||||||
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package ru.windcorp.progressia.client.events;
|
||||||
|
|
||||||
|
import ru.windcorp.progressia.client.Client;
|
||||||
|
import ru.windcorp.progressia.common.world.entity.EntityDataPlayer;
|
||||||
|
|
||||||
|
public interface NewLocalEntityEvent extends ClientEvent {
|
||||||
|
|
||||||
|
EntityDataPlayer getNewEntity();
|
||||||
|
EntityDataPlayer getPreviousEntity();
|
||||||
|
|
||||||
|
public class Immutable extends ClientEvent.Default implements NewLocalEntityEvent {
|
||||||
|
|
||||||
|
private final EntityDataPlayer newEntity;
|
||||||
|
private final EntityDataPlayer previousEntity;
|
||||||
|
|
||||||
|
public Immutable(Client client, EntityDataPlayer newEntity, EntityDataPlayer previousEntity) {
|
||||||
|
super(client);
|
||||||
|
this.newEntity = newEntity;
|
||||||
|
this.previousEntity = previousEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EntityDataPlayer getNewEntity() {
|
||||||
|
return newEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EntityDataPlayer getPreviousEntity() {
|
||||||
|
return previousEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -55,6 +55,25 @@ public class Colors {
|
|||||||
output = new Vec4();
|
output = new Vec4();
|
||||||
return color.mul(multiplier, multiplier, multiplier, 1, output);
|
return color.mul(multiplier, multiplier, multiplier, 1, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Vec4 mix(Vec4 zero, Vec4 one, float t, Vec4 output) {
|
||||||
|
if (output == null) {
|
||||||
|
output = new Vec4();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (t <= 0) {
|
||||||
|
return output.set(zero);
|
||||||
|
} else if (t >= 1) {
|
||||||
|
return output.set(one);
|
||||||
|
}
|
||||||
|
|
||||||
|
return output.set(
|
||||||
|
zero.x * (1 - t) + one.x * t,
|
||||||
|
zero.y * (1 - t) + one.y * t,
|
||||||
|
zero.z * (1 - t) + one.z * t,
|
||||||
|
zero.w * (1 - t) + one.w * t
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public static Vec4 toVector(int argb, Vec4 output) {
|
public static Vec4 toVector(int argb, Vec4 output) {
|
||||||
output.w = ((argb & 0xFF000000) >>> 24) / (float) 0xFF; // Alpha
|
output.w = ((argb & 0xFF000000) >>> 24) / (float) 0xFF; // Alpha
|
||||||
|
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Progressia
|
||||||
|
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package ru.windcorp.progressia.client.graphics;
|
||||||
|
|
||||||
|
import ru.windcorp.progressia.client.graphics.backend.GraphicsInterface;
|
||||||
|
|
||||||
|
public class ExponentAnimation {
|
||||||
|
|
||||||
|
private final float speed;
|
||||||
|
private float value;
|
||||||
|
|
||||||
|
public ExponentAnimation(float speed, float value) {
|
||||||
|
this.speed = speed;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getSpeed() {
|
||||||
|
return speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(float value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float update(float target, double timeStep) {
|
||||||
|
float difference = value - target;
|
||||||
|
value += difference * (1 - Math.exp(speed * timeStep));
|
||||||
|
|
||||||
|
float newDifference = value - target;
|
||||||
|
if (difference * newDifference < 0) {
|
||||||
|
// Whoops, we've overshot
|
||||||
|
value = target;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float updateForFrame(float target) {
|
||||||
|
return update(target, GraphicsInterface.getFrameLength());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -21,16 +21,10 @@ package ru.windcorp.progressia.client.graphics;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import com.google.common.eventbus.Subscribe;
|
|
||||||
|
|
||||||
import ru.windcorp.progressia.client.graphics.backend.GraphicsInterface;
|
import ru.windcorp.progressia.client.graphics.backend.GraphicsInterface;
|
||||||
import ru.windcorp.progressia.client.graphics.input.CursorEvent;
|
|
||||||
import ru.windcorp.progressia.client.graphics.input.FrameResizeEvent;
|
|
||||||
import ru.windcorp.progressia.client.graphics.input.InputEvent;
|
import ru.windcorp.progressia.client.graphics.input.InputEvent;
|
||||||
import ru.windcorp.progressia.client.graphics.input.KeyEvent;
|
|
||||||
import ru.windcorp.progressia.client.graphics.input.WheelEvent;
|
|
||||||
import ru.windcorp.progressia.client.graphics.input.bus.Input;
|
|
||||||
|
|
||||||
public class GUI {
|
public class GUI {
|
||||||
|
|
||||||
@ -43,21 +37,13 @@ public class GUI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static final List<LayerStackModification> MODIFICATION_QUEUE = Collections
|
private static final List<LayerStackModification> MODIFICATION_QUEUE = Collections
|
||||||
.synchronizedList(new ArrayList<>());
|
.synchronizedList(new ArrayList<>());
|
||||||
|
|
||||||
private static class ModifiableInput extends Input {
|
|
||||||
@Override
|
|
||||||
public void initialize(InputEvent event, Target target) {
|
|
||||||
super.initialize(event, target);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final ModifiableInput THE_INPUT = new ModifiableInput();
|
|
||||||
|
|
||||||
private GUI() {
|
private GUI() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addBottomLayer(Layer layer) {
|
public static void addBottomLayer(Layer layer) {
|
||||||
|
Objects.requireNonNull(layer, "layer");
|
||||||
modify(layers -> {
|
modify(layers -> {
|
||||||
layers.add(layer);
|
layers.add(layer);
|
||||||
layer.onAdded();
|
layer.onAdded();
|
||||||
@ -65,6 +51,7 @@ public class GUI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void addTopLayer(Layer layer) {
|
public static void addTopLayer(Layer layer) {
|
||||||
|
Objects.requireNonNull(layer, "layer");
|
||||||
modify(layers -> {
|
modify(layers -> {
|
||||||
layers.add(0, layer);
|
layers.add(0, layer);
|
||||||
layer.onAdded();
|
layer.onAdded();
|
||||||
@ -72,11 +59,18 @@ public class GUI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void removeLayer(Layer layer) {
|
public static void removeLayer(Layer layer) {
|
||||||
|
Objects.requireNonNull(layer, "layer");
|
||||||
modify(layers -> {
|
modify(layers -> {
|
||||||
layers.remove(layer);
|
layers.remove(layer);
|
||||||
layer.onRemoved();
|
layer.onRemoved();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void updateLayer(Layer layer) {
|
||||||
|
modify(layers -> {
|
||||||
|
// Do nothing
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private static void modify(LayerStackModification mod) {
|
private static void modify(LayerStackModification mod) {
|
||||||
MODIFICATION_QUEUE.add(mod);
|
MODIFICATION_QUEUE.add(mod);
|
||||||
@ -88,33 +82,33 @@ public class GUI {
|
|||||||
|
|
||||||
public static void render() {
|
public static void render() {
|
||||||
synchronized (LAYERS) {
|
synchronized (LAYERS) {
|
||||||
|
|
||||||
if (!MODIFICATION_QUEUE.isEmpty()) {
|
if (!MODIFICATION_QUEUE.isEmpty()) {
|
||||||
MODIFICATION_QUEUE.forEach(action -> action.affect(LAYERS));
|
MODIFICATION_QUEUE.forEach(action -> action.affect(LAYERS));
|
||||||
MODIFICATION_QUEUE.clear();
|
MODIFICATION_QUEUE.clear();
|
||||||
|
|
||||||
boolean isMouseCurrentlyCaptured = GraphicsInterface.isMouseCaptured();
|
boolean isMouseCurrentlyCaptured = GraphicsInterface.isMouseCaptured();
|
||||||
Layer.CursorPolicy policy = Layer.CursorPolicy.REQUIRE;
|
Layer.CursorPolicy policy = Layer.CursorPolicy.REQUIRE;
|
||||||
|
|
||||||
for (Layer layer : LAYERS) {
|
for (Layer layer : LAYERS) {
|
||||||
Layer.CursorPolicy currentPolicy = layer.getCursorPolicy();
|
Layer.CursorPolicy currentPolicy = layer.getCursorPolicy();
|
||||||
|
|
||||||
if (currentPolicy != Layer.CursorPolicy.INDIFFERENT) {
|
if (currentPolicy != Layer.CursorPolicy.INDIFFERENT) {
|
||||||
policy = currentPolicy;
|
policy = currentPolicy;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean shouldCaptureMouse = (policy == Layer.CursorPolicy.FORBID);
|
boolean shouldCaptureMouse = (policy == Layer.CursorPolicy.FORBID);
|
||||||
if (shouldCaptureMouse != isMouseCurrentlyCaptured) {
|
if (shouldCaptureMouse != isMouseCurrentlyCaptured) {
|
||||||
GraphicsInterface.setMouseCaptured(shouldCaptureMouse);
|
GraphicsInterface.setMouseCaptured(shouldCaptureMouse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = LAYERS.size() - 1; i >= 0; --i) {
|
for (int i = LAYERS.size() - 1; i >= 0; --i) {
|
||||||
LAYERS.get(i).render();
|
LAYERS.get(i).render();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,43 +116,12 @@ public class GUI {
|
|||||||
LAYERS.forEach(Layer::invalidate);
|
LAYERS.forEach(Layer::invalidate);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void dispatchInputEvent(InputEvent event) {
|
public static void dispatchInput(InputEvent event) {
|
||||||
Input.Target target;
|
synchronized (LAYERS) {
|
||||||
|
for (int i = 0; i < LAYERS.size(); ++i) {
|
||||||
if (event instanceof KeyEvent) {
|
LAYERS.get(i).handleInput(event);
|
||||||
if (((KeyEvent) event).isMouse()) {
|
|
||||||
target = Input.Target.HOVERED;
|
|
||||||
} else {
|
|
||||||
target = Input.Target.FOCUSED;
|
|
||||||
}
|
}
|
||||||
} else if (event instanceof CursorEvent) {
|
|
||||||
target = Input.Target.HOVERED;
|
|
||||||
} else if (event instanceof WheelEvent) {
|
|
||||||
target = Input.Target.HOVERED;
|
|
||||||
} else if (event instanceof FrameResizeEvent) {
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
target = Input.Target.ALL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
THE_INPUT.initialize(event, target);
|
|
||||||
LAYERS.forEach(l -> l.handleInput(THE_INPUT));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Object getEventSubscriber() {
|
|
||||||
return new Object() {
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onFrameResized(FrameResizeEvent event) {
|
|
||||||
GUI.invalidateEverything();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onInput(InputEvent event) {
|
|
||||||
dispatchInputEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,13 +15,13 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics;
|
package ru.windcorp.progressia.client.graphics;
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import ru.windcorp.progressia.client.graphics.backend.GraphicsInterface;
|
import ru.windcorp.progressia.client.graphics.backend.GraphicsInterface;
|
||||||
import ru.windcorp.progressia.client.graphics.input.bus.Input;
|
import ru.windcorp.progressia.client.graphics.input.InputEvent;
|
||||||
|
|
||||||
public abstract class Layer {
|
public abstract class Layer {
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ public abstract class Layer {
|
|||||||
|
|
||||||
protected abstract void doRender();
|
protected abstract void doRender();
|
||||||
|
|
||||||
protected abstract void handleInput(Input input);
|
public abstract void handleInput(InputEvent input);
|
||||||
|
|
||||||
protected int getWidth() {
|
protected int getWidth() {
|
||||||
return GraphicsInterface.getFrameWidth();
|
return GraphicsInterface.getFrameWidth();
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend;
|
package ru.windcorp.progressia.client.graphics.backend;
|
||||||
|
|
||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
|
@ -15,10 +15,11 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend;
|
package ru.windcorp.progressia.client.graphics.backend;
|
||||||
|
|
||||||
import glm.vec._2.i.Vec2i;
|
import glm.vec._2.i.Vec2i;
|
||||||
|
|
||||||
import org.lwjgl.glfw.GLFWVidMode;
|
import org.lwjgl.glfw.GLFWVidMode;
|
||||||
|
|
||||||
import static org.lwjgl.glfw.GLFW.*;
|
import static org.lwjgl.glfw.GLFW.*;
|
||||||
@ -42,6 +43,13 @@ public class GraphicsBackend {
|
|||||||
private static boolean vSyncEnabled = false;
|
private static boolean vSyncEnabled = false;
|
||||||
private static boolean isGLFWInitialized = false;
|
private static boolean isGLFWInitialized = false;
|
||||||
private static boolean isOpenGLInitialized = false;
|
private static boolean isOpenGLInitialized = false;
|
||||||
|
|
||||||
|
private static boolean allowDisablingCursor;
|
||||||
|
static {
|
||||||
|
String key = GraphicsBackend.class.getName() + ".allowDisablingCursor";
|
||||||
|
allowDisablingCursor = Boolean.parseBoolean(System.getProperty(key, "true"));
|
||||||
|
}
|
||||||
|
private static boolean forceCursorToCenter = false;
|
||||||
|
|
||||||
private GraphicsBackend() {
|
private GraphicsBackend() {
|
||||||
}
|
}
|
||||||
@ -61,7 +69,7 @@ public class GraphicsBackend {
|
|||||||
static void setOpenGLInitialized(boolean isOpenGLInitialized) {
|
static void setOpenGLInitialized(boolean isOpenGLInitialized) {
|
||||||
GraphicsBackend.isOpenGLInitialized = isOpenGLInitialized;
|
GraphicsBackend.isOpenGLInitialized = isOpenGLInitialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initialize() {
|
public static void initialize() {
|
||||||
startRenderThread();
|
startRenderThread();
|
||||||
}
|
}
|
||||||
@ -114,6 +122,10 @@ public class GraphicsBackend {
|
|||||||
frameLength = now - frameStart;
|
frameLength = now - frameStart;
|
||||||
frameStart = now;
|
frameStart = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (forceCursorToCenter) {
|
||||||
|
glfwSetCursorPos(windowHandle, FRAME_SIZE.x / 2.0, FRAME_SIZE.y / 2.0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void endFrame() {
|
static void endFrame() {
|
||||||
@ -159,14 +171,27 @@ public class GraphicsBackend {
|
|||||||
|
|
||||||
public static void setFullscreen() {
|
public static void setFullscreen() {
|
||||||
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
||||||
glfwSetWindowMonitor(getWindowHandle(), glfwGetPrimaryMonitor(), 0, 0, vidmode.width(), vidmode.height(), 0);
|
glfwSetWindowMonitor(
|
||||||
|
getWindowHandle(),
|
||||||
|
glfwGetPrimaryMonitor(),
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
vidmode.width(),
|
||||||
|
vidmode.height(),
|
||||||
|
0);
|
||||||
isFullscreen = true;
|
isFullscreen = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setWindowed() {
|
public static void setWindowed() {
|
||||||
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
||||||
glfwSetWindowMonitor(getWindowHandle(), 0, (vidmode.width() - getFrameWidth()) / 2,
|
glfwSetWindowMonitor(
|
||||||
(vidmode.height() - getFrameHeight()) / 2, getFrameWidth(), getFrameHeight(), 0);
|
getWindowHandle(),
|
||||||
|
0,
|
||||||
|
(vidmode.width() - getFrameWidth()) / 2,
|
||||||
|
(vidmode.height() - getFrameHeight()) / 2,
|
||||||
|
getFrameWidth(),
|
||||||
|
getFrameHeight(),
|
||||||
|
0);
|
||||||
isFullscreen = false;
|
isFullscreen = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,10 +206,18 @@ public class GraphicsBackend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isMouseCaptured() {
|
public static boolean isMouseCaptured() {
|
||||||
|
if (!allowDisablingCursor) {
|
||||||
|
return forceCursorToCenter;
|
||||||
|
}
|
||||||
return glfwGetInputMode(windowHandle, GLFW_CURSOR) == GLFW_CURSOR_DISABLED;
|
return glfwGetInputMode(windowHandle, GLFW_CURSOR) == GLFW_CURSOR_DISABLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setMouseCaptured(boolean capture) {
|
public static void setMouseCaptured(boolean capture) {
|
||||||
|
if (!allowDisablingCursor) {
|
||||||
|
forceCursorToCenter = capture;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int mode = capture ? GLFW_CURSOR_DISABLED : GLFW_CURSOR_NORMAL;
|
int mode = capture ? GLFW_CURSOR_DISABLED : GLFW_CURSOR_NORMAL;
|
||||||
glfwSetInputMode(windowHandle, GLFW_CURSOR, mode);
|
glfwSetInputMode(windowHandle, GLFW_CURSOR, mode);
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend;
|
package ru.windcorp.progressia.client.graphics.backend;
|
||||||
|
|
||||||
import glm.vec._2.i.Vec2i;
|
import glm.vec._2.i.Vec2i;
|
||||||
@ -68,6 +68,10 @@ public class GraphicsInterface {
|
|||||||
public static void subscribeToInputEvents(Object listener) {
|
public static void subscribeToInputEvents(Object listener) {
|
||||||
InputHandler.register(listener);
|
InputHandler.register(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void unsubscribeFromInputEvents(Object listener) {
|
||||||
|
InputHandler.unregister(listener);
|
||||||
|
}
|
||||||
|
|
||||||
public static void startNextLayer() {
|
public static void startNextLayer() {
|
||||||
GraphicsBackend.startNextLayer();
|
GraphicsBackend.startNextLayer();
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend;
|
package ru.windcorp.progressia.client.graphics.backend;
|
||||||
|
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
@ -39,6 +39,7 @@ public class InputHandler {
|
|||||||
|
|
||||||
public void initialize(int key, int scancode, int action, int mods) {
|
public void initialize(int key, int scancode, int action, int mods) {
|
||||||
this.setTime(GraphicsInterface.getTime());
|
this.setTime(GraphicsInterface.getTime());
|
||||||
|
this.setConsumed(false);
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.scancode = scancode;
|
this.scancode = scancode;
|
||||||
this.action = action;
|
this.action = action;
|
||||||
@ -49,11 +50,17 @@ public class InputHandler {
|
|||||||
|
|
||||||
private static final ModifiableKeyEvent THE_KEY_EVENT = new ModifiableKeyEvent();
|
private static final ModifiableKeyEvent THE_KEY_EVENT = new ModifiableKeyEvent();
|
||||||
|
|
||||||
static void handleKeyInput(long window, int key, int scancode, int action, int mods) {
|
static void handleKeyInput(
|
||||||
|
long window,
|
||||||
|
int key,
|
||||||
|
int scancode,
|
||||||
|
int action,
|
||||||
|
int mods
|
||||||
|
) {
|
||||||
if (GraphicsBackend.getWindowHandle() != window)
|
if (GraphicsBackend.getWindowHandle() != window)
|
||||||
return;
|
return;
|
||||||
THE_KEY_EVENT.initialize(key, scancode, action, mods);
|
THE_KEY_EVENT.initialize(key, scancode, action, mods);
|
||||||
dispatch(THE_KEY_EVENT);
|
INPUT_EVENT_BUS.post(THE_KEY_EVENT);
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case GLFW.GLFW_PRESS:
|
case GLFW.GLFW_PRESS:
|
||||||
@ -65,7 +72,12 @@ public class InputHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handleMouseButtonInput(long window, int key, int action, int mods) {
|
static void handleMouseButtonInput(
|
||||||
|
long window,
|
||||||
|
int key,
|
||||||
|
int action,
|
||||||
|
int mods
|
||||||
|
) {
|
||||||
handleKeyInput(window, key, Integer.MAX_VALUE - key, action, mods);
|
handleKeyInput(window, key, Integer.MAX_VALUE - key, action, mods);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,6 +91,7 @@ public class InputHandler {
|
|||||||
|
|
||||||
public void initialize(double x, double y) {
|
public void initialize(double x, double y) {
|
||||||
this.setTime(GraphicsInterface.getTime());
|
this.setTime(GraphicsInterface.getTime());
|
||||||
|
this.setConsumed(false);
|
||||||
getNewPosition().set(x, y);
|
getNewPosition().set(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +99,11 @@ public class InputHandler {
|
|||||||
|
|
||||||
private static final ModifiableCursorMoveEvent THE_CURSOR_MOVE_EVENT = new ModifiableCursorMoveEvent();
|
private static final ModifiableCursorMoveEvent THE_CURSOR_MOVE_EVENT = new ModifiableCursorMoveEvent();
|
||||||
|
|
||||||
static void handleMouseMoveInput(long window, double x, double y) {
|
static void handleMouseMoveInput(
|
||||||
|
long window,
|
||||||
|
double x,
|
||||||
|
double y
|
||||||
|
) {
|
||||||
if (GraphicsBackend.getWindowHandle() != window)
|
if (GraphicsBackend.getWindowHandle() != window)
|
||||||
return;
|
return;
|
||||||
y = GraphicsInterface.getFrameHeight() - y; // Flip y axis
|
y = GraphicsInterface.getFrameHeight() - y; // Flip y axis
|
||||||
@ -94,7 +111,7 @@ public class InputHandler {
|
|||||||
InputTracker.initializeCursorPosition(x, y);
|
InputTracker.initializeCursorPosition(x, y);
|
||||||
|
|
||||||
THE_CURSOR_MOVE_EVENT.initialize(x, y);
|
THE_CURSOR_MOVE_EVENT.initialize(x, y);
|
||||||
dispatch(THE_CURSOR_MOVE_EVENT);
|
INPUT_EVENT_BUS.post(THE_CURSOR_MOVE_EVENT);
|
||||||
|
|
||||||
InputTracker.getCursorPosition().set(x, y);
|
InputTracker.getCursorPosition().set(x, y);
|
||||||
}
|
}
|
||||||
@ -109,6 +126,7 @@ public class InputHandler {
|
|||||||
|
|
||||||
public void initialize(double xOffset, double yOffset) {
|
public void initialize(double xOffset, double yOffset) {
|
||||||
this.setTime(GraphicsInterface.getTime());
|
this.setTime(GraphicsInterface.getTime());
|
||||||
|
this.setConsumed(false);
|
||||||
this.getOffset().set(xOffset, yOffset);
|
this.getOffset().set(xOffset, yOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,11 +134,15 @@ public class InputHandler {
|
|||||||
|
|
||||||
private static final ModifiableWheelScrollEvent THE_WHEEL_SCROLL_EVENT = new ModifiableWheelScrollEvent();
|
private static final ModifiableWheelScrollEvent THE_WHEEL_SCROLL_EVENT = new ModifiableWheelScrollEvent();
|
||||||
|
|
||||||
static void handleWheelScroll(long window, double xoffset, double yoffset) {
|
static void handleWheelScroll(
|
||||||
|
long window,
|
||||||
|
double xoffset,
|
||||||
|
double yoffset
|
||||||
|
) {
|
||||||
if (GraphicsBackend.getWindowHandle() != window)
|
if (GraphicsBackend.getWindowHandle() != window)
|
||||||
return;
|
return;
|
||||||
THE_WHEEL_SCROLL_EVENT.initialize(xoffset, yoffset);
|
THE_WHEEL_SCROLL_EVENT.initialize(xoffset, yoffset);
|
||||||
dispatch(THE_WHEEL_SCROLL_EVENT);
|
INPUT_EVENT_BUS.post(THE_WHEEL_SCROLL_EVENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FrameResizeEvent
|
// FrameResizeEvent
|
||||||
@ -133,6 +155,7 @@ public class InputHandler {
|
|||||||
|
|
||||||
public void initialize(int width, int height) {
|
public void initialize(int width, int height) {
|
||||||
this.setTime(GraphicsInterface.getTime());
|
this.setTime(GraphicsInterface.getTime());
|
||||||
|
this.setConsumed(false);
|
||||||
this.getNewSize().set(width, height);
|
this.getNewSize().set(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,19 +166,22 @@ public class InputHandler {
|
|||||||
/*
|
/*
|
||||||
* NB: this is NOT a GLFW callback, the raw callback is in GraphicsBackend
|
* NB: this is NOT a GLFW callback, the raw callback is in GraphicsBackend
|
||||||
*/
|
*/
|
||||||
static void handleFrameResize(int width, int height) {
|
static void handleFrameResize(
|
||||||
|
int width,
|
||||||
|
int height
|
||||||
|
) {
|
||||||
THE_FRAME_RESIZE_EVENT.initialize(width, height);
|
THE_FRAME_RESIZE_EVENT.initialize(width, height);
|
||||||
dispatch(THE_FRAME_RESIZE_EVENT);
|
INPUT_EVENT_BUS.post(THE_FRAME_RESIZE_EVENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Misc
|
// Misc
|
||||||
|
|
||||||
private static void dispatch(InputEvent event) {
|
|
||||||
INPUT_EVENT_BUS.post(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void register(Object listener) {
|
public static void register(Object listener) {
|
||||||
INPUT_EVENT_BUS.register(listener);
|
INPUT_EVENT_BUS.register(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void unregister(Object listener) {
|
||||||
|
INPUT_EVENT_BUS.unregister(listener);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend;
|
package ru.windcorp.progressia.client.graphics.backend;
|
||||||
|
|
||||||
import glm.vec._2.d.Vec2d;
|
import glm.vec._2.d.Vec2d;
|
||||||
@ -24,7 +24,10 @@ import gnu.trove.set.hash.TIntHashSet;
|
|||||||
|
|
||||||
public class InputTracker {
|
public class InputTracker {
|
||||||
|
|
||||||
private static final Vec2d CURSOR_POSITION = new Vec2d(Double.NaN, Double.NaN);
|
private static final Vec2d CURSOR_POSITION = new Vec2d(
|
||||||
|
Double.NaN,
|
||||||
|
Double.NaN
|
||||||
|
);
|
||||||
|
|
||||||
private static final TIntSet PRESSED_KEYS = new TIntHashSet(256);
|
private static final TIntSet PRESSED_KEYS = new TIntHashSet(256);
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend;
|
package ru.windcorp.progressia.client.graphics.backend;
|
||||||
|
|
||||||
import static org.lwjgl.opengl.GL11.*;
|
import static org.lwjgl.opengl.GL11.*;
|
||||||
@ -24,7 +24,11 @@ import static org.lwjgl.system.MemoryUtil.*;
|
|||||||
|
|
||||||
import org.lwjgl.opengl.GL;
|
import org.lwjgl.opengl.GL;
|
||||||
|
|
||||||
|
import com.google.common.eventbus.Subscribe;
|
||||||
|
|
||||||
import ru.windcorp.progressia.client.graphics.GUI;
|
import ru.windcorp.progressia.client.graphics.GUI;
|
||||||
|
import ru.windcorp.progressia.client.graphics.input.FrameResizeEvent;
|
||||||
|
import ru.windcorp.progressia.client.graphics.input.InputEvent;
|
||||||
|
|
||||||
class LWJGLInitializer {
|
class LWJGLInitializer {
|
||||||
|
|
||||||
@ -66,7 +70,7 @@ class LWJGLInitializer {
|
|||||||
GraphicsBackend.setWindowHandle(handle);
|
GraphicsBackend.setWindowHandle(handle);
|
||||||
|
|
||||||
glfwMakeContextCurrent(handle);
|
glfwMakeContextCurrent(handle);
|
||||||
glfwSwapInterval(0); // TODO: remove after config system is added
|
glfwSwapInterval(0); // TODO: remove after config system is added
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void positionWindow() {
|
private static void positionWindow() {
|
||||||
@ -92,16 +96,35 @@ class LWJGLInitializer {
|
|||||||
private static void setupWindowCallbacks() {
|
private static void setupWindowCallbacks() {
|
||||||
long handle = GraphicsBackend.getWindowHandle();
|
long handle = GraphicsBackend.getWindowHandle();
|
||||||
|
|
||||||
glfwSetFramebufferSizeCallback(handle, GraphicsBackend::onFrameResized);
|
glfwSetFramebufferSizeCallback(
|
||||||
|
handle,
|
||||||
|
GraphicsBackend::onFrameResized
|
||||||
|
);
|
||||||
|
|
||||||
glfwSetKeyCallback(handle, InputHandler::handleKeyInput);
|
glfwSetKeyCallback(handle, InputHandler::handleKeyInput);
|
||||||
glfwSetMouseButtonCallback(handle, InputHandler::handleMouseButtonInput);
|
glfwSetMouseButtonCallback(
|
||||||
|
handle,
|
||||||
|
InputHandler::handleMouseButtonInput
|
||||||
|
);
|
||||||
|
|
||||||
glfwSetCursorPosCallback(handle, InputHandler::handleMouseMoveInput);
|
glfwSetCursorPosCallback(handle, InputHandler::handleMouseMoveInput);
|
||||||
|
|
||||||
glfwSetScrollCallback(handle, InputHandler::handleWheelScroll);
|
glfwSetScrollCallback(handle, InputHandler::handleWheelScroll);
|
||||||
|
|
||||||
GraphicsInterface.subscribeToInputEvents(GUI.getEventSubscriber());
|
GraphicsInterface.subscribeToInputEvents(new Object() {
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onFrameResized(FrameResizeEvent event) {
|
||||||
|
GUI.invalidateEverything();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onInputEvent(InputEvent event) {
|
||||||
|
GUI.dispatchInput(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend;
|
package ru.windcorp.progressia.client.graphics.backend;
|
||||||
|
|
||||||
import java.lang.ref.PhantomReference;
|
import java.lang.ref.PhantomReference;
|
||||||
@ -34,13 +34,19 @@ public class OpenGLObjectTracker {
|
|||||||
private static final ReferenceQueue<OpenGLDeletable> DELETE_QUEUE = new ReferenceQueue<>();
|
private static final ReferenceQueue<OpenGLDeletable> DELETE_QUEUE = new ReferenceQueue<>();
|
||||||
|
|
||||||
public synchronized static void register(OpenGLDeletable object, IntConsumer glDeleter) {
|
public synchronized static void register(OpenGLDeletable object, IntConsumer glDeleter) {
|
||||||
GLPhantomReference<OpenGLDeletable> glRef = new GLPhantomReference<>(object, DELETE_QUEUE, object.getHandle(),
|
GLPhantomReference<OpenGLDeletable> glRef = new GLPhantomReference<>(
|
||||||
glDeleter);
|
object,
|
||||||
|
DELETE_QUEUE,
|
||||||
|
object.getHandle(),
|
||||||
|
glDeleter
|
||||||
|
);
|
||||||
TO_DELETE.add(glRef);
|
TO_DELETE.add(glRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void deleteAllObjects() {
|
public static void deleteAllObjects() {
|
||||||
for (GLPhantomReference<OpenGLDeletable> glRef : TO_DELETE) {
|
for (
|
||||||
|
GLPhantomReference<OpenGLDeletable> glRef : TO_DELETE
|
||||||
|
) {
|
||||||
glRef.clear();
|
glRef.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,16 +75,20 @@ public class OpenGLObjectTracker {
|
|||||||
* It is possible to create a phantom reference with a {@code null}
|
* It is possible to create a phantom reference with a {@code null}
|
||||||
* queue, but such a reference is completely useless: Its {@code get}
|
* queue, but such a reference is completely useless: Its {@code get}
|
||||||
* method will always return {@code null} and, since it does not have a
|
* method will always return {@code null} and, since it does not have a
|
||||||
* queue, it will never be enqueued.
|
* queue,
|
||||||
|
* it will never be enqueued.
|
||||||
*
|
*
|
||||||
* @param referent
|
* @param referent the object the new phantom reference will refer to
|
||||||
* the object the new phantom reference will refer to
|
* @param q the queue with which the reference is to be
|
||||||
* @param q
|
* registered,
|
||||||
* the queue with which the reference is to be registered, or
|
* or {@code null} if registration is not required
|
||||||
* {@code null} if registration is not required
|
|
||||||
*/
|
*/
|
||||||
public GLPhantomReference(T referent, ReferenceQueue<? super T> q, int referentGLhandle,
|
public GLPhantomReference(
|
||||||
IntConsumer GLDeleter) {
|
T referent,
|
||||||
|
ReferenceQueue<? super T> q,
|
||||||
|
int referentGLhandle,
|
||||||
|
IntConsumer GLDeleter
|
||||||
|
) {
|
||||||
super(referent, q);
|
super(referent, q);
|
||||||
this.referentGLhandle = referentGLhandle;
|
this.referentGLhandle = referentGLhandle;
|
||||||
this.GLDeleter = GLDeleter;
|
this.GLDeleter = GLDeleter;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend;
|
package ru.windcorp.progressia.client.graphics.backend;
|
||||||
|
|
||||||
import ru.windcorp.jputil.functions.ThrowingRunnable;
|
import ru.windcorp.jputil.functions.ThrowingRunnable;
|
||||||
@ -41,7 +41,11 @@ public class RenderTaskQueue {
|
|||||||
HANDLER.invokeNow(task);
|
HANDLER.invokeNow(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <E extends Exception> void waitAndInvoke(ThrowingRunnable<E> task) throws InterruptedException, E {
|
public static <E extends Exception> void waitAndInvoke(
|
||||||
|
ThrowingRunnable<E> task
|
||||||
|
)
|
||||||
|
throws InterruptedException,
|
||||||
|
E {
|
||||||
HANDLER.waitAndInvoke(task);
|
HANDLER.waitAndInvoke(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend;
|
package ru.windcorp.progressia.client.graphics.backend;
|
||||||
|
|
||||||
import static org.lwjgl.glfw.GLFW.*;
|
import static org.lwjgl.glfw.GLFW.*;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend;
|
package ru.windcorp.progressia.client.graphics.backend;
|
||||||
|
|
||||||
import static org.lwjgl.opengl.GL15.GL_DYNAMIC_DRAW;
|
import static org.lwjgl.opengl.GL15.GL_DYNAMIC_DRAW;
|
||||||
@ -23,7 +23,9 @@ import static org.lwjgl.opengl.GL15.GL_STATIC_DRAW;
|
|||||||
import static org.lwjgl.opengl.GL15.GL_STREAM_DRAW;
|
import static org.lwjgl.opengl.GL15.GL_STREAM_DRAW;
|
||||||
|
|
||||||
public enum Usage { // TODO add _COPY and _READ, pref. as another enum
|
public enum Usage { // TODO add _COPY and _READ, pref. as another enum
|
||||||
STATIC(GL_STATIC_DRAW), DYNAMIC(GL_DYNAMIC_DRAW), STREAM(GL_STREAM_DRAW);
|
STATIC(GL_STATIC_DRAW),
|
||||||
|
DYNAMIC(GL_DYNAMIC_DRAW),
|
||||||
|
STREAM(GL_STREAM_DRAW);
|
||||||
|
|
||||||
private final int glCode;
|
private final int glCode;
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend;
|
package ru.windcorp.progressia.client.graphics.backend;
|
||||||
|
|
||||||
import static org.lwjgl.opengl.GL20.*;
|
import static org.lwjgl.opengl.GL20.*;
|
||||||
@ -28,7 +28,8 @@ import ru.windcorp.progressia.client.graphics.backend.OpenGLObjectTracker.OpenGL
|
|||||||
public class VertexBufferObject implements OpenGLDeletable {
|
public class VertexBufferObject implements OpenGLDeletable {
|
||||||
|
|
||||||
public static enum BindTarget {
|
public static enum BindTarget {
|
||||||
ARRAY(GL_ARRAY_BUFFER), ELEMENT_ARRAY(GL_ELEMENT_ARRAY_BUFFER);
|
ARRAY(GL_ARRAY_BUFFER),
|
||||||
|
ELEMENT_ARRAY(GL_ELEMENT_ARRAY_BUFFER);
|
||||||
|
|
||||||
private final int glCode;
|
private final int glCode;
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend.shaders;
|
package ru.windcorp.progressia.client.graphics.backend.shaders;
|
||||||
|
|
||||||
import ru.windcorp.progressia.common.resource.Resource;
|
import ru.windcorp.progressia.common.resource.Resource;
|
||||||
@ -32,7 +32,12 @@ public class CombinedShader extends Shader {
|
|||||||
for (int i = 1; i < resources.length; ++i) {
|
for (int i = 1; i < resources.length; ++i) {
|
||||||
if (ShaderType.guessByResourceName(resources[i]) != first) {
|
if (ShaderType.guessByResourceName(resources[i]) != first) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Deduced shader types of " + resources[0] + " and " + resources[i] + " differ");
|
"Deduced shader types of "
|
||||||
|
+ resources[0]
|
||||||
|
+ " and "
|
||||||
|
+ resources[i]
|
||||||
|
+ " differ"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,8 +71,19 @@ public class CombinedShader extends Shader {
|
|||||||
if (contents.codePointAt(versionIndex) == '#') {
|
if (contents.codePointAt(versionIndex) == '#') {
|
||||||
final String versionAnnotation = "#version ";
|
final String versionAnnotation = "#version ";
|
||||||
|
|
||||||
if (contents.regionMatches(versionIndex, versionAnnotation, 0, versionAnnotation.length())) {
|
if (
|
||||||
contents = contents.substring(versionIndex + versionAnnotation.length() + "120".length());
|
contents.regionMatches(
|
||||||
|
versionIndex,
|
||||||
|
versionAnnotation,
|
||||||
|
0,
|
||||||
|
versionAnnotation.length()
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
contents = contents.substring(
|
||||||
|
versionIndex
|
||||||
|
+ versionAnnotation.length()
|
||||||
|
+ "120".length()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend.shaders;
|
package ru.windcorp.progressia.client.graphics.backend.shaders;
|
||||||
|
|
||||||
import static org.lwjgl.opengl.GL11.*;
|
import static org.lwjgl.opengl.GL11.*;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend.shaders;
|
package ru.windcorp.progressia.client.graphics.backend.shaders;
|
||||||
|
|
||||||
import static org.lwjgl.opengl.GL11.*;
|
import static org.lwjgl.opengl.GL11.*;
|
||||||
@ -57,7 +57,10 @@ public class Shader implements OpenGLDeletable {
|
|||||||
if (resource.contains("fsh"))
|
if (resource.contains("fsh"))
|
||||||
return FRAGMENT;
|
return FRAGMENT;
|
||||||
|
|
||||||
throw new IllegalArgumentException("Cannot deduce shader type from resource name \"" + resource + "\"");
|
throw new IllegalArgumentException(
|
||||||
|
"Cannot deduce shader type from resource name \"" +
|
||||||
|
resource + "\""
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +90,10 @@ public class Shader implements OpenGLDeletable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Shader(String resource) {
|
public Shader(String resource) {
|
||||||
this(ShaderType.guessByResourceName(resource), getShaderResource(resource).readAsString());
|
this(
|
||||||
|
ShaderType.guessByResourceName(resource),
|
||||||
|
getShaderResource(resource).readAsString()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend.shaders.attributes;
|
package ru.windcorp.progressia.client.graphics.backend.shaders.attributes;
|
||||||
|
|
||||||
import ru.windcorp.progressia.client.graphics.backend.shaders.Program;
|
import ru.windcorp.progressia.client.graphics.backend.shaders.Program;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.windcorp.progressia.client.graphics.backend.shaders.attributes;
|
package ru.windcorp.progressia.client.graphics.backend.shaders.attributes;
|
||||||
|
|
||||||
import static org.lwjgl.opengl.GL11.*;
|
import static org.lwjgl.opengl.GL11.*;
|
||||||
@ -51,29 +51,104 @@ public class AttributeVertexArray extends Attribute {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(int size, boolean normalized, int stride, ByteBuffer pointer) {
|
public void set(
|
||||||
glVertexAttribPointer(handle, size, GL_BYTE, normalized, stride, pointer);
|
int size,
|
||||||
|
boolean normalized,
|
||||||
|
int stride,
|
||||||
|
ByteBuffer pointer
|
||||||
|
) {
|
||||||
|
glVertexAttribPointer(
|
||||||
|
handle,
|
||||||
|
size,
|
||||||
|
GL_BYTE,
|
||||||
|
normalized,
|
||||||
|
stride,
|
||||||
|
pointer
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(int size, boolean normalized, int stride, FloatBuffer pointer) {
|
public void set(
|
||||||
glVertexAttribPointer(handle, size, GL_FLOAT, normalized, stride, pointer);
|
int size,
|
||||||
|
boolean normalized,
|
||||||
|
int stride,
|
||||||
|
FloatBuffer pointer
|
||||||
|
) {
|
||||||
|
glVertexAttribPointer(
|
||||||
|
handle,
|
||||||
|
size,
|
||||||
|
GL_FLOAT,
|
||||||
|
normalized,
|
||||||
|
stride,
|
||||||
|
pointer
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(int size, boolean normalized, int stride, IntBuffer pointer) {
|
public void set(
|
||||||
glVertexAttribPointer(handle, size, GL_INT, normalized, stride, pointer);
|
int size,
|
||||||
|
boolean normalized,
|
||||||
|
int stride,
|
||||||
|
IntBuffer pointer
|
||||||
|
) {
|
||||||
|
glVertexAttribPointer(
|
||||||
|
handle,
|
||||||
|
size,
|
||||||
|
GL_INT,
|
||||||
|
normalized,
|
||||||
|
stride,
|
||||||
|
pointer
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(int size, boolean normalized, int stride, ShortBuffer pointer) {
|
public void set(
|
||||||
glVertexAttribPointer(handle, size, GL_SHORT, normalized, stride, pointer);
|
int size,
|
||||||
|
boolean normalized,
|
||||||
|
int stride,
|
||||||
|
ShortBuffer pointer
|
||||||
|
) {
|
||||||
|
glVertexAttribPointer(
|
||||||
|
handle,
|
||||||
|
size,
|
||||||
|
GL_SHORT,
|
||||||
|
normalized,
|
||||||
|
stride,
|
||||||
|
pointer
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(int size, int type, boolean normalized, int stride, long pointer) {
|
public void set(
|
||||||
glVertexAttribPointer(handle, size, type, normalized, stride, pointer);
|
int size,
|
||||||
|
int type,
|
||||||
|
boolean normalized,
|
||||||
|
int stride,
|
||||||
|
long pointer
|
||||||
|
) {
|
||||||
|
glVertexAttribPointer(
|
||||||
|
handle,
|
||||||
|
size,
|
||||||
|
type,
|
||||||
|
normalized,
|
||||||
|
stride,
|
||||||
|
pointer
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(int size, int type, boolean normalized, int stride, VertexBufferObject vbo, long offset) {
|
public void set(
|
||||||
|
int size,
|
||||||
|
int type,
|
||||||
|
boolean normalized,
|
||||||
|
int stride,
|
||||||
|
VertexBufferObject vbo,
|
||||||
|
long offset
|
||||||
|
) {
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vbo.getHandle());
|
glBindBuffer(GL_ARRAY_BUFFER, vbo.getHandle());
|
||||||
glVertexAttribPointer(handle, size, type, normalized, stride, offset);
|
glVertexAttribPointer(
|
||||||
|
handle,
|
||||||
|
size,
|
||||||
|
type,
|
||||||
|
normalized,
|
||||||
|
stride,
|
||||||
|
offset
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user