mirror of
https://github.com/Anuken/Mindustry.git
synced 2026-03-13 02:11:08 -07:00
Less editor filter state
This commit is contained in:
parent
69d8af7874
commit
210fb349de
13 changed files with 38 additions and 44 deletions
|
|
@ -164,7 +164,7 @@ public class MapGenerateDialog extends BaseDialog{
|
|||
for(int x = 0; x < editor.width(); x++){
|
||||
for(int y = 0; y < editor.height(); y++){
|
||||
Tile tile = editor.tile(x, y);
|
||||
input.apply(x, y, tile.block(), tile.floor(), tile.overlay());
|
||||
input.set(x, y, tile.block(), tile.floor(), tile.overlay());
|
||||
filter.apply(input);
|
||||
writeTiles[x + y*world.width()] = PackTile.get(input.block.id, input.floor.id, input.overlay.id);
|
||||
}
|
||||
|
|
@ -420,7 +420,7 @@ public class MapGenerateDialog extends BaseDialog{
|
|||
pixmap.each((px, py) -> {
|
||||
int x = px * scaling, y = py * scaling;
|
||||
long tile = buffer1[px + py * w];
|
||||
input.apply(x, y, content.block(PackTile.block(tile)), content.block(PackTile.floor(tile)), content.block(PackTile.overlay(tile)));
|
||||
input.set(x, y, content.block(PackTile.block(tile)), content.block(PackTile.floor(tile)), content.block(PackTile.overlay(tile)));
|
||||
filter.apply(input);
|
||||
buffer2[px + py * w] = PackTile.get(input.block.id, input.floor.id, input.overlay.id);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ public class BlendFilter extends GenerateFilter{
|
|||
}
|
||||
|
||||
@Override
|
||||
public void apply(){
|
||||
public void apply(GenerateInput in){
|
||||
if(in.floor == block || block == Blocks.air || in.floor == ignore || (!floor.isFloor() && (in.block == block || in.block == ignore))) return;
|
||||
|
||||
int rad = (int)radius;
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ public class ClearFilter extends GenerateFilter{
|
|||
}
|
||||
|
||||
@Override
|
||||
public void apply(){
|
||||
public void apply(GenerateInput in){
|
||||
|
||||
if(in.block == block){
|
||||
in.block = Blocks.air;
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ public class DistortFilter extends GenerateFilter{
|
|||
}
|
||||
|
||||
@Override
|
||||
public void apply(){
|
||||
Tile tile = in.tile(in.x + noise(in.x, in.y, scl, mag) - mag / 2f, in.y + noise(in.x, in.y, scl, mag) - mag / 2f);
|
||||
public void apply(GenerateInput in){
|
||||
Tile tile = in.tile(in.x + noise(in, scl, mag) - mag / 2f, in.y + noise(in, scl, mag) - mag / 2f);
|
||||
|
||||
in.floor = tile.floor();
|
||||
if(!tile.block().synthetic() && !in.block.synthetic()) in.block = tile.block();
|
||||
|
|
|
|||
|
|
@ -14,10 +14,7 @@ import mindustry.world.*;
|
|||
public abstract class GenerateFilter{
|
||||
public int seed = 0;
|
||||
|
||||
protected transient GenerateInput in;
|
||||
|
||||
public void apply(Tiles tiles, GenerateInput in){
|
||||
this.in = in;
|
||||
|
||||
if(isBuffered()){
|
||||
//buffer of tiles used, each tile packed into a long struct
|
||||
|
|
@ -26,8 +23,8 @@ public abstract class GenerateFilter{
|
|||
for(int i = 0; i < tiles.width * tiles.height; i++){
|
||||
Tile tile = tiles.geti(i);
|
||||
|
||||
in.apply(tile.x, tile.y, tile.block(), tile.floor(), tile.overlay());
|
||||
apply();
|
||||
in.set(tile.x, tile.y, tile.block(), tile.floor(), tile.overlay());
|
||||
apply(in);
|
||||
|
||||
buffer[i] = PackTile.get(in.block.id, in.floor.id, in.overlay.id);
|
||||
}
|
||||
|
|
@ -48,8 +45,8 @@ public abstract class GenerateFilter{
|
|||
}
|
||||
}else{
|
||||
for(Tile tile : tiles){
|
||||
in.apply(tile.x, tile.y, tile.block(), tile.floor(), tile.overlay());
|
||||
apply();
|
||||
in.set(tile.x, tile.y, tile.block(), tile.floor(), tile.overlay());
|
||||
apply(in);
|
||||
|
||||
tile.setFloor(in.floor.asFloor());
|
||||
tile.setOverlay(!in.floor.asFloor().hasSurface() && in.overlay.asFloor().needsSurface ? Blocks.air : in.overlay);
|
||||
|
|
@ -61,16 +58,11 @@ public abstract class GenerateFilter{
|
|||
}
|
||||
}
|
||||
|
||||
public final void apply(GenerateInput in){
|
||||
this.in = in;
|
||||
apply();
|
||||
}
|
||||
|
||||
/** @return a new array of options for configuring this filter */
|
||||
public abstract FilterOption[] options();
|
||||
|
||||
/** apply the actual filter on the input */
|
||||
protected void apply(){}
|
||||
public void apply(GenerateInput in){}
|
||||
|
||||
/** draw any additional guides */
|
||||
public void draw(Image image){}
|
||||
|
|
@ -108,12 +100,14 @@ public abstract class GenerateFilter{
|
|||
|
||||
//utility generation functions
|
||||
|
||||
protected float noise(float x, float y, float scl, float mag){
|
||||
return (float)in.noise.octaveNoise2D(1f, 0f, 1f / scl, x, y) * mag;
|
||||
//TODO would be nice if these functions used the seed and ditched "in" completely; simplex should be stateless
|
||||
|
||||
protected float noise(GenerateInput in, float scl, float mag){
|
||||
return (float)in.noise.octaveNoise2D(1f, 0f, 1f / scl, in.x, in.y) * mag;
|
||||
}
|
||||
|
||||
protected float noise(float x, float y, float scl, float mag, float octaves, float persistence){
|
||||
return (float)in.noise.octaveNoise2D(octaves, persistence, 1f / scl, x, y) * mag;
|
||||
protected float noise(GenerateInput in, float scl, float mag, float octaves, float persistence){
|
||||
return (float)in.noise.octaveNoise2D(octaves, persistence, 1f / scl, in.x, in.y) * mag;
|
||||
}
|
||||
|
||||
protected float rnoise(float x, float y, float scl, float mag){
|
||||
|
|
@ -124,8 +118,8 @@ public abstract class GenerateFilter{
|
|||
return RidgedPerlin.noise2d(seed + 1, (int)(x), (int)(y), octaves, falloff, 1f / scl) * mag;
|
||||
}
|
||||
|
||||
protected float chance(){
|
||||
return Mathf.randomSeed(Pack.longInt(in.x, in.y + seed));
|
||||
protected float chance(int x, int y){
|
||||
return Mathf.randomSeed(Pack.longInt(x, y + seed));
|
||||
}
|
||||
|
||||
/** an input for generating at a certain coordinate. should only be instantiated once. */
|
||||
|
|
@ -140,7 +134,7 @@ public abstract class GenerateFilter{
|
|||
Simplex noise = new Simplex();
|
||||
TileProvider buffer;
|
||||
|
||||
public void apply(int x, int y, Block block, Block floor, Block overlay){
|
||||
public void set(int x, int y, Block block, Block floor, Block overlay){
|
||||
this.floor = floor;
|
||||
this.block = block;
|
||||
this.overlay = overlay;
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public class MedianFilter extends GenerateFilter{
|
|||
}
|
||||
|
||||
@Override
|
||||
public void apply(){
|
||||
public void apply(GenerateInput in){
|
||||
int rad = (int)radius;
|
||||
blocks.clear();
|
||||
floors.clear();
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ public class MirrorFilter extends GenerateFilter{
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void apply(){
|
||||
public void apply(GenerateInput in){
|
||||
v1.trnsExact(angle - 90, 1f);
|
||||
v2.set(v1).scl(-1f);
|
||||
|
||||
|
|
@ -41,7 +41,7 @@ public class MirrorFilter extends GenerateFilter{
|
|||
v3.set(in.x, in.y);
|
||||
|
||||
if(!left(v1, v2, v3)){
|
||||
mirror(v3, v1.x, v1.y, v2.x, v2.y);
|
||||
mirror(in.width, in.height, v3, v1.x, v1.y, v2.x, v2.y);
|
||||
Tile tile = in.tile(v3.x, v3.y);
|
||||
in.floor = tile.floor();
|
||||
if(!tile.block().synthetic()){
|
||||
|
|
@ -73,11 +73,11 @@ public class MirrorFilter extends GenerateFilter{
|
|||
Draw.reset();
|
||||
}
|
||||
|
||||
void mirror(Vec2 p, float x0, float y0, float x1, float y1){
|
||||
void mirror(int width, int height, Vec2 p, float x0, float y0, float x1, float y1){
|
||||
//special case: uneven map mirrored at 45 degree angle (or someone might just want rotational symmetry)
|
||||
if((in.width != in.height && angle % 90 != 0) || rotate){
|
||||
p.x = in.width - p.x - 1;
|
||||
p.y = in.height - p.y - 1;
|
||||
if((width != height && angle % 90 != 0) || rotate){
|
||||
p.x = width - p.x - 1;
|
||||
p.y = height - p.y - 1;
|
||||
}else{
|
||||
float dx = x1 - x0;
|
||||
float dy = y1 - y0;
|
||||
|
|
|
|||
|
|
@ -29,8 +29,8 @@ public class NoiseFilter extends GenerateFilter{
|
|||
}
|
||||
|
||||
@Override
|
||||
public void apply(){
|
||||
float noise = noise(in.x, in.y, scl, 1f, octaves, falloff);
|
||||
public void apply(GenerateInput in){
|
||||
float noise = noise(in, scl, 1f, octaves, falloff);
|
||||
|
||||
if(noise > threshold && (target == Blocks.air || in.floor == target || in.block == target)){
|
||||
if(floor != Blocks.air) in.floor = floor;
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ public class OreFilter extends GenerateFilter{
|
|||
}
|
||||
|
||||
@Override
|
||||
public void apply(){
|
||||
float noise = noise(in.x, in.y, scl, 1f, octaves, falloff);
|
||||
public void apply(GenerateInput in){
|
||||
float noise = noise(in, scl, 1f, octaves, falloff);
|
||||
|
||||
if(noise > threshold && in.overlay != Blocks.spawn && (target == Blocks.air || in.floor == target || in.overlay == target) && in.floor.asFloor().hasSurface()){
|
||||
in.overlay = ore;
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public class OreMedianFilter extends GenerateFilter{
|
|||
}
|
||||
|
||||
@Override
|
||||
public void apply(){
|
||||
public void apply(GenerateInput in){
|
||||
if(in.overlay == Blocks.spawn) return;
|
||||
|
||||
int cx = (in.x / 2) * 2;
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ public class RiverNoiseFilter extends GenerateFilter{
|
|||
}
|
||||
|
||||
@Override
|
||||
public void apply(){
|
||||
public void apply(GenerateInput in){
|
||||
float noise = rnoise(in.x, in.y, (int)octaves, scl, falloff, 1f);
|
||||
|
||||
if(noise >= threshold){
|
||||
|
|
|
|||
|
|
@ -26,9 +26,9 @@ public class ScatterFilter extends GenerateFilter{
|
|||
}
|
||||
|
||||
@Override
|
||||
public void apply(){
|
||||
public void apply(GenerateInput in){
|
||||
|
||||
if(block != Blocks.air && (in.floor == flooronto || flooronto == Blocks.air) && in.block == Blocks.air && chance() <= chance){
|
||||
if(block != Blocks.air && (in.floor == flooronto || flooronto == Blocks.air) && in.block == Blocks.air && chance(in.x, in.y) <= chance){
|
||||
if(!block.isOverlay()){
|
||||
in.block = block;
|
||||
}else{
|
||||
|
|
@ -36,7 +36,7 @@ public class ScatterFilter extends GenerateFilter{
|
|||
}
|
||||
}
|
||||
|
||||
if(floor != Blocks.air && (in.floor == flooronto || flooronto == Blocks.air) && chance() <= chance){
|
||||
if(floor != Blocks.air && (in.floor == flooronto || flooronto == Blocks.air) && chance(in.x, in.y) <= chance){
|
||||
in.floor = floor;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@ public class TerrainFilter extends GenerateFilter{
|
|||
}
|
||||
|
||||
@Override
|
||||
public void apply(){
|
||||
float noise = noise(in.x, in.y, scl, magnitude, octaves, falloff) + Mathf.dst((float)in.x / in.width, (float)in.y / in.height, 0.5f, 0.5f) * circleScl;
|
||||
public void apply(GenerateInput in){
|
||||
float noise = noise(in, scl, magnitude, octaves, falloff) + Mathf.dst((float)in.x / in.width, (float)in.y / in.height, 0.5f, 0.5f) * circleScl;
|
||||
|
||||
if(floor != Blocks.air){
|
||||
in.floor = floor;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue