From 40008f44ac52f010770e14985ecb2a7befaae1a1 Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 1 Oct 2018 13:28:35 -0400 Subject: [PATCH] Circle collision initial commit --- core/src/io/anuke/mindustry/core/Control.java | 4 ++-- core/src/io/anuke/mindustry/core/Logic.java | 10 +++++----- .../src/io/anuke/mindustry/core/NetServer.java | 4 ++-- core/src/io/anuke/mindustry/core/World.java | 8 ++++---- .../io/anuke/mindustry/entities/Player.java | 4 ---- core/src/io/anuke/mindustry/entities/Unit.java | 12 ------------ .../src/io/anuke/mindustry/entities/Units.java | 18 +++++++++--------- .../mindustry/entities/units/BaseUnit.java | 1 - .../world/blocks/defense/ForceProjector.java | 4 ++-- 9 files changed, 24 insertions(+), 41 deletions(-) diff --git a/core/src/io/anuke/mindustry/core/Control.java b/core/src/io/anuke/mindustry/core/Control.java index 4b913632a0..801f9f73b9 100644 --- a/core/src/io/anuke/mindustry/core/Control.java +++ b/core/src/io/anuke/mindustry/core/Control.java @@ -24,7 +24,7 @@ import io.anuke.mindustry.type.Recipe; import io.anuke.mindustry.ui.dialogs.FloatingDialog; import io.anuke.ucore.core.*; import io.anuke.ucore.entities.Entities; -import io.anuke.ucore.entities.EntityPhysics; +import io.anuke.ucore.entities.EntityQuery; import io.anuke.ucore.modules.Module; import io.anuke.ucore.util.Atlas; @@ -302,7 +302,7 @@ public class Control extends Module{ @Override public void init(){ - EntityPhysics.initPhysics(); + EntityQuery.init(); Platform.instance.updateRPC(); diff --git a/core/src/io/anuke/mindustry/core/Logic.java b/core/src/io/anuke/mindustry/core/Logic.java index 63bcb58e51..018f46a698 100644 --- a/core/src/io/anuke/mindustry/core/Logic.java +++ b/core/src/io/anuke/mindustry/core/Logic.java @@ -17,7 +17,7 @@ import io.anuke.ucore.core.Events; import io.anuke.ucore.core.Timers; import io.anuke.ucore.entities.Entities; import io.anuke.ucore.entities.EntityGroup; -import io.anuke.ucore.entities.EntityPhysics; +import io.anuke.ucore.entities.EntityQuery; import io.anuke.ucore.modules.Module; import static io.anuke.mindustry.Vars.*; @@ -39,8 +39,8 @@ public class Logic extends Module{ @Override public void init(){ - EntityPhysics.initPhysics(); - EntityPhysics.collisions().setCollider(tilesize, world::solid); + EntityQuery.init(); + EntityQuery.collisions().setCollider(tilesize, world::solid); } public void play(){ @@ -167,11 +167,11 @@ public class Logic extends Module{ for(EntityGroup group : unitGroups){ if(!group.isEmpty()){ - EntityPhysics.collideGroups(bulletGroup, group); + EntityQuery.collideGroups(bulletGroup, group); } } - EntityPhysics.collideGroups(bulletGroup, playerGroup); + EntityQuery.collideGroups(bulletGroup, playerGroup); world.pathfinder().update(); } diff --git a/core/src/io/anuke/mindustry/core/NetServer.java b/core/src/io/anuke/mindustry/core/NetServer.java index 25fd2511d5..b4264fd8f2 100644 --- a/core/src/io/anuke/mindustry/core/NetServer.java +++ b/core/src/io/anuke/mindustry/core/NetServer.java @@ -27,7 +27,7 @@ import io.anuke.mindustry.world.Tile; import io.anuke.ucore.core.Timers; import io.anuke.ucore.entities.Entities; import io.anuke.ucore.entities.EntityGroup; -import io.anuke.ucore.entities.EntityPhysics; +import io.anuke.ucore.entities.EntityQuery; import io.anuke.ucore.entities.trait.Entity; import io.anuke.ucore.io.ByteBufferOutput; import io.anuke.ucore.io.CountableByteArrayOutputStream; @@ -508,7 +508,7 @@ public class NetServer extends Module{ returnArray.clear(); if(represent.isClipped()){ - EntityPhysics.getNearby(group, viewport, entity -> { + EntityQuery.getNearby(group, viewport, entity -> { if(((SyncTrait) entity).isSyncing() && viewport.contains(entity.getX(), entity.getY())){ returnArray.add(entity); } diff --git a/core/src/io/anuke/mindustry/core/World.java b/core/src/io/anuke/mindustry/core/World.java index fe0906b891..c2d09dc1e5 100644 --- a/core/src/io/anuke/mindustry/core/World.java +++ b/core/src/io/anuke/mindustry/core/World.java @@ -18,7 +18,7 @@ import io.anuke.mindustry.maps.generation.WorldGenerator; import io.anuke.mindustry.world.blocks.OreBlock; import io.anuke.ucore.core.Events; import io.anuke.ucore.core.Timers; -import io.anuke.ucore.entities.EntityPhysics; +import io.anuke.ucore.entities.EntityQuery; import io.anuke.ucore.modules.Module; import io.anuke.ucore.util.Log; import io.anuke.ucore.util.Mathf; @@ -222,7 +222,7 @@ public class World extends Module{ } } - EntityPhysics.resizeTree(0, 0, tiles.length * tilesize, tiles[0].length * tilesize); + EntityQuery.resizeTree(0, 0, tiles.length * tilesize, tiles[0].length * tilesize); generating = false; Events.fire(new WorldLoadEvent()); @@ -251,7 +251,7 @@ public class World extends Module{ Map map = new Map("Sector " + sector.x + ", " + sector.y, new MapMeta(0, new ObjectMap<>(), width, height, null), true, () -> null); setMap(map); - EntityPhysics.resizeTree(0, 0, width * tilesize, height * tilesize); + EntityQuery.resizeTree(0, 0, width * tilesize, height * tilesize); generator.generateMap(tiles, sector); @@ -267,7 +267,7 @@ public class World extends Module{ createTiles(width, height); - EntityPhysics.resizeTree(0, 0, width * tilesize, height * tilesize); + EntityQuery.resizeTree(0, 0, width * tilesize, height * tilesize); try{ generator.loadTileData(tiles, MapIO.readTileData(map, true), map.meta.hasOreGen(), 0); diff --git a/core/src/io/anuke/mindustry/entities/Player.java b/core/src/io/anuke/mindustry/entities/Player.java index d7eb92ae78..2ae4e48ac8 100644 --- a/core/src/io/anuke/mindustry/entities/Player.java +++ b/core/src/io/anuke/mindustry/entities/Player.java @@ -487,10 +487,6 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra updateMech(); } - if(isLocal){ - avoidOthers(8f); - } - updateBuilding(this); x = Mathf.clamp(x, 0, world.width() * tilesize); diff --git a/core/src/io/anuke/mindustry/entities/Unit.java b/core/src/io/anuke/mindustry/entities/Unit.java index 3120fdfda6..4ae18c14ae 100644 --- a/core/src/io/anuke/mindustry/entities/Unit.java +++ b/core/src/io/anuke/mindustry/entities/Unit.java @@ -15,7 +15,6 @@ import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.blocks.Floor; import io.anuke.ucore.core.Effects; import io.anuke.ucore.core.Timers; -import io.anuke.ucore.entities.EntityPhysics; import io.anuke.ucore.entities.impl.DestructibleEntity; import io.anuke.ucore.entities.trait.DamageTrait; import io.anuke.ucore.entities.trait.DrawTrait; @@ -193,17 +192,6 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ return tile == null ? (Floor) Blocks.air : tile.floor(); } - public void avoidOthers(float avoidRange){ - - EntityPhysics.getNearby(getGroup(), x, y, avoidRange * 2f, t -> { - if(t == this || (t instanceof Unit && (((Unit) t).isDead() || (((Unit) t).isFlying() != isFlying()) || ((Unit) t).getCarrier() == this) || getCarrier() == t)) - return; - float dst = distanceTo(t); - if(dst > avoidRange) return; - velocity.add(moveVector.set(x, y).sub(t.getX(), t.getY()).setLength(1f * (1f - (dst / avoidRange)) / getMass())); - }); - } - /**Updates velocity and status effects.*/ public void updateVelocityStatus(float drag, float maxVelocity){ Floor floor = getFloorOn(); diff --git a/core/src/io/anuke/mindustry/entities/Units.java b/core/src/io/anuke/mindustry/entities/Units.java index 5bcb881a14..a777ddee76 100644 --- a/core/src/io/anuke/mindustry/entities/Units.java +++ b/core/src/io/anuke/mindustry/entities/Units.java @@ -8,7 +8,7 @@ import io.anuke.mindustry.game.Team; import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Tile; import io.anuke.ucore.entities.EntityGroup; -import io.anuke.ucore.entities.EntityPhysics; +import io.anuke.ucore.entities.EntityQuery; import io.anuke.ucore.function.Consumer; import io.anuke.ucore.function.Predicate; import io.anuke.ucore.util.EnumSet; @@ -213,11 +213,11 @@ public class Units{ EntityGroup group = unitGroups[team.ordinal()]; if(!group.isEmpty()){ - EntityPhysics.getNearby(group, rect, entity -> cons.accept((Unit) entity)); + EntityQuery.getNearby(group, rect, entity -> cons.accept((Unit) entity)); } //now check all players - EntityPhysics.getNearby(playerGroup, rect, player -> { + EntityQuery.getNearby(playerGroup, rect, player -> { if(((Unit) player).team == team) cons.accept((Unit) player); }); } @@ -230,7 +230,7 @@ public class Units{ EntityGroup group = unitGroups[team.ordinal()]; if(!group.isEmpty()){ - EntityPhysics.getNearby(group, rect, entity -> { + EntityQuery.getNearby(group, rect, entity -> { if(entity.distanceTo(x, y) <= radius){ cons.accept((Unit) entity); } @@ -238,7 +238,7 @@ public class Units{ } //now check all players - EntityPhysics.getNearby(playerGroup, rect, player -> { + EntityQuery.getNearby(playerGroup, rect, player -> { if(((Unit) player).team == team && player.distanceTo(x, y) <= radius){ cons.accept((Unit) player); } @@ -253,12 +253,12 @@ public class Units{ for(Team team : Team.all){ EntityGroup group = unitGroups[team.ordinal()]; if(!group.isEmpty()){ - EntityPhysics.getNearby(group, rect, entity -> cons.accept((Unit) entity)); + EntityQuery.getNearby(group, rect, entity -> cons.accept((Unit) entity)); } } //now check all enemy players - EntityPhysics.getNearby(playerGroup, rect, player -> cons.accept((Unit) player)); + EntityQuery.getNearby(playerGroup, rect, player -> cons.accept((Unit) player)); } /** @@ -270,12 +270,12 @@ public class Units{ for(Team other : targets){ EntityGroup group = unitGroups[other.ordinal()]; if(!group.isEmpty()){ - EntityPhysics.getNearby(group, rect, entity -> cons.accept((Unit) entity)); + EntityQuery.getNearby(group, rect, entity -> cons.accept((Unit) entity)); } } //now check all enemy players - EntityPhysics.getNearby(playerGroup, rect, player -> { + EntityQuery.getNearby(playerGroup, rect, player -> { if(targets.contains(((Player) player).team)){ cons.accept((Unit) player); } diff --git a/core/src/io/anuke/mindustry/entities/units/BaseUnit.java b/core/src/io/anuke/mindustry/entities/units/BaseUnit.java index 78035af666..15b111772b 100644 --- a/core/src/io/anuke/mindustry/entities/units/BaseUnit.java +++ b/core/src/io/anuke/mindustry/entities/units/BaseUnit.java @@ -306,7 +306,6 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{ } if(!Net.client()){ - avoidOthers(4f + type.hitsize); if(spawner != -1 && (world.tile(spawner) == null || world.tile(spawner).entity == null)){ damage(health); diff --git a/core/src/io/anuke/mindustry/world/blocks/defense/ForceProjector.java b/core/src/io/anuke/mindustry/world/blocks/defense/ForceProjector.java index 420ba46a93..aaf4acee17 100644 --- a/core/src/io/anuke/mindustry/world/blocks/defense/ForceProjector.java +++ b/core/src/io/anuke/mindustry/world/blocks/defense/ForceProjector.java @@ -16,7 +16,7 @@ import io.anuke.ucore.core.Effects; import io.anuke.ucore.core.Graphics; import io.anuke.ucore.core.Timers; import io.anuke.ucore.entities.EntityGroup; -import io.anuke.ucore.entities.EntityPhysics; +import io.anuke.ucore.entities.EntityQuery; import io.anuke.ucore.entities.impl.BaseEntity; import io.anuke.ucore.entities.trait.DrawTrait; import io.anuke.ucore.graphics.Draw; @@ -127,7 +127,7 @@ public class ForceProjector extends Block { float realRadius = realRadius(entity); if(!entity.broken){ - EntityPhysics.getNearby(bulletGroup, tile.drawx(), tile.drawy(), realRadius*2f, bullet -> { + EntityQuery.getNearby(bulletGroup, tile.drawx(), tile.drawy(), realRadius*2f, bullet -> { AbsorbTrait trait = (AbsorbTrait)bullet; if(trait.canBeAbsorbed() && trait.getTeam() != tile.getTeam() && isInsideHexagon(trait.getX(), trait.getY(), realRadius * 2f, tile.drawx(), tile.drawy())){ trait.absorb();