Compare commits
86 Commits
TechDemo
...
falling-sa
Author | SHA1 | Date | |
---|---|---|---|
71250104ea | |||
51752f95f9 | |||
175f092673 | |||
59129f95c9 | |||
efff41a6db | |||
30879a1241 | |||
9fc1a21191
|
|||
4f620b7261
|
|||
6f90bf345b
|
|||
2328f2ae3a
|
|||
15b5d367b4
|
|||
ca2014802a
|
|||
539a61e854
|
|||
a3760d7425
|
|||
d33b48578d
|
|||
a6fd81ba1e
|
|||
82872c7cf3
|
|||
54c66d28d6
|
|||
78a1c25554
|
|||
a03c783fc9
|
|||
0a45613e45
|
|||
5fb4c601ff
|
|||
020802a89c
|
|||
0f909039fe
|
|||
15f741bc04
|
|||
80541eafc3
|
|||
0f60d45ffa
|
|||
fbc803d6e2
|
|||
dccfcc9419 | |||
c2a2cc074a | |||
1ee9a55d19 | |||
a338a00f1d | |||
9a326603cd | |||
d7afe39f00
|
|||
0264e512ab
|
|||
e47fb3c4bd
|
|||
eace6733ce
|
|||
085f602427
|
|||
737b495fc4
|
|||
e58007ea11 | |||
ae2980c9de | |||
3879e5ffac | |||
47eb9fa5af | |||
bf49687ab6 | |||
b3ae829383 | |||
b374e9a736 | |||
531a8c99c3
|
|||
6fb7e7fc04
|
|||
20dccf3d12
|
|||
32851b8fb0
|
|||
a95bdf1efe
|
|||
e0a03cad1d
|
|||
2532e80f6a
|
|||
3c3f3816df
|
|||
2d3d250f92
|
|||
c49fdfa5ff
|
|||
9d7f69892b
|
|||
7ecdfdfb4d
|
|||
4332a78221
|
|||
ef572c43c7
|
|||
f28c765e3f
|
|||
f4311fb27c
|
|||
abd8d9eebb
|
|||
a9a21ce664
|
|||
bd5a1fa04e
|
|||
2d55d4db51
|
|||
d438d2aa14
|
|||
d3c5011063
|
|||
10d271059c
|
|||
acef9d32df
|
|||
848178b343
|
|||
b1666fa4b9
|
|||
73d24d36f4 | |||
bdb3bff570 | |||
6997bb1104 | |||
eac0a34516 | |||
f9717be412
|
|||
127d1c3d87 | |||
26a35f306c
|
|||
52f3f653d8 | |||
553837f207
|
|||
8c5493f78e
|
|||
fc85eb5658
|
|||
260562310a
|
|||
85edc07c75 | |||
fcf225f9c7 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -30,6 +30,8 @@ build_packages/*
|
||||
!build_packages/NSIS
|
||||
build_packages/NSIS/*
|
||||
!build_packages/NSIS/ProgressiaInstaller.nsi
|
||||
!build_packages/NSIS/logo.ico
|
||||
!build_packages/NSIS/left_side.bmp
|
||||
|
||||
# ... and except build_packages/DEB/template
|
||||
!build_packages/DEB
|
||||
|
@ -16,7 +16,7 @@ temperature mechanics and a parallelism-capable server.
|
||||
- GNU/Linux (x64, arm32 or arm64), Windows XP or later (x64 or x86) or MacOS (x64)
|
||||
- Java 8 or later
|
||||
- OpenGL 2.1 or later
|
||||
- Probably at least 4 GiB RAM
|
||||
- Probably about 0.5 GiB RAM
|
||||
- Less than 1 GiB of storage space
|
||||
|
||||
See [Build Guide](docs/building/BuildGuide.md) for compilation requirements.
|
||||
|
@ -3,17 +3,17 @@
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
@ -24,24 +24,24 @@ buildDebianPackage() {
|
||||
|
||||
# Commands that must be available to execute this action
|
||||
requiredCommands='dpkg-deb fakeroot'
|
||||
|
||||
|
||||
# Package name. Sync with control file manually!
|
||||
name='progressia-techdemo'
|
||||
# Version that the package will receive. Sync with control file manually!
|
||||
version='1.0_all'
|
||||
|
||||
|
||||
# This directory will be copied into $tmpDir
|
||||
templateDirectory="build_packages/DEB/template"
|
||||
|
||||
|
||||
# Files that must be present
|
||||
requiredFiles="$templateDirectory/DEBIAN/control"
|
||||
|
||||
|
||||
nameAndVersion="$name-$version"
|
||||
tmpDir="build_packages/DEB/$nameAndVersion"
|
||||
outputFile="build_packages/DEB/$nameAndVersion.deb"
|
||||
|
||||
echo "Checking environment to build Debian package"
|
||||
|
||||
|
||||
for item in $requiredCommands; do
|
||||
if command -v "$item" &> /dev/null; then
|
||||
echo "- $item found"
|
||||
@ -50,7 +50,7 @@ buildDebianPackage() {
|
||||
exit 100
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
for file in $requiredFiles; do
|
||||
if ! [ -r "$file" ]; then
|
||||
echoerr "$file is missing or not readable, cannot package"
|
||||
@ -59,13 +59,13 @@ buildDebianPackage() {
|
||||
echo "- $file is present and readable"
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
echo "Environment OK; packaging Debian package"
|
||||
exitCode=0
|
||||
|
||||
|
||||
{
|
||||
shareDir="$tmpDir/usr/share/progressia"
|
||||
|
||||
|
||||
mkdir -p "$tmpDir" &&
|
||||
mkdir -p "$shareDir" &&
|
||||
cp -r "$templateDirectory"/* "$tmpDir" &&
|
||||
@ -79,7 +79,7 @@ buildDebianPackage() {
|
||||
echoerr "Could not create Debian package"
|
||||
exitCode=1
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
if [ -d "$tmpDir" ]; then
|
||||
rm -r "$tmpDir"
|
||||
@ -89,7 +89,7 @@ buildDebianPackage() {
|
||||
echoerr "Could not clean up after packaging Debian package"
|
||||
exitCode=2
|
||||
}
|
||||
|
||||
|
||||
exit "$exitCode"
|
||||
}
|
||||
|
||||
@ -97,15 +97,15 @@ buildWindowsInstaller() {
|
||||
|
||||
# Commands that must be available to execute this action
|
||||
requiredCommands='makensis'
|
||||
|
||||
|
||||
# NSIS configuration file that must be present
|
||||
configurationFile='build_packages/NSIS/ProgressiaInstaller.nsi'
|
||||
|
||||
|
||||
# File that will be output
|
||||
outputFile='build_packages/NSIS/ProgressiaInstaller.exe'
|
||||
|
||||
echo "Checking environment to build Windows installer"
|
||||
|
||||
|
||||
for item in $requiredCommands; do
|
||||
if command -v "$item" &> /dev/null; then
|
||||
echo "- $item found"
|
||||
@ -114,20 +114,21 @@ buildWindowsInstaller() {
|
||||
exit 100
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
if ! [ -r "$configurationFile" ]; then
|
||||
echoerr "$configurationFile is missing or not readable, cannot build"
|
||||
exit 101
|
||||
else
|
||||
echo "- $configurationFile is present and readable"
|
||||
fi
|
||||
|
||||
|
||||
echo "Environment OK; building Windows installer"
|
||||
exitCode=0
|
||||
|
||||
|
||||
{
|
||||
cp -r 'build/libs/lib' 'build_packages/NSIS/lib' &&
|
||||
cp 'build/libs/Progressia.jar' 'build_packages/NSIS/Progressia.jar' &&
|
||||
cp 'LICENSE' 'build_packages/NSIS/LICENSE.txt' &&
|
||||
echo "------ NSIS ------" &&
|
||||
makensis "$configurationFile" &&
|
||||
echo "---- NSIS END ----" &&
|
||||
@ -136,7 +137,7 @@ buildWindowsInstaller() {
|
||||
echoerr "Could not build Windows installer"
|
||||
exitCode=1
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
if [ -d 'build_packages/NSIS/lib' ]; then
|
||||
rm -r 'build_packages/NSIS/lib'
|
||||
@ -144,12 +145,15 @@ buildWindowsInstaller() {
|
||||
if [ -e 'build_packages/NSIS/Progressia.jar' ]; then
|
||||
rm 'build_packages/NSIS/Progressia.jar'
|
||||
fi
|
||||
if [ -e 'build_packages/NSIS/LICENSE.txt' ]; then
|
||||
rm 'build_packages/NSIS/LICENSE.txt'
|
||||
fi
|
||||
echo "Cleaned up"
|
||||
} || {
|
||||
echoerr "Could not clean up after building Windows installer"
|
||||
exitCode=2
|
||||
}
|
||||
|
||||
|
||||
exit "$exitCode"
|
||||
}
|
||||
|
||||
|
@ -10,16 +10,32 @@
|
||||
;--------------------------------
|
||||
;General
|
||||
|
||||
!define PROJECT_NAME "Progressia"
|
||||
|
||||
; MUI Settings / Icons
|
||||
!define MUI_ICON "logo.ico"
|
||||
;!define MUI_UNICON ;Uninstall icon
|
||||
|
||||
; MUI Settings / Header
|
||||
; !define MUI_HEADERIMAGE
|
||||
; !define MUI_HEADERIMAGE_RIGHT
|
||||
; !define MUI_HEADERIMAGE_BITMAP "${NSISDIR}\Contrib\Graphics\Header\orange-r-nsis.bmp"
|
||||
; !define MUI_HEADERIMAGE_UNBITMAP "${NSISDIR}\Contrib\Graphics\Header\orange-uninstall-r-nsis.bmp"
|
||||
|
||||
; MUI Settings / Wizard
|
||||
!define MUI_WELCOMEFINISHPAGE_BITMAP "left_side.bmp"
|
||||
!define MUI_UNWELCOMEFINISHPAGE_BITMAP "left_side.bmp"
|
||||
|
||||
;Name and file
|
||||
Name "Progressia"
|
||||
OutFile "ProgressiaInstaller.exe"
|
||||
Name "${PROJECT_NAME}"
|
||||
OutFile "${PROJECT_NAME}Installer.exe"
|
||||
Unicode True
|
||||
|
||||
;Default installation folder
|
||||
InstallDir "$PROGRAMFILES\Progressia"
|
||||
InstallDir "$PROGRAMFILES\${PROJECT_NAME}"
|
||||
|
||||
;Get installation folder from registry if available
|
||||
InstallDirRegKey HKLM "Software\Progressia" "Install_Dir"
|
||||
InstallDirRegKey HKLM "Software\${PROJECT_NAME}" ""
|
||||
|
||||
;Request application privileges for Windows Vista
|
||||
RequestExecutionLevel admin
|
||||
@ -33,14 +49,18 @@
|
||||
;Pages
|
||||
|
||||
!insertmacro MUI_PAGE_WELCOME
|
||||
;!insertmacro MUI_PAGE_LICENSE "${NSISDIR}\Docs\Modern UI\License.txt"
|
||||
!insertmacro MUI_PAGE_LICENSE "LICENSE.txt"
|
||||
!insertmacro MUI_PAGE_COMPONENTS
|
||||
!insertmacro MUI_PAGE_DIRECTORY
|
||||
!insertmacro MUI_PAGE_INSTFILES
|
||||
!define MUI_FINISHPAGE_RUN
|
||||
!define MUI_FINISHPAGE_RUN_TEXT "Start ${PROJECT_NAME}"
|
||||
!define MUI_FINISHPAGE_RUN_FUNCTION "LaunchLink"
|
||||
!insertmacro MUI_PAGE_FINISH
|
||||
|
||||
!insertmacro MUI_UNPAGE_WELCOME
|
||||
!insertmacro MUI_UNPAGE_CONFIRM
|
||||
!insertmacro MUI_UNPAGE_COMPONENTS
|
||||
!insertmacro MUI_UNPAGE_INSTFILES
|
||||
!insertmacro MUI_UNPAGE_FINISH
|
||||
|
||||
@ -52,35 +72,40 @@
|
||||
;--------------------------------
|
||||
;Installer Sections
|
||||
|
||||
Section "Install Progressia" SecDummy
|
||||
Section "Install ${PROJECT_NAME}" SEC0000
|
||||
|
||||
SectionIn RO ;Make it read-only
|
||||
SetOutPath "$INSTDIR"
|
||||
SetOverwrite on
|
||||
|
||||
;Files
|
||||
File Progressia.jar
|
||||
File logo.ico
|
||||
File /r lib
|
||||
|
||||
;Store installation folder
|
||||
WriteRegStr HKLM SOFTWARE\Progressia "Install_Dir" "$INSTDIR"
|
||||
|
||||
;Create uninstaller
|
||||
|
||||
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Progressia" "DisplayName" "Progressia (remove only)"
|
||||
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Progressia" "UninstallString" "$INSTDIR\Uninstall.exe"
|
||||
|
||||
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PROJECT_NAME}" "DisplayName" "${PROJECT_NAME} (remove only)"
|
||||
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PROJECT_NAME}" "UninstallString" "$INSTDIR\Uninstall.exe"
|
||||
WriteUninstaller "$INSTDIR\Uninstall.exe"
|
||||
|
||||
|
||||
SectionEnd
|
||||
|
||||
;--------------------------------
|
||||
;Descriptions
|
||||
Section "Create Desktop Shortcut" SEC0001
|
||||
SetOutPath "$APPDATA\${PROJECT_NAME}"
|
||||
CreateShortCut "$DESKTOP\${PROJECT_NAME}.lnk" "$INSTDIR\${PROJECT_NAME}.jar" "" "$INSTDIR\logo.ico"
|
||||
SectionEnd
|
||||
|
||||
;Language strings
|
||||
LangString DESC_SecDummy ${LANG_ENGLISH} "A test section."
|
||||
Section "Start Menu Shortcuts" SEC0002
|
||||
|
||||
;Assign language strings to sections
|
||||
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
|
||||
!insertmacro MUI_DESCRIPTION_TEXT ${SecDummy} $(DESC_SecDummy)
|
||||
!insertmacro MUI_FUNCTION_DESCRIPTION_END
|
||||
CreateDirectory "$SMPROGRAMS\${PROJECT_NAME}"
|
||||
CreateShortcut "$SMPROGRAMS\${PROJECT_NAME}\Uninstall.lnk" "$INSTDIR\Uninstall.exe"
|
||||
CreateShortcut "$SMPROGRAMS\${PROJECT_NAME}\${PROJECT_NAME}.lnk" "$INSTDIR\${PROJECT_NAME}.jar" "" "$INSTDIR\logo.ico"
|
||||
|
||||
SectionEnd
|
||||
|
||||
;--------------------------------
|
||||
;Uninstaller Section
|
||||
@ -92,9 +117,45 @@ Section "Uninstall"
|
||||
Delete $INSTDIR\Uninstall.exe
|
||||
Delete $INSTDIR\Progressia.jar
|
||||
Delete $INSTDIR\lib\*.*
|
||||
Delete $INSTDIR\logo.ico
|
||||
|
||||
RMDir /r "$INSTDIR"
|
||||
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Progressia"
|
||||
DeleteRegKey HKLM "Software\Progressia"
|
||||
RMDir $INSTDIR\lib
|
||||
|
||||
Delete $DESKTOP\${PROJECT_NAME}.lnk
|
||||
|
||||
Delete $SMPROGRAMS\${PROJECT_NAME}\Uninstall.lnk
|
||||
Delete $SMPROGRAMS\${PROJECT_NAME}\${PROJECT_NAME}.lnk
|
||||
|
||||
RMDir $INSTDIR
|
||||
|
||||
RMDir /r $SMPROGRAMS\${PROJECT_NAME}
|
||||
|
||||
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PROJECT_NAME}"
|
||||
DeleteRegKey HKLM "Software\${PROJECT_NAME}"
|
||||
|
||||
SectionEnd
|
||||
|
||||
Section "un.Remove user data"
|
||||
|
||||
RMDir /r "$APPDATA\${PROJECT_NAME}"
|
||||
|
||||
SectionEnd
|
||||
|
||||
;--------------------------------
|
||||
;Functions
|
||||
|
||||
Function LaunchLink
|
||||
SetOutPath "$APPDATA\${PROJECT_NAME}"
|
||||
ExecShell "" "$INSTDIR\${PROJECT_NAME}.jar"
|
||||
FunctionEnd
|
||||
|
||||
;--------------------------------
|
||||
;Descriptions
|
||||
|
||||
;Language strings
|
||||
LangString DESC_SecDummy ${LANG_ENGLISH} "Install ${PROJECT_NAME}."
|
||||
|
||||
;Assign language strings to sections
|
||||
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
|
||||
!insertmacro MUI_DESCRIPTION_TEXT ${SEC0000} $(DESC_SecDummy)
|
||||
!insertmacro MUI_FUNCTION_DESCRIPTION_END
|
BIN
build_packages/NSIS/left_side.bmp
Normal file
BIN
build_packages/NSIS/left_side.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 151 KiB |
BIN
build_packages/NSIS/logo.ico
Normal file
BIN
build_packages/NSIS/logo.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 187 KiB |
69
docs/CONTRIBUTING.md
Normal file
69
docs/CONTRIBUTING.md
Normal file
@ -0,0 +1,69 @@
|
||||
# Contributing Guidelines
|
||||
|
||||
This document lists conventions adopted by Progressia developers.
|
||||
|
||||
## git
|
||||
|
||||
### Branches
|
||||
Progressia repository contains a `master` branch and several "feature" branches.
|
||||
|
||||
`master` is expected to contain a version of the game suitable for demonstration and forking/branching. Do not commit directly to `master` without OLEGSHA's approval.
|
||||
- `master` must always correctly build without compiler warnings (see below).
|
||||
- `master` must always pass all unit tests.
|
||||
- `master` must always be able to launch successfully.
|
||||
- `master` must always only contain working features.
|
||||
- `master` should not contain excessive debug code.
|
||||
- `master` must always have its code and filenames formatted (see below).
|
||||
|
||||
"Feature" branches are branches dedicated to the development of a single feature. When the feature reaches completion the branch is merged into `master` and removed. Intermediate merges into `master` may occur when some fitting milestone is reached. Intermediate merges from `master` may be done as necessary. Merges between "feature" branches should generally be avoided.
|
||||
|
||||
When beginning work on a new feature, create a new branch based on `master` (or on another "feature" branch if absolutely necessary). Use `all-small-with-dashes` to name the branch: `add-trees` or `rebalance-plastics` are good names. Do not fix unrelated bugs or work on unrelated features in a "feature" branch - create a new one, switch to an existing one or commit directly to `master` if the changes are small enough.
|
||||
|
||||
"Feature" branches may not be formatted properly. Formatting is required before merging into `master` or other branches.
|
||||
|
||||
### Commits
|
||||
- Commits must leave the branch in a state that builds without compiler warnings (see below).
|
||||
- Changes should be grouped in commits semantically. Avoid committing many small related changes in sequence; if necessary, wait and accumulate them. Avoid committing unrelated changes together; if necessary, split staged changes into several commits. This should normally result in about 1-2 commits for a day's work.
|
||||
- Commit bulk changes (renaming, formatting, ...) separately. Don't ever commit whitespace changes outside formatting commits.
|
||||
- Message format:
|
||||
|
||||
```
|
||||
Short description of changes
|
||||
<empty line>
|
||||
- Enumeration of changes
|
||||
- Nest when appropriate
|
||||
- Use dashes only
|
||||
- List not needed for small commits
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
Changed packages for relations, renamed Face to ShapePart
|
||||
|
||||
- Added BlockRelation as an abstract superclass to existing relations
|
||||
- Must be given an absolute "up" direction before use
|
||||
- Moved AbsFace, AbsRelation and BlockRelation to .world.rels
|
||||
- Renamed Face to ShapePart to reduce confusion with AbsFace
|
||||
```
|
||||
|
||||
- Only commit changes described in the commit message. Please double-check staged files before committing.
|
||||
- Avoid merge conflicts. Pull before committing.
|
||||
- Better sign commits than not. See: [git](https://git-scm.com/book/en/v2/Git-Tools-Signing-Your-Work), [GitHub](https://docs.github.com/en/github/authenticating-to-github/managing-commit-signature-verification).
|
||||
|
||||
## Code
|
||||
|
||||
### Warnings
|
||||
Make sure that all committed code contains no compiler warnings. This specifically includes unused imports, unused private members, missing `@Override`s and warnings related to generics.
|
||||
|
||||
Warnings about unknown tokens in `@SuppressWarnings` are temporarily ignored. Please disable them in your IDE.
|
||||
|
||||
### Code Style
|
||||
Formatting code is important.
|
||||
|
||||
- The format is specified within the files inside `/templates_and_presets/eclipse_ide`. Import the specifications into Eclipse or IntelliJ IDEA and use the IDEs' format feature. Alternatively format the code manually in accordance with existing files.
|
||||
- Only use tabs for indentation. Never indent with spaces even when wrapping lines. This is to ensure that indentation does not break when tab width is different.
|
||||
- Don't use `I` prefix for interfaces (not `IDoable` but `Doable`).
|
||||
- Prioritize readability over compactness. Do not hesitate to use (very) long identifiers if they aid comprehension.
|
||||
- Document all mathematics unless it is trivial, especially when using math notation for variable names.
|
||||
- Use proper English when writing comments. Avoid boxes in comments. Use `//` for single-line comments.
|
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
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
package ru.windcorp.jputil;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
@ -611,8 +611,7 @@ public class ArrayUtil {
|
||||
int end = offset + length;
|
||||
if (end > arrayLength || offset < 0)
|
||||
throw new IllegalArgumentException(
|
||||
"Array contains [0; " + arrayLength + "), requested [" + offset + "; " + end + ")"
|
||||
);
|
||||
"Array contains [0; " + arrayLength + "), requested [" + offset + "; " + end + ")");
|
||||
|
||||
return length;
|
||||
}
|
||||
@ -628,8 +627,7 @@ public class ArrayUtil {
|
||||
|
||||
if (end > arrayLength || start < 0)
|
||||
throw new IllegalArgumentException(
|
||||
"Array contains [0; " + arrayLength + "), requested [" + start + "; " + end + ")"
|
||||
);
|
||||
"Array contains [0; " + arrayLength + "), requested [" + start + "; " + end + ")");
|
||||
|
||||
return end;
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil;
|
||||
|
||||
import java.io.OutputStream;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -30,18 +30,8 @@ public class PrimitiveUtil {
|
||||
private static final Map<Class<?>, Object> PRIMITIVE_TO_NULL = new HashMap<>();
|
||||
|
||||
static {
|
||||
for (
|
||||
Class<?> boxed : new Class<?>[] {
|
||||
Boolean.class,
|
||||
Byte.class,
|
||||
Short.class,
|
||||
Character.class,
|
||||
Integer.class,
|
||||
Long.class,
|
||||
Float.class,
|
||||
Double.class
|
||||
}
|
||||
) {
|
||||
for (Class<?> boxed : new Class<?>[] { Boolean.class, Byte.class, Short.class, Character.class, Integer.class,
|
||||
Long.class, Float.class, Double.class }) {
|
||||
try {
|
||||
PRIMITIVE_TO_BOXED.put((Class<?>) boxed.getField("TYPE").get(null), boxed);
|
||||
} catch (Exception e) {
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil;
|
||||
|
||||
import java.util.function.*;
|
||||
@ -40,8 +40,7 @@ import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* 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">
|
||||
* terminal operations</a> on a given monitor.
|
||||
*
|
||||
@ -50,7 +49,7 @@ import java.util.stream.Stream;
|
||||
*/
|
||||
|
||||
// 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")
|
||||
|
||||
public class SyncStreams {
|
||||
@ -1070,21 +1069,18 @@ 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">
|
||||
* terminal operations</a> acquire the provided monitor's lock before
|
||||
* execution. Intermediate operations
|
||||
* return streams that are also synchronized on the same object. The created
|
||||
* stream will behave identically
|
||||
* to the provided stream in all other aspects. Use this to synchronize
|
||||
* access to stream's source.
|
||||
* execution. Intermediate operations return streams that are also
|
||||
* synchronized on the same object. The created stream will behave
|
||||
* identically to the provided stream in all other aspects. Use this to
|
||||
* synchronize access to stream's source.
|
||||
* <p>
|
||||
* <i>The returned {@code Stream}'s {@link Stream#iterator() iterator()} and
|
||||
* {@link Stream#spliterator()
|
||||
* spliterator()} methods return regular non-synchronized iterators and
|
||||
* spliterators respectively</i>. It
|
||||
* is the user's responsibility to avoid concurrency issues:
|
||||
* {@link Stream#spliterator() spliterator()} methods return regular
|
||||
* non-synchronized iterators and spliterators respectively</i>. It is the
|
||||
* user's responsibility to avoid concurrency issues:
|
||||
*
|
||||
* <pre>
|
||||
* synchronized (stream.getMonitor()) {
|
||||
@ -1103,14 +1099,17 @@ public class SyncStreams {
|
||||
* stream.forEach(System.out::println); // Should never throw a ConcurrentModificationException
|
||||
* </pre>
|
||||
*
|
||||
* @param <T> the class of objects in the Stream
|
||||
* @param stream the stream to wrap.
|
||||
* @param monitor the object that the stream will use for synchronization.
|
||||
* When {@code null}, the stream
|
||||
* will synchronize on itself.
|
||||
* @param <T>
|
||||
* the class of objects in the Stream
|
||||
* @param stream
|
||||
* the stream to wrap.
|
||||
* @param monitor
|
||||
* 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
|
||||
* {@code monitor} and backed by {@code stream}.
|
||||
* @throws NullPointerException if {@code stream == null}.
|
||||
* @throws NullPointerException
|
||||
* if {@code stream == null}.
|
||||
*/
|
||||
public static <T> SyncStream<T> synchronizedStream(Stream<T> stream, Object monitor) {
|
||||
Objects.requireNonNull(stream, "stream cannot be null");
|
||||
@ -1118,22 +1117,19 @@ 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">
|
||||
* terminal operations</a> acquire the provided monitor's lock before
|
||||
* execution. Intermediate operations
|
||||
* return streams that are also synchronized on the same object. The created
|
||||
* stream will behave identically
|
||||
* to the provided stream in all other aspects. Use this to synchronize
|
||||
* access to stream's source.
|
||||
* execution. Intermediate operations return streams that are also
|
||||
* synchronized on the same object. The created stream will behave
|
||||
* identically to the provided stream in all other aspects. Use this to
|
||||
* synchronize access to stream's source.
|
||||
* <p>
|
||||
* <i>The returned {@code IntStream}'s {@link IntStream#iterator()
|
||||
* iterator()} and
|
||||
* {@link IntStream#spliterator() spliterator()} methods return regular
|
||||
* non-synchronized iterators and
|
||||
* spliterators respectively</i>. It is the user's responsibility to avoid
|
||||
* concurrency issues:
|
||||
* iterator()} and {@link IntStream#spliterator() spliterator()} methods
|
||||
* return regular non-synchronized iterators and spliterators
|
||||
* respectively</i>. It is the user's responsibility to avoid concurrency
|
||||
* issues:
|
||||
*
|
||||
* <pre>
|
||||
* synchronized (stream.getMonitor()) {
|
||||
@ -1152,13 +1148,15 @@ public class SyncStreams {
|
||||
* stream.forEach(System.out::println); // Should never throw a ConcurrentModificationException
|
||||
* </pre>
|
||||
*
|
||||
* @param stream the stream to wrap.
|
||||
* @param monitor the object that the stream will use for synchronization.
|
||||
* When {@code null}, the stream
|
||||
* will synchronize on itself.
|
||||
* @param stream
|
||||
* the stream to wrap.
|
||||
* @param monitor
|
||||
* the object that the stream will use for synchronization. When
|
||||
* {@code null}, the stream will synchronize on itself.
|
||||
* @return a {@link SyncIntStream} synchronized on {@code monitor} and
|
||||
* backed by {@code stream}.
|
||||
* @throws NullPointerException if {@code stream == null}.
|
||||
* @throws NullPointerException
|
||||
* if {@code stream == null}.
|
||||
*/
|
||||
public static SyncIntStream synchronizedStream(IntStream stream, Object monitor) {
|
||||
Objects.requireNonNull(stream, "stream cannot be null");
|
||||
@ -1166,22 +1164,19 @@ 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">
|
||||
* terminal operations</a> acquire the provided monitor's lock before
|
||||
* execution. Intermediate operations
|
||||
* return streams that are also synchronized on the same object. The created
|
||||
* stream will behave identically
|
||||
* to the provided stream in all other aspects. Use this to synchronize
|
||||
* access to stream's source.
|
||||
* execution. Intermediate operations return streams that are also
|
||||
* synchronized on the same object. The created stream will behave
|
||||
* identically to the provided stream in all other aspects. Use this to
|
||||
* synchronize access to stream's source.
|
||||
* <p>
|
||||
* <i>The returned {@code LongStream}'s {@link LongStream#iterator()
|
||||
* iterator()} and
|
||||
* {@link LongStream#spliterator() spliterator()} methods return regular
|
||||
* non-synchronized iterators and
|
||||
* spliterators respectively</i>. It is the user's responsibility to avoid
|
||||
* concurrency issues:
|
||||
* iterator()} and {@link LongStream#spliterator() spliterator()} methods
|
||||
* return regular non-synchronized iterators and spliterators
|
||||
* respectively</i>. It is the user's responsibility to avoid concurrency
|
||||
* issues:
|
||||
*
|
||||
* <pre>
|
||||
* synchronized (stream.getMonitor()) {
|
||||
@ -1200,13 +1195,15 @@ public class SyncStreams {
|
||||
* stream.forEach(System.out::println); // Should never throw a ConcurrentModificationException
|
||||
* </pre>
|
||||
*
|
||||
* @param stream the stream to wrap.
|
||||
* @param monitor the object that the stream will use for synchronization.
|
||||
* When {@code null}, the stream
|
||||
* will synchronize on itself.
|
||||
* @param stream
|
||||
* the stream to wrap.
|
||||
* @param monitor
|
||||
* the object that the stream will use for synchronization. When
|
||||
* {@code null}, the stream will synchronize on itself.
|
||||
* @return a {@link SyncLongStream} synchronized on {@code monitor} and
|
||||
* backed by {@code stream}.
|
||||
* @throws NullPointerException if {@code stream == null}.
|
||||
* @throws NullPointerException
|
||||
* if {@code stream == null}.
|
||||
*/
|
||||
public static SyncLongStream synchronizedStream(LongStream stream, Object monitor) {
|
||||
Objects.requireNonNull(stream, "stream cannot be null");
|
||||
@ -1214,22 +1211,19 @@ 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">
|
||||
* terminal operations</a> acquire the provided monitor's lock before
|
||||
* execution. Intermediate operations
|
||||
* return streams that are also synchronized on the same object. The created
|
||||
* stream will behave identically
|
||||
* to the provided stream in all other aspects. Use this to synchronize
|
||||
* access to stream's source.
|
||||
* execution. Intermediate operations return streams that are also
|
||||
* synchronized on the same object. The created stream will behave
|
||||
* identically to the provided stream in all other aspects. Use this to
|
||||
* synchronize access to stream's source.
|
||||
* <p>
|
||||
* <i>The returned {@code DoubleStream}'s {@link DoubleStream#iterator()
|
||||
* iterator()} and
|
||||
* {@link DoubleStream#spliterator() spliterator()} methods return regular
|
||||
* non-synchronized iterators and
|
||||
* spliterators respectively</i>. It is the user's responsibility to avoid
|
||||
* concurrency issues:
|
||||
* iterator()} and {@link DoubleStream#spliterator() spliterator()} methods
|
||||
* return regular non-synchronized iterators and spliterators
|
||||
* respectively</i>. It is the user's responsibility to avoid concurrency
|
||||
* issues:
|
||||
*
|
||||
* <pre>
|
||||
* synchronized (stream.getMonitor()) {
|
||||
@ -1248,13 +1242,15 @@ public class SyncStreams {
|
||||
* stream.forEach(System.out::println); // Should never throw a ConcurrentModificationException
|
||||
* </pre>
|
||||
*
|
||||
* @param stream the stream to wrap.
|
||||
* @param monitor the object that the stream will use for synchronization.
|
||||
* When {@code null}, the stream
|
||||
* will synchronize on itself.
|
||||
* @param stream
|
||||
* the stream to wrap.
|
||||
* @param monitor
|
||||
* the object that the stream will use for synchronization. When
|
||||
* {@code null}, the stream will synchronize on itself.
|
||||
* @return a {@link SyncDoubleStream} synchronized on {@code monitor} and
|
||||
* backed by {@code stream}.
|
||||
* @throws NullPointerException if {@code stream == null}.
|
||||
* @throws NullPointerException
|
||||
* if {@code stream == null}.
|
||||
*/
|
||||
public static SyncDoubleStream synchronizedStream(DoubleStream stream, Object monitor) {
|
||||
Objects.requireNonNull(stream, "stream cannot be null");
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil;
|
||||
|
||||
public class SyntaxException extends Exception {
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.chars;
|
||||
|
||||
import java.text.CharacterIterator;
|
||||
@ -108,7 +108,7 @@ public class CharArrayIterator implements CharacterIterator {
|
||||
return pos;
|
||||
}
|
||||
|
||||
// @SuppressWarnings("all") Just STFU, this _is_ terrific
|
||||
// @SuppressWarnings("all") Just STFU, this _is_ terrific
|
||||
|
||||
// SonarLint: "clone" should not be overridden (java:S2975)
|
||||
// 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
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
package ru.windcorp.jputil.chars;
|
||||
|
||||
import java.util.function.IntConsumer;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.chars;
|
||||
|
||||
import java.util.Objects;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.chars;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.chars;
|
||||
|
||||
import java.util.function.IntSupplier;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.chars;
|
||||
|
||||
public class EscapeException extends Exception {
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.chars;
|
||||
|
||||
import java.text.CharacterIterator;
|
||||
@ -103,14 +103,8 @@ public class Escaper {
|
||||
|
||||
}
|
||||
|
||||
public static final Escaper JAVA = new Escaper(
|
||||
'\\',
|
||||
'u',
|
||||
"tbnrf'\"".toCharArray(),
|
||||
"\t\b\n\r\f\'\"".toCharArray(),
|
||||
true,
|
||||
true
|
||||
);
|
||||
public static final Escaper JAVA = new Escaper('\\', 'u', "tbnrf'\"".toCharArray(), "\t\b\n\r\f\'\"".toCharArray(),
|
||||
true, true);
|
||||
|
||||
private final char escapeChar;
|
||||
private final char unicodeEscapeChar;
|
||||
@ -120,14 +114,8 @@ public class Escaper {
|
||||
private final boolean preferUnicode;
|
||||
private final boolean strict;
|
||||
|
||||
protected Escaper(
|
||||
char escapeChar,
|
||||
char unicodeEscapeChar,
|
||||
char[] safes,
|
||||
char[] unsafes,
|
||||
boolean preferUnicode,
|
||||
boolean strict
|
||||
) {
|
||||
protected Escaper(char escapeChar, char unicodeEscapeChar, char[] safes, char[] unsafes, boolean preferUnicode,
|
||||
boolean strict) {
|
||||
this.escapeChar = escapeChar;
|
||||
this.unicodeEscapeChar = unicodeEscapeChar;
|
||||
this.safes = safes;
|
||||
@ -152,8 +140,7 @@ public class Escaper {
|
||||
for (char c : unsafes) {
|
||||
if (c == escapeChar)
|
||||
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)
|
||||
throw new IllegalArgumentException("Unsafe characters contain Unicode escape chatacter");
|
||||
}
|
||||
@ -173,11 +160,7 @@ public class Escaper {
|
||||
end = Integer.MAX_VALUE;
|
||||
else
|
||||
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);
|
||||
}
|
||||
|
||||
@ -225,11 +208,7 @@ public class Escaper {
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
@ -257,11 +236,7 @@ public class Escaper {
|
||||
end = Integer.MAX_VALUE;
|
||||
else
|
||||
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));
|
||||
}
|
||||
}
|
||||
@ -282,10 +257,8 @@ public class Escaper {
|
||||
|
||||
if (src.current() == unicodeEscapeChar) {
|
||||
src.next();
|
||||
return (char) (hexValue(src.consume()) << (4 * 3) |
|
||||
hexValue(src.consume()) << (4 * 2) |
|
||||
hexValue(src.consume()) << (4 * 1) |
|
||||
hexValue(src.consume()) << (4 * 0));
|
||||
return (char) (hexValue(src.consume()) << (4 * 3) | hexValue(src.consume()) << (4 * 2)
|
||||
| hexValue(src.consume()) << (4 * 1) | hexValue(src.consume()) << (4 * 0));
|
||||
}
|
||||
|
||||
int index = ArrayUtil.firstIndexOf(safes, src.current());
|
||||
@ -315,11 +288,7 @@ public class Escaper {
|
||||
|
||||
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);
|
||||
result++;
|
||||
}
|
||||
@ -328,11 +297,7 @@ public class Escaper {
|
||||
}
|
||||
|
||||
public void skipOneSequence(CharReader src) {
|
||||
if (
|
||||
src.current() == escapeChar
|
||||
&&
|
||||
src.next() == unicodeEscapeChar
|
||||
) {
|
||||
if (src.current() == escapeChar && src.next() == unicodeEscapeChar) {
|
||||
src.advance(4);
|
||||
}
|
||||
src.next();
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.chars;
|
||||
|
||||
import java.text.CharacterIterator;
|
||||
@ -86,7 +86,7 @@ public class FancyCharacterIterator implements CharacterIterator {
|
||||
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)
|
||||
// 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
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
package ru.windcorp.jputil.chars;
|
||||
|
||||
public class IndentedStringBuilder {
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.chars;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -41,13 +41,8 @@ public class StringUtil {
|
||||
private static final String EMPTY_PLACEHOLDER = "[empty]";
|
||||
private static final String DEFAULT_SEPARATOR = "; ";
|
||||
|
||||
public static <T> String arrayToString(
|
||||
T[] array,
|
||||
String separator,
|
||||
String empty,
|
||||
String nullPlaceholder,
|
||||
String nullArray
|
||||
) {
|
||||
public static <T> String arrayToString(T[] array, String separator, String empty, String nullPlaceholder,
|
||||
String nullArray) {
|
||||
|
||||
if (separator == null) {
|
||||
throw new IllegalArgumentException(new NullPointerException());
|
||||
@ -79,13 +74,8 @@ public class StringUtil {
|
||||
return arrayToString(array, DEFAULT_SEPARATOR);
|
||||
}
|
||||
|
||||
public static String iteratorToString(
|
||||
Iterator<?> iterator,
|
||||
String separator,
|
||||
String empty,
|
||||
String nullPlaceholder,
|
||||
String nullIterator
|
||||
) {
|
||||
public static String iteratorToString(Iterator<?> iterator, String separator, String empty, String nullPlaceholder,
|
||||
String nullIterator) {
|
||||
|
||||
if (separator == null) {
|
||||
throw new IllegalArgumentException(new NullPointerException());
|
||||
@ -119,13 +109,8 @@ public class StringUtil {
|
||||
return iteratorToString(iterator, DEFAULT_SEPARATOR);
|
||||
}
|
||||
|
||||
public static String iterableToString(
|
||||
Iterable<?> iterable,
|
||||
String separator,
|
||||
String empty,
|
||||
String nullPlaceholder,
|
||||
String nullIterable
|
||||
) {
|
||||
public static String iterableToString(Iterable<?> iterable, String separator, String empty, String nullPlaceholder,
|
||||
String nullIterable) {
|
||||
|
||||
if (separator == null) {
|
||||
throw new IllegalArgumentException(new NullPointerException());
|
||||
@ -146,14 +131,8 @@ public class StringUtil {
|
||||
return iterableToString(iterable, DEFAULT_SEPARATOR);
|
||||
}
|
||||
|
||||
public static <T> String supplierToString(
|
||||
IntFunction<T> supplier,
|
||||
int length,
|
||||
String separator,
|
||||
String empty,
|
||||
String nullPlaceholder,
|
||||
String nullSupplier
|
||||
) {
|
||||
public static <T> String supplierToString(IntFunction<T> supplier, int length, String separator, String empty,
|
||||
String nullPlaceholder, String nullSupplier) {
|
||||
|
||||
if (separator == null)
|
||||
throw new IllegalArgumentException(new NullPointerException());
|
||||
@ -163,28 +142,15 @@ public class StringUtil {
|
||||
return empty;
|
||||
|
||||
if (length > 0) {
|
||||
return supplierToStringExactly(
|
||||
supplier,
|
||||
length,
|
||||
separator,
|
||||
nullPlaceholder
|
||||
);
|
||||
return supplierToStringExactly(supplier, length, separator, nullPlaceholder);
|
||||
} else {
|
||||
return supplierToStringUntilNull(
|
||||
supplier,
|
||||
separator,
|
||||
empty
|
||||
);
|
||||
return supplierToStringUntilNull(supplier, separator, empty);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static <T> String supplierToStringExactly(
|
||||
IntFunction<T> supplier,
|
||||
int length,
|
||||
String separator,
|
||||
String nullPlaceholder
|
||||
) {
|
||||
private static <T> String supplierToStringExactly(IntFunction<T> supplier, int length, String separator,
|
||||
String nullPlaceholder) {
|
||||
T element = supplier.apply(0);
|
||||
|
||||
StringBuilder sb = new StringBuilder(element == null ? nullPlaceholder : element.toString());
|
||||
@ -198,11 +164,7 @@ public class StringUtil {
|
||||
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);
|
||||
|
||||
if (element == null) {
|
||||
@ -366,11 +328,7 @@ public class StringUtil {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
charLoop: for (char c : src.toCharArray()) {
|
||||
if (
|
||||
(resultIndex + 1) < arrayLength
|
||||
&&
|
||||
test.test(c)
|
||||
) {
|
||||
if ((resultIndex + 1) < arrayLength && test.test(c)) {
|
||||
result[resultIndex] = resetStringBuilder(sb);
|
||||
++resultIndex;
|
||||
continue charLoop;
|
||||
@ -389,17 +347,17 @@ public class StringUtil {
|
||||
* index.
|
||||
* <p>
|
||||
* Indices {@code 0} and {@code src.length() - 1} produce {@code str}
|
||||
* excluding
|
||||
* the specified character and {@code ""}.
|
||||
* excluding the specified character and {@code ""}.
|
||||
* <p>
|
||||
*
|
||||
* @param src the String to split
|
||||
* @param at index to split at
|
||||
* @throws IllegalArgumentException if the index is out of bounds for
|
||||
* {@code src}
|
||||
* @param src
|
||||
* the String to split
|
||||
* @param at
|
||||
* index to split at
|
||||
* @throws IllegalArgumentException
|
||||
* if the index is out of bounds for {@code src}
|
||||
* @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) {
|
||||
Objects.requireNonNull(src, "src");
|
||||
@ -416,10 +374,7 @@ public class StringUtil {
|
||||
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) };
|
||||
}
|
||||
|
||||
/**
|
||||
@ -427,8 +382,7 @@ public class StringUtil {
|
||||
* indices.
|
||||
* <p>
|
||||
* 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>
|
||||
* Examples:
|
||||
*
|
||||
@ -439,13 +393,14 @@ public class StringUtil {
|
||||
* splitAt("a.b", 1, 1, 1) -> {"a", "", "", "b"}
|
||||
* </pre>
|
||||
*
|
||||
* @param src the String to split
|
||||
* @param at indices to split at, in any order
|
||||
* @throws IllegalArgumentException if some index is out of bounds for
|
||||
* {@code src}
|
||||
* @param src
|
||||
* the String to split
|
||||
* @param at
|
||||
* indices to split at, in any order
|
||||
* @throws IllegalArgumentException
|
||||
* if some index is out of bounds for {@code src}
|
||||
* @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) {
|
||||
Objects.requireNonNull(src, "src");
|
||||
@ -553,10 +508,8 @@ public class StringUtil {
|
||||
}
|
||||
|
||||
if (endPos < beginPos) {
|
||||
throw new IllegalArgumentException(
|
||||
"endPos must be greater than or equal to beginPos (endPos="
|
||||
+ endPos + ", beginPos=" + beginPos + ")"
|
||||
);
|
||||
throw new IllegalArgumentException("endPos must be greater than or equal to beginPos (endPos=" + endPos
|
||||
+ ", beginPos=" + beginPos + ")");
|
||||
}
|
||||
|
||||
if (endPos >= Math.min(a.length, b.length)) {
|
||||
@ -592,8 +545,7 @@ public class StringUtil {
|
||||
|
||||
/**
|
||||
* 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>
|
||||
* Examples:
|
||||
* <p>
|
||||
@ -630,10 +582,12 @@ public class StringUtil {
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
* @param src - the array to search in.
|
||||
* @param target - the character to search for.
|
||||
* @param skip - the amount of <code>target</code> characters to be
|
||||
* skipped.
|
||||
* @param src
|
||||
* - the array to search in.
|
||||
* @param target
|
||||
* - the character to search for.
|
||||
* @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>
|
||||
* character or -1, if none found.
|
||||
* @see StringUtil#indexFromEnd(char[], char, int)
|
||||
@ -653,8 +607,7 @@ public class StringUtil {
|
||||
|
||||
/**
|
||||
* 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>.
|
||||
* <p>
|
||||
* Examples:
|
||||
@ -692,13 +645,15 @@ public class StringUtil {
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
* @param src - the array to search in.
|
||||
* @param target - the character to search for.
|
||||
* @param skip - the amount of <code>target</code> characters to be
|
||||
* skipped.
|
||||
* @param src
|
||||
* - the array to search in.
|
||||
* @param target
|
||||
* - the character to search for.
|
||||
* @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>character
|
||||
* from the end of the array or -1, if none found.
|
||||
* <code>target</code>character from the end of the array or -1, if
|
||||
* none found.
|
||||
* @see StringUtil#indexFromBeginning(char[], char, int)
|
||||
*/
|
||||
public static int indexFromEnd(char[] src, char target, int skip) {
|
||||
@ -873,12 +828,8 @@ public class StringUtil {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void buildCombinations(
|
||||
StringBuilder sb,
|
||||
Collection<String> result,
|
||||
Iterable<String>[] parts,
|
||||
int index
|
||||
) {
|
||||
private static void buildCombinations(StringBuilder sb, Collection<String> result, Iterable<String>[] parts,
|
||||
int index) {
|
||||
if (index >= parts.length) {
|
||||
result.add(sb.toString());
|
||||
} else {
|
||||
@ -904,13 +855,8 @@ public class StringUtil {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void buildCombinations(
|
||||
StringBuilder sb,
|
||||
String[] result,
|
||||
int[] resultIndex,
|
||||
String[][] parts,
|
||||
int index
|
||||
) {
|
||||
private static void buildCombinations(StringBuilder sb, String[] result, int[] resultIndex, String[][] parts,
|
||||
int index) {
|
||||
if (index >= parts.length) {
|
||||
result[resultIndex[0]++] = sb.toString();
|
||||
} else {
|
||||
@ -985,10 +931,7 @@ public class StringUtil {
|
||||
}
|
||||
|
||||
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) {
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.chars;
|
||||
|
||||
public class UncheckedEscapeException extends RuntimeException {
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.chars;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.chars.reader;
|
||||
|
||||
/**
|
||||
@ -27,10 +27,9 @@ public abstract class AbstractCharReader implements CharReader {
|
||||
|
||||
/**
|
||||
* Current position of this CharReader. The reader maps its input to
|
||||
* positions starting from 0.
|
||||
* Positions that are negative or lower than 0 are invalid.
|
||||
* {@link #current()}
|
||||
* will throw an exception if position is invalid.
|
||||
* positions starting from 0. Positions that are negative or lower than 0
|
||||
* are invalid. {@link #current()} will throw an exception if position is
|
||||
* invalid.
|
||||
*/
|
||||
protected int position = 0;
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.chars.reader;
|
||||
|
||||
import java.util.Objects;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.chars.reader;
|
||||
|
||||
/**
|
||||
@ -51,9 +51,12 @@ public abstract class BufferedCharReader extends AbstractCharReader {
|
||||
/**
|
||||
* Acquires next characters and stores them in the array.
|
||||
*
|
||||
* @param buffer the output array
|
||||
* @param offset index of the first character
|
||||
* @param length maximum amount of characters to be pulled
|
||||
* @param buffer
|
||||
* the output array
|
||||
* @param offset
|
||||
* index of the first character
|
||||
* @param length
|
||||
* maximum amount of characters to be pulled
|
||||
* @return the amount of characters actually pulled
|
||||
*/
|
||||
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
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
package ru.windcorp.jputil.chars.reader;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -30,7 +30,7 @@ import ru.windcorp.jputil.chars.Escaper;
|
||||
*/
|
||||
|
||||
// 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")
|
||||
|
||||
public interface CharReader {
|
||||
@ -179,8 +179,7 @@ public interface CharReader {
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.chars.reader;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.chars.reader;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.chars.reader;
|
||||
|
||||
import java.util.Objects;
|
||||
@ -38,8 +38,7 @@ public class StringCharReader extends AbstractCharReader {
|
||||
int end = offset + length;
|
||||
if (end > str.length() || offset < 0)
|
||||
throw new IllegalArgumentException(
|
||||
"String contains [0; " + str.length() + "), requested [" + offset + "; " + end + ")"
|
||||
);
|
||||
"String contains [0; " + str.length() + "), requested [" + offset + "; " + end + ")");
|
||||
|
||||
this.offset = offset;
|
||||
this.length = length;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.functions;
|
||||
|
||||
@FunctionalInterface
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.functions;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
@ -44,9 +44,16 @@ public interface ThrowingBiConsumer<T, U, E extends Exception> {
|
||||
}
|
||||
|
||||
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> second
|
||||
) {
|
||||
ThrowingBiConsumer<? super T, ? super U, ? extends E> first,
|
||||
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) -> {
|
||||
first.accept(t, u);
|
||||
second.accept(t, u);
|
||||
@ -54,19 +61,7 @@ public interface ThrowingBiConsumer<T, U, E extends Exception> {
|
||||
}
|
||||
|
||||
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) -> {
|
||||
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
|
||||
) {
|
||||
ThrowingBiConsumer<? super T, ? super U, E> first, BiConsumer<? super T, ? super U> second) {
|
||||
return (t, u) -> {
|
||||
first.accept(t, u);
|
||||
second.accept(t, u);
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.functions;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
@ -39,30 +39,24 @@ public interface ThrowingConsumer<T, E extends Exception> {
|
||||
};
|
||||
}
|
||||
|
||||
public static <T, E extends Exception> ThrowingConsumer<T, E> concat(
|
||||
ThrowingConsumer<? super T, ? extends E> first,
|
||||
ThrowingConsumer<? super T, ? extends E> second
|
||||
) {
|
||||
public static <T, E extends Exception> ThrowingConsumer<T, E> concat(ThrowingConsumer<? super T, ? extends E> first,
|
||||
ThrowingConsumer<? super T, ? extends E> second) {
|
||||
return t -> {
|
||||
first.accept(t);
|
||||
second.accept(t);
|
||||
};
|
||||
}
|
||||
|
||||
public static <T, E extends Exception> ThrowingConsumer<T, E> concat(
|
||||
Consumer<? super T> first,
|
||||
ThrowingConsumer<? super T, ? extends E> second
|
||||
) {
|
||||
public static <T, E extends Exception> ThrowingConsumer<T, E> concat(Consumer<? super T> first,
|
||||
ThrowingConsumer<? super T, ? extends E> second) {
|
||||
return t -> {
|
||||
first.accept(t);
|
||||
second.accept(t);
|
||||
};
|
||||
}
|
||||
|
||||
public static <T, E extends Exception> ThrowingConsumer<T, E> concat(
|
||||
ThrowingConsumer<? super T, ? extends E> first,
|
||||
Consumer<? super T> second
|
||||
) {
|
||||
public static <T, E extends Exception> ThrowingConsumer<T, E> concat(ThrowingConsumer<? super T, ? extends E> first,
|
||||
Consumer<? super T> second) {
|
||||
return t -> {
|
||||
first.accept(t);
|
||||
second.accept(t);
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.functions;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
@ -28,10 +28,8 @@ public interface ThrowingFunction<T, R, E extends Exception> {
|
||||
R apply(T t) throws E;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
default Function<T, R> withHandler(
|
||||
BiConsumer<? super T, ? super E> handler,
|
||||
Function<? super T, ? extends R> value
|
||||
) {
|
||||
default Function<T, R> withHandler(BiConsumer<? super T, ? super E> handler,
|
||||
Function<? super T, ? extends R> value) {
|
||||
return t -> {
|
||||
try {
|
||||
return apply(t);
|
||||
@ -58,23 +56,18 @@ public interface ThrowingFunction<T, R, E extends Exception> {
|
||||
}
|
||||
|
||||
public static <T, R, I, E extends Exception> ThrowingFunction<T, R, E> compose(
|
||||
ThrowingFunction<? super T, I, ? extends E> first,
|
||||
ThrowingFunction<? super I, ? extends R, ? extends E> second
|
||||
) {
|
||||
ThrowingFunction<? super T, I, ? extends E> first,
|
||||
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));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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
|
||||
) {
|
||||
ThrowingFunction<? super T, I, E> first, Function<? super I, ? extends R> second) {
|
||||
return t -> second.apply(first.apply(t));
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.functions;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
@ -38,10 +38,8 @@ public interface ThrowingRunnable<E extends Exception> {
|
||||
};
|
||||
}
|
||||
|
||||
public static <E extends Exception> ThrowingRunnable<E> concat(
|
||||
ThrowingRunnable<? extends E> first,
|
||||
ThrowingRunnable<? extends E> second
|
||||
) {
|
||||
public static <E extends Exception> ThrowingRunnable<E> concat(ThrowingRunnable<? extends E> first,
|
||||
ThrowingRunnable<? extends E> second) {
|
||||
return () -> {
|
||||
first.run();
|
||||
second.run();
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.functions;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.iterators;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.iterators;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.iterators;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.iterators;
|
||||
|
||||
import java.util.Iterator;
|
||||
@ -49,10 +49,8 @@ public class RangeIterator<E> implements Iterator<E> {
|
||||
public E next() {
|
||||
update();
|
||||
if (nextIndex >= from + amount) {
|
||||
throw new NoSuchElementException(
|
||||
"RangeIterator about to retrieve element " + nextIndex
|
||||
+ " which exceeds upper boundary " + (from + amount)
|
||||
);
|
||||
throw new NoSuchElementException("RangeIterator about to retrieve element " + nextIndex
|
||||
+ " which exceeds upper boundary " + (from + amount));
|
||||
}
|
||||
|
||||
E result = parent.next();
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.iterators;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.selectors;
|
||||
|
||||
public abstract class AbstractSelectorOperator implements SelectorOperator {
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.selectors;
|
||||
|
||||
import ru.windcorp.jputil.SyntaxException;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.selectors;
|
||||
|
||||
import ru.windcorp.jputil.SyntaxException;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.selectors;
|
||||
|
||||
import java.util.Deque;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.selectors;
|
||||
|
||||
import java.util.Deque;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.selectors;
|
||||
|
||||
import java.util.Deque;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.selectors;
|
||||
|
||||
import java.util.Deque;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.selectors;
|
||||
|
||||
import java.util.Deque;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.selectors;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.selectors;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.selectors;
|
||||
|
||||
import java.util.Deque;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.jputil.selectors;
|
||||
|
||||
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<SelectorOperator> operators = Collections
|
||||
.synchronizedCollection(new ArrayList<SelectorOperator>());
|
||||
.synchronizedCollection(new ArrayList<SelectorOperator>());
|
||||
|
||||
private String stackPrefix = null;
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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;
|
||||
|
||||
public class Progressia {
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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;
|
||||
|
||||
import ru.windcorp.progressia.common.util.crash.CrashReports;
|
||||
@ -40,6 +40,7 @@ public class ProgressiaLauncher {
|
||||
CrashReports.registerProvider(new OpenALContextProvider());
|
||||
CrashReports.registerProvider(new ArgsContextProvider());
|
||||
CrashReports.registerProvider(new LanguageContextProvider());
|
||||
CrashReports.registerProvider(new ScreenContextProvider());
|
||||
// Analyzers
|
||||
CrashReports.registerAnalyzer(new OutOfMemoryAnalyzer());
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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;
|
||||
|
||||
public interface Proxy {
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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;
|
||||
|
||||
import ru.windcorp.progressia.client.comms.DefaultClientCommsListener;
|
||||
@ -24,7 +24,7 @@ import ru.windcorp.progressia.client.graphics.world.Camera;
|
||||
import ru.windcorp.progressia.client.graphics.world.EntityAnchor;
|
||||
import ru.windcorp.progressia.client.graphics.world.LocalPlayer;
|
||||
import ru.windcorp.progressia.client.world.WorldRender;
|
||||
import ru.windcorp.progressia.common.world.WorldData;
|
||||
import ru.windcorp.progressia.common.world.DefaultWorldData;
|
||||
import ru.windcorp.progressia.common.world.entity.EntityData;
|
||||
|
||||
public class Client {
|
||||
@ -36,7 +36,7 @@ public class Client {
|
||||
|
||||
private final ServerCommsChannel comms;
|
||||
|
||||
public Client(WorldData world, ServerCommsChannel comms) {
|
||||
public Client(DefaultWorldData world, ServerCommsChannel comms) {
|
||||
this.world = new WorldRender(world, this);
|
||||
this.comms = comms;
|
||||
|
||||
@ -69,11 +69,7 @@ public class Client {
|
||||
return;
|
||||
}
|
||||
|
||||
getCamera().setAnchor(
|
||||
new EntityAnchor(
|
||||
getWorld().getEntityRenderable(entity)
|
||||
)
|
||||
);
|
||||
getCamera().setAnchor(new EntityAnchor(getWorld().getEntityRenderable(entity)));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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;
|
||||
|
||||
import ru.windcorp.progressia.Proxy;
|
||||
@ -32,6 +32,7 @@ import ru.windcorp.progressia.common.resource.ResourceManager;
|
||||
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.TestMusicPlayer;
|
||||
|
||||
public class ClientProxy implements Proxy {
|
||||
|
||||
@ -41,10 +42,8 @@ public class ClientProxy implements Proxy {
|
||||
try {
|
||||
RenderTaskQueue.waitAndInvoke(FlatRenderProgram::init);
|
||||
RenderTaskQueue.waitAndInvoke(WorldRenderProgram::init);
|
||||
RenderTaskQueue.waitAndInvoke(
|
||||
() -> Typefaces
|
||||
.setDefault(GNUUnifontLoader.load(ResourceManager.getResource("assets/unifont-13.0.03.hex.gz")))
|
||||
);
|
||||
RenderTaskQueue.waitAndInvoke(() -> Typefaces
|
||||
.setDefault(GNUUnifontLoader.load(ResourceManager.getResource("assets/unifont-13.0.03.hex.gz"))));
|
||||
} catch (InterruptedException e) {
|
||||
throw CrashReports.report(e, "ClientProxy failed");
|
||||
}
|
||||
@ -59,6 +58,8 @@ public class ClientProxy implements Proxy {
|
||||
|
||||
ServerState.startServer();
|
||||
ClientState.connectToLocalServer();
|
||||
|
||||
TestMusicPlayer.start();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,13 +15,13 @@
|
||||
* 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;
|
||||
|
||||
import ru.windcorp.progressia.client.comms.localhost.LocalServerCommsChannel;
|
||||
import ru.windcorp.progressia.client.graphics.GUI;
|
||||
import ru.windcorp.progressia.client.graphics.world.LayerWorld;
|
||||
import ru.windcorp.progressia.common.world.WorldData;
|
||||
import ru.windcorp.progressia.common.world.DefaultWorldData;
|
||||
import ru.windcorp.progressia.server.ServerState;
|
||||
import ru.windcorp.progressia.test.LayerAbout;
|
||||
import ru.windcorp.progressia.test.LayerTestUI;
|
||||
@ -41,11 +41,9 @@ public class ClientState {
|
||||
|
||||
public static void connectToLocalServer() {
|
||||
|
||||
WorldData world = new WorldData();
|
||||
DefaultWorldData world = new DefaultWorldData();
|
||||
|
||||
LocalServerCommsChannel channel = new LocalServerCommsChannel(
|
||||
ServerState.getInstance()
|
||||
);
|
||||
LocalServerCommsChannel channel = new LocalServerCommsChannel(ServerState.getInstance());
|
||||
|
||||
Client client = new Client(world, channel);
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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;
|
||||
|
||||
import ru.windcorp.progressia.ProgressiaLauncher;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.audio;
|
||||
|
||||
public enum AudioFormat {
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.audio;
|
||||
|
||||
import org.lwjgl.openal.*;
|
||||
@ -23,6 +23,7 @@ import ru.windcorp.progressia.client.audio.backend.AudioReader;
|
||||
import ru.windcorp.progressia.client.audio.backend.Listener;
|
||||
import ru.windcorp.progressia.client.audio.backend.SoundType;
|
||||
import ru.windcorp.progressia.client.audio.backend.Speaker;
|
||||
import ru.windcorp.progressia.common.resource.Resource;
|
||||
|
||||
import static org.lwjgl.openal.AL11.*;
|
||||
import static org.lwjgl.openal.ALC10.*;
|
||||
@ -40,13 +41,9 @@ public class AudioManager {
|
||||
|
||||
private static List<Speaker> soundSpeakers = new ArrayList<>(SOUNDS_NUM);
|
||||
private static Speaker musicSpeaker;
|
||||
private static ArrayList<SoundType> soundsBuffer = new ArrayList<>();
|
||||
|
||||
public static void initAL() {
|
||||
String defaultDeviceName = alcGetString(
|
||||
0,
|
||||
ALC_DEFAULT_DEVICE_SPECIFIER
|
||||
);
|
||||
String defaultDeviceName = alcGetString(0, ALC_DEFAULT_DEVICE_SPECIFIER);
|
||||
|
||||
device = alcOpenDevice(defaultDeviceName);
|
||||
|
||||
@ -75,38 +72,23 @@ public class AudioManager {
|
||||
lastSoundIndex = 0;
|
||||
}
|
||||
speaker = soundSpeakers.get(lastSoundIndex);
|
||||
} while (
|
||||
speaker.getState()
|
||||
.equals(Speaker.State.PLAYING_LOOP)
|
||||
);
|
||||
} while (speaker.getState().equals(Speaker.State.PLAYING_LOOP));
|
||||
return speaker;
|
||||
}
|
||||
|
||||
private static SoundType findSoundType(String soundID) throws Exception {
|
||||
for (SoundType s : soundsBuffer) {
|
||||
if (s.getId().equals(soundID)) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
throw new Exception(
|
||||
"ERROR: The selected sound is not loaded or" +
|
||||
" not exists"
|
||||
);
|
||||
}
|
||||
|
||||
public static Speaker initSpeaker(String soundID) {
|
||||
public static Speaker initSpeaker(SoundType st) {
|
||||
Speaker speaker = getLastSpeaker();
|
||||
try {
|
||||
findSoundType(soundID).initSpeaker(speaker);
|
||||
st.initSpeaker(speaker);
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
return speaker;
|
||||
}
|
||||
|
||||
public static Speaker initMusicSpeaker(String soundID) {
|
||||
public static Speaker initMusicSpeaker(SoundType st) {
|
||||
try {
|
||||
findSoundType(soundID).initSpeaker(musicSpeaker);
|
||||
st.initSpeaker(musicSpeaker);
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
@ -120,11 +102,11 @@ public class AudioManager {
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadSound(String path, String id, AudioFormat format) {
|
||||
public static void loadSound(Resource resource, String id, AudioFormat format) {
|
||||
if (format == AudioFormat.MONO) {
|
||||
soundsBuffer.add(AudioReader.readAsMono(path, id));
|
||||
AudioRegistry.getInstance().register(AudioReader.readAsMono(resource, id));
|
||||
} else {
|
||||
soundsBuffer.add(AudioReader.readAsStereo(path, id));
|
||||
AudioRegistry.getInstance().register(AudioReader.readAsStereo(resource, id));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.audio;
|
||||
|
||||
import ru.windcorp.progressia.client.audio.backend.SoundType;
|
||||
import ru.windcorp.progressia.common.util.namespaces.NamespacedInstanceRegistry;
|
||||
|
||||
public class AudioRegistry extends NamespacedInstanceRegistry<SoundType> {
|
||||
|
||||
private static final AudioRegistry INSTANCE = new AudioRegistry();
|
||||
|
||||
/**
|
||||
* @return the instance
|
||||
*/
|
||||
public static AudioRegistry getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
}
|
@ -15,9 +15,11 @@
|
||||
* 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.audio;
|
||||
|
||||
import ru.windcorp.progressia.common.resource.ResourceManager;
|
||||
|
||||
public class AudioSystem {
|
||||
static public void initialize() {
|
||||
AudioManager.initAL();
|
||||
@ -27,10 +29,7 @@ public class AudioSystem {
|
||||
}
|
||||
|
||||
static void loadAudioData() {
|
||||
AudioManager.loadSound(
|
||||
"assets/sounds/block_destroy_clap.ogg",
|
||||
"Progressia:BlockDestroy",
|
||||
AudioFormat.MONO
|
||||
);
|
||||
AudioManager.loadSound(ResourceManager.getResource("assets/sounds/block_destroy_clap.ogg"),
|
||||
"Progressia:BlockDestroy", AudioFormat.MONO);
|
||||
}
|
||||
}
|
||||
|
@ -15,76 +15,38 @@
|
||||
* 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.audio;
|
||||
|
||||
import glm.vec._3.Vec3;
|
||||
import ru.windcorp.progressia.client.audio.backend.SoundType;
|
||||
import ru.windcorp.progressia.client.audio.backend.Speaker;
|
||||
import ru.windcorp.progressia.common.util.namespaces.Namespaced;
|
||||
|
||||
public class Music extends Namespaced {
|
||||
private Vec3 position = new Vec3();
|
||||
private Vec3 velocity = new Vec3();
|
||||
private float pitch = 1.0f;
|
||||
private float gain = 1.0f;
|
||||
public class Music extends Sound {
|
||||
|
||||
public Music(SoundType soundType, int timeLength, float pitch, float gain) {
|
||||
super(soundType, timeLength, new Vec3(), new Vec3(), pitch, gain);
|
||||
}
|
||||
|
||||
public Music(SoundType soundType) {
|
||||
super(soundType);
|
||||
}
|
||||
|
||||
public Music(String id, int timeLength, float pitch, float gain) {
|
||||
super(id, timeLength, new Vec3(), new Vec3(), pitch, gain);
|
||||
}
|
||||
|
||||
public Music(String id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public Music(
|
||||
String id,
|
||||
Vec3 position,
|
||||
Vec3 velocity,
|
||||
float pitch,
|
||||
float gain
|
||||
) {
|
||||
this(id);
|
||||
this.position = position;
|
||||
this.velocity = velocity;
|
||||
this.pitch = pitch;
|
||||
this.gain = gain;
|
||||
@Override
|
||||
protected Speaker initSpeaker() {
|
||||
return AudioManager.initMusicSpeaker(soundType);
|
||||
}
|
||||
|
||||
public void play(boolean loop) {
|
||||
Speaker speaker = AudioManager.initMusicSpeaker(this.getId());
|
||||
speaker.setGain(gain);
|
||||
speaker.setPitch(pitch);
|
||||
speaker.setPosition(position);
|
||||
speaker.setVelocity(velocity);
|
||||
|
||||
if (loop) {
|
||||
speaker.playLoop();
|
||||
} else {
|
||||
speaker.play();
|
||||
}
|
||||
}
|
||||
|
||||
public void setGain(float gain) {
|
||||
this.gain = gain;
|
||||
}
|
||||
|
||||
public void setPitch(float pitch) {
|
||||
this.pitch = pitch;
|
||||
}
|
||||
|
||||
public void setVelocity(Vec3 velocity) {
|
||||
this.velocity = velocity;
|
||||
}
|
||||
|
||||
public Vec3 getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public float getGain() {
|
||||
return gain;
|
||||
}
|
||||
|
||||
public Vec3 getVelocity() {
|
||||
return velocity;
|
||||
}
|
||||
|
||||
public float getPitch() {
|
||||
return pitch;
|
||||
@Override
|
||||
public void setPosition(Vec3 position) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
@ -15,32 +15,32 @@
|
||||
* 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.audio;
|
||||
|
||||
import glm.vec._3.Vec3;
|
||||
import ru.windcorp.progressia.client.audio.backend.SoundType;
|
||||
import ru.windcorp.progressia.client.audio.backend.Speaker;
|
||||
import ru.windcorp.progressia.common.util.namespaces.Namespaced;
|
||||
|
||||
public class SoundEffect
|
||||
extends Namespaced {
|
||||
public class Sound {
|
||||
|
||||
private Vec3 position = new Vec3();
|
||||
private Vec3 velocity = new Vec3();
|
||||
private float pitch = 1.0f;
|
||||
private float gain = 1.0f;
|
||||
protected Vec3 position = new Vec3(0f, 0f, 0f);
|
||||
protected Vec3 velocity = new Vec3(0f, 0f, 0f);
|
||||
protected float pitch = 1.0f;
|
||||
protected float gain = 1.0f;
|
||||
protected int timeLength = 0;
|
||||
|
||||
public SoundEffect(String id) {
|
||||
super(id);
|
||||
protected SoundType soundType;
|
||||
|
||||
public Sound(SoundType soundType) {
|
||||
this.soundType = soundType;
|
||||
}
|
||||
|
||||
public SoundEffect(
|
||||
String id,
|
||||
Vec3 position,
|
||||
Vec3 velocity,
|
||||
float pitch,
|
||||
float gain
|
||||
) {
|
||||
public Sound(String id) {
|
||||
this(AudioRegistry.getInstance().get(id));
|
||||
}
|
||||
|
||||
public Sound(String id, int timeLength, Vec3 position, Vec3 velocity, float pitch, float gain) {
|
||||
this(id);
|
||||
this.position = position;
|
||||
this.velocity = velocity;
|
||||
@ -48,8 +48,20 @@ public class SoundEffect
|
||||
this.gain = gain;
|
||||
}
|
||||
|
||||
public Sound(SoundType soundType, int timeLength, Vec3 position, Vec3 velocity, float pitch, float gain) {
|
||||
this(soundType);
|
||||
this.position = position;
|
||||
this.velocity = velocity;
|
||||
this.pitch = pitch;
|
||||
this.gain = gain;
|
||||
}
|
||||
|
||||
protected Speaker initSpeaker() {
|
||||
return AudioManager.initSpeaker(soundType);
|
||||
}
|
||||
|
||||
public void play(boolean loop) {
|
||||
Speaker speaker = AudioManager.initSpeaker(this.getId());
|
||||
Speaker speaker = initSpeaker();
|
||||
speaker.setGain(gain);
|
||||
speaker.setPitch(pitch);
|
||||
speaker.setPosition(position);
|
||||
@ -93,4 +105,9 @@ public class SoundEffect
|
||||
public float getPitch() {
|
||||
return pitch;
|
||||
}
|
||||
|
||||
public double getDuration() {
|
||||
return soundType.getDuration();
|
||||
}
|
||||
|
||||
}
|
@ -15,7 +15,7 @@
|
||||
* 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.audio.backend;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
@ -33,39 +33,24 @@ public class AudioReader {
|
||||
}
|
||||
|
||||
// TODO fix converting from mono-stereo
|
||||
private static SoundType readAsSpecified(String path, String id, int format) {
|
||||
private static SoundType readAsSpecified(Resource resource, String id, int format) {
|
||||
IntBuffer channelBuffer = BufferUtils.createIntBuffer(1);
|
||||
IntBuffer rateBuffer = BufferUtils.createIntBuffer(1);
|
||||
|
||||
Resource res = ResourceManager.getResource(path);
|
||||
ShortBuffer rawAudio = decodeVorbis(resource, channelBuffer, rateBuffer);
|
||||
|
||||
ShortBuffer rawAudio = decodeVorbis(res, channelBuffer, rateBuffer);
|
||||
|
||||
return new SoundType(
|
||||
id,
|
||||
rawAudio,
|
||||
format,
|
||||
rateBuffer.get(0)
|
||||
);
|
||||
return new SoundType(id, rawAudio, format, rateBuffer.get(0));
|
||||
}
|
||||
|
||||
public static SoundType readAsMono(String path, String id) {
|
||||
return readAsSpecified(path, id, AL_FORMAT_MONO16);
|
||||
public static SoundType readAsMono(Resource resource, String id) {
|
||||
return readAsSpecified(resource, id, AL_FORMAT_MONO16);
|
||||
}
|
||||
|
||||
public static SoundType readAsStereo(String path, String id) {
|
||||
return readAsSpecified(path, id, AL_FORMAT_STEREO16);
|
||||
public static SoundType readAsStereo(Resource resource, String id) {
|
||||
return readAsSpecified(resource, id, AL_FORMAT_STEREO16);
|
||||
}
|
||||
|
||||
private static ShortBuffer decodeVorbis(
|
||||
Resource dataToDecode,
|
||||
IntBuffer channelsBuffer,
|
||||
IntBuffer rateBuffer
|
||||
) {
|
||||
return stb_vorbis_decode_memory(
|
||||
dataToDecode.readAsBytes(),
|
||||
channelsBuffer,
|
||||
rateBuffer
|
||||
);
|
||||
private static ShortBuffer decodeVorbis(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
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
package ru.windcorp.progressia.client.audio.backend;
|
||||
|
||||
import glm.vec._3.Vec3;
|
||||
@ -55,9 +55,8 @@ public class Listener {
|
||||
if (isInWorld) {
|
||||
|
||||
if (wasInWorld) {
|
||||
velocity.set(camera.getLastAnchorPosition()).sub(position).div(
|
||||
(float) GraphicsInterface.getFrameLength()
|
||||
);
|
||||
velocity.set(camera.getLastAnchorPosition()).sub(position)
|
||||
.div((float) GraphicsInterface.getFrameLength());
|
||||
} else {
|
||||
// If !wasInWorld, previous position is nonsence. Assume 0.
|
||||
velocity.set(0);
|
||||
@ -72,9 +71,9 @@ public class Listener {
|
||||
}
|
||||
|
||||
/*
|
||||
* Only apply if there is a chance that params changed.
|
||||
* This can only happen if we are in world now (isInWorld) or we just
|
||||
* left world (wasInWorld, then we need to reset).
|
||||
* Only apply if there is a chance that params changed. This can only
|
||||
* happen if we are in world now (isInWorld) or we just left world
|
||||
* (wasInWorld, then we need to reset).
|
||||
*/
|
||||
if (isInWorld || wasInWorld) {
|
||||
applyParams();
|
||||
@ -91,17 +90,7 @@ public class Listener {
|
||||
private void applyParams() {
|
||||
alListener3f(AL_POSITION, position.x, position.y, position.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,12 +15,15 @@
|
||||
* 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.audio.backend;
|
||||
|
||||
import ru.windcorp.progressia.common.util.namespaces.Namespaced;
|
||||
|
||||
import java.nio.ShortBuffer;
|
||||
|
||||
import org.lwjgl.openal.AL10;
|
||||
|
||||
import static org.lwjgl.openal.AL11.*;
|
||||
|
||||
public class SoundType extends Namespaced {
|
||||
@ -29,13 +32,9 @@ public class SoundType extends Namespaced {
|
||||
private int sampleRate;
|
||||
private int format;
|
||||
private int audioBuffer;
|
||||
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);
|
||||
this.rawAudio = rawAudio;
|
||||
this.sampleRate = sampleRate;
|
||||
@ -46,9 +45,14 @@ public class SoundType extends Namespaced {
|
||||
private void createAudioBuffer() {
|
||||
this.audioBuffer = alGenBuffers();
|
||||
alBufferData(audioBuffer, format, rawAudio, sampleRate);
|
||||
duration = rawAudio.limit() / (double) sampleRate / (format == AL10.AL_FORMAT_STEREO16 ? 2 : 1);
|
||||
}
|
||||
|
||||
public void initSpeaker(Speaker speaker) {
|
||||
speaker.setAudioData(audioBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
public double getDuration() {
|
||||
return duration;
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@
|
||||
* 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.audio.backend;
|
||||
|
||||
import glm.vec._3.Vec3;
|
||||
@ -24,9 +24,7 @@ import static org.lwjgl.openal.AL11.*;
|
||||
public class Speaker {
|
||||
|
||||
public enum State {
|
||||
NOT_PLAYING,
|
||||
PLAYING,
|
||||
PLAYING_LOOP
|
||||
NOT_PLAYING, PLAYING, PLAYING_LOOP
|
||||
}
|
||||
|
||||
// Buffers
|
||||
@ -49,13 +47,7 @@ public class Speaker {
|
||||
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);
|
||||
setPosition(position);
|
||||
setVelocity(velocity);
|
||||
@ -63,12 +55,7 @@ public class Speaker {
|
||||
setGain(gain);
|
||||
}
|
||||
|
||||
public Speaker(
|
||||
Vec3 position,
|
||||
Vec3 velocity,
|
||||
float pitch,
|
||||
float gain
|
||||
) {
|
||||
public Speaker(Vec3 position, Vec3 velocity, float pitch, float gain) {
|
||||
setPosition(position);
|
||||
setVelocity(velocity);
|
||||
setPitch(pitch);
|
||||
@ -120,6 +107,7 @@ public class Speaker {
|
||||
}
|
||||
|
||||
public void setAudioData(int audioData) {
|
||||
stop();
|
||||
this.audioData = audioData;
|
||||
alSourcei(this.sourceData, AL_BUFFER, audioData);
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.comms;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -39,9 +39,7 @@ public class DefaultClientCommsListener implements CommsListener {
|
||||
@Override
|
||||
public void onPacketReceived(Packet packet) {
|
||||
if (packet instanceof PacketAffectWorld) {
|
||||
((PacketAffectWorld) packet).apply(
|
||||
getClient().getWorld().getData()
|
||||
);
|
||||
((PacketAffectWorld) packet).apply(getClient().getWorld().getData());
|
||||
} else if (packet instanceof PacketSetLocalPlayer) {
|
||||
setLocalPlayer((PacketSetLocalPlayer) packet);
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.comms;
|
||||
|
||||
import ru.windcorp.progressia.common.comms.CommsChannel;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.comms.controls;
|
||||
|
||||
import ru.windcorp.progressia.common.util.namespaces.Namespaced;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.comms.controls;
|
||||
|
||||
import ru.windcorp.progressia.client.graphics.input.InputEvent;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.comms.controls;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
@ -33,17 +33,12 @@ public class ControlTriggerLambda extends ControlTriggerInputBased {
|
||||
private final Predicate<InputEvent> predicate;
|
||||
private final BiConsumer<InputEvent, ControlData> dataWriter;
|
||||
|
||||
public ControlTriggerLambda(
|
||||
String id,
|
||||
Predicate<InputEvent> predicate,
|
||||
BiConsumer<InputEvent, ControlData> dataWriter
|
||||
) {
|
||||
public ControlTriggerLambda(String id, Predicate<InputEvent> predicate,
|
||||
BiConsumer<InputEvent, ControlData> dataWriter) {
|
||||
super(id);
|
||||
|
||||
this.packetId = NamespacedUtil.getId(
|
||||
NamespacedUtil.getNamespace(id),
|
||||
"ControlKeyPress" + NamespacedUtil.getName(id)
|
||||
);
|
||||
this.packetId = NamespacedUtil.getId(NamespacedUtil.getNamespace(id),
|
||||
"ControlKeyPress" + NamespacedUtil.getName(id));
|
||||
|
||||
this.predicate = predicate;
|
||||
this.dataWriter = dataWriter;
|
||||
@ -54,10 +49,7 @@ public class ControlTriggerLambda extends ControlTriggerInputBased {
|
||||
if (!predicate.test(event))
|
||||
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());
|
||||
|
||||
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.comms.controls;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import ru.windcorp.progressia.client.graphics.input.InputEvent;
|
||||
import ru.windcorp.progressia.common.comms.controls.PacketControl;
|
||||
|
||||
public class ControlTriggerLocalLambda extends ControlTriggerInputBased {
|
||||
|
||||
private final Predicate<InputEvent> predicate;
|
||||
private final Consumer<InputEvent> action;
|
||||
|
||||
public ControlTriggerLocalLambda(String id, Predicate<InputEvent> predicate, Consumer<InputEvent> action) {
|
||||
super(id);
|
||||
|
||||
this.predicate = predicate;
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketControl onInputEvent(InputEvent event) {
|
||||
if (!predicate.test(event))
|
||||
return null;
|
||||
|
||||
action.accept(event);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -15,7 +15,7 @@
|
||||
* 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.comms.controls;
|
||||
|
||||
import ru.windcorp.progressia.common.util.namespaces.NamespacedInstanceRegistry;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.comms.controls;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
@ -27,133 +27,119 @@ import ru.windcorp.progressia.common.comms.controls.ControlData;
|
||||
|
||||
public class ControlTriggers {
|
||||
|
||||
public static ControlTriggerInputBased of(
|
||||
String id,
|
||||
BiConsumer<InputEvent, ControlData> dataWriter,
|
||||
Predicate<InputEvent> predicate
|
||||
) {
|
||||
public static ControlTriggerInputBased of(String id, BiConsumer<InputEvent, ControlData> dataWriter,
|
||||
Predicate<InputEvent> predicate) {
|
||||
return new ControlTriggerLambda(id, predicate, dataWriter);
|
||||
}
|
||||
|
||||
public static ControlTriggerInputBased of(
|
||||
String id,
|
||||
Consumer<ControlData> dataWriter,
|
||||
Predicate<InputEvent> predicate
|
||||
) {
|
||||
return of(
|
||||
id,
|
||||
(input, control) -> dataWriter.accept(control),
|
||||
predicate
|
||||
);
|
||||
public static ControlTriggerInputBased of(String id, Consumer<ControlData> dataWriter,
|
||||
Predicate<InputEvent> predicate) {
|
||||
return of(id, (input, control) -> dataWriter.accept(control), predicate);
|
||||
}
|
||||
|
||||
public static ControlTriggerInputBased of(
|
||||
String id,
|
||||
Predicate<InputEvent> predicate
|
||||
) {
|
||||
return of(
|
||||
id,
|
||||
(input, control) -> {
|
||||
},
|
||||
predicate
|
||||
);
|
||||
public static ControlTriggerInputBased of(String id, Predicate<InputEvent> predicate) {
|
||||
return of(id, (input, control) -> {
|
||||
}, predicate);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <I extends InputEvent> ControlTriggerInputBased of(
|
||||
String id,
|
||||
Class<I> inputType,
|
||||
BiConsumer<I, ControlData> dataWriter,
|
||||
Predicate<I>... predicates
|
||||
) {
|
||||
return of(
|
||||
id,
|
||||
createCheckedDataWriter(inputType, dataWriter),
|
||||
createCheckedCompoundPredicate(inputType, predicates)
|
||||
);
|
||||
public static <I extends InputEvent> ControlTriggerInputBased of(String id, Class<I> inputType,
|
||||
BiConsumer<I, ControlData> dataWriter, Predicate<I>... predicates) {
|
||||
return of(id, createCheckedDataWriter(inputType, dataWriter),
|
||||
createCheckedCompoundPredicate(inputType, predicates));
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <I extends InputEvent> ControlTriggerInputBased of(
|
||||
String id,
|
||||
Class<I> inputType,
|
||||
Consumer<ControlData> dataWriter,
|
||||
Predicate<I>... predicates
|
||||
) {
|
||||
return of(
|
||||
id,
|
||||
inputType,
|
||||
(input, control) -> dataWriter.accept(control),
|
||||
predicates
|
||||
);
|
||||
public static <I extends InputEvent> ControlTriggerInputBased of(String id, Class<I> inputType,
|
||||
Consumer<ControlData> dataWriter, Predicate<I>... predicates) {
|
||||
return of(id, inputType, (input, control) -> dataWriter.accept(control), predicates);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <I extends InputEvent> ControlTriggerInputBased of(
|
||||
String id,
|
||||
Class<I> inputType,
|
||||
Predicate<I>... predicates
|
||||
) {
|
||||
return of(
|
||||
id,
|
||||
(input, control) -> {
|
||||
},
|
||||
createCheckedCompoundPredicate(inputType, predicates)
|
||||
);
|
||||
public static <I extends InputEvent> ControlTriggerInputBased of(String id, Class<I> inputType,
|
||||
Predicate<I>... predicates) {
|
||||
return of(id, (input, control) -> {
|
||||
}, createCheckedCompoundPredicate(inputType, predicates));
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static ControlTriggerInputBased of(
|
||||
String id,
|
||||
BiConsumer<InputEvent, ControlData> dataWriter,
|
||||
Predicate<InputEvent>... predicates
|
||||
) {
|
||||
return of(
|
||||
id,
|
||||
InputEvent.class,
|
||||
dataWriter,
|
||||
predicates
|
||||
);
|
||||
public static ControlTriggerInputBased of(String id, BiConsumer<InputEvent, ControlData> dataWriter,
|
||||
Predicate<InputEvent>... predicates) {
|
||||
return of(id, InputEvent.class, dataWriter, predicates);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <I extends InputEvent> ControlTriggerInputBased of(
|
||||
String id,
|
||||
Consumer<ControlData> dataWriter,
|
||||
Predicate<InputEvent>... predicates
|
||||
) {
|
||||
return of(
|
||||
id,
|
||||
(input, control) -> dataWriter.accept(control),
|
||||
predicates
|
||||
);
|
||||
public static <I extends InputEvent> ControlTriggerInputBased of(String id, Consumer<ControlData> dataWriter,
|
||||
Predicate<InputEvent>... predicates) {
|
||||
return of(id, (input, control) -> dataWriter.accept(control), predicates);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static ControlTriggerInputBased of(
|
||||
String id,
|
||||
Predicate<InputEvent>... predicates
|
||||
) {
|
||||
return of(
|
||||
id,
|
||||
InputEvent.class,
|
||||
(input, control) -> {
|
||||
},
|
||||
predicates
|
||||
);
|
||||
public static ControlTriggerInputBased of(String id, Predicate<InputEvent>... predicates) {
|
||||
return of(id, InputEvent.class, (input, control) -> {
|
||||
}, predicates);
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
///
|
||||
///
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
public static ControlTriggerInputBased localOf(String id, Consumer<InputEvent> action,
|
||||
Predicate<InputEvent> predicate) {
|
||||
return new ControlTriggerLocalLambda(id, predicate, action);
|
||||
}
|
||||
|
||||
public static ControlTriggerInputBased localOf(String id, Runnable action, Predicate<InputEvent> predicate) {
|
||||
return localOf(id, input -> action.run(), predicate);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <I extends InputEvent> ControlTriggerInputBased localOf(String id, Class<I> inputType,
|
||||
Consumer<I> action, Predicate<I>... predicates) {
|
||||
return localOf(id, createCheckedAction(inputType, action),
|
||||
createCheckedCompoundPredicate(inputType, predicates));
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <I extends InputEvent> ControlTriggerInputBased localOf(String id, Class<I> inputType,
|
||||
Runnable action, Predicate<I>... predicates) {
|
||||
return localOf(id, inputType, input -> action.run(), predicates);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static ControlTriggerInputBased localOf(String id, Consumer<InputEvent> action,
|
||||
Predicate<InputEvent>... predicates) {
|
||||
return localOf(id, InputEvent.class, action, predicates);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <I extends InputEvent> ControlTriggerInputBased localOf(String id, Runnable action,
|
||||
Predicate<InputEvent>... predicates) {
|
||||
return of(id, input -> action.run(), predicates);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private static <I extends InputEvent> Predicate<InputEvent> createCheckedCompoundPredicate(
|
||||
Class<I> inputType,
|
||||
Predicate<I>[] predicates
|
||||
) {
|
||||
private static <I extends InputEvent> Consumer<InputEvent> createCheckedAction(Class<I> inputType,
|
||||
Consumer<I> action) {
|
||||
return inputEvent -> action.accept(inputType.cast(inputEvent));
|
||||
}
|
||||
|
||||
private static <I extends InputEvent> Predicate<InputEvent> createCheckedCompoundPredicate(Class<I> inputType,
|
||||
Predicate<I>[] predicates) {
|
||||
return new CompoundCastPredicate<>(inputType, predicates);
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.comms.controls;
|
||||
|
||||
import ru.windcorp.progressia.client.Client;
|
||||
@ -32,8 +32,7 @@ public class InputBasedControls {
|
||||
this.client = client;
|
||||
|
||||
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) {
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.comms.localhost;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.comms.localhost;
|
||||
|
||||
import ru.windcorp.progressia.client.comms.ServerCommsChannel;
|
||||
@ -34,11 +34,7 @@ public class LocalServerCommsChannel extends ServerCommsChannel {
|
||||
public void connect(String login) {
|
||||
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);
|
||||
}
|
||||
|
@ -34,7 +34,13 @@ public class Colors {
|
||||
DEBUG_BLUE = toVector(0xFF0000FF),
|
||||
DEBUG_CYAN = toVector(0xFF00FFFF),
|
||||
DEBUG_MAGENTA = toVector(0xFFFF00FF),
|
||||
DEBUG_YELLOW = toVector(0xFFFFFF00);
|
||||
DEBUG_YELLOW = toVector(0xFFFFFF00),
|
||||
|
||||
LIGHT_GRAY = toVector(0xFFCBCBD0),
|
||||
BLUE = toVector(0xFF37A2E6),
|
||||
HOVER_BLUE = toVector(0xFFC3E4F7),
|
||||
DISABLED_GRAY = toVector(0xFFE5E5E5),
|
||||
DISABLED_BLUE = toVector(0xFFB2D8ED);
|
||||
|
||||
public static Vec4 toVector(int argb) {
|
||||
return toVector(argb, new Vec4());
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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 java.util.ArrayList;
|
||||
@ -24,6 +24,7 @@ import java.util.List;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
|
||||
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;
|
||||
@ -42,7 +43,7 @@ public class GUI {
|
||||
}
|
||||
|
||||
private static final List<LayerStackModification> MODIFICATION_QUEUE = Collections
|
||||
.synchronizedList(new ArrayList<>());
|
||||
.synchronizedList(new ArrayList<>());
|
||||
|
||||
private static class ModifiableInput extends Input {
|
||||
@Override
|
||||
@ -57,15 +58,24 @@ public class GUI {
|
||||
}
|
||||
|
||||
public static void addBottomLayer(Layer layer) {
|
||||
modify(layers -> layers.add(layer));
|
||||
modify(layers -> {
|
||||
layers.add(layer);
|
||||
layer.onAdded();
|
||||
});
|
||||
}
|
||||
|
||||
public static void addTopLayer(Layer layer) {
|
||||
modify(layers -> layers.add(0, layer));
|
||||
modify(layers -> {
|
||||
layers.add(0, layer);
|
||||
layer.onAdded();
|
||||
});
|
||||
}
|
||||
|
||||
public static void removeLayer(Layer layer) {
|
||||
modify(layers -> layers.remove(layer));
|
||||
modify(layers -> {
|
||||
layers.remove(layer);
|
||||
layer.onRemoved();
|
||||
});
|
||||
}
|
||||
|
||||
private static void modify(LayerStackModification mod) {
|
||||
@ -78,12 +88,33 @@ public class GUI {
|
||||
|
||||
public static void render() {
|
||||
synchronized (LAYERS) {
|
||||
MODIFICATION_QUEUE.forEach(action -> action.affect(LAYERS));
|
||||
MODIFICATION_QUEUE.clear();
|
||||
|
||||
|
||||
if (!MODIFICATION_QUEUE.isEmpty()) {
|
||||
MODIFICATION_QUEUE.forEach(action -> action.affect(LAYERS));
|
||||
MODIFICATION_QUEUE.clear();
|
||||
|
||||
boolean isMouseCurrentlyCaptured = GraphicsInterface.isMouseCaptured();
|
||||
Layer.CursorPolicy policy = Layer.CursorPolicy.REQUIRE;
|
||||
|
||||
for (Layer layer : LAYERS) {
|
||||
Layer.CursorPolicy currentPolicy = layer.getCursorPolicy();
|
||||
|
||||
if (currentPolicy != Layer.CursorPolicy.INDIFFERENT) {
|
||||
policy = currentPolicy;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
boolean shouldCaptureMouse = (policy == Layer.CursorPolicy.FORBID);
|
||||
if (shouldCaptureMouse != isMouseCurrentlyCaptured) {
|
||||
GraphicsInterface.setMouseCaptured(shouldCaptureMouse);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = LAYERS.size() - 1; i >= 0; --i) {
|
||||
LAYERS.get(i).render();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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 java.util.concurrent.atomic.AtomicBoolean;
|
||||
@ -30,15 +30,52 @@ public abstract class Layer {
|
||||
private boolean hasInitialized = false;
|
||||
|
||||
private final AtomicBoolean isValid = new AtomicBoolean(false);
|
||||
|
||||
/**
|
||||
* Represents various requests that a {@link Layer} can make regarding the
|
||||
* presence of a visible cursor. The value of the highest layer that is not
|
||||
* {@link #INDIFFERENT} is used.
|
||||
*/
|
||||
public static enum CursorPolicy {
|
||||
/**
|
||||
* Require that a cursor is visible.
|
||||
*/
|
||||
REQUIRE,
|
||||
|
||||
/**
|
||||
* The {@link Layer} should not affect the presence or absence of a
|
||||
* visible cursor; lower layers should be consulted.
|
||||
*/
|
||||
INDIFFERENT,
|
||||
|
||||
/**
|
||||
* Forbid a visible cursor.
|
||||
*/
|
||||
FORBID
|
||||
}
|
||||
|
||||
private CursorPolicy cursorPolicy = CursorPolicy.INDIFFERENT;
|
||||
|
||||
public Layer(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Layer " + name;
|
||||
}
|
||||
|
||||
public CursorPolicy getCursorPolicy() {
|
||||
return cursorPolicy;
|
||||
}
|
||||
|
||||
public void setCursorPolicy(CursorPolicy cursorPolicy) {
|
||||
this.cursorPolicy = cursorPolicy;
|
||||
}
|
||||
|
||||
void render() {
|
||||
GraphicsInterface.startNextLayer();
|
||||
@ -78,5 +115,13 @@ public abstract class Layer {
|
||||
protected int getHeight() {
|
||||
return GraphicsInterface.getFrameHeight();
|
||||
}
|
||||
|
||||
protected void onAdded() {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
protected void onRemoved() {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.backend;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
|
@ -15,14 +15,14 @@
|
||||
* 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.backend;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
import glm.vec._2.i.Vec2i;
|
||||
import org.lwjgl.glfw.GLFWVidMode;
|
||||
|
||||
import static org.lwjgl.glfw.GLFW.*;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
public class GraphicsBackend {
|
||||
|
||||
@ -38,9 +38,30 @@ public class GraphicsBackend {
|
||||
|
||||
private static boolean faceCullingEnabled = false;
|
||||
|
||||
private static boolean isFullscreen = false;
|
||||
private static boolean vSyncEnabled = false;
|
||||
private static boolean isGLFWInitialized = false;
|
||||
private static boolean isOpenGLInitialized = false;
|
||||
|
||||
private GraphicsBackend() {
|
||||
}
|
||||
|
||||
public static boolean isGLFWInitialized() {
|
||||
return isGLFWInitialized;
|
||||
}
|
||||
|
||||
static void setGLFWInitialized(boolean isGLFWInitialized) {
|
||||
GraphicsBackend.isGLFWInitialized = isGLFWInitialized;
|
||||
}
|
||||
|
||||
public static boolean isOpenGLInitialized() {
|
||||
return isOpenGLInitialized;
|
||||
}
|
||||
|
||||
static void setOpenGLInitialized(boolean isOpenGLInitialized) {
|
||||
GraphicsBackend.isOpenGLInitialized = isOpenGLInitialized;
|
||||
}
|
||||
|
||||
public static void initialize() {
|
||||
startRenderThread();
|
||||
}
|
||||
@ -128,4 +149,48 @@ public class GraphicsBackend {
|
||||
faceCullingEnabled = useFaceCulling;
|
||||
}
|
||||
|
||||
public static boolean isFullscreen() {
|
||||
return isFullscreen;
|
||||
}
|
||||
|
||||
public static boolean isVSyncEnabled() {
|
||||
return vSyncEnabled;
|
||||
}
|
||||
|
||||
public static void setFullscreen() {
|
||||
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
||||
glfwSetWindowMonitor(getWindowHandle(), glfwGetPrimaryMonitor(), 0, 0, vidmode.width(), vidmode.height(), 0);
|
||||
isFullscreen = true;
|
||||
}
|
||||
|
||||
public static void setWindowed() {
|
||||
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
||||
glfwSetWindowMonitor(getWindowHandle(), 0, (vidmode.width() - getFrameWidth()) / 2,
|
||||
(vidmode.height() - getFrameHeight()) / 2, getFrameWidth(), getFrameHeight(), 0);
|
||||
isFullscreen = false;
|
||||
}
|
||||
|
||||
public static void setVSyncEnabled(boolean enable) {
|
||||
glfwSwapInterval(enable ? 1 : 0);
|
||||
vSyncEnabled = enable;
|
||||
}
|
||||
|
||||
public static int getRefreshRate() {
|
||||
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
||||
return vidmode.refreshRate();
|
||||
}
|
||||
|
||||
public static boolean isMouseCaptured() {
|
||||
return glfwGetInputMode(windowHandle, GLFW_CURSOR) == GLFW_CURSOR_DISABLED;
|
||||
}
|
||||
|
||||
public static void setMouseCaptured(boolean capture) {
|
||||
int mode = capture ? GLFW_CURSOR_DISABLED : GLFW_CURSOR_NORMAL;
|
||||
glfwSetInputMode(windowHandle, GLFW_CURSOR, mode);
|
||||
|
||||
if (!capture) {
|
||||
glfwSetCursorPos(windowHandle, FRAME_SIZE.x / 2.0, FRAME_SIZE.y / 2.0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.backend;
|
||||
|
||||
import glm.vec._2.i.Vec2i;
|
||||
@ -73,4 +73,21 @@ public class GraphicsInterface {
|
||||
GraphicsBackend.startNextLayer();
|
||||
}
|
||||
|
||||
public static void makeFullscreen(boolean state) {
|
||||
if (state) {
|
||||
GraphicsBackend.setFullscreen();
|
||||
} else {
|
||||
GraphicsBackend.setWindowed();
|
||||
}
|
||||
GraphicsBackend.setVSyncEnabled(GraphicsBackend.isVSyncEnabled());
|
||||
}
|
||||
|
||||
public static boolean isMouseCaptured() {
|
||||
return GraphicsBackend.isMouseCaptured();
|
||||
}
|
||||
|
||||
public static void setMouseCaptured(boolean capture) {
|
||||
GraphicsBackend.setMouseCaptured(capture);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.backend;
|
||||
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
@ -49,13 +49,7 @@ public class InputHandler {
|
||||
|
||||
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)
|
||||
return;
|
||||
THE_KEY_EVENT.initialize(key, scancode, action, mods);
|
||||
@ -71,12 +65,7 @@ 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);
|
||||
}
|
||||
|
||||
@ -97,11 +86,7 @@ public class InputHandler {
|
||||
|
||||
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)
|
||||
return;
|
||||
y = GraphicsInterface.getFrameHeight() - y; // Flip y axis
|
||||
@ -131,11 +116,7 @@ public class InputHandler {
|
||||
|
||||
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)
|
||||
return;
|
||||
THE_WHEEL_SCROLL_EVENT.initialize(xoffset, yoffset);
|
||||
@ -162,10 +143,7 @@ public class InputHandler {
|
||||
/*
|
||||
* 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);
|
||||
dispatch(THE_FRAME_RESIZE_EVENT);
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.backend;
|
||||
|
||||
import glm.vec._2.d.Vec2d;
|
||||
@ -24,10 +24,7 @@ import gnu.trove.set.hash.TIntHashSet;
|
||||
|
||||
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);
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.backend;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
@ -50,6 +50,7 @@ class LWJGLInitializer {
|
||||
private static void initializeGLFW() {
|
||||
// TODO Do GLFW error handling: check glfwInit, setup error callback
|
||||
glfwInit();
|
||||
GraphicsBackend.setGLFWInitialized(true);
|
||||
}
|
||||
|
||||
private static void createWindow() {
|
||||
@ -64,10 +65,8 @@ class LWJGLInitializer {
|
||||
|
||||
GraphicsBackend.setWindowHandle(handle);
|
||||
|
||||
glfwSetInputMode(handle, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||
|
||||
glfwMakeContextCurrent(handle);
|
||||
glfwSwapInterval(0);
|
||||
glfwSwapInterval(0); // TODO: remove after config system is added
|
||||
}
|
||||
|
||||
private static void positionWindow() {
|
||||
@ -87,21 +86,16 @@ class LWJGLInitializer {
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
RenderTaskQueue.schedule(OpenGLObjectTracker::deleteEnqueuedObjects);
|
||||
GraphicsBackend.setOpenGLInitialized(true);
|
||||
}
|
||||
|
||||
private static void setupWindowCallbacks() {
|
||||
long handle = GraphicsBackend.getWindowHandle();
|
||||
|
||||
glfwSetFramebufferSizeCallback(
|
||||
handle,
|
||||
GraphicsBackend::onFrameResized
|
||||
);
|
||||
glfwSetFramebufferSizeCallback(handle, GraphicsBackend::onFrameResized);
|
||||
|
||||
glfwSetKeyCallback(handle, InputHandler::handleKeyInput);
|
||||
glfwSetMouseButtonCallback(
|
||||
handle,
|
||||
InputHandler::handleMouseButtonInput
|
||||
);
|
||||
glfwSetMouseButtonCallback(handle, InputHandler::handleMouseButtonInput);
|
||||
|
||||
glfwSetCursorPosCallback(handle, InputHandler::handleMouseMoveInput);
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.backend;
|
||||
|
||||
import java.lang.ref.PhantomReference;
|
||||
@ -34,19 +34,13 @@ public class OpenGLObjectTracker {
|
||||
private static final ReferenceQueue<OpenGLDeletable> DELETE_QUEUE = new ReferenceQueue<>();
|
||||
|
||||
public synchronized static void register(OpenGLDeletable object, IntConsumer glDeleter) {
|
||||
GLPhantomReference<OpenGLDeletable> glRef = new GLPhantomReference<>(
|
||||
object,
|
||||
DELETE_QUEUE,
|
||||
object.getHandle(),
|
||||
glDeleter
|
||||
);
|
||||
GLPhantomReference<OpenGLDeletable> glRef = new GLPhantomReference<>(object, DELETE_QUEUE, object.getHandle(),
|
||||
glDeleter);
|
||||
TO_DELETE.add(glRef);
|
||||
}
|
||||
|
||||
public static void deleteAllObjects() {
|
||||
for (
|
||||
GLPhantomReference<OpenGLDeletable> glRef : TO_DELETE
|
||||
) {
|
||||
for (GLPhantomReference<OpenGLDeletable> glRef : TO_DELETE) {
|
||||
glRef.clear();
|
||||
}
|
||||
}
|
||||
@ -75,20 +69,16 @@ public class OpenGLObjectTracker {
|
||||
* It is possible to create a phantom reference with a {@code null}
|
||||
* queue, but such a reference is completely useless: Its {@code get}
|
||||
* 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 the object the new phantom reference will refer to
|
||||
* @param q the queue with which the reference is to be
|
||||
* registered,
|
||||
* or {@code null} if registration is not required
|
||||
* @param referent
|
||||
* the object the new phantom reference will refer to
|
||||
* @param q
|
||||
* the queue with which the reference is to be registered, or
|
||||
* {@code null} if registration is not required
|
||||
*/
|
||||
public GLPhantomReference(
|
||||
T referent,
|
||||
ReferenceQueue<? super T> q,
|
||||
int referentGLhandle,
|
||||
IntConsumer GLDeleter
|
||||
) {
|
||||
public GLPhantomReference(T referent, ReferenceQueue<? super T> q, int referentGLhandle,
|
||||
IntConsumer GLDeleter) {
|
||||
super(referent, q);
|
||||
this.referentGLhandle = referentGLhandle;
|
||||
this.GLDeleter = GLDeleter;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.backend;
|
||||
|
||||
import ru.windcorp.jputil.functions.ThrowingRunnable;
|
||||
@ -41,11 +41,7 @@ public class RenderTaskQueue {
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.backend;
|
||||
|
||||
import static org.lwjgl.glfw.GLFW.*;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.backend;
|
||||
|
||||
import static org.lwjgl.opengl.GL15.GL_DYNAMIC_DRAW;
|
||||
@ -23,9 +23,7 @@ import static org.lwjgl.opengl.GL15.GL_STATIC_DRAW;
|
||||
import static org.lwjgl.opengl.GL15.GL_STREAM_DRAW;
|
||||
|
||||
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;
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.backend;
|
||||
|
||||
import static org.lwjgl.opengl.GL20.*;
|
||||
@ -28,8 +28,7 @@ import ru.windcorp.progressia.client.graphics.backend.OpenGLObjectTracker.OpenGL
|
||||
public class VertexBufferObject implements OpenGLDeletable {
|
||||
|
||||
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;
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.backend.shaders;
|
||||
|
||||
import ru.windcorp.progressia.common.resource.Resource;
|
||||
@ -32,12 +32,7 @@ public class CombinedShader extends Shader {
|
||||
for (int i = 1; i < resources.length; ++i) {
|
||||
if (ShaderType.guessByResourceName(resources[i]) != first) {
|
||||
throw new IllegalArgumentException(
|
||||
"Deduced shader types of "
|
||||
+ resources[0]
|
||||
+ " and "
|
||||
+ resources[i]
|
||||
+ " differ"
|
||||
);
|
||||
"Deduced shader types of " + resources[0] + " and " + resources[i] + " differ");
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,19 +66,8 @@ public class CombinedShader extends Shader {
|
||||
if (contents.codePointAt(versionIndex) == '#') {
|
||||
final String versionAnnotation = "#version ";
|
||||
|
||||
if (
|
||||
contents.regionMatches(
|
||||
versionIndex,
|
||||
versionAnnotation,
|
||||
0,
|
||||
versionAnnotation.length()
|
||||
)
|
||||
) {
|
||||
contents = contents.substring(
|
||||
versionIndex
|
||||
+ versionAnnotation.length()
|
||||
+ "120".length()
|
||||
);
|
||||
if (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
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
package ru.windcorp.progressia.client.graphics.backend.shaders;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* 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.backend.shaders;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
@ -57,10 +57,7 @@ public class Shader implements OpenGLDeletable {
|
||||
if (resource.contains("fsh"))
|
||||
return FRAGMENT;
|
||||
|
||||
throw new IllegalArgumentException(
|
||||
"Cannot deduce shader type from resource name \"" +
|
||||
resource + "\""
|
||||
);
|
||||
throw new IllegalArgumentException("Cannot deduce shader type from resource name \"" + resource + "\"");
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,10 +87,7 @@ public class Shader implements OpenGLDeletable {
|
||||
}
|
||||
|
||||
public Shader(String resource) {
|
||||
this(
|
||||
ShaderType.guessByResourceName(resource),
|
||||
getShaderResource(resource).readAsString()
|
||||
);
|
||||
this(ShaderType.guessByResourceName(resource), getShaderResource(resource).readAsString());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user