Fixed some hitbox issues, preparing to remake floor rendering

This commit is contained in:
Anuken 2018-05-01 23:45:32 -04:00
parent 3dd07d2f4a
commit c3967c79c9
6 changed files with 23 additions and 44 deletions

View File

@ -4,7 +4,7 @@ import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.utils.IntArray;
import com.badlogic.gdx.utils.Queue;
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.Team;
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.util.Geometry;
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.world;
public class Pathfinder {
private static final float SQRT2 = Mathf.sqrt(2f);
private static final float unitBlockCost = 4f;
private static boolean avoid = false;
private AsyncExecutor executor = new AsyncExecutor(8);
private float[][][] weights;
@ -30,30 +27,10 @@ public class Pathfinder {
public Pathfinder(){
Events.on(WorldLoadEvent.class, this::clear);
}
public void update(){
if(avoid) {
Events.on(TileChangeEvent.class, tile -> {
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){
@ -68,10 +45,12 @@ public class Pathfinder {
for(GridPoint2 point : Geometry.d8) {
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)){
target = world.tile(dx, dy);
if(values[dx][dy] < value && (target == null || values[dx][dy] < tl) &&
(other.getWallID() == 0 || state.teams.areEnemies(team, other.getTeam()))){
target = other;
tl = values[dx][dy];
}
}
@ -83,7 +62,7 @@ public class Pathfinder {
}
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){
@ -138,7 +117,6 @@ public class Pathfinder {
}
}
}
}
Log.info("Elapsed calculation time: {0}", Timers.elapsedNs());

View File

@ -117,8 +117,6 @@ public class Logic extends Module {
runWave();
}
world.pathfinder().update();
if(!Entities.defaultGroup().isEmpty()) throw new RuntimeException("Do not add anything to the default group!");
Entities.update(bulletGroup);

View File

@ -319,15 +319,13 @@ public class Renderer extends RendererModule{
if(world.tile(worldx, worldy) == null) continue;
float value = world.pathfinder().getDebugValue(worldx, worldy);
if(value == Float.MAX_VALUE){
Draw.text("R", worldx*tilesize, worldy*tilesize);
}else{
Draw.text(value + "", worldx*tilesize, worldy*tilesize);
}
Draw.color(Color.PURPLE);
Draw.alpha((value % 10f) / 10f);
Lines.square(worldx * tilesize, worldy*tilesize, 4f);
}
}
Draw.tscl(0.5f);
Draw.color();
}
void drawPlayerNames(){

View File

@ -132,7 +132,7 @@ public class BaseUnit extends Unit{
public void added(){
maxhealth = type.health;
hitbox.solid = true;
hitbox.solid = !isFlying();
hitbox.setSize(type.hitsize);
hitboxTile.setSize(type.hitsizeTile);
state.set(this, type.getStartState());

View File

@ -177,10 +177,6 @@ public class BlockRenderer{
}
}
public void clearTiles(){
floorRenderer.clearTiles();
}
public void beginFloor(){
floorRenderer.beginDraw();
}

View File

@ -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);
}
}