Cache absent sections' coords in RelightCtx and handle ValueError from uncreatable sections.
This commit is contained in:
parent
16d3aa19fa
commit
7c58091558
@ -63,6 +63,7 @@ cdef class RelightCtx(object):
|
|||||||
cdef:
|
cdef:
|
||||||
map[section_key_t, RelightSection] section_cache
|
map[section_key_t, RelightSection] section_cache
|
||||||
map[chunk_key_t, RelightChunk] chunk_cache
|
map[chunk_key_t, RelightChunk] chunk_cache
|
||||||
|
set[section_key_t] absent_sections
|
||||||
|
|
||||||
object dimension
|
object dimension
|
||||||
unsigned char [:] brightness
|
unsigned char [:] brightness
|
||||||
@ -101,12 +102,24 @@ cdef class RelightCtx(object):
|
|||||||
# later as Cython attempts to decref the uninitialized memoryview and segfaults.
|
# later as Cython attempts to decref the uninitialized memoryview and segfaults.
|
||||||
cdef RelightSection cachedSection = [None, None, None, NULL, 0]
|
cdef RelightSection cachedSection = [None, None, None, NULL, 0]
|
||||||
cdef long long key = section_key(cx, cy, cz)
|
cdef long long key = section_key(cx, cy, cz)
|
||||||
|
|
||||||
|
# Fast exit for absent sections
|
||||||
|
if self.absent_sections.find(key) != self.absent_sections.end():
|
||||||
|
return NULL
|
||||||
|
|
||||||
if not self.dimension.containsChunk(cx, cz):
|
if not self.dimension.containsChunk(cx, cz):
|
||||||
return NULL
|
return NULL
|
||||||
chunk = self.dimension.getChunk(cx, cz)
|
chunk = self.dimension.getChunk(cx, cz)
|
||||||
section = chunk.getSection(cy, create=True)
|
try:
|
||||||
if section is None:
|
section = chunk.getSection(cy, create=True)
|
||||||
|
except ValueError:
|
||||||
|
self.absent_sections.insert(key)
|
||||||
return NULL
|
return NULL
|
||||||
|
|
||||||
|
if section is None:
|
||||||
|
self.absent_sections.insert(key)
|
||||||
|
return NULL
|
||||||
|
|
||||||
if self.section_cache.size() > CACHE_LIMIT:
|
if self.section_cache.size() > CACHE_LIMIT:
|
||||||
# xxx decache something!
|
# xxx decache something!
|
||||||
pass
|
pass
|
||||||
|
Reference in New Issue
Block a user