Skip to content

Commit

Permalink
revert "fix #16";
Browse files Browse the repository at this point in the history
fix NPE when bulletShow=false;
fix "D/V/T/F" need restart
  • Loading branch information
way-zer committed Sep 19, 2024
1 parent e1f57a9 commit aa95d18
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 232 deletions.
16 changes: 7 additions & 9 deletions patches/client/0036-API-C-DebugUtil.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.*;
Expand All @@ -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");
211 changes: 3 additions & 208 deletions patches/client/0037-OC-Batch.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion patches/client/0038-H-UI-AuxiliaryTools.patch
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Subject: [PATCH] H(UI): AuxiliaryTools
1 file changed, 13 insertions(+)

diff --git a/core/src/mindustry/ui/fragments/HudFragment.java b/core/src/mindustry/ui/fragments/HudFragment.java
index fe959362b9a79dbeb79eb12f5ce73ef693e0cd33..2c674865d350123c3eba5f402dc528b0b94ef210 100644
index d13458daa505cb321dfb02b173cfd4ad6b3f4eb5..0b3d391dbea4bdd88e1a9635ff8510d476477328 100644
--- a/core/src/mindustry/ui/fragments/HudFragment.java
+++ b/core/src/mindustry/ui/fragments/HudFragment.java
@@ -42,6 +42,7 @@ public class HudFragment{
Expand Down
4 changes: 2 additions & 2 deletions patches/client/0039-H-UI-NewCoreItemsDisplay.patch
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Content-Transfer-Encoding: 8bit
1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/core/src/mindustry/ui/fragments/HudFragment.java b/core/src/mindustry/ui/fragments/HudFragment.java
index 2c674865d350123c3eba5f402dc528b0b94ef210..c84b479b57324153c9f5de05d6d656d2d5e48271 100644
index 0b3d391dbea4bdd88e1a9635ff8510d476477328..d8579557ba0378190e5f9ffb3ca0747c9857492c 100644
--- a/core/src/mindustry/ui/fragments/HudFragment.java
+++ b/core/src/mindustry/ui/fragments/HudFragment.java
@@ -30,6 +30,7 @@ import mindustry.ui.*;
Expand Down Expand Up @@ -44,7 +44,7 @@ index 2c674865d350123c3eba5f402dc528b0b94ef210..c84b479b57324153c9f5de05d6d656d2
//paused table
parent.fill(t -> {
t.name = "paused";
@@ -333,8 +329,9 @@ public class HudFragment{
@@ -331,8 +327,9 @@ public class HudFragment{
t.collapser(v -> v.add().height(pauseHeight), () -> state.isPaused() && !netServer.isWaitingForPlayers()).row();

t.table(c -> {
Expand Down
16 changes: 15 additions & 1 deletion patches/client/0056-OC-no-bullet-create-when-hidden.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Subject: [PATCH] OC: no bullet create when hidden

---
core/src/mindustry/entities/bullet/BulletType.java | 2 ++
1 file changed, 2 insertions(+)
core/src/mindustry/type/Weapon.java | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/core/src/mindustry/entities/bullet/BulletType.java b/core/src/mindustry/entities/bullet/BulletType.java
index 160a45d8d245cdf0fe60baaa1c92ca135bf53a5c..aabfd4f3750978651e912a2dac5ad651b67a6a97 100644
Expand All @@ -27,3 +28,16 @@ index 160a45d8d245cdf0fe60baaa1c92ca135bf53a5c..aabfd4f3750978651e912a2dac5ad651
if(!Mathf.chance(createChance)) return null;
if(ignoreSpawnAngle) angle = 0;
if(spawnUnit != null){
diff --git a/core/src/mindustry/type/Weapon.java b/core/src/mindustry/type/Weapon.java
index f9ec8feac6e944e76b5e2309da9b78e9d1269348..bf50d03c33d9251ce0c7d600beba56ca1a7c578a 100644
--- a/core/src/mindustry/type/Weapon.java
+++ b/core/src/mindustry/type/Weapon.java
@@ -525,7 +525,7 @@ public class Weapon implements Cloneable{

//override to do special things to a bullet after spawning
protected void handleBullet(Unit unit, WeaponMount mount, Bullet bullet){
- if(continuous){
+ if(continuous && bullet != null){
float
weaponRotation = unit.rotation - 90 + (rotate ? mount.rotation : baseRotation),
mountX = unit.x + Angles.trnsx(unit.rotation - 90, x, y),
Loading

0 comments on commit aa95d18

Please sign in to comment.