From 9676364c1fe5fe5eae69c55e7d7a45392decfb2d Mon Sep 17 00:00:00 2001 From: Jude Melton-Houghton Date: Sun, 9 Oct 2022 10:50:26 -0400 Subject: Optimize lighting calculation (#12797) --- src/nodedef.h | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'src/nodedef.h') diff --git a/src/nodedef.h b/src/nodedef.h index 8f0d0e9e8..044fdd8b2 100644 --- a/src/nodedef.h +++ b/src/nodedef.h @@ -505,10 +505,13 @@ struct ContentFeatures liquid_alternative_source_id == f.liquid_alternative_source_id; } - bool lightingEquivalent(const ContentFeatures &other) const { - return light_propagates == other.light_propagates - && sunlight_propagates == other.sunlight_propagates - && light_source == other.light_source; + ContentLightingFlags getLightingFlags() const { + ContentLightingFlags flags; + flags.has_light = param_type == CPT_LIGHT; + flags.light_propagates = light_propagates; + flags.sunlight_propagates = sunlight_propagates; + flags.light_source = light_source; + return flags; } int getGroup(const std::string &group) const @@ -580,6 +583,15 @@ public: return get(n.getContent()); } + inline ContentLightingFlags getLightingFlags(content_t c) const { + // No bound check is necessary, since the array's length is CONTENT_MAX + 1. + return m_content_lighting_flag_cache[c]; + } + + inline ContentLightingFlags getLightingFlags(const MapNode &n) const { + return getLightingFlags(n.getContent()); + } + /*! * Returns the node properties for a node name. * @param name name of a node @@ -826,6 +838,11 @@ private: * Even constant NodeDefManager instances can register listeners. */ mutable std::vector m_pending_resolve_callbacks; + + /*! + * Fast cache of content lighting flags. + */ + ContentLightingFlags m_content_lighting_flag_cache[CONTENT_MAX + 1L]; }; NodeDefManager *createNodeDefManager(); -- cgit v1.2.3