Skip to content
This repository was archived by the owner on Mar 15, 2024. It is now read-only.

Commit 2d8e4b9

Browse files
committed
Cleanup and refinements.
1 parent f8a78f0 commit 2d8e4b9

File tree

7 files changed

+100
-27
lines changed

7 files changed

+100
-27
lines changed

src/main/java/com/badlogic/gdx/checksum/CRC32.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ public String toString() {
8282
return String.format("%08x", value);
8383
}
8484

85+
public static CRC32 reset(CRC32 checksum) {
86+
checksum.value = 0;
87+
return checksum;
88+
}
89+
8590
public static boolean isNullOrZero(CRC32 checksum) {
8691
return checksum == null || checksum.value == 0;
8792
}

src/main/java/com/badlogic/gdx/function/BooleanFunction.java

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/main/java/com/badlogic/gdx/graphics/glutils/MultiTargetFrameBuffer.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,12 @@ public Texture getColorBufferTexture(int index) {
268268
return colorTextures[index];
269269
}
270270

271+
@Override
272+
protected void attachFrameBufferColorTexture() {
273+
gl30.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
274+
colorTexture.getTextureObjectHandle(), 0);
275+
}
276+
271277
public void clampToBorder(int index, Color color) {
272278
int handle = colorTextures[index].getTextureObjectHandle();
273279
gl30.glBindTexture(GL_TEXTURE_2D, handle);

src/main/java/com/badlogic/gdx/random/RandomNumbers.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ public int nextInt(final int n) {
2222
return (int) nextLong(n);
2323
}
2424

25+
public int nextInt(int start, int end) {
26+
return start + nextInt(end - start + 1);
27+
}
28+
2529
public long nextLong() {
2630
return generator.next();
2731
}

src/main/java/com/badlogic/gdx/random/XoRoShiRo128Plus.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,10 @@ public void seed(long s0, long s1) {
5555
this.s1 = s1;
5656
}
5757

58+
public void getSeed(long[] out) {
59+
out[0] = s0;
60+
out[1] = s1;
61+
}
62+
5863
}
5964

src/main/java/com/badlogic/gdx/utils/ArrayUtils.java

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package com.badlogic.gdx.utils;
22

3-
import com.badlogic.gdx.function.BooleanFunction;
4-
53
import javax.annotation.Nonnull;
64
import java.util.*;
75
import java.util.function.Consumer;
6+
import java.util.function.Predicate;
87

98
/**
109
* Array utility functions.
@@ -28,9 +27,9 @@ public static <T> void forEach(T[] array, Consumer<T> action) {
2827
* <p>
2928
* @return true if end of array was reached
3029
*/
31-
public static <T> boolean forEachWhile(T[] array, BooleanFunction<T> action) {
30+
public static <T> boolean forEachWhile(T[] array, Predicate<T> predicate) {
3231
for (T t : array) {
33-
if (!action.apply(t)) {
32+
if (!predicate.test(t)) {
3433
return false;
3534
}
3635
}
@@ -42,9 +41,9 @@ public static <T> boolean forEachWhile(T[] array, BooleanFunction<T> action) {
4241
* <p>
4342
* @return true if end of array was reached
4443
*/
45-
public static <T> boolean forEachWhile(Array<T> array, BooleanFunction<T> action) {
44+
public static <T> boolean forEachWhile(Array<T> array, Predicate<T> action) {
4645
for (T t : array) {
47-
if (!action.apply(t)) {
46+
if (!action.test(t)) {
4847
return false;
4948
}
5049
}
@@ -56,9 +55,9 @@ public static <T> boolean forEachWhile(Array<T> array, BooleanFunction<T> action
5655
* <p>
5756
* Returns null if no match is found.
5857
*/
59-
public static <T> T find(T[] array, BooleanFunction<T> match) {
58+
public static <T> T find(T[] array, Predicate<T> match) {
6059
for (T t : array) {
61-
if (match.apply(t)) {
60+
if (match.test(t)) {
6261
return t;
6362
}
6463
}
@@ -70,9 +69,9 @@ public static <T> T find(T[] array, BooleanFunction<T> match) {
7069
* <p>
7170
* Returns null if no match is found.
7271
*/
73-
public static <T> T find(Array<T> array, BooleanFunction<T> match) {
72+
public static <T> T find(Array<T> array, Predicate<T> match) {
7473
for (T t : array) {
75-
if (match.apply(t)) {
74+
if (match.test(t)) {
7675
return t;
7776
}
7877
}
@@ -84,9 +83,9 @@ public static <T> T find(Array<T> array, BooleanFunction<T> match) {
8483
* <p>
8584
* Returns -1 if no match is found.
8685
*/
87-
public static <T> int findIndex(T[] array, BooleanFunction<T> match) {
86+
public static <T> int findIndex(T[] array, Predicate<T> match) {
8887
for (int i = 0; i < array.length; i++) {
89-
if (match.apply(array[i])) {
88+
if (match.test(array[i])) {
9089
return i;
9190
}
9291
}
@@ -98,9 +97,9 @@ public static <T> int findIndex(T[] array, BooleanFunction<T> match) {
9897
* <p>
9998
* Returns -1 if no match is found.
10099
*/
101-
public static <T> int findIndex(Array<T> array, BooleanFunction<T> match) {
100+
public static <T> int findIndex(Array<T> array, Predicate<T> match) {
102101
for (int i = 0; i < array.size; i++) {
103-
if (match.apply(array.get(i))) {
102+
if (match.test(array.get(i))) {
104103
return i;
105104
}
106105
}
@@ -110,9 +109,9 @@ public static <T> int findIndex(Array<T> array, BooleanFunction<T> match) {
110109
/**
111110
* Iterates the array, consuming items only which fulfill the user-defined comparison.
112111
*/
113-
public static <T> void findAll(T[] array, BooleanFunction<T> match, Consumer<T> action) {
112+
public static <T> void findAll(T[] array, Predicate<T> match, Consumer<T> action) {
114113
for (T t : array) {
115-
if (match.apply(t)) {
114+
if (match.test(t)) {
116115
action.accept(t);
117116
}
118117
}
@@ -179,6 +178,40 @@ public static <T> T[][] expand(T[][] arrayOfArray, Class<T> clazz,
179178
return dest;
180179
}
181180

181+
/**
182+
* Expands an existing three-dimensional array.
183+
* <p>
184+
* This is a very memory-inefficient operation.
185+
*/
186+
@SuppressWarnings("unchecked")
187+
public static <T> T[][][] expand(T[][][] arrayOfArrayOfArray, Class<T> clazz,
188+
int lowerDim0, int upperDim0, int lowerDim1, int upperDim1) {
189+
190+
int columns = arrayOfArrayOfArray.length + lowerDim0 + upperDim0;
191+
int rows = arrayOfArrayOfArray[0].length + lowerDim1 + upperDim1;
192+
int depth = arrayOfArrayOfArray[0][0].length;
193+
194+
Object copy = java.lang.reflect.Array.newInstance(clazz, columns, rows, depth);
195+
196+
T[][][] dest = (T[][][]) copy;
197+
198+
for (int i = lowerDim0; i < columns - upperDim0; i++) {
199+
for (int j = lowerDim1; j < rows - upperDim1; j++) {
200+
/*for (int k = 0; k < depth; k++) {
201+
dest[i][j][k] = arrayOfArrayOfArray[i - lowerDim0][j - lowerDim1][k];
202+
}*/
203+
System.arraycopy(
204+
arrayOfArrayOfArray[i - lowerDim0][j - lowerDim1],
205+
0,
206+
dest[i][j],
207+
0,
208+
depth);
209+
}
210+
}
211+
212+
return dest;
213+
}
214+
182215
/**
183216
* Combined check for null or empty array.
184217
*/

src/main/java/com/badlogic/gdx/utils/FileUtils.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.badlogic.gdx.utils;
22

3+
import com.badlogic.gdx.Files;
34
import com.badlogic.gdx.checksum.SHA1;
5+
import com.badlogic.gdx.files.FileHandle;
46

57
import java.io.*;
68

@@ -53,4 +55,33 @@ public static SHA1 hashStream(InputStream stream) throws IOException {
5355
return sha1;
5456
}
5557

58+
public static FileHandle newFileHandle(File file, Files.FileType type) {
59+
return new FileHandleHelper(file, type);
60+
}
61+
62+
/**
63+
* Normalizes the path of a file handle.
64+
*
65+
* This does some hoops to work around some restrictions of the {@link FileHandle} class.
66+
*/
67+
public static FileHandle normalize(FileHandle file) {
68+
return new FileHandleHelper(file).normalize();
69+
}
70+
71+
private static class FileHandleHelper extends FileHandle {
72+
73+
FileHandleHelper(FileHandle file) {
74+
super(file.file(), file.type());
75+
}
76+
77+
FileHandleHelper(File file, Files.FileType type) {
78+
super(file, type);
79+
}
80+
81+
FileHandleHelper normalize() {
82+
file = file.toPath().normalize().toFile();
83+
return this;
84+
}
85+
}
86+
5687
}

0 commit comments

Comments
 (0)