Skip to content

Commit

Permalink
fix #16
Browse files Browse the repository at this point in the history
  • Loading branch information
way-zer committed Sep 17, 2024
1 parent d428459 commit 23e3452
Showing 1 changed file with 208 additions and 3 deletions.
211 changes: 208 additions & 3 deletions patches/client/0044-OC-Batch.patch
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ way-zer <[email protected]> on 2024/7/23
顶点合并等优化已合并到arc上游
way-zer <[email protected]> on 2024/8/4
---
core/src/arc/graphics/g2d/MySpriteBatch.java | 230 +++++++++++++++++++
core/src/mindustry/graphics/MultiPacker.java | 2 +-
2 files changed, 231 insertions(+), 1 deletion(-)
core/src/arc/graphics/g2d/MySpriteBatch.java | 230 ++++++++++++++++++
core/src/mindustry/graphics/MultiPacker.java | 2 +-
.../world/blocks/logic/LogicDisplay.java | 174 +++++++------
3 files changed, 315 insertions(+), 91 deletions(-)

diff --git a/core/src/arc/graphics/g2d/MySpriteBatch.java b/core/src/arc/graphics/g2d/MySpriteBatch.java
index e2bdb30e190a210f25130c423c853892798e4c28..97228b7fadd15f0491a50849bfb19f4f3ced8bb6 100644
Expand Down Expand Up @@ -289,3 +290,207 @@ index e5f473a7651495f7f61856e6df711fba12dfb1be..f1a3f1cbbac0fbda6dfabe689f25c210

//TODO stuff like this throws OOM on some devices
environment(4096, 2048),
diff --git a/core/src/mindustry/world/blocks/logic/LogicDisplay.java b/core/src/mindustry/world/blocks/logic/LogicDisplay.java
index 1db6409a264c5977e4ccfbf7709d1db430ac31e6..c8794b047f0faccadd106edca05997af1f03c648 100644
--- a/core/src/mindustry/world/blocks/logic/LogicDisplay.java
+++ b/core/src/mindustry/world/blocks/logic/LogicDisplay.java
@@ -20,25 +20,25 @@ import mindustryX.features.*;

public class LogicDisplay extends Block{
public static final byte
- commandClear = 0,
- commandColor = 1,
- //virtual command, unpacked in instruction
- commandColorPack = 2,
- commandStroke = 3,
- commandLine = 4,
- commandRect = 5,
- commandLineRect = 6,
- commandPoly = 7,
- commandLinePoly = 8,
- commandTriangle = 9,
- commandImage = 10,
- //note that this command actually only draws 1 character, unpacked in instruction
- commandPrint = 11,
-
- commandTranslate = 12,
- commandScale = 13,
- commandRotate = 14,
- commandResetTransform = 15
+ commandClear = 0,
+ commandColor = 1,
+ //virtual command, unpacked in instruction
+ commandColorPack = 2,
+ commandStroke = 3,
+ commandLine = 4,
+ commandRect = 5,
+ commandLineRect = 6,
+ commandPoly = 7,
+ commandLinePoly = 8,
+ commandTriangle = 9,
+ commandImage = 10,
+ //note that this command actually only draws 1 character, unpacked in instruction
+ commandPrint = 11,
+
+ commandTranslate = 12,
+ commandScale = 13,
+ commandRotate = 14,
+ commandResetTransform = 15
;

public static final float scaleStep = 0.05f;
@@ -78,89 +78,83 @@ public class LogicDisplay extends Block{

//don't even bother processing anything when displays are off.
if(!Vars.renderer.drawDisplays) return;
+ Draw.draw(Draw.z(), this::draw0);
+ }

- Draw.draw(Draw.z(), () -> {
- if(buffer == null){
- buffer = new FrameBuffer(displaySize, displaySize);
- //clear the buffer - some OSs leave garbage in it
- buffer.begin(Pal.darkerMetal);
- buffer.end();
- }
- });
+ private void draw0(){
+ if(buffer == null){
+ buffer = new FrameBuffer(displaySize, displaySize);
+ //clear the buffer - some OSs leave garbage in it
+ buffer.begin(Pal.darkerMetal);
+ buffer.end();
+ }

//don't bother processing commands if displays are off
if(!commands.isEmpty()){
- Draw.draw(Draw.z(), () -> {
- Tmp.m1.set(Draw.proj());
- Tmp.m2.set(Draw.trans());
- Draw.proj(0, 0, displaySize, displaySize);
- if(transform != null){
- Draw.trans(transform);
- }
- buffer.begin();
- Draw.color(color);
- Lines.stroke(stroke);
-
- while(!commands.isEmpty()){
- long c = commands.removeFirst();
- int type = DisplayCmd.type(c);
- int x = unpackSign(DisplayCmd.x(c)), y = unpackSign(DisplayCmd.y(c)),
- p1 = unpackSign(DisplayCmd.p1(c)), p2 = unpackSign(DisplayCmd.p2(c)), p3 = unpackSign(DisplayCmd.p3(c)), p4 = unpackSign(DisplayCmd.p4(c));
-
- switch(type){
- case commandClear -> {
- //discard any pending batched sprites, so they don't get drawn over the cleared screen later
- Draw.discard();
- Core.graphics.clear(x / 255f, y / 255f, p1 / 255f, 1f);
- }
- case commandLine -> Lines.line(x, y, p1, p2);
- case commandRect -> Fill.crect(x, y, p1, p2);
- case commandLineRect -> Lines.rect(x, y, p1, p2);
- case commandPoly -> Fill.poly(x, y, Math.min(p1, maxSides), p2, p3);
- case commandLinePoly -> Lines.poly(x, y, Math.min(p1, maxSides), p2, p3);
- case commandTriangle -> Fill.tri(x, y, p1, p2, p3, p4);
- case commandColor -> Draw.color(this.color = Color.toFloatBits(x, y, p1, p2));
- case commandStroke -> Lines.stroke(this.stroke = x);
- case commandImage -> {
- if(p4 >= 0 && p4 < ContentType.all.length && Vars.content.getByID(ContentType.all[p4], p1) instanceof UnlockableContent u){
- var icon = u.fullIcon;
- Draw.rect(icon, x, y, p2, p2 / icon.ratio(), p3);
- }
+ Tmp.m1.set(Draw.proj());
+ Tmp.m2.set(Draw.trans());
+ Draw.proj(0, 0, displaySize, displaySize);
+ if(transform != null){
+ Draw.trans(transform);
+ }
+ buffer.begin();
+ Draw.color(color);
+ Lines.stroke(stroke);
+
+ while(!commands.isEmpty()){
+ long c = commands.removeFirst();
+ int type = DisplayCmd.type(c);
+ int x = unpackSign(DisplayCmd.x(c)), y = unpackSign(DisplayCmd.y(c)),
+ p1 = unpackSign(DisplayCmd.p1(c)), p2 = unpackSign(DisplayCmd.p2(c)), p3 = unpackSign(DisplayCmd.p3(c)), p4 = unpackSign(DisplayCmd.p4(c));
+
+ switch(type){
+ case commandClear -> {
+ //discard any pending batched sprites, so they don't get drawn over the cleared screen later
+ Draw.discard();
+ Core.graphics.clear(x / 255f, y / 255f, p1 / 255f, 1f);
+ }
+ case commandLine -> Lines.line(x, y, p1, p2);
+ case commandRect -> Fill.crect(x, y, p1, p2);
+ case commandLineRect -> Lines.rect(x, y, p1, p2);
+ case commandPoly -> Fill.poly(x, y, Math.min(p1, maxSides), p2, p3);
+ case commandLinePoly -> Lines.poly(x, y, Math.min(p1, maxSides), p2, p3);
+ case commandTriangle -> Fill.tri(x, y, p1, p2, p3, p4);
+ case commandColor -> Draw.color(this.color = Color.toFloatBits(x, y, p1, p2));
+ case commandStroke -> Lines.stroke(this.stroke = x);
+ case commandImage -> {
+ if(p4 >= 0 && p4 < ContentType.all.length && Vars.content.getByID(ContentType.all[p4], p1) instanceof UnlockableContent u){
+ var icon = u.fullIcon;
+ Draw.rect(icon, x, y, p2, p2 / icon.ratio(), p3);
}
- case commandPrint -> {
- var glyph = Fonts.logic.getData().getGlyph((char)p1);
- if(glyph != null){
- Tmp.tr1.set(Fonts.logic.getRegion().texture);
- Tmp.tr1.set(glyph.u, glyph.v2, glyph.u2, glyph.v);
-
- Draw.rect(Tmp.tr1, x + Tmp.tr1.width/2f + glyph.xoffset, y + Tmp.tr1.height/2f + glyph.yoffset + Fonts.logic.getData().capHeight + Fonts.logic.getData().ascent, Tmp.tr1.width, Tmp.tr1.height);
- }
+ }
+ case commandPrint -> {
+ var glyph = Fonts.logic.getData().getGlyph((char)p1);
+ if(glyph != null){
+ Tmp.tr1.set(Fonts.logic.getRegion().texture);
+ Tmp.tr1.set(glyph.u, glyph.v2, glyph.u2, glyph.v);
+
+ Draw.rect(Tmp.tr1, x + Tmp.tr1.width / 2f + glyph.xoffset, y + Tmp.tr1.height / 2f + glyph.yoffset + Fonts.logic.getData().capHeight + Fonts.logic.getData().ascent, Tmp.tr1.width, Tmp.tr1.height);
}
- case commandTranslate -> Draw.trans((transform == null ? (transform = new Mat()) : transform).translate(x, y));
- case commandScale -> Draw.trans((transform == null ? (transform = new Mat()) : transform).scale(x * scaleStep, y * scaleStep));
- case commandRotate-> Draw.trans((transform == null ? (transform = new Mat()) : transform).rotate(p1));
- case commandResetTransform -> Draw.trans((transform == null ? (transform = new Mat()) : transform).idt());
}
+ case commandTranslate -> Draw.trans((transform == null ? (transform = new Mat()) : transform).translate(x, y));
+ case commandScale -> Draw.trans((transform == null ? (transform = new Mat()) : transform).scale(x * scaleStep, y * scaleStep));
+ case commandRotate -> Draw.trans((transform == null ? (transform = new Mat()) : transform).rotate(p1));
+ case commandResetTransform -> Draw.trans((transform == null ? (transform = new Mat()) : transform).idt());
}
+ }

- buffer.end();
- Draw.proj(Tmp.m1);
- Draw.trans(Tmp.m2);
- Draw.reset();
- });
+ buffer.end();
+ Draw.proj(Tmp.m1);
+ Draw.trans(Tmp.m2);
+ Draw.reset();
}

Draw.blend(Blending.disabled);
- Draw.draw(Draw.z(), () -> {
- if(buffer != null){
- if(RenderExt.logicDisplayNoBorder){
- Draw.rect(Draw.wrap(buffer.getTexture()), x, y, (buffer.getWidth() + 16) * Draw.scl, -(buffer.getHeight() + 16) * Draw.scl);
- return;
- }
- Draw.rect(Draw.wrap(buffer.getTexture()), x, y, buffer.getWidth() * scaleFactor * Draw.scl, -buffer.getHeight() * scaleFactor * Draw.scl);
- }
- });
- Draw.blend();
+ if(RenderExt.logicDisplayNoBorder){
+ Draw.rect(Draw.wrap(buffer.getTexture()), x, y, (buffer.getWidth() + 16) * Draw.scl, -(buffer.getHeight() + 16) * Draw.scl);
+ return;
+ }
+ Draw.rect(Draw.wrap(buffer.getTexture()), x, y, buffer.getWidth() * scaleFactor * Draw.scl, -buffer.getHeight() * scaleFactor * Draw.scl);
}

@Override

0 comments on commit 23e3452

Please sign in to comment.