Scale cleanup / Name cleanup
This commit is contained in:
@@ -43,6 +43,9 @@ public class EntityProcess extends BaseProcessor{
|
|||||||
allComponents.addAll(allComponents(type));
|
allComponents.addAll(allComponents(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//add all components w/ dependencies
|
||||||
|
allComponents.addAll(types(Depends.class));
|
||||||
|
|
||||||
//create component interfaces
|
//create component interfaces
|
||||||
for(Stype component : allComponents){
|
for(Stype component : allComponents){
|
||||||
TypeSpec.Builder inter = TypeSpec.interfaceBuilder(interfaceName(component)).addModifiers(Modifier.PUBLIC).addAnnotation(EntityInterface.class);
|
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
|
//look at each definition
|
||||||
for(Stype type : allDefs){
|
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);
|
TypeSpec.Builder builder = TypeSpec.classBuilder(name).addModifiers(Modifier.PUBLIC, Modifier.FINAL);
|
||||||
|
|
||||||
Array<Stype> components = allComponents(type);
|
Array<Stype> components = allComponents(type);
|
||||||
@@ -175,10 +181,11 @@ public class EntityProcess extends BaseProcessor{
|
|||||||
}
|
}
|
||||||
|
|
||||||
String interfaceName(Stype comp){
|
String interfaceName(Stype comp){
|
||||||
if(!comp.name().endsWith("c")){
|
String suffix = "Comp";
|
||||||
err("All components must have names that end with 'c'.", comp.e);
|
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 */
|
/** @return all components that a entity def has */
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
package mindustry.entities;
|
package mindustry.entities;
|
||||||
|
|
||||||
import arc.Core;
|
import arc.*;
|
||||||
import arc.struct.Array;
|
import arc.func.*;
|
||||||
import arc.func.Cons;
|
import arc.graphics.*;
|
||||||
import arc.graphics.Color;
|
|
||||||
import arc.graphics.g2d.*;
|
import arc.graphics.g2d.*;
|
||||||
import arc.math.Mathf;
|
import arc.math.*;
|
||||||
import arc.math.geom.Position;
|
import arc.math.geom.*;
|
||||||
import arc.util.pooling.Pools;
|
import arc.struct.*;
|
||||||
import mindustry.entities.type.EffectEntity;
|
import arc.util.pooling.*;
|
||||||
import mindustry.entities.traits.ScaleTrait;
|
import mindustry.entities.type.*;
|
||||||
|
|
||||||
public class Effects{
|
public class Effects{
|
||||||
private static final EffectContainer container = new EffectContainer();
|
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 float x, y, time, lifetime, rotation;
|
||||||
public Color color;
|
public Color color;
|
||||||
public int id;
|
public int id;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package mindustry.entities.def;
|
package mindustry.entities.def;
|
||||||
|
|
||||||
import arc.math.geom.*;
|
import arc.math.geom.*;
|
||||||
import arc.util.*;
|
|
||||||
import mindustry.annotations.Annotations.*;
|
import mindustry.annotations.Annotations.*;
|
||||||
import mindustry.entities.bullet.*;
|
import mindustry.entities.bullet.*;
|
||||||
import mindustry.entities.units.*;
|
import mindustry.entities.units.*;
|
||||||
@@ -10,18 +9,18 @@ import mindustry.net.*;
|
|||||||
|
|
||||||
class EntityDefs{
|
class EntityDefs{
|
||||||
|
|
||||||
@EntityDef({Unitc.class, Connectionc.class})
|
@EntityDef({UnitComp.class, ConnectionComp.class})
|
||||||
class PlayerDef{}
|
class PlayerDef{}
|
||||||
|
|
||||||
@EntityDef({Bulletc.class, Velc.class})
|
@EntityDef({BulletComp.class, VelComp.class})
|
||||||
class BulletDef{}
|
class BulletDef{}
|
||||||
|
|
||||||
@Depends({Healthc.class, Velc.class, Statusc.class})
|
@Depends({HealthComp.class, VelComp.class, StatusComp.class})
|
||||||
class Unitc{
|
class UnitComp{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Healthc{
|
class HealthComp{
|
||||||
float health, maxHealth;
|
float health, maxHealth;
|
||||||
boolean dead;
|
boolean dead;
|
||||||
|
|
||||||
@@ -30,7 +29,7 @@ class EntityDefs{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class Posc implements Position{
|
abstract class PosComp implements Position{
|
||||||
float x, y;
|
float x, y;
|
||||||
|
|
||||||
void set(float x, float y){
|
void set(float x, float y){
|
||||||
@@ -39,8 +38,8 @@ class EntityDefs{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Depends(Posc.class)
|
@Depends(PosComp.class)
|
||||||
class Velc{
|
class VelComp{
|
||||||
//transient fields act as imports from any other component clases; these are ignored by the generator
|
//transient fields act as imports from any other component clases; these are ignored by the generator
|
||||||
transient float x, y;
|
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();
|
final Statuses statuses = new Statuses();
|
||||||
|
|
||||||
void update(){
|
void update(){
|
||||||
@@ -61,11 +72,11 @@ class EntityDefs{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Connectionc{
|
class ConnectionComp{
|
||||||
NetConnection connection;
|
NetConnection connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Bulletc{
|
class BulletComp{
|
||||||
BulletType bullet;
|
BulletType bullet;
|
||||||
|
|
||||||
void init(){
|
void init(){
|
||||||
@@ -74,7 +85,7 @@ class EntityDefs{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@BaseComponent
|
@BaseComponent
|
||||||
class Entityc{
|
class EntityComp{
|
||||||
int id;
|
int id;
|
||||||
|
|
||||||
void init(){}
|
void init(){}
|
||||||
@@ -85,13 +96,7 @@ class EntityDefs{
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void testing(){
|
static void testing(){
|
||||||
Entityt abullet = new BulletGen();
|
Entityc abullet = new BulletGen();
|
||||||
Entityt aplayer = new PlayerGen();
|
Entityc 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)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package mindustry.entities.traits;
|
package mindustry.entities.traits;
|
||||||
|
|
||||||
import arc.math.Mathf;
|
import arc.math.*;
|
||||||
import arc.util.Time;
|
import arc.util.Time;
|
||||||
|
|
||||||
public interface TimeTrait extends ScaleTrait, Entity{
|
public interface TimeTrait extends Scaled, Entity{
|
||||||
|
|
||||||
float lifetime();
|
float lifetime();
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import mindustry.world.*;
|
|||||||
|
|
||||||
import static mindustry.Vars.*;
|
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);
|
public Interval timer = new Interval(3);
|
||||||
|
|
||||||
private float lifeScl;
|
private float lifeScl;
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
package mindustry.entities.type;
|
package mindustry.entities.type;
|
||||||
|
|
||||||
import arc.util.pooling.Pool.Poolable;
|
import arc.util.pooling.Pool.*;
|
||||||
import mindustry.entities.traits.ScaleTrait;
|
import mindustry.entities.traits.*;
|
||||||
import mindustry.entities.traits.TimeTrait;
|
|
||||||
|
|
||||||
public abstract class TimedEntity extends BaseEntity implements ScaleTrait, TimeTrait, Poolable{
|
public abstract class TimedEntity extends BaseEntity implements TimeTrait, Poolable{
|
||||||
public float time;
|
public float time;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user