Skip to content

Commit

Permalink
Welcome to the satellite!
Browse files Browse the repository at this point in the history
  • Loading branch information
GlennFolker committed Apr 4, 2024
1 parent 05f1cfa commit a128b41
Show file tree
Hide file tree
Showing 11 changed files with 296 additions and 63 deletions.
Binary file modified assets/maps/confictura-test.msav
Binary file not shown.
Binary file added assets/sprites-raw/effects/monolith-brand.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion proc/src/confictura/proc/ConficturaProc.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

public class ConficturaProc{
protected static final TaskQueue runs = new TaskQueue();
protected static final Proc[] procs = {new BlockProc()};
protected static final Proc[] procs = {new BlockProc(), new EffectProc()};

public static GenAtlas atlas;

Expand Down
44 changes: 3 additions & 41 deletions proc/src/confictura/proc/list/BlockProc.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import arc.func.*;
import arc.graphics.*;
import arc.math.*;
import arc.util.*;
import arc.util.serialization.*;
import arc.util.serialization.Jval.*;
import confictura.graphics.g2d.*;
import confictura.proc.*;
import confictura.proc.GenAtlas.*;
import confictura.world.blocks.*;
Expand Down Expand Up @@ -62,53 +62,15 @@ public void init(Cons<Runnable> async){
}

if(block.customShadow && (block.variants == 0 ? !block.customShadowRegion.found() : any(block.variantRegions, t -> !t.found()))){
// Gaussian blur kernel half-width and -height.
int blurWidth = 64, blurHeight = 64;
// Gaussian filter standard deviation.
float deviation = 16f;

var blur = new float[(2 * blurWidth + 1) * (2 * blurHeight + 1)];
float s = 2f * deviation * deviation, nor = 0f;

for(int tx = -blurWidth; tx <= blurWidth; tx++){
for(int ty = -blurHeight; ty <= blurHeight; ty++){
float r = Mathf.sqrt(tx * tx + ty * ty);
float res = Mathf.pow(Mathf.E, -(r * r) / s) / (Mathf.pi * s);

blur[tx + blurWidth + (ty + blurHeight) * (2 * blurWidth + 1)] = res;
nor += res;
}
}

for(int i = 0; i < blur.length; i++) blur[i] /= nor;

int index = 0;
for(var variant : block.variants == 0 ? iter(block.fullIcon) : iter(block.variantRegions)){
var reg = atlas.conv(variant);
var pix = reg.pixmap();

var ref = new Pixmap(pix.width + blurWidth * 2, pix.height + blurHeight * 2);
ref.draw(pix, blurWidth, blurHeight);
Pixmaps.bleed(ref, Integer.MAX_VALUE);

var shadow = new Pixmap(ref.width, ref.height);
ref.each((x, y) -> {
float a = 0f;
for(int tx = -blurWidth; tx <= blurWidth; tx++){
for(int ty = -blurHeight; ty <= blurHeight; ty++){
float factor = blur[tx + blurWidth + (ty + blurHeight) * (2 * blurWidth + 1)];
a += ((ref.get(x + tx, y + ty) & 0xff) / 255f) * factor;
}
}

shadow.setRaw(x, y, 0xffffff00 | (int)(a * 255f));
});

var name = block.name.substring("confictura-".length()) + "-shadow";
if(block.variants != 0) name += ++index;

var shadow = CPixmaps.gaussianBlur(reg.pixmap(), 32, 32, 8f);
shadow.each((x, y) -> shadow.setRaw(x, y, 0xffffff00 | shadow.getRaw(x, y) & 0xff));
new GenRegion(name, reg.file.sibling(name + ".png"), shadow).save(true);
ref.dispose();
}
}

Expand Down
25 changes: 25 additions & 0 deletions proc/src/confictura/proc/list/EffectProc.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package confictura.proc.list;

import arc.func.*;
import confictura.graphics.g2d.*;
import confictura.proc.*;
import confictura.proc.GenAtlas.*;

import static confictura.proc.ConficturaProc.*;

public class EffectProc implements Proc{
@Override
public void init(Cons<Runnable> async){
async.get(() -> {
var brand = atlas.find("confictura-monolith-brand");
new GenRegion(
"confictura-monolith-brand-glow",
brand.file.sibling("monolith-brand-glow.png"),
CPixmaps.gaussianBlur(brand.pixmap(), 16, 16, 4f)
).save(true);
});
}

@Override
public void finish(){}
}
4 changes: 4 additions & 0 deletions src/confictura/ConficturaMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ public void init(){

cinematicDialog = new CinematicEditorDialog();
scriptDialog = new ScriptDialog();

//TODO Ideally I should make my own duplicate `Lines` class that draws things with more detail.
// However, until I can get rid of my laziness, I'll keep this code.
Lines.setCirclePrecision(2.4f);
}
}

Expand Down
122 changes: 112 additions & 10 deletions src/confictura/content/CFx.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,50 @@
package confictura.content;

import arc.graphics.*;
import arc.graphics.g2d.*;
import arc.math.*;
import arc.math.geom.*;
import arc.util.pooling.*;
import confictura.graphics.*;
import mindustry.content.*;
import mindustry.entities.*;
import mindustry.gen.*;
import mindustry.graphics.*;

import static arc.Core.*;
import static arc.graphics.g2d.Draw.*;
import static arc.graphics.g2d.Lines.*;
import static arc.math.Angles.*;
import static arc.math.Interp.*;
import static confictura.graphics.CPal.*;
import static confictura.util.StructUtils.*;
import static mindustry.Vars.*;

/**
* Defines the {@linkplain Effect visual effects} this mod offers.
* @author GlennFolker
*/
public final class CFx{
private static final Rand rand = new Rand();
private static final Vec2 v1 = new Vec2();
private static final Vec2 v1 = new Vec2(), v2 = new Vec2();
private static final Color c1 = new Color();

public static final Effect

eneraphyteSteam = new Effect(120f, e -> {
color(monolithLighter, monolithMid, monolithDark, e.fin(smoother));
alpha(e.fslope() * 0.7f);

float len = 1f + e.finpow() * 5f;
rand.setSeed(e.id);

int amount = rand.random(1, 3);
for(int i = 0; i < amount; i++){
v1.trns(rand.random(360f), rand.random(len)).add(e.x, e.y);
Fill.circle(v1.x, v1.y, rand.random(0.8f, 2f) + smooth.apply(e.fslope()) * 0.9f);
}
}),

erodedEneraphyteSteam = new Effect(100f, e -> {
color(monolithLight, monolithDark, monolithDarker, e.fin(smoother));
alpha(e.fslope() * 0.5f);
Expand All @@ -33,18 +59,94 @@ public final class CFx{
}
}),

eneraphyteSteam = new Effect(120f, e -> {
color(monolithLighter, monolithMid, monolithDark, e.fin(smoother));
alpha(e.fslope() * 0.7f);
satelliteEntrySignal = new Effect(60f, e -> {
e.scaled(48f, s -> {
z(Layer.effect);
color(monolithLighter, monolithMid, monolithDarker, s.fin() * 1.5f);
stroke(s.fout());

float len = 1f + e.finpow() * 5f;
rand.setSeed(e.id);
Lines.circle(e.x, e.y, s.fin(pow3Out) * 24f);
});

int amount = rand.random(1, 3);
for(int i = 0; i < amount; i++){
v1.trns(rand.random(360f), rand.random(len)).add(e.x, e.y);
Fill.circle(v1.x, v1.y, rand.random(0.8f, 2f) + smooth.apply(e.fslope()) * 0.9f);
z(Layer.blockAdditive);
blend(Blending.additive);
color(Color.white, monolithMid, monolithDarker, e.fin(pow5In));
alpha(e.fout(pow2Out));

TextureRegion region = atlas.find("confictura-monolith-brand"), glow = atlas.find("confictura-monolith-brand-glow");

float
grow = 8f, prog = e.fin(pow3Out) * grow,
regSize = region.width * region.scl() * xscl * 0.75f, glowSize = glow.width * region.scl() * xscl * 0.75f,
aspect = (float)glow.width / region.width;

regSize = regSize - grow + prog;
glowSize = glowSize + (-grow + prog) * aspect;

Draw.rect(region, e.x, e.y, regSize, regSize);
Draw.rect(glow, e.x, e.y, glowSize, glowSize);

blend();
}).layer(Layer.blockAdditive),

satelliteEntryTrails = new ExtEffect(() -> {
class State extends EffectState{
@Override
public void remove(){
if(data instanceof Trail[] trails) each(trails, trail -> Fx.trailFade.at(x, y, trail.width(), monolithLighter, trail));
super.remove();
}
} return Pools.obtain(State.class, State::new);
}, () -> new Trail[]{
CTrails.singlePhantasmal(72),
CTrails.singlePhantasmal(72)
}, /* Lifetime is set later by `SatelliteEntry`, don't worry. */ 0f, e -> {
if(!(e.data instanceof Trail[] trails)) return;

for(int i = 0; i < trails.length; i++){
v1.trns(e.fin(pow5In) * 1.5f * 360f + 90f * Mathf.signs[i], e.fout(pow10Out) * 32f).add(e.x, e.y);

var trail = trails[i];
if(!state.isPaused()) trail.update(v1.x, v1.y, 1f);

trail.drawCap(monolithLighter, 1f);
trail.draw(monolithLighter, 1f);
}
}),

satelliteEntryExhaust = new Effect(60f, e -> {
e.scaled(24f, s -> {
z(Layer.blockAdditive);
color(monolithLighter, monolithMid, monolithDarker, s.fin(pow2Out));
alpha(s.fout(pow2Out));

blend(Blending.additive);

float size = s.fout(pow2In) * 6f;
Draw.rect("hcircle", e.x, e.y, size, size, e.rotation - 180f);

v1.trns(e.rotation + 90f, size / 2f);
v2.trns(e.rotation, 32f);

float c1 = getColor().toFloatBits(), c2 = CFx.c1.set(getColor()).a(0f).toFloatBits();
Fill.quad(
e.x - v1.x, e.y - v1.y, c1,
e.x + v2.x - v1.x, e.y + v2.y - v1.y, c2,
e.x + v2.x + v1.x, e.y + v2.y + v1.y, c2,
e.x + v1.x, e.y + v1.y, c1
);

blend();
reset();
});

z(Layer.effect);

color(monolithLighter, monolithMid, monolithDarker, e.fin());
stroke(1.5f * e.fout());
randLenVectors(e.id, 6, 64f, e.rotation, 30f, (x, y) ->
lineAngle(e.x + x * e.fin(pow3Out), e.y + y * e.fin(pow3Out), Mathf.angle(x, y), e.fout(pow2Out) * 8f)
);
});

private CFx(){
Expand Down
59 changes: 59 additions & 0 deletions src/confictura/graphics/ExtEffect.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package confictura.graphics;

import arc.func.*;
import arc.graphics.*;
import arc.util.*;
import mindustry.entities.*;
import mindustry.gen.*;

public class ExtEffect extends Effect{
public Prov<? extends EffectState> constructor;
public @Nullable Prov<Object> data;

public ExtEffect(float lifetime, Cons<EffectContainer> e){
this(EffectState::create, lifetime, e);
}

public ExtEffect(float lifetime, float clip, Cons<EffectContainer> e){
this(EffectState::create, lifetime, clip, e);
}

public ExtEffect(Prov<? extends EffectState> constructor, float lifetime, Cons<EffectContainer> e){
this(constructor, null, lifetime, e);
}

public ExtEffect(Prov<? extends EffectState> constructor, float lifetime, float clip, Cons<EffectContainer> e){
this(constructor, null, lifetime, clip, e);
}

public ExtEffect(Prov<? extends EffectState> constructor, @Nullable Prov<Object> data, float lifetime, Cons<EffectContainer> e){
this(constructor, data, lifetime, 50f, e);
}

public ExtEffect(Prov<? extends EffectState> constructor, @Nullable Prov<Object> data, float lifetime, float clip, Cons<EffectContainer> e){
super(lifetime, clip, e);
this.constructor = constructor;
this.data = data;
}

@Override
protected void add(float x, float y, float rotation, Color color, Object data){
inst(x, y, rotation, color, data).add();
}

protected EffectState inst(float x, float y, float rotation, Color color, Object data){
var e = constructor.get();
e.effect = this;
e.rotation = baseRotation + rotation;
e.data = this.data != null ? this.data.get() : data;
e.lifetime = lifetime;
e.set(x, y);
e.color.set(color);
if(followParent && data instanceof Posc p){
e.parent = p;
e.rotWithParent = rotWithParent;
}

return e;
}
}
56 changes: 56 additions & 0 deletions src/confictura/graphics/g2d/CPixmaps.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package confictura.graphics.g2d;

import arc.graphics.*;
import arc.math.*;

import static arc.graphics.Pixmaps.*;

public final class CPixmaps{
private CPixmaps(){
throw new AssertionError();
}

public static Pixmap gaussianBlur(Pixmap in, int blurWidth, int blurHeight, float deviation){
var blur = new float[(2 * blurWidth + 1) * (2 * blurHeight + 1)];
float s = 2f * deviation * deviation, nor = 0f;

for(int tx = -blurWidth; tx <= blurWidth; tx++){
for(int ty = -blurHeight; ty <= blurHeight; ty++){
float r = Mathf.sqrt(tx * tx + ty * ty);
float res = Mathf.pow(Mathf.E, -(r * r) / s) / (Mathf.pi * s);

blur[tx + blurWidth + (ty + blurHeight) * (2 * blurWidth + 1)] = res;
nor += res;
}
}

for(int i = 0; i < blur.length; i++) blur[i] /= nor;

var ref = new Pixmap(in.width + blurWidth * 2, in.height + blurHeight * 2);
ref.draw(in, blurWidth, blurHeight);
bleed(ref, Integer.MAX_VALUE);

Color sum = new Color(), col = new Color();

var out = new Pixmap(ref.width, ref.height);
ref.each((x, y) -> {
sum.set(0f, 0f, 0f, 0f);
for(int tx = -blurWidth; tx <= blurWidth; tx++){
for(int ty = -blurHeight; ty <= blurHeight; ty++){
float factor = blur[tx + blurWidth + (ty + blurHeight) * (2 * blurWidth + 1)];
col.set(ref.get(x + tx, y + ty));

sum.r += col.r * factor;
sum.g += col.g * factor;
sum.b += col.b * factor;
sum.a += col.a * factor;
}
}

out.setRaw(x, y, sum.rgba());
});

ref.dispose();
return out;
}
}
2 changes: 1 addition & 1 deletion src/confictura/ui/dialogs/CinematicEditorDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public CinematicEditorDialog(){
up = Tex.buttonEdge3;
down = Tex.buttonEdgeDown3;
over = Tex.buttonEdgeOver3;
}}, this::show).width(320f).visible(cinematicEditor::isAttached));
}}, this::show).width(320f).visible(() -> ui.hudfrag.shown && cinematicEditor.isAttached()));
}else{
//TODO mobile.
}
Expand Down
Loading

0 comments on commit a128b41

Please sign in to comment.