Optimizations

This commit is contained in:
Anuken
2018-07-11 12:19:21 -04:00
parent bce0101278
commit 2b58bd5bd8
11 changed files with 21 additions and 91 deletions

View File

@@ -27,7 +27,7 @@ allprojects {
gdxVersion = '1.9.8'
roboVMVersion = '2.3.0'
aiVersion = '1.8.1'
uCoreVersion = 'e1749b8798'
uCoreVersion = '7673041e62'
getVersionString = {
String buildVersion = getBuildVersion()

View File

@@ -3,6 +3,8 @@ precision mediump float;
precision mediump int;
#endif
#define SPACE 1.0
uniform sampler2D u_texture;
uniform vec4 u_color;
@@ -11,30 +13,15 @@ uniform vec2 u_texsize;
varying vec4 v_color;
varying vec2 v_texCoord;
bool id(vec4 v){
return v.a > 0.1;
}
void main() {
vec2 T = v_texCoord.xy;
vec2 v = vec2(1.0/u_texsize.x, 1.0/u_texsize.y);
bool any = false;
vec4 c = texture2D(u_texture, v_texCoord.xy);
float step = 1.0;
vec4 c = texture2D(u_texture, T);
if(texture2D(u_texture, T).a < 0.1 &&
(id(texture2D(u_texture, T + vec2(0, step) * v)) || id(texture2D(u_texture, T + vec2(0, -step) * v)) ||
id(texture2D(u_texture, T + vec2(step, 0) * v)) || id(texture2D(u_texture, T + vec2(-step, 0) * v))))
any = true;
if(any){
gl_FragColor = u_color;
}else{
gl_FragColor = c * v_color;
}
gl_FragColor = mix(c * v_color, u_color,
(1.0-step(0.1, texture2D(u_texture, v_texCoord.xy).a)) *
step(0.1, texture2D(u_texture, v_texCoord.xy + vec2(0, SPACE) * v).a +
texture2D(u_texture, v_texCoord.xy + vec2(0, -SPACE) * v).a +
texture2D(u_texture, v_texCoord.xy + vec2(SPACE, 0) * v).a +
texture2D(u_texture, v_texCoord.xy + vec2(-SPACE, 0) * v).a));
}

View File

@@ -253,7 +253,7 @@ public class Renderer extends RendererModule{
}
private void drawFlyerShadows(){
Graphics.surface(effectSurface);
Graphics.surface(effectSurface, true, false);
float trnsX = 12, trnsY = -13;
@@ -263,12 +263,12 @@ public class Renderer extends RendererModule{
for(EntityGroup<? extends BaseUnit> group : unitGroups){
if(!group.isEmpty()){
drawAndInterpolate(group, Unit::isFlying, Unit::drawShadow);
drawAndInterpolate(group, unit -> unit.isFlying() && !unit.isDead(), Unit::drawShadow);
}
}
if(!playerGroup.isEmpty()){
drawAndInterpolate(playerGroup, Unit::isFlying, Unit::drawShadow);
drawAndInterpolate(playerGroup, unit -> unit.isFlying() && !unit.isDead(), Unit::drawShadow);
}
Graphics.end();

View File

@@ -4,10 +4,6 @@ import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.TimeUtils;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.Entities;
import io.anuke.ucore.entities.EntityGroup;
import io.anuke.ucore.entities.EntityGroup.ArrayContainer;
import io.anuke.ucore.entities.trait.Entity;
import io.anuke.ucore.util.Log;
import static io.anuke.mindustry.Vars.control;
@@ -89,9 +85,6 @@ public class ThreadHandler {
public void setEnabled(boolean enabled){
if(enabled){
logic.doUpdate = false;
for(EntityGroup<?> group : Entities.getAllGroups()){
impl.switchContainer(group);
}
Timers.runTask(2f, () -> {
impl.start(this::runLogic);
this.enabled = true;
@@ -99,9 +92,6 @@ public class ThreadHandler {
}else{
this.enabled = false;
impl.stop();
for(EntityGroup<?> group : Entities.getAllGroups()){
group.setContainer(new ArrayContainer<>());
}
Timers.runTask(2f, () -> {
logic.doUpdate = true;
});
@@ -175,6 +165,5 @@ public class ThreadHandler {
void stop();
void wait(Object object) throws InterruptedException;
void notify(Object object);
<T extends Entity> void switchContainer(EntityGroup<T> group);
}
}

View File

@@ -374,7 +374,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
float wobblyness = 0.6f;
trail.update(x + Angles.trnsx(rotation + 180f, 5f) + Mathf.range(wobblyness),
y + Angles.trnsy(rotation + 180f, 5f) + Mathf.range(wobblyness));
trail.draw(mech.trailColor, mech.trailColor, 5f * (isFlying() ? 1f : boostHeat));
trail.draw(mech.trailColor, 5f * (isFlying() ? 1f : boostHeat));
}else{
trail.clear();
}

View File

@@ -76,7 +76,7 @@ public abstract class FlyingUnit extends BaseUnit implements CarryTrait{
@Override
public void drawOver() {
trail.draw(Palette.lightTrail, Palette.lightTrail, 5f);
trail.draw(Palette.lightTrail, 5f);
}
@Override

View File

@@ -149,7 +149,7 @@ public class Drone extends FlyingUnit implements BuilderTrait {
@Override
public void drawOver() {
trail.draw(Palette.lightTrail, Palette.lightTrail, 3f);
trail.draw(Palette.lightTrail, 3f);
TargetTrait entity = target;

View File

@@ -57,7 +57,7 @@ public class BlockRenderer{
int expandr = 4;
Graphics.surface(renderer.effectSurface);
Graphics.surface(renderer.effectSurface, true, false);
int avgx = Mathf.scl(camera.position.x, tilesize);
int avgy = Mathf.scl(camera.position.y, tilesize);

View File

@@ -40,7 +40,8 @@ public class Trail {
points.clear();
}
public synchronized void draw(Color start, Color end, float stroke){
public synchronized void draw(Color color, float stroke){
Draw.color(color);
for(int i = 0; i < points.size - 2; i += 2){
float x = points.get(i);
@@ -49,8 +50,6 @@ public class Trail {
float y2 = points.get(i + 3);
float s = Mathf.clamp((float)(i) / points.size);
Draw.color(start, end, s);
Lines.stroke(s * stroke);
Lines.line(x, y, x2, y2);
}
@@ -59,8 +58,6 @@ public class Trail {
Fill.circle(points.get(points.size-2), points.get(points.size-1), stroke/2f);
}
Draw.color(start);
Draw.reset();
}
}

View File

@@ -1,5 +1,6 @@
package io.anuke.mindustry.ui;
import com.badlogic.gdx.utils.Align;
import io.anuke.ucore.function.Listenable;
import io.anuke.ucore.scene.ui.ImageButton;
@@ -10,6 +11,6 @@ public class MobileButton extends ImageButton {
resizeImage(isize);
clicked(listener);
row();
add(text).growX().wrap();
add(text).growX().wrap().center().get().setAlignment(Align.center, Align.center);
}
}

View File

@@ -1,14 +1,8 @@
package io.anuke.kryonet;
import io.anuke.mindustry.core.ThreadHandler.ThreadProvider;
import io.anuke.ucore.entities.EntityGroup;
import io.anuke.ucore.entities.EntityGroup.EntityContainer;
import io.anuke.ucore.entities.trait.Entity;
import io.anuke.ucore.util.Log;
import java.util.Iterator;
import java.util.concurrent.CopyOnWriteArrayList;
public class DefaultThreadImpl implements ThreadProvider {
private Thread thread;
@@ -54,42 +48,4 @@ public class DefaultThreadImpl implements ThreadProvider {
object.notify();
}
@Override
public <T extends Entity> void switchContainer(EntityGroup<T> group) {
group.setContainer(new ConcurrentContainer<>());
}
static class ConcurrentContainer<T> implements EntityContainer<T>{
private CopyOnWriteArrayList<T> list = new CopyOnWriteArrayList<>();
@Override
public int size() {
return list.size();
}
@Override
public void add(T item) {
list.add(item);
}
@Override
public void clear() {
list.clear();
}
@Override
public void remove(T item) {
list.remove(item);
}
@Override
public T get(int index) {
return list.get(index);
}
@Override
public Iterator<T> iterator() {
return list.iterator();
}
}
}