mirror of
https://github.com/darksaid98/Flashback.git
synced 2026-12-01 22:16:01 +00:00
Stuff
This commit is contained in:
1 parent
9c4a30d224
commit
666398e480
174 files changed
+8694
-2942
No files matched your search
@@ -0,0 +1,68 @@
|
||||
package com.moulberry.flashback.exporting;
|
||||
|
||||
import com.mojang.blaze3d.platform.NativeImage;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SaveableFramebufferQueue implements AutoCloseable {
|
||||
|
||||
private final int width;
|
||||
private final int height;
|
||||
|
||||
private static final int CAPACITY = 3;
|
||||
|
||||
private final List<SaveableFramebuffer> available = new ArrayList<>();
|
||||
private final List<SaveableFramebuffer> waiting = new ArrayList<>();
|
||||
|
||||
public SaveableFramebufferQueue(int width, int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
for (int i = 0; i < CAPACITY; i++) {
|
||||
this.available.add(new SaveableFramebuffer());
|
||||
}
|
||||
}
|
||||
|
||||
public SaveableFramebuffer take() {
|
||||
if (this.available.isEmpty()) {
|
||||
throw new IllegalStateException("No textures available!");
|
||||
}
|
||||
return this.available.removeFirst();
|
||||
}
|
||||
|
||||
public void startDownload(SaveableFramebuffer texture) {
|
||||
texture.startDownload(this.width, this.height);
|
||||
this.waiting.add(texture);
|
||||
}
|
||||
|
||||
public @Nullable NativeImage finishDownload(boolean drain) {
|
||||
if (this.waiting.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!drain && !this.available.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
SaveableFramebuffer texture = this.waiting.removeFirst();
|
||||
NativeImage nativeImage = texture.finishDownload(this.width, this.height);
|
||||
this.available.add(texture);
|
||||
return nativeImage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
for (SaveableFramebuffer texture : this.waiting) {
|
||||
texture.close();
|
||||
}
|
||||
for (SaveableFramebuffer texture : this.available) {
|
||||
texture.close();
|
||||
}
|
||||
this.waiting.clear();
|
||||
this.available.clear();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user