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

Geometry renderer #42227

Merged
merged 9 commits into from
Jul 26, 2020
Merged

Conversation

barsoosayque
Copy link
Contributor

@barsoosayque barsoosayque commented Jul 17, 2020

Summary

SUMMARY: Infrastructure "Decouple rectangle rendering in SDL related code"

Purpose of change

First of all, decoupling and documenting the rendering code. Making it more modular and easier to tweak.

I'm working on a fix for I-am-Erk/CDDA-Tilesets#133, more specifically: rendering a symbol in no sprite for item is found. I need fonts for that, and I can't use them since fonts are using hardcoded static variables and functions from sdltiles.cpp. To decouple fonts, I first need to decouple the mechanism to draw rectangles (since it actually uses two different implementations depending on options user selected).

Describe the solution

Introduce an interface which whole purpose is to render geometry. Use that interface instead of hardcoded functions.

Good:

  • Non-intrusive
  • Modular
  • Easy to understand and use

Bad:

  • vtables :(

Describe alternatives you've considered

Maybe using some template magic to reduce usage of virtual stuff. However, I don't think that is going to work, since that one option is known only at runtime, and this option decides what rectangle rendering mechanism to use.

Testing

Loaded up the game, everything works and renders. Color modulated option works. No performance impact is noticed.

@anothersimulacrum anothersimulacrum added [C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style SDL: Tiles / Sound Tiles visual interface and sounds. labels Jul 17, 2020
src/sdl_geometry.h Outdated Show resolved Hide resolved
src/sdl_utils.cpp Outdated Show resolved Hide resolved
@Qrox
Copy link
Contributor

Qrox commented Jul 18, 2020

No performance impact is noticed.

Have you tested using debug menu - info - draw benchmark?

@barsoosayque
Copy link
Contributor Author

Have you tested using debug menu - info - draw benchmark?

I haven't 😓 (Didn't know that was possible). Anyway, yes, the draw benchmark confirms that there is no performance decrease:

image

On the top is this PR, on the bottom -- master branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style SDL: Tiles / Sound Tiles visual interface and sounds.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants