Wall generation

This commit is contained in:
Anuken
2020-02-17 20:33:01 -05:00
parent e215772f30
commit da2cc292c3
18 changed files with 123 additions and 40 deletions

View File

@@ -302,6 +302,7 @@ public class Blocks implements ContentList{
icerocks = new StaticWall("icerocks"){{
variants = 2;
iceSnow.asFloor().wall = this;
}};
snowrocks = new StaticWall("snowrocks"){{
@@ -365,11 +366,13 @@ public class Blocks implements ContentList{
moss = new Floor("moss"){{
variants = 3;
attributes.set(Attribute.spores, 0.15f);
wall = sporePine;
}};
sporeMoss = new Floor("spore-moss"){{
variants = 3;
attributes.set(Attribute.spores, 0.3f);
wall = sporerocks;
}};
metalFloor = new Floor("metal-floor"){{

View File

@@ -17,6 +17,7 @@ public class UnitTypes implements ContentList{
public static @EntityDef({Unitc.class}) UnitType spirit;
public static @EntityDef({Unitc.class, Builderc.class}) UnitType phantom;
//TODO remove
public static UnitType alpha, delta, tau, omega, dart, javelin, trident, glaive;
public static UnitType starter;

View File

@@ -233,6 +233,10 @@ public class ContentLoader{
return (Block)getByID(ContentType.block, id);
}
public Block block(String name){
return (Block)getByName(ContentType.block, name);
}
public Array<Item> items(){
return getBy(ContentType.item);
}

View File

@@ -7,7 +7,6 @@ import arc.math.geom.*;
import arc.struct.*;
import arc.util.ArcAnnotate.*;
import arc.util.*;
import mindustry.content.*;
import mindustry.core.GameState.*;
import mindustry.game.EventType.*;
import mindustry.game.*;
@@ -69,11 +68,11 @@ public class World{
}
public int width(){
return tiles.width();
return tiles.width;
}
public int height(){
return tiles.height();
return tiles.height;
}
public int unitWidth(){
@@ -130,7 +129,7 @@ public class World{
public Tiles resize(int width, int height){
clearTileEntities();
if(tiles.width() != width || tiles.height() != height){
if(tiles.width != width || tiles.height != height){
tiles = new Tiles(width, height);
}
@@ -164,7 +163,7 @@ public class World{
addDarkness(tiles);
}
Groups.resize(-finalWorldBounds, -finalWorldBounds, tiles.width() * tilesize + finalWorldBounds * 2, tiles.height() * tilesize + finalWorldBounds * 2);
Groups.resize(-finalWorldBounds, -finalWorldBounds, tiles.width * tilesize + finalWorldBounds * 2, tiles.height * tilesize + finalWorldBounds * 2);
generating = false;
Events.fire(new WorldLoadEvent());
@@ -207,8 +206,7 @@ public class World{
sector.planet.generator.generate(position, gen);
tiles.set(x, y, new Tile(x, y, gen.floor, gen.overlay, gen.block));
});
tiles.get(size/2, size/2).setBlock(Blocks.coreShard, Team.sharded);
sector.planet.generator.decorate(tiles);
});
}
@@ -300,8 +298,8 @@ public class World{
}
public void addDarkness(Tiles tiles){
byte[] dark = new byte[tiles.width() * tiles.height()];
byte[] writeBuffer = new byte[tiles.width() * tiles.height()];
byte[] dark = new byte[tiles.width * tiles.height];
byte[] writeBuffer = new byte[tiles.width * tiles.height];
byte darkIterations = 4;
@@ -314,11 +312,11 @@ public class World{
for(int i = 0; i < darkIterations; i++){
for(Tile tile : tiles){
int idx = tile.y * tiles.width() + tile.x;
int idx = tile.y * tiles.width + tile.x;
boolean min = false;
for(Point2 point : Geometry.d4){
int newX = tile.x + point.x, newY = tile.y + point.y;
int nidx = newY * tiles.width() + newX;
int nidx = newY * tiles.width + newX;
if(tiles.in(newX, newY) && dark[nidx] < dark[idx]){
min = true;
break;
@@ -331,7 +329,7 @@ public class World{
}
for(Tile tile : tiles){
int idx = tile.y * tiles.width() + tile.x;
int idx = tile.y * tiles.width + tile.x;
if(tile.isDarkened()){
tile.rotation(dark[idx]);
@@ -341,7 +339,7 @@ public class World{
boolean full = true;
for(Point2 p : Geometry.d4){
int px = p.x + tile.x, py = p.y + tile.y;
int nidx = py * tiles.width() + px;
int nidx = py * tiles.width + px;
if(tiles.in(px, py) && !(tile.isDarkened() && dark[nidx] == 4)){
full = false;
break;

View File

@@ -120,4 +120,9 @@ public class PlanetRenderer implements PlanetGenerator{
public void generate(Vec3 position, TileGen tile){
}
@Override
public void decorate(Tiles tiles){
}
}

View File

@@ -133,7 +133,7 @@ public class MapIO{
}
public static Pixmap generatePreview(Tiles tiles){
Pixmap pixmap = new Pixmap(tiles.width(), tiles.height(), Format.RGBA8888);
Pixmap pixmap = new Pixmap(tiles.width, tiles.height, Format.RGBA8888);
for(int x = 0; x < pixmap.getWidth(); x++){
for(int y = 0; y < pixmap.getHeight(); y++){
Tile tile = tiles.getn(x, y);

View File

@@ -182,7 +182,7 @@ public abstract class BasicGenerator extends RandomGenerator{
Tile end = tiles.getn(endX, endY);
GridBits closed = new GridBits(width, height);
IntFloatMap costs = new IntFloatMap();
PriorityQueue<Tile> queue = new PriorityQueue<>(tiles.width() * tiles.height()/4, (a, b) -> Float.compare(costs.get(a.pos(), 0f) + dh.cost(a.x, a.y, end.x, end.y), costs.get(b.pos(), 0f) + dh.cost(b.x, b.y, end.x, end.y)));
PriorityQueue<Tile> queue = new PriorityQueue<>(tiles.width * tiles.height /4, (a, b) -> Float.compare(costs.get(a.pos(), 0f) + dh.cost(a.x, a.y, end.x, end.y), costs.get(b.pos(), 0f) + dh.cost(b.x, b.y, end.x, end.y)));
queue.add(start);
boolean found = false;
while(!queue.isEmpty()){

View File

@@ -62,7 +62,7 @@ public class MapGenerator extends Generator{
for(Tile tile : tiles){
if(tile.overlay() == Blocks.spawn){
int rad = 10;
Geometry.circle(tile.x, tile.y, tiles.width(), tiles.height(), rad, (wx, wy) -> {
Geometry.circle(tile.x, tile.y, tiles.width, tiles.height, rad, (wx, wy) -> {
if(tile.overlay().itemDrop != null){
tile.clearOverlay();
}

View File

@@ -20,11 +20,14 @@ public abstract class RandomGenerator extends Generator{
public void generate(Tiles tiles){
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
floor = Blocks.air;
block = Blocks.air;
ore = Blocks.air;
Tile prev = tiles.getn(x, y);
floor = prev.floor();
block = prev.block();
ore = prev.overlay();
generate(x, y);
tiles.set(x, y, new Tile(x, y, floor, ore, block));
prev.setFloor(floor.asFloor());
prev.setBlock(block);
prev.setOverlay(ore);
}
}

View File

@@ -8,4 +8,5 @@ public interface PlanetGenerator{
float getHeight(Vec3 position);
Color getColor(Vec3 position);
void generate(Vec3 position, TileGen tile);
void decorate(Tiles tiles);
}

View File

@@ -3,11 +3,14 @@ package mindustry.maps.planet;
import arc.graphics.*;
import arc.math.*;
import arc.math.geom.*;
import arc.struct.*;
import arc.util.*;
import arc.util.noise.*;
import mindustry.content.*;
import mindustry.game.*;
import mindustry.world.*;
//TODO refactor into generic planet class
public class TestPlanetGenerator implements PlanetGenerator{
Simplex noise = new Simplex();
float scl = 5f;
@@ -53,6 +56,57 @@ public class TestPlanetGenerator implements PlanetGenerator{
@Override
public void generate(Vec3 position, TileGen tile){
tile.floor = getBlock(position);
tile.block = tile.floor.asFloor().wall;
if(noise.octaveNoise3D(5, 0.6, 8.0, position.x, position.y, position.z) > 0.65){
tile.block = Blocks.air;
}
}
@Override
public void decorate(Tiles tiles){
//OvergrowthGenerator generator = new OvergrowthGenerator(tiles.width, tiles.height);
//generator.init(Loadouts.basicNucleus);
//generator.generate(tiles);
GridBits write = new GridBits(tiles.width, tiles.height);
GridBits read = new GridBits(tiles.width, tiles.height);
//double removalChance = 0.2;
//remove random tiles
//tiles.each((x, y) -> {
//});
tiles.each((x, y) -> read.set(x, y, !tiles.get(x, y).block().isAir()));
int iterations = 4, birthLimit = 16, deathLimit = 16, radius = 3;
for(int i = 0; i < iterations; i++){
tiles.each((x, y) -> {
int alive = 0;
for(int cx = -radius; cx <= radius; cx++){
for(int cy = -radius; cy <= radius; cy++){
if((cx == 0 && cy == 0) || !Mathf.within(cx, cy, radius)) continue;
if(!Structs.inBounds(x + cx, y + cy, tiles.width, tiles.height) || read.get(x + cx, y + cy)){
alive++;
}
}
}
if(read.get(x, y)){
write.set(x, y, alive >= deathLimit);
}else{
write.set(x, y, alive > birthLimit);
}
});
//flush results.
tiles.each((x, y) -> read.set(x, y, write.get(x, y)));
}
tiles.each((x, y) -> tiles.get(x, y).setBlock(!write.get(x, y) ? Blocks.air : tiles.get(x, y).floor().wall));
tiles.get(tiles.width /2, tiles.height /2).setBlock(Blocks.coreShard, Team.sharded);
}
Block getBlock(Vec3 position){

View File

@@ -7,6 +7,7 @@ import mindustry.world.*;
import static mindustry.Vars.schematics;
//TODO remove
public class DesertWastesGenerator extends BasicGenerator{
public DesertWastesGenerator(int width, int height){

View File

@@ -7,6 +7,7 @@ import mindustry.world.*;
import static mindustry.Vars.schematics;
//TODO remove
public class OvergrowthGenerator extends BasicGenerator{
public OvergrowthGenerator(int width, int height){
@@ -15,13 +16,12 @@ public class OvergrowthGenerator extends BasicGenerator{
@Override
public void generate(int x, int y){
floor = Blocks.moss;
}
@Override
public void decorate(Tiles tiles){
ores(tiles);
terrain(tiles, Blocks.sporePine, 70f, 1.4f, 1f);
//terrain(tiles, Blocks.sporePine, 70f, 1.4f, 1f);
int rand = 40;
int border = 25;
@@ -36,7 +36,7 @@ public class OvergrowthGenerator extends BasicGenerator{
distort(tiles, 20f, 4f);
inverseFloodFill(tiles, tiles.getn(spawnX, spawnY), Blocks.sporerocks);
noise(tiles, Blocks.darksandTaintedWater, Blocks.duneRocks, 4, 0.7f, 120f, 0.64f);
//noise(tiles, Blocks.darksandTaintedWater, Blocks.duneRocks, 4, 0.7f, 120f, 0.64f);
//scatter(tiles, Blocks.sporePine, Blocks.whiteTreeDead, 1f);
tiles.getn(endX, endY).setOverlay(Blocks.spawn);

View File

@@ -161,6 +161,10 @@ public class Block extends BlockStorage{
this.solid = false;
}
public boolean isAir(){
return id == 0;
}
public boolean canBreak(Tile tile){
return true;
}

View File

@@ -7,8 +7,9 @@ import java.util.*;
/** A tile container. */
public class Tiles implements Iterable<Tile>{
public final int width, height;
private final Tile[] array;
private final int width, height;
private final TileIterator iterator = new TileIterator();
public Tiles(int width, int height){
@@ -63,14 +64,6 @@ public class Tiles implements Iterable<Tile>{
return get(Pos.x(pos), Pos.y(pos));
}
public int width(){
return width;
}
public int height(){
return height;
}
@Override
public Iterator<Tile> iterator(){
iterator.index = 0;

View File

@@ -6,8 +6,8 @@ import arc.graphics.g2d.*;
import arc.graphics.g2d.TextureAtlas.*;
import arc.math.*;
import arc.math.geom.*;
import arc.util.ArcAnnotate.*;
import arc.struct.*;
import arc.util.ArcAnnotate.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.graphics.*;
@@ -16,7 +16,7 @@ import mindustry.type.*;
import mindustry.ui.*;
import mindustry.world.*;
import static mindustry.Vars.tilesize;
import static mindustry.Vars.*;
public class Floor extends Block{
/** number of different variant regions to use */
@@ -57,6 +57,8 @@ public class Floor extends Block{
public boolean oreDefault = false;
/** Ore generation params. */
public float oreScale = 24f, oreThreshold = 0.828f;
/** Wall variant of this block. May be Blocks.air if not found. */
public Block wall = Blocks.air;
protected TextureRegion[][] edges;
protected byte eq = 0;
@@ -92,6 +94,20 @@ public class Floor extends Block{
edgeRegion = Core.atlas.find("edge");
}
@Override
public void init(){
super.init();
if(wall == Blocks.air){
wall = content.block(name + "Rocks");
if(wall == null) wall = content.block(name + "rocks");
if(wall == null) wall = content.block(name.replace("darksand", "dune") + "rocks");
}
//keep default value if not found...
if(wall == null) wall = Blocks.air;
}
@Override
public void createIcons(MultiPacker packer){
super.createIcons(packer);