mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Optimize lighting calculation (#12797)
This commit is contained in:
parent
440d966b93
commit
9676364c1f
18 changed files with 188 additions and 220 deletions
|
@ -53,95 +53,6 @@ void MapNode::getColor(const ContentFeatures &f, video::SColor *color) const
|
|||
*color = f.color;
|
||||
}
|
||||
|
||||
void MapNode::setLight(LightBank bank, u8 a_light, const ContentFeatures &f) noexcept
|
||||
{
|
||||
// If node doesn't contain light data, ignore this
|
||||
if(f.param_type != CPT_LIGHT)
|
||||
return;
|
||||
if(bank == LIGHTBANK_DAY)
|
||||
{
|
||||
param1 &= 0xf0;
|
||||
param1 |= a_light & 0x0f;
|
||||
}
|
||||
else if(bank == LIGHTBANK_NIGHT)
|
||||
{
|
||||
param1 &= 0x0f;
|
||||
param1 |= (a_light & 0x0f)<<4;
|
||||
}
|
||||
else
|
||||
assert("Invalid light bank" == NULL);
|
||||
}
|
||||
|
||||
void MapNode::setLight(LightBank bank, u8 a_light, const NodeDefManager *nodemgr)
|
||||
{
|
||||
setLight(bank, a_light, nodemgr->get(*this));
|
||||
}
|
||||
|
||||
bool MapNode::isLightDayNightEq(const NodeDefManager *nodemgr) const
|
||||
{
|
||||
const ContentFeatures &f = nodemgr->get(*this);
|
||||
bool isEqual;
|
||||
|
||||
if (f.param_type == CPT_LIGHT) {
|
||||
u8 day = MYMAX(f.light_source, param1 & 0x0f);
|
||||
u8 night = MYMAX(f.light_source, (param1 >> 4) & 0x0f);
|
||||
isEqual = day == night;
|
||||
} else {
|
||||
isEqual = true;
|
||||
}
|
||||
|
||||
return isEqual;
|
||||
}
|
||||
|
||||
u8 MapNode::getLight(LightBank bank, const NodeDefManager *nodemgr) const
|
||||
{
|
||||
// Select the brightest of [light source, propagated light]
|
||||
const ContentFeatures &f = nodemgr->get(*this);
|
||||
|
||||
u8 light;
|
||||
if(f.param_type == CPT_LIGHT)
|
||||
light = bank == LIGHTBANK_DAY ? param1 & 0x0f : (param1 >> 4) & 0x0f;
|
||||
else
|
||||
light = 0;
|
||||
|
||||
return MYMAX(f.light_source, light);
|
||||
}
|
||||
|
||||
u8 MapNode::getLightRaw(LightBank bank, const ContentFeatures &f) const noexcept
|
||||
{
|
||||
if(f.param_type == CPT_LIGHT)
|
||||
return bank == LIGHTBANK_DAY ? param1 & 0x0f : (param1 >> 4) & 0x0f;
|
||||
return 0;
|
||||
}
|
||||
|
||||
u8 MapNode::getLightNoChecks(LightBank bank, const ContentFeatures *f) const noexcept
|
||||
{
|
||||
return MYMAX(f->light_source,
|
||||
bank == LIGHTBANK_DAY ? param1 & 0x0f : (param1 >> 4) & 0x0f);
|
||||
}
|
||||
|
||||
bool MapNode::getLightBanks(u8 &lightday, u8 &lightnight,
|
||||
const NodeDefManager *nodemgr) const
|
||||
{
|
||||
// Select the brightest of [light source, propagated light]
|
||||
const ContentFeatures &f = nodemgr->get(*this);
|
||||
if(f.param_type == CPT_LIGHT)
|
||||
{
|
||||
lightday = param1 & 0x0f;
|
||||
lightnight = (param1>>4)&0x0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
lightday = 0;
|
||||
lightnight = 0;
|
||||
}
|
||||
if(f.light_source > lightday)
|
||||
lightday = f.light_source;
|
||||
if(f.light_source > lightnight)
|
||||
lightnight = f.light_source;
|
||||
return f.param_type == CPT_LIGHT || f.light_source != 0;
|
||||
}
|
||||
|
||||
u8 MapNode::getFaceDir(const NodeDefManager *nodemgr,
|
||||
bool allow_wallmounted) const
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue