Skip to content

Commit 3e217d9

Browse files
committed
fix fix
1 parent 713bf2a commit 3e217d9

2 files changed

Lines changed: 23 additions & 19 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ mod_name=MadParticle
3535
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
3636
mod_license=GNU GPL 3.0
3737
# The mod version. See https://semver.org/
38-
mod_version=26.1.2-3
38+
mod_version=26.1.2-4
3939
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
4040
# This should match the base package used for the mod sources.
4141
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html

src/main/java/cn/ussshenzhou/madparticle/particle/render/PersistentMappedArrayBuffer.java

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,45 +17,49 @@
1717
*/
1818
public class PersistentMappedArrayBuffer {
1919
private final ArrayList<PersistentMappedBuffer> buffers = new ArrayList<>();
20-
protected int byteSize, usingIndex = -1;
20+
private PersistentMappedBuffer lastUsing = null;
21+
protected int byteSize, usingIndex = 0;
2122
private static final int N = 4;
22-
private boolean trapping = false;
2323

2424
public PersistentMappedArrayBuffer() {
25+
ensureCapacity(1024 * 1024);
2526
}
2627

2728
public void ensureCapacity(int byteSize) {
28-
PersistentMappedBuffer using = usingIndex == -1 ? null : buffers.get(usingIndex);
2929
if (byteSize > this.byteSize) {
30-
buffers.forEach(persistentMappedBuffer -> {
31-
if (persistentMappedBuffer != using) {
32-
persistentMappedBuffer.free();
30+
if (lastUsing != null) {
31+
lastUsing.free();
32+
}
33+
if (!buffers.isEmpty()) {
34+
lastUsing = buffers.get(usingIndex);
35+
}
36+
for (var buffer : buffers) {
37+
if (buffer != lastUsing) {
38+
buffer.free();
3339
}
34-
});
40+
}
3541
buffers.clear();
3642
this.byteSize = (int) (byteSize * 1.25);
3743
buffers.addAll(IntStream.range(0, N).mapToObj(i -> new PersistentMappedBuffer(this.byteSize)).toList());
38-
if (using != null) {
39-
buffers.add(using);
40-
trapping = true;
41-
}
44+
usingIndex = 0;
4245
}
4346
}
4447

45-
@SuppressWarnings("SequencedCollectionMethodCanBeUsed")
4648
public PersistentMappedBuffer getNext() {
47-
return trapping ? buffers.get(0) : buffers.get((usingIndex + 1) % N);
49+
return buffers.get((usingIndex + 1) % N);
4850
}
4951

5052
public PersistentMappedBuffer getCurrent() {
51-
return trapping ? buffers.get(N) : buffers.get(usingIndex);
53+
if (lastUsing != null) {
54+
return lastUsing;
55+
}
56+
return buffers.get(usingIndex);
5257
}
5358

5459
public void next() {
55-
if (trapping) {
56-
trapping = false;
57-
usingIndex = 0;
58-
return;
60+
if (lastUsing != null) {
61+
lastUsing.free();
62+
lastUsing = null;
5963
}
6064
usingIndex = (usingIndex + 1) % N;
6165
}

0 commit comments

Comments
 (0)