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{
//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. */

View file

@ -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));
}

View file

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

View file

@ -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})

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.*;
@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();
}

View file

@ -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

View file

@ -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;