This commit is contained in:
Anuken
2020-02-06 20:24:30 -05:00
parent e3136e9e09
commit f83b6728cf
8 changed files with 34 additions and 29 deletions

View File

@@ -5,16 +5,10 @@ import java.lang.annotation.*;
public class Annotations{ public class Annotations{
//region entity interfaces //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{ public enum DrawLayer{
floor, floor,
groundShadows, groundShadows,
groundUnder,
ground, ground,
flyingShadows, flyingShadows,
flying, flying,
@@ -69,6 +63,7 @@ public class Annotations{
public @interface EntityDef{ public @interface EntityDef{
Class[] value(); Class[] value();
boolean isFinal() default true; boolean isFinal() default true;
boolean pooled() default false;
} }
/** Indicates an internal interface for entity components. */ /** Indicates an internal interface for entity components. */

View File

@@ -157,7 +157,8 @@ public class EntityProcess extends BaseProcessor{
//look at each definition //look at each definition
for(Stype type : allDefs){ 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")){ if(!type.name().endsWith("Def")){
err("All entity def names must end with 'Def'", type.e); err("All entity def names must end with 'Def'", type.e);
} }
@@ -279,7 +280,7 @@ public class EntityProcess extends BaseProcessor{
//add create() method //add create() method
builder.addMethod(MethodSpec.methodBuilder("create").addModifiers(Modifier.PUBLIC, Modifier.STATIC) builder.addMethod(MethodSpec.methodBuilder("create").addModifiers(Modifier.PUBLIC, Modifier.STATIC)
.returns(tname(packageName + "." + name)) .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)); definitions.add(new EntityDefinition("mindustry.gen." + name, builder, type, components, groups));
} }

View File

@@ -209,6 +209,7 @@ public class Renderer implements ApplicationListener{
blocks.drawBlocks(Layer.overlay); blocks.drawBlocks(Layer.overlay);
Groups.drawGroundShadows(); Groups.drawGroundShadows();
Groups.drawGroundUnder();
Groups.drawGround(); Groups.drawGround();
blocks.drawBlocks(Layer.turret); blocks.drawBlocks(Layer.turret);

View File

@@ -4,13 +4,13 @@ import mindustry.annotations.Annotations.*;
class AllEntities{ class AllEntities{
@EntityDef({BulletComp.class, VelComp.class, TimedComp.class}) @EntityDef(value = {BulletComp.class, VelComp.class, TimedComp.class}, pooled = true)
class BulletDef{} class BulletDef{}
@EntityDef(value = {TileComp.class}, isFinal = false) @EntityDef(value = {TileComp.class}, isFinal = false)
class TileDef{} class TileDef{}
@EntityDef({EffectComp.class}) @EntityDef(value = {EffectComp.class}, pooled = true)
class EffectDef{} class EffectDef{}
@EntityDef({DecalComp.class}) @EntityDef({DecalComp.class})

View File

@@ -1,9 +0,0 @@
package mindustry.entities.def;
import mindustry.annotations.Annotations.*;
import mindustry.gen.*;
@Component
abstract class DrawLightComp implements Drawc{
void drawLight(){}
}

View File

@@ -8,12 +8,17 @@ import mindustry.gen.*;
import mindustry.world.blocks.*; import mindustry.world.blocks.*;
@Component @Component
abstract class LegsComp implements Posc, Flyingc, Hitboxc{ abstract class LegsComp implements Posc, Flyingc, Hitboxc, DrawLayerGroundUnderc{
transient float x, y;
float baseRotation, walkTime; float baseRotation, walkTime;
void drawLegs(){ abstract TextureRegion legRegion();
abstract TextureRegion baseRegion();
@Override
public void drawGroundUnder(){
Draw.mixcol(Color.white, hitAlpha()); Draw.mixcol(Color.white, hitAlpha());
TextureRegion legRegion = null, baseRegion = null;
float ft = Mathf.sin(walkTime * vel().len() * 5f, 6f, 2f + hitSize() / 15f); 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){ for(int i : Mathf.signs){
Draw.rect(legRegion, Draw.rect(legRegion(),
x() + Angles.trnsx(baseRotation, ft * i), x + Angles.trnsx(baseRotation, ft * i),
y() + Angles.trnsy(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); legRegion().getWidth() * i * Draw.scl, legRegion().getHeight() * Draw.scl - Mathf.clamp(ft * i, 0, 2), baseRotation - 90);
} }
if(floor.isLiquid){ if(floor.isLiquid){
@@ -36,7 +41,7 @@ abstract class LegsComp implements Posc, Flyingc, Hitboxc{
Draw.color(Color.white); Draw.color(Color.white);
} }
Draw.rect(baseRegion, x(), y(), baseRotation - 90); Draw.rect(baseRegion(), x, y, baseRotation - 90);
Draw.mixcol(); Draw.mixcol();
} }

View File

@@ -25,6 +25,14 @@ abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitbox
private UnitController controller; private UnitController controller;
private UnitDef type; private UnitDef type;
TextureRegion baseRegion(){
return type.baseRegion;
}
TextureRegion legRegion(){
return type.legRegion;
}
@Override @Override
public TextureRegion getShadowRegion(){ public TextureRegion getShadowRegion(){
return type.region; return type.region;
@@ -112,6 +120,10 @@ abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitbox
@Override @Override
public void draw(){ public void draw(){
drawCell(); drawCell();
if(type.lightRadius > 0){
renderer.lights.add(x, y, type.lightRadius, type.lightColor, type.lightOpacity);
}
} }
@Override @Override

View File

@@ -37,7 +37,7 @@ public class UnitDef extends UnlockableContent{
public float hitsize = 6f, hitsizeTile = 4f; public float hitsize = 6f, hitsizeTile = 4f;
public float cellOffsetX = 0f, cellOffsetY = 0f; public float cellOffsetX = 0f, cellOffsetY = 0f;
public float lightRadius = 60f; public float lightRadius = 60f, lightOpacity = 0.6f;
public Color lightColor = Pal.powerLight; public Color lightColor = Pal.powerLight;
public boolean drawCell = true, drawItems = true; public boolean drawCell = true, drawItems = true;