aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorJude Melton-Houghton <jwmhjwmh@gmail.com>2022-10-09 10:50:26 -0400
committerGitHub <noreply@github.com>2022-10-09 10:50:26 -0400
commit9676364c1fe5fe5eae69c55e7d7a45392decfb2d (patch)
treeb21c99ce54820b24bfef9028c39b01f28ed3c1ca /src/client
parent440d966b939059dfa51604eb68d61eecb12baeb4 (diff)
downloadminetest-9676364c1fe5fe5eae69c55e7d7a45392decfb2d.tar.xz
Optimize lighting calculation (#12797)
Diffstat (limited to 'src/client')
-rw-r--r--src/client/clientmap.cpp21
-rw-r--r--src/client/content_cso.cpp3
-rw-r--r--src/client/content_mapblock.cpp2
-rw-r--r--src/client/mapblock_mesh.cpp16
-rw-r--r--src/client/particles.cpp3
5 files changed, 24 insertions, 21 deletions
diff --git a/src/client/clientmap.cpp b/src/client/clientmap.cpp
index 23234c365..b74499ac3 100644
--- a/src/client/clientmap.cpp
+++ b/src/client/clientmap.cpp
@@ -527,8 +527,8 @@ static bool getVisibleBrightness(Map *map, const v3f &p0, v3f dir, float step,
{
v3s16 p = floatToInt(p0 /*+ dir * 3*BS*/, BS);
MapNode n = map->getNode(p);
- if(ndef->get(n).param_type == CPT_LIGHT &&
- !ndef->get(n).sunlight_propagates)
+ if(ndef->getLightingFlags(n).has_light &&
+ !ndef->getLightingFlags(n).sunlight_propagates)
allow_allowing_non_sunlight_propagates = true;
}
// If would start at CONTENT_IGNORE, start closer
@@ -549,15 +549,13 @@ static bool getVisibleBrightness(Map *map, const v3f &p0, v3f dir, float step,
v3s16 p = floatToInt(pf, BS);
MapNode n = map->getNode(p);
+ ContentLightingFlags f = ndef->getLightingFlags(n);
if (allow_allowing_non_sunlight_propagates && i == 0 &&
- ndef->get(n).param_type == CPT_LIGHT &&
- !ndef->get(n).sunlight_propagates) {
+ f.has_light && !f.sunlight_propagates) {
allow_non_sunlight_propagates = true;
}
- if (ndef->get(n).param_type != CPT_LIGHT ||
- (!ndef->get(n).sunlight_propagates &&
- !allow_non_sunlight_propagates)){
+ if (!f.has_light || (!f.sunlight_propagates && !allow_non_sunlight_propagates)){
nonlight_seen = true;
noncount++;
if(noncount >= 4)
@@ -566,10 +564,10 @@ static bool getVisibleBrightness(Map *map, const v3f &p0, v3f dir, float step,
}
if (distance >= sunlight_min_d && !*sunlight_seen && !nonlight_seen)
- if (n.getLight(LIGHTBANK_DAY, ndef) == LIGHT_SUN)
+ if (n.getLight(LIGHTBANK_DAY, f) == LIGHT_SUN)
*sunlight_seen = true;
noncount = 0;
- brightness_sum += decode_light(n.getLightBlend(daylight_factor, ndef));
+ brightness_sum += decode_light(n.getLightBlend(daylight_factor, f));
brightness_count++;
}
*result = 0;
@@ -653,8 +651,9 @@ int ClientMap::getBackgroundBrightness(float max_d, u32 daylight_factor,
int ret = 0;
if(brightness_count == 0){
MapNode n = getNode(floatToInt(m_camera_position, BS));
- if(m_nodedef->get(n).param_type == CPT_LIGHT){
- ret = decode_light(n.getLightBlend(daylight_factor, m_nodedef));
+ ContentLightingFlags f = m_nodedef->getLightingFlags(n);
+ if(f.has_light){
+ ret = decode_light(n.getLightBlend(daylight_factor, f));
} else {
ret = oldvalue;
}
diff --git a/src/client/content_cso.cpp b/src/client/content_cso.cpp
index f9641afbe..50ae4e413 100644
--- a/src/client/content_cso.cpp
+++ b/src/client/content_cso.cpp
@@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "clientenvironment.h"
#include "client.h"
#include "map.h"
+#include "nodedef.h"
class SmokePuffCSO: public ClientSimpleObject
{
@@ -50,7 +51,7 @@ public:
bool pos_ok;
MapNode n = env->getMap().getNode(floatToInt(pos, BS), &pos_ok);
light = pos_ok ? decode_light(n.getLightBlend(env->getDayNightRatio(),
- env->getGameDef()->ndef()))
+ env->getGameDef()->ndef()->getLightingFlags(n)))
: 64;
video::SColor color(255,light,light,light);
m_spritenode->setColor(color);
diff --git a/src/client/content_mapblock.cpp b/src/client/content_mapblock.cpp
index 7fd5aefb1..a9abbceeb 100644
--- a/src/client/content_mapblock.cpp
+++ b/src/client/content_mapblock.cpp
@@ -472,7 +472,7 @@ void MapblockMeshGenerator::prepareLiquidNodeDrawing()
// it at what it emits, for an increased effect
u8 e = decode_light(f->light_source);
light = LightPair(std::max(e, light.lightDay), std::max(e, light.lightNight));
- } else if (nodedef->get(ntop).param_type == CPT_LIGHT) {
+ } else if (nodedef->getLightingFlags(ntop).has_light) {
// Otherwise, use the light of the node on top if possible
light = LightPair(getInteriorLight(ntop, 0, nodedef));
}
diff --git a/src/client/mapblock_mesh.cpp b/src/client/mapblock_mesh.cpp
index 5036f8bd6..519932cd4 100644
--- a/src/client/mapblock_mesh.cpp
+++ b/src/client/mapblock_mesh.cpp
@@ -102,7 +102,7 @@ void MeshMakeData::setSmoothLighting(bool smooth_lighting)
static u8 getInteriorLight(enum LightBank bank, MapNode n, s32 increment,
const NodeDefManager *ndef)
{
- u8 light = n.getLight(bank, ndef);
+ u8 light = n.getLight(bank, ndef->getLightingFlags(n));
if (light > 0)
light = rangelim(light + increment, 0, LIGHT_SUN);
return decode_light(light);
@@ -126,17 +126,19 @@ u16 getInteriorLight(MapNode n, s32 increment, const NodeDefManager *ndef)
static u8 getFaceLight(enum LightBank bank, MapNode n, MapNode n2,
v3s16 face_dir, const NodeDefManager *ndef)
{
+ ContentLightingFlags f1 = ndef->getLightingFlags(n);
+ ContentLightingFlags f2 = ndef->getLightingFlags(n2);
+
u8 light;
- u8 l1 = n.getLight(bank, ndef);
- u8 l2 = n2.getLight(bank, ndef);
+ u8 l1 = n.getLight(bank, f1);
+ u8 l2 = n2.getLight(bank, f2);
if(l1 > l2)
light = l1;
else
light = l2;
// Boost light level for light sources
- u8 light_source = MYMAX(ndef->get(n).light_source,
- ndef->get(n2).light_source);
+ u8 light_source = MYMAX(f1.light_source, f2.light_source);
if(light_source > light)
light = light_source;
@@ -184,8 +186,8 @@ static u16 getSmoothLightCombined(const v3s16 &p,
light_source_max = f.light_source;
// Check f.solidness because fast-style leaves look better this way
if (f.param_type == CPT_LIGHT && f.solidness != 2) {
- u8 light_level_day = n.getLightNoChecks(LIGHTBANK_DAY, &f);
- u8 light_level_night = n.getLightNoChecks(LIGHTBANK_NIGHT, &f);
+ u8 light_level_day = n.getLight(LIGHTBANK_DAY, f.getLightingFlags());
+ u8 light_level_night = n.getLight(LIGHTBANK_NIGHT, f.getLightingFlags());
if (light_level_day == LIGHT_SUN)
direct_sunlight = true;
light_day += decode_light(light_level_day);
diff --git a/src/client/particles.cpp b/src/client/particles.cpp
index 99723d8d6..b272976d5 100644
--- a/src/client/particles.cpp
+++ b/src/client/particles.cpp
@@ -265,7 +265,8 @@ void Particle::updateLight()
);
MapNode n = m_env->getClientMap().getNode(p, &pos_ok);
if (pos_ok)
- light = n.getLightBlend(m_env->getDayNightRatio(), m_gamedef->ndef());
+ light = n.getLightBlend(m_env->getDayNightRatio(),
+ m_gamedef->ndef()->getLightingFlags(n));
else
light = blend_light(m_env->getDayNightRatio(), LIGHT_SUN, 0);