Tile code cleanup

This commit is contained in:
Anuken
2020-03-03 19:29:41 -05:00
parent bac1648d4b
commit 087f8129b9
10 changed files with 75 additions and 103 deletions
+5 -16
View File
@@ -78,10 +78,7 @@ public class BlockIndexer{
//create bitset for each team type that contains each quadrant //create bitset for each team type that contains each quadrant
structQuadrants = new GridBits[Team.all().length]; structQuadrants = new GridBits[Team.all().length];
for(int x = 0; x < world.width(); x++){ for(Tile tile : world.tiles){
for(int y = 0; y < world.height(); y++){
Tile tile = world.tile(x, y);
process(tile); process(tile);
if(tile.entity != null && tile.entity.damaged()){ if(tile.entity != null && tile.entity.damaged()){
@@ -90,7 +87,6 @@ public class BlockIndexer{
if(tile.drop() != null) allOres.add(tile.drop()); if(tile.drop() != null) allOres.add(tile.drop());
} }
}
for(int x = 0; x < quadWidth(); x++){ for(int x = 0; x < quadWidth(); x++){
for(int y = 0; y < quadHeight(); y++){ for(int y = 0; y < quadHeight(); y++){
@@ -119,9 +115,7 @@ public class BlockIndexer{
if(structQuadrants == null) return; if(structQuadrants == null) return;
//go through every tile... ouch //go through every tile... ouch
for(int x = 0; x < world.width(); x++){ for(Tile tile : world.tiles){
for(int y = 0; y < world.height(); y++){
Tile tile = world.tile(x, y);
if(tile.team() == team){ if(tile.team() == team){
int quadrantX = tile.x / quadrantSize; int quadrantX = tile.x / quadrantSize;
int quadrantY = tile.y / quadrantSize; int quadrantY = tile.y / quadrantSize;
@@ -129,7 +123,6 @@ public class BlockIndexer{
} }
} }
} }
}
/** @return whether this item is present on this map.*/ /** @return whether this item is present on this map.*/
public boolean hasOre(Item item){ public boolean hasOre(Item item){
@@ -403,12 +396,9 @@ public class BlockIndexer{
ores.put(item, new ObjectSet<>()); ores.put(item, new ObjectSet<>());
} }
for(int x = 0; x < world.width(); x++){ for(Tile tile : world.tiles){
for(int y = 0; y < world.height(); y++){ int qx = (tile.x / quadrantSize);
int qx = (x / quadrantSize); int qy = (tile.y / quadrantSize);
int qy = (y / quadrantSize);
Tile tile = world.tile(x, y);
//add position of quadrant to list when an ore is found //add position of quadrant to list when an ore is found
if(tile.drop() != null && scanOres.contains(tile.drop()) && tile.block() == Blocks.air){ if(tile.drop() != null && scanOres.contains(tile.drop()) && tile.block() == Blocks.air){
@@ -419,7 +409,6 @@ public class BlockIndexer{
} }
} }
} }
}
private class TileIndex{ private class TileIndex{
public final EnumSet<BlockFlag> flags; public final EnumSet<BlockFlag> flags;
+5 -7
View File
@@ -1,13 +1,13 @@
package mindustry.ai; package mindustry.ai;
import arc.*; import arc.*;
import mindustry.annotations.Annotations.*;
import arc.struct.*;
import arc.func.*; import arc.func.*;
import arc.math.geom.*; import arc.math.geom.*;
import arc.util.*; import arc.struct.*;
import arc.util.ArcAnnotate.*; import arc.util.ArcAnnotate.*;
import arc.util.*;
import arc.util.async.*; import arc.util.async.*;
import mindustry.annotations.Annotations.*;
import mindustry.game.EventType.*; import mindustry.game.EventType.*;
import mindustry.game.*; import mindustry.game.*;
import mindustry.gen.*; import mindustry.gen.*;
@@ -45,10 +45,8 @@ public class Pathfinder implements Runnable{
created = new GridBits(Team.all().length, PathTarget.all.length); created = new GridBits(Team.all().length, PathTarget.all.length);
list = new Array<>(); list = new Array<>();
for(int x = 0; x < world.width(); x++){ for(Tile tile : world.tiles){
for(int y = 0; y < world.height(); y++){ tiles[tile.x][tile.y] = packTile(tile);
tiles[x][y] = packTile(world.rawTile(x, y));
}
} }
//special preset which may help speed things up; this is optional //special preset which may help speed things up; this is optional
+3 -6
View File
@@ -118,12 +118,9 @@ public class WaveSpawner{
flySpawns.clear(); flySpawns.clear();
groundSpawns.clear(); groundSpawns.clear();
for(int x = 0; x < world.width(); x++){ for(Tile tile : world.tiles){
for(int y = 0; y < world.height(); y++){ if(tile.overlay() == Blocks.spawn){
addSpawns(tile.x, tile.y);
if(world.tile(x, y).overlay() == Blocks.spawn){
addSpawns(x, y);
}
} }
} }
} }
@@ -254,14 +254,11 @@ public class MapEditorDialog extends Dialog implements Disposable{
))); )));
world.endMapLoad(); world.endMapLoad();
//add entities so they update. is this really needed? //add entities so they update. is this really needed?
for(int x = 0; x < world.width(); x++){ for(Tile tile : world.tiles){
for(int y = 0; y < world.height(); y++){
Tile tile = world.rawTile(x, y);
if(tile.entity != null){ if(tile.entity != null){
tile.entity.add(); tile.entity.add();
} }
} }
}
player.set(world.width() * tilesize/2f, world.height() * tilesize/2f); player.set(world.width() * tilesize/2f, world.height() * tilesize/2f);
//TODO figure out how to kill player //TODO figure out how to kill player
//player.dead(false); //player.dead(false);
+3 -10
View File
@@ -53,14 +53,11 @@ public class BlockRenderer implements Disposable{
Draw.color(shadowColor); Draw.color(shadowColor);
for(int x = 0; x < world.width(); x++){ for(Tile tile : world.tiles){
for(int y = 0; y < world.height(); y++){
Tile tile = world.rawTile(x, y);
if(tile.block().hasShadow){ if(tile.block().hasShadow){
Fill.rect(tile.x + 0.5f, tile.y + 0.5f, 1, 1); Fill.rect(tile.x + 0.5f, tile.y + 0.5f, 1, 1);
} }
} }
}
Draw.flush(); Draw.flush();
Draw.color(); Draw.color();
@@ -72,18 +69,14 @@ public class BlockRenderer implements Disposable{
Core.graphics.clear(Color.white); Core.graphics.clear(Color.white);
Draw.proj().setOrtho(0, 0, fog.getWidth(), fog.getHeight()); Draw.proj().setOrtho(0, 0, fog.getWidth(), fog.getHeight());
for(int x = 0; x < world.width(); x++){ for(Tile tile : world.tiles){
for(int y = 0; y < world.height(); y++){ float darkness = world.getDarkness(tile.x, tile.y);
Tile tile = world.rawTile(x, y);
float darkness = world.getDarkness(x, y);
if(darkness > 0){ if(darkness > 0){
Draw.color(0f, 0f, 0f, Math.min((darkness + 0.5f) / 4f, 1f)); Draw.color(0f, 0f, 0f, Math.min((darkness + 0.5f) / 4f, 1f));
Fill.rect(tile.x + 0.5f, tile.y + 0.5f, 1, 1); Fill.rect(tile.x + 0.5f, tile.y + 0.5f, 1, 1);
} }
} }
}
Draw.flush(); Draw.flush();
Draw.color(); Draw.color();
+8 -21
View File
@@ -170,13 +170,13 @@ public class MenuRenderer implements Disposable{
Draw.proj().setOrtho(0, 0, shadows.getWidth(), shadows.getHeight()); Draw.proj().setOrtho(0, 0, shadows.getWidth(), shadows.getHeight());
shadows.beginDraw(Color.clear); shadows.beginDraw(Color.clear);
Draw.color(Color.black); Draw.color(Color.black);
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){ for(Tile tile : world.tiles){
if(world.rawTile(x, y).block() != Blocks.air){ if(tile.block() != Blocks.air){
Fill.rect(x + 0.5f, y + 0.5f, 1, 1); Fill.rect(tile.x + 0.5f, tile.y + 0.5f, 1, 1);
}
} }
} }
Draw.color(); Draw.color();
shadows.endDraw(); shadows.endDraw();
@@ -185,33 +185,20 @@ public class MenuRenderer implements Disposable{
Core.batch = batch = new CacheBatch(new SpriteCache(width * height * 6, false)); Core.batch = batch = new CacheBatch(new SpriteCache(width * height * 6, false));
batch.beginCache(); batch.beginCache();
for(int x = 0; x < width; x++){ for(Tile tile : world.tiles){
for(int y = 0; y < height; y++){
Tile tile = world.rawTile(x, y);
tile.floor().draw(tile); tile.floor().draw(tile);
} }
}
for(int x = 0; x < width; x++){ for(Tile tile : world.tiles){
for(int y = 0; y < height; y++){
Tile tile = world.rawTile(x, y);
if(tile.overlay() != Blocks.air){
tile.overlay().draw(tile); tile.overlay().draw(tile);
} }
}
}
cacheFloor = batch.endCache(); cacheFloor = batch.endCache();
batch.beginCache(); batch.beginCache();
for(int x = 0; x < width; x++){ for(Tile tile : world.tiles){
for(int y = 0; y < height; y++){
Tile tile = world.rawTile(x, y);
if(tile.block() != Blocks.air){
tile.block().draw(tile); tile.block().draw(tile);
} }
}
}
cacheWall = batch.endCache(); cacheWall = batch.endCache();
@@ -128,10 +128,8 @@ public class MinimapRenderer implements Disposable{
} }
public void updateAll(){ public void updateAll(){
for(int x = 0; x < world.width(); x++){ for(Tile tile : world.tiles){
for(int y = 0; y < world.height(); y++){ pixmap.draw(tile.x, pixmap.getHeight() - 1 - tile.y, colorFor(tile));
pixmap.draw(x, pixmap.getHeight() - 1 - y, colorFor(world.tile(x, y)));
}
} }
texture.draw(pixmap, 0, 0); texture.draw(pixmap, 0, 0);
} }
+16
View File
@@ -243,6 +243,16 @@ public class Tile implements Position{
Call.setTile(this, block, team, rotation); Call.setTile(this, block, team, rotation);
} }
/** set()-s this tile, except it's synced across the network */
public void setFloorNet(Block floor, Block overlay){
Call.setFloor(this, floor, overlay);
}
/** set()-s this tile, except it's synced across the network */
public void setFloorNet(Block floor){
setFloorNet(floor, Blocks.air);
}
public byte rotation(){ public byte rotation(){
return rotation; return rotation;
} }
@@ -526,6 +536,12 @@ public class Tile implements Position{
//remote utility methods //remote utility methods
@Remote(called = Loc.server)
public static void setFloor(Tile tile, Block floor, Block overlay){
tile.setFloor(floor.asFloor());
tile.setOverlay(overlay);
}
@Remote(called = Loc.server) @Remote(called = Loc.server)
public static void removeTile(Tile tile){ public static void removeTile(Tile tile){
tile.remove(); tile.remove();
+1 -1
View File
@@ -1,3 +1,3 @@
org.gradle.daemon=true org.gradle.daemon=true
org.gradle.jvmargs=-Xms256m -Xmx1024m org.gradle.jvmargs=-Xms256m -Xmx1024m
archash=80007985ae0f1cb24531272e910844d0b4b5bb18 archash=69ef047313449905aff6d1390d7136f9c7cdc986
+1 -4
View File
@@ -47,9 +47,7 @@ public class ZoneTests{
ObjectSet<Item> resources = new ObjectSet<>(); ObjectSet<Item> resources = new ObjectSet<>();
boolean hasSpawnPoint = false; boolean hasSpawnPoint = false;
for(int x = 0; x < world.width(); x++){ for(Tile tile : world.tiles){
for(int y = 0; y < world.height(); y++){
Tile tile = world.tile(x, y);
if(tile.drop() != null){ if(tile.drop() != null){
resources.add(tile.drop()); resources.add(tile.drop());
} }
@@ -57,7 +55,6 @@ public class ZoneTests{
hasSpawnPoint = true; hasSpawnPoint = true;
} }
} }
}
Array<SpawnGroup> spawns = state.rules.spawns; Array<SpawnGroup> spawns = state.rules.spawns;
for(int i = 1; i <= 100; i++){ for(int i = 1; i <= 100; i++){