Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up converter terrain merging with Cython #1369

Open
1 of 3 tasks
heinezen opened this issue Jan 21, 2021 · 2 comments
Open
1 of 3 tasks

Speed up converter terrain merging with Cython #1369

heinezen opened this issue Jan 21, 2021 · 2 comments

Comments

@heinezen
Copy link
Task lists! Give feedback
Member

@heinezen heinezen commented Jan 21, 2021

Required skills: Cython, Python

Difficulty: Easy

The terrain textures in AoC and SWGB are stored as isometric* tiles (see #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 #141 (comment)). 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.

@zehuilu
Copy link

@zehuilu zehuilu commented Mar 26, 2021

Hello, can I take this?

@TheJJ
Copy link
Member

@TheJJ TheJJ commented Mar 26, 2021

Sure, you can just submit an early pull request and get help in the chatroom :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
convert
  
output
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants