From 3847434c4262654ec15996d3154fb7f4763f1cd7 Mon Sep 17 00:00:00 2001 From: Anuken Date: Thu, 10 Mar 2022 19:14:01 -0500 Subject: [PATCH] Non-stupid shockwave shader uniform setting --- core/src/mindustry/entities/Damage.java | 2 +- core/src/mindustry/graphics/Shaders.java | 22 ++++++++++------------ core/src/mindustry/io/TypeIO.java | 2 +- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/core/src/mindustry/entities/Damage.java b/core/src/mindustry/entities/Damage.java index d6c1c609f1..d561908b10 100644 --- a/core/src/mindustry/entities/Damage.java +++ b/core/src/mindustry/entities/Damage.java @@ -472,7 +472,7 @@ public class Damage{ } //cap radius to prevent lag - float radius = Math.min(baseRadius, 30), rad2 = radius * radius; + float radius = Math.min(baseRadius, 100), rad2 = radius * radius; int rays = Mathf.ceil(radius * 2 * Mathf.pi); double spacing = Math.PI * 2.0 / rays; damages.clear(); diff --git a/core/src/mindustry/graphics/Shaders.java b/core/src/mindustry/graphics/Shaders.java index 3119fc7767..71e36af43a 100644 --- a/core/src/mindustry/graphics/Shaders.java +++ b/core/src/mindustry/graphics/Shaders.java @@ -359,21 +359,15 @@ public class Shaders{ public static class ShockwaveShader extends LoadShader{ static final int max = 64; static final int size = 5; - static final String[] uniformNames = new String[max]; //x y radius life[1-0] lifetime protected FloatSeq data = new FloatSeq(); + protected FloatSeq uniforms = new FloatSeq(); protected boolean hadAny = false; protected FrameBuffer buffer = new FrameBuffer(); public float lifetime = 20f; - static{ - for(int i = 0; i < max; i++){ - uniformNames[i] = "u_shockwaves[" + i + "]"; - } - } - public ShockwaveShader(){ super("shockwave", "screenspace"); @@ -429,17 +423,21 @@ public class Shaders{ setUniformf("u_resolution", Core.camera.width, Core.camera.height); setUniformf("u_campos", Core.camera.position.x - Core.camera.width/2f, Core.camera.position.y - Core.camera.height/2f); + uniforms.clear(); + var items = data.items; for(int i = 0; i < count; i++){ int offset = i * size; - setUniformf(uniformNames[i], - items[offset], items[offset + 1], //xy - items[offset + 2] * (1f - items[offset + 3]), //radius * time - items[offset + 3] //time - //lifetime ignored + uniforms.add( + items[offset], items[offset + 1], //xy + items[offset + 2] * (1f - items[offset + 3]), //radius * time + items[offset + 3] //time + //lifetime ignored ); } + + setUniform4fv("u_shockwaves", uniforms.items, 0, uniforms.size); } } diff --git a/core/src/mindustry/io/TypeIO.java b/core/src/mindustry/io/TypeIO.java index 1861059514..00ed8bb0d6 100644 --- a/core/src/mindustry/io/TypeIO.java +++ b/core/src/mindustry/io/TypeIO.java @@ -313,7 +313,7 @@ public class TypeIO{ /** @return the maximum acceptable amount of plans to send over the network */ public static int getMaxPlans(Queue plans){ //limit to prevent buffer overflows - int used = Math.min(plans.size, 15); + int used = Math.min(plans.size, 20); int totalLength = 0; //prevent buffer overflow by checking config length