Cleanup, optimization
This commit is contained in:
@@ -114,7 +114,7 @@ public class EntityCollisions{
|
||||
|
||||
group.each(s -> {
|
||||
s.updateLastPosition();
|
||||
//tree.insert(s);
|
||||
tree.insert(s);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ public class EntityCollisions{
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void collideGroups(EntityGroup<? extends Hitboxc> groupa, EntityGroup<? extends Hitboxc> groupb){
|
||||
public <T extends Hitboxc> void collide(EntityGroup<T> groupa){
|
||||
|
||||
groupa.each(solid -> {
|
||||
solid.hitbox(r1);
|
||||
@@ -216,7 +216,9 @@ public class EntityCollisions{
|
||||
r2.merge(r1);
|
||||
|
||||
arrOut.clear();
|
||||
groupb.tree().getIntersect(arrOut, r2);
|
||||
|
||||
//get all targets based on what entity wants to collide with
|
||||
solid.getCollisions(tree -> tree.intersect(r2, arrOut));
|
||||
|
||||
for(Hitboxc sc : arrOut){
|
||||
sc.hitbox(r1);
|
||||
|
||||
@@ -45,8 +45,8 @@ public class EntityGroup<T extends Entityc> implements Iterable<T>{
|
||||
array.sort(comp);
|
||||
}
|
||||
|
||||
public void collide(EntityGroup<? extends Hitboxc> other){
|
||||
collisions.collideGroups((EntityGroup<? extends Hitboxc>)this, other);
|
||||
public void collide(){
|
||||
collisions.collide((EntityGroup<? extends Hitboxc>)this);
|
||||
}
|
||||
|
||||
public void updatePhysics(){
|
||||
@@ -108,14 +108,14 @@ public class EntityGroup<T extends Entityc> implements Iterable<T>{
|
||||
public void intersect(float x, float y, float width, float height, Cons<? super T> out){
|
||||
//don't waste time for empty groups
|
||||
if(isEmpty()) return;
|
||||
tree.getIntersect(out, x, y, width, height);
|
||||
tree.intersect(height, x, y, width, out);
|
||||
}
|
||||
|
||||
public Array<T> intersect(float x, float y, float width, float height){
|
||||
intersectArray.clear();
|
||||
//don't waste time for empty groups
|
||||
if(isEmpty()) return intersectArray;
|
||||
tree.getIntersect(intersectArray, intersectRect.set(x, y, width, height));
|
||||
tree.intersect(intersectRect.set(x, y, width, height), intersectArray);
|
||||
return intersectArray;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package mindustry.entities;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.gen.*;
|
||||
|
||||
class AllDefs{
|
||||
class GroupDefs{
|
||||
|
||||
@GroupDef(value = Entityc.class, mapping = true)
|
||||
class gall{
|
||||
@@ -15,7 +15,7 @@ class AllDefs{
|
||||
|
||||
}
|
||||
|
||||
@GroupDef(value = Bulletc.class, spatial = true)
|
||||
@GroupDef(value = Bulletc.class, spatial = true, collide = true)
|
||||
class gbullet{
|
||||
|
||||
}
|
||||
@@ -30,7 +30,7 @@ public class Units{
|
||||
* @return whether the target is invalid
|
||||
*/
|
||||
public static boolean invalidateTarget(Posc target, Team team, float x, float y, float range){
|
||||
return target == null || !target.isAdded() || (range != Float.MAX_VALUE && !target.withinDst(x, y, range)) || (target instanceof Teamc && ((Teamc)target).team() == team) || (target instanceof Healthc && !((Healthc)target).isValid());
|
||||
return target == null || !target.isAdded() || (range != Float.MAX_VALUE && !target.within(x, y, range)) || (target instanceof Teamc && ((Teamc)target).team() == team) || (target instanceof Healthc && !((Healthc)target).isValid());
|
||||
}
|
||||
|
||||
/** See {@link #invalidateTarget(Posc, Team, float, float, float)} */
|
||||
@@ -131,6 +131,7 @@ public class Units{
|
||||
result = null;
|
||||
cdist = 0f;
|
||||
|
||||
//TODO optimize
|
||||
for(Unitc e : Groups.unit){
|
||||
if(!predicate.get(e) || e.team() != team) continue;
|
||||
|
||||
@@ -164,17 +165,13 @@ public class Units{
|
||||
|
||||
/** Iterates over all units in a rectangle. */
|
||||
public static void nearby(Team team, float x, float y, float width, float height, Cons<Unitc> cons){
|
||||
Groups.unit.intersect(x, y, width, height, u -> {
|
||||
if(u.team() == team){
|
||||
cons.get(u);
|
||||
}
|
||||
});
|
||||
teamIndex.tree(team).intersect(height, x, y, width, cons);
|
||||
}
|
||||
|
||||
/** Iterates over all units in a circle around this position. */
|
||||
public static void nearby(Team team, float x, float y, float radius, Cons<Unitc> cons){
|
||||
Groups.unit.intersect(x - radius, y - radius, radius*2f, radius*2f, unit -> {
|
||||
if(unit.team() == team && unit.withinDst(x, y, radius)){
|
||||
nearby(team, x - radius, y - radius, radius*2f, radius*2f, unit -> {
|
||||
if(unit.within(x, y, radius)){
|
||||
cons.get(unit);
|
||||
}
|
||||
});
|
||||
@@ -192,11 +189,9 @@ public class Units{
|
||||
|
||||
/** Iterates over all units that are enemies of this team. */
|
||||
public static void nearbyEnemies(Team team, float x, float y, float width, float height, Cons<Unitc> cons){
|
||||
Groups.unit.intersect(x, y, width, height, u -> {
|
||||
if(team.isEnemy(u.team())){
|
||||
cons.get(u);
|
||||
}
|
||||
});
|
||||
for(Team enemy : state.teams.enemiesOf(team)){
|
||||
nearby(enemy, x, y, width, height, cons);
|
||||
}
|
||||
}
|
||||
|
||||
/** Iterates over all units that are enemies of this team. */
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package mindustry.entities.def;
|
||||
|
||||
import arc.func.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.util.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.entities.bullet.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
|
||||
@@ -12,11 +15,20 @@ import static mindustry.Vars.*;
|
||||
|
||||
@EntityDef(value = {Bulletc.class}, pooled = true)
|
||||
@Component
|
||||
abstract class BulletComp implements Timedc, Damagec, Collisionc, Teamc, Posc, Drawc, Shielderc, Ownerc, Velc, Bulletc, Timerc{
|
||||
abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Drawc, Shielderc, Ownerc, Velc, Bulletc, Timerc{
|
||||
@Import Team team;
|
||||
|
||||
Object data;
|
||||
BulletType type;
|
||||
float damage;
|
||||
|
||||
@Override
|
||||
public void getCollisions(Cons<QuadTree> consumer){
|
||||
for(Team team : state.teams.enemiesOf(team)){
|
||||
consumer.get(teamIndex.tree(team));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBullets(){
|
||||
type.draw(this);
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
package mindustry.entities.def;
|
||||
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.async.CollisionProcess.*;
|
||||
import mindustry.gen.*;
|
||||
|
||||
/** Can be collided with. Collision elibility depends on team.
|
||||
* TODO merge with hitboxcomp?*/
|
||||
@Component
|
||||
abstract class CollisionComp implements Hitboxc{
|
||||
transient CollisionRef colref;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package mindustry.entities.def;
|
||||
|
||||
import arc.func.*;
|
||||
import arc.math.geom.QuadTree.*;
|
||||
import arc.math.geom.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
@@ -26,6 +27,10 @@ abstract class HitboxComp implements Posc, QuadTreeObject{
|
||||
updateLastPosition();
|
||||
}
|
||||
|
||||
void getCollisions(Cons<QuadTree> consumer){
|
||||
|
||||
}
|
||||
|
||||
void updateLastPosition(){
|
||||
lastX = x;
|
||||
lastY = y;
|
||||
|
||||
@@ -18,7 +18,7 @@ import mindustry.world.blocks.environment.*;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
@Component
|
||||
abstract class UnitComp implements Healthc, Physicsc, Collisionc, Statusc, Teamc, Itemsc, Rotc, Unitc, Weaponsc, Drawc, Boundedc, Syncc, Shieldc{
|
||||
abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, Itemsc, Rotc, Unitc, Weaponsc, Drawc, Boundedc, Syncc, Shieldc{
|
||||
@Import float x, y, rotation, elevation, maxHealth;
|
||||
|
||||
private UnitController controller;
|
||||
@@ -122,7 +122,7 @@ abstract class UnitComp implements Healthc, Physicsc, Collisionc, Statusc, Teamc
|
||||
if(team() != state.rules.waveTeam){
|
||||
float relativeSize = state.rules.dropZoneRadius + bounds()/2f + 1f;
|
||||
for(Tile spawn : spawner.getSpawns()){
|
||||
if(withinDst(spawn.worldx(), spawn.worldy(), relativeSize)){
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user