From c071efaa43ad3dcba7d60a7a67e942aae2a7dc83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Juh=C3=A1sz?= Date: Thu, 20 Oct 2016 21:41:38 +0200 Subject: Improved lighting This commit rewrites the procedure that is responsible for light updating. this commit -provides iterative solutions for unlighting and light spreading -introduces a new priority queue-like container for the iteration -creates per-node MapBlock caching to reduce retrieving MapBlocks from the map -calculates with map block positions and in-block relative node coordinates -skips light updating if it is not necessary since the node's new light will be the same as its old light was --- src/mapnode.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/mapnode.cpp') diff --git a/src/mapnode.cpp b/src/mapnode.cpp index eba47446d..5efebf3d8 100644 --- a/src/mapnode.cpp +++ b/src/mapnode.cpp @@ -54,10 +54,10 @@ MapNode::MapNode(INodeDefManager *ndef, const std::string &name, param2 = a_param2; } -void MapNode::setLight(enum LightBank bank, u8 a_light, INodeDefManager *nodemgr) +void MapNode::setLight(enum LightBank bank, u8 a_light, const ContentFeatures &f) { // If node doesn't contain light data, ignore this - if(nodemgr->get(*this).param_type != CPT_LIGHT) + if(f.param_type != CPT_LIGHT) return; if(bank == LIGHTBANK_DAY) { @@ -73,6 +73,11 @@ void MapNode::setLight(enum LightBank bank, u8 a_light, INodeDefManager *nodemgr assert("Invalid light bank" == NULL); } +void MapNode::setLight(enum LightBank bank, u8 a_light, INodeDefManager *nodemgr) +{ + setLight(bank, a_light, nodemgr->get(*this)); +} + bool MapNode::isLightDayNightEq(INodeDefManager *nodemgr) const { const ContentFeatures &f = nodemgr->get(*this); @@ -103,6 +108,13 @@ u8 MapNode::getLight(enum LightBank bank, INodeDefManager *nodemgr) const return MYMAX(f.light_source, light); } +u8 MapNode::getLightRaw(enum LightBank bank, const ContentFeatures &f) const +{ + if(f.param_type == CPT_LIGHT) + return bank == LIGHTBANK_DAY ? param1 & 0x0f : (param1 >> 4) & 0x0f; + return 0; +} + u8 MapNode::getLightNoChecks(enum LightBank bank, const ContentFeatures *f) const { return MYMAX(f->light_source, -- cgit v1.2.3