Asteroid background improvements

This commit is contained in:
Anuken
2021-09-16 12:40:35 -04:00
parent ad425f322c
commit c9fa7356c2
11 changed files with 107 additions and 15 deletions

View File

@@ -35,7 +35,7 @@ public class Blocks implements ContentList{
public static Block
//environment
air, spawn, cliff, deepwater, water, taintedWater, deepTaintedWater, tar, slag, stone, craters, charr, sand, darksand, dirt, mud, ice, snow, darksandTaintedWater, space,
air, spawn, cliff, deepwater, water, taintedWater, deepTaintedWater, tar, slag, stone, craters, charr, sand, darksand, dirt, mud, ice, snow, darksandTaintedWater, space, empty,
dacite, rhyolite, rhyoliteCrater, regolith, yellowStone, redIce,
redmat, bluemat,
stoneWall, dirtWall, sporeWall, iceWall, daciteWall, sporePine, snowPine, pine, shrubs, whiteTree, whiteTreeDead, sporeCluster,
@@ -231,6 +231,12 @@ public class Blocks implements ContentList{
placeableOn = false;
solid = true;
variants = 0;
canShadow = false;
}};
empty = new EmptyFloor("empty"){{
placeableOn = false;
solid = true;
}};
stone = new Floor("stone");

View File

@@ -1,6 +1,7 @@
package mindustry.core;
import arc.*;
import arc.assets.loaders.TextureLoader.*;
import arc.files.*;
import arc.graphics.*;
import arc.graphics.Texture.*;
@@ -310,8 +311,43 @@ public class Renderer implements ApplicationListener{
Events.fire(Trigger.postDraw);
}
private void drawBackground(){
//nothing to draw currently
protected void drawBackground(){
if(state.rules.backgroundTexture != null){
if(!assets.isLoaded(state.rules.backgroundTexture, Texture.class)){
var file = assets.getFileHandleResolver().resolve(state.rules.backgroundTexture);
//don't draw invalid/non-existent backgrounds.
if(!file.exists() || !file.extEquals("png")){
return;
}
var desc = assets.load(state.rules.backgroundTexture, Texture.class, new TextureParameter(){{
wrapU = TextureWrap.mirroredRepeat;
wrapV = TextureWrap.mirroredRepeat;
magFilter = TextureFilter.linear;
minFilter = TextureFilter.linear;
}});
assets.finishLoadingAsset(desc);
}
Texture tex = assets.get(state.rules.backgroundTexture, Texture.class);
Tmp.tr1.set(tex);
Tmp.tr1.u = 0f;
Tmp.tr1.v = 0f;
float ratio = camera.width / camera.height;
float size = state.rules.backgroundScl;
Tmp.tr1.u2 = size;
Tmp.tr1.v2 = size / ratio;
float sx = (camera.position.x) / state.rules.backgroundSpeed, sy = (camera.position.y) / state.rules.backgroundSpeed;
Tmp.tr1.scroll(sx + state.rules.backgroundOffsetX, -sy + state.rules.backgroundOffsetY);
Draw.rect(Tmp.tr1, camera.position.x, camera.position.y, camera.width, camera.height);
}
}
void updateLandParticles(){

View File

@@ -8,6 +8,7 @@ import arc.math.geom.Geometry.*;
import arc.struct.*;
import arc.util.*;
import arc.util.noise.*;
import mindustry.*;
import mindustry.content.*;
import mindustry.core.GameState.*;
import mindustry.ctype.*;
@@ -479,12 +480,14 @@ public class World{
//TODO optimize; this is very slow and called too often!
public float getDarkness(int x, int y){
int edgeBlend = 2;
float dark = 0;
int edgeDst = Math.min(x, Math.min(y, Math.min(Math.abs(x - (tiles.width - 1)), Math.abs(y - (tiles.height - 1)))));
if(edgeDst <= edgeBlend){
dark = Math.max((edgeBlend - edgeDst) * (4f / edgeBlend), dark);
if(Vars.state.rules.borderDarkness){
int edgeBlend = 2;
int edgeDst = Math.min(x, Math.min(y, Math.min(Math.abs(x - (tiles.width - 1)), Math.abs(y - (tiles.height - 1)))));
if(edgeDst <= edgeBlend){
dark = Math.max((edgeBlend - edgeDst) * (4f / edgeBlend), dark);
}
}
if(state.hasSector() && state.getSector().preset == null){

View File

@@ -44,6 +44,7 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
boolean spawnedByCore;
double flag;
transient float shadowAlpha = -1f;
transient Seq<Ability> abilities = new Seq<>(0);
transient float healTime;
private transient float resupplyTime = Mathf.random(10f);

View File

@@ -117,8 +117,18 @@ public class Rules{
public @Nullable String modeName;
/** Whether cores incinerate items when full, just like in the campaign. */
public boolean coreIncinerates = false;
/** If false, borders fade out into darkness. Only use with custom backgrounds!*/
public boolean borderDarkness = true;
/** special tags for additional info. */
public StringMap tags = new StringMap();
/** path to background texture with extension (e.g. "sprites/space.png")*/
public @Nullable String backgroundTexture;
/** background texture move speed scaling - bigger numbers mean slower movement */
public float backgroundSpeed = 27000f;
/** background texture scaling factor */
public float backgroundScl = 1f;
/** background UV offsets */
public float backgroundOffsetX = 0.1f, backgroundOffsetY = 0.1f;
/** Copies this ruleset exactly. Not efficient at all, do not use often. */
public Rules copy(){

View File

@@ -46,9 +46,9 @@ public class AsteroidGenerator extends BlankPlanetGenerator{
int sx = width/2, sy = height/2;
rand = new Rand(seed);
pass((x, y) -> {
floor = Blocks.space;
});
Floor background = Blocks.empty.asFloor();
tiles.eachTile(t -> t.setFloor(background));
//spawn asteroids
asteroid(sx, sy, rand.random(30, 50));
@@ -70,7 +70,7 @@ public class AsteroidGenerator extends BlankPlanetGenerator{
//random noise stone
pass((x, y) -> {
if(floor != Blocks.space){
if(floor != background){
if(Ridged.noise2d(seed, x, y, foct, fper, 1f / fscl) - Ridged.noise2d(seed, x, y, 1, 1f, 5f)/2.7f > fmag){
floor = Blocks.stone;
}
@@ -79,12 +79,12 @@ public class AsteroidGenerator extends BlankPlanetGenerator{
//walls at insides
pass((x, y) -> {
if(floor == Blocks.space || Ridged.noise2d(seed + 1, x, y, 4, 0.7f, 1f / 60f) > 0.45f || Mathf.within(x, y, sx, sy, 20 + Ridged.noise2d(seed, x, y, 3, 0.5f, 1f / 30f) * 6f)) return;
if(floor == background || Ridged.noise2d(seed + 1, x, y, 4, 0.7f, 1f / 60f) > 0.45f || Mathf.within(x, y, sx, sy, 20 + Ridged.noise2d(seed, x, y, 3, 0.5f, 1f / 30f) * 6f)) return;
int radius = 6;
for(int dx = x - radius; dx <= x + radius; dx++){
for(int dy = y - radius; dy <= y + radius; dy++){
if(Mathf.within(dx, dy, x, y, radius + 0.0001f) && tiles.in(dx, dy) && tiles.getn(dx, dy).floor() == Blocks.space){
if(Mathf.within(dx, dy, x, y, radius + 0.0001f) && tiles.in(dx, dy) && tiles.getn(dx, dy).floor() == background){
return;
}
}
@@ -132,6 +132,8 @@ public class AsteroidGenerator extends BlankPlanetGenerator{
Schematics.placeLaunchLoadout(sx, sy);
state.rules.backgroundTexture = "sprites/space.png";
state.rules.borderDarkness = false;
state.rules.environment = Env.space;
}

View File

@@ -698,8 +698,15 @@ public class UnitType extends UnlockableContent{
}
public void drawShadow(Unit unit){
Draw.color(Pal.shadow);
float e = Math.max(unit.elevation, visualElevation) * (1f - unit.drownTime);
float x = unit.x + shadowTX * e, y = unit.y + shadowTY * e;
Floor floor = world.floorWorld(x, y);
float dest = floor.canShadow ? 1f : 0f;
//yes, this updates state in draw()... which isn't a problem, because I don't want it to be obvious anyway
unit.shadowAlpha = unit.shadowAlpha < 0 ? dest : Mathf.approachDelta(unit.shadowAlpha, dest, 0.11f);
Draw.color(Pal.shadow, Pal.shadow.a * unit.shadowAlpha);
Draw.rect(shadowRegion, unit.x + shadowTX * e, unit.y + shadowTY * e, unit.rotation - 90);
Draw.color();
}

View File

@@ -14,6 +14,7 @@ public class AirBlock extends Floor{
useColor = false;
wall = this;
needsSurface = false;
canShadow = false;
}
@Override

View File

@@ -0,0 +1,24 @@
package mindustry.world.blocks.environment;
import mindustry.content.*;
import mindustry.world.*;
public class EmptyFloor extends Floor{
public EmptyFloor(String name){
super(name);
variants = 0;
canShadow = false;
}
@Override
public void drawBase(Tile tile){
//draws only edges, never itself
drawEdges(tile);
Floor floor = tile.overlay();
if(floor != Blocks.air && floor != this){
floor.drawBase(tile);
}
}
}

View File

@@ -59,6 +59,8 @@ public class Floor extends Block{
public Block wall = Blocks.air;
/** Decoration block. Usually a rock. May be air. */
public Block decoration = Blocks.air;
/** Whether units can draw shadows over this. */
public boolean canShadow = true;
/** Whether this overlay needs a surface to be on. False for floating blocks, like spawns. */
public boolean needsSurface = true;