Scale cleanup / Name cleanup

This commit is contained in:
Anuken 2020-02-02 13:59:24 -05:00
parent 5eb3f0f3de
commit c978410cb3
7 changed files with 52 additions and 85 deletions

View File

@ -43,6 +43,9 @@ public class EntityProcess extends BaseProcessor{
allComponents.addAll(allComponents(type));
}
//add all components w/ dependencies
allComponents.addAll(types(Depends.class));
//create component interfaces
for(Stype component : allComponents){
TypeSpec.Builder inter = TypeSpec.interfaceBuilder(interfaceName(component)).addModifiers(Modifier.PUBLIC).addAnnotation(EntityInterface.class);
@ -78,7 +81,10 @@ public class EntityProcess extends BaseProcessor{
//look at each definition
for(Stype type : allDefs){
String name = type.name().replace("Def", "Gen");
if(!type.name().endsWith("Def")){
err("All entity def names must end with 'Def'", type.e);
}
String name = type.name().replace("Def", "Gen"); //TODO remove 'gen'
TypeSpec.Builder builder = TypeSpec.classBuilder(name).addModifiers(Modifier.PUBLIC, Modifier.FINAL);
Array<Stype> components = allComponents(type);
@ -175,10 +181,11 @@ public class EntityProcess extends BaseProcessor{
}
String interfaceName(Stype comp){
if(!comp.name().endsWith("c")){
err("All components must have names that end with 'c'.", comp.e);
String suffix = "Comp";
if(!comp.name().endsWith(suffix)){
err("All components must have names that end with 'Comp'.", comp.e);
}
return comp.name().substring(0, comp.name().length() - 1) + "t";
return comp.name().substring(0, comp.name().length() - suffix.length()) + "c";
}
/** @return all components that a entity def has */

View File

@ -1,15 +1,14 @@
package mindustry.entities;
import arc.Core;
import arc.struct.Array;
import arc.func.Cons;
import arc.graphics.Color;
import arc.*;
import arc.func.*;
import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.math.Mathf;
import arc.math.geom.Position;
import arc.util.pooling.Pools;
import mindustry.entities.type.EffectEntity;
import mindustry.entities.traits.ScaleTrait;
import arc.math.*;
import arc.math.geom.*;
import arc.struct.*;
import arc.util.pooling.*;
import mindustry.entities.type.*;
public class Effects{
private static final EffectContainer container = new EffectContainer();
@ -126,7 +125,7 @@ public class Effects{
}
}
public static class EffectContainer implements ScaleTrait{
public static class EffectContainer implements Scaled{
public float x, y, time, lifetime, rotation;
public Color color;
public int id;

View File

@ -1,7 +1,6 @@
package mindustry.entities.def;
import arc.math.geom.*;
import arc.util.*;
import mindustry.annotations.Annotations.*;
import mindustry.entities.bullet.*;
import mindustry.entities.units.*;
@ -10,18 +9,18 @@ import mindustry.net.*;
class EntityDefs{
@EntityDef({Unitc.class, Connectionc.class})
@EntityDef({UnitComp.class, ConnectionComp.class})
class PlayerDef{}
@EntityDef({Bulletc.class, Velc.class})
@EntityDef({BulletComp.class, VelComp.class})
class BulletDef{}
@Depends({Healthc.class, Velc.class, Statusc.class})
class Unitc{
@Depends({HealthComp.class, VelComp.class, StatusComp.class})
class UnitComp{
}
class Healthc{
class HealthComp{
float health, maxHealth;
boolean dead;
@ -30,7 +29,7 @@ class EntityDefs{
}
}
abstract class Posc implements Position{
abstract class PosComp implements Position{
float x, y;
void set(float x, float y){
@ -39,8 +38,8 @@ class EntityDefs{
}
}
@Depends(Posc.class)
class Velc{
@Depends(PosComp.class)
class VelComp{
//transient fields act as imports from any other component clases; these are ignored by the generator
transient float x, y;
@ -53,7 +52,19 @@ class EntityDefs{
}
}
class Statusc{
@Depends(PosComp.class)
class HitboxComp{
transient float x, y;
float hitSize;
boolean collides(Hitboxc other){
return Intersector.overlapsRect(x - hitSize/2f, y - hitSize/2f, hitSize, hitSize,
other.getX() - other.getHitSize()/2f, other.getY() - other.getHitSize()/2f, other.getHitSize(), other.getHitSize());
}
}
class StatusComp{
final Statuses statuses = new Statuses();
void update(){
@ -61,11 +72,11 @@ class EntityDefs{
}
}
class Connectionc{
class ConnectionComp{
NetConnection connection;
}
class Bulletc{
class BulletComp{
BulletType bullet;
void init(){
@ -74,7 +85,7 @@ class EntityDefs{
}
@BaseComponent
class Entityc{
class EntityComp{
int id;
void init(){}
@ -85,13 +96,7 @@ class EntityDefs{
}
static void testing(){
Entityt abullet = new BulletGen();
Entityt aplayer = new PlayerGen();
if(abullet instanceof Post){
Log.info("Pos: " + abullet.as(Post.class).getX());
}
Log.info(abullet.as(Post.class).dst(aplayer.as(Post.class)));
Entityc abullet = new BulletGen();
Entityc aplayer = new PlayerGen();
}
}

View File

@ -1,43 +0,0 @@
package mindustry.entities.traits;
import arc.math.Interpolation;
public interface ScaleTrait{
/** 0 to 1. */
float fin();
/** 1 to 0 */
default float fout(){
return 1f - fin();
}
/** 1 to 0 */
default float fout(Interpolation i){
return i.apply(fout());
}
/** 1 to 0, ending at the specified margin */
default float fout(float margin){
float f = fin();
if(f >= 1f - margin){
return 1f - (f - (1f - margin)) / margin;
}else{
return 1f;
}
}
/** 0 to 1 **/
default float fin(Interpolation i){
return i.apply(fin());
}
/** 0 to 1 */
default float finpow(){
return Interpolation.pow3Out.apply(fin());
}
/** 0 to 1 to 0 */
default float fslope(){
return (0.5f - Math.abs(fin() - 0.5f)) * 2f;
}
}

View File

@ -1,9 +1,9 @@
package mindustry.entities.traits;
import arc.math.Mathf;
import arc.math.*;
import arc.util.Time;
public interface TimeTrait extends ScaleTrait, Entity{
public interface TimeTrait extends Scaled, Entity{
float lifetime();

View File

@ -16,7 +16,7 @@ import mindustry.world.*;
import static mindustry.Vars.*;
public class Bullet extends SolidEntity implements DamageTrait, ScaleTrait, Poolable, DrawTrait, VelocityTrait, TimeTrait, TeamTrait, AbsorbTrait{
public class Bullet extends SolidEntity implements DamageTrait, Scaled, Poolable, DrawTrait, VelocityTrait, TimeTrait, TeamTrait, AbsorbTrait{
public Interval timer = new Interval(3);
private float lifeScl;

View File

@ -1,10 +1,9 @@
package mindustry.entities.type;
import arc.util.pooling.Pool.Poolable;
import mindustry.entities.traits.ScaleTrait;
import mindustry.entities.traits.TimeTrait;
import arc.util.pooling.Pool.*;
import mindustry.entities.traits.*;
public abstract class TimedEntity extends BaseEntity implements ScaleTrait, TimeTrait, Poolable{
public abstract class TimedEntity extends BaseEntity implements TimeTrait, Poolable{
public float time;
@Override