Add support for lighting level toned maps: nightspawn daynightspawn

This commit is contained in:
Mike Primm 2020-05-02 15:21:47 -05:00
parent 28f2935fc5
commit e7fefeae8d
4 changed files with 103 additions and 2 deletions

View File

@ -63,6 +63,16 @@ public class Color {
public final void setAlpha(int v) {
val = (val & 0x00FFFFFF) | (v << 24);
}
public final void scaleColor(Color minimum, Color maximum) {
int alpha = (val >> 24) & 0xFF;
int red = (val >> 16) & 0xFF;
int green = (val >> 8) & 0xFF;
int blue = val & 0xFF;
red = minimum.getRed() + ((maximum.getRed() - minimum.getRed()) * red) / 256;
green = minimum.getGreen() + ((maximum.getGreen() - minimum.getGreen()) * green) / 256;
blue = minimum.getBlue() + ((maximum.getBlue() - minimum.getBlue()) * blue) / 256;
setRGBA(red, green, blue, alpha);
}
/**
* Scale each color component, based on the corresponding component
* @param c - color to blend

View File

@ -10,7 +10,7 @@ import static org.dynmap.JSONUtils.s;
public class DefaultHDLighting implements HDLighting {
private String name;
protected final boolean grayscale;
protected boolean grayscale;
protected final Color graytone;
public DefaultHDLighting(DynmapCore core, ConfigurationNode configuration) {

View File

@ -0,0 +1,68 @@
package org.dynmap.hdmap;
import org.dynmap.Color;
import org.dynmap.ConfigurationNode;
import org.dynmap.DynmapCore;
import org.dynmap.DynmapWorld;
import org.dynmap.Log;
import org.dynmap.MapManager;
import org.dynmap.utils.LightLevels;
import org.dynmap.utils.BlockStep;
public class LightLevelHDLighting extends DefaultHDLighting {
private final Color[] lightlevelcolors = new Color[16];
protected final boolean night_and_day; /* If true, render both day (prefix+'-day') and night (prefix) tiles */
private final boolean night;
private final Color mincolor = new Color(0x40, 0x40, 0x40);
private final Color maxcolor = new Color(0xFF, 0xFF, 0xFF);
public LightLevelHDLighting(DynmapCore core, ConfigurationNode configuration) {
super(core, configuration);
grayscale = true; // Force to grayscale
for (int i = 0; i < 16; i++) {
lightlevelcolors[i] = configuration.getColor("color" + i, null);
}
night = configuration.getBoolean("night", false);
night_and_day = configuration.getBoolean("night-and-day", false);
}
/* Apply lighting to given pixel colors (1 outcolor if normal, 2 if night/day) */
public void applyLighting(HDPerspectiveState ps, HDShaderState ss, Color incolor, Color[] outcolor) {
super.applyLighting(ps, ss, incolor, outcolor); // Apply default lighting (outcolors will be grayscale)
// Compute light levels
LightLevels ll = ps.getCachedLightLevels(0);
ps.getLightLevels(ll);
if (outcolor.length == 1) {
// Scale range between 25% and 100% intensity (we don't want blacks, since that will prevent color from showing
outcolor[0].scaleColor(mincolor, maxcolor);
int lightlevel = night ? ll.emitted : Math.max(ll.sky, ll.emitted);
if (lightlevelcolors[lightlevel] != null) {
outcolor[0].blendColor(lightlevelcolors[lightlevel]);
}
}
else {
// Scale range between 25% and 100% intensity (we don't want blacks, since that will prevent color from showing
outcolor[0].scaleColor(mincolor, maxcolor);
outcolor[1].scaleColor(mincolor, maxcolor);
int daylightlevel = Math.max(ll.sky, ll.emitted);
if (lightlevelcolors[ll.emitted] != null) {
outcolor[0].blendColor(lightlevelcolors[ll.emitted]);
}
if (lightlevelcolors[daylightlevel] != null) {
outcolor[1].blendColor(lightlevelcolors[daylightlevel]);
}
}
}
/* Test if night/day is enabled for this renderer */
public boolean isNightAndDayEnabled() { return night_and_day; }
/* Test if sky light level needed */
public boolean isSkyLightLevelNeeded() { return true; }
/* Test if emitted light level needed */
public boolean isEmittedLightLevelNeeded() { return true; }
@Override
public int[] getBrightnessTable(DynmapWorld world) {
return null;
}
}

View File

@ -98,5 +98,28 @@ lightings:
name: parchment-noshadow
grayscale: true
graytone: '#C09A53'
# Spawn at night warning map
- class: org.dynmap.hdmap.LightLevelHDLighting
name: nightspawn
color0: '#FF0000'
color1: '#FF6600'
color2: '#FF9900'
color3: '#FFCC00'
color4: '#FFCC33'
color5: '#FFCC66'
color6: '#FFCC99'
color7: '#FFFF00'
night: true
# Spawn day-night warning map
- class: org.dynmap.hdmap.LightLevelHDLighting
name: daynightspawn
color0: '#FF0000'
color1: '#FF6600'
color2: '#FF9900'
color3: '#FFCC00'
color4: '#FFCC33'
color5: '#FFCC66'
color6: '#FFCC99'
color7: '#FFFF00'
night-and-day: true