Skip to content

Commit

Permalink
Do not render clear lights
Browse files Browse the repository at this point in the history
Clear lights no longer get mapped to `DrawableLight` instances, making it so that they no longer get rendered.

With this change, `DrawableLight`s can no longer have `null` paints. This means we no longer need to support "default
paints" in `ZoneRenderer.renderLightOverlay()`, so that parameter and related logic have been removed.
  • Loading branch information
kwvanderlinde committed Jul 31, 2023
1 parent c4c3d9c commit 00f6a8e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,27 @@
package net.rptools.maptool.client.ui.zone;

import java.awt.geom.Area;
import javax.annotation.Nonnull;
import net.rptools.maptool.model.drawing.DrawablePaint;

public class DrawableLight {

private DrawablePaint paint;
private Area area;
private @Nonnull DrawablePaint paint;
private @Nonnull Area area;
private int lumens;

public DrawableLight(DrawablePaint paint, Area area, int lumens) {
public DrawableLight(@Nonnull DrawablePaint paint, @Nonnull Area area, int lumens) {
super();
this.paint = paint;
this.area = area;
this.lumens = lumens;
}

public DrawablePaint getPaint() {
public @Nonnull DrawablePaint getPaint() {
return paint;
}

public Area getArea() {
public @Nonnull Area getArea() {
return area;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1427,7 +1427,6 @@ private void renderLights(Graphics2D g, PlayerView view) {
overlayBlending,
view.isGMView() ? null : LightOverlayClipStyle.CLIP_TO_VISIBLE_AREA,
drawableLights,
Color.black,
overlayFillColor);
timer.stop("renderLights:renderLightOverlay");
}
Expand Down Expand Up @@ -1463,7 +1462,6 @@ private void renderAuras(Graphics2D g, PlayerView view) {
AlphaComposite.SrcOver,
view.isGMView() ? null : LightOverlayClipStyle.CLIP_TO_VISIBLE_AREA,
drawableAuras,
new Color(255, 255, 255, 150),
new Color(0, 0, 0, 0));
timer.stop("renderAuras:renderAuraOverlay");
}
Expand Down Expand Up @@ -1580,15 +1578,13 @@ private void renderLumensOverlay(
* @param clipStyle How to clip the overlay relative to the visible area. Set to null for no extra
* clipping.
* @param lights The lights that will be rendered and blended.
* @param defaultPaint A default paint for lights without a paint.
*/
private void renderLightOverlay(
Graphics2D g,
Composite lightBlending,
Composite overlayBlending,
@Nullable LightOverlayClipStyle clipStyle,
Collection<DrawableLight> lights,
Paint defaultPaint,
Paint backgroundFill) {
if (lights.isEmpty()) {
// No point spending resources accomplishing nothing.
Expand Down Expand Up @@ -1631,8 +1627,7 @@ private void renderLightOverlay(
// Draw lights onto the buffer image so the map doesn't affect how they blend
timer.start("renderLightOverlay:drawLights");
for (var light : lights) {
var paint = light.getPaint() != null ? light.getPaint().getPaint() : defaultPaint;
newG.setPaint(paint);
newG.setPaint(light.getPaint().getPaint());
timer.start("renderLightOverlay:fillLight");
newG.fill(light.getArea());
timer.stop("renderLightOverlay:fillLight");
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/net/rptools/maptool/client/ui/zone/ZoneView.java
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,12 @@ public Collection<DrawableLight> getDrawableLights(PlayerView view) {
return null;
}

// Lights without a colour are "clear" and should not be rendered.
var paint = laud.lightInfo().light().getPaint();
if (paint == null) {
return null;
}

// Make sure each drawable light is restricted to the area it covers,
// accounting for darkness effects.
final var obscuredArea = new Area(laud.litArea().area());
Expand All @@ -770,10 +776,7 @@ public Collection<DrawableLight> getDrawableLights(PlayerView view) {
isDarkness
? lumensLevel.get().darknessArea()
: lumensLevel.get().lightArea());
return new DrawableLight(
laud.lightInfo().light().getPaint(),
obscuredArea,
laud.litArea().lumens());
return new DrawableLight(paint, obscuredArea, laud.litArea().lumens());
})
.filter(Objects::nonNull)
.toList();
Expand Down

0 comments on commit 00f6a8e

Please sign in to comment.