1
0
mirror of https://github.com/Anuken/Mindustry.git synced 2024-11-10 15:05:23 +03:00

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
structQuadrants = new GridBits[Team.all().length];
for(int x = 0; x < world.width(); x++){
for(int y = 0; y < world.height(); y++){
Tile tile = world.tile(x, y);
for(Tile tile : world.tiles){
process(tile);
process(tile);
if(tile.entity != null && tile.entity.damaged()){
notifyTileDamaged(tile.entity);
}
if(tile.drop() != null) allOres.add(tile.drop());
if(tile.entity != null && tile.entity.damaged()){
notifyTileDamaged(tile.entity);
}
if(tile.drop() != null) allOres.add(tile.drop());
}
for(int x = 0; x < quadWidth(); x++){
@ -119,14 +115,11 @@ public class BlockIndexer{
if(structQuadrants == null) return;
//go through every tile... ouch
for(int x = 0; x < world.width(); x++){
for(int y = 0; y < world.height(); y++){
Tile tile = world.tile(x, y);
if(tile.team() == team){
int quadrantX = tile.x / quadrantSize;
int quadrantY = tile.y / quadrantSize;
structQuadrant(team).set(quadrantX, quadrantY);
}
for(Tile tile : world.tiles){
if(tile.team() == team){
int quadrantX = tile.x / quadrantSize;
int quadrantY = tile.y / quadrantSize;
structQuadrant(team).set(quadrantX, quadrantY);
}
}
}
@ -403,20 +396,16 @@ public class BlockIndexer{
ores.put(item, new ObjectSet<>());
}
for(int x = 0; x < world.width(); x++){
for(int y = 0; y < world.height(); y++){
int qx = (x / quadrantSize);
int qy = (y / quadrantSize);
for(Tile tile : world.tiles){
int qx = (tile.x / quadrantSize);
int qy = (tile.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){
ores.get(tile.drop()).add(world.tile(
//make sure to clamp quadrant middle position, since it might go off bounds
Mathf.clamp(qx * quadrantSize + quadrantSize / 2, 0, world.width() - 1),
Mathf.clamp(qy * quadrantSize + quadrantSize / 2, 0, world.height() - 1)));
}
//add position of quadrant to list when an ore is found
if(tile.drop() != null && scanOres.contains(tile.drop()) && tile.block() == Blocks.air){
ores.get(tile.drop()).add(world.tile(
//make sure to clamp quadrant middle position, since it might go off bounds
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;
import arc.*;
import mindustry.annotations.Annotations.*;
import arc.struct.*;
import arc.func.*;
import arc.math.geom.*;
import arc.util.*;
import arc.struct.*;
import arc.util.ArcAnnotate.*;
import arc.util.*;
import arc.util.async.*;
import mindustry.annotations.Annotations.*;
import mindustry.game.EventType.*;
import mindustry.game.*;
import mindustry.gen.*;
@ -45,10 +45,8 @@ public class Pathfinder implements Runnable{
created = new GridBits(Team.all().length, PathTarget.all.length);
list = new Array<>();
for(int x = 0; x < world.width(); x++){
for(int y = 0; y < world.height(); y++){
tiles[x][y] = packTile(world.rawTile(x, y));
}
for(Tile tile : world.tiles){
tiles[tile.x][tile.y] = packTile(tile);
}
//special preset which may help speed things up; this is optional

View File

@ -118,12 +118,9 @@ public class WaveSpawner{
flySpawns.clear();
groundSpawns.clear();
for(int x = 0; x < world.width(); x++){
for(int y = 0; y < world.height(); y++){
if(world.tile(x, y).overlay() == Blocks.spawn){
addSpawns(x, y);
}
for(Tile tile : world.tiles){
if(tile.overlay() == Blocks.spawn){
addSpawns(tile.x, tile.y);
}
}
}

View File

@ -254,12 +254,9 @@ public class MapEditorDialog extends Dialog implements Disposable{
)));
world.endMapLoad();
//add entities so they update. is this really needed?
for(int x = 0; x < world.width(); x++){
for(int y = 0; y < world.height(); y++){
Tile tile = world.rawTile(x, y);
if(tile.entity != null){
tile.entity.add();
}
for(Tile tile : world.tiles){
if(tile.entity != null){
tile.entity.add();
}
}
player.set(world.width() * tilesize/2f, world.height() * tilesize/2f);

View File

@ -53,12 +53,9 @@ public class BlockRenderer implements Disposable{
Draw.color(shadowColor);
for(int x = 0; x < world.width(); x++){
for(int y = 0; y < world.height(); y++){
Tile tile = world.rawTile(x, y);
if(tile.block().hasShadow){
Fill.rect(tile.x + 0.5f, tile.y + 0.5f, 1, 1);
}
for(Tile tile : world.tiles){
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);
Draw.proj().setOrtho(0, 0, fog.getWidth(), fog.getHeight());
for(int x = 0; x < world.width(); x++){
for(int y = 0; y < world.height(); y++){
Tile tile = world.rawTile(x, y);
for(Tile tile : world.tiles){
float darkness = world.getDarkness(tile.x, tile.y);
float darkness = world.getDarkness(x, y);
if(darkness > 0){
Draw.color(0f, 0f, 0f, Math.min((darkness + 0.5f) / 4f, 1f));
Fill.rect(tile.x + 0.5f, tile.y + 0.5f, 1, 1);
}
if(darkness > 0){
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());
shadows.beginDraw(Color.clear);
Draw.color(Color.black);
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
if(world.rawTile(x, y).block() != Blocks.air){
Fill.rect(x + 0.5f, y + 0.5f, 1, 1);
}
for(Tile tile : world.tiles){
if(tile.block() != Blocks.air){
Fill.rect(tile.x + 0.5f, tile.y + 0.5f, 1, 1);
}
}
Draw.color();
shadows.endDraw();
@ -185,32 +185,19 @@ public class MenuRenderer implements Disposable{
Core.batch = batch = new CacheBatch(new SpriteCache(width * height * 6, false));
batch.beginCache();
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
Tile tile = world.rawTile(x, y);
tile.floor().draw(tile);
}
for(Tile tile : world.tiles){
tile.floor().draw(tile);
}
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
Tile tile = world.rawTile(x, y);
if(tile.overlay() != Blocks.air){
tile.overlay().draw(tile);
}
}
for(Tile tile : world.tiles){
tile.overlay().draw(tile);
}
cacheFloor = batch.endCache();
batch.beginCache();
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
Tile tile = world.rawTile(x, y);
if(tile.block() != Blocks.air){
tile.block().draw(tile);
}
}
for(Tile tile : world.tiles){
tile.block().draw(tile);
}
cacheWall = batch.endCache();

View File

@ -128,10 +128,8 @@ public class MinimapRenderer implements Disposable{
}
public void updateAll(){
for(int x = 0; x < world.width(); x++){
for(int y = 0; y < world.height(); y++){
pixmap.draw(x, pixmap.getHeight() - 1 - y, colorFor(world.tile(x, y)));
}
for(Tile tile : world.tiles){
pixmap.draw(tile.x, pixmap.getHeight() - 1 - tile.y, colorFor(tile));
}
texture.draw(pixmap, 0, 0);
}

View File

@ -243,6 +243,16 @@ public class Tile implements Position{
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(){
return rotation;
}
@ -526,6 +536,12 @@ public class Tile implements Position{
//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)
public static void removeTile(Tile tile){
tile.remove();

View File

@ -1,3 +1,3 @@
org.gradle.daemon=true
org.gradle.jvmargs=-Xms256m -Xmx1024m
archash=80007985ae0f1cb24531272e910844d0b4b5bb18
archash=69ef047313449905aff6d1390d7136f9c7cdc986

View File

@ -47,15 +47,12 @@ public class ZoneTests{
ObjectSet<Item> resources = new ObjectSet<>();
boolean hasSpawnPoint = false;
for(int x = 0; x < world.width(); x++){
for(int y = 0; y < world.height(); y++){
Tile tile = world.tile(x, y);
if(tile.drop() != null){
resources.add(tile.drop());
}
if(tile.block() instanceof CoreBlock && tile.team() == state.rules.defaultTeam){
hasSpawnPoint = true;
}
for(Tile tile : world.tiles){
if(tile.drop() != null){
resources.add(tile.drop());
}
if(tile.block() instanceof CoreBlock && tile.team() == state.rules.defaultTeam){
hasSpawnPoint = true;
}
}