diff options
| author | Jude Melton-Houghton <jwmhjwmh@gmail.com> | 2022-10-09 10:50:26 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-09 10:50:26 -0400 |
| commit | 9676364c1fe5fe5eae69c55e7d7a45392decfb2d (patch) | |
| tree | b21c99ce54820b24bfef9028c39b01f28ed3c1ca /src/nodedef.h | |
| parent | 440d966b939059dfa51604eb68d61eecb12baeb4 (diff) | |
| download | minetest-9676364c1fe5fe5eae69c55e7d7a45392decfb2d.tar.xz | |
Optimize lighting calculation (#12797)
Diffstat (limited to 'src/nodedef.h')
| -rw-r--r-- | src/nodedef.h | 25 |
1 files changed, 21 insertions, 4 deletions
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<NodeResolver *> m_pending_resolve_callbacks; + + /*! + * Fast cache of content lighting flags. + */ + ContentLightingFlags m_content_lighting_flag_cache[CONTENT_MAX + 1L]; }; NodeDefManager *createNodeDefManager(); |
