Memory optimizations, multithreading fixes, uCore updated

This commit is contained in:
Anuken
2018-06-05 14:03:08 -04:00
parent c5ed0afb4e
commit 917e2e40fb
87 changed files with 1018 additions and 752 deletions

View File

@@ -28,10 +28,7 @@ import io.anuke.ucore.entities.trait.SolidTrait;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Fill;
import io.anuke.ucore.graphics.Lines;
import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Geometry;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Timer;
import io.anuke.ucore.util.*;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@@ -69,7 +66,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
private boolean respawning;
private float walktime;
private Queue<BuildRequest> placeQueue = new Queue<>();
private Queue<BuildRequest> placeQueue = new ThreadQueue<>();
private Tile mining;
private CarriableTrait carrying;
private Trail trail = new Trail(16);
@@ -239,13 +236,13 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
}
for (int i : Mathf.signs) {
Draw.rect(mname + "-leg",
Draw.rect(mech.legRegion,
x + Angles.trnsx(baseRotation, ft * i),
y + Angles.trnsy(baseRotation, ft * i),
12f * i, 12f - Mathf.clamp(ft * i, 0, 2), baseRotation - 90);
}
Draw.rect(mname + "-base", x, y,baseRotation- 90);
Draw.rect(mech.baseRegion, x, y, baseRotation- 90);
}
if(floor.liquid) {
@@ -254,13 +251,13 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
Draw.tint(Color.WHITE);
}
Draw.rect(mname, x, y, rotation -90);
Draw.rect(mech.region, x, y, rotation -90);
for (int i : Mathf.signs) {
float tra = rotation - 90,
trX = 4*i, trY = 3 - weapon.getRecoil(this, i > 0)*1.5f;
float w = i > 0 ? -8 : 8;
Draw.rect(weapon.name + "-equip",
Draw.rect(weapon.equipRegion,
x + Angles.trnsx(tra, trX, trY),
y + Angles.trnsy(tra, trX, trY), w, 8, rotation - 90);
}
@@ -413,11 +410,15 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
if(ui.chatfrag.chatOpen()) return;
float speed = Inputs.keyDown("dash") ? (debug ? Player.dashSpeed * 5f : Player.dashSpeed) : Player.walkSpeed;
float carrySlowdown = 0.3f;
speed *= ((1f-carrySlowdown) + (inventory.hasItem() ? (float)inventory.getItem().amount/inventory.capacity(): 1f) * carrySlowdown);
//drop from carrier on key press
if(Inputs.keyTap("drop_unit") && getCarrier() != null){
getCarrier().dropCarry();
}
movement.set(0, 0);
String section = "player_" + (playerIndex + 1);
@@ -549,6 +550,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait {
placeQueue.clear();
dead = true;
respawning = false;
trail.clear();
add();
heal();

View File

@@ -1,6 +1,7 @@
package io.anuke.mindustry.entities.bullet;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.Angles;
@@ -9,16 +10,26 @@ import io.anuke.ucore.util.Mathf;
/**A BulletType for most ammo-based bullets shot from turrets and units.*/
public class BasicBulletType extends BulletType {
public Color backColor = Palette.bulletYellowBack, frontColor = Palette.bulletYellow;
public String bulletSprite = "bullet";
public float bulletWidth = 5f, bulletHeight = 7f;
public float bulletShrink = 0.5f;
public String bulletSprite;
public int fragBullets = 9;
public float fragVelocityMin = 0.2f, fragVelocityMax = 1f;
public BulletType fragBullet = null;
public BasicBulletType(float speed, float damage) {
public TextureRegion backRegion;
public TextureRegion frontRegion;
public BasicBulletType(float speed, float damage, String bulletSprite) {
super(speed, damage);
this.bulletSprite = bulletSprite;
}
@Override
public void load() {
backRegion = Draw.region(bulletSprite + "-back");
frontRegion = Draw.region(bulletSprite);
}
@Override
@@ -26,9 +37,9 @@ public class BasicBulletType extends BulletType {
float height = bulletHeight * ((1f - bulletShrink) + bulletShrink * b.fout());
Draw.color(backColor);
Draw.rect(bulletSprite + "-back", b.x, b.y, bulletWidth, height, b.angle() - 90);
Draw.rect(backRegion, b.x, b.y, bulletWidth, height, b.angle() - 90);
Draw.color(frontColor);
Draw.rect(bulletSprite, b.x, b.y, bulletWidth, height, b.angle() - 90);
Draw.rect(frontRegion, b.x, b.y, bulletWidth, height, b.angle() - 90);
Draw.color();
}

View File

@@ -3,11 +3,12 @@ package io.anuke.mindustry.entities.bullet;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.content.StatusEffects;
import io.anuke.mindustry.content.fx.BulletFx;
import io.anuke.mindustry.game.Content;
import io.anuke.mindustry.type.StatusEffect;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.entities.impl.BaseBulletType;
public abstract class BulletType extends BaseBulletType<Bullet>{
public abstract class BulletType extends BaseBulletType<Bullet> implements Content{
private static int lastid = 0;
private static Array<BulletType> types = new Array<>();
@@ -46,6 +47,16 @@ public abstract class BulletType extends BaseBulletType<Bullet>{
Effects.effect(despawneffect, b.x, b.y, b.angle());
}
@Override
public String getContentTypeName() {
return "bullettype";
}
@Override
public Array<? extends Content> getAll() {
return types;
}
public static BulletType getByID(int id){
return types.get(id);
}

View File

@@ -25,7 +25,7 @@ public class Rubble extends TimedEntity implements BelowLiquidTrait, DrawTrait {
@Override
public float lifetime() {
return 7000f;
return 8200f;
}
@Override

View File

@@ -113,7 +113,7 @@ public interface BuilderTrait {
}else if(current.remove){
if(Build.validBreak(unit.getTeam(), current.x, current.y) && current.recipe == Recipe.getByResult(tile.block())){ //if it's valid, break it
float progress = 1f / tile.getBreakTime();
float progress = 1f / tile.getBreakTime() * Timers.delta() * getBuildPower(tile);
TileEntity core = unit.getClosestCore();
//update accumulation of resources to add
@@ -164,7 +164,7 @@ public interface BuilderTrait {
//otherwise, update it.
BuildEntity entity = tile.entity();
entity.addProgress(core.items, 1f / entity.recipe.cost);
entity.addProgress(core.items, 1f / entity.recipe.cost * Timers.delta() * getBuildPower(tile));
unit.rotation = Mathf.slerpDelta(unit.rotation, unit.angleTo(entity), 0.4f);
getCurrentRequest().progress = entity.progress();
}

View File

@@ -76,7 +76,6 @@ public class FlyingUnit extends BaseUnit implements CarryTrait{
}
}
@Override
public UnitState getStartState(){
return attack;

View File

@@ -10,7 +10,6 @@ import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.types.Floor;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.graphics.Hue;
import io.anuke.ucore.util.*;
import static io.anuke.mindustry.Vars.world;
@@ -67,7 +66,7 @@ public abstract class GroundUnit extends BaseUnit {
Floor floor = getFloorOn();
if(floor.liquid){
Draw.tint(Hue.mix(Color.WHITE, floor.liquidColor, 0.5f));
Draw.tint(Color.WHITE, floor.liquidColor, 0.5f);
}
for (int i : Mathf.signs) {

View File

@@ -3,9 +3,9 @@ package io.anuke.mindustry.entities.units.types;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.utils.Queue;
import io.anuke.mindustry.content.Items;
import io.anuke.mindustry.entities.traits.BuilderTrait;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.entities.Units;
import io.anuke.mindustry.entities.traits.BuilderTrait;
import io.anuke.mindustry.entities.units.BaseUnit;
import io.anuke.mindustry.entities.units.FlyingUnit;
import io.anuke.mindustry.entities.units.UnitState;
@@ -25,6 +25,7 @@ import io.anuke.ucore.graphics.Shapes;
import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Geometry;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.ThreadQueue;
import static io.anuke.mindustry.Vars.unitGroups;
import static io.anuke.mindustry.Vars.world;
@@ -35,7 +36,7 @@ public class Drone extends FlyingUnit implements BuilderTrait {
protected static boolean initialized;
protected Tile mineTile;
protected Queue<BuildRequest> placeQueue = new Queue<>();
protected Queue<BuildRequest> placeQueue = new ThreadQueue<>();
/**Initialize placement event notifier system.
* Static initialization is to be avoided, thus, this is done lazily.*/

View File

@@ -1,43 +1,31 @@
package io.anuke.mindustry.entities.units.types;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import io.anuke.mindustry.entities.units.FlyingUnit;
import io.anuke.mindustry.entities.units.UnitType;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Mathf;
public class Vtol extends FlyingUnit {
static TextureRegion
booster1 = Draw.region("vtol-booster-1"),
booster2 = Draw.region("vtol-booster-2"),
region = Draw.region("vtol");
public Vtol(UnitType type, Team team) {
super(type, team);
}
@Override
public void drawUnder() {
float rotation = this.rotation - 90;
float scl = 0.6f + Mathf.absin(Timers.time(), 1f, 0.3f);
float dy = -6f*scl;
Draw.color(Palette.lighterOrange, Palette.lightFlame, Mathf.absin(Timers.time(), 3f, 0.7f));
Draw.rect("vtol-flame",
x + Angles.trnsx(rotation, 0, dy),
y + Angles.trnsy(rotation, 0, dy), Mathf.atan2(0, dy) + rotation);
Draw.color();
}
@Override
public void draw() {
Draw.alpha(hitTime / hitDuration);
Draw.rect(type.name, x, y, rotation - 90);
Draw.rect(region, x, y, rotation - 90);
for(int i : Mathf.signs){
Draw.rect(type.name + "-booster-1", x, y, 12*i, 12, rotation - 90);
Draw.rect(type.name + "-booster-2", x, y, 12*i, 12, rotation - 90);
Draw.rect(booster1, x, y, 12*i, 12, rotation - 90);
Draw.rect(booster2, x, y, 12*i, 12, rotation - 90);
}
Draw.alpha(1f);