Line optimization & cleanup

This commit is contained in:
Anuken
2020-09-15 13:19:02 -04:00
parent 1327a2bef4
commit b3d7515dcd
21 changed files with 63 additions and 66 deletions

View File

@@ -35,7 +35,7 @@ public class Blocks implements ContentList{
//environment
air, spawn, cliff, deepwater, water, taintedWater, tar, slag, stone, craters, charr, sand, darksand, dirt, ice, snow, darksandTaintedWater,
dacite, stoneWall, dirtWall, sporeWall, iceWall, daciteWall, cliffs, sporePine, snowPine, pine, shrubs, whiteTree, whiteTreeDead, sporeCluster,
dacite, stoneWall, dirtWall, sporeWall, iceWall, daciteWall, sporePine, snowPine, pine, shrubs, whiteTree, whiteTreeDead, sporeCluster,
iceSnow, sandWater, darksandWater, duneWall, sandWall, moss, sporeMoss, shale, shaleWall, shaleBoulder, sandBoulder, daciteBoulder, grass, salt,
metalFloor, metalFloorDamaged, metalFloor2, metalFloor3, metalFloor5, basalt, magmarock, hotrock, snowWall, boulder, snowBoulder, saltWall,
darkPanel1, darkPanel2, darkPanel3, darkPanel4, darkPanel5, darkPanel6, darkMetal,

View File

@@ -206,7 +206,7 @@ public class Weathers implements ContentList{
float scale = 1f / 2000f;
float scroll = Time.time() * scale;
Tmp.tr1.setTexture(noise);
Tmp.tr1.texture = noise;
Core.camera.bounds(Tmp.r1);
Tmp.tr1.set(Tmp.r1.x*scale, Tmp.r1.y*scale, (Tmp.r1.x + Tmp.r1.width)*scale, (Tmp.r1.y + Tmp.r1.height)*scale);
Tmp.tr1.scroll(-xspeed * scroll, -yspeed * scroll);
@@ -287,7 +287,7 @@ public class Weathers implements ContentList{
float scale = 1f / 2000f;
float scroll = Time.time() * scale;
Tmp.tr1.setTexture(noise);
Tmp.tr1.texture = noise;
Core.camera.bounds(Tmp.r1);
Tmp.tr1.set(Tmp.r1.x*scale, Tmp.r1.y*scale, (Tmp.r1.x + Tmp.r1.width)*scale, (Tmp.r1.y + Tmp.r1.height)*scale);
Tmp.tr1.scroll(-xspeed * scroll, -yspeed * scroll);

View File

@@ -24,7 +24,7 @@ public class MapRenderer implements Disposable{
public MapRenderer(MapEditor editor){
this.editor = editor;
this.texture = Core.atlas.find("clear-editor").getTexture();
this.texture = Core.atlas.find("clear-editor").texture;
}
public void resize(int width, int height){

View File

@@ -32,7 +32,6 @@ public class WaveGraph extends Table{
rect((x, y, width, height) -> {
Lines.stroke(Scl.scl(3f));
Lines.precise(true);
GlyphLayout lay = Pools.obtain(GlyphLayout.class, GlyphLayout::new);
Font font = Fonts.outline;
@@ -122,7 +121,6 @@ public class WaveGraph extends Table{
Pools.free(lay);
Lines.precise(false);
Draw.reset();
}).pad(4).padBottom(10).grow();

View File

@@ -61,7 +61,6 @@ public class LaserBulletType extends BulletType{
float compound = 1f;
Lines.lineAngle(b.x, b.y, b.rotation(), baseLen);
Lines.precise(true);
for(Color color : colors){
Draw.color(color);
Lines.stroke((cwidth *= lengthFalloff) * b.fout());
@@ -76,7 +75,6 @@ public class LaserBulletType extends BulletType{
compound *= lengthFalloff;
}
Lines.precise(false);
Draw.reset();
Tmp.v1.trns(b.rotation(), baseLen * 1.1f);

View File

@@ -150,15 +150,14 @@ public class Drawf{
}
public static void laser(Team team, TextureRegion line, TextureRegion edge, float x, float y, float x2, float y2, float rotation, float scale){
Tmp.v1.trns(rotation, 8f * scale * Draw.scl);
float scl = 8f * scale * Draw.scl;
float vx = Mathf.cosDeg(rotation) * scl, vy = Mathf.sinDeg(rotation) * scl;
Draw.rect(edge, x, y, edge.width * scale * Draw.scl, edge.height * scale * Draw.scl, rotation + 180);
Draw.rect(edge, x2, y2, edge.width * scale * Draw.scl, edge.height * scale * Draw.scl, rotation);
Lines.stroke(12f * scale);
Lines.precise(true);
Lines.line(line, x + Tmp.v1.x, y + Tmp.v1.y, x2 - Tmp.v1.x, y2 - Tmp.v1.y, false, 0f);
Lines.precise(false);
Lines.line(line, x + vx, y + vy, x2 - vx, y2 - vy, false);
Lines.stroke(1f);
light(team, x, y, x2, y2);

View File

@@ -98,7 +98,7 @@ public class LightRenderer{
vertices[22] = v;
vertices[23] = 0;
Draw.vert(ledge.getTexture(), vertices, 0, vertices.length);
Draw.vert(ledge.texture, vertices, 0, vertices.length);
Vec2 v3 = Tmp.v2.trnsExact(rot, stroke);
@@ -136,7 +136,7 @@ public class LightRenderer{
vertices[22] = v;
vertices[23] = 0;
Draw.vert(ledge.getTexture(), vertices, 0, vertices.length);
Draw.vert(ledge.texture, vertices, 0, vertices.length);
vertices[0] = lx2;
vertices[1] = ly2;
@@ -166,7 +166,7 @@ public class LightRenderer{
vertices[22] = v;
vertices[23] = 0;
Draw.vert(ledge.getTexture(), vertices, 0, vertices.length);
Draw.vert(ledge.texture, vertices, 0, vertices.length);
});
}

View File

@@ -98,7 +98,6 @@ public class LoadRenderer implements Disposable{
float w = Core.graphics.getWidth(), h = Core.graphics.getHeight(), s = Scl.scl();
//s = 2f;
Lines.precise(true);
Draw.proj().setOrtho(0, 0, Core.graphics.getWidth(), Core.graphics.getHeight());
@@ -467,7 +466,6 @@ public class LoadRenderer implements Disposable{
font.draw(red + "[[[[ " + key + " ]]\n"+orange+"<" + Version.modifier + " " + (Version.build == 0 ? " [init]" : Version.build == -1 ? " custom" : " " + Version.build) + ">", w/2f, h/2f + 110*s, Align.center);
}
Lines.precise(false);
Draw.flush();
fx.end();

View File

@@ -154,7 +154,7 @@ public class Shaders{
setUniformf("u_progress", progress);
setUniformf("u_uv", region.u, region.v);
setUniformf("u_uv2", region.u2, region.v2);
setUniformf("u_texsize", region.getTexture().getWidth(), region.getTexture().height);
setUniformf("u_texsize", region.texture.getWidth(), region.texture.height);
}
}
@@ -174,7 +174,7 @@ public class Shaders{
setUniformf("u_uv", region.u, region.v);
setUniformf("u_uv2", region.u2, region.v2);
setUniformf("u_time", Time.time());
setUniformf("u_texsize", region.getTexture().getWidth(), region.getTexture().height);
setUniformf("u_texsize", region.texture.getWidth(), region.texture.height);
}
}

View File

@@ -192,10 +192,10 @@ public class Mods implements Loadable{
private PageType getPage(AtlasRegion region){
return
region.getTexture() == Core.atlas.find("white").getTexture() ? PageType.main :
region.getTexture() == Core.atlas.find("stone1").getTexture() ? PageType.environment :
region.getTexture() == Core.atlas.find("clear-editor").getTexture() ? PageType.editor :
region.getTexture() == Core.atlas.find("whiteui").getTexture() ? PageType.ui :
region.texture == Core.atlas.find("white").texture ? PageType.main :
region.texture == Core.atlas.find("stone1").texture ? PageType.environment :
region.texture == Core.atlas.find("clear-editor").texture ? PageType.editor :
region.texture == Core.atlas.find("whiteui").texture ? PageType.ui :
PageType.main;
}

View File

@@ -587,10 +587,10 @@ public class UnitType extends UnlockableContent{
Draw.rect(footRegion, leg.base.x, leg.base.y, position.angleTo(leg.base));
Lines.stroke(legRegion.height * Draw.scl * flips);
Lines.line(legRegion, position.x, position.y, leg.joint.x, leg.joint.y, false, 0);
Lines.line(legRegion, position.x, position.y, leg.joint.x, leg.joint.y, false);
Lines.stroke(legBaseRegion.height * Draw.scl * flips);
Lines.line(legBaseRegion, leg.joint.x + Tmp.v1.x, leg.joint.y + Tmp.v1.y, leg.base.x, leg.base.y, false, 0);
Lines.line(legBaseRegion, leg.joint.x + Tmp.v1.x, leg.joint.y + Tmp.v1.y, leg.base.x, leg.base.y, false);
if(jointRegion.found()){
Draw.rect(jointRegion, leg.joint.x, leg.joint.y);

View File

@@ -72,7 +72,7 @@ public class Fonts{
public static void loadContentIcons(){
Seq<Font> fonts = Seq.with(Fonts.chat, Fonts.def, Fonts.outline);
Texture uitex = Core.atlas.find("logo").getTexture();
Texture uitex = Core.atlas.find("logo").texture;
int size = (int)(Fonts.def.getData().lineHeight/Fonts.def.getData().scaleY);
try(Scanner scan = new Scanner(Core.files.internal("icons/icons.properties").read(512))){
@@ -84,7 +84,7 @@ public class Fonts{
int ch = Integer.parseInt(character);
TextureRegion region = Core.atlas.find(texture);
if(region.getTexture() != uitex){
if(region.texture != uitex){
continue;
//throw new IllegalArgumentException("Font icon '" + texture + "' is not in the UI texture.");
}
@@ -160,21 +160,21 @@ public class Fonts{
//grab all textures from the ui page, remove all the regions assigned to it, then copy them over to Fonts.packer and replace the texture in this atlas.
//grab old UI texture and regions...
Texture texture = atlas.find("logo").getTexture();
Texture texture = atlas.find("logo").texture;
Page page = UI.packer.getPages().first();
Seq<AtlasRegion> regions = atlas.getRegions().select(t -> t.getTexture() == texture);
Seq<AtlasRegion> regions = atlas.getRegions().select(t -> t.texture == texture);
for(AtlasRegion region : regions){
//get new pack rect
page.setDirty(false);
Rect rect = UI.packer.pack(region.name + (region.splits != null ? ".9" : ""), atlas.getPixmap(region));
//set new texture
region.setTexture(UI.packer.getPages().first().getTexture());
region.texture = UI.packer.getPages().first().getTexture();
//set its new position
region.set((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height);
//add old texture
atlas.getTextures().add(region.getTexture());
atlas.getTextures().add(region.texture);
}
//remove old texture, it will no longer be used
@@ -191,7 +191,7 @@ public class Fonts{
if(g == null) throw new IllegalArgumentException("No glyph: " + glyph + " (" + (int)glyph + ")");
float size = Math.max(g.width, g.height);
TextureRegionDrawable draw = new TextureRegionDrawable(new TextureRegion(font.getRegion().getTexture(), g.u, g.v2, g.u2, g.v)){
TextureRegionDrawable draw = new TextureRegionDrawable(new TextureRegion(font.getRegion().texture, g.u, g.v2, g.u2, g.v)){
@Override
public void draw(float x, float y, float width, float height){
Draw.color(Tmp.c1.set(tint).mul(Draw.getColor()).toFloatBits());

View File

@@ -160,6 +160,7 @@ public class CustomRulesDialog extends BaseDialog{
title("@rules.title.enemy");
check("@rules.attack", b -> rules.attackMode = b, () -> rules.attackMode);
check("@rules.buildai", b -> rules.waveTeam.rules().ai = b, () -> rules.waveTeam.rules().ai);
number("@rules.enemycorebuildradius", f -> rules.enemyCoreBuildRadius = f * tilesize, () -> Math.min(rules.enemyCoreBuildRadius / tilesize, 200));
title("@rules.title.environment");

View File

@@ -104,7 +104,7 @@ public class LoadDialog extends BaseDialog{
button.left().add(new BorderImage(def, 4f)).update(im -> {
TextureRegionDrawable draw = (TextureRegionDrawable)im.getDrawable();
if(draw.getRegion().getTexture().isDisposed()){
if(draw.getRegion().texture.isDisposed()){
draw.setRegion(def);
}

View File

@@ -673,7 +673,7 @@ public class Block extends UnlockableContent{
public void load(){
region = Core.atlas.find(name);
if(cracks == null || (cracks[0][0].getTexture() != null && cracks[0][0].getTexture().isDisposed())){
if(cracks == null || (cracks[0][0].texture != null && cracks[0][0].texture.isDisposed())){
cracks = new TextureRegion[maxCrackSize][crackRegions];
for(int size = 1; size <= maxCrackSize; size++){
for(int i = 0; i < crackRegions; i++){

View File

@@ -45,7 +45,7 @@ public class ExtendingItemBridge extends ItemBridge{
x + Geometry.d4[i].x * tilesize / 2f,
y + Geometry.d4[i].y * tilesize / 2f,
x + ex,
y + ey, false, 0f);
y + ey, false);
Draw.rect(endRegion, x, y, i * 90 + 90);
Draw.rect(endRegion,

View File

@@ -61,11 +61,17 @@ public class ItemBridge extends Block{
if(otherReq == null) return;
Lines.stroke(8f);
Lines.line(bridgeRegion,
req.drawx(),
req.drawy(),
otherReq.drawx(),
otherReq.drawy(), false, -tilesize / 2f);
Tmp.v1.set(otherReq.drawx(), otherReq.drawx()).sub(req.drawx(), req.drawy()).setLength(-tilesize/2f);
Lines.line(
bridgeRegion,
req.drawx() + Tmp.v1.x,
req.drawy() + Tmp.v1.y,
otherReq.drawx() - Tmp.v1.x,
otherReq.drawy() - Tmp.v1.y, false
);
Draw.rect(arrowRegion, (req.drawx() + otherReq.drawx()) / 2f, (req.drawy() + otherReq.drawy()) / 2f,
Angles.angle(req.drawx(), req.drawy(), otherReq.drawx(), otherReq.drawy()));
}
@@ -296,11 +302,14 @@ public class ItemBridge extends Block{
Draw.rect(endRegion, other.drawx(), other.drawy(), i * 90 + 270);
Lines.stroke(8f);
Tmp.v1.set(x, y).sub(other.worldx(), other.worldy()).setLength(-tilesize/2f);
Lines.line(bridgeRegion,
x,
y,
other.worldx(),
other.worldy(), false, -tilesize / 2f);
x + Tmp.v1.x,
y + Tmp.v1.y,
other.worldx() - Tmp.v1.x,
other.worldy() - Tmp.v1.y, false);
int dist = Math.max(Math.abs(other.x - tile.x), Math.abs(other.y - tile.y));

View File

@@ -274,7 +274,7 @@ public class PayloadConveyor extends Block{
boolean overlaps = Intersector.intersectRectangles(bounds, sprite, over);
TextureRegion out = Tmp.tr1;
out.set(region.getTexture());
out.set(region.texture);
if(overlaps){
float w = region.u2 - region.u;

View File

@@ -67,7 +67,6 @@ public class LogicDisplay extends Block{
buffer.begin();
Draw.color(color);
Lines.stroke(stroke);
Lines.precise(true);
while(!commands.isEmpty()){
long c = commands.removeFirst();
@@ -88,8 +87,6 @@ public class LogicDisplay extends Block{
}
}
Lines.precise(false);
buffer.end();
Draw.proj(Tmp.m1);
Draw.reset();

View File

@@ -145,22 +145,19 @@ public class PowerNode extends PowerBlock{
Draw.reset();
}
protected void drawLaser(Team team, float x1, float y1, float x2, float y2, float satisfaction, int size1, int size2){
float angle1 = Angles.angle(x1, y1, x2, y2);
t1.trns(angle1, size1 * tilesize / 2f - 1.5f);
t2.trns(angle1 + 180f, size2 * tilesize / 2f - 1.5f);
x1 += t1.x;
y1 += t1.y;
x2 += t2.x;
y2 += t2.y;
protected void setupColor(float satisfaction){
float fract = 1f - satisfaction;
Draw.color(laserColor1, laserColor2, fract * 0.86f + Mathf.absin(3f, 0.1f));
Draw.alpha(renderer.laserOpacity);
Drawf.laser(team, laser, laserEnd, x1, y1, x2, y2, 0.25f);
Draw.color();
}
protected void drawLaser(Team team, float x1, float y1, float x2, float y2, int size1, int size2){
float angle1 = Angles.angle(x1, y1, x2, y2);
float vx = Mathf.cosDeg(angle1), vy = Mathf.sinDeg(angle1);
float len1 = size1 * tilesize / 2f - 1.5f, len2 = size2 * tilesize / 2f - 1.5f;
Drawf.laser(team, laser, laserEnd, x1 + vx*len1, y1 + vy*len1, x2 - vx*len2, y2 - vy*len2, 0.25f);
}
protected boolean overlaps(float srcx, float srcy, Tile other, float range){
@@ -214,6 +211,7 @@ public class PowerNode extends PowerBlock{
@Override
public void drawRequestConfigTop(BuildPlan req, Eachable<BuildPlan> list){
if(req.config instanceof Point2[]){
setupColor(1f);
for(Point2 point : (Point2[])req.config){
otherReq = null;
list.each(other -> {
@@ -224,8 +222,9 @@ public class PowerNode extends PowerBlock{
if(otherReq == null || otherReq.block == null) return;
drawLaser(player.team(), req.drawx(), req.drawy(), otherReq.drawx(), otherReq.drawy(), 1f, size, otherReq.block.size);
drawLaser(player.team(), req.drawx(), req.drawy(), otherReq.drawx(), otherReq.drawy(), size, otherReq.block.size);
}
Draw.color();
}
}
@@ -386,6 +385,7 @@ public class PowerNode extends PowerBlock{
if(Mathf.zero(renderer.laserOpacity)) return;
Draw.z(Layer.power);
setupColor(power.graph.getSatisfaction());
for(int i = 0; i < power.links.size; i++){
Building link = world.build(power.links.get(i));
@@ -394,7 +394,7 @@ public class PowerNode extends PowerBlock{
if(link.block instanceof PowerNode && !(link.pos() < tile.pos())) continue;
drawLaserTo(link);
drawLaser(team, x, y, link.x, link.y, size, link.block.size);
}
Draw.reset();
@@ -404,10 +404,6 @@ public class PowerNode extends PowerBlock{
return power.links.contains(other.pos());
}
protected void drawLaserTo(Building target){
drawLaser(team, x, y, target.x, target.y, power.graph.getSatisfaction(), size, target.block.size);
}
@Override
public Point2[] config(){
Point2[] out = new Point2[power.links.size];