fix: "sunlight leakage" when GlobalLightLevel was changed, premature lightmap rendering on leftmost side of screen where no pre-calculated light value was given

Former-commit-id: bf628e9bde44858f641998e65bf5fef847060791
Former-commit-id: b32fec30a112a7b5868e51ba1394454d5740c5d9
This commit is contained in:
Song Minjae
2016-03-03 16:57:43 +09:00
parent 5f6206541e
commit dc788aa515
4 changed files with 157 additions and 142 deletions

View File

@@ -1,46 +1,49 @@
"id";"name" ;"opacity";"strength";"fluid";"viscosity";"solid";"wall";"lumcolor";"opaque";"drop";"fall";"friction"
# Friction: 0: frictionless, <16: slippery, 16: regular, >16: sticky | Opacity/Lumcolor: 40-step RGB | Opaque: whether the tile completely hides wall behind
"0";"TILE_AIR" ; "1641"; "0"; "0"; "N/A"; "0"; "0"; "0"; "0"; "0"; "0";"16"
"1";"TILE_STONE" ; "8205"; "25"; "0"; "N/A"; "1"; "1"; "0"; "1"; "1"; "0";"16"
"2";"TILE_DIRT" ; "8205"; "6"; "0"; "N/A"; "1"; "1"; "0"; "1"; "2"; "0";"16"
"3";"TILE_GRASS" ; "8205"; "6"; "0"; "N/A"; "1"; "1"; "0"; "1"; "2"; "0";"16"
"4";"TILE_PLANK_NORMAL" ; "8205"; "12"; "0"; "N/A"; "1"; "1"; "0"; "1"; "4"; "0";"16"
"5";"TILE_PLANK_EBONY" ; "8205"; "12"; "0"; "N/A"; "1"; "1"; "0"; "1"; "5"; "0";"16"
"6";"TILE_PLANK_BIRCH" ; "8205"; "12"; "0"; "N/A"; "1"; "1"; "0"; "1"; "6"; "0";"16"
"7";"TILE_PLANK_BLOODROSE" ; "8205"; "12"; "0"; "N/A"; "1"; "1"; "0"; "1"; "7"; "0";"16"
"8";"TILE_TRUNK_NORMAL" ; "8205"; "12"; "0"; "N/A"; "1"; "0"; "0"; "1"; "8"; "0";"16"
"9";"TILE_TRUNK_EBONY" ; "8205"; "12"; "0"; "N/A"; "1"; "0"; "0"; "1"; "9"; "0";"16"
"10";"TILE_TRUNK_BIRCH" ; "8205"; "12"; "0"; "N/A"; "1"; "0"; "0"; "1"; "10"; "0";"16"
"11";"TILE_TRUNK_BLOODROSE" ; "8205"; "12"; "0"; "N/A"; "1"; "0"; "0"; "1"; "11"; "0";"16"
"12";"TILE_STONE_QUARRIED" ; "8205"; "25"; "0"; "N/A"; "1"; "1"; "0"; "1"; "12"; "0";"16"
"13";"TILE_SAND" ; "8205"; "6"; "0"; "N/A"; "1"; "1"; "0"; "1"; "13"; "1";"16"
"14";"TILE_GRAVEL" ; "8205"; "6"; "0"; "N/A"; "1"; "0"; "0"; "1"; "14"; "1";"16"
"0";"TILE_AIR" ; "1641"; "0"; "0"; "0"; "0"; "0"; "0"; "0"; "0"; "0";"16"
"1";"TILE_STONE" ; "8205"; "25"; "0"; "0"; "1"; "1"; "0"; "1"; "1"; "0";"16"
"2";"TILE_DIRT" ; "8205"; "6"; "0"; "0"; "1"; "1"; "0"; "1"; "2"; "0";"16"
"3";"TILE_GRASS" ; "8205"; "6"; "0"; "0"; "1"; "1"; "0"; "1"; "2"; "0";"16"
"4";"TILE_PLANK_NORMAL" ; "8205"; "12"; "0"; "0"; "1"; "1"; "0"; "1"; "4"; "0";"16"
"5";"TILE_PLANK_EBONY" ; "8205"; "12"; "0"; "0"; "1"; "1"; "0"; "1"; "5"; "0";"16"
"6";"TILE_PLANK_BIRCH" ; "8205"; "12"; "0"; "0"; "1"; "1"; "0"; "1"; "6"; "0";"16"
"7";"TILE_PLANK_BLOODROSE" ; "8205"; "12"; "0"; "0"; "1"; "1"; "0"; "1"; "7"; "0";"16"
"8";"TILE_TRUNK_NORMAL" ; "8205"; "12"; "0"; "0"; "1"; "0"; "0"; "1"; "8"; "0";"16"
"9";"TILE_TRUNK_EBONY" ; "8205"; "12"; "0"; "0"; "1"; "0"; "0"; "1"; "9"; "0";"16"
"10";"TILE_TRUNK_BIRCH" ; "8205"; "12"; "0"; "0"; "1"; "0"; "0"; "1"; "10"; "0";"16"
"11";"TILE_TRUNK_BLOODROSE" ; "8205"; "12"; "0"; "0"; "1"; "0"; "0"; "1"; "11"; "0";"16"
"12";"TILE_STONE_QUARRIED" ; "8205"; "25"; "0"; "0"; "1"; "1"; "0"; "1"; "12"; "0";"16"
"13";"TILE_SAND" ; "8205"; "6"; "0"; "0"; "1"; "1"; "0"; "1"; "13"; "1";"16"
"14";"TILE_GRAVEL" ; "8205"; "6"; "0"; "0"; "1"; "0"; "0"; "1"; "14"; "1";"16"
"15";"TILE_ORE_MALACHITE" ; "8205"; "25"; "0"; "N/A"; "1"; "0"; "0"; "1"; "15"; "0";"16"
"16";"TILE_ORE_HEMATITE" ; "8205"; "25"; "0"; "N/A"; "1"; "0"; "0"; "1"; "16"; "0";"16"
"17";"TILE_ORE_NATURAL_GOLD" ; "8205"; "25"; "0"; "N/A"; "1"; "0"; "0"; "1"; "17"; "0";"16"
"18";"TILE_ORE_NATURAL_SILVER" ; "8205"; "25"; "0"; "N/A"; "1"; "0"; "0"; "1"; "18"; "0";"16"
"19";"TILE_ORE_RUTILE" ; "8205"; "25"; "0"; "N/A"; "1"; "0"; "0"; "1"; "19"; "0";"16"
"20";"TILE_ORE_AURICHALCUMITE" ; "8205"; "25"; "0"; "N/A"; "1"; "0"; "0"; "1"; "20"; "0";"16"
"21";"TILE_GEM_RUBY" ; "8205"; "25"; "0"; "N/A"; "1"; "0"; "0"; "1"; "21"; "0";"16"
"22";"TILE_GEM_EMERALD" ; "8205"; "25"; "0"; "N/A"; "1"; "0"; "0"; "1"; "22"; "0";"16"
"23";"TILE_GEM_SAPPHIRE" ; "8205"; "25"; "0"; "N/A"; "1"; "0"; "0"; "1"; "23"; "0";"16"
"24";"TILE_GEM_TOPAZ" ; "8205"; "25"; "0"; "N/A"; "1"; "0"; "0"; "1"; "24"; "0";"16"
"25";"TILE_GEM_DIAMOND" ; "8205"; "25"; "0"; "N/A"; "1"; "0"; "0"; "1"; "25"; "0";"16"
"26";"TILE_GEM_AMETHYST" ; "8205"; "25"; "0"; "N/A"; "1"; "0"; "0"; "1"; "26"; "0";"16"
"15";"TILE_ORE_MALACHITE" ; "8205"; "25"; "0"; "0"; "1"; "0"; "0"; "1"; "15"; "0";"16"
"16";"TILE_ORE_HEMATITE" ; "8205"; "25"; "0"; "0"; "1"; "0"; "0"; "1"; "16"; "0";"16"
"17";"TILE_ORE_NATURAL_GOLD" ; "8205"; "25"; "0"; "0"; "1"; "0"; "0"; "1"; "17"; "0";"16"
"18";"TILE_ORE_NATURAL_SILVER" ; "8205"; "25"; "0"; "0"; "1"; "0"; "0"; "1"; "18"; "0";"16"
"19";"TILE_ORE_RUTILE" ; "8205"; "25"; "0"; "0"; "1"; "0"; "0"; "1"; "19"; "0";"16"
"20";"TILE_ORE_AURICHALCUMITE" ; "8205"; "25"; "0"; "0"; "1"; "0"; "0"; "1"; "20"; "0";"16"
"21";"TILE_GEM_RUBY" ; "8205"; "25"; "0"; "0"; "1"; "0"; "0"; "1"; "21"; "0";"16"
"22";"TILE_GEM_EMERALD" ; "8205"; "25"; "0"; "0"; "1"; "0"; "0"; "1"; "22"; "0";"16"
"23";"TILE_GEM_SAPPHIRE" ; "8205"; "25"; "0"; "0"; "1"; "0"; "0"; "1"; "23"; "0";"16"
"24";"TILE_GEM_TOPAZ" ; "8205"; "25"; "0"; "0"; "1"; "0"; "0"; "1"; "24"; "0";"16"
"25";"TILE_GEM_DIAMOND" ; "8205"; "25"; "0"; "0"; "1"; "0"; "0"; "1"; "25"; "0";"16"
"26";"TILE_GEM_AMETHYST" ; "8205"; "25"; "0"; "0"; "1"; "0"; "0"; "1"; "26"; "0";"16"
"27";"TILE_SNOW" ; "8205"; "6"; "0"; "N/A"; "1"; "1"; "0"; "1"; "27"; "0";"16"
"28";"TILE_ICE_FRAGILE" ; "3282"; "1"; "0"; "N/A"; "1"; "0"; "0"; "0"; "28"; "0";"16"
"29";"TILE_ICE_NATURAL" ; "6564"; "25"; "0"; "N/A"; "1"; "1"; "0"; "1"; "29"; "0"; "8"
"30";"TILE_ICE_CLEAR_MAGICAL" ; "8205"; "25"; "0"; "N/A"; "1"; "1"; "5009"; "0"; "30"; "0"; "8"
"27";"TILE_SNOW" ; "8205"; "6"; "0"; "0"; "1"; "1"; "0"; "1"; "27"; "0";"16"
"28";"TILE_ICE_FRAGILE" ; "3282"; "1"; "0"; "0"; "1"; "0"; "0"; "0"; "28"; "0";"16"
"29";"TILE_ICE_NATURAL" ; "6564"; "25"; "0"; "0"; "1"; "1"; "0"; "1"; "29"; "0"; "8"
"30";"TILE_ICE_CLEAR_MAGICAL" ; "8205"; "25"; "0"; "0"; "1"; "1"; "5009"; "0"; "30"; "0"; "8"
# see scandinavian name set female of this tile id!
"31";"TILE_PLATFORM_STONE" ; "0"; "0"; "0"; "N/A"; "0"; "0"; "0"; "0"; "31"; "0";"16"
"32";"TILE_PLATFORM_WOODEN" ; "0"; "0"; "0"; "N/A"; "0"; "0"; "0"; "0"; "32"; "0";"16"
"33";"TILE_PLATFORM_EBONY" ; "0"; "0"; "0"; "N/A"; "0"; "0"; "0"; "0"; "33"; "0";"16"
"34";"TILE_PLATFORM_BIRCH" ; "0"; "0"; "0"; "N/A"; "0"; "0"; "0"; "0"; "34"; "0";"16"
"35";"TILE_PLATFORM_BLOODROSE" ; "0"; "0"; "0"; "N/A"; "0"; "0"; "0"; "0"; "35"; "0";"16"
"31";"TILE_PLATFORM_STONE" ; "0"; "0"; "0"; "0"; "0"; "0"; "0"; "0"; "31"; "0";"16"
"32";"TILE_PLATFORM_WOODEN" ; "0"; "0"; "0"; "0"; "0"; "0"; "0"; "0"; "32"; "0";"16"
"33";"TILE_PLATFORM_EBONY" ; "0"; "0"; "0"; "0"; "0"; "0"; "0"; "0"; "33"; "0";"16"
"34";"TILE_PLATFORM_BIRCH" ; "0"; "0"; "0"; "0"; "0"; "0"; "0"; "0"; "34"; "0";"16"
"35";"TILE_PLATFORM_BLOODROSE" ; "0"; "0"; "0"; "0"; "0"; "0"; "0"; "0"; "35"; "0";"16"
"36";"TILE_TORCH" ; "0"; "0"; "0"; "N/A"; "0"; "0"; "63412"; "0"; "36"; "0";"16"
"36";"TILE_TORCH" ; "0"; "0"; "0"; "0"; "0"; "0"; "63412"; "0"; "36"; "0";"16"
# 63412 (ffa44e) : real candlelight colour taken from properly configured camera.
"239";"TILE_WATER" ; "6522"; "100"; "1"; "2"; "0"; "0"; "0"; "0"; "239"; "0";"16"
"255";"TILE_LAVA" ; "62358"; "100"; "1"; "2"; "0"; "0"; "48320"; "0"; "239"; "0";"16"
"239";"TILE_WATER" ; "6522"; "100"; "1"; "16"; "0"; "0"; "0"; "0"; "239"; "0";"16"
"255";"TILE_LAVA" ; "62358"; "100"; "1"; "16"; "0"; "0"; "48320"; "0"; "239"; "0";"16"
# Friction: 0: frictionless, <16: slippery, 16: regular, >16: sticky
# Opacity/Lumcolor: 40-step RGB
# Opaque: whether the tile completely hides wall behind
# Viscosity: (walkspeedmax) * (1 + (n/16))
Can't render this file because it contains an unexpected character in line 1 and column 12.

View File

@@ -47,6 +47,7 @@ public class LightmapRenderer {
}
@Deprecated
public static void addLantern(int x, int y, char intensity) {
LightmapLantern thisLantern = new LightmapLantern(x, y, intensity);
@@ -64,6 +65,7 @@ public class LightmapRenderer {
lanterns.add(thisLantern);
}
@Deprecated
public static void removeLantern(int x, int y) {
for (int i = lanterns.size() - 1; i >= 0; i--) {
LightmapLantern lantern = lanterns.get(i);
@@ -85,11 +87,11 @@ public class LightmapRenderer {
}
int for_y_start = div16(MapCamera.getCameraY()) - MUL;
int for_x_start = div16(MapCamera.getCameraX()) - MUL;
int for_y_start = div16(MapCamera.getCameraY()) - 1;
int for_x_start = div16(MapCamera.getCameraX()) - 1;
int for_y_end = clampHTile(for_y_start + div16(MapCamera.getRenderHeight()) + 2) + MUL;
int for_x_end = clampWTile(for_x_start + div16(MapCamera.getRenderWidth()) + 2) + MUL;
int for_y_end = clampHTile(for_y_start + div16(MapCamera.getRenderHeight()) + 2) + 1;
int for_x_end = clampWTile(for_x_start + div16(MapCamera.getRenderWidth()) + 2) + 1;
/**
* Updating order:
@@ -102,13 +104,12 @@ public class LightmapRenderer {
* for all staticLightMap[y][x]
*/
// Round 1
purgePartOfLightmap(for_x_start, for_y_start, for_x_end, for_y_end);
//System.out.println(for_x_start);
//System.out.println(for_x_end);
purgePartOfLightmap(for_x_start - 1, for_y_start - 1, for_x_end + 1, for_y_end + 1);
// if wider purge were not applied, GL changing (sunset, sunrise) will behave incorrectly
// ("leakage" of non-updated sunlight)
try {
// Round 1
for (int y = for_y_start; y < for_y_end; y++) {
for (int x = for_x_start; x < for_x_end; x++) {
staticLightMap[y][x] = calculate(x, y);
@@ -140,16 +141,18 @@ public class LightmapRenderer {
}
public static void draw(Graphics g) {
int for_x_start = MapCamera.getRenderStartX();
int for_y_start = MapCamera.getRenderStartY();
int for_x_start = MapCamera.getRenderStartX() - 1;
int for_y_start = MapCamera.getRenderStartY() - 1;
int for_x_end = MapCamera.getRenderEndX();
int for_y_end = MapCamera.getRenderEndY();
// draw
try {
for (int y = for_y_start; y < for_y_end; y++) {
for (int x = for_x_start; x < for_x_end; x++) {
// smooth
if (Terrarum.game.screenZoom >= 1 && ((boolean) Terrarum.game.gameConfig.get("smoothlighting"))) {
if (Terrarum.game.screenZoom >= 1 && ((boolean) Terrarum.game.gameConfig.get(
"smoothlighting"))) {
char thisLightLevel = staticLightMap[y][x];
if (y > 0 && x < for_x_end && thisLightLevel == 0 && staticLightMap[y - 1][x] == 0) {
try {
@@ -188,20 +191,28 @@ public class LightmapRenderer {
*/
char a = (y == 0) ? thisLightLevel
: (y == Terrarum.game.map.height - 1) ? thisLightLevel
: maximiseRGB(staticLightMap[y][x]
, staticLightMap[y - 1][x]);
: maximiseRGB(
staticLightMap[y][x]
,
staticLightMap[y - 1][x]);
char d = (y == 0) ? thisLightLevel
: (y == Terrarum.game.map.height - 1) ? thisLightLevel
: maximiseRGB(staticLightMap[y][x]
, staticLightMap[y + 1][x]);
: maximiseRGB(
staticLightMap[y][x]
,
staticLightMap[y + 1][x]);
char b = (x == 0) ? thisLightLevel
: (x == Terrarum.game.map.width - 1) ? thisLightLevel
: maximiseRGB(staticLightMap[y][x]
, staticLightMap[y][x - 1]);
: maximiseRGB(
staticLightMap[y][x]
,
staticLightMap[y][x - 1]);
char c = (x == 0) ? thisLightLevel
: (x == Terrarum.game.map.width - 1) ? thisLightLevel
: maximiseRGB(staticLightMap[y][x]
, staticLightMap[y][x + 1]);
: maximiseRGB(
staticLightMap[y][x]
,
staticLightMap[y][x + 1]);
char[] colourMapItoL = new char[4];
colourMapItoL[0] = colourLinearMix(a, b);
colourMapItoL[1] = colourLinearMix(a, c);
@@ -213,8 +224,10 @@ public class LightmapRenderer {
g.setColor(toTargetColour(colourMapItoL[iy * 2 + ix]));
g.fillRect(
Math.round(x * TSIZE * Terrarum.game.screenZoom) + (ix * TSIZE / 2 * Terrarum.game.screenZoom)
, Math.round(y * TSIZE * Terrarum.game.screenZoom) + (iy * TSIZE / 2 * Terrarum.game.screenZoom)
Math.round(
x * TSIZE * Terrarum.game.screenZoom) + (ix * TSIZE / 2 * Terrarum.game.screenZoom)
, Math.round(
y * TSIZE * Terrarum.game.screenZoom) + (iy * TSIZE / 2 * Terrarum.game.screenZoom)
, FastMath.ceil(TSIZE * Terrarum.game.screenZoom / 2)
, FastMath.ceil(TSIZE * Terrarum.game.screenZoom / 2)
);
@@ -239,7 +252,8 @@ public class LightmapRenderer {
g.fillRect(
Math.round(x * TSIZE * Terrarum.game.screenZoom)
, Math.round(y * TSIZE * Terrarum.game.screenZoom)
, FastMath.ceil(TSIZE * Terrarum.game.screenZoom) * sameLevelCounter
, FastMath.ceil(
TSIZE * Terrarum.game.screenZoom) * sameLevelCounter
, FastMath.ceil(TSIZE * Terrarum.game.screenZoom)
);
@@ -252,6 +266,8 @@ public class LightmapRenderer {
}
}
}
catch (ArrayIndexOutOfBoundsException e) {}
}
private static Color toTargetColour(char raw) {
return new Col40().createSlickColor(raw);
@@ -561,10 +577,6 @@ public class LightmapRenderer {
return (i < 0) ? 0 : (i > 1) ? 1 : i;
}
public static char[][] getStaticLightMap() {
return staticLightMap;
}
public static char getValueFromMap(int x, int y) {
return staticLightMap[y][x];
}