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

View File

@@ -78,18 +78,14 @@ 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++){ process(tile);
Tile tile = world.tile(x, y);
process(tile); if(tile.entity != null && tile.entity.damaged()){
notifyTileDamaged(tile.entity);
if(tile.entity != null && tile.entity.damaged()){
notifyTileDamaged(tile.entity);
}
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++){
@@ -119,14 +115,11 @@ 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++){ if(tile.team() == team){
Tile tile = world.tile(x, y); int quadrantX = tile.x / quadrantSize;
if(tile.team() == team){ int quadrantY = tile.y / quadrantSize;
int quadrantX = tile.x / quadrantSize; structQuadrant(team).set(quadrantX, quadrantY);
int quadrantY = tile.y / quadrantSize;
structQuadrant(team).set(quadrantX, quadrantY);
}
} }
} }
} }
@@ -403,20 +396,16 @@ 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
if(tile.drop() != null && scanOres.contains(tile.drop()) && tile.block() == Blocks.air){
//add position of quadrant to list when an ore is found ores.get(tile.drop()).add(world.tile(
if(tile.drop() != null && scanOres.contains(tile.drop()) && tile.block() == Blocks.air){ //make sure to clamp quadrant middle position, since it might go off bounds
ores.get(tile.drop()).add(world.tile( Mathf.clamp(qx * quadrantSize + quadrantSize / 2, 0, world.width() - 1),
//make sure to clamp quadrant middle position, since it might go off bounds Mathf.clamp(qy * quadrantSize + quadrantSize / 2, 0, world.height() - 1)));
Mathf.clamp(qx * quadrantSize + quadrantSize / 2, 0, world.width() - 1),
Mathf.clamp(qy * quadrantSize + quadrantSize / 2, 0, world.height() - 1)));
}
} }
} }
} }

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

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

View File

@@ -254,12 +254,9 @@ 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++){ if(tile.entity != null){
Tile tile = world.rawTile(x, y); tile.entity.add();
if(tile.entity != null){
tile.entity.add();
}
} }
} }
player.set(world.width() * tilesize/2f, world.height() * tilesize/2f); player.set(world.width() * tilesize/2f, world.height() * tilesize/2f);

View File

@@ -53,12 +53,9 @@ 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++){ if(tile.block().hasShadow){
Tile tile = world.rawTile(x, y); Fill.rect(tile.x + 0.5f, tile.y + 0.5f, 1, 1);
if(tile.block().hasShadow){
Fill.rect(tile.x + 0.5f, tile.y + 0.5f, 1, 1);
}
} }
} }
@@ -72,16 +69,12 @@ 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){
Draw.color(0f, 0f, 0f, Math.min((darkness + 0.5f) / 4f, 1f));
if(darkness > 0){ Fill.rect(tile.x + 0.5f, tile.y + 0.5f, 1, 1);
Draw.color(0f, 0f, 0f, Math.min((darkness + 0.5f) / 4f, 1f));
Fill.rect(tile.x + 0.5f, tile.y + 0.5f, 1, 1);
}
} }
} }

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,32 +185,19 @@ 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.floor().draw(tile);
Tile tile = world.rawTile(x, y);
tile.floor().draw(tile);
}
} }
for(int x = 0; x < width; x++){ for(Tile tile : world.tiles){
for(int y = 0; y < height; y++){ tile.overlay().draw(tile);
Tile tile = world.rawTile(x, y);
if(tile.overlay() != Blocks.air){
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.block().draw(tile);
Tile tile = world.rawTile(x, y);
if(tile.block() != Blocks.air){
tile.block().draw(tile);
}
}
} }
cacheWall = batch.endCache(); cacheWall = batch.endCache();

View File

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

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();

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

View File

@@ -47,15 +47,12 @@ 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++){ if(tile.drop() != null){
Tile tile = world.tile(x, y); resources.add(tile.drop());
if(tile.drop() != null){ }
resources.add(tile.drop()); if(tile.block() instanceof CoreBlock && tile.team() == state.rules.defaultTeam){
} hasSpawnPoint = true;
if(tile.block() instanceof CoreBlock && tile.team() == state.rules.defaultTeam){
hasSpawnPoint = true;
}
} }
} }