mirror of
https://github.com/MistWeatherMedia/WeatherSTAR-3000-Java.git
synced 2026-11-28 14:38:08 -08:00
Add files via upload
This commit is contained in:
1 parent
5eb6fade7f
commit
116a409b6d
43 files changed
+7836
No files matched your search
@@ -0,0 +1,60 @@
|
||||
package renderer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import WS3000.weatherstar3000.GameObject;
|
||||
import components.SpriteRenderer;
|
||||
|
||||
public class Renderer {
|
||||
private final int MAX_BATCH_SIZE = 2500;
|
||||
private List<RenderBatch> batches;
|
||||
|
||||
public Renderer() {
|
||||
this.batches = new ArrayList<>();
|
||||
|
||||
}
|
||||
|
||||
public void add(GameObject go) {
|
||||
SpriteRenderer spr = go.getComponent(SpriteRenderer.class);
|
||||
if (spr != null) {
|
||||
add(spr);
|
||||
}
|
||||
}
|
||||
|
||||
private void add(SpriteRenderer sprite) {
|
||||
boolean added = false;
|
||||
for (RenderBatch batch : batches) {
|
||||
if (batch.hasRoom() && batch.zIndex() == sprite.gameObject.zIndex()) {
|
||||
Texture tex = sprite.getTexture();
|
||||
if (tex == null || (batch.hasTexture(tex) || batch.hasTextureRoom())) {
|
||||
batch.addSprite(sprite);
|
||||
added = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!added) {
|
||||
RenderBatch newBatch = new RenderBatch(MAX_BATCH_SIZE, sprite.gameObject.zIndex());
|
||||
newBatch.start();
|
||||
batches.add(newBatch);
|
||||
newBatch.addSprite(sprite);
|
||||
Collections.sort(batches);
|
||||
}
|
||||
}
|
||||
|
||||
public void render() {
|
||||
for (RenderBatch batch : batches) {
|
||||
batch.render();
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
for (RenderBatch batch : batches) {
|
||||
batch.clear(); // Resets numSprites to 0
|
||||
}
|
||||
//this.batches.clear();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user