Fixed some hitbox issues, preparing to remake floor rendering
This commit is contained in:
@@ -4,7 +4,7 @@ import com.badlogic.gdx.math.GridPoint2;
|
|||||||
import com.badlogic.gdx.utils.IntArray;
|
import com.badlogic.gdx.utils.IntArray;
|
||||||
import com.badlogic.gdx.utils.Queue;
|
import com.badlogic.gdx.utils.Queue;
|
||||||
import com.badlogic.gdx.utils.async.AsyncExecutor;
|
import com.badlogic.gdx.utils.async.AsyncExecutor;
|
||||||
import io.anuke.mindustry.entities.Units;
|
import io.anuke.mindustry.game.EventType.TileChangeEvent;
|
||||||
import io.anuke.mindustry.game.EventType.WorldLoadEvent;
|
import io.anuke.mindustry.game.EventType.WorldLoadEvent;
|
||||||
import io.anuke.mindustry.game.Team;
|
import io.anuke.mindustry.game.Team;
|
||||||
import io.anuke.mindustry.game.TeamInfo.TeamData;
|
import io.anuke.mindustry.game.TeamInfo.TeamData;
|
||||||
@@ -14,15 +14,12 @@ import io.anuke.ucore.core.Events;
|
|||||||
import io.anuke.ucore.core.Timers;
|
import io.anuke.ucore.core.Timers;
|
||||||
import io.anuke.ucore.util.Geometry;
|
import io.anuke.ucore.util.Geometry;
|
||||||
import io.anuke.ucore.util.Log;
|
import io.anuke.ucore.util.Log;
|
||||||
import io.anuke.ucore.util.Mathf;
|
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.state;
|
import static io.anuke.mindustry.Vars.state;
|
||||||
import static io.anuke.mindustry.Vars.world;
|
import static io.anuke.mindustry.Vars.world;
|
||||||
|
|
||||||
public class Pathfinder {
|
public class Pathfinder {
|
||||||
private static final float SQRT2 = Mathf.sqrt(2f);
|
|
||||||
private static final float unitBlockCost = 4f;
|
private static final float unitBlockCost = 4f;
|
||||||
private static boolean avoid = false;
|
|
||||||
|
|
||||||
private AsyncExecutor executor = new AsyncExecutor(8);
|
private AsyncExecutor executor = new AsyncExecutor(8);
|
||||||
private float[][][] weights;
|
private float[][][] weights;
|
||||||
@@ -30,30 +27,10 @@ public class Pathfinder {
|
|||||||
|
|
||||||
public Pathfinder(){
|
public Pathfinder(){
|
||||||
Events.on(WorldLoadEvent.class, this::clear);
|
Events.on(WorldLoadEvent.class, this::clear);
|
||||||
}
|
|
||||||
|
|
||||||
public void update(){
|
Events.on(TileChangeEvent.class, tile -> {
|
||||||
if(avoid) {
|
|
||||||
|
|
||||||
for (TeamData data : state.teams.getTeams()) {
|
});
|
||||||
for (int i = 0; i < blocked.size; i++) {
|
|
||||||
int c = blocked.get(i);
|
|
||||||
weights[data.team.ordinal()][c % world.width()][c / world.width()] -= unitBlockCost;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
blocked.clear();
|
|
||||||
|
|
||||||
Units.getAllUnits(unit -> {
|
|
||||||
if (unit.isFlying()) return;
|
|
||||||
int cx = world.toTile(unit.x), cy = world.toTile(unit.y);
|
|
||||||
for (TeamData data : state.teams.getTeams()) {
|
|
||||||
if (weights[data.team.ordinal()][cx][cy] < Float.MAX_VALUE)
|
|
||||||
weights[data.team.ordinal()][cx][cy] += unitBlockCost;
|
|
||||||
}
|
|
||||||
blocked.add(cx + cy * world.width());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tile getTargetTile(Team team, Tile tile){
|
public Tile getTargetTile(Team team, Tile tile){
|
||||||
@@ -68,10 +45,12 @@ public class Pathfinder {
|
|||||||
for(GridPoint2 point : Geometry.d8) {
|
for(GridPoint2 point : Geometry.d8) {
|
||||||
int dx = tile.x + point.x, dy = tile.y + point.y;
|
int dx = tile.x + point.x, dy = tile.y + point.y;
|
||||||
|
|
||||||
if(!Mathf.inBounds(dx, dy, world.width(), world.height())) continue;
|
Tile other = world.tile(dx, dy);
|
||||||
|
if(other == null) continue;
|
||||||
|
|
||||||
if(values[dx][dy] < value && (target == null || values[dx][dy] < tl)){
|
if(values[dx][dy] < value && (target == null || values[dx][dy] < tl) &&
|
||||||
target = world.tile(dx, dy);
|
(other.getWallID() == 0 || state.teams.areEnemies(team, other.getTeam()))){
|
||||||
|
target = other;
|
||||||
tl = values[dx][dy];
|
tl = values[dx][dy];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -83,7 +62,7 @@ public class Pathfinder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public float getDebugValue(int x, int y){
|
public float getDebugValue(int x, int y){
|
||||||
return weights[Team.blue.ordinal()][x][y];
|
return weights[Team.red.ordinal()][x][y];
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean passable(Tile tile){
|
private boolean passable(Tile tile){
|
||||||
@@ -138,7 +117,6 @@ public class Pathfinder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.info("Elapsed calculation time: {0}", Timers.elapsedNs());
|
Log.info("Elapsed calculation time: {0}", Timers.elapsedNs());
|
||||||
|
|||||||
@@ -117,8 +117,6 @@ public class Logic extends Module {
|
|||||||
runWave();
|
runWave();
|
||||||
}
|
}
|
||||||
|
|
||||||
world.pathfinder().update();
|
|
||||||
|
|
||||||
if(!Entities.defaultGroup().isEmpty()) throw new RuntimeException("Do not add anything to the default group!");
|
if(!Entities.defaultGroup().isEmpty()) throw new RuntimeException("Do not add anything to the default group!");
|
||||||
|
|
||||||
Entities.update(bulletGroup);
|
Entities.update(bulletGroup);
|
||||||
|
|||||||
@@ -319,15 +319,13 @@ public class Renderer extends RendererModule{
|
|||||||
if(world.tile(worldx, worldy) == null) continue;
|
if(world.tile(worldx, worldy) == null) continue;
|
||||||
|
|
||||||
float value = world.pathfinder().getDebugValue(worldx, worldy);
|
float value = world.pathfinder().getDebugValue(worldx, worldy);
|
||||||
if(value == Float.MAX_VALUE){
|
Draw.color(Color.PURPLE);
|
||||||
Draw.text("R", worldx*tilesize, worldy*tilesize);
|
Draw.alpha((value % 10f) / 10f);
|
||||||
}else{
|
Lines.square(worldx * tilesize, worldy*tilesize, 4f);
|
||||||
Draw.text(value + "", worldx*tilesize, worldy*tilesize);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Draw.tscl(0.5f);
|
Draw.color();
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawPlayerNames(){
|
void drawPlayerNames(){
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ public class BaseUnit extends Unit{
|
|||||||
public void added(){
|
public void added(){
|
||||||
maxhealth = type.health;
|
maxhealth = type.health;
|
||||||
|
|
||||||
hitbox.solid = true;
|
hitbox.solid = !isFlying();
|
||||||
hitbox.setSize(type.hitsize);
|
hitbox.setSize(type.hitsize);
|
||||||
hitboxTile.setSize(type.hitsizeTile);
|
hitboxTile.setSize(type.hitsizeTile);
|
||||||
state.set(this, type.getStartState());
|
state.set(this, type.getStartState());
|
||||||
|
|||||||
@@ -177,10 +177,6 @@ public class BlockRenderer{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearTiles(){
|
|
||||||
floorRenderer.clearTiles();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void beginFloor(){
|
public void beginFloor(){
|
||||||
floorRenderer.beginDraw();
|
floorRenderer.beginDraw();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package io.anuke.mindustry.world.blocks.types.units;
|
||||||
|
|
||||||
|
import io.anuke.mindustry.world.Block;
|
||||||
|
|
||||||
|
public class CommandCenter extends Block {
|
||||||
|
public CommandCenter(String name) {
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user