Speed up converter terrain merging with Cython
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.4k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
Required skills: Cython, Python
Difficulty: Easy
The terrain textures in AoC and SWGB are stored as isometric* tiles (see https://github.com/SFTtech/openage/issues/141 for an example). In the converter, we merge all these tiles together to get the cartesian projection of the texture (also used in the HD Edition: see https://github.com/SFTtech/openage/issues/141#issuecomment-62250621). The cartesian projection has many advantages, the main one being that the image size is halved and the generated texture file smaller.
An algorithm for terrain merging has already been implemented here using Cython. You main goal is to improve the speed of the conversion by reducing the Python overhead of the function and adjusting the algorithm. Cython will generates a file that shows the overhead of the source file in bin/openage/convert/processor/export/texture_merge.html when you build the project. We want the Python overhead of the merge function to be as small as possible.
For your conveniance,we have made a list of things that could be improved. You should probably have a look at the code first though.
- The image rotation in line 142 uses a numpy function that could be implemented directly in our code.
- Currently, the algorithm is split into two steps: First all terrain tiles are merged into one big tile, then this tile is projected to cartesian. The initial merging step requires an alpha blend. We can skip the initial merging step by projecting each tile to cartesian directly and directly placing it in the correct position in the final image. This would halve the number of required pixel copy operations.
-
texture.framesin theTexturecurrently stores the terrain tiles asTextureImageobjects. The tiles could be instead be stored as numpy arrays which can be accessed faster with Cython's memoryviews.
You can test your changes with the singlefile media converter.
Further reading:
* Technically, the projection is a dimetric (or game isometric) projection. Keep that in mind, when you search the internet for it.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with openage/convert/processor/export/terrain_merge.pyx and inspect the generated bin/openage/convert/processor/export/texture_merge.html for Python overhead. Read the singlefile media converter guide and relevant converter architecture or workflow documentation before benchmarking. Done means the terrain conversion is faster with lower merge-function overhead while preserving the generated cartesian terrain textures.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- performance, tooling
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100