1. Fixes DrawStringwithColors kerning fit handling and newline handling.
2. Splits tests into one file per function call, making it easier to compare diffs and add new tests.
Also adds `--update_expected` argument to update the expected files with actual results.
When using KerningFitSpacing with centered or right-aligned text,
adjust the horizontal start position after changing the spacing.
Co-authored-by: Gleb Mazovetskiy <glex.spb@gmail.com>
In C++, globals initialization order accross translation units is not
defined. Accessing a global via a function ensures that it is initialized.
This will be needed for #7638, which will statically initialize change
handlers after the Options object has been initialized.
1. Moves more assets-related stuff from `init` to `engine/assets`.
2. Removes `SDL_audiolib` dependency from `soundsample.h`.
3. Cleans up some unused/missing includes.
Untangles dependencies by splitting up `engine.{h,cpp}` into 3 files:
1. `primitive_render`
2. `ticks` -- only contains `GetAnimationFrame` for now.
3. `GetWidth2` renamed to `CalculateSpriteTileCenterX` and moved to `levels/dun_tile.hpp`.
1. Do not draw foliage with the pause trn.
2. Display the number of steps.
3. If the tile is not walkable (allowed for destination tile), display
the number of steps in yellow.
Stairs can have the same `TileProperties` as floors but do not
always follor the same graphics layout as floors, so we shouldn't
apply optimizations to them.
The only floors affected seem to be:
1. Caves: tile 48 sub-tile 171 frame 461 (TileProperties: None)
2. Hell: tile 46 sub-tile 141 frame 386 (TileProperties: BlocksMissile)
Note that the few broken in pixels in caves are actually incorrectly
attributed to the non-Solid tile, really they should be part of the
solid tile 49.
As there doesn't seem to be a quick and easy way to check if a frame
is part of Stairs, we add a check for BlocksMissile tile property
instead.
This fixes Hell but isn't enough to fix Caves.
To fix Caves, we then add a `BlocksMissile` flag to the broken sub-tile.
`dev.display.grid()` previously tanked the FPS even on my beefy machine.
It is now much faster.
I've also noticed that the grid is glitchy when but this is also the
case before this PR.
During `ReencodeDungeonCels`, extracts floor tile foliage into
a triangle with the floor frame and a separate 16-px tall `TransparentSquare`.
This means that the floor frames are now always triangles and
the foliage can be rendered directly without masking.
Dungeon graphics sizes:
Map | Frames | Foliage frames | Byte size | Before PR | After PR
-----|--------|---------------:|-----------:|----------:|----------:
Town | 3,803 | 41 | 2,317,832 | 2,242,056 | 2,242,190
L1 | 1,119 | 11 | 738,836 | 721,604 | 721,110
L4 | 1,091 | 6 | 603,140 | 584,500 | 584,242
RG99 binary size reduced by ~4 KiB: 2,426,380 bytes -> 2,421,388 bytes
Previously, there were 2 loops to render all the lines of a diamond.
This changes it to call `RenderLeftTriangle` + `RenderRightTriangle`.
That's 4 loops + some extra clipping calculations
Yet, this version is ~28% faster.
I don't understand why it's faster at all.
Perhaps it's only faster on some hardware?
Modern computers are magic.
Anyway, here are the (very surprising) results on my Ryzen 3950x:
```
BASELINE=master
BENCHMARK=dun_render_benchmark
git checkout "$BASELINE"
tools/build_and_run_benchmark.py -B "build-reld-${BASELINE}" --no-run "$BENCHMARK"
git checkout -
tools/build_and_run_benchmark.py --no-run "$BENCHMARK"
tools/linux_reduced_cpu_variance_run.sh ~/google-benchmark/tools/compare.py -a benchmarks \
"build-reld-${BASELINE}/${BENCHMARK}" "build-reld/${BENCHMARK}" \
--benchmark_filter='.*BlackTile.*' --benchmark_repetitions=10
```
```
Comparing build-reld-master/dun_render_benchmark to build-reld/dun_render_benchmark
Benchmark Time CPU Time Old Time New CPU Old CPU New
------------------------------------------------------------------------------------------------------------------------
BM_RenderBlackTile_pvalue 0.0002 0.0002 U Test, Repetitions: 10 vs 10
BM_RenderBlackTile_mean -0.2786 -0.2786 156 113 156 113
BM_RenderBlackTile_median -0.2808 -0.2808 157 113 157 113
BM_RenderBlackTile_stddev -0.3148 -0.3138 1 1 1 1
BM_RenderBlackTile_cv -0.0503 -0.0488 0 0 0 0
OVERALL_GEOMEAN -0.2785 -0.2786 0 0 0 0
```