Time.delta cleanup / Basic mobile input

This commit is contained in:
Anuken
2020-07-19 12:21:21 -04:00
parent f9ed74c15a
commit a074010eb7
91 changed files with 414 additions and 247 deletions

View File

@@ -114,9 +114,9 @@ abstract class BuilderComp implements Unitc{
BuildEntity entity = tile.bc();
if(current.breaking){
entity.deconstruct(base(), core, 1f / entity.buildCost * Time.delta() * type().buildSpeed * state.rules.buildSpeedMultiplier);
entity.deconstruct(base(), core, 1f / entity.buildCost * Time.delta * type().buildSpeed * state.rules.buildSpeedMultiplier);
}else{
if(entity.construct(base(), core, 1f / entity.buildCost * Time.delta() * type().buildSpeed * state.rules.buildSpeedMultiplier, current.hasConfig)){
if(entity.construct(base(), core, 1f / entity.buildCost * Time.delta * type().buildSpeed * state.rules.buildSpeedMultiplier, current.hasConfig)){
if(current.hasConfig){
Call.tileConfig(null, tile.build, current.config);
}

View File

@@ -201,14 +201,14 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
}
public Building nearby(int dx, int dy){
return world.ent(tile.x + dx, tile.y + dy);
return world.build(tile.x + dx, tile.y + dy);
}
public Building nearby(int rotation){
if(rotation == 0) return world.ent(tile.x + 1, tile.y);
if(rotation == 1) return world.ent(tile.x, tile.y + 1);
if(rotation == 2) return world.ent(tile.x - 1, tile.y);
if(rotation == 3) return world.ent(tile.x, tile.y - 1);
if(rotation == 0) return world.build(tile.x + 1, tile.y);
if(rotation == 1) return world.build(tile.x, tile.y + 1);
if(rotation == 2) return world.build(tile.x - 1, tile.y);
if(rotation == 3) return world.build(tile.x, tile.y - 1);
return null;
}
@@ -290,7 +290,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
/** Scaled delta. */
public float delta(){
return Time.delta() * timeScale;
return Time.delta * timeScale;
}
/** Efficiency * delta. */
@@ -305,7 +305,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
/** Call when nothing is happening to the entity. This increments the internal sleep timer. */
public void sleep(){
sleepTime += Time.delta();
sleepTime += Time.delta;
if(!sleeping && sleepTime >= timeToSleep){
remove();
sleeping = true;
@@ -518,14 +518,14 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
Liquid other = next.liquids().current();
if((other.flammability > 0.3f && liquid.temperature > 0.7f) || (liquid.flammability > 0.3f && other.temperature > 0.7f)){
damage(1 * Time.delta());
next.damage(1 * Time.delta());
if(Mathf.chance(0.1 * Time.delta())){
damage(1 * Time.delta);
next.damage(1 * Time.delta);
if(Mathf.chance(0.1 * Time.delta)){
Fx.fire.at(fx, fy);
}
}else if((liquid.temperature > 0.7f && other.temperature < 0.55f) || (other.temperature > 0.7f && liquid.temperature < 0.55f)){
liquids.remove(liquid, Math.min(liquids.get(liquid), 0.7f * Time.delta()));
if(Mathf.chance(0.2f * Time.delta())){
liquids.remove(liquid, Math.min(liquids.get(liquid), 0.7f * Time.delta));
if(Mathf.chance(0.2f * Time.delta)){
Fx.steam.at(fx, fy);
}
}
@@ -797,7 +797,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
int range = 10;
tempTiles.clear();
Geometry.circle(tileX(), tileY(), range, (x, y) -> {
Building other = world.ent(x, y);
Building other = world.build(x, y);
if(other != null && other.block instanceof PowerNode && ((PowerNode)other.block).linkValid(other, base()) && !PowerNode.insulated(other, base())
&& !other.proximity().contains(this.<Building>base()) &&
!(block.outputsPower && proximity.contains(p -> p.power() != null && p.power().graph == other.power().graph))){
@@ -926,60 +926,63 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
table.row();
table.table(bars -> {
bars.defaults().growX().height(18f).pad(4);
//only display everything else if the team is the same
if(team == player.team()){
table.table(bars -> {
bars.defaults().growX().height(18f).pad(4);
displayBars(bars);
}).growX();
table.row();
table.table(this::displayConsumption).growX();
displayBars(bars);
}).growX();
table.row();
table.table(this::displayConsumption).growX();
boolean displayFlow = (block.category == Category.distribution || block.category == Category.liquid) && Core.settings.getBool("flow");
boolean displayFlow = (block.category == Category.distribution || block.category == Category.liquid) && Core.settings.getBool("flow");
if(displayFlow){
String ps = " " + StatUnit.perSecond.localized();
if(displayFlow){
String ps = " " + StatUnit.perSecond.localized();
if(items != null){
table.row();
table.left();
table.table(l -> {
Bits current = new Bits();
if(items != null){
table.row();
table.left();
table.table(l -> {
Bits current = new Bits();
Runnable rebuild = () -> {
l.clearChildren();
Runnable rebuild = () -> {
l.clearChildren();
l.left();
for(Item item : content.items()){
if(items.hasFlowItem(item)){
l.image(item.icon(Cicon.small)).padRight(3f);
l.label(() -> items.getFlowRate(item) < 0 ? "..." : Strings.fixed(items.getFlowRate(item), 1) + ps).color(Color.lightGray);
l.row();
}
}
};
rebuild.run();
l.update(() -> {
for(Item item : content.items()){
if(items.hasFlowItem(item) && !current.get(item.id)){
current.set(item.id);
rebuild.run();
}
}
});
}).left();
}
if(liquids != null){
table.row();
table.table(l -> {
l.left();
for(Item item : content.items()){
if(items.hasFlowItem(item)){
l.image(item.icon(Cicon.small)).padRight(3f);
l.label(() -> items.getFlowRate(item) < 0 ? "..." : Strings.fixed(items.getFlowRate(item), 1) + ps).color(Color.lightGray);
l.row();
}
}
};
rebuild.run();
l.update(() -> {
for(Item item : content.items()){
if(items.hasFlowItem(item) && !current.get(item.id)){
current.set(item.id);
rebuild.run();
}
}
l.image(() -> liquids.current().icon(Cicon.small)).padRight(3f);
l.label(() -> liquids.getFlowRate() < 0 ? "..." : Strings.fixed(liquids.getFlowRate(), 2) + ps).color(Color.lightGray);
});
}).left();
}
}
if(liquids != null){
table.row();
table.table(l -> {
l.left();
l.image(() -> liquids.current().icon(Cicon.small)).padRight(3f);
l.label(() -> liquids.getFlowRate() < 0 ? "..." : Strings.fixed(liquids.getFlowRate(), 2) + ps).color(Color.lightGray);
});
}
table.marginBottom(-5);
}
table.marginBottom(-5);
}
public void displayConsumption(Table table){
@@ -1065,7 +1068,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
Point2[] nearby = Edges.getEdges(block.size);
for(Point2 point : nearby){
Building other = world.ent(tile.x + point.x, tile.y + point.y);
Building other = world.build(tile.x + point.x, tile.y + point.y);
//remove this tile from all nearby tile's proximities
if(other != null){
tmpTiles.add(other);
@@ -1084,7 +1087,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
Point2[] nearby = Edges.getEdges(block.size);
for(Point2 point : nearby){
Building other = world.ent(tile.x + point.x, tile.y + point.y);
Building other = world.build(tile.x + point.x, tile.y + point.y);
if(other == null || !(other.tile.interactable(team))) continue;
@@ -1175,7 +1178,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
@Final
@Override
public void update(){
timeScaleDuration -= Time.delta();
timeScaleDuration -= Time.delta;
if(timeScaleDuration <= 0f || !block.canOverdrive){
timeScale = 1f;
}

View File

@@ -111,7 +111,7 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw
if(type.collidesTiles && type.collides && type.collidesGround){
world.raycastEach(world.toTile(lastX()), world.toTile(lastY()), tileX(), tileY(), (x, y) -> {
Building tile = world.ent(x, y);
Building tile = world.build(x, y);
if(tile == null) return false;
if(tile.collide(base()) && type.collides(base(), tile) && !tile.dead() && (type.collidesTeam || tile.team != team)){

View File

@@ -26,19 +26,19 @@ abstract class FireComp implements Timedc, Posc, Firec{
@Override
public void update(){
if(Mathf.chance(0.1 * Time.delta())){
if(Mathf.chance(0.1 * Time.delta)){
Fx.fire.at(x + Mathf.range(4f), y + Mathf.range(4f));
}
if(Mathf.chance(0.05 * Time.delta())){
if(Mathf.chance(0.05 * Time.delta)){
Fx.fireSmoke.at(x + Mathf.range(4f), y + Mathf.range(4f));
}
if(Mathf.chance(0.001 * Time.delta())){
if(Mathf.chance(0.001 * Time.delta)){
Sounds.fire.at(this);
}
time = Mathf.clamp(time + Time.delta(), 0, lifetime());
time = Mathf.clamp(time + Time.delta, 0, lifetime());
if(Vars.net.client()){
return;
@@ -55,7 +55,7 @@ abstract class FireComp implements Timedc, Posc, Firec{
float flammability = baseFlammability + puddleFlammability;
if(!damage && flammability <= 0){
time += Time.delta() * 8;
time += Time.delta * 8;
}
if(baseFlammability < 0 || block != tile.block()){
@@ -64,20 +64,20 @@ abstract class FireComp implements Timedc, Posc, Firec{
}
if(damage){
lifetime += Mathf.clamp(flammability / 8f, 0f, 0.6f) * Time.delta();
lifetime += Mathf.clamp(flammability / 8f, 0f, 0.6f) * Time.delta;
}
if(flammability > 1f && Mathf.chance(spreadChance * Time.delta() * Mathf.clamp(flammability / 5f, 0.3f, 2f))){
if(flammability > 1f && Mathf.chance(spreadChance * Time.delta * Mathf.clamp(flammability / 5f, 0.3f, 2f))){
Point2 p = Geometry.d4[Mathf.random(3)];
Tile other = world.tile(tile.x + p.x, tile.y + p.y);
Fires.create(other);
if(Mathf.chance(fireballChance * Time.delta() * Mathf.clamp(flammability / 10f))){
if(Mathf.chance(fireballChance * Time.delta * Mathf.clamp(flammability / 10f))){
Bullets.fireball.createNet(Team.derelict, x, y, Mathf.random(360f), -1f, 1, 1);
}
}
if(Mathf.chance(0.1 * Time.delta())){
if(Mathf.chance(0.1 * Time.delta)){
Puddlec p = Puddles.get(tile);
puddleFlammability = p != null ? p.getFlammability() / 3f : 0;

View File

@@ -44,8 +44,8 @@ abstract class FlyingComp implements Posc, Velc, Healthc, Hitboxc{
}
void wobble(){
x += Mathf.sin(Time.time() + id() * 99, 25f, 0.05f) * Time.delta() * elevation;
y += Mathf.cos(Time.time() + id() * 99, 25f, 0.05f) * Time.delta() * elevation;
x += Mathf.sin(Time.time() + id() * 99, 25f, 0.05f) * Time.delta * elevation;
y += Mathf.cos(Time.time() + id() * 99, 25f, 0.05f) * Time.delta * elevation;
}
void moveAt(Vec2 vector, float acceleration){
@@ -81,7 +81,7 @@ abstract class FlyingComp implements Posc, Velc, Healthc, Hitboxc{
}
if(canDrown() && floor.isLiquid && floor.drownTime > 0){
drownTime += Time.delta() * 1f / floor.drownTime;
drownTime += Time.delta * 1f / floor.drownTime;
drownTime = Mathf.clamp(drownTime);
if(Mathf.chanceDelta(0.05f)){
floor.drownUpdateEffect.at(x, y, 1f, floor.mapColor);

View File

@@ -24,7 +24,7 @@ abstract class HealthComp implements Entityc{
@Override
public void update(){
hitTime -= Time.delta() / hitDuration;
hitTime -= Time.delta / hitDuration;
}
void killed(){
@@ -82,11 +82,11 @@ abstract class HealthComp implements Entityc{
}
void damageContinuous(float amount){
damage(amount * Time.delta(), hitTime <= -10 + hitDuration);
damage(amount * Time.delta, hitTime <= -10 + hitDuration);
}
void damageContinuousPierce(float amount){
damagePierce(amount * Time.delta(), hitTime <= -20 + hitDuration);
damagePierce(amount * Time.delta, hitTime <= -20 + hitDuration);
}
void clampHealth(){

View File

@@ -14,6 +14,6 @@ abstract class MechComp implements Posc, Flyingc, Hitboxc, Unitc, Mechc, Elevati
public void update(){
float len = deltaLen();
baseRotation = Angles.moveToward(baseRotation, deltaAngle(), type().baseRotateSpeed * Mathf.clamp(len / type().speed));
walkTime += Time.delta()*len;
walkTime += Time.delta *len;
}
}

View File

@@ -58,7 +58,7 @@ abstract class MinerComp implements Itemsc, Posc, Teamc, Rotc, Drawc, Unitc{
}else{
Item item = mineTile.drop();
rotation(Mathf.slerpDelta(rotation(), angleTo(mineTile.worldx(), mineTile.worldy()), 0.4f));
mineTimer += Time.delta()*type.mineSpeed;
mineTimer += Time.delta *type.mineSpeed;
if(mineTimer >= 50f + item.hardness*10f){
mineTimer = 0;
@@ -76,7 +76,7 @@ abstract class MinerComp implements Itemsc, Posc, Teamc, Rotc, Drawc, Unitc{
}
}
if(Mathf.chance(0.06 * Time.delta())){
if(Mathf.chance(0.06 * Time.delta)){
Fx.pulverizeSmall.at(mineTile.worldx() + Mathf.range(tilesize / 2f), mineTile.worldy() + Mathf.range(tilesize / 2f), 0f, item.color);
}
}

View File

@@ -119,7 +119,7 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc, Dra
}else if(core != null){
//have a small delay before death to prevent the camera from jumping around too quickly
//(this is not for balance)
deathTimer += Time.delta();
deathTimer += Time.delta;
if(deathTimer >= deathDelay){
//request spawn - this happens serverside only
core.requestSpawn(base());
@@ -127,7 +127,7 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc, Dra
}
}
textFadeTime -= Time.delta() / (60 * 5);
textFadeTime -= Time.delta / (60 * 5);
}

View File

@@ -43,13 +43,13 @@ abstract class PuddleComp implements Posc, Puddlec, Drawc{
//update code
float addSpeed = accepting > 0 ? 3f : 0f;
amount -= Time.delta() * (1f - liquid.viscosity) / (5f + addSpeed);
amount -= Time.delta * (1f - liquid.viscosity) / (5f + addSpeed);
amount += accepting;
accepting = 0f;
if(amount >= maxLiquid / 1.5f && generation < maxGeneration){
float deposited = Math.min((amount - maxLiquid / 1.5f) / 4f, 0.3f) * Time.delta();
float deposited = Math.min((amount - maxLiquid / 1.5f) / 4f, 0.3f) * Time.delta;
for(Point2 point : Geometry.d4){
Tile other = world.tile(tile.x + point.x, tile.y + point.y);
if(other != null && other.block() == Blocks.air){
@@ -87,7 +87,7 @@ abstract class PuddleComp implements Posc, Puddlec, Drawc{
updateTime = 40f;
}
updateTime -= Time.delta();
updateTime -= Time.delta;
}
@Override

View File

@@ -52,7 +52,7 @@ abstract class ShieldComp implements Healthc, Posc{
@Override
public void update(){
shieldAlpha -= Time.delta() / 15f;
shieldAlpha -= Time.delta / 15f;
if(shieldAlpha < 0) shieldAlpha = 0f;
}
}

View File

@@ -117,7 +117,7 @@ abstract class StatusComp implements Posc, Flyingc{
while(index < statuses.size){
StatusEntry entry = statuses.get(index++);
entry.time = Math.max(entry.time - Time.delta(), 0);
entry.time = Math.max(entry.time - Time.delta, 0);
applied.set(entry.effect.id);
if(entry.time <= 0 && !entry.effect.permanent){

View File

@@ -13,7 +13,7 @@ abstract class TimedComp implements Entityc, Scaled{
@MethodPriority(100)
@Override
public void update(){
time = Math.min(time + Time.delta(), lifetime);
time = Math.min(time + Time.delta, lifetime);
if(time >= lifetime){
remove();

View File

@@ -103,7 +103,7 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
}
public void lookAt(float angle){
rotation = Angles.moveToward(rotation, angle, type.rotateSpeed * Time.delta());
rotation = Angles.moveToward(rotation, angle, type.rotateSpeed * Time.delta);
}
public void lookAt(Position pos){
@@ -176,7 +176,7 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
float relativeSize = state.rules.dropZoneRadius + bounds()/2f + 1f;
for(Tile spawn : spawner.getSpawns()){
if(within(spawn.worldx(), spawn.worldy(), relativeSize)){
vel().add(Tmp.v1.set(this).sub(spawn.worldx(), spawn.worldy()).setLength(0.1f + 1f - dst(spawn) / relativeSize).scl(0.45f * Time.delta()));
vel().add(Tmp.v1.set(this).sub(spawn.worldx(), spawn.worldy()).setLength(0.1f + 1f - dst(spawn) / relativeSize).scl(0.45f * Time.delta));
}
}
}
@@ -204,7 +204,7 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
}
//move down
elevation -= type.fallSpeed * Time.delta();
elevation -= type.fallSpeed * Time.delta;
if(isGrounded()){
destroy();

View File

@@ -17,8 +17,8 @@ abstract class VelComp implements Posc{
@MethodPriority(-1)
@Override
public void update(){
move(vel.x * Time.delta(), vel.y * Time.delta());
vel.scl(1f - drag * Time.delta());
move(vel.x * Time.delta, vel.y * Time.delta);
vel.scl(1f - drag * Time.delta);
}
boolean moving(){

View File

@@ -42,7 +42,7 @@ abstract class WaterMoveComp implements Posc, Velc, Hitboxc, Flyingc, Unitc{
Floor floor = floorOn();
Color color = Tmp.c1.set(floor.mapColor).mul(1.5f);
trailColor.lerp(color, Mathf.clamp(Time.delta() * 0.04f));
trailColor.lerp(color, Mathf.clamp(Time.delta * 0.04f));
tleft.draw(trailColor, type.trailScl);
tright.draw(trailColor, type.trailScl);

View File

@@ -47,6 +47,10 @@ abstract class WeaponsComp implements Teamc, Posc, Rotc{
}
}
void controlWeapons(boolean rotateShoot){
controlWeapons(rotateShoot, rotateShoot);
}
void controlWeapons(boolean rotate, boolean shoot){
for(WeaponMount mount : mounts){
mount.rotate = rotate;
@@ -82,11 +86,11 @@ abstract class WeaponsComp implements Teamc, Posc, Rotc{
public void update(){
for(WeaponMount mount : mounts){
Weapon weapon = mount.weapon;
mount.reload = Math.max(mount.reload - Time.delta() * reloadMultiplier, 0);
mount.reload = Math.max(mount.reload - Time.delta * reloadMultiplier, 0);
//flip weapon shoot side for alternating weapons at half reload
if(weapon.otherSide != -1 && weapon.alternate && mount.side == weapon.flipSprite &&
mount.reload + Time.delta() > weapon.reload/2f && mount.reload <= weapon.reload/2f){
mount.reload + Time.delta > weapon.reload/2f && mount.reload <= weapon.reload/2f){
mounts[weapon.otherSide].side = !mounts[weapon.otherSide].side;
mount.side = !mount.side;
}
@@ -97,7 +101,7 @@ abstract class WeaponsComp implements Teamc, Posc, Rotc{
axisY = this.y + Angles.trnsy(rotation - 90, weapon.x, weapon.y);
mount.targetRotation = Angles.angle(axisX, axisY, mount.aimX, mount.aimY) - rotation;
mount.rotation = Angles.moveToward(mount.rotation, mount.targetRotation, weapon.rotateSpeed * Time.delta());
mount.rotation = Angles.moveToward(mount.rotation, mount.targetRotation, weapon.rotateSpeed * Time.delta);
}else{
mount.rotation = 0;
mount.targetRotation = angleTo(mount.aimX, mount.aimY);