diff --git a/annotations/src/main/java/mindustry/annotations/Annotations.java b/annotations/src/main/java/mindustry/annotations/Annotations.java index 65c3942f76..e82d6f567b 100644 --- a/annotations/src/main/java/mindustry/annotations/Annotations.java +++ b/annotations/src/main/java/mindustry/annotations/Annotations.java @@ -5,16 +5,10 @@ import java.lang.annotation.*; public class Annotations{ //region entity interfaces - /** Indicates that a component field is read-only. - @Target({ElementType.METHOD}) - @Retention(RetentionPolicy.SOURCE) - public @interface Render{ - RenderLayer value(); - }*/ - public enum DrawLayer{ floor, groundShadows, + groundUnder, ground, flyingShadows, flying, @@ -69,6 +63,7 @@ public class Annotations{ public @interface EntityDef{ Class[] value(); boolean isFinal() default true; + boolean pooled() default false; } /** Indicates an internal interface for entity components. */ diff --git a/annotations/src/main/java/mindustry/annotations/impl/EntityProcess.java b/annotations/src/main/java/mindustry/annotations/impl/EntityProcess.java index d6ce2ad8a0..d541cbdf97 100644 --- a/annotations/src/main/java/mindustry/annotations/impl/EntityProcess.java +++ b/annotations/src/main/java/mindustry/annotations/impl/EntityProcess.java @@ -157,7 +157,8 @@ public class EntityProcess extends BaseProcessor{ //look at each definition for(Stype type : allDefs){ - boolean isFinal = type.annotation(EntityDef.class).isFinal(); + EntityDef ann = type.annotation(EntityDef.class); + boolean isFinal = ann.isFinal(); if(!type.name().endsWith("Def")){ err("All entity def names must end with 'Def'", type.e); } @@ -279,7 +280,7 @@ public class EntityProcess extends BaseProcessor{ //add create() method builder.addMethod(MethodSpec.methodBuilder("create").addModifiers(Modifier.PUBLIC, Modifier.STATIC) .returns(tname(packageName + "." + name)) - .addStatement("return new $L()", name).build()); + .addStatement(ann.pooled() ? "return " : "return new $L()", name).build()); definitions.add(new EntityDefinition("mindustry.gen." + name, builder, type, components, groups)); } diff --git a/core/src/mindustry/core/Renderer.java b/core/src/mindustry/core/Renderer.java index 0597c870d8..1d1f1abb80 100644 --- a/core/src/mindustry/core/Renderer.java +++ b/core/src/mindustry/core/Renderer.java @@ -209,6 +209,7 @@ public class Renderer implements ApplicationListener{ blocks.drawBlocks(Layer.overlay); Groups.drawGroundShadows(); + Groups.drawGroundUnder(); Groups.drawGround(); blocks.drawBlocks(Layer.turret); diff --git a/core/src/mindustry/entities/def/AllEntities.java b/core/src/mindustry/entities/def/AllEntities.java index 06b6d8036b..c8dee75ac2 100644 --- a/core/src/mindustry/entities/def/AllEntities.java +++ b/core/src/mindustry/entities/def/AllEntities.java @@ -4,13 +4,13 @@ import mindustry.annotations.Annotations.*; class AllEntities{ - @EntityDef({BulletComp.class, VelComp.class, TimedComp.class}) + @EntityDef(value = {BulletComp.class, VelComp.class, TimedComp.class}, pooled = true) class BulletDef{} @EntityDef(value = {TileComp.class}, isFinal = false) class TileDef{} - @EntityDef({EffectComp.class}) + @EntityDef(value = {EffectComp.class}, pooled = true) class EffectDef{} @EntityDef({DecalComp.class}) diff --git a/core/src/mindustry/entities/def/DrawLightComp.java b/core/src/mindustry/entities/def/DrawLightComp.java deleted file mode 100644 index 5fd8cc02d2..0000000000 --- a/core/src/mindustry/entities/def/DrawLightComp.java +++ /dev/null @@ -1,9 +0,0 @@ -package mindustry.entities.def; - -import mindustry.annotations.Annotations.*; -import mindustry.gen.*; - -@Component -abstract class DrawLightComp implements Drawc{ - void drawLight(){} -} diff --git a/core/src/mindustry/entities/def/LegsComp.java b/core/src/mindustry/entities/def/LegsComp.java index 658bc3aa33..1c01d0d32b 100644 --- a/core/src/mindustry/entities/def/LegsComp.java +++ b/core/src/mindustry/entities/def/LegsComp.java @@ -8,12 +8,17 @@ import mindustry.gen.*; import mindustry.world.blocks.*; @Component -abstract class LegsComp implements Posc, Flyingc, Hitboxc{ +abstract class LegsComp implements Posc, Flyingc, Hitboxc, DrawLayerGroundUnderc{ + transient float x, y; + float baseRotation, walkTime; - void drawLegs(){ + abstract TextureRegion legRegion(); + abstract TextureRegion baseRegion(); + + @Override + public void drawGroundUnder(){ Draw.mixcol(Color.white, hitAlpha()); - TextureRegion legRegion = null, baseRegion = null; float ft = Mathf.sin(walkTime * vel().len() * 5f, 6f, 2f + hitSize() / 15f); @@ -24,10 +29,10 @@ abstract class LegsComp implements Posc, Flyingc, Hitboxc{ } for(int i : Mathf.signs){ - Draw.rect(legRegion, - x() + Angles.trnsx(baseRotation, ft * i), - y() + Angles.trnsy(baseRotation, ft * i), - legRegion.getWidth() * i * Draw.scl, legRegion.getHeight() * Draw.scl - Mathf.clamp(ft * i, 0, 2), baseRotation - 90); + Draw.rect(legRegion(), + x + Angles.trnsx(baseRotation, ft * i), + y + Angles.trnsy(baseRotation, ft * i), + legRegion().getWidth() * i * Draw.scl, legRegion().getHeight() * Draw.scl - Mathf.clamp(ft * i, 0, 2), baseRotation - 90); } if(floor.isLiquid){ @@ -36,7 +41,7 @@ abstract class LegsComp implements Posc, Flyingc, Hitboxc{ Draw.color(Color.white); } - Draw.rect(baseRegion, x(), y(), baseRotation - 90); + Draw.rect(baseRegion(), x, y, baseRotation - 90); Draw.mixcol(); } diff --git a/core/src/mindustry/entities/def/UnitComp.java b/core/src/mindustry/entities/def/UnitComp.java index 57255ef3e7..27b6b28d66 100644 --- a/core/src/mindustry/entities/def/UnitComp.java +++ b/core/src/mindustry/entities/def/UnitComp.java @@ -25,6 +25,14 @@ abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitbox private UnitController controller; private UnitDef type; + TextureRegion baseRegion(){ + return type.baseRegion; + } + + TextureRegion legRegion(){ + return type.legRegion; + } + @Override public TextureRegion getShadowRegion(){ return type.region; @@ -112,6 +120,10 @@ abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitbox @Override public void draw(){ drawCell(); + + if(type.lightRadius > 0){ + renderer.lights.add(x, y, type.lightRadius, type.lightColor, type.lightOpacity); + } } @Override diff --git a/core/src/mindustry/type/UnitDef.java b/core/src/mindustry/type/UnitDef.java index 6faa2f6260..d7f7cf808b 100644 --- a/core/src/mindustry/type/UnitDef.java +++ b/core/src/mindustry/type/UnitDef.java @@ -37,7 +37,7 @@ public class UnitDef extends UnlockableContent{ public float hitsize = 6f, hitsizeTile = 4f; public float cellOffsetX = 0f, cellOffsetY = 0f; - public float lightRadius = 60f; + public float lightRadius = 60f, lightOpacity = 0.6f; public Color lightColor = Pal.powerLight; public boolean drawCell = true, drawItems = true;