Autogenerated render layer groups
This commit is contained in:
@@ -2,5 +2,4 @@ apply plugin: "java"
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
sourceSets.main.java.srcDirs = ["src/main/java/"]
|
||||
sourceSets.main.resources.srcDirs = ["src/main/resources/"]
|
||||
|
||||
sourceSets.main.resources.srcDirs = ["src/main/resources/"]
|
||||
@@ -5,14 +5,14 @@ import java.lang.annotation.*;
|
||||
public class Annotations{
|
||||
//region entity interfaces
|
||||
|
||||
/** Indicates that a component field is read-only. */
|
||||
/** Indicates that a component field is read-only.
|
||||
@Target({ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface Render{
|
||||
RenderLayer value();
|
||||
}
|
||||
}*/
|
||||
|
||||
public enum RenderLayer{
|
||||
public enum DrawLayer{
|
||||
floor,
|
||||
groundShadows,
|
||||
ground,
|
||||
|
||||
@@ -3,7 +3,6 @@ package mindustry.annotations;
|
||||
import arc.files.*;
|
||||
import arc.struct.Array;
|
||||
import arc.util.*;
|
||||
import arc.util.Log.*;
|
||||
import com.squareup.javapoet.*;
|
||||
import com.sun.source.util.*;
|
||||
import mindustry.annotations.util.*;
|
||||
@@ -154,7 +153,7 @@ public abstract class BaseProcessor extends AbstractProcessor{
|
||||
messager = env.getMessager();
|
||||
|
||||
if(System.getProperty("debug") == null){
|
||||
Log.setLogLevel(LogLevel.err);
|
||||
//Log.setLogLevel(LogLevel.err);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,8 @@ public class EntityProcess extends BaseProcessor{
|
||||
//parse groups
|
||||
for(Smethod group : allGroups){
|
||||
GroupDef an = group.annotation(GroupDef.class);
|
||||
groupDefs.add(new GroupDefinition(group.name(), types(an, GroupDef::value), an));
|
||||
Array<Stype> types = types(an, GroupDef::value);
|
||||
groupDefs.add(new GroupDefinition(group.name(), ClassName.bestGuess(packageName + "." + interfaceName(types.first())), types, an.spatial(), an.mapping()));
|
||||
}
|
||||
|
||||
//create component interfaces
|
||||
@@ -70,7 +71,8 @@ public class EntityProcess extends BaseProcessor{
|
||||
|
||||
//implement extra interfaces these components may have, e.g. position
|
||||
for(Stype extraInterface : component.interfaces().select(i -> !isCompInterface(i))){
|
||||
inter.addSuperinterface(extraInterface.mirror());
|
||||
//javapoet completely chokes on this if I add `addSuperInterface` or create the type name with TypeName.get
|
||||
inter.superinterfaces.add(tname(extraInterface.fullName()));
|
||||
}
|
||||
|
||||
//implement super interfaces
|
||||
@@ -135,18 +137,36 @@ public class EntityProcess extends BaseProcessor{
|
||||
Log.info("");
|
||||
}
|
||||
|
||||
//generate special render layer interfaces
|
||||
for(DrawLayer layer : DrawLayer.values()){
|
||||
//create the DrawLayer interface that entities need to implement
|
||||
String name = "DrawLayer" + Strings.capitalize(layer.name()) + "c";
|
||||
TypeSpec.Builder inter = TypeSpec.interfaceBuilder(name)
|
||||
.addSuperinterface(tname(packageName + ".Entityc"))
|
||||
.addModifiers(Modifier.PUBLIC).addAnnotation(EntityInterface.class);
|
||||
inter.addMethod(MethodSpec.methodBuilder("draw" + Strings.capitalize(layer.name())).addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT).build());
|
||||
write(inter);
|
||||
|
||||
//create group definition with no components directly
|
||||
GroupDefinition def = new GroupDefinition(layer.name(), ClassName.bestGuess(packageName + "." + name), Array.with(), false, false);
|
||||
//add manual inclusions of entities to be added to this group
|
||||
def.manualInclusions.addAll(allDefs.select(s -> allComponents(s).contains(comp -> comp.interfaces().contains(in -> in.name().equals(name)))));
|
||||
|
||||
groupDefs.add(def);
|
||||
}
|
||||
|
||||
//look at each definition
|
||||
for(Stype type : allDefs){
|
||||
boolean isFinal = type.annotation(EntityDef.class).isFinal();
|
||||
if(!type.name().endsWith("Def")){
|
||||
err("All entity def names must end with 'Def'", type.e);
|
||||
}
|
||||
String name = type.name().replace("Def", "Entity"); //TODO remove extra underscore
|
||||
String name = type.name().replace("Def", "Entity");
|
||||
TypeSpec.Builder builder = TypeSpec.classBuilder(name).addModifiers(Modifier.PUBLIC);
|
||||
if(isFinal) builder.addModifiers(Modifier.FINAL);
|
||||
|
||||
Array<Stype> components = allComponents(type);
|
||||
Array<GroupDefinition> groups = groupDefs.select(g -> !g.components.contains(s -> !components.contains(s)));
|
||||
Array<GroupDefinition> groups = groupDefs.select(g -> (!g.components.isEmpty() && !g.components.contains(s -> !components.contains(s))) || g.manualInclusions.contains(type));
|
||||
ObjectMap<String, Array<Smethod>> methods = new ObjectMap<>();
|
||||
|
||||
//add all components
|
||||
@@ -268,31 +288,40 @@ public class EntityProcess extends BaseProcessor{
|
||||
TypeSpec.Builder groupsBuilder = TypeSpec.classBuilder("Groups").addModifiers(Modifier.PUBLIC);
|
||||
MethodSpec.Builder groupInit = MethodSpec.methodBuilder("init").addModifiers(Modifier.PUBLIC, Modifier.STATIC);
|
||||
for(GroupDefinition group : groupDefs){
|
||||
Stype ctype = group.components.first();
|
||||
//Stype ctype = group.components.first();
|
||||
//class names for interface/group
|
||||
ClassName itype = ClassName.bestGuess("mindustry.gen." + interfaceName(ctype));
|
||||
ClassName itype = group.baseType;
|
||||
ClassName groupc = ClassName.bestGuess("mindustry.entities.EntityGroup");
|
||||
|
||||
//add field...
|
||||
groupsBuilder.addField(ParameterizedTypeName.get(
|
||||
ClassName.bestGuess("mindustry.entities.EntityGroup"), itype), group.name, Modifier.PUBLIC, Modifier.STATIC);
|
||||
|
||||
groupInit.addStatement("$L = new $T<>($L.class, $L, $L)", group.name, groupc, itype, group.def.spatial(), group.def.mapping());
|
||||
groupInit.addStatement("$L = new $T<>($L.class, $L, $L)", group.name, groupc, itype, group.spatial, group.mapping);
|
||||
}
|
||||
|
||||
//write the groups
|
||||
groupsBuilder.addMethod(groupInit.build());
|
||||
|
||||
//add method for resizing all necessary groups
|
||||
MethodSpec.Builder groupResize = MethodSpec.methodBuilder("resize")
|
||||
.addParameter(TypeName.FLOAT, "x").addParameter(TypeName.FLOAT, "y").addParameter(TypeName.FLOAT, "w").addParameter(TypeName.FLOAT, "h")
|
||||
.addModifiers(Modifier.PUBLIC, Modifier.STATIC);
|
||||
|
||||
//method resize
|
||||
for(GroupDefinition group : groupDefs){
|
||||
if(group.def.spatial()){
|
||||
if(group.spatial){
|
||||
groupResize.addStatement("$L.resize(x, y, w, h)", group.name);
|
||||
}
|
||||
}
|
||||
|
||||
for(DrawLayer layer : DrawLayer.values()){
|
||||
MethodSpec.Builder groupDraw = MethodSpec.methodBuilder("draw" + Strings.capitalize(layer.name()))
|
||||
.addModifiers(Modifier.PUBLIC, Modifier.STATIC);
|
||||
groupDraw.addStatement("$L.draw($L::$L)", layer.name(), "DrawLayer" + Strings.capitalize(layer.name()) + "c", "draw" + Strings.capitalize(layer.name()));
|
||||
groupsBuilder.addMethod(groupDraw.build());
|
||||
}
|
||||
|
||||
groupsBuilder.addMethod(groupResize.build());
|
||||
|
||||
write(groupsBuilder);
|
||||
@@ -520,13 +549,17 @@ public class EntityProcess extends BaseProcessor{
|
||||
|
||||
class GroupDefinition{
|
||||
final String name;
|
||||
final ClassName baseType;
|
||||
final Array<Stype> components;
|
||||
final GroupDef def;
|
||||
final boolean spatial, mapping;
|
||||
final ObjectSet<Stype> manualInclusions = new ObjectSet<>();
|
||||
|
||||
public GroupDefinition(String name, Array<Stype> components, GroupDef def){
|
||||
public GroupDefinition(String name, ClassName bestType, Array<Stype> components, boolean spatial, boolean mapping){
|
||||
this.baseType = bestType;
|
||||
this.components = components;
|
||||
this.name = name;
|
||||
this.def = def;
|
||||
this.spatial = spatial;
|
||||
this.mapping = mapping;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -187,7 +187,7 @@ public class Renderer implements ApplicationListener{
|
||||
|
||||
blocks.floor.drawFloor();
|
||||
|
||||
render(RenderLayer.floor);
|
||||
Groups.drawFloor();
|
||||
|
||||
blocks.processBlocks();
|
||||
blocks.drawShadows();
|
||||
@@ -208,25 +208,25 @@ public class Renderer implements ApplicationListener{
|
||||
|
||||
blocks.drawBlocks(Layer.overlay);
|
||||
|
||||
render(RenderLayer.groundShadows);
|
||||
render(RenderLayer.ground);
|
||||
Groups.drawGroundShadows();
|
||||
Groups.drawGround();
|
||||
|
||||
blocks.drawBlocks(Layer.turret);
|
||||
|
||||
render(RenderLayer.flyingShadows);
|
||||
Groups.drawFlyingShadows();
|
||||
|
||||
blocks.drawBlocks(Layer.power);
|
||||
blocks.drawBlocks(Layer.lights);
|
||||
|
||||
render(RenderLayer.flying);
|
||||
Groups.drawFlying();
|
||||
|
||||
Draw.flush();
|
||||
if(bloom != null && !pixelator.enabled()){
|
||||
bloom.capture();
|
||||
}
|
||||
|
||||
render(RenderLayer.bullets);
|
||||
render(RenderLayer.effects);
|
||||
Groups.drawBullets();
|
||||
Groups.drawEffects();
|
||||
|
||||
Draw.flush();
|
||||
if(bloom != null && !pixelator.enabled()){
|
||||
@@ -240,9 +240,9 @@ public class Renderer implements ApplicationListener{
|
||||
|
||||
overlays.drawTop();
|
||||
|
||||
render(RenderLayer.names);
|
||||
//TODO should use (draw)
|
||||
Groups.player.each(p -> !p.dead(), Playerc::drawName);
|
||||
if(!pixelator.enabled()){
|
||||
Groups.drawNames();
|
||||
}
|
||||
|
||||
if(state.rules.lighting){
|
||||
lights.draw();
|
||||
@@ -254,10 +254,6 @@ public class Renderer implements ApplicationListener{
|
||||
Draw.flush();
|
||||
}
|
||||
|
||||
private void render(RenderLayer layer){
|
||||
|
||||
}
|
||||
|
||||
private void drawLanding(){
|
||||
if(landTime > 0 && player.closestCore() != null){
|
||||
float fract = landTime / Fx.coreLand.lifetime;
|
||||
|
||||
@@ -22,9 +22,6 @@ class AllEntities{
|
||||
@EntityDef({UnitComp.class})
|
||||
class GenericUnitDef{}
|
||||
|
||||
@EntityDef({BuilderComp.class})
|
||||
class GenericBuilderDef{}
|
||||
|
||||
@GroupDef(EntityComp.class)
|
||||
void all(){
|
||||
|
||||
@@ -45,11 +42,6 @@ class AllEntities{
|
||||
|
||||
}
|
||||
|
||||
@GroupDef(DrawComp.class)
|
||||
void drawer(){
|
||||
|
||||
}
|
||||
|
||||
@GroupDef(SyncComp.class)
|
||||
void sync(){
|
||||
|
||||
|
||||
@@ -6,13 +6,27 @@ import mindustry.annotations.Annotations.*;
|
||||
import mindustry.gen.*;
|
||||
|
||||
@Component
|
||||
abstract class DrawShadowComp implements Drawc, Rotc, Flyingc{
|
||||
abstract class DrawShadowComp implements Drawc, Rotc, Flyingc, DrawLayerFlyingShadowsc, DrawLayerGroundShadowsc{
|
||||
static final float shadowTX = -12, shadowTY = -13, shadowColor = Color.toFloatBits(0, 0, 0, 0.22f);
|
||||
|
||||
transient float x, y, rotation;
|
||||
|
||||
abstract TextureRegion getShadowRegion();
|
||||
|
||||
@Override
|
||||
public void drawFlyingShadows(){
|
||||
if(isFlying()){
|
||||
drawShadow();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawGroundShadows(){
|
||||
if(isGrounded()){
|
||||
drawShadow();
|
||||
}
|
||||
}
|
||||
|
||||
void drawShadow(){
|
||||
if(!isGrounded()){
|
||||
Draw.color(shadowColor);
|
||||
|
||||
@@ -21,6 +21,10 @@ abstract class FlyingComp implements Posc, Velc, Healthc{
|
||||
return elevation < 0.001f;
|
||||
}
|
||||
|
||||
boolean isFlying(){
|
||||
return elevation >= 0.001f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
Floor floor = floorOn();
|
||||
|
||||
@@ -19,10 +19,20 @@ import mindustry.world.blocks.*;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
@Component
|
||||
abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitboxc, Rotc, Massc, Unitc, Weaponsc{
|
||||
abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitboxc, Rotc, Massc, Unitc, Weaponsc, DrawShadowc{
|
||||
private UnitController controller;
|
||||
private UnitDef type;
|
||||
|
||||
@Override
|
||||
public TextureRegion getShadowRegion(){
|
||||
return type.region;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float clipSize(){
|
||||
return type.region.getWidth() * 2f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int itemCapacity(){
|
||||
return type.itemCapacity;
|
||||
|
||||
@@ -6,6 +6,7 @@ import arc.graphics.Texture.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.graphics.gl.*;
|
||||
import arc.util.*;
|
||||
import mindustry.gen.*;
|
||||
|
||||
import static arc.Core.*;
|
||||
import static mindustry.Vars.renderer;
|
||||
@@ -52,8 +53,7 @@ public class Pixelator implements Disposable{
|
||||
Draw.rect(Draw.wrap(buffer.getTexture()), Core.camera.position.x, Core.camera.position.y, Core.camera.width, -Core.camera.height);
|
||||
Draw.blend();
|
||||
|
||||
//TODO implement drawing functions, maybe
|
||||
//Groups.player.draw(p -> !p.isDead(), Playerc::drawName);
|
||||
Groups.drawNames();
|
||||
|
||||
Core.camera.position.set(px, py);
|
||||
Core.settings.put("animatedwater", hadWater);
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
package mindustry.graphics;
|
||||
|
||||
public enum RenderLayer{
|
||||
floor,
|
||||
groundShadows,
|
||||
ground,
|
||||
flyingShadows,
|
||||
flying,
|
||||
bullets,
|
||||
effects,
|
||||
names,
|
||||
}
|
||||
Reference in New Issue
Block a user