SFTtech / SFTtech/openage

Speed up converter terrain merging with Cython

Open
#1,369 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area: assets good first issue improvement lang: cython
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.frames in the Texture currently stores the terrain tiles as TextureImage objects. 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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.