Support for team-only lighting

This commit is contained in:
Anuken
2020-06-15 13:54:02 -04:00
parent b5660a50ca
commit 7001ad09cb
24 changed files with 90 additions and 75 deletions

View File

@@ -8,6 +8,7 @@ import arc.math.geom.*;
import arc.struct.*;
import arc.util.*;
import mindustry.entities.*;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.type.*;
@@ -526,7 +527,7 @@ public class Fx{
color();
Drawf.light(e.x, e.y, 20f * e.fslope(), Pal.lightFlame, 0.5f);
Drawf.light(Team.derelict, e.x, e.y, 20f * e.fslope(), Pal.lightFlame, 0.5f);
}),
fireSmoke = new Effect(35f, e -> {

View File

@@ -166,7 +166,7 @@ public abstract class BulletType extends Content{
}
public void drawLight(Bulletc b){
Drawf.light(b, lightRadius, lightColor, lightOpacity);
Drawf.light(b.team(), b, lightRadius, lightColor, lightOpacity);
}
public void init(Bulletc b){

View File

@@ -72,7 +72,7 @@ public class ContinuousLaserBulletType extends BulletType{
Tmp.v1.trns(b.rotation(), baseLen * 1.1f);
Drawf.light(b.x(), b.y(), b.x() + Tmp.v1.x, b.y() + Tmp.v1.y, 40, Color.orange, 0.7f);
Drawf.light(b.team(), b.x(), b.y(), b.x() + Tmp.v1.x, b.y() + Tmp.v1.y, 40, Color.orange, 0.7f);
Draw.reset();
}

View File

@@ -93,7 +93,7 @@ public class LaserBulletType extends BulletType{
Draw.reset();
Tmp.v1.trns(b.rotation(), baseLen * 1.1f);
Drawf.light(b.x(), b.y(), b.x() + Tmp.v1.x, b.y() + Tmp.v1.y, width * 1.4f * b.fout(), colors[0], 0.6f);
Drawf.light(b.team(), b.x(), b.y(), b.x() + Tmp.v1.x, b.y() + Tmp.v1.y, width * 1.4f * b.fout(), colors[0], 0.6f);
}
@Override

View File

@@ -94,7 +94,7 @@ abstract class MinerComp implements Itemsc, Posc, Teamc, Rotc, Drawc{
Draw.color(Color.lightGray, Color.white, 1f - flashScl + Mathf.absin(Time.time(), 0.5f, flashScl));
Drawf.laser(Core.atlas.find("minelaser"), Core.atlas.find("minelaser-end"), px, py, ex, ey, 0.75f);
Drawf.laser(team(), Core.atlas.find("minelaser"), Core.atlas.find("minelaser-end"), px, py, ex, ey, 0.75f);
//TODO hack?
if(isLocal()){

View File

@@ -8,13 +8,14 @@ import arc.util.*;
import mindustry.annotations.Annotations.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.type.*;
import mindustry.world.*;
import static mindustry.Vars.world;
import static mindustry.entities.Puddles.maxLiquid;
import static mindustry.Vars.*;
import static mindustry.entities.Puddles.*;
@EntityDef(value = {Puddlec.class}, pooled = true)
@Component
@@ -111,7 +112,7 @@ abstract class PuddleComp implements Posc, Puddlec, Drawc{
if(liquid.lightColor.a > 0.001f && f > 0){
Color color = liquid.lightColor;
float opacity = color.a * f;
Drawf.light(tile.drawx(), tile.drawy(), 30f * f, color, opacity * 0.8f);
Drawf.light(Team.derelict, tile.drawx(), tile.drawy(), 30f * f, color, opacity * 0.8f);
}
}

View File

@@ -758,7 +758,7 @@ abstract class TileComp implements Posc, Teamc, Healthc, Tilec, Timerc, QuadTree
float fract = 1f;
float opacity = color.a * fract;
if(opacity > 0.001f){
Drawf.light(x, y, block.size * 30f * fract, color, opacity);
Drawf.light(team, x, y, block.size * 30f * fract, color, opacity);
}
}
}

View File

@@ -16,7 +16,7 @@ import mindustry.world.*;
* Does not store game state, just configuration.
*/
public class Rules{
/** Whether ever team has infinite resources and instant build speed. */
/** Whether every team has infinite resources and instant build speed. */
public boolean infiniteResources;
/** Team-specific rules. */
public TeamRules teams = new TeamRules();
@@ -76,8 +76,11 @@ public class Rules{
public Seq<WeatherEntry> weather = new Seq<>(1);
/** Blocks that cannot be placed. */
public ObjectSet<Block> bannedBlocks = new ObjectSet<>();
/** Whether everything is dark. Enables lights. Experimental. */
/** Whether ambient lighting is enabled. */
public boolean lighting = false;
/** Whether enemy lighting is visible.
* If lighting is enabled and this is false, a fog-of-war effect is partially achieved. */
public boolean enemyLights = true;
/** Ambient light color, used when lighting is enabled. */
public Color ambientLight = new Color(0.01f, 0.01f, 0.04f, 0.99f);
/** Multiplier for solar panel power output.

View File

@@ -27,11 +27,12 @@ public class BlockRenderer implements Disposable{
public final FloorRenderer floor = new FloorRenderer();
private Seq<Tile> tileview = new Seq<>(false, initialRequests, Tile.class);
private Seq<Tile> lightview = new Seq<>(false, initialRequests, Tile.class);
private int lastCamX, lastCamY, lastRangeX, lastRangeY;
private float brokenFade = 0f;
private FrameBuffer shadows = new FrameBuffer();
private FrameBuffer fog = new FrameBuffer();
private FrameBuffer dark = new FrameBuffer();
private Seq<Tilec> outArray2 = new Seq<>();
private Seq<Tile> shadowEvents = new Seq<>();
private IntSet processedEntities = new IntSet();
@@ -61,11 +62,11 @@ public class BlockRenderer implements Disposable{
Draw.color();
shadows.end();
fog.getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
fog.resize(world.width(), world.height());
fog.begin();
dark.getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
dark.resize(world.width(), world.height());
dark.begin();
Core.graphics.clear(Color.white);
Draw.proj().setOrtho(0, 0, fog.getWidth(), fog.getHeight());
Draw.proj().setOrtho(0, 0, dark.getWidth(), dark.getHeight());
for(Tile tile : world.tiles){
float darkness = world.getDarkness(tile.x, tile.y);
@@ -78,7 +79,7 @@ public class BlockRenderer implements Disposable{
Draw.flush();
Draw.color();
fog.end();
dark.end();
});
Events.on(TileChangeEvent.class, event -> {
@@ -96,18 +97,8 @@ public class BlockRenderer implements Disposable{
}
public void drawDarkness(){
float ww = world.width() * tilesize, wh = world.height() * tilesize;
float x = camera.position.x + tilesize / 2f, y = camera.position.y + tilesize / 2f;
float u = (x - camera.width / 2f) / ww,
v = (y - camera.height / 2f) / wh,
u2 = (x + camera.width / 2f) / ww,
v2 = (y + camera.height / 2f) / wh;
Tmp.tr1.set(fog.getTexture());
Tmp.tr1.set(u, v2, u2, v);
Draw.shader(Shaders.fog);
Draw.rect(Tmp.tr1, camera.position.x, camera.position.y, camera.width, camera.height);
Draw.shader(Shaders.darkness);
Draw.fbo(dark, world.width(), world.height(), tilesize);
Draw.shader();
}
@@ -167,7 +158,7 @@ public class BlockRenderer implements Disposable{
Tmp.tr1.set(shadows.getTexture());
Tmp.tr1.set(u, v2, u2, v);
Draw.shader(Shaders.fog);
Draw.shader(Shaders.darkness);
Draw.rect(Tmp.tr1, camera.position.x, camera.position.y, camera.width, camera.height);
Draw.shader();
}
@@ -187,6 +178,7 @@ public class BlockRenderer implements Disposable{
}
tileview.clear();
lightview.clear();
processedEntities.clear();
int minx = Math.max(avgx - rangex - expandr, 0);
@@ -208,6 +200,11 @@ public class BlockRenderer implements Disposable{
if(tile.entity != null) processedEntities.add(tile.entity.id());
}
//lights are drawn even in the expanded range
if(tile.entity != null){
lightview.add(tile);
}
if(tile.entity != null && tile.entity.power() != null && tile.entity.power().links.size > 0){
for(Tilec other : tile.entity.getPowerConnections(outArray2)){
if(other.block() instanceof PowerNode){ //TODO need a generic way to render connections!
@@ -228,6 +225,7 @@ public class BlockRenderer implements Disposable{
public void drawBlocks(){
drawDestroyed();
//draw most tile stuff
for(int i = 0; i < tileview.size; i++){
Tile tile = tileview.items[i];
Block block = tile.block();
@@ -250,8 +248,6 @@ public class BlockRenderer implements Disposable{
Draw.z(Layer.block);
}
entity.drawLight();
if(displayStatus && block.consumes.any()){
entity.drawStatus();
}
@@ -259,13 +255,23 @@ public class BlockRenderer implements Disposable{
Draw.reset();
}
}
//draw lights
for(int i = 0; i < lightview.size; i++){
Tile tile = lightview.items[i];
Tilec entity = tile.entity;
if(entity != null){
entity.drawLight();
}
}
}
@Override
public void dispose(){
shadows.dispose();
fog.dispose();
shadows = fog = null;
dark.dispose();
shadows = dark = null;
floor.dispose();
}
}

View File

@@ -8,6 +8,7 @@ import arc.math.geom.*;
import arc.util.*;
import mindustry.*;
import mindustry.ctype.*;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.ui.*;
import mindustry.world.*;
@@ -48,24 +49,28 @@ public class Drawf{
return z;
}
public static void light(float x, float y, float radius, Color color, float opacity){
renderer.lights.add(x, y, radius, color, opacity);
public static void light(Team team, float x, float y, float radius, Color color, float opacity){
if(allowLight(team)) renderer.lights.add(x, y, radius, color, opacity);
}
public static void light(Position pos, float radius, Color color, float opacity){
light(pos.getX(), pos.getY(), radius, color, opacity);
public static void light(Team team, Position pos, float radius, Color color, float opacity){
light(team, pos.getX(), pos.getY(), radius, color, opacity);
}
public static void light(float x, float y, TextureRegion region, Color color, float opacity){
renderer.lights.add(x, y, region, color, opacity);
public static void light(Team team, float x, float y, TextureRegion region, Color color, float opacity){
if(allowLight(team)) renderer.lights.add(x, y, region, color, opacity);
}
public static void light(float x, float y, float x2, float y2){
renderer.lights.line(x, y, x2, y2, 30, Color.orange, 0.3f);
public static void light(Team team, float x, float y, float x2, float y2){
if(allowLight(team)) renderer.lights.line(x, y, x2, y2, 30, Color.orange, 0.3f);
}
public static void light(float x, float y, float x2, float y2, float stroke, Color tint, float alpha){
renderer.lights.line(x, y, x2, y2, stroke, tint, alpha);
public static void light(Team team, float x, float y, float x2, float y2, float stroke, Color tint, float alpha){
if(allowLight(team)) renderer.lights.line(x, y, x2, y2, stroke, tint, alpha);
}
private static boolean allowLight(Team team){
return team == Team.derelict || team == Vars.player.team() || state.rules.enemyLights;
}
public static void selected(Tilec tile, Color color){
@@ -155,15 +160,15 @@ public class Drawf{
Draw.color();
}
public static void laser(TextureRegion line, TextureRegion edge, float x, float y, float x2, float y2, float scale){
laser(line, edge, x, y, x2, y2, Mathf.angle(x2 - x, y2 - y), scale);
public static void laser(Team team, TextureRegion line, TextureRegion edge, float x, float y, float x2, float y2, float scale){
laser(team, line, edge, x, y, x2, y2, Mathf.angle(x2 - x, y2 - y), scale);
}
public static void laser(TextureRegion line, TextureRegion edge, float x, float y, float x2, float y2){
laser(line, edge, x, y, x2, y2, Mathf.angle(x2 - x, y2 - y), 1f);
public static void laser(Team team, TextureRegion line, TextureRegion edge, float x, float y, float x2, float y2){
laser(team, line, edge, x, y, x2, y2, Mathf.angle(x2 - x, y2 - y), 1f);
}
public static void laser(TextureRegion line, TextureRegion edge, float x, float y, float x2, float y2, float rotation, float scale){
public static void laser(Team team, TextureRegion line, TextureRegion edge, float x, float y, float x2, float y2, float rotation, float scale){
Tmp.v1.trns(rotation, 8f * scale * Draw.scl);
Draw.rect(edge, x, y, edge.getWidth() * scale * Draw.scl, edge.getHeight() * scale * Draw.scl, rotation + 180);
@@ -175,7 +180,7 @@ public class Drawf{
Lines.precise(false);
Lines.stroke(1f);
Drawf.light(x, y, x2, y2);
light(team, x, y, x2, y2);
}
public static void tri(float x, float y, float width, float length, float rotation){

View File

@@ -18,7 +18,7 @@ public class Shaders{
public static BlockBuild blockbuild;
public static @Nullable ShieldShader shield;
public static UnitBuild build;
public static FogShader fog;
public static DarknessShader darkness;
public static LightShader light;
public static SurfaceShader water, tar, slag;
public static PlanetShader planet;
@@ -38,7 +38,7 @@ public class Shaders{
t.printStackTrace();
}
build = new UnitBuild();
fog = new FogShader();
darkness = new DarknessShader();
light = new LightShader();
water = new SurfaceShader("water");
tar = new SurfaceShader("tar");
@@ -131,9 +131,9 @@ public class Shaders{
}
public static class FogShader extends LoadShader{
public FogShader(){
super("fog", "default");
public static class DarknessShader extends LoadShader{
public DarknessShader(){
super("darkness", "default");
}
}

View File

@@ -342,7 +342,7 @@ public class UnitType extends UnlockableContent{
public void drawLight(Unitc unit){
if(lightRadius > 0){
Drawf.light(unit, lightRadius, lightColor, lightOpacity);
Drawf.light(unit.team(), unit, lightRadius, lightColor, lightOpacity);
}
}

View File

@@ -110,7 +110,7 @@ public class MendProjector extends Block{
@Override
public void drawLight(){
Drawf.light(x, y, 50f * efficiency(), baseColor, 0.7f * efficiency());
Drawf.light(team, x, y, 50f * efficiency(), baseColor, 0.7f * efficiency());
}
@Override

View File

@@ -67,7 +67,7 @@ public class OverdriveProjector extends Block{
@Override
public void drawLight(){
Drawf.light(x, y, 50f * efficiency(), baseColor, 0.7f * efficiency());
Drawf.light(team, x, y, 50f * efficiency(), baseColor, 0.7f * efficiency());
}
@Override

View File

@@ -115,8 +115,7 @@ public class ImpactReactor extends PowerGenerator{
@Override
public void drawLight(){
float fract = tile.<FusionReactorEntity>ent().warmup;
Drawf.light(x, y, (110f + Mathf.absin(5, 5f)) * fract, Tmp.c1.set(plasma2).lerp(plasma1, Mathf.absin(7f, 0.2f)), 0.8f * fract);
Drawf.light(team, x, y, (110f + Mathf.absin(5, 5f)) * warmup, Tmp.c1.set(plasma2).lerp(plasma1, Mathf.absin(7f, 0.2f)), 0.8f * warmup);
}
@Override

View File

@@ -85,9 +85,7 @@ public class ItemLiquidGenerator extends PowerGenerator{
}
public class ItemLiquidGeneratorEntity extends GeneratorEntity{
public float explosiveness;
public float heat;
public float totalTime;
public float explosiveness, heat, totalTime;
@Override
public boolean productionValid(){
@@ -100,6 +98,8 @@ public class ItemLiquidGenerator extends PowerGenerator{
//Power amount is delta'd by PowerGraph class already.
float calculationDelta = delta();
heat = Mathf.lerpDelta(heat, generateTime >= 0.001f ? 1f : 0f, 0.05f);
if(!consValid()){
productionEfficiency = 0.0f;
return;
@@ -113,7 +113,6 @@ public class ItemLiquidGenerator extends PowerGenerator{
}
}
heat = Mathf.lerpDelta(heat, generateTime >= 0.001f ? 1f : 0f, 0.05f);
totalTime += heat;
//liquid takes priority over solids
@@ -175,7 +174,7 @@ public class ItemLiquidGenerator extends PowerGenerator{
@Override
public void drawLight(){
Drawf.light(x, y, (60f + Mathf.absin(10f, 5f)) * productionEfficiency * size, Color.orange, 0.5f);
Drawf.light(team, x, y, (60f + Mathf.absin(10f, 5f)) * size, Color.orange, 0.5f * heat);
}
}
}

View File

@@ -50,7 +50,7 @@ public class LightBlock extends Block{
@Override
public void drawLight(){
Drawf.light(x, y, radius, Tmp.c1.set(color), brightness * efficiency());
Drawf.light(team, x, y, radius, Tmp.c1.set(color), brightness * efficiency());
}
@Override

View File

@@ -143,7 +143,7 @@ public class NuclearReactor extends PowerGenerator{
@Override
public void drawLight(){
float fract = productionEfficiency;
Drawf.light(x, y, (90f + Mathf.absin(5, 5f)) * fract, Tmp.c1.set(lightColor).lerp(Color.scarlet, heat), 0.6f * fract);
Drawf.light(team, x, y, (90f + Mathf.absin(5, 5f)) * fract, Tmp.c1.set(lightColor).lerp(Color.scarlet, heat), 0.6f * fract);
}
@Override

View File

@@ -11,6 +11,7 @@ import arc.util.ArcAnnotate.*;
import arc.util.*;
import mindustry.annotations.Annotations.*;
import mindustry.entities.units.*;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.ui.*;
@@ -131,7 +132,7 @@ public class PowerNode extends PowerBlock{
Draw.reset();
}
protected void drawLaser(float x1, float y1, float x2, float y2, float satisfaction, int size1, int size2){
protected void drawLaser(Team team, float x1, float y1, float x2, float y2, float satisfaction, int size1, int size2){
float opacity = Core.settings.getInt("lasersopacity") / 100f;
if(Mathf.zero(opacity)) return;
@@ -148,7 +149,7 @@ public class PowerNode extends PowerBlock{
Draw.color(Color.white, Pal.powerLight, fract * 0.86f + Mathf.absin(3f, 0.1f));
Draw.alpha(opacity);
Drawf.laser(laser, laserEnd, x1, y1, x2, y2, 0.25f);
Drawf.laser(team, laser, laserEnd, x1, y1, x2, y2, 0.25f);
Draw.color();
}
@@ -213,7 +214,7 @@ public class PowerNode extends PowerBlock{
if(otherReq == null || otherReq.block == null) return;
drawLaser(req.drawx(), req.drawy(), otherReq.drawx(), otherReq.drawy(), 1f, size, otherReq.block.size);
drawLaser(player.team(), req.drawx(), req.drawy(), otherReq.drawx(), otherReq.drawy(), 1f, size, otherReq.block.size);
}
}
}
@@ -386,7 +387,7 @@ public class PowerNode extends PowerBlock{
}
protected void drawLaserTo(Tilec target){
drawLaser(x, y, target.x(), target.y(), power.graph.getSatisfaction(), size, target.block().size);
drawLaser(team, x, y, target.x(), target.y(), power.graph.getSatisfaction(), size, target.block().size);
}
@Override

View File

@@ -45,7 +45,7 @@ public class ThermalGenerator extends PowerGenerator{
@Override
public void drawLight(){
Drawf.light(x, y, (40f + Mathf.absin(10f, 5f)) * productionEfficiency * size, Color.scarlet, 0.4f);
Drawf.light(team, x, y, (40f + Mathf.absin(10f, 5f)) * productionEfficiency * size, Color.scarlet, 0.4f);
}
@Override

View File

@@ -41,7 +41,7 @@ public class GenericSmelter extends GenericCrafter{
@Override
public void drawLight(){
Drawf.light(x, y, (60f + Mathf.absin(10f, 5f)) * warmup * size, flameColor, 0.65f);
Drawf.light(team, x, y, (60f + Mathf.absin(10f, 5f)) * warmup * size, flameColor, 0.65f);
}
}
}

View File

@@ -103,7 +103,7 @@ public class CoreBlock extends StorageBlock{
@Override
public void drawLight(){
Drawf.light(x, y, 30f * size, Pal.accent, 0.5f + Mathf.absin(20f, 0.1f));
Drawf.light(team, x, y, 30f * size, Pal.accent, 0.5f + Mathf.absin(20f, 0.1f));
}
@Override

View File

@@ -76,7 +76,7 @@ public class RepairPoint extends Block{
float len = 5f;
Draw.color(Color.valueOf("e8ffd7"));
Drawf.laser(laser, laserEnd,
Drawf.laser(team, laser, laserEnd,
x + Angles.trnsx(ang, len), y + Angles.trnsy(ang, len),
target.x(), target.y(), strength);
Draw.color();