Formatted source, added/updated copyright headers
- Also added formatting settings for Eclipse IDE
This commit is contained in:
parent
8f3009300f
commit
c2d91726a7
@ -1,5 +1,23 @@
|
||||
#!/bin/bash
|
||||
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
|
||||
echoerr() { echo "$@" 1>&2; }
|
||||
|
||||
buildDebianPackage() {
|
||||
|
@ -100,6 +100,18 @@ Alternatively, specify another location outside of the project's root directory.
|
||||
Step 5 is required to specify that the game must run in some directory other than the project root,
|
||||
which is the default in Eclipse.
|
||||
|
||||
### Applying formatting templates
|
||||
|
||||
Windcorp's Progressia repository is formatted with a style defined for Eclipse IDE in
|
||||
`templates_and_presets/eclipse_ide`.
|
||||
Please apply these templates to the project to automatically format the source in a similar fashion.
|
||||
|
||||
1. In project context menu, click 'Properties'.
|
||||
2. In 'Java Code Style' > 'Code Templates', check 'Enable project specific settings', then click 'Import' and select
|
||||
`templates_and_presets/eclipse_ide/CodeTemplates.xml`.
|
||||
3. In 'Java Code Style' > 'Formatter', check 'Enable project specific settings', then click 'Import' and select
|
||||
`templates_and_presets/eclipse_ide/FormatterProfile.xml`.
|
||||
|
||||
## Common problems
|
||||
|
||||
### Buildship plugin fails with a cryptic message
|
||||
|
@ -3,9 +3,11 @@ package kdotjpg.opensimplex2.areagen;
|
||||
* This file has been modified in the following ways:
|
||||
* - added a package declaration at line 1;
|
||||
* - added missing @Override annotations;
|
||||
* - commented out line 965 due to unused variables.
|
||||
* - commented out line 967 due to unused variables.
|
||||
* The original version of this file can be found at
|
||||
* https://raw.githubusercontent.com/KdotJPG/OpenSimplex2/master/java/areagen/OpenSimplex2S.java
|
||||
*
|
||||
* @formatter:off
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -983,16 +985,3 @@ public class OpenSimplex2S {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
@ -23,7 +24,8 @@ import java.util.Objects;
|
||||
|
||||
public class ArrayUtil {
|
||||
|
||||
private ArrayUtil() {}
|
||||
private ArrayUtil() {
|
||||
}
|
||||
|
||||
public static int firstIndexOf(byte[] array, byte element) {
|
||||
for (int i = 0; i < array.length; ++i) {
|
||||
@ -68,7 +70,8 @@ public class ArrayUtil {
|
||||
|
||||
public static boolean isSorted(byte[] array, boolean ascending) {
|
||||
for (int i = 0; i < array.length - 1; ++i) {
|
||||
if (array[i] == array[i + 1]) continue;
|
||||
if (array[i] == array[i + 1])
|
||||
continue;
|
||||
|
||||
if ((array[i] < array[i + 1]) != ascending) {
|
||||
return false;
|
||||
@ -121,7 +124,8 @@ public class ArrayUtil {
|
||||
|
||||
public static boolean isSorted(short[] array, boolean ascending) {
|
||||
for (int i = 0; i < array.length - 1; ++i) {
|
||||
if (array[i] == array[i + 1]) continue;
|
||||
if (array[i] == array[i + 1])
|
||||
continue;
|
||||
|
||||
if ((array[i] < array[i + 1]) != ascending) {
|
||||
return false;
|
||||
@ -174,7 +178,8 @@ public class ArrayUtil {
|
||||
|
||||
public static boolean isSorted(int[] array, boolean ascending) {
|
||||
for (int i = 0; i < array.length - 1; ++i) {
|
||||
if (array[i] == array[i + 1]) continue;
|
||||
if (array[i] == array[i + 1])
|
||||
continue;
|
||||
|
||||
if ((array[i] < array[i + 1]) != ascending) {
|
||||
return false;
|
||||
@ -227,7 +232,8 @@ public class ArrayUtil {
|
||||
|
||||
public static boolean isSorted(long[] array, boolean ascending) {
|
||||
for (int i = 0; i < array.length - 1; ++i) {
|
||||
if (array[i] == array[i + 1]) continue;
|
||||
if (array[i] == array[i + 1])
|
||||
continue;
|
||||
|
||||
if ((array[i] < array[i + 1]) != ascending) {
|
||||
return false;
|
||||
@ -280,7 +286,8 @@ public class ArrayUtil {
|
||||
|
||||
public static boolean isSorted(float[] array, boolean ascending) {
|
||||
for (int i = 0; i < array.length - 1; ++i) {
|
||||
if (array[i] == array[i + 1]) continue;
|
||||
if (array[i] == array[i + 1])
|
||||
continue;
|
||||
|
||||
if ((array[i] < array[i + 1]) != ascending) {
|
||||
return false;
|
||||
@ -333,7 +340,8 @@ public class ArrayUtil {
|
||||
|
||||
public static boolean isSorted(double[] array, boolean ascending) {
|
||||
for (int i = 0; i < array.length - 1; ++i) {
|
||||
if (array[i] == array[i + 1]) continue;
|
||||
if (array[i] == array[i + 1])
|
||||
continue;
|
||||
|
||||
if ((array[i] < array[i + 1]) != ascending) {
|
||||
return false;
|
||||
@ -414,7 +422,8 @@ public class ArrayUtil {
|
||||
|
||||
public static boolean isSorted(char[] array, boolean ascending) {
|
||||
for (int i = 0; i < array.length - 1; ++i) {
|
||||
if (array[i] == array[i + 1]) continue;
|
||||
if (array[i] == array[i + 1])
|
||||
continue;
|
||||
|
||||
if ((array[i] < array[i + 1]) != ascending) {
|
||||
return false;
|
||||
@ -508,7 +517,8 @@ public class ArrayUtil {
|
||||
|
||||
public static <T extends Comparable<T>> boolean isSorted(T[] array, boolean ascending) {
|
||||
for (int i = 0; i < array.length - 1; ++i) {
|
||||
if (array[i] == array[i + 1]) continue;
|
||||
if (array[i] == array[i + 1])
|
||||
continue;
|
||||
|
||||
int order = array[i].compareTo(array[i + 1]);
|
||||
|
||||
@ -600,7 +610,9 @@ public class ArrayUtil {
|
||||
|
||||
int end = offset + length;
|
||||
if (end > arrayLength || offset < 0)
|
||||
throw new IllegalArgumentException("Array contains [0; " + arrayLength + "), requested [" + offset + "; " + end + ")");
|
||||
throw new IllegalArgumentException(
|
||||
"Array contains [0; " + arrayLength + "), requested [" + offset + "; " + end + ")"
|
||||
);
|
||||
|
||||
return length;
|
||||
}
|
||||
@ -615,7 +627,9 @@ public class ArrayUtil {
|
||||
throw new IllegalArgumentException("Start > end: " + start + " > " + end);
|
||||
|
||||
if (end > arrayLength || start < 0)
|
||||
throw new IllegalArgumentException("Array contains [0; " + arrayLength + "), requested [" + start + "; " + end + ")");
|
||||
throw new IllegalArgumentException(
|
||||
"Array contains [0; " + arrayLength + "), requested [" + start + "; " + end + ")"
|
||||
);
|
||||
|
||||
return end;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
@ -22,16 +23,25 @@ import java.util.Map;
|
||||
|
||||
public class PrimitiveUtil {
|
||||
|
||||
private PrimitiveUtil() {}
|
||||
private PrimitiveUtil() {
|
||||
}
|
||||
|
||||
private static final Map<Class<?>, Class<?>> PRIMITIVE_TO_BOXED = new HashMap<>();
|
||||
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) {
|
||||
@ -39,14 +49,14 @@ public class PrimitiveUtil {
|
||||
}
|
||||
}
|
||||
|
||||
PRIMITIVE_TO_NULL.put(Boolean.TYPE, Boolean.FALSE);
|
||||
PRIMITIVE_TO_NULL.put(Byte.TYPE, Byte.valueOf((byte) 0));
|
||||
PRIMITIVE_TO_NULL.put(Short.TYPE, Short.valueOf((short) 0));
|
||||
PRIMITIVE_TO_NULL.put(Integer.TYPE, Integer.valueOf(0));
|
||||
PRIMITIVE_TO_NULL.put(Long.TYPE, Long.valueOf(0));
|
||||
PRIMITIVE_TO_NULL.put(Float.TYPE, Float.valueOf(Float.NaN));
|
||||
PRIMITIVE_TO_NULL.put(Double.TYPE, Double.valueOf(Double.NaN));
|
||||
PRIMITIVE_TO_NULL.put(Character.TYPE, Character.valueOf('\u0000'));
|
||||
PRIMITIVE_TO_NULL.put(Boolean.TYPE, Boolean.FALSE);
|
||||
PRIMITIVE_TO_NULL.put(Byte.TYPE, Byte.valueOf((byte) 0));
|
||||
PRIMITIVE_TO_NULL.put(Short.TYPE, Short.valueOf((short) 0));
|
||||
PRIMITIVE_TO_NULL.put(Integer.TYPE, Integer.valueOf(0));
|
||||
PRIMITIVE_TO_NULL.put(Long.TYPE, Long.valueOf(0));
|
||||
PRIMITIVE_TO_NULL.put(Float.TYPE, Float.valueOf(Float.NaN));
|
||||
PRIMITIVE_TO_NULL.put(Double.TYPE, Double.valueOf(Double.NaN));
|
||||
PRIMITIVE_TO_NULL.put(Character.TYPE, Character.valueOf('\u0000'));
|
||||
}
|
||||
|
||||
public static Class<?> getBoxedClass(Class<?> primitiveClass) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -11,7 +11,11 @@
|
||||
* 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.jputil;
|
||||
|
||||
import java.util.function.*;
|
||||
@ -35,10 +39,14 @@ import java.util.stream.LongStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Contains static methods to create {@link Stream Streams} that synchronize their
|
||||
* <a href="https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html#StreamOps">
|
||||
* Contains static methods to create {@link Stream Streams} that synchronize
|
||||
* 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.
|
||||
* @author Javapony (<a href="mailto:kvadropups@gmail.com">kvadropups@gmail.com</a>)
|
||||
*
|
||||
* @author Javapony
|
||||
* (<a href="mailto:kvadropups@gmail.com">kvadropups@gmail.com</a>)
|
||||
*/
|
||||
|
||||
// SonarLint: "Stream.peek" should be used with caution (java:S3864)
|
||||
@ -1063,20 +1071,30 @@ public class SyncStreams {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* <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
|
||||
* <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.
|
||||
* <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:
|
||||
*
|
||||
* <pre>
|
||||
* synchronized (stream.getMonitor()) {
|
||||
* Iterator<T> it = stream.iterator();
|
||||
* ...
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* Usage example:
|
||||
*
|
||||
* <pre>
|
||||
* Set<Object> s = Collections.synchronizedSet(new HashSet<>());
|
||||
* ...
|
||||
@ -1085,11 +1103,13 @@ 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.
|
||||
* @return a {@link SyncStream SyncStream<T>} synchronized on {@code monitor} and backed by {@code stream}.
|
||||
* @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}.
|
||||
*/
|
||||
public static <T> SyncStream<T> synchronizedStream(Stream<T> stream, Object monitor) {
|
||||
@ -1099,20 +1119,31 @@ public class SyncStreams {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* <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:
|
||||
* <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.
|
||||
* <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:
|
||||
*
|
||||
* <pre>
|
||||
* synchronized (stream.getMonitor()) {
|
||||
* PrimitiveIterator.OfInt it = stream.iterator();
|
||||
* ...
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* Usage example:
|
||||
*
|
||||
* <pre>
|
||||
* Set<Object> s = Collections.synchronizedSet(new HashSet<>());
|
||||
* ...
|
||||
@ -1121,10 +1152,12 @@ 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.
|
||||
* @return a {@link SyncIntStream} synchronized on {@code monitor} and backed by {@code 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 SyncIntStream} synchronized on {@code monitor} and
|
||||
* backed by {@code stream}.
|
||||
* @throws NullPointerException if {@code stream == null}.
|
||||
*/
|
||||
public static SyncIntStream synchronizedStream(IntStream stream, Object monitor) {
|
||||
@ -1134,20 +1167,31 @@ public class SyncStreams {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* <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:
|
||||
* <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.
|
||||
* <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:
|
||||
*
|
||||
* <pre>
|
||||
* synchronized (stream.getMonitor()) {
|
||||
* PrimitiveIterator.OfLong it = stream.iterator();
|
||||
* ...
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* Usage example:
|
||||
*
|
||||
* <pre>
|
||||
* Set<Object> s = Collections.synchronizedSet(new HashSet<>());
|
||||
* ...
|
||||
@ -1156,10 +1200,12 @@ 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.
|
||||
* @return a {@link SyncLongStream} synchronized on {@code monitor} and backed by {@code 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 SyncLongStream} synchronized on {@code monitor} and
|
||||
* backed by {@code stream}.
|
||||
* @throws NullPointerException if {@code stream == null}.
|
||||
*/
|
||||
public static SyncLongStream synchronizedStream(LongStream stream, Object monitor) {
|
||||
@ -1169,20 +1215,31 @@ public class SyncStreams {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* <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:
|
||||
* <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.
|
||||
* <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:
|
||||
*
|
||||
* <pre>
|
||||
* synchronized (stream.getMonitor()) {
|
||||
* PrimitiveIterator.OfDouble it = stream.iterator();
|
||||
* ...
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* Usage example:
|
||||
*
|
||||
* <pre>
|
||||
* Set<Object> s = Collections.synchronizedSet(new HashSet<>());
|
||||
* ...
|
||||
@ -1191,10 +1248,12 @@ 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.
|
||||
* @return a {@link SyncDoubleStream} synchronized on {@code monitor} and backed by {@code 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 SyncDoubleStream} synchronized on {@code monitor} and
|
||||
* backed by {@code stream}.
|
||||
* @throws NullPointerException if {@code stream == null}.
|
||||
*/
|
||||
public static SyncDoubleStream synchronizedStream(DoubleStream stream, Object monitor) {
|
||||
@ -1205,6 +1264,7 @@ public class SyncStreams {
|
||||
/*
|
||||
* Private constructor
|
||||
*/
|
||||
private SyncStreams() {}
|
||||
private SyncStreams() {
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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 {
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
@ -110,10 +111,13 @@ public class CharArrayIterator implements CharacterIterator {
|
||||
// @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 exception safety.
|
||||
// SonarLint: "toString()" and "clone()" methods should not return null (java:S2225)
|
||||
// The clause is unreachable: CharacterArrayIterator implements Cloneable and superclass is Object.
|
||||
@SuppressWarnings({"squid:S2975", "squid:S2225"})
|
||||
// And I wouldn't have done that if only CharacterIterator had not required
|
||||
// exception safety.
|
||||
// SonarLint: "toString()" and "clone()" methods should not return null
|
||||
// (java:S2225)
|
||||
// The clause is unreachable: CharacterArrayIterator implements Cloneable
|
||||
// and superclass is Object.
|
||||
@SuppressWarnings({ "squid:S2975", "squid:S2225" })
|
||||
|
||||
@Override
|
||||
public CharArrayIterator clone() {
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
@ -23,11 +24,11 @@ import ru.windcorp.jputil.ArrayUtil;
|
||||
|
||||
/**
|
||||
* @author Javapony
|
||||
*
|
||||
*/
|
||||
public class CharConsumers {
|
||||
|
||||
private CharConsumers() {}
|
||||
private CharConsumers() {
|
||||
}
|
||||
|
||||
public static CharConsumer fillArray(char[] array, int offset, int length) {
|
||||
return new ArrayFiller(array, offset, length);
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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 {
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
@ -102,7 +103,14 @@ 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;
|
||||
@ -113,9 +121,13 @@ public class Escaper {
|
||||
private final boolean strict;
|
||||
|
||||
protected Escaper(
|
||||
char escapeChar, char unicodeEscapeChar,
|
||||
char[] safes, char[] unsafes,
|
||||
boolean preferUnicode, boolean strict) {
|
||||
char escapeChar,
|
||||
char unicodeEscapeChar,
|
||||
char[] safes,
|
||||
char[] unsafes,
|
||||
boolean preferUnicode,
|
||||
boolean strict
|
||||
) {
|
||||
this.escapeChar = escapeChar;
|
||||
this.unicodeEscapeChar = unicodeEscapeChar;
|
||||
this.safes = safes;
|
||||
@ -131,13 +143,19 @@ public class Escaper {
|
||||
throw new IllegalArgumentException("Duplicate unsafe character '" + unsafes[duplicate] + "'");
|
||||
|
||||
for (char c : safes) {
|
||||
if (c == escapeChar) throw new IllegalArgumentException("Safe characters contain escape chatacter");
|
||||
if (c == unicodeEscapeChar) throw new IllegalArgumentException("Safe characters contain Unicode escape chatacter");
|
||||
if (c == escapeChar)
|
||||
throw new IllegalArgumentException("Safe characters contain escape chatacter");
|
||||
if (c == unicodeEscapeChar)
|
||||
throw new IllegalArgumentException("Safe characters contain Unicode escape chatacter");
|
||||
}
|
||||
|
||||
for (char c : unsafes) {
|
||||
if (c == escapeChar) throw new IllegalArgumentException("Unsafe characters contain escape chatacter (escape character is escaped automatically)");
|
||||
if (c == unicodeEscapeChar) throw new IllegalArgumentException("Unsafe characters contain Unicode escape chatacter");
|
||||
if (c == escapeChar)
|
||||
throw new IllegalArgumentException(
|
||||
"Unsafe characters contain escape chatacter (escape character is escaped automatically)"
|
||||
);
|
||||
if (c == unicodeEscapeChar)
|
||||
throw new IllegalArgumentException("Unsafe characters contain Unicode escape chatacter");
|
||||
}
|
||||
}
|
||||
|
||||
@ -151,11 +169,15 @@ public class Escaper {
|
||||
|
||||
public void escape(CharReader src, int length, CharPredicate until, CharConsumer output) {
|
||||
int end;
|
||||
if (length < 0) end = Integer.MAX_VALUE;
|
||||
else end = src.getPosition() + length;
|
||||
while (src.has() &&
|
||||
if (length < 0)
|
||||
end = Integer.MAX_VALUE;
|
||||
else
|
||||
end = src.getPosition() + length;
|
||||
while (
|
||||
src.has() &&
|
||||
src.getPosition() < end &&
|
||||
(until == null || !until.test(src.current())))
|
||||
(until == null || !until.test(src.current()))
|
||||
)
|
||||
escape(src.consume(), output);
|
||||
}
|
||||
|
||||
@ -180,8 +202,9 @@ public class Escaper {
|
||||
}
|
||||
}
|
||||
|
||||
// SonarLint: Assignments should not be made from within sub-expressions (java:S1121)
|
||||
// Seems self-evident enough
|
||||
// SonarLint: Assignments should not be made from within sub-expressions
|
||||
// (java:S1121)
|
||||
// Seems self-evident enough
|
||||
@SuppressWarnings("squid:S1121")
|
||||
|
||||
private void escapeAsHex(char c, CharConsumer output) {
|
||||
@ -190,19 +213,23 @@ public class Escaper {
|
||||
output.accept(StringUtil.hexDigit(c >>= (4 * 3)));
|
||||
output.accept(StringUtil.hexDigit(c >>= (4 * 2)));
|
||||
output.accept(StringUtil.hexDigit(c >>= (4 * 1)));
|
||||
output.accept(StringUtil.hexDigit(c >> (4 * 0)));
|
||||
output.accept(StringUtil.hexDigit(c >> (4 * 0)));
|
||||
}
|
||||
|
||||
public int getEscapedLength(CharReader src, int length, CharPredicate until) {
|
||||
int end;
|
||||
if (length < 0) end = Integer.MAX_VALUE;
|
||||
else end = src.getPosition() + length;
|
||||
if (length < 0)
|
||||
end = Integer.MAX_VALUE;
|
||||
else
|
||||
end = src.getPosition() + length;
|
||||
|
||||
int result = 0;
|
||||
|
||||
while (src.has() &&
|
||||
while (
|
||||
src.has() &&
|
||||
src.getPosition() < end &&
|
||||
(until == null || !until.test(src.current()))) {
|
||||
(until == null || !until.test(src.current()))
|
||||
) {
|
||||
result += getEscapedLength(src.consume());
|
||||
}
|
||||
|
||||
@ -226,11 +253,15 @@ public class Escaper {
|
||||
|
||||
public void unescape(CharReader src, int length, CharPredicate until, CharConsumer output) throws EscapeException {
|
||||
int end;
|
||||
if (length < 0) end = Integer.MAX_VALUE;
|
||||
else end = src.getPosition() + length;
|
||||
while (src.has() &&
|
||||
if (length < 0)
|
||||
end = Integer.MAX_VALUE;
|
||||
else
|
||||
end = src.getPosition() + length;
|
||||
while (
|
||||
src.has() &&
|
||||
src.getPosition() < end &&
|
||||
(until == null || !until.test(src.current()))) {
|
||||
(until == null || !until.test(src.current()))
|
||||
) {
|
||||
output.accept(unescapeOneSequence(src));
|
||||
}
|
||||
}
|
||||
@ -251,12 +282,10 @@ 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());
|
||||
@ -279,14 +308,18 @@ public class Escaper {
|
||||
|
||||
public int getUnescapedLength(CharReader src, int length, CharPredicate until) {
|
||||
int end;
|
||||
if (length < 0) end = Integer.MAX_VALUE;
|
||||
else end = src.getPosition() + length;
|
||||
if (length < 0)
|
||||
end = Integer.MAX_VALUE;
|
||||
else
|
||||
end = src.getPosition() + length;
|
||||
|
||||
int result = 0;
|
||||
|
||||
while (src.has() &&
|
||||
while (
|
||||
src.has() &&
|
||||
src.getPosition() < end &&
|
||||
(until == null || !until.test(src.current()))) {
|
||||
(until == null || !until.test(src.current()))
|
||||
) {
|
||||
skipOneSequence(src);
|
||||
result++;
|
||||
}
|
||||
@ -296,7 +329,7 @@ public class Escaper {
|
||||
|
||||
public void skipOneSequence(CharReader src) {
|
||||
if (
|
||||
src.current() == escapeChar
|
||||
src.current() == escapeChar
|
||||
&&
|
||||
src.next() == unicodeEscapeChar
|
||||
) {
|
||||
@ -425,13 +458,20 @@ public class Escaper {
|
||||
*/
|
||||
|
||||
private static int hexValue(char c) throws EscapeException {
|
||||
if (c < '0') throw thisIsNotAHexDigit(c);
|
||||
if (c <= '9') return c - '0';
|
||||
if (c < 'A') throw thisIsNotAHexDigit(c);
|
||||
if (c <= 'F') return c - 'A';
|
||||
if (c < 'a') throw thisIsNotAHexDigit(c);
|
||||
if (c <= 'f') return c - 'a';
|
||||
if (c == CharReader.DONE) throw new EscapeException("Incomplete Unicode escape sequence at the end");
|
||||
if (c < '0')
|
||||
throw thisIsNotAHexDigit(c);
|
||||
if (c <= '9')
|
||||
return c - '0';
|
||||
if (c < 'A')
|
||||
throw thisIsNotAHexDigit(c);
|
||||
if (c <= 'F')
|
||||
return c - 'A';
|
||||
if (c < 'a')
|
||||
throw thisIsNotAHexDigit(c);
|
||||
if (c <= 'f')
|
||||
return c - 'a';
|
||||
if (c == CharReader.DONE)
|
||||
throw new EscapeException("Incomplete Unicode escape sequence at the end");
|
||||
throw thisIsNotAHexDigit(c);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -11,7 +11,11 @@
|
||||
* 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.jputil.chars;
|
||||
|
||||
import java.text.CharacterIterator;
|
||||
@ -76,7 +80,8 @@ public class FancyCharacterIterator implements CharacterIterator {
|
||||
StringBuilder sb = new StringBuilder("\"");
|
||||
sb.append(data);
|
||||
sb.append("\"\n ");
|
||||
for (int i = 0; i < obj.getIndex(); ++i) sb.append(' ');
|
||||
for (int i = 0; i < obj.getIndex(); ++i)
|
||||
sb.append(' ');
|
||||
sb.append("^ Here.");
|
||||
return sb.toString();
|
||||
}
|
||||
@ -84,10 +89,13 @@ public class FancyCharacterIterator implements CharacterIterator {
|
||||
// @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 exception safety.
|
||||
// SonarLint: "toString()" and "clone()" methods should not return null (java:S2225)
|
||||
// The clause is unreachable: CharacterArrayIterator implements Cloneable and superclass is Object.
|
||||
@SuppressWarnings({"squid:S2975", "squid:S2225"})
|
||||
// And I wouldn't have done that if only CharacterIterator had not required
|
||||
// exception safety.
|
||||
// SonarLint: "toString()" and "clone()" methods should not return null
|
||||
// (java:S2225)
|
||||
// The clause is unreachable: CharacterArrayIterator implements Cloneable
|
||||
// and superclass is Object.
|
||||
@SuppressWarnings({ "squid:S2975", "squid:S2225" })
|
||||
|
||||
@Override
|
||||
public FancyCharacterIterator clone() {
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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 {
|
||||
@ -41,7 +42,7 @@ public class IndentedStringBuilder {
|
||||
}
|
||||
|
||||
public IndentedStringBuilder() {
|
||||
this(new char[] {' '});
|
||||
this(new char[] { ' ' });
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -65,7 +66,8 @@ public class IndentedStringBuilder {
|
||||
protected void updateIndent() {
|
||||
if (indentLevel < indentCache.length) {
|
||||
indent = indentCache[indentLevel];
|
||||
if (indent != null) return;
|
||||
if (indent != null)
|
||||
return;
|
||||
}
|
||||
|
||||
char[] fill = getIndentFill();
|
||||
@ -115,7 +117,8 @@ public class IndentedStringBuilder {
|
||||
}
|
||||
|
||||
public IndentedStringBuilder appendRaw(String str) {
|
||||
if (str.isEmpty()) return this; // Do not append indent
|
||||
if (str.isEmpty())
|
||||
return this; // Do not append indent
|
||||
|
||||
if (!indentApplied) {
|
||||
sb.append(indent);
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
@ -33,18 +34,19 @@ import ru.windcorp.jputil.ArrayUtil;
|
||||
|
||||
public class StringUtil {
|
||||
|
||||
private StringUtil() {}
|
||||
private StringUtil() {
|
||||
}
|
||||
|
||||
private static final String NULL_PLACEHOLDER = "[null]";
|
||||
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
|
||||
T[] array,
|
||||
String separator,
|
||||
String empty,
|
||||
String nullPlaceholder,
|
||||
String nullArray
|
||||
) {
|
||||
|
||||
if (separator == null) {
|
||||
@ -78,11 +80,11 @@ public class StringUtil {
|
||||
}
|
||||
|
||||
public static String iteratorToString(
|
||||
Iterator<?> iterator,
|
||||
String separator,
|
||||
String empty,
|
||||
String nullPlaceholder,
|
||||
String nullIterator
|
||||
Iterator<?> iterator,
|
||||
String separator,
|
||||
String empty,
|
||||
String nullPlaceholder,
|
||||
String nullIterator
|
||||
) {
|
||||
|
||||
if (separator == null) {
|
||||
@ -118,11 +120,11 @@ public class StringUtil {
|
||||
}
|
||||
|
||||
public static String iterableToString(
|
||||
Iterable<?> iterable,
|
||||
String separator,
|
||||
String empty,
|
||||
String nullPlaceholder,
|
||||
String nullIterable
|
||||
Iterable<?> iterable,
|
||||
String separator,
|
||||
String empty,
|
||||
String nullPlaceholder,
|
||||
String nullIterable
|
||||
) {
|
||||
|
||||
if (separator == null) {
|
||||
@ -145,40 +147,43 @@ public class StringUtil {
|
||||
}
|
||||
|
||||
public static <T> String supplierToString(
|
||||
IntFunction<T> supplier,
|
||||
int length,
|
||||
String separator,
|
||||
String empty,
|
||||
String nullPlaceholder,
|
||||
String nullSupplier
|
||||
IntFunction<T> supplier,
|
||||
int length,
|
||||
String separator,
|
||||
String empty,
|
||||
String nullPlaceholder,
|
||||
String nullSupplier
|
||||
) {
|
||||
|
||||
if (separator == null) throw new IllegalArgumentException(new NullPointerException());
|
||||
if (supplier == null) return nullSupplier;
|
||||
if (length == 0) return empty;
|
||||
if (separator == null)
|
||||
throw new IllegalArgumentException(new NullPointerException());
|
||||
if (supplier == null)
|
||||
return nullSupplier;
|
||||
if (length == 0)
|
||||
return empty;
|
||||
|
||||
if (length > 0) {
|
||||
return supplierToStringExactly(
|
||||
supplier,
|
||||
length,
|
||||
separator,
|
||||
nullPlaceholder
|
||||
supplier,
|
||||
length,
|
||||
separator,
|
||||
nullPlaceholder
|
||||
);
|
||||
} else {
|
||||
return supplierToStringUntilNull(
|
||||
supplier,
|
||||
separator,
|
||||
empty
|
||||
supplier,
|
||||
separator,
|
||||
empty
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static <T> String supplierToStringExactly(
|
||||
IntFunction<T> supplier,
|
||||
int length,
|
||||
String separator,
|
||||
String nullPlaceholder
|
||||
IntFunction<T> supplier,
|
||||
int length,
|
||||
String separator,
|
||||
String nullPlaceholder
|
||||
) {
|
||||
T element = supplier.apply(0);
|
||||
|
||||
@ -194,9 +199,9 @@ public class StringUtil {
|
||||
}
|
||||
|
||||
private static <T> String supplierToStringUntilNull(
|
||||
IntFunction<T> supplier,
|
||||
String separator,
|
||||
String empty
|
||||
IntFunction<T> supplier,
|
||||
String separator,
|
||||
String empty
|
||||
) {
|
||||
T element = supplier.apply(0);
|
||||
|
||||
@ -258,9 +263,12 @@ public class StringUtil {
|
||||
}
|
||||
|
||||
public static String[] split(String src, char separator, int arrayLength) {
|
||||
if (arrayLength < 0) throw illegalArrayLength(arrayLength);
|
||||
else if (arrayLength == 0) return new String[0];
|
||||
else if (arrayLength == 1) return new String[] { src };
|
||||
if (arrayLength < 0)
|
||||
throw illegalArrayLength(arrayLength);
|
||||
else if (arrayLength == 0)
|
||||
return new String[0];
|
||||
else if (arrayLength == 1)
|
||||
return new String[] { src };
|
||||
|
||||
String[] result = new String[arrayLength];
|
||||
|
||||
@ -299,17 +307,19 @@ public class StringUtil {
|
||||
}
|
||||
|
||||
public static String[] split(String src, int arrayLength, char... separator) {
|
||||
if (arrayLength < 0) throw illegalArrayLength(arrayLength);
|
||||
else if (arrayLength == 0) return new String[0];
|
||||
else if (arrayLength == 1) return new String[] { src };
|
||||
if (arrayLength < 0)
|
||||
throw illegalArrayLength(arrayLength);
|
||||
else if (arrayLength == 0)
|
||||
return new String[0];
|
||||
else if (arrayLength == 1)
|
||||
return new String[] { src };
|
||||
|
||||
String[] result = new String[arrayLength];
|
||||
|
||||
int resultIndex = 0;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
charLoop:
|
||||
for (char c : src.toCharArray()) {
|
||||
charLoop: for (char c : src.toCharArray()) {
|
||||
if ((resultIndex + 1) < arrayLength) {
|
||||
for (char h : separator) {
|
||||
if (c == h) {
|
||||
@ -331,7 +341,8 @@ public class StringUtil {
|
||||
public static int count(String src, CharPredicate test) {
|
||||
int i = 0;
|
||||
for (char c : src.toCharArray()) {
|
||||
if (test.test(c)) i++;
|
||||
if (test.test(c))
|
||||
i++;
|
||||
}
|
||||
|
||||
return i;
|
||||
@ -342,19 +353,21 @@ public class StringUtil {
|
||||
}
|
||||
|
||||
public static String[] split(String src, int arrayLength, CharPredicate test) {
|
||||
if (arrayLength < 0) throw illegalArrayLength(arrayLength);
|
||||
else if (arrayLength == 0) return new String[0];
|
||||
else if (arrayLength == 1) return new String[] { src };
|
||||
if (arrayLength < 0)
|
||||
throw illegalArrayLength(arrayLength);
|
||||
else if (arrayLength == 0)
|
||||
return new String[0];
|
||||
else if (arrayLength == 1)
|
||||
return new String[] { src };
|
||||
|
||||
String[] result = new String[arrayLength];
|
||||
|
||||
int resultIndex = 0;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
charLoop:
|
||||
for (char c : src.toCharArray()) {
|
||||
charLoop: for (char c : src.toCharArray()) {
|
||||
if (
|
||||
(resultIndex + 1) < arrayLength
|
||||
(resultIndex + 1) < arrayLength
|
||||
&&
|
||||
test.test(c)
|
||||
) {
|
||||
@ -372,16 +385,21 @@ public class StringUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits {@code src} at index {@code at} discarding the character at that index.
|
||||
* Splits {@code src} at index {@code at} discarding the character at that
|
||||
* index.
|
||||
* <p>
|
||||
* Indices {@code 0} and {@code src.length() - 1} produce {@code str} excluding
|
||||
* Indices {@code 0} and {@code src.length() - 1} produce {@code str}
|
||||
* 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}
|
||||
* @return an array containing the substrings, in order of encounter in {@code src}.
|
||||
* Its length is always 2.
|
||||
* @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.
|
||||
*/
|
||||
public static String[] splitAt(String src, int at) {
|
||||
Objects.requireNonNull(src, "src");
|
||||
@ -393,42 +411,50 @@ public class StringUtil {
|
||||
}
|
||||
|
||||
if (at == 0) {
|
||||
return new String[] {"", src.substring(1)};
|
||||
return new String[] { "", src.substring(1) };
|
||||
} else if (at == src.length()) {
|
||||
return new String[] {src.substring(0, src.length() - 1), ""};
|
||||
return new String[] { src.substring(0, src.length() - 1), "" };
|
||||
}
|
||||
|
||||
return new String[] {
|
||||
src.substring(0, at),
|
||||
src.substring(at + 1)
|
||||
src.substring(0, at),
|
||||
src.substring(at + 1)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits {@code src} at indices {@code at} discarding characters at those indices.
|
||||
* Splits {@code src} at indices {@code at} discarding characters at those
|
||||
* indices.
|
||||
* <p>
|
||||
* Indices {@code 0} and {@code src.length() - 1} produce extra zero-length outputs.
|
||||
* Indices {@code 0} and {@code src.length() - 1} produce extra zero-length
|
||||
* outputs.
|
||||
* Duplicate indices produce extra zero-length outputs.
|
||||
* <p>
|
||||
* Examples:
|
||||
*
|
||||
* <pre>
|
||||
* splitAt("a.b.c", new int[] {1, 3}) -> {"a", "b", "c"}
|
||||
* splitAt("a..b", new int[] {1, 2}) -> {"a", "", "b"}
|
||||
* splitAt(".b.", new int[] {0, 2}) -> {"", "b", ""}
|
||||
* splitAt("a.b", new int[] {1, 1, 1}) -> {"a", "", "", "b"}
|
||||
* splitAt("a.b.c", 1, 3) -> {"a", "b", "c"}
|
||||
* splitAt("a..b", 1, 2) -> {"a", "", "b"}
|
||||
* splitAt(".b.", 0, 2) -> {"", "b", ""}
|
||||
* 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}
|
||||
* @return an array containing the substrings, in order of encounter in {@code src}.
|
||||
* Its length is always {@code at.length + 1}.
|
||||
* @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}.
|
||||
*/
|
||||
public static String[] splitAt(String src, int... at) {
|
||||
Objects.requireNonNull(src, "src");
|
||||
Objects.requireNonNull(at, "at");
|
||||
|
||||
if (at.length == 0) return new String[] {src};
|
||||
if (at.length == 1) return splitAt(src, at[0]);
|
||||
if (at.length == 0)
|
||||
return new String[] { src };
|
||||
if (at.length == 1)
|
||||
return splitAt(src, at[0]);
|
||||
|
||||
int[] indices; // Always sorted
|
||||
|
||||
@ -481,8 +507,7 @@ public class StringUtil {
|
||||
char current;
|
||||
int resultIndex = 0;
|
||||
|
||||
mainLoop:
|
||||
for (int srcIndex = 0; srcIndex < src.length(); ++srcIndex) {
|
||||
mainLoop: for (int srcIndex = 0; srcIndex < src.length(); ++srcIndex) {
|
||||
current = src.charAt(srcIndex);
|
||||
|
||||
for (char c : remove) {
|
||||
@ -510,13 +535,13 @@ public class StringUtil {
|
||||
|
||||
Reader reader = new InputStreamReader(is, encoding);
|
||||
while (true) {
|
||||
int readChars = reader.read(buffer, 0, buffer.length);
|
||||
int readChars = reader.read(buffer, 0, buffer.length);
|
||||
|
||||
if (readChars == -1) {
|
||||
break;
|
||||
}
|
||||
if (readChars == -1) {
|
||||
break;
|
||||
}
|
||||
|
||||
result.append(buffer, 0, readChars);
|
||||
result.append(buffer, 0, readChars);
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
@ -528,12 +553,15 @@ 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)) {
|
||||
return false; // At least one of the arrays does not contain at least one of the required elements
|
||||
return false; // At least one of the arrays does not contain at
|
||||
// least one of the required elements
|
||||
}
|
||||
|
||||
for (int i = beginPos; i < endPos; ++i) {
|
||||
@ -563,9 +591,12 @@ 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.<p>
|
||||
* Examples:<p>
|
||||
* Finds and returns the index of the specified appearance of the specified
|
||||
* character
|
||||
* in the given array. The search starts at index 0.
|
||||
* <p>
|
||||
* Examples:
|
||||
* <p>
|
||||
* <table border="1">
|
||||
* <tr>
|
||||
* <th align="center"><code>src</code></th>
|
||||
@ -573,15 +604,38 @@ public class StringUtil {
|
||||
* <th align="center"><code>skip</code></th>
|
||||
* <th align="center">returns</th>
|
||||
* </tr>
|
||||
* <tr align="center"><td><code>a<u>.</u>b.c</code></td><td><code>'.'</code></td><td><code>0</code></td><td><code>1</code></td></tr>
|
||||
* <tr align="center"><td><code>a.b<u>.</u>c</code></td><td><code>'.'</code></td><td><code>1</code></td><td><code>3</code></td></tr>
|
||||
* <tr align="center"><td><code>a.b.c</code></td><td><code>'.'</code></td><td><code>2</code></td><td><code>-1</code></td></tr>
|
||||
* <tr align="center"><td><code>a.b.c</code></td><td><code>'d'</code></td><td><i>any</i></td><td><code>-1</code></td></tr>
|
||||
* <tr align="center">
|
||||
* <td><code>a<u>.</u>b.c</code></td>
|
||||
* <td><code>'.'</code></td>
|
||||
* <td><code>0</code></td>
|
||||
* <td><code>1</code></td>
|
||||
* </tr>
|
||||
* <tr align="center">
|
||||
* <td><code>a.b<u>.</u>c</code></td>
|
||||
* <td><code>'.'</code></td>
|
||||
* <td><code>1</code></td>
|
||||
* <td><code>3</code></td>
|
||||
* </tr>
|
||||
* <tr align="center">
|
||||
* <td><code>a.b.c</code></td>
|
||||
* <td><code>'.'</code></td>
|
||||
* <td><code>2</code></td>
|
||||
* <td><code>-1</code></td>
|
||||
* </tr>
|
||||
* <tr align="center">
|
||||
* <td><code>a.b.c</code></td>
|
||||
* <td><code>'d'</code></td>
|
||||
* <td><i>any</i></td>
|
||||
* <td><code>-1</code></td>
|
||||
* </tr>
|
||||
* </table>
|
||||
* @param src - the array to search in.
|
||||
*
|
||||
* @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.
|
||||
* @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)
|
||||
*/
|
||||
public static int indexFromBeginning(char[] src, char target, int skip) {
|
||||
@ -598,9 +652,13 @@ 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 <code>src.length - 1</code>.<p>
|
||||
* Examples:<p>
|
||||
* Finds and returns the index of the specified appearance of the specified
|
||||
* character
|
||||
* in the given array. The search starts at index
|
||||
* <code>src.length - 1</code>.
|
||||
* <p>
|
||||
* Examples:
|
||||
* <p>
|
||||
* <table border="1">
|
||||
* <tr>
|
||||
* <th align="center"><code>src</code></th>
|
||||
@ -608,16 +666,39 @@ public class StringUtil {
|
||||
* <th align="center"><code>skip</code></th>
|
||||
* <th align="center">returns</th>
|
||||
* </tr>
|
||||
* <tr align="center"><td><code>a.b<u>.</u>c</code></td><td><code>'.'</code></td><td><code>0</code></td><td><code>3</code></td></tr>
|
||||
* <tr align="center"><td><code>a<u>.</u>b.c</code></td><td><code>'.'</code></td><td><code>1</code></td><td><code>1</code></td></tr>
|
||||
* <tr align="center"><td><code>a.b.c</code></td><td><code>'.'</code></td><td><code>2</code></td><td><code>-1</code></td></tr>
|
||||
* <tr align="center"><td><code>a.b.c</code></td><td><code>'d'</code></td><td><i>any</i></td><td><code>-1</code></td></tr>
|
||||
* <tr align="center">
|
||||
* <td><code>a.b<u>.</u>c</code></td>
|
||||
* <td><code>'.'</code></td>
|
||||
* <td><code>0</code></td>
|
||||
* <td><code>3</code></td>
|
||||
* </tr>
|
||||
* <tr align="center">
|
||||
* <td><code>a<u>.</u>b.c</code></td>
|
||||
* <td><code>'.'</code></td>
|
||||
* <td><code>1</code></td>
|
||||
* <td><code>1</code></td>
|
||||
* </tr>
|
||||
* <tr align="center">
|
||||
* <td><code>a.b.c</code></td>
|
||||
* <td><code>'.'</code></td>
|
||||
* <td><code>2</code></td>
|
||||
* <td><code>-1</code></td>
|
||||
* </tr>
|
||||
* <tr align="center">
|
||||
* <td><code>a.b.c</code></td>
|
||||
* <td><code>'d'</code></td>
|
||||
* <td><i>any</i></td>
|
||||
* <td><code>-1</code></td>
|
||||
* </tr>
|
||||
* </table>
|
||||
* @param src - the array to search in.
|
||||
*
|
||||
* @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.
|
||||
* @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.
|
||||
* @see StringUtil#indexFromBeginning(char[], char, int)
|
||||
*/
|
||||
public static int indexFromEnd(char[] src, char target, int skip) {
|
||||
@ -691,32 +772,32 @@ public class StringUtil {
|
||||
}
|
||||
|
||||
public static String center(String src, int length) {
|
||||
return center(src, length, ' ');
|
||||
}
|
||||
return center(src, length, ' ');
|
||||
}
|
||||
|
||||
public static String center(String src, int length, char filler) {
|
||||
if (length <= 0) {
|
||||
public static String center(String src, int length, char filler) {
|
||||
if (length <= 0) {
|
||||
throw new IllegalArgumentException("length must be positive (" + length + ")");
|
||||
}
|
||||
|
||||
if (src == null || length <= src.length()) {
|
||||
return src;
|
||||
}
|
||||
if (src == null || length <= src.length()) {
|
||||
return src;
|
||||
}
|
||||
|
||||
char[] result = new char[length];
|
||||
char[] result = new char[length];
|
||||
|
||||
int leftPaddingLength = (length - src.length()) / 2;
|
||||
int leftPaddingLength = (length - src.length()) / 2;
|
||||
|
||||
Arrays.fill(result, 0, leftPaddingLength, filler);
|
||||
Arrays.fill(result, 0, leftPaddingLength, filler);
|
||||
|
||||
for (int i = 0; i < src.length(); ++i) {
|
||||
result[i + leftPaddingLength] = src.charAt(i);
|
||||
}
|
||||
for (int i = 0; i < src.length(); ++i) {
|
||||
result[i + leftPaddingLength] = src.charAt(i);
|
||||
}
|
||||
|
||||
Arrays.fill(result, leftPaddingLength + src.length(), result.length, filler);
|
||||
Arrays.fill(result, leftPaddingLength + src.length(), result.length, filler);
|
||||
|
||||
return new String(result);
|
||||
}
|
||||
return new String(result);
|
||||
}
|
||||
|
||||
public static int countWords(String src) {
|
||||
int i = 0;
|
||||
@ -792,8 +873,12 @@ 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 {
|
||||
@ -811,15 +896,21 @@ public class StringUtil {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
int length = 1;
|
||||
for (String[] array : parts) length *= array.length;
|
||||
for (String[] array : parts)
|
||||
length *= array.length;
|
||||
String[] result = new String[length];
|
||||
|
||||
buildCombinations(sb, result, new int[] {0}, parts, 0);
|
||||
buildCombinations(sb, result, new int[] { 0 }, parts, 0);
|
||||
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 {
|
||||
@ -887,8 +978,7 @@ public class StringUtil {
|
||||
result[1] = 'x';
|
||||
|
||||
for (int digit = 0; digit < digits; ++digit) {
|
||||
result[(digits - digit - 1) + 2] =
|
||||
hexDigit(x, digit);
|
||||
result[(digits - digit - 1) + 2] = hexDigit(x, digit);
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -896,14 +986,16 @@ public class StringUtil {
|
||||
|
||||
private static char hexDigit(long value, int digit) {
|
||||
return hexDigit(
|
||||
(int) (value >>> (4 * digit))
|
||||
(int) (value >>> (4 * digit))
|
||||
& 0xF
|
||||
);
|
||||
}
|
||||
|
||||
public static char hexDigit(int value) {
|
||||
if (value < 0xA) return (char) ('0' + value);
|
||||
else return (char) ('A' - 0xA + value);
|
||||
if (value < 0xA)
|
||||
return (char) ('0' + value);
|
||||
else
|
||||
return (char) ('A' - 0xA + value);
|
||||
}
|
||||
|
||||
public static String replaceAll(String source, String substring, String replacement) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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 {
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
@ -85,11 +86,14 @@ public class WordReader implements Iterator<String> {
|
||||
while (true) {
|
||||
c = nextChar();
|
||||
|
||||
if (isExhausted) break;
|
||||
if (isExhausted)
|
||||
break;
|
||||
|
||||
if (Character.isWhitespace(c)) {
|
||||
if (length == 0) continue;
|
||||
else break;
|
||||
if (length == 0)
|
||||
continue;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (wordBuffer.length == length) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,20 +14,22 @@
|
||||
*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @author Javapony
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractCharReader implements CharReader {
|
||||
|
||||
protected static final int DEFAULT_MARK_STACK_SIZE = 8;
|
||||
|
||||
/**
|
||||
* 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()}
|
||||
* 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.
|
||||
*/
|
||||
protected int position = 0;
|
||||
@ -36,12 +38,12 @@ public abstract class AbstractCharReader implements CharReader {
|
||||
private int nextMark = 0;
|
||||
|
||||
protected static int closestGreaterPowerOf2(int x) {
|
||||
x |= x >> 1;
|
||||
x |= x >> 2;
|
||||
x |= x >> 4;
|
||||
x |= x >> 8;
|
||||
x |= x >> 16;
|
||||
return x + 1;
|
||||
x |= x >> 1;
|
||||
x |= x >> 2;
|
||||
x |= x >> 4;
|
||||
x |= x >> 8;
|
||||
x |= x >> 16;
|
||||
return x + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -80,7 +82,8 @@ public abstract class AbstractCharReader implements CharReader {
|
||||
}
|
||||
|
||||
private void ensureMarksCapacity() {
|
||||
if (nextMark < marks.length) return;
|
||||
if (nextMark < marks.length)
|
||||
return;
|
||||
int[] newMarks = new int[closestGreaterPowerOf2(nextMark)];
|
||||
System.arraycopy(marks, 0, newMarks, 0, nextMark);
|
||||
marks = newMarks;
|
||||
@ -96,7 +99,8 @@ public abstract class AbstractCharReader implements CharReader {
|
||||
reset();
|
||||
|
||||
sb.append("\"\n ");
|
||||
for (int i = 0; i < position; ++i) sb.append(' ');
|
||||
for (int i = 0; i < position; ++i)
|
||||
sb.append(' ');
|
||||
sb.append("^ (pos " + position + ")");
|
||||
return sb.toString();
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
@ -23,7 +24,6 @@ import ru.windcorp.jputil.ArrayUtil;
|
||||
|
||||
/**
|
||||
* @author Javapony
|
||||
*
|
||||
*/
|
||||
public class ArrayCharReader extends AbstractCharReader {
|
||||
|
||||
@ -42,7 +42,8 @@ public class ArrayCharReader extends AbstractCharReader {
|
||||
*/
|
||||
@Override
|
||||
public char current() {
|
||||
if (position >= length) return DONE;
|
||||
if (position >= length)
|
||||
return DONE;
|
||||
if (position < 0)
|
||||
throw new IllegalStateException("Position " + position + " is invalid");
|
||||
return array[position + offset];
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,12 +14,12 @@
|
||||
*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @author Javapony
|
||||
*
|
||||
*/
|
||||
public abstract class BufferedCharReader extends AbstractCharReader {
|
||||
|
||||
@ -42,7 +42,9 @@ public abstract class BufferedCharReader extends AbstractCharReader {
|
||||
|
||||
/**
|
||||
* Acquires the next character.
|
||||
* @return the character or {@link #DONE} if the end of the reader has been reached
|
||||
*
|
||||
* @return the character or {@link #DONE} if the end of the reader has been
|
||||
* reached
|
||||
*/
|
||||
protected abstract char pullChar();
|
||||
|
||||
@ -65,7 +67,8 @@ public abstract class BufferedCharReader extends AbstractCharReader {
|
||||
}
|
||||
|
||||
private int pullChars(int offset, int length) {
|
||||
if (exhausted || length == 0) return 0;
|
||||
if (exhausted || length == 0)
|
||||
return 0;
|
||||
|
||||
int pulled = pullChars(buffer, offset, length);
|
||||
if (pulled != length) {
|
||||
@ -82,7 +85,8 @@ public abstract class BufferedCharReader extends AbstractCharReader {
|
||||
}
|
||||
|
||||
if (getPosition() >= bufferNextIndex) {
|
||||
if (exhausted) return DONE;
|
||||
if (exhausted)
|
||||
return DONE;
|
||||
|
||||
ensureBufferCapacity();
|
||||
|
||||
@ -92,7 +96,8 @@ public abstract class BufferedCharReader extends AbstractCharReader {
|
||||
int pulled = pullChars(bufferNextIndex, needToPull);
|
||||
bufferNextIndex += pulled;
|
||||
|
||||
if (exhausted) return DONE;
|
||||
if (exhausted)
|
||||
return DONE;
|
||||
}
|
||||
|
||||
// TODO test the shit out of current()
|
||||
@ -101,7 +106,8 @@ public abstract class BufferedCharReader extends AbstractCharReader {
|
||||
}
|
||||
|
||||
private void ensureBufferCapacity() {
|
||||
if (getPosition() < buffer.length) return;
|
||||
if (getPosition() < buffer.length)
|
||||
return;
|
||||
char[] newBuffer = new char[closestGreaterPowerOf2(getPosition())];
|
||||
System.arraycopy(buffer, 0, newBuffer, 0, bufferNextIndex);
|
||||
buffer = newBuffer;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
@ -26,7 +27,6 @@ import ru.windcorp.jputil.chars.Escaper;
|
||||
|
||||
/**
|
||||
* @author Javapony
|
||||
*
|
||||
*/
|
||||
|
||||
// SonarLint: Constants should not be defined in interfaces (java:S1214)
|
||||
@ -38,7 +38,9 @@ public interface CharReader {
|
||||
char DONE = '\uFFFF';
|
||||
|
||||
char current();
|
||||
|
||||
int getPosition();
|
||||
|
||||
int setPosition(int position);
|
||||
|
||||
default char next() {
|
||||
@ -94,7 +96,8 @@ public interface CharReader {
|
||||
default char[] getChars(int length) {
|
||||
char[] result = new char[length];
|
||||
int from = getChars(result);
|
||||
if (from != length) Arrays.fill(result, from, length, DONE);
|
||||
if (from != length)
|
||||
Arrays.fill(result, from, length, DONE);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -104,7 +107,8 @@ public interface CharReader {
|
||||
|
||||
default String getString(int length) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < length && !isEnd(); ++i) sb.append(consume());
|
||||
for (int i = 0; i < length && !isEnd(); ++i)
|
||||
sb.append(consume());
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@ -114,8 +118,10 @@ public interface CharReader {
|
||||
|
||||
default boolean match(CharSequence seq) {
|
||||
for (int i = 0; i < seq.length(); ++i) {
|
||||
if (isEnd()) return false;
|
||||
if (current() != seq.charAt(i)) return false;
|
||||
if (isEnd())
|
||||
return false;
|
||||
if (current() != seq.charAt(i))
|
||||
return false;
|
||||
next();
|
||||
}
|
||||
|
||||
@ -135,8 +141,10 @@ public interface CharReader {
|
||||
|
||||
default boolean match(char[] array) {
|
||||
for (int i = 0; i < array.length; ++i) {
|
||||
if (isEnd()) return false;
|
||||
if (current() != array[i]) return false;
|
||||
if (isEnd())
|
||||
return false;
|
||||
if (current() != array[i])
|
||||
return false;
|
||||
next();
|
||||
}
|
||||
|
||||
@ -170,8 +178,10 @@ public interface CharReader {
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips to the end of the current line. Both <code>"\n"</code>, <code>"\r"</code>
|
||||
* Skips to the end of the current line. Both <code>"\n"</code>,
|
||||
* <code>"\r"</code>
|
||||
* and <code>"\r\n"</code> are considered line separators.
|
||||
*
|
||||
* @return the amount of characters in the skipped line
|
||||
*/
|
||||
default int skipLine() {
|
||||
@ -209,7 +219,8 @@ public interface CharReader {
|
||||
reset();
|
||||
|
||||
char[] result = new char[length];
|
||||
for (int i = 0; i < length; ++i) result[i] = consume();
|
||||
for (int i = 0; i < length; ++i)
|
||||
result[i] = consume();
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -234,7 +245,8 @@ public interface CharReader {
|
||||
reset();
|
||||
|
||||
char[] result = new char[length];
|
||||
for (int i = 0; i < result.length; ++i) result[i] = consume();
|
||||
for (int i = 0; i < result.length; ++i)
|
||||
result[i] = consume();
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -242,13 +254,15 @@ public interface CharReader {
|
||||
mark();
|
||||
int result = 0;
|
||||
|
||||
while (consume() != DONE) result++;
|
||||
while (consume() != DONE)
|
||||
result++;
|
||||
|
||||
reset();
|
||||
return result;
|
||||
}
|
||||
|
||||
int mark();
|
||||
|
||||
int forget();
|
||||
|
||||
default int reset() {
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
@ -29,11 +30,11 @@ import ru.windcorp.jputil.chars.CharSupplier;
|
||||
|
||||
/**
|
||||
* @author Javapony
|
||||
*
|
||||
*/
|
||||
public class CharReaders {
|
||||
|
||||
private CharReaders() {}
|
||||
private CharReaders() {
|
||||
}
|
||||
|
||||
public static CharReader wrap(char[] array, int offset, int length) {
|
||||
return new ArrayCharReader(array, offset, length);
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
@ -22,7 +23,6 @@ import java.io.Reader;
|
||||
|
||||
/**
|
||||
* @author Javapony
|
||||
*
|
||||
*/
|
||||
public class ReaderCharReader extends BufferedCharReader {
|
||||
|
||||
@ -47,7 +47,8 @@ public class ReaderCharReader extends BufferedCharReader {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ru.windcorp.jputil.chars.reader.BufferedCharReader#pullChars(char[], int, int)
|
||||
* @see ru.windcorp.jputil.chars.reader.BufferedCharReader#pullChars(char[],
|
||||
* int, int)
|
||||
*/
|
||||
@Override
|
||||
protected int pullChars(char[] buffer, int offset, int length) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,14 +14,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.jputil.chars.reader;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author Javapony
|
||||
*
|
||||
*/
|
||||
public class StringCharReader extends AbstractCharReader {
|
||||
|
||||
@ -37,7 +37,9 @@ 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 + ")");
|
||||
throw new IllegalArgumentException(
|
||||
"String contains [0; " + str.length() + "), requested [" + offset + "; " + end + ")"
|
||||
);
|
||||
|
||||
this.offset = offset;
|
||||
this.length = length;
|
||||
@ -48,7 +50,8 @@ public class StringCharReader extends AbstractCharReader {
|
||||
*/
|
||||
@Override
|
||||
public char current() {
|
||||
if (position >= length) return DONE;
|
||||
if (position >= length)
|
||||
return DONE;
|
||||
if (position < 0)
|
||||
throw new IllegalStateException("Position " + position + " is invalid");
|
||||
return str.charAt(position + offset);
|
||||
|
@ -1,3 +1,21 @@
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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.jputil.functions;
|
||||
|
||||
@FunctionalInterface
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
@ -43,8 +44,9 @@ 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);
|
||||
@ -52,8 +54,9 @@ 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) {
|
||||
BiConsumer<? super T, ? super U> first,
|
||||
ThrowingBiConsumer<? super T, ? super U, E> second
|
||||
) {
|
||||
return (t, u) -> {
|
||||
first.accept(t, u);
|
||||
second.accept(t, u);
|
||||
@ -61,8 +64,9 @@ 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, 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);
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
@ -38,21 +39,30 @@ public interface ThrowingConsumer<T, E extends Exception> {
|
||||
};
|
||||
}
|
||||
|
||||
public static <T, E extends Exception> ThrowingConsumer<T, E> concat(ThrowingConsumer<? super T, ? extends E> first, 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);
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
@ -27,14 +28,18 @@ 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);
|
||||
} catch (RuntimeException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
if (handler != null) handler.accept(t, (E) e);
|
||||
if (handler != null)
|
||||
handler.accept(t, (E) e);
|
||||
return value == null ? null : value.apply(t);
|
||||
}
|
||||
};
|
||||
@ -53,20 +58,23 @@ 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) {
|
||||
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));
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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,8 +39,8 @@ public interface ThrowingRunnable<E extends Exception> {
|
||||
}
|
||||
|
||||
public static <E extends Exception> ThrowingRunnable<E> concat(
|
||||
ThrowingRunnable<? extends E> first,
|
||||
ThrowingRunnable<? extends E> second
|
||||
ThrowingRunnable<? extends E> first,
|
||||
ThrowingRunnable<? extends E> second
|
||||
) {
|
||||
return () -> {
|
||||
first.run();
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
@ -33,7 +34,8 @@ public interface ThrowingSupplier<T, E extends Exception> {
|
||||
} catch (RuntimeException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
if (handler != null) handler.accept((E) e);
|
||||
if (handler != null)
|
||||
handler.accept((E) e);
|
||||
return value == null ? null : value.get();
|
||||
}
|
||||
};
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
@ -22,7 +23,6 @@ import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* @author Javapony
|
||||
*
|
||||
*/
|
||||
public class FunctionIterator<T, E> implements Iterator<E> {
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
@ -46,8 +47,9 @@ public class PeekingIterator<E> implements Iterator<E> {
|
||||
return next;
|
||||
}
|
||||
|
||||
// SonarLint: "Iterator.next()" methods should throw "NoSuchElementException" (java:S2272)
|
||||
// peek() throws NoSuchElementException as expected
|
||||
// SonarLint: "Iterator.next()" methods should throw
|
||||
// "NoSuchElementException" (java:S2272)
|
||||
// peek() throws NoSuchElementException as expected
|
||||
@SuppressWarnings("squid:S2272")
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
@ -48,8 +49,10 @@ 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();
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
@ -46,7 +47,8 @@ public class Reiterator<E> implements Iterable<E> {
|
||||
public E next() {
|
||||
E result;
|
||||
synchronized (source) {
|
||||
if (!hasNext()) throw new NoSuchElementException();
|
||||
if (!hasNext())
|
||||
throw new NoSuchElementException();
|
||||
result = data.get(index);
|
||||
}
|
||||
index++;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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 {
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* JPUtil
|
||||
* Copyright (C) 2019 Javapony/OLEGSHA
|
||||
* Copyright (C) 2019-2021 OLEGSHA/Javapony 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
@ -33,11 +34,10 @@ public class SelectorSystem<T> {
|
||||
public static final char EXPRESSION_OPEN = '(';
|
||||
public static final char EXPRESSION_CLOSE = ')';
|
||||
|
||||
private final Collection<Selector<T>> selectors =
|
||||
Collections.synchronizedCollection(new ArrayList<Selector<T>>());
|
||||
private final Collection<Selector<T>> selectors = Collections.synchronizedCollection(new ArrayList<Selector<T>>());
|
||||
|
||||
private final Collection<SelectorOperator> operators =
|
||||
Collections.synchronizedCollection(new ArrayList<SelectorOperator>());
|
||||
private final Collection<SelectorOperator> operators = Collections
|
||||
.synchronizedCollection(new ArrayList<SelectorOperator>());
|
||||
|
||||
private String stackPrefix = null;
|
||||
|
||||
@ -125,8 +125,7 @@ public class SelectorSystem<T> {
|
||||
synchronized (getSelectorOperators()) {
|
||||
synchronized (getSelectors()) {
|
||||
|
||||
tokenCycle:
|
||||
while (tokens.hasNext()) {
|
||||
tokenCycle: while (tokens.hasNext()) {
|
||||
token = tokens.next();
|
||||
|
||||
for (SelectorOperator operator : getSelectorOperators()) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020 Wind Corporation
|
||||
* 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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 {
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020 Wind Corporation
|
||||
* 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
@ -42,7 +43,7 @@ public class ProgressiaLauncher {
|
||||
// Analyzers
|
||||
CrashReports.registerAnalyzer(new OutOfMemoryAnalyzer());
|
||||
|
||||
Thread.setDefaultUncaughtExceptionHandler((Thread thread, Throwable t)-> {
|
||||
Thread.setDefaultUncaughtExceptionHandler((Thread thread, Throwable t) -> {
|
||||
CrashReports.crash(t, "Uncaught exception in thread %s", thread.getName());
|
||||
});
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020 Wind Corporation
|
||||
* 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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 {
|
||||
|
@ -1,3 +1,21 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import ru.windcorp.progressia.client.comms.DefaultClientCommsListener;
|
||||
@ -51,9 +69,11 @@ public class Client {
|
||||
return;
|
||||
}
|
||||
|
||||
getCamera().setAnchor(new EntityAnchor(
|
||||
getCamera().setAnchor(
|
||||
new EntityAnchor(
|
||||
getWorld().getEntityRenderable(entity)
|
||||
));
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020 Wind Corporation
|
||||
* 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
@ -40,7 +41,10 @@ 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");
|
||||
}
|
||||
|
@ -1,3 +1,21 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import ru.windcorp.progressia.client.comms.localhost.LocalServerCommsChannel;
|
||||
@ -26,7 +44,7 @@ public class ClientState {
|
||||
WorldData world = new WorldData();
|
||||
|
||||
LocalServerCommsChannel channel = new LocalServerCommsChannel(
|
||||
ServerState.getInstance()
|
||||
ServerState.getInstance()
|
||||
);
|
||||
|
||||
Client client = new Client(world, channel);
|
||||
@ -41,6 +59,7 @@ public class ClientState {
|
||||
|
||||
}
|
||||
|
||||
private ClientState() {}
|
||||
private ClientState() {
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020 Wind Corporation
|
||||
* 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
|
@ -1,5 +1,23 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
public enum AudioFormat {
|
||||
MONO, STEREO
|
||||
MONO, STEREO
|
||||
}
|
||||
|
@ -1,3 +1,21 @@
|
||||
/*
|
||||
* 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 org.lwjgl.openal.*;
|
||||
@ -26,8 +44,8 @@ public class AudioManager {
|
||||
|
||||
public static void initAL() {
|
||||
String defaultDeviceName = alcGetString(
|
||||
0,
|
||||
ALC_DEFAULT_DEVICE_SPECIFIER
|
||||
0,
|
||||
ALC_DEFAULT_DEVICE_SPECIFIER
|
||||
);
|
||||
|
||||
device = alcOpenDevice(defaultDeviceName);
|
||||
@ -57,27 +75,30 @@ 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 {
|
||||
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");
|
||||
throw new Exception(
|
||||
"ERROR: The selected sound is not loaded or" +
|
||||
" not exists"
|
||||
);
|
||||
}
|
||||
|
||||
public static Speaker initSpeaker(String soundID) {
|
||||
Speaker speaker = getLastSpeaker();
|
||||
try {
|
||||
findSoundType(soundID).initSpeaker(speaker);
|
||||
} catch (Exception ex)
|
||||
{
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
return speaker;
|
||||
@ -86,8 +107,7 @@ public class AudioManager {
|
||||
public static Speaker initMusicSpeaker(String soundID) {
|
||||
try {
|
||||
findSoundType(soundID).initSpeaker(musicSpeaker);
|
||||
} catch (Exception ex)
|
||||
{
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
return musicSpeaker;
|
||||
@ -103,8 +123,7 @@ public class AudioManager {
|
||||
public static void loadSound(String path, String id, AudioFormat format) {
|
||||
if (format == AudioFormat.MONO) {
|
||||
soundsBuffer.add(AudioReader.readAsMono(path, id));
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
soundsBuffer.add(AudioReader.readAsStereo(path, id));
|
||||
}
|
||||
}
|
||||
@ -128,8 +147,7 @@ public class AudioManager {
|
||||
return deviceCapabilities;
|
||||
}
|
||||
|
||||
public static void createBuffers()
|
||||
{
|
||||
public static void createBuffers() {
|
||||
for (int i = 0; i < SOUNDS_NUM; ++i) {
|
||||
soundSpeakers.add(new Speaker());
|
||||
}
|
||||
|
@ -1,3 +1,21 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
public class AudioSystem {
|
||||
@ -9,8 +27,10 @@ public class AudioSystem {
|
||||
}
|
||||
|
||||
static void loadAudioData() {
|
||||
AudioManager.loadSound("assets/sounds/block_destroy_clap.ogg",
|
||||
"Progressia:BlockDestroy",
|
||||
AudioFormat.MONO);
|
||||
AudioManager.loadSound(
|
||||
"assets/sounds/block_destroy_clap.ogg",
|
||||
"Progressia:BlockDestroy",
|
||||
AudioFormat.MONO
|
||||
);
|
||||
}
|
||||
}
|
@ -1,3 +1,21 @@
|
||||
/*
|
||||
* 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 glm.vec._3.Vec3;
|
||||
@ -5,66 +23,68 @@ 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;
|
||||
private Vec3 position = new Vec3();
|
||||
private Vec3 velocity = new Vec3();
|
||||
private float pitch = 1.0f;
|
||||
private float gain = 1.0f;
|
||||
|
||||
public Music(String id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
public void play(boolean loop) {
|
||||
Speaker speaker = AudioManager.initMusicSpeaker(this.getId());
|
||||
speaker.setGain(gain);
|
||||
speaker.setPitch(pitch);
|
||||
speaker.setPosition(position);
|
||||
speaker.setVelocity(velocity);
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
if (loop) {
|
||||
speaker.playLoop();
|
||||
} else {
|
||||
speaker.play();
|
||||
}
|
||||
}
|
||||
public void setGain(float gain) {
|
||||
this.gain = gain;
|
||||
}
|
||||
|
||||
public void setGain(float gain) {
|
||||
this.gain = gain;
|
||||
}
|
||||
public void setPitch(float pitch) {
|
||||
this.pitch = pitch;
|
||||
}
|
||||
|
||||
public void setPitch(float pitch) { this.pitch = pitch; }
|
||||
public void setVelocity(Vec3 velocity) {
|
||||
this.velocity = velocity;
|
||||
}
|
||||
|
||||
public void setVelocity(Vec3 velocity) {
|
||||
this.velocity = velocity;
|
||||
}
|
||||
public Vec3 getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public Vec3 getPosition() { return position; }
|
||||
public float getGain() {
|
||||
return gain;
|
||||
}
|
||||
|
||||
public float getGain() {
|
||||
return gain;
|
||||
}
|
||||
public Vec3 getVelocity() {
|
||||
return velocity;
|
||||
}
|
||||
|
||||
public Vec3 getVelocity() {
|
||||
return velocity;
|
||||
}
|
||||
|
||||
public float getPitch() {
|
||||
return pitch;
|
||||
}
|
||||
public float getPitch() {
|
||||
return pitch;
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,21 @@
|
||||
/*
|
||||
* 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 glm.vec._3.Vec3;
|
||||
@ -5,74 +23,74 @@ import ru.windcorp.progressia.client.audio.backend.Speaker;
|
||||
import ru.windcorp.progressia.common.util.namespaces.Namespaced;
|
||||
|
||||
public class SoundEffect
|
||||
extends Namespaced {
|
||||
extends Namespaced {
|
||||
|
||||
private Vec3 position = new Vec3();
|
||||
private Vec3 velocity = new Vec3();
|
||||
private float pitch = 1.0f;
|
||||
private float gain = 1.0f;
|
||||
private Vec3 position = new Vec3();
|
||||
private Vec3 velocity = new Vec3();
|
||||
private float pitch = 1.0f;
|
||||
private float gain = 1.0f;
|
||||
|
||||
public SoundEffect(String id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
public SoundEffect(String id)
|
||||
{
|
||||
super(id);
|
||||
}
|
||||
public SoundEffect(
|
||||
String id,
|
||||
Vec3 position,
|
||||
Vec3 velocity,
|
||||
float pitch,
|
||||
float gain
|
||||
) {
|
||||
this(id);
|
||||
this.position = position;
|
||||
this.velocity = velocity;
|
||||
this.pitch = pitch;
|
||||
this.gain = gain;
|
||||
}
|
||||
|
||||
public SoundEffect(String id,
|
||||
Vec3 position,
|
||||
Vec3 velocity,
|
||||
float pitch,
|
||||
float gain)
|
||||
{
|
||||
this(id);
|
||||
this.position = position;
|
||||
this.velocity = velocity;
|
||||
this.pitch = pitch;
|
||||
this.gain = gain;
|
||||
}
|
||||
public void play(boolean loop) {
|
||||
Speaker speaker = AudioManager.initSpeaker(this.getId());
|
||||
speaker.setGain(gain);
|
||||
speaker.setPitch(pitch);
|
||||
speaker.setPosition(position);
|
||||
speaker.setVelocity(velocity);
|
||||
|
||||
public void play(boolean loop)
|
||||
{
|
||||
Speaker speaker = AudioManager.initSpeaker(this.getId());
|
||||
speaker.setGain(gain);
|
||||
speaker.setPitch(pitch);
|
||||
speaker.setPosition(position);
|
||||
speaker.setVelocity(velocity);
|
||||
if (loop) {
|
||||
speaker.playLoop();
|
||||
} else {
|
||||
speaker.play();
|
||||
}
|
||||
}
|
||||
|
||||
if (loop) {
|
||||
speaker.playLoop();
|
||||
} else {
|
||||
speaker.play();
|
||||
}
|
||||
}
|
||||
public void setGain(float gain) {
|
||||
this.gain = gain;
|
||||
}
|
||||
|
||||
public void setGain(float gain) {
|
||||
this.gain = gain;
|
||||
}
|
||||
public void setPitch(float pitch) {
|
||||
this.pitch = pitch;
|
||||
}
|
||||
|
||||
public void setPitch(float pitch) { this.pitch = pitch; }
|
||||
public void setPosition(Vec3 position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public void setPosition(Vec3 position) {
|
||||
this.position = position;
|
||||
}
|
||||
public void setVelocity(Vec3 velocity) {
|
||||
this.velocity = velocity;
|
||||
}
|
||||
|
||||
public void setVelocity(Vec3 velocity) {
|
||||
this.velocity = velocity;
|
||||
}
|
||||
public Vec3 getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public Vec3 getPosition() {
|
||||
return position;
|
||||
}
|
||||
public float getGain() {
|
||||
return gain;
|
||||
}
|
||||
|
||||
public float getGain() {
|
||||
return gain;
|
||||
}
|
||||
public Vec3 getVelocity() {
|
||||
return velocity;
|
||||
}
|
||||
|
||||
public Vec3 getVelocity() {
|
||||
return velocity;
|
||||
}
|
||||
|
||||
public float getPitch() {
|
||||
return pitch;
|
||||
}
|
||||
public float getPitch() {
|
||||
return pitch;
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,21 @@
|
||||
/*
|
||||
* 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.backend;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
@ -11,7 +29,8 @@ import static org.lwjgl.openal.AL10.*;
|
||||
|
||||
public class AudioReader {
|
||||
|
||||
private AudioReader() {}
|
||||
private AudioReader() {
|
||||
}
|
||||
|
||||
// TODO fix converting from mono-stereo
|
||||
private static SoundType readAsSpecified(String path, String id, int format) {
|
||||
@ -22,27 +41,31 @@ public class AudioReader {
|
||||
|
||||
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 readAsStereo(String path,String id) {
|
||||
public static SoundType readAsStereo(String path, String id) {
|
||||
return readAsSpecified(path, id, AL_FORMAT_STEREO16);
|
||||
}
|
||||
|
||||
private static ShortBuffer decodeVorbis(
|
||||
Resource dataToDecode,
|
||||
IntBuffer channelsBuffer,
|
||||
IntBuffer rateBuffer
|
||||
Resource dataToDecode,
|
||||
IntBuffer channelsBuffer,
|
||||
IntBuffer rateBuffer
|
||||
) {
|
||||
return stb_vorbis_decode_memory(
|
||||
dataToDecode.readAsBytes(),
|
||||
channelsBuffer,
|
||||
rateBuffer
|
||||
dataToDecode.readAsBytes(),
|
||||
channelsBuffer,
|
||||
rateBuffer
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,21 @@
|
||||
/*
|
||||
* 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.backend;
|
||||
|
||||
import glm.vec._3.Vec3;
|
||||
@ -12,7 +30,8 @@ public class Listener {
|
||||
|
||||
private static final Listener INSTANCE = new Listener();
|
||||
|
||||
private Listener() {}
|
||||
private Listener() {
|
||||
}
|
||||
|
||||
public static Listener getInstance() {
|
||||
return INSTANCE;
|
||||
@ -37,7 +56,7 @@ public class Listener {
|
||||
|
||||
if (wasInWorld) {
|
||||
velocity.set(camera.getLastAnchorPosition()).sub(position).div(
|
||||
(float) GraphicsInterface.getFrameLength()
|
||||
(float) GraphicsInterface.getFrameLength()
|
||||
);
|
||||
} else {
|
||||
// If !wasInWorld, previous position is nonsence. Assume 0.
|
||||
@ -72,9 +91,17 @@ 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
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,3 +1,21 @@
|
||||
/*
|
||||
* 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.backend;
|
||||
|
||||
import ru.windcorp.progressia.common.util.namespaces.Namespaced;
|
||||
@ -12,8 +30,12 @@ public class SoundType extends Namespaced {
|
||||
private int format;
|
||||
private int audioBuffer;
|
||||
|
||||
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;
|
||||
|
@ -1,3 +1,21 @@
|
||||
/*
|
||||
* 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.backend;
|
||||
|
||||
import glm.vec._3.Vec3;
|
||||
@ -5,147 +23,145 @@ import static org.lwjgl.openal.AL11.*;
|
||||
|
||||
public class Speaker {
|
||||
|
||||
public enum State {
|
||||
NOT_PLAYING,
|
||||
PLAYING,
|
||||
PLAYING_LOOP
|
||||
}
|
||||
public enum State {
|
||||
NOT_PLAYING,
|
||||
PLAYING,
|
||||
PLAYING_LOOP
|
||||
}
|
||||
|
||||
// Buffers
|
||||
private int audioData;
|
||||
private int sourceData;
|
||||
// Buffers
|
||||
private int audioData;
|
||||
private int sourceData;
|
||||
|
||||
// Characteristics
|
||||
private Vec3 position = new Vec3();
|
||||
private Vec3 velocity = new Vec3();
|
||||
private float pitch = 1.0f;
|
||||
private float gain = 1.0f;
|
||||
private State state = State.NOT_PLAYING;
|
||||
// Characteristics
|
||||
private Vec3 position = new Vec3();
|
||||
private Vec3 velocity = new Vec3();
|
||||
private float pitch = 1.0f;
|
||||
private float gain = 1.0f;
|
||||
private State state = State.NOT_PLAYING;
|
||||
|
||||
public Speaker() {
|
||||
sourceData = alGenSources();
|
||||
}
|
||||
public Speaker() {
|
||||
sourceData = alGenSources();
|
||||
}
|
||||
|
||||
public Speaker(int audioData) {
|
||||
this();
|
||||
setAudioData(audioData);
|
||||
}
|
||||
public Speaker(int audioData) {
|
||||
this();
|
||||
setAudioData(audioData);
|
||||
}
|
||||
|
||||
public Speaker(
|
||||
int audioData,
|
||||
Vec3 position,
|
||||
Vec3 velocity,
|
||||
float pitch,
|
||||
float gain
|
||||
) {
|
||||
setAudioData(audioData);
|
||||
setPosition(position);
|
||||
setVelocity(velocity);
|
||||
setPitch(pitch);
|
||||
setGain(gain);
|
||||
}
|
||||
public Speaker(
|
||||
int audioData,
|
||||
Vec3 position,
|
||||
Vec3 velocity,
|
||||
float pitch,
|
||||
float gain
|
||||
) {
|
||||
setAudioData(audioData);
|
||||
setPosition(position);
|
||||
setVelocity(velocity);
|
||||
setPitch(pitch);
|
||||
setGain(gain);
|
||||
}
|
||||
|
||||
public Speaker(
|
||||
Vec3 position,
|
||||
Vec3 velocity,
|
||||
float pitch,
|
||||
float gain
|
||||
) {
|
||||
setPosition(position);
|
||||
setVelocity(velocity);
|
||||
setPitch(pitch);
|
||||
setGain(gain);
|
||||
}
|
||||
public Speaker(
|
||||
Vec3 position,
|
||||
Vec3 velocity,
|
||||
float pitch,
|
||||
float gain
|
||||
) {
|
||||
setPosition(position);
|
||||
setVelocity(velocity);
|
||||
setPitch(pitch);
|
||||
setGain(gain);
|
||||
}
|
||||
|
||||
public void play() {
|
||||
alSourcePlay(sourceData);
|
||||
state = State.PLAYING;
|
||||
}
|
||||
public void play() {
|
||||
alSourcePlay(sourceData);
|
||||
state = State.PLAYING;
|
||||
}
|
||||
|
||||
public void playLoop() {
|
||||
alSourcei(sourceData, AL_LOOPING, AL_TRUE);
|
||||
alSourcePlay(sourceData);
|
||||
state = State.PLAYING_LOOP;
|
||||
}
|
||||
public void playLoop() {
|
||||
alSourcei(sourceData, AL_LOOPING, AL_TRUE);
|
||||
alSourcePlay(sourceData);
|
||||
state = State.PLAYING_LOOP;
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
alSourceStop(sourceData);
|
||||
if (state == State.PLAYING_LOOP) {
|
||||
alSourcei(sourceData, AL_LOOPING, AL_FALSE);
|
||||
}
|
||||
state = State.NOT_PLAYING;
|
||||
}
|
||||
public void stop() {
|
||||
alSourceStop(sourceData);
|
||||
if (state == State.PLAYING_LOOP) {
|
||||
alSourcei(sourceData, AL_LOOPING, AL_FALSE);
|
||||
}
|
||||
state = State.NOT_PLAYING;
|
||||
}
|
||||
|
||||
public void pause() {
|
||||
alSourcePause(sourceData);
|
||||
state = State.NOT_PLAYING;
|
||||
}
|
||||
public void pause() {
|
||||
alSourcePause(sourceData);
|
||||
state = State.NOT_PLAYING;
|
||||
}
|
||||
|
||||
public boolean isPlaying() {
|
||||
final int speakerState = alGetSourcei(sourceData, AL_SOURCE_STATE);
|
||||
if (speakerState == AL_PLAYING) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
state = State.NOT_PLAYING;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public boolean isPlaying() {
|
||||
final int speakerState = alGetSourcei(sourceData, AL_SOURCE_STATE);
|
||||
if (speakerState == AL_PLAYING) {
|
||||
return true;
|
||||
} else {
|
||||
state = State.NOT_PLAYING;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// GETTERS & SETTERS
|
||||
// GETTERS & SETTERS
|
||||
|
||||
public int getAudioData() {
|
||||
return audioData;
|
||||
}
|
||||
public int getAudioData() {
|
||||
return audioData;
|
||||
}
|
||||
|
||||
public int getSourceData() {
|
||||
return sourceData;
|
||||
}
|
||||
public int getSourceData() {
|
||||
return sourceData;
|
||||
}
|
||||
|
||||
public void setAudioData(int audioData) {
|
||||
this.audioData = audioData;
|
||||
alSourcei(this.sourceData, AL_BUFFER, audioData);
|
||||
}
|
||||
public void setAudioData(int audioData) {
|
||||
this.audioData = audioData;
|
||||
alSourcei(this.sourceData, AL_BUFFER, audioData);
|
||||
}
|
||||
|
||||
public void setPosition(Vec3 position) {
|
||||
this.position = position;
|
||||
alSource3f(sourceData, AL_POSITION, position.x, position.y, position.z);
|
||||
}
|
||||
public void setPosition(Vec3 position) {
|
||||
this.position = position;
|
||||
alSource3f(sourceData, AL_POSITION, position.x, position.y, position.z);
|
||||
}
|
||||
|
||||
public Vec3 getPosition() {
|
||||
return position;
|
||||
}
|
||||
public Vec3 getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setVelocity(Vec3 velocity) {
|
||||
alSource3f(sourceData, AL_VELOCITY, velocity.x, velocity.y, velocity.z);
|
||||
this.velocity = velocity;
|
||||
}
|
||||
public void setVelocity(Vec3 velocity) {
|
||||
alSource3f(sourceData, AL_VELOCITY, velocity.x, velocity.y, velocity.z);
|
||||
this.velocity = velocity;
|
||||
}
|
||||
|
||||
public Vec3 getVelocity() {
|
||||
return velocity;
|
||||
}
|
||||
public Vec3 getVelocity() {
|
||||
return velocity;
|
||||
}
|
||||
|
||||
public void setPitch(float pitch) {
|
||||
alSourcef(sourceData, AL_PITCH, pitch);
|
||||
this.pitch = pitch;
|
||||
}
|
||||
public void setPitch(float pitch) {
|
||||
alSourcef(sourceData, AL_PITCH, pitch);
|
||||
this.pitch = pitch;
|
||||
}
|
||||
|
||||
public float getPitch() {
|
||||
return pitch;
|
||||
}
|
||||
public float getPitch() {
|
||||
return pitch;
|
||||
}
|
||||
|
||||
public void setGain(float gain) {
|
||||
alSourcef(sourceData, AL_GAIN, gain);
|
||||
this.gain = gain;
|
||||
}
|
||||
public void setGain(float gain) {
|
||||
alSourcef(sourceData, AL_GAIN, gain);
|
||||
this.gain = gain;
|
||||
}
|
||||
|
||||
public float getGain() {
|
||||
return gain;
|
||||
}
|
||||
public float getGain() {
|
||||
return gain;
|
||||
}
|
||||
|
||||
public State getState()
|
||||
{
|
||||
return state;
|
||||
}
|
||||
public State getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
}
|
@ -1,3 +1,21 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -22,7 +40,7 @@ public class DefaultClientCommsListener implements CommsListener {
|
||||
public void onPacketReceived(Packet packet) {
|
||||
if (packet instanceof PacketAffectWorld) {
|
||||
((PacketAffectWorld) packet).apply(
|
||||
getClient().getWorld().getData()
|
||||
getClient().getWorld().getData()
|
||||
);
|
||||
} else if (packet instanceof PacketSetLocalPlayer) {
|
||||
setLocalPlayer((PacketSetLocalPlayer) packet);
|
||||
|
@ -1,3 +1,21 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import ru.windcorp.progressia.common.comms.CommsChannel;
|
||||
|
@ -1,3 +1,21 @@
|
||||
/*
|
||||
* 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 ru.windcorp.progressia.common.util.namespaces.Namespaced;
|
||||
|
@ -1,3 +1,21 @@
|
||||
/*
|
||||
* 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 ru.windcorp.progressia.client.graphics.input.InputEvent;
|
||||
|
@ -1,3 +1,21 @@
|
||||
/*
|
||||
* 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.BiConsumer;
|
||||
@ -16,15 +34,15 @@ public class ControlTriggerLambda extends ControlTriggerInputBased {
|
||||
private final BiConsumer<InputEvent, ControlData> dataWriter;
|
||||
|
||||
public ControlTriggerLambda(
|
||||
String id,
|
||||
Predicate<InputEvent> predicate,
|
||||
BiConsumer<InputEvent, ControlData> dataWriter
|
||||
String id,
|
||||
Predicate<InputEvent> predicate,
|
||||
BiConsumer<InputEvent, ControlData> dataWriter
|
||||
) {
|
||||
super(id);
|
||||
|
||||
this.packetId = NamespacedUtil.getId(
|
||||
NamespacedUtil.getNamespace(id),
|
||||
"ControlKeyPress" + NamespacedUtil.getName(id)
|
||||
NamespacedUtil.getNamespace(id),
|
||||
"ControlKeyPress" + NamespacedUtil.getName(id)
|
||||
);
|
||||
|
||||
this.predicate = predicate;
|
||||
@ -33,11 +51,12 @@ public class ControlTriggerLambda extends ControlTriggerInputBased {
|
||||
|
||||
@Override
|
||||
public PacketControl onInputEvent(InputEvent event) {
|
||||
if (!predicate.test(event)) return null;
|
||||
if (!predicate.test(event))
|
||||
return null;
|
||||
|
||||
PacketControl packet = new PacketControl(
|
||||
packetId,
|
||||
ControlDataRegistry.getInstance().create(getId())
|
||||
packetId,
|
||||
ControlDataRegistry.getInstance().create(getId())
|
||||
);
|
||||
|
||||
dataWriter.accept(event, packet.getControl());
|
||||
|
@ -1,11 +1,28 @@
|
||||
/*
|
||||
* 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 ru.windcorp.progressia.common.util.namespaces.NamespacedInstanceRegistry;
|
||||
|
||||
public class ControlTriggerRegistry extends NamespacedInstanceRegistry<ControlTrigger> {
|
||||
|
||||
private static final ControlTriggerRegistry INSTANCE =
|
||||
new ControlTriggerRegistry();
|
||||
private static final ControlTriggerRegistry INSTANCE = new ControlTriggerRegistry();
|
||||
|
||||
public static ControlTriggerRegistry getInstance() {
|
||||
return INSTANCE;
|
||||
|
@ -1,3 +1,21 @@
|
||||
/*
|
||||
* 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.BiConsumer;
|
||||
@ -10,134 +28,131 @@ import ru.windcorp.progressia.common.comms.controls.ControlData;
|
||||
public class ControlTriggers {
|
||||
|
||||
public static ControlTriggerInputBased of(
|
||||
String id,
|
||||
BiConsumer<InputEvent, ControlData> dataWriter,
|
||||
Predicate<InputEvent> predicate
|
||||
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
|
||||
String id,
|
||||
Consumer<ControlData> dataWriter,
|
||||
Predicate<InputEvent> predicate
|
||||
) {
|
||||
return of(
|
||||
id,
|
||||
(input, control) -> dataWriter.accept(control),
|
||||
predicate
|
||||
id,
|
||||
(input, control) -> dataWriter.accept(control),
|
||||
predicate
|
||||
);
|
||||
}
|
||||
|
||||
public static ControlTriggerInputBased of(
|
||||
String id,
|
||||
Predicate<InputEvent> predicate
|
||||
String id,
|
||||
Predicate<InputEvent> predicate
|
||||
) {
|
||||
return of(
|
||||
id,
|
||||
(input, control) -> {},
|
||||
predicate
|
||||
id,
|
||||
(input, control) -> {
|
||||
},
|
||||
predicate
|
||||
);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <I extends InputEvent> ControlTriggerInputBased of(
|
||||
String id,
|
||||
Class<I> inputType,
|
||||
BiConsumer<I, ControlData> dataWriter,
|
||||
Predicate<I>... predicates
|
||||
String id,
|
||||
Class<I> inputType,
|
||||
BiConsumer<I, ControlData> dataWriter,
|
||||
Predicate<I>... predicates
|
||||
) {
|
||||
return of(
|
||||
id,
|
||||
createCheckedDataWriter(inputType, dataWriter),
|
||||
createCheckedCompoundPredicate(inputType, predicates)
|
||||
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
|
||||
String id,
|
||||
Class<I> inputType,
|
||||
Consumer<ControlData> dataWriter,
|
||||
Predicate<I>... predicates
|
||||
) {
|
||||
return of(
|
||||
id,
|
||||
inputType,
|
||||
(input, control) -> dataWriter.accept(control),
|
||||
predicates
|
||||
id,
|
||||
inputType,
|
||||
(input, control) -> dataWriter.accept(control),
|
||||
predicates
|
||||
);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <I extends InputEvent> ControlTriggerInputBased of(
|
||||
String id,
|
||||
Class<I> inputType,
|
||||
Predicate<I>... predicates
|
||||
String id,
|
||||
Class<I> inputType,
|
||||
Predicate<I>... predicates
|
||||
) {
|
||||
return of(
|
||||
id,
|
||||
(input, control) -> {},
|
||||
createCheckedCompoundPredicate(inputType, predicates)
|
||||
id,
|
||||
(input, control) -> {
|
||||
},
|
||||
createCheckedCompoundPredicate(inputType, predicates)
|
||||
);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static ControlTriggerInputBased of(
|
||||
String id,
|
||||
BiConsumer<InputEvent, ControlData> dataWriter,
|
||||
Predicate<InputEvent>... predicates
|
||||
String id,
|
||||
BiConsumer<InputEvent, ControlData> dataWriter,
|
||||
Predicate<InputEvent>... predicates
|
||||
) {
|
||||
return of(
|
||||
id,
|
||||
InputEvent.class,
|
||||
dataWriter,
|
||||
predicates
|
||||
id,
|
||||
InputEvent.class,
|
||||
dataWriter,
|
||||
predicates
|
||||
);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <I extends InputEvent> ControlTriggerInputBased of(
|
||||
String id,
|
||||
Consumer<ControlData> dataWriter,
|
||||
Predicate<InputEvent>... predicates
|
||||
String id,
|
||||
Consumer<ControlData> dataWriter,
|
||||
Predicate<InputEvent>... predicates
|
||||
) {
|
||||
return of(
|
||||
id,
|
||||
(input, control) -> dataWriter.accept(control),
|
||||
predicates
|
||||
id,
|
||||
(input, control) -> dataWriter.accept(control),
|
||||
predicates
|
||||
);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static ControlTriggerInputBased of(
|
||||
String id,
|
||||
Predicate<InputEvent>... predicates
|
||||
String id,
|
||||
Predicate<InputEvent>... predicates
|
||||
) {
|
||||
return of(
|
||||
id,
|
||||
InputEvent.class,
|
||||
(input, control) -> {},
|
||||
predicates
|
||||
id,
|
||||
InputEvent.class,
|
||||
(input, control) -> {
|
||||
},
|
||||
predicates
|
||||
);
|
||||
}
|
||||
|
||||
private static
|
||||
<I extends InputEvent>
|
||||
BiConsumer<InputEvent, ControlData>
|
||||
createCheckedDataWriter(
|
||||
Class<I> inputType,
|
||||
BiConsumer<I, ControlData> dataWriter
|
||||
private static <I extends InputEvent> BiConsumer<InputEvent, ControlData> createCheckedDataWriter(
|
||||
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> Predicate<InputEvent> createCheckedCompoundPredicate(
|
||||
Class<I> inputType,
|
||||
Predicate<I>[] predicates
|
||||
) {
|
||||
return new CompoundCastPredicate<>(inputType, predicates);
|
||||
}
|
||||
@ -171,6 +186,7 @@ public class ControlTriggers {
|
||||
|
||||
}
|
||||
|
||||
private ControlTriggers() {}
|
||||
private ControlTriggers() {
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,3 +1,21 @@
|
||||
/*
|
||||
* 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 ru.windcorp.progressia.client.Client;
|
||||
@ -14,8 +32,8 @@ 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) {
|
||||
|
@ -1,3 +1,21 @@
|
||||
/*
|
||||
* 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.localhost;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -1,3 +1,21 @@
|
||||
/*
|
||||
* 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.localhost;
|
||||
|
||||
import ru.windcorp.progressia.client.comms.ServerCommsChannel;
|
||||
@ -17,9 +35,9 @@ public class LocalServerCommsChannel extends ServerCommsChannel {
|
||||
setState(State.CONNECTED);
|
||||
|
||||
this.localClient = new LocalClient(
|
||||
server.getClientManager().grabClientId(),
|
||||
login,
|
||||
this
|
||||
server.getClientManager().grabClientId(),
|
||||
login,
|
||||
this
|
||||
);
|
||||
|
||||
server.getClientManager().addClient(localClient);
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020 Wind Corporation
|
||||
* 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
|
||||
@ -14,27 +14,27 @@
|
||||
*
|
||||
* 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 glm.vec._4.Vec4;
|
||||
|
||||
public class Colors {
|
||||
|
||||
public static final Vec4
|
||||
WHITE = toVector(0xFFFFFFFF),
|
||||
BLACK = toVector(0xFF000000),
|
||||
public static final Vec4 WHITE = toVector(0xFFFFFFFF),
|
||||
BLACK = toVector(0xFF000000),
|
||||
|
||||
GRAY_4 = toVector(0xFF444444),
|
||||
GRAY = toVector(0xFF888888),
|
||||
GRAY_A = toVector(0xFFAAAAAA),
|
||||
GRAY_4 = toVector(0xFF444444),
|
||||
GRAY = toVector(0xFF888888),
|
||||
GRAY_A = toVector(0xFFAAAAAA),
|
||||
|
||||
DEBUG_RED = toVector(0xFFFF0000),
|
||||
DEBUG_GREEN = toVector(0xFF00FF00),
|
||||
DEBUG_BLUE = toVector(0xFF0000FF),
|
||||
DEBUG_CYAN = toVector(0xFF00FFFF),
|
||||
DEBUG_MAGENTA = toVector(0xFFFF00FF),
|
||||
DEBUG_YELLOW = toVector(0xFFFFFF00);
|
||||
DEBUG_RED = toVector(0xFFFF0000),
|
||||
DEBUG_GREEN = toVector(0xFF00FF00),
|
||||
DEBUG_BLUE = toVector(0xFF0000FF),
|
||||
DEBUG_CYAN = toVector(0xFF00FFFF),
|
||||
DEBUG_MAGENTA = toVector(0xFFFF00FF),
|
||||
DEBUG_YELLOW = toVector(0xFFFFFF00);
|
||||
|
||||
public static Vec4 toVector(int argb) {
|
||||
return toVector(argb, new Vec4());
|
||||
@ -45,15 +45,16 @@ public class Colors {
|
||||
}
|
||||
|
||||
public static Vec4 multiplyRGB(Vec4 color, float multiplier, Vec4 output) {
|
||||
if (output == null) output = new Vec4();
|
||||
if (output == null)
|
||||
output = new Vec4();
|
||||
return color.mul(multiplier, multiplier, multiplier, 1, output);
|
||||
}
|
||||
|
||||
public static Vec4 toVector(int argb, Vec4 output) {
|
||||
output.w = ((argb & 0xFF000000) >>> 24) / (float) 0xFF; // Alpha
|
||||
output.x = ((argb & 0x00FF0000) >>> 16) / (float) 0xFF; // Red
|
||||
output.y = ((argb & 0x0000FF00) >>> 8) / (float) 0xFF; // Green
|
||||
output.z = ((argb & 0x000000FF) ) / (float) 0xFF; // Blue
|
||||
output.y = ((argb & 0x0000FF00) >>> 8) / (float) 0xFF; // Green
|
||||
output.z = ((argb & 0x000000FF)) / (float) 0xFF; // Blue
|
||||
|
||||
return output;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020 Wind Corporation
|
||||
* 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
@ -40,7 +41,8 @@ public class GUI {
|
||||
void affect(List<Layer> layers);
|
||||
}
|
||||
|
||||
private static final List<LayerStackModification> MODIFICATION_QUEUE = Collections.synchronizedList(new ArrayList<>());
|
||||
private static final List<LayerStackModification> MODIFICATION_QUEUE = Collections
|
||||
.synchronizedList(new ArrayList<>());
|
||||
|
||||
private static class ModifiableInput extends Input {
|
||||
@Override
|
||||
@ -51,7 +53,8 @@ public class GUI {
|
||||
|
||||
private static final ModifiableInput THE_INPUT = new ModifiableInput();
|
||||
|
||||
private GUI() {}
|
||||
private GUI() {
|
||||
}
|
||||
|
||||
public static void addBottomLayer(Layer layer) {
|
||||
modify(layers -> layers.add(layer));
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020 Wind Corporation
|
||||
* 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
|
@ -1,3 +1,21 @@
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020-2021 Wind Corporation and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ru.windcorp.progressia.client.graphics.backend;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
@ -22,6 +40,7 @@ public class FaceCulling {
|
||||
}
|
||||
}
|
||||
|
||||
private FaceCulling() {}
|
||||
private FaceCulling() {
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020 Wind Corporation
|
||||
* 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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.*;
|
||||
@ -37,7 +38,8 @@ public class GraphicsBackend {
|
||||
|
||||
private static boolean faceCullingEnabled = false;
|
||||
|
||||
private GraphicsBackend() {}
|
||||
private GraphicsBackend() {
|
||||
}
|
||||
|
||||
public static void initialize() {
|
||||
startRenderThread();
|
||||
@ -73,7 +75,8 @@ public class GraphicsBackend {
|
||||
}
|
||||
|
||||
static void onFrameResized(long window, int newWidth, int newHeight) {
|
||||
if (window != windowHandle) return;
|
||||
if (window != windowHandle)
|
||||
return;
|
||||
|
||||
InputHandler.handleFrameResize(newWidth, newHeight);
|
||||
FRAME_SIZE.set(newWidth, newHeight);
|
||||
@ -113,7 +116,8 @@ public class GraphicsBackend {
|
||||
}
|
||||
|
||||
public static void setFaceCulling(boolean useFaceCulling) {
|
||||
if (useFaceCulling == faceCullingEnabled) return;
|
||||
if (useFaceCulling == faceCullingEnabled)
|
||||
return;
|
||||
|
||||
if (useFaceCulling) {
|
||||
glEnable(GL_CULL_FACE);
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020 Wind Corporation
|
||||
* 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
|
||||
@ -14,14 +14,16 @@
|
||||
*
|
||||
* 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;
|
||||
|
||||
public class GraphicsInterface {
|
||||
|
||||
private GraphicsInterface() {}
|
||||
private GraphicsInterface() {
|
||||
}
|
||||
|
||||
public static Thread getRenderThread() {
|
||||
return GraphicsBackend.getRenderThread();
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020 Wind Corporation
|
||||
* 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
@ -46,17 +47,17 @@ public class InputHandler {
|
||||
|
||||
}
|
||||
|
||||
private static final ModifiableKeyEvent THE_KEY_EVENT =
|
||||
new ModifiableKeyEvent();
|
||||
private static final ModifiableKeyEvent THE_KEY_EVENT = new ModifiableKeyEvent();
|
||||
|
||||
static void handleKeyInput(
|
||||
long window,
|
||||
int key,
|
||||
int scancode,
|
||||
int action,
|
||||
int mods
|
||||
long window,
|
||||
int key,
|
||||
int scancode,
|
||||
int action,
|
||||
int mods
|
||||
) {
|
||||
if (GraphicsBackend.getWindowHandle() != window) return;
|
||||
if (GraphicsBackend.getWindowHandle() != window)
|
||||
return;
|
||||
THE_KEY_EVENT.initialize(key, scancode, action, mods);
|
||||
dispatch(THE_KEY_EVENT);
|
||||
|
||||
@ -71,10 +72,10 @@ public class InputHandler {
|
||||
}
|
||||
|
||||
static void handleMouseButtonInput(
|
||||
long window,
|
||||
int key,
|
||||
int action,
|
||||
int mods
|
||||
long window,
|
||||
int key,
|
||||
int action,
|
||||
int mods
|
||||
) {
|
||||
handleKeyInput(window, key, Integer.MAX_VALUE - key, action, mods);
|
||||
}
|
||||
@ -94,14 +95,15 @@ public class InputHandler {
|
||||
|
||||
}
|
||||
|
||||
private static final ModifiableCursorMoveEvent THE_CURSOR_MOVE_EVENT =
|
||||
new ModifiableCursorMoveEvent();
|
||||
private static final ModifiableCursorMoveEvent THE_CURSOR_MOVE_EVENT = new ModifiableCursorMoveEvent();
|
||||
|
||||
static void handleMouseMoveInput(
|
||||
long window,
|
||||
double x, double y
|
||||
long window,
|
||||
double x,
|
||||
double y
|
||||
) {
|
||||
if (GraphicsBackend.getWindowHandle() != window) return;
|
||||
if (GraphicsBackend.getWindowHandle() != window)
|
||||
return;
|
||||
y = GraphicsInterface.getFrameHeight() - y; // Flip y axis
|
||||
|
||||
InputTracker.initializeCursorPosition(x, y);
|
||||
@ -127,15 +129,15 @@ public class InputHandler {
|
||||
|
||||
}
|
||||
|
||||
private static final ModifiableWheelScrollEvent THE_WHEEL_SCROLL_EVENT =
|
||||
new ModifiableWheelScrollEvent();
|
||||
private static final ModifiableWheelScrollEvent THE_WHEEL_SCROLL_EVENT = new ModifiableWheelScrollEvent();
|
||||
|
||||
static void handleWheelScroll(
|
||||
long window,
|
||||
double xoffset,
|
||||
double yoffset
|
||||
long window,
|
||||
double xoffset,
|
||||
double yoffset
|
||||
) {
|
||||
if (GraphicsBackend.getWindowHandle() != window) return;
|
||||
if (GraphicsBackend.getWindowHandle() != window)
|
||||
return;
|
||||
THE_WHEEL_SCROLL_EVENT.initialize(xoffset, yoffset);
|
||||
dispatch(THE_WHEEL_SCROLL_EVENT);
|
||||
}
|
||||
@ -155,15 +157,14 @@ public class InputHandler {
|
||||
|
||||
}
|
||||
|
||||
private static final ModifiableFrameResizeEvent THE_FRAME_RESIZE_EVENT =
|
||||
new ModifiableFrameResizeEvent();
|
||||
private static final ModifiableFrameResizeEvent THE_FRAME_RESIZE_EVENT = new ModifiableFrameResizeEvent();
|
||||
|
||||
/*
|
||||
* NB: this is NOT a GLFW callback, the raw callback is in GraphicsBackend
|
||||
*/
|
||||
static void handleFrameResize(
|
||||
int width,
|
||||
int height
|
||||
int width,
|
||||
int height
|
||||
) {
|
||||
THE_FRAME_RESIZE_EVENT.initialize(width, height);
|
||||
dispatch(THE_FRAME_RESIZE_EVENT);
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020 Wind Corporation
|
||||
* 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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,12 +25,14 @@ import gnu.trove.set.hash.TIntHashSet;
|
||||
public class InputTracker {
|
||||
|
||||
private static final Vec2d CURSOR_POSITION = new Vec2d(
|
||||
Double.NaN, Double.NaN
|
||||
Double.NaN,
|
||||
Double.NaN
|
||||
);
|
||||
|
||||
private static final TIntSet PRESSED_KEYS = new TIntHashSet(256);
|
||||
|
||||
private InputTracker() {}
|
||||
private InputTracker() {
|
||||
}
|
||||
|
||||
public static double getCursorX() {
|
||||
return CURSOR_POSITION.x;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020 Wind Corporation
|
||||
* 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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.*;
|
||||
@ -27,7 +28,8 @@ import ru.windcorp.progressia.client.graphics.GUI;
|
||||
|
||||
class LWJGLInitializer {
|
||||
|
||||
private LWJGLInitializer() {}
|
||||
private LWJGLInitializer() {
|
||||
}
|
||||
|
||||
public static void initialize() {
|
||||
checkEnvironment();
|
||||
@ -90,12 +92,16 @@ class LWJGLInitializer {
|
||||
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);
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020 Wind Corporation
|
||||
* 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
@ -33,15 +34,19 @@ 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();
|
||||
}
|
||||
}
|
||||
@ -66,20 +71,24 @@ public class OpenGLObjectTracker {
|
||||
/**
|
||||
* Creates a new phantom reference that refers to the given object and
|
||||
* is registered with the given queue.
|
||||
*
|
||||
* <p> It is possible to create a phantom reference with a {@code null}
|
||||
* <p>
|
||||
* 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,
|
||||
* method will always return {@code null} and, since it does not have a
|
||||
* 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,
|
||||
* @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;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020 Wind Corporation
|
||||
* 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
@ -22,8 +23,7 @@ import ru.windcorp.progressia.common.util.TaskQueue;
|
||||
|
||||
public class RenderTaskQueue {
|
||||
|
||||
private static final TaskQueue HANDLER =
|
||||
new TaskQueue(GraphicsInterface::isRenderThread);
|
||||
private static final TaskQueue HANDLER = new TaskQueue(GraphicsInterface::isRenderThread);
|
||||
|
||||
public static void schedule(Runnable task) {
|
||||
HANDLER.schedule(task);
|
||||
@ -42,8 +42,10 @@ public class RenderTaskQueue {
|
||||
}
|
||||
|
||||
public static <E extends Exception> void waitAndInvoke(
|
||||
ThrowingRunnable<E> task
|
||||
) throws InterruptedException, E {
|
||||
ThrowingRunnable<E> task
|
||||
)
|
||||
throws InterruptedException,
|
||||
E {
|
||||
HANDLER.waitAndInvoke(task);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020 Wind Corporation
|
||||
* 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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.*;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020 Wind Corporation
|
||||
* 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020 Wind Corporation
|
||||
* 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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.*;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020 Wind Corporation
|
||||
* 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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;
|
||||
@ -31,11 +32,11 @@ 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"
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -61,8 +62,7 @@ public class CombinedShader extends Shader {
|
||||
String contents = resource.readAsString();
|
||||
|
||||
int versionIndex;
|
||||
for (versionIndex = 0; versionIndex < contents.length(); ++versionIndex)
|
||||
{
|
||||
for (versionIndex = 0; versionIndex < contents.length(); ++versionIndex) {
|
||||
if (!Character.isWhitespace(contents.codePointAt(versionIndex)))
|
||||
break;
|
||||
}
|
||||
@ -71,14 +71,16 @@ public class CombinedShader extends Shader {
|
||||
if (contents.codePointAt(versionIndex) == '#') {
|
||||
final String versionAnnotation = "#version ";
|
||||
|
||||
if (contents.regionMatches(
|
||||
if (
|
||||
contents.regionMatches(
|
||||
versionIndex,
|
||||
versionAnnotation,
|
||||
0,
|
||||
versionAnnotation.length()
|
||||
)) {
|
||||
)
|
||||
) {
|
||||
contents = contents.substring(
|
||||
versionIndex
|
||||
versionIndex
|
||||
+ versionAnnotation.length()
|
||||
+ "120".length()
|
||||
);
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020 Wind Corporation
|
||||
* 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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.*;
|
||||
@ -58,6 +59,8 @@ public class Program implements OpenGLDeletable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHandle() { return handle; }
|
||||
public int getHandle() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020 Wind Corporation
|
||||
* 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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.*;
|
||||
@ -47,13 +48,17 @@ public class Shader implements OpenGLDeletable {
|
||||
public static ShaderType guessByResourceName(String resource) {
|
||||
resource = resource.toLowerCase(Locale.ENGLISH);
|
||||
|
||||
if (resource.contains("vertex")) return VERTEX;
|
||||
if (resource.contains("fragment")) return FRAGMENT;
|
||||
if (resource.contains("vsh")) return VERTEX;
|
||||
if (resource.contains("fsh")) return FRAGMENT;
|
||||
if (resource.contains("vertex"))
|
||||
return VERTEX;
|
||||
if (resource.contains("fragment"))
|
||||
return FRAGMENT;
|
||||
if (resource.contains("vsh"))
|
||||
return VERTEX;
|
||||
if (resource.contains("fsh"))
|
||||
return FRAGMENT;
|
||||
|
||||
throw new IllegalArgumentException(
|
||||
"Cannot deduce shader type from resource name \"" +
|
||||
"Cannot deduce shader type from resource name \"" +
|
||||
resource + "\""
|
||||
);
|
||||
}
|
||||
@ -86,8 +91,8 @@ public class Shader implements OpenGLDeletable {
|
||||
|
||||
public Shader(String resource) {
|
||||
this(
|
||||
ShaderType.guessByResourceName(resource),
|
||||
getShaderResource(resource).readAsString()
|
||||
ShaderType.guessByResourceName(resource),
|
||||
getShaderResource(resource).readAsString()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020 Wind Corporation
|
||||
* 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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.attributes;
|
||||
|
||||
import ru.windcorp.progressia.client.graphics.backend.shaders.Program;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020 Wind Corporation
|
||||
* 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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.attributes;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
@ -51,63 +52,102 @@ public class AttributeVertexArray extends Attribute {
|
||||
}
|
||||
|
||||
public void set(
|
||||
int size, boolean normalized, int stride,
|
||||
ByteBuffer pointer
|
||||
int size,
|
||||
boolean normalized,
|
||||
int stride,
|
||||
ByteBuffer pointer
|
||||
) {
|
||||
glVertexAttribPointer(
|
||||
handle,
|
||||
size, GL_BYTE, normalized, stride, pointer
|
||||
handle,
|
||||
size,
|
||||
GL_BYTE,
|
||||
normalized,
|
||||
stride,
|
||||
pointer
|
||||
);
|
||||
}
|
||||
|
||||
public void set(
|
||||
int size, boolean normalized, int stride,
|
||||
FloatBuffer pointer
|
||||
int size,
|
||||
boolean normalized,
|
||||
int stride,
|
||||
FloatBuffer pointer
|
||||
) {
|
||||
glVertexAttribPointer(
|
||||
handle,
|
||||
size, GL_FLOAT, normalized, stride, pointer
|
||||
handle,
|
||||
size,
|
||||
GL_FLOAT,
|
||||
normalized,
|
||||
stride,
|
||||
pointer
|
||||
);
|
||||
}
|
||||
|
||||
public void set(
|
||||
int size, boolean normalized, int stride,
|
||||
IntBuffer pointer
|
||||
int size,
|
||||
boolean normalized,
|
||||
int stride,
|
||||
IntBuffer pointer
|
||||
) {
|
||||
glVertexAttribPointer(
|
||||
handle,
|
||||
size, GL_INT, normalized, stride, pointer
|
||||
handle,
|
||||
size,
|
||||
GL_INT,
|
||||
normalized,
|
||||
stride,
|
||||
pointer
|
||||
);
|
||||
}
|
||||
|
||||
public void set(
|
||||
int size, boolean normalized, int stride,
|
||||
ShortBuffer pointer
|
||||
int size,
|
||||
boolean normalized,
|
||||
int stride,
|
||||
ShortBuffer pointer
|
||||
) {
|
||||
glVertexAttribPointer(
|
||||
handle,
|
||||
size, GL_SHORT, normalized, stride, pointer
|
||||
handle,
|
||||
size,
|
||||
GL_SHORT,
|
||||
normalized,
|
||||
stride,
|
||||
pointer
|
||||
);
|
||||
}
|
||||
|
||||
public void set(
|
||||
int size, int type, boolean normalized, int stride,
|
||||
long pointer
|
||||
int size,
|
||||
int type,
|
||||
boolean normalized,
|
||||
int stride,
|
||||
long pointer
|
||||
) {
|
||||
glVertexAttribPointer(
|
||||
handle,
|
||||
size, type, normalized, stride, pointer
|
||||
handle,
|
||||
size,
|
||||
type,
|
||||
normalized,
|
||||
stride,
|
||||
pointer
|
||||
);
|
||||
}
|
||||
|
||||
public void set(
|
||||
int size, int type, boolean normalized, int stride,
|
||||
VertexBufferObject vbo, long offset
|
||||
int size,
|
||||
int type,
|
||||
boolean normalized,
|
||||
int stride,
|
||||
VertexBufferObject vbo,
|
||||
long offset
|
||||
) {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo.getHandle());
|
||||
glVertexAttribPointer(
|
||||
handle,
|
||||
size, type, normalized, stride, offset
|
||||
handle,
|
||||
size,
|
||||
type,
|
||||
normalized,
|
||||
stride,
|
||||
offset
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020 Wind Corporation
|
||||
* 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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.uniforms;
|
||||
|
||||
import ru.windcorp.progressia.client.graphics.backend.shaders.Program;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020 Wind Corporation
|
||||
* 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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.uniforms;
|
||||
|
||||
import static org.lwjgl.opengl.GL20.*;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020 Wind Corporation
|
||||
* 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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.uniforms;
|
||||
|
||||
import static org.lwjgl.opengl.GL20.*;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020 Wind Corporation
|
||||
* 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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.uniforms;
|
||||
|
||||
import static org.lwjgl.opengl.GL20.*;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*******************************************************************************
|
||||
/*
|
||||
* Progressia
|
||||
* Copyright (C) 2020 Wind Corporation
|
||||
* 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
|
||||
@ -14,7 +14,8 @@
|
||||
*
|
||||
* 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.uniforms;
|
||||
|
||||
import static org.lwjgl.opengl.GL20.*;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user