Use cython fused types (templated functions) to remove redundancy from smp.pyx and smx.pyx #1370
Labels
area: assets
Involved with assets (images, sounds, ...)
good first issue
Suitable for newcomers
improvement
Enhancement of an existing component
lang: cython
Implemented using Cython code
Required skills: Cython
Difficulty: Medium
SMX is the graphics storage format in AoE2:DE. We export these files to PNG in the converter.
Because of the different storage formats and layers, the
process_drawing_cmds
function exists 3 times in smp.pyx, and 5 times in smx.pyx, both inopenage/convert/value_object/read/media/
.We can use one generic function (one for
smp
, one forsmx
) that can handle all of the features at once.We can do that using templates in Cython, called "fused functions".
Here's an example how it works in principle.
rolf
function is saved two times - once forvariant_1
and once forvariant_2
. And it won't have anyif
in its body then.if CompressionVariant is
lines behave likeif constexpr
inside a templated entity.We defined multiple variants of
process_drawing_cmds
to avoid a lot of branches (if
s) in the codepath, since this function is called more than a million times during the conversion process.You can test your changes with the singlefile media converter.
Further reading:
The text was updated successfully, but these errors were encountered: