Cleanup
This commit is contained in:
@@ -10,10 +10,16 @@ import mindustry.async.PhysicsProcess.PhysicsWorld.*;
|
||||
import mindustry.gen.*;
|
||||
|
||||
public class PhysicsProcess implements AsyncProcess{
|
||||
private static final int
|
||||
layers = 3,
|
||||
layerGround = 0,
|
||||
layerLegs = 1,
|
||||
layerFlying = 2;
|
||||
|
||||
private PhysicsWorld physics;
|
||||
private Seq<PhysicRef> refs = new Seq<>(false);
|
||||
//currently only enabled for units
|
||||
private EntityGroup<? extends Physicsc> group = Groups.unit;
|
||||
private EntityGroup<Unit> group = Groups.unit;
|
||||
|
||||
@Override
|
||||
public void begin(){
|
||||
@@ -29,9 +35,8 @@ public class PhysicsProcess implements AsyncProcess{
|
||||
return false;
|
||||
});
|
||||
|
||||
//find entities without bodies and assign them
|
||||
for(Physicsc entity : group){
|
||||
boolean grounded = entity.isGrounded();
|
||||
//find Unit without bodies and assign them
|
||||
for(Unit entity : group){
|
||||
|
||||
if(entity.physref() == null){
|
||||
PhysicsBody body = new PhysicsBody();
|
||||
@@ -39,7 +44,6 @@ public class PhysicsProcess implements AsyncProcess{
|
||||
body.y = entity.y();
|
||||
body.mass = entity.mass();
|
||||
body.radius = entity.hitSize() / 2f;
|
||||
body.flag = grounded ? 1 : 0;
|
||||
|
||||
PhysicRef ref = new PhysicRef(entity, body);
|
||||
refs.add(ref);
|
||||
@@ -52,7 +56,9 @@ public class PhysicsProcess implements AsyncProcess{
|
||||
//save last position
|
||||
PhysicRef ref = entity.physref();
|
||||
|
||||
ref.body.flag = grounded ? 1 : 0;
|
||||
ref.body.layer =
|
||||
entity.type().allowLegStep ? layerLegs :
|
||||
entity.isGrounded() ? layerGround : layerFlying;
|
||||
ref.x = entity.x();
|
||||
ref.y = entity.y();
|
||||
}
|
||||
@@ -116,13 +122,16 @@ public class PhysicsProcess implements AsyncProcess{
|
||||
//how much to soften movement by
|
||||
private static final float scl = 1.25f;
|
||||
|
||||
private final QuadTree<PhysicsBody> tree;
|
||||
private final QuadTree<PhysicsBody>[] trees = new QuadTree[layers];
|
||||
private final Seq<PhysicsBody> bodies = new Seq<>(false, 16, PhysicsBody.class);
|
||||
private final Seq<PhysicsBody> seq = new Seq<>(PhysicsBody.class);
|
||||
private final Rect rect = new Rect();
|
||||
private final Vec2 vec = new Vec2();
|
||||
|
||||
public PhysicsWorld(Rect bounds){
|
||||
tree = new QuadTree<>(new Rect(bounds));
|
||||
for(int i = 0; i < layers; i++){
|
||||
trees[i] = new QuadTree<>(new Rect(bounds));
|
||||
}
|
||||
}
|
||||
|
||||
public void add(PhysicsBody body){
|
||||
@@ -134,18 +143,27 @@ public class PhysicsProcess implements AsyncProcess{
|
||||
}
|
||||
|
||||
public void update(){
|
||||
tree.clear();
|
||||
for(int i = 0; i < layers; i++){
|
||||
trees[i].clear();
|
||||
}
|
||||
|
||||
for(int i = 0; i < bodies.size; i++){
|
||||
PhysicsBody body = bodies.items[i];
|
||||
body.collided = false;
|
||||
tree.insert(body);
|
||||
trees[body.layer].insert(body);
|
||||
}
|
||||
|
||||
for(int i = 0; i < bodies.size; i++){
|
||||
PhysicsBody body = bodies.items[i];
|
||||
body.hitbox(rect);
|
||||
tree.intersect(rect, other -> {
|
||||
if(other.flag != body.flag || other == body || other.collided) return;
|
||||
|
||||
seq.size = 0;
|
||||
trees[body.layer].intersect(rect, seq);
|
||||
|
||||
for(int j = 0; j < seq.size; j++){
|
||||
PhysicsBody other = seq.items[j];
|
||||
|
||||
if(other == body || other.collided) continue;
|
||||
|
||||
float rs = body.radius + other.radius;
|
||||
float dst = Mathf.dst(body.x, body.y, other.x, other.y);
|
||||
@@ -160,14 +178,14 @@ public class PhysicsProcess implements AsyncProcess{
|
||||
other.x -= vec.x * m2 / scl;
|
||||
other.y -= vec.y * m2 / scl;
|
||||
}
|
||||
});
|
||||
}
|
||||
body.collided = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static class PhysicsBody implements QuadTreeObject{
|
||||
public float x, y, radius, mass;
|
||||
public int flag = 0;
|
||||
public int layer = 0;
|
||||
public boolean collided = false;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -463,6 +463,7 @@ public class UnitTypes implements ContentList{
|
||||
visualElevation = 0.2f;
|
||||
allowLegStep = true;
|
||||
ammoType = AmmoTypes.powerHigh;
|
||||
groundLayer = Layer.legUnit;
|
||||
|
||||
speed = 0.3f;
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ public class GameState{
|
||||
/** Wave countdown in ticks. */
|
||||
public float wavetime;
|
||||
/** Whether the game is in game over state. */
|
||||
public boolean gameOver = false, launched = false, serverPaused = false, wasTimeout;
|
||||
public boolean gameOver = false, serverPaused = false, wasTimeout;
|
||||
/** Map that is currently being played on. */
|
||||
public @NonNull Map map = emptyMap;
|
||||
/** The current game rules. */
|
||||
|
||||
@@ -24,17 +24,17 @@ public class Lightning{
|
||||
|
||||
/** Create a lighting branch at a location. Use Team.derelict to damage everyone. */
|
||||
public static void create(Team team, Color color, float damage, float x, float y, float targetAngle, int length){
|
||||
createLightingInternal(null, lastSeed++, team, color, damage, x, y, targetAngle, length);
|
||||
createLightningInternal(null, lastSeed++, team, color, damage, x, y, targetAngle, length);
|
||||
}
|
||||
|
||||
/** Create a lighting branch at a location. Uses bullet parameters. */
|
||||
public static void create(Bullet bullet, Color color, float damage, float x, float y, float targetAngle, int length){
|
||||
createLightingInternal(bullet, lastSeed++, bullet.team, color, damage, x, y, targetAngle, length);
|
||||
createLightningInternal(bullet, lastSeed++, bullet.team, color, damage, x, y, targetAngle, length);
|
||||
}
|
||||
|
||||
//TODO remote method
|
||||
//@Remote(called = Loc.server, unreliable = true)
|
||||
private static void createLightingInternal(Bullet hitter, int seed, Team team, Color color, float damage, float x, float y, float rotation, int length){
|
||||
private static void createLightningInternal(Bullet hitter, int seed, Team team, Color color, float damage, float x, float y, float rotation, int length){
|
||||
random.setSeed(seed);
|
||||
hit.clear();
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ public class Stats{
|
||||
/** Friendly buildings destroyed. */
|
||||
public int buildingsDestroyed;
|
||||
|
||||
//TODO fix
|
||||
public RankResult calculateRank(Sector zone, boolean launched){
|
||||
float score = 0;
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ public class Sector{
|
||||
|
||||
public boolean isBeingPlayed(){
|
||||
//after the launch dialog, a sector is no longer considered being played
|
||||
return Vars.state.isGame() && Vars.state.rules.sector == this && !Vars.state.launched && !Vars.state.gameOver;
|
||||
return Vars.state.isGame() && Vars.state.rules.sector == this && !Vars.state.gameOver;
|
||||
}
|
||||
|
||||
public boolean isCaptured(){
|
||||
|
||||
@@ -29,7 +29,7 @@ public class GameOverDialog extends BaseDialog{
|
||||
}
|
||||
|
||||
void rebuild(){
|
||||
title.setText(state.launched ? "@launch.title" : "@gameover");
|
||||
title.setText("@gameover");
|
||||
buttons.clear();
|
||||
cont.clear();
|
||||
|
||||
@@ -79,7 +79,7 @@ public class GameOverDialog extends BaseDialog{
|
||||
}
|
||||
|
||||
if(state.hasSector()){
|
||||
RankResult result = state.stats.calculateRank(state.getSector(), state.launched);
|
||||
RankResult result = state.stats.calculateRank(state.getSector(), true);
|
||||
t.add(Core.bundle.format("stat.rank", result.rank + result.modifier));
|
||||
t.row();
|
||||
}
|
||||
|
||||
@@ -168,6 +168,7 @@ public class ResearchDialog extends BaseDialog{
|
||||
Core.app.post(() -> {
|
||||
if(net.client()){
|
||||
//TODO make this not display every time
|
||||
//TODO rework this in the future
|
||||
ui.showInfo("campaign.multiplayer");
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user