forked from Anuken/Mindustry
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix NPE when bulletShow=false; fix "D/V/T/F" need restart
- Loading branch information
Showing
6 changed files
with
40 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,8 @@ way-zer <[email protected]> on 2024/7/21 | |
core/src/arc/graphics/g2d/MySpriteBatch.java | 26 +++++++++++++++++++ | ||
core/src/mindustry/ClientLauncher.java | 2 +- | ||
core/src/mindustry/core/Logic.java | 3 +++ | ||
.../mindustry/ui/fragments/HudFragment.java | 9 +++++++ | ||
4 files changed, 39 insertions(+), 1 deletion(-) | ||
.../mindustry/ui/fragments/HudFragment.java | 7 +++++ | ||
4 files changed, 37 insertions(+), 1 deletion(-) | ||
create mode 100644 core/src/arc/graphics/g2d/MySpriteBatch.java | ||
|
||
diff --git a/core/src/arc/graphics/g2d/MySpriteBatch.java b/core/src/arc/graphics/g2d/MySpriteBatch.java | ||
|
@@ -90,7 +90,7 @@ index d1c7c5ca602c6c765cc62c9e2f0b384c3ad0a254..b640803511bcae93b5c8d8c71ffdc23b | |
|
||
/** @return whether the wave timer is paused due to enemies */ | ||
diff --git a/core/src/mindustry/ui/fragments/HudFragment.java b/core/src/mindustry/ui/fragments/HudFragment.java | ||
index 23d4ad03c71131265f82478a0285110cdf71059d..fe959362b9a79dbeb79eb12f5ce73ef693e0cd33 100644 | ||
index 23d4ad03c71131265f82478a0285110cdf71059d..d13458daa505cb321dfb02b173cfd4ad6b3f4eb5 100644 | ||
--- a/core/src/mindustry/ui/fragments/HudFragment.java | ||
+++ b/core/src/mindustry/ui/fragments/HudFragment.java | ||
@@ -29,6 +29,7 @@ import mindustry.type.*; | ||
|
@@ -101,18 +101,16 @@ index 23d4ad03c71131265f82478a0285110cdf71059d..fe959362b9a79dbeb79eb12f5ce73ef6 | |
|
||
import static mindustry.Vars.*; | ||
import static mindustry.gen.Tex.*; | ||
@@ -282,6 +283,14 @@ public class HudFragment{ | ||
@@ -282,6 +283,12 @@ public class HudFragment{ | ||
|
||
info.label(() -> fps.get(Core.graphics.getFramesPerSecond())).left().style(Styles.outlineLabel).name("fps"); | ||
info.row(); | ||
+ info.label(() -> Strings.format("LG/DW/UI(ms) @/@/@", Time.nanosToMillis(DebugUtil.logicTime), Time.nanosToMillis(DebugUtil.rendererTime), Time.nanosToMillis(DebugUtil.uiTime))) | ||
+ .left().style(Styles.outlineLabel).name("cpuTime"); | ||
+ info.row(); | ||
+ if(DebugUtil.renderDebug){ | ||
+ info.label(() -> Strings.format("D/V/T/F @/@/@/@", | ||
+ DebugUtil.lastDrawRequests, DebugUtil.lastVertices, DebugUtil.lastSwitchTexture, DebugUtil.lastFlushCount)).left().style(Styles.outlineLabel).name("draw"); | ||
+ info.row(); | ||
+ } | ||
+ info.collapser(t-> t.label(() -> Strings.format("D/V/T/F @/@/@/@", | ||
+ DebugUtil.lastDrawRequests, DebugUtil.lastVertices, DebugUtil.lastSwitchTexture, DebugUtil.lastFlushCount)).left().style(Styles.outlineLabel).name("draw"), ()->DebugUtil.renderDebug); | ||
+ info.row(); | ||
|
||
if(android){ | ||
info.label(() -> memnative.get((int)(Core.app.getJavaHeap() / 1024 / 1024), (int)(Core.app.getNativeHeap() / 1024 / 1024))).left().style(Styles.outlineLabel).name("memory2"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,10 +22,9 @@ way-zer <[email protected]> on 2024/7/23 | |
顶点合并等优化已合并到arc上游 | ||
way-zer <[email protected]> on 2024/8/4 | ||
--- | ||
core/src/arc/graphics/g2d/MySpriteBatch.java | 224 ++++++++++++++++++ | ||
core/src/mindustry/graphics/MultiPacker.java | 2 +- | ||
.../world/blocks/logic/LogicDisplay.java | 174 +++++++------- | ||
3 files changed, 309 insertions(+), 91 deletions(-) | ||
core/src/arc/graphics/g2d/MySpriteBatch.java | 224 +++++++++++++++++++ | ||
core/src/mindustry/graphics/MultiPacker.java | 2 +- | ||
2 files changed, 225 insertions(+), 1 deletion(-) | ||
|
||
diff --git a/core/src/arc/graphics/g2d/MySpriteBatch.java b/core/src/arc/graphics/g2d/MySpriteBatch.java | ||
index e2bdb30e190a210f25130c423c853892798e4c28..f0c580f01f0a0014870d1f37b37cbf4eeb4748d6 100644 | ||
|
@@ -284,207 +283,3 @@ 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.