Better fog / Research cost tweaks

This commit is contained in:
Anuken
2022-02-19 16:24:22 -05:00
parent c5ec8ff3ce
commit 895fa784cf
17 changed files with 158 additions and 117 deletions

View File

@@ -12,15 +12,17 @@ import mindustry.game.EventType.*;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.world.*;
import mindustry.world.meta.*;
import static mindustry.Vars.*;
/** Highly experimental fog-of-war renderer. */
public class FogRenderer{
public static final Color
staticColor = new Color(0f, 0f, 0f, 1f),
dynamicColor = new Color(0f, 0f, 0f, 0.5f);
private FrameBuffer staticFog = new FrameBuffer(), dynamicFog = new FrameBuffer();
private LongSeq events = new LongSeq();
private LongSeq dynamics = new LongSeq();
private boolean dynamicUpdate = false;
private Rect rect = new Rect();
private @Nullable Team lastTeam;
@@ -35,12 +37,6 @@ public class FogRenderer{
events.add(event);
}
public void flushDynamic(LongSeq seq){
dynamics.clear();
dynamics.addAll(seq);
dynamicUpdate = true;
}
public Texture getStaticTexture(){
return staticFog.getTexture();
}
@@ -54,25 +50,33 @@ public class FogRenderer{
if(fogControl.getDiscovered(player.team()) == null) return;
//resize if world size changes
boolean
clearStatic = staticFog.resizeCheck(world.width(), world.height()),
clearDynamic = dynamicFog.resizeCheck(world.width(), world.height());
boolean clearStatic = staticFog.resizeCheck(world.width(), world.height());
dynamicFog.resize(world.width(), world.height());
if(player.team() != lastTeam){
copyFromCpu();
lastTeam = player.team();
clearStatic = false;
dynamicUpdate = true;
}
if(clearDynamic || dynamicUpdate){
dynamicUpdate = false;
//draw dynamic fog every frame
{
Draw.proj(0, 0, staticFog.getWidth(), staticFog.getHeight());
Core.camera.bounds(Tmp.r1);
Draw.proj(0, 0, staticFog.getWidth() * tilesize, staticFog.getHeight() * tilesize);
dynamicFog.begin(Color.black);
ScissorStack.push(rect.set(1, 1, staticFog.getWidth() - 2, staticFog.getHeight() - 2));
//TODO render all (clipped) view circles
Team team = player.team();
for(var build : indexer.getFlagged(team, BlockFlag.hasFogRadius)){
poly(Tmp.r1, build.x, build.y, build.block.fogRadius * tilesize);
}
for(var unit : team.data().units){
poly(Tmp.r1, unit.x, unit.y, unit.type.fogRadius * tilesize);
}
dynamicFog.end();
ScissorStack.pop();
@@ -95,18 +99,10 @@ public class FogRenderer{
Draw.color(Color.white);
//process new fog events
//process new static fog events
for(int i = 0; i < events.size; i++){
long e = events.items[i];
Tile tile = world.tile(FogEvent.x(e), FogEvent.y(e));
float o = 0f;
//visual offset for uneven blocks; this is not reflected on the CPU, but it doesn't really matter
if(tile != null && tile.block().size % 2 == 0 && tile.isCenter()){
o = 0.5f;
}
Fill.poly(FogEvent.x(e) + 0.5f + o, FogEvent.y(e) + 0.5f + o, 20, FogEvent.radius(e) + 0.3f);
renderEvent(events.items[i]);
}
events.clear();
staticFog.end();
@@ -115,12 +111,32 @@ public class FogRenderer{
}
staticFog.getTexture().setFilter(TextureFilter.linear);
dynamicFog.getTexture().setFilter(TextureFilter.linear);
Draw.shader(Shaders.fog);
Draw.color(dynamicColor);
Draw.fbo(dynamicFog.getTexture(), world.width(), world.height(), tilesize);
Draw.color(staticColor);
Draw.fbo(staticFog.getTexture(), world.width(), world.height(), tilesize);
Draw.shader();
}
void poly(Rect check, float x, float y, float rad){
if(check.overlaps(x - rad / 2f, y - rad / 2f, rad * 2f, rad * 2f)){
Fill.poly(x, y, 20, rad);
}
}
void renderEvent(long e){
Tile tile = world.tile(FogEvent.x(e), FogEvent.y(e));
float o = 0f;
//visual offset for uneven blocks; this is not reflected on the CPU, but it doesn't really matter
if(tile != null && tile.block().size % 2 == 0 && tile.isCenter()){
o = 0.5f;
}
Fill.poly(FogEvent.x(e) + 0.5f + o, FogEvent.y(e) + 0.5f + o, 20, FogEvent.radius(e) + 0.3f);
}
public void copyFromCpu(){
staticFog.resize(world.width(), world.height());
staticFog.begin(Color.black);

View File

@@ -100,7 +100,7 @@ public class MinimapRenderer{
updateUnitArray();
}else{
units.clear();
Groups.unit.each(units::add);
Groups.unit.copy(units);
}
float sz = baseSize * zoom;
@@ -112,10 +112,12 @@ public class MinimapRenderer{
rect.set((dx - sz) * tilesize, (dy - sz) * tilesize, sz * 2 * tilesize, sz * 2 * tilesize);
for(Unit unit : units){
if(unit.inFogTo(player.team())) continue;
float rx = !withLabels ? (unit.x - rect.x) / rect.width * w : unit.x / (world.width() * tilesize) * w;
float ry = !withLabels ? (unit.y - rect.y) / rect.width * h : unit.y / (world.height() * tilesize) * h;
Draw.mixcol(unit.team().color, 1f);
Draw.mixcol(unit.team.color, 1f);
float scale = Scl.scl(1f) / 2f * scaling * 32f;
var region = unit.icon();
Draw.rect(region, x + rx, y + ry, scale, scale * (float)region.height / region.width, unit.rotation() - 90);
@@ -144,11 +146,23 @@ public class MinimapRenderer{
zoom = z;
}
Draw.shader(Shaders.fog);
renderer.fog.getStaticTexture().setFilter(TextureFilter.nearest);
Texture staticTex = renderer.fog.getStaticTexture(), dynamicTex = renderer.fog.getDynamicTexture();
//crisp pixels
Tmp.tr1.set(renderer.fog.getStaticTexture());
staticTex.setFilter(TextureFilter.nearest);
dynamicTex.setFilter(TextureFilter.nearest);
Tmp.tr1.set(dynamicTex);
Tmp.tr1.set(region.u, 1f - region.v, region.u2, 1f - region.v2);
Draw.color(FogRenderer.dynamicColor);
Draw.rect(Tmp.tr1, x + w/2f, y + h/2f, w, h);
Tmp.tr1.texture = staticTex;
Draw.color(FogRenderer.staticColor);
Draw.rect(Tmp.tr1, x + w/2f, y + h/2f, w, h);
Draw.color();
Draw.shader();
}