New tile edge algorithms / Struct value type generation

This commit is contained in:
Anuken
2019-01-28 22:11:23 -05:00
parent 5a3ec8f407
commit 54bade668e
19 changed files with 7275 additions and 7459 deletions

View File

@@ -1,7 +1,9 @@
package io.anuke.mindustry.content;
import io.anuke.arc.Core;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.TextureRegion;
import io.anuke.mindustry.game.ContentList;
import io.anuke.mindustry.graphics.CacheLayer;
import io.anuke.mindustry.type.Category;
@@ -32,8 +34,9 @@ public class Blocks implements ContentList{
public static Block
//environment
air, part, spawn, space, metalfloor, deepwater, water, tar, stone, craters, charr, blackstone, dirt, sand, ice, snow, iceSnow,
grass, holostone, holostoneSnow, shrub, rock, icerock, blackrock, rocks, icerocks, cliffs, pine, whiteTree, sporeCluster,
air, part, spawn, deepwater, water, tar, stone, craters, charr, sand, ice, snow,
grass, holostone, rocks, icerocks, cliffs, pine, whiteTree, whiteTreeDead, sporeCluster,
iceSnow,
//crafting
siliconSmelter, graphitePress, plastaniumCompressor, multiPress, phaseWeaver, surgeSmelter, pyratiteMixer, blastMixer, cryofluidMixer,
@@ -83,6 +86,12 @@ public class Blocks implements ContentList{
public void draw(Tile tile){}
public void load(){}
public void init(){}
public TextureRegion[] variantRegions(){
if(variantRegions == null){
variantRegions = new TextureRegion[]{Core.atlas.find("clear")};
}
return variantRegions;
}
};
part = new BlockPart();
@@ -97,18 +106,6 @@ public class Blocks implements ContentList{
new BuildBlock("build" + i);
}
space = new Floor("space"){{
placeableOn = false;
variants = 0;
cacheLayer = CacheLayer.space;
solid = true;
minimapColor = Color.valueOf("000001");
}};
metalfloor = new Floor("metalfloor"){{
variants = 6;
}};
deepwater = new Floor("deepwater"){{
liquidColor = Color.valueOf("546bb3");
speedMultiplier = 0.2f;
@@ -161,16 +158,6 @@ public class Blocks implements ContentList{
minimapColor = Color.valueOf("323232");
}};
blackstone = new Floor("blackstone"){{
minimapColor = Color.valueOf("252525");
playerUnmineable = true;
hasOres = true;
}};
dirt = new Floor("dirt"){{
minimapColor = Color.valueOf("6e501e");
}};
sand = new Floor("sand"){{
itemDrop = Items.sand;
minimapColor = Color.valueOf("988a67");
@@ -184,13 +171,12 @@ public class Blocks implements ContentList{
minimapColor = Color.valueOf("b8eef8");
}};
snow = new Floor("snow"){{
minimapColor = Color.valueOf("c2d1d2");
holostone = new Floor("holostone"){{
hasOres = true;
}};
iceSnow = new Floor("ice-snow"){{
snow = new Floor("snow"){{
minimapColor = Color.valueOf("c2d1d2");
variants = 3;
}};
grass = new Floor("grass"){{
@@ -198,8 +184,6 @@ public class Blocks implements ContentList{
minimapColor = Color.valueOf("549d5b");
}};
shrub = new Rock("shrub");
cliffs = new StaticWall("cliffs"){{
variants = 1;
fillsTile = false;
@@ -218,19 +202,18 @@ public class Blocks implements ContentList{
variants = 0;
}};
whiteTree = new TreeBlock("white-tree-dead"){{
whiteTreeDead = new TreeBlock("white-tree-dead"){{
}};
whiteTree = new TreeBlock("white-tree"){{
}};
sporeCluster = new Rock("spore-cluster"){{
variants = 3;
}};
holostone = new Floor("holostone"){{
hasOres = true;
}};
holostoneSnow = new Floor("holostone-snow"){{
iceSnow = new Floor("iceSnow"){{
variants = 3;
}};
//endregion

View File

@@ -167,7 +167,7 @@ public class MapEditorDialog extends Dialog implements Disposable{
editor.beginEdit(data, meta.tags, false);
view.clearStack();
}catch(Exception e){
ui.showError(Core.bundle.format("editor.errormapload", Strings.parseException(e, false)));
ui.showError(Core.bundle.format("editor.errorimageload", Strings.parseException(e, false)));
Log.err(e);
}
}));

View File

@@ -201,7 +201,7 @@ public class FloorRenderer{
int chunksx = Mathf.ceil((float) (world.width()) / chunksize),
chunksy = Mathf.ceil((float) (world.height()) / chunksize) ;
cache = new Chunk[chunksx][chunksy];
SpriteCache sprites = new SpriteCache(world.width() * world.height() * 3, (world.width() / chunksize) * (world.height() / chunksize) * 2, false);
SpriteCache sprites = new SpriteCache(world.width() * world.height() * 5, (world.width() / chunksize) * (world.height() / chunksize) * 2, false);
cbatch = new CacheBatch(sprites);
Time.mark();

View File

@@ -13,6 +13,7 @@ import io.anuke.mindustry.maps.MapTileData.TileDataMarker;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.OreBlock;
import io.anuke.mindustry.world.blocks.StaticWall;
import io.anuke.mindustry.world.blocks.storage.CoreBlock;
import static io.anuke.mindustry.Vars.*;
@@ -89,7 +90,8 @@ public class MapGenerator extends Generator{
int newX = Mathf.clamp((int)(simplex.octaveNoise2D(1, 1, 1.0 / scl, x, y) * distortion + x), 0, data.width()-1);
int newY = Mathf.clamp((int)(simplex.octaveNoise2D(1, 1, 1.0 / scl, x + 9999, y + 9999) * distortion + y), 0, data.height()-1);
if(tiles[newX][newY].block() != Blocks.spawn && !tile.block().synthetic()&& !tiles[newX][newY].block().synthetic()){
if(tile.block() instanceof StaticWall
&& tiles[newX][newY].block() instanceof StaticWall){
tile.setBlock(tiles[newX][newY].block());
}

View File

@@ -115,7 +115,7 @@ public class Block extends BlockStorage{
protected Array<Tile> tempTiles = new Array<>();
protected TextureRegion[] icons = new TextureRegion[Icon.values().length];
protected TextureRegion[] generatedIcons;
protected TextureRegion[] variants;
protected TextureRegion[] variantRegions;
protected TextureRegion region;
public Block(String name){
@@ -503,10 +503,10 @@ public class Block extends BlockStorage{
}
public TextureRegion[] variantRegions(){
if(variants == null){
variants = new TextureRegion[]{icon(Icon.full)};
if(variantRegions == null){
variantRegions = new TextureRegion[]{icon(Icon.full)};
}
return variants;
return variantRegions;
}
public boolean hasEntity(){

View File

@@ -20,7 +20,8 @@ public class LegacyColorMapper implements ContentList{
public void load(){
defaultValue = new LegacyBlock(Blocks.stone, Blocks.air);
map("ff0000", Blocks.dirt, 0);
//TODO remap colors later
// map("ff0000", Blocks.dirt, 0);
map("00ff00", Blocks.stone, 0);
map("323232", Blocks.stone, 0);
map("646464", Blocks.stone, 1);
@@ -28,15 +29,15 @@ public class LegacyColorMapper implements ContentList{
map("5ab464", Blocks.grass, 1);
map("506eb4", Blocks.water, 0);
map("465a96", Blocks.deepwater, 0);
map("252525", Blocks.blackstone, 0);
map("575757", Blocks.blackstone, 1);
//map("252525", Blocks.blackstone, 0);
//map("575757", Blocks.blackstone, 1);
map("988a67", Blocks.sand, 0);
map("e5d8bb", Blocks.sand, 1);
map("c2d1d2", Blocks.snow, 0);
map("c4e3e7", Blocks.ice, 0);
map("f7feff", Blocks.snow, 1);
map("6e501e", Blocks.dirt, 0);
map("ed5334", Blocks.blackstone, 0);
//map("6e501e", Blocks.dirt, 0);
//map("ed5334", Blocks.blackstone, 0);
map("292929", Blocks.tar, 0);
map("c3a490", OreBlock.get(Blocks.stone, Items.copper), 0);
map("161616", OreBlock.get(Blocks.stone, Items.coal), 0);

View File

@@ -6,6 +6,8 @@ import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.TextureRegion;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.geom.Geometry;
import io.anuke.arc.math.geom.Point2;
import io.anuke.mindustry.content.Fx;
import io.anuke.mindustry.content.StatusEffects;
import io.anuke.mindustry.type.Item;
@@ -51,8 +53,9 @@ public class Floor extends Block{
public float heat = 0f;
/** if true, this block cannot be mined by players. useful for annoying things like sand. */
public boolean playerUnmineable = false;
protected TextureRegion[] regions;
protected TextureRegion[][] edges;
protected byte eq = 0;
public Floor(String name){
super(name);
@@ -65,24 +68,26 @@ public class Floor extends Block{
//load variant regions for drawing
if(variants > 0){
regions = new TextureRegion[variants];
variantRegions = new TextureRegion[variants];
for(int i = 0; i < variants; i++){
regions[i] = Core.atlas.find(name + (i + 1));
variantRegions[i] = Core.atlas.find(name + (i + 1));
}
}else{
regions = new TextureRegion[1];
regions[0] = Core.atlas.find(name);
variantRegions = new TextureRegion[1];
variantRegions[0] = Core.atlas.find(name);
}
int size = (int)(tilesize / Draw.scl);
edges = Core.atlas.find(name + "-edge").split(size, size);
region = regions[0];
if(Core.atlas.has(name + "-edge")){
edges = Core.atlas.find(name + "-edge").split(size, size);
}
region = variantRegions[0];
}
@Override
public TextureRegion[] variantRegions(){
return regions;
public TextureRegion[] generateIcons(){
return new TextureRegion[]{Core.atlas.find(Core.atlas.has(name) ? name : name + "1")};
}
@Override
@@ -98,12 +103,57 @@ public class Floor extends Block{
public void draw(Tile tile){
Mathf.random.setSeed(tile.pos());
Draw.rect(regions[Mathf.randomSeed(tile.pos(), 0, Math.max(0, regions.length - 1))], tile.worldx(), tile.worldy());
Draw.rect(variantRegions[Mathf.randomSeed(tile.pos(), 0, Math.max(0, variantRegions.length - 1))], tile.worldx(), tile.worldy());
drawEdges(tile);
}
@Override
public TextureRegion[] generateIcons(){
return new TextureRegion[]{Core.atlas.find(Core.atlas.has(name) ? name : name + "1")};
protected void drawEdges(Tile tile){
eq = 0;
Floor floor = tile.floor();
for(int i = 0; i < 8; i++){
Point2 point = Geometry.d8[i];
Tile other = tile.getNearby(point);
if(other != null && other.floor().id < floor.id && other.floor().edges != null){
eq |= (1 << i);
}
}
for(int i = 0; i < 8; i++){
if(eq(i)){
Point2 point = Geometry.d8[i];
Tile other = tile.getNearby(point);
TextureRegion region = edge(other.floor(), type(i), 2-(point.x + 1), 2-(point.y + 1));
Draw.rect(region, tile.worldx(), tile.worldy());
}
}
}
int type(int i){
if(!eq(i - 1) && !eq(i + 1)){
//case 0: touching
return 0;
}else if(eq(i - 1) && eq(i - 2) && eq(i + 1) && eq(i + 2)){
//case 2: surrounded
return 2;
}else if(eq(i - 1) && eq(i + 1)){
//case 1: flat
return 1;
}else{
//case 0 is rounded, so it's the safest choice, should work for most possibilities
return 0;
}
}
boolean eq(int i){
return (eq & (1 << Mathf.mod(i, 8))) != 0;
}
TextureRegion edge(Floor block, int type, int x, int y){
return block.edges[x + type*3][2-y];
}
}

View File

@@ -31,7 +31,7 @@ public class OreBlock extends Floor{
@Override
public void draw(Tile tile){
Draw.rect(regions[Mathf.randomSeed(tile.pos(), 0, Math.max(0, regions.length - 1))], tile.worldx(), tile.worldy());
Draw.rect(variantRegions[Mathf.randomSeed(tile.pos(), 0, Math.max(0, variantRegions.length - 1))], tile.worldx(), tile.worldy());
}
public static Block get(Block floor, Item item){