Merge branches 'master' and 'splinterface' of https://github.com/Anuken/Mindustry

This commit is contained in:
Anuken
2020-02-02 13:59:41 -05:00
14 changed files with 691 additions and 149 deletions

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

@@ -0,0 +1,102 @@
package mindustry.entities.def;
import arc.math.geom.*;
import mindustry.annotations.Annotations.*;
import mindustry.entities.bullet.*;
import mindustry.entities.units.*;
import mindustry.gen.*;
import mindustry.net.*;
class EntityDefs{
@EntityDef({UnitComp.class, ConnectionComp.class})
class PlayerDef{}
@EntityDef({BulletComp.class, VelComp.class})
class BulletDef{}
@Depends({HealthComp.class, VelComp.class, StatusComp.class})
class UnitComp{
}
class HealthComp{
float health, maxHealth;
boolean dead;
float healthf(){
return health / maxHealth;
}
}
abstract class PosComp implements Position{
float x, y;
void set(float x, float y){
this.x = x;
this.y = y;
}
}
@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;
final Vec2 vel = new Vec2();
void update(){
x += vel.x;
y += vel.y;
vel.scl(0.9f);
}
}
@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(){
statuses.update(null);
}
}
class ConnectionComp{
NetConnection connection;
}
class BulletComp{
BulletType bullet;
void init(){
bullet.init();
}
}
@BaseComponent
class EntityComp{
int id;
void init(){}
<T> T as(Class<T> type){
return (T)this;
}
}
static void testing(){
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