Commit Graph
225 Commits
Author SHA1 Message Date
qndel 731ad1ada5 use std::rotate (#6019) 2023-04-22 13:53:03 +02:00
Anders Jenbo dc2d97c112 Split lighting shades from trn tables 2023-04-21 07:40:19 +02:00
Anders Jenbo ec9d1b5550 Rename _oLight to applyLighting 2023-04-19 19:41:10 +02:00
Gleb Mazovetskiy ac0627f029 Add a debug function that describes a CLX
Example output (also demonstrates a bug in our encoder):

CLX sprite: 16x20 pixelDataSize=97b

command | width | bytes | color(s)
--------|------:|------:|---------
Transp. |    80 |     1 |
Pixels  |     2 |     3 | 203 199
Fill    |     3 |     2 | 202
Pixels  |     2 |     3 | 199 201
Fill    |     1 |     2 | 205
Transp. |     8 |     1 |
Pixels  |     3 |     4 | 205 199 196
Fill    |     4 |     2 | 197
Fill    |     1 |     2 | 202
Transp. |     9 |     1 |
Pixels  |     6 |     7 | 206 199 197 203 206 202
Fill    |     1 |     2 | 204
Transp. |    10 |     1 |
Pixels  |     4 |     5 | 206 199 197 205
Fill    |     1 |     2 | 207
Transp. |    12 |     1 |
Pixels  |     3 |     4 | 206 197 197
Fill    |     1 |     2 | 205
Transp. |     9 |     1 |
Pixels  |     7 |     8 | 207 205 203 206 206 197 197
Fill    |     1 |     2 | 206
Transp. |     8 |     1 |
Pixels  |     3 |     4 | 204 197 199
Fill    |     1 |     2 | 205
Transp. |     1 |     1 |
Pixels  |     2 |     3 | 202 197
Fill    |     1 |     2 | 204
Transp. |     8 |     1 |
Pixels  |     7 |     8 | 206 197 199 207 206 199 196
Fill    |     1 |     2 | 205
Transp. |     9 |     1 |
Pixels  |     1 |     2 | 203
Fill    |     4 |     2 | 197
Fill    |     1 |     2 | 202
Transp. |    10 |     1 |
Pixels  |     5 |     6 | 207 205 199 199 203
Fill    |     1 |     2 | 207
Transp. |    89 |     1 |
2023-04-11 08:50:07 +02:00
Gleb Mazovetskiy 8408743eed Draw item labels before the monster health bar
Fixes #5867
2023-03-26 11:57:49 +01:00
Gleb Mazovetskiy 3f0d089928 Blitter: Minor optimization
`src < end - 3` is one more instruction than `src + 3 < end`.

Godbolt: https://godbolt.org/z/PPfhYYWG8

RG-99 binary becomes 224 bytes smaller.
2023-03-24 11:50:49 +00:00
Gleb Mazovetskiy e81f8affba Fix rendering issues introduced by #5913
Fixes #5914
2023-03-23 11:43:50 +01:00
Gleb Mazovetskiy 774993c6d0 dun_renderer: Avoid calling 0-width Blit*
A slight optimization to avoid calling blit functions entirely
when the width is zero.
2023-03-22 10:30:06 +00:00
Gleb Mazovetskiy 397529bf0f Rendering: Unify and optimize pixel blitters
1. Unifies the underlying CLX and dun_render blitters.
2. Optimizes them by unrolling loops and using pointer comparison rather
   than length comparison (saves a length decrement).
3. In `dun_render`, extracts `RenderLineTransparent/Opaque` branches into
   functions via explicit template specialization.

Example RG-99 FPS (non-PGO'd): 17.4->18.4
2023-03-21 13:42:23 +00:00
obligaron 36ecc50fcb Always use infravision in Arenas 2023-03-13 01:00:30 +01:00
Gleb Mazovetskiy 957bd03b98 Remove FMT_COMPILE in "cold" places
Removes most `FMT_COMPILE` calls.
`FMT_COMPILE` results in better performance but larger code size.

Removes `FMT_COMPILE` calls for places that are called infrequently,
i.e. not on every frame.

RG-99 binary size reduced by ~4 KiB.
2023-03-12 19:29:35 +01:00
Gleb Mazovetskiy f7580f188c Fix multiline DrawStringWithColors alignment
For center or right alignment, the lines past the first line were
aligned incorrectly. The alignment was based on the width of the
format string.
2023-02-14 09:42:14 +00:00
KPhoenix a1fbf5253f enum talk_id -> enum class TalkID 2023-02-09 13:04:01 +01:00
Gleb Mazovetskiy 98294e0ad5 Optimize MissileData: 32 bytes -> 24
23 bytes used, 1 spare byte in the padding.
2023-02-07 08:08:04 +01:00
Gleb Mazovetskiy 0a6a8e8aa0 Clean up missile data access
Replace enum static casts with `GetMissile(Sprite)Data`.
2023-02-03 14:37:44 +00:00
KPhoenix 7947b99511 Implement new enum class 2023-02-03 05:05:12 +01:00
Gleb Mazovetskiy 1788d2f8ec Remove miniwin
Event handling code moved to `engine/events.{hpp,cpp}`.
2023-02-01 16:06:57 +00:00
staphen dd6ce177f7 Derive viewport geometry from player position 2023-01-30 04:22:33 +01:00
Gleb Mazovetskiy 527e876fff Disable item labels when in store
Also disable ground item outlines on hover when in store.
2023-01-22 15:58:12 +01:00
c99f7cf644 Floating numbers (#5639)
Co-authored-by: qndel <[email protected]>
Co-authored-by: Stephen C. Wills <[email protected]>
2023-01-22 07:20:10 +01:00
KPhoenix 8db521727d enum missile_id -> enum class MissileID
Changes `enum missile_id` to `enum class MissileID`
2023-01-18 17:17:25 +00:00
Anders Jenbo e50e21e0e4 Use outline for spell icon texts 2023-01-12 11:04:53 +01:00
Anders Jenbo bb2463862c Use Position in AddItemToLabelQueue() 2023-01-12 09:56:47 +01:00
Anders Jenbo a29fc3a074 Correct casing for Player::isWalking() 2023-01-12 09:42:49 +01:00
Gleb Mazovetskiy f4b8edb5dc Surface.pitch(): int -> uint16_t 2022-12-14 10:12:24 +01:00
Gleb Mazovetskiy e06ca9a016 dun_render: Remove unused argument from RenderTile
Now that we pass the mask into `RenderTile`, we no longer need to pass
`levelPieceId`.
2022-12-14 10:12:24 +01:00
Gleb Mazovetskiy aa2f88e5f6 Remove software cursor state for hardware cursor
Switching between software and hardware cursor could cause a glitch
as described in #5560.

Fixes #5560
2022-12-08 12:09:36 +01:00
Gleb Mazovetskiy 1addfc9e54 dun_render: Deduplicate trapezoid upper half 2022-12-05 05:17:24 +01:00
Gleb Mazovetskiy 63a042d0e3 dun_render: Simplify non-masked primitives
As we recently confirmed, Square and Left/RightTriangle primitives
never use masks other than Transparent and Solid.

Simplify the code to take advantage of that.
2022-12-05 05:17:24 +01:00
Gleb Mazovetskiy 55d25fd079 dun_render: Swap32LE the data offset 2022-12-05 05:05:55 +01:00
Gleb Mazovetskiy 79b330825d dun_render: Avoid Invalid tile type
1. Do not call `RenderTile` with invalid values to begin with.
2. Move mask selection out of `RenderTile`.
2022-12-05 01:32:29 +01:00
Gleb Mazovetskiy 44ed0296d8 dun_render: Overhaul mask handling
We notice that masks can be described by 2 parameters:

1. Whether they have 0 or 1 as their high bits.
2. Whether they shift to the left or to the right on the next line.

Describing masks this way allows us to lift them to template variables and simplify the code.
We also avoid handling the mask in the `RenderLine` loop entirely.

Also fixes a foliage rendering bug: Transparent foliage pixels were previously blended but they should have been simply skipped.
2022-12-04 21:53:52 +01:00
Gleb Mazovetskiy 5024bc0f07 Show FPS up to 1 decimal point
If FPS < 100, print it with 1 decimal point.
Useful for measuring performance impact on low-end devices.
2022-12-03 21:42:18 +01:00
Gleb Mazovetskiy 7a3882722e Text rendering and chat input fixes
1. Fixes the return value (bytes rendered).
2. Fixes line wrapping / end-of-rendering based on the given rectangle:
   1. Accounts for `BaseLineOffset`.
   2. Fixes an off-by-one error for the y coordinate.
   3. Wraps the cursor when needed.
3. Fix chat input box dimensions (height is 3 * line height).
4. Set the hint that indicates that we do not render the current
   IME suggestion (SDL_TEXTEDITING). This indicates to IME
   that it should render the suggestion instead.
2022-11-27 22:40:20 +00:00
Gleb Mazovetskiy aca4aae3c1 dun_render: Remove the use of LightTableIndex
Replaces the global with an argument.
2022-11-25 15:00:04 +01:00
Gleb Mazovetskiy 3afef6299f Level renderer: Remove cel_transparency/foliage_active globals 2022-11-25 15:00:04 +01:00
Gleb Mazovetskiy 1293dfb86d Level renderer: Remove level_piece_id global
`DrawFloor` now passes the piece ID into RenderTile.
Previously, `DrawFloor` did not set `level_piece_id`.
2022-11-25 14:16:30 +01:00
Gleb Mazovetskiy c616e0d6d2 Level renderer: Remove arch_draw_type global 2022-11-25 14:16:30 +01:00
Gleb Mazovetskiy 69c429bb68 Level renderer: Remove level_cel_block global 2022-11-25 14:16:30 +01:00
Gleb Mazovetskiy 5ac54027dc Text rendering: Clip text to the given rect
Previously, we only clipped to the given surface, without clipping to the given rect.
2022-11-22 04:54:21 +01:00
Gleb Mazovetskiy a7324a15c0 Item labels: Clip to viewport
Instead of redrawing the panel to avoid item label clipping, clip the labels themselves.
2022-11-22 03:14:58 +00:00
Gleb Mazovetskiy 9db80ef5d7 Assets: Load files directly for UNPACKED_MPQS
When using `UNPACKED_MPQS`, avoid all the SDL machinery for reading
files.

This is beneficial not only due to reduced indirection but also because
we can test for the file's existence and get the file size without
opening it, which is much faster.
2022-11-22 02:44:25 +01:00
Gleb Mazovetskiy 4c0b43508a DoBlitScreen: Fix update rects
Fixes chat input at 640x480.

Also fixes the other rects, they were slightly off.
2022-11-17 14:25:03 +01:00
obligaron dc3d797269 GetOffsetForWalking: use uint8_t for animation fraction 2022-11-11 13:29:00 +00:00
obligaron eca1a68bec AnimationInfo: Use fixed point math for fractions 2022-11-06 12:31:40 +00:00
Gleb Mazovetskiy 1da4be3839 Fix chat
Accidentally broken by #5453
2022-11-02 11:19:00 +00:00
Gleb Mazovetskiy 680ab5ec40 Overhaul backbuffer state handling
When rendering directly to the output buffer, we need to maintain the
state of what has been drawn and what needs redrawing per-buffer.

We previously tried to do it implicitly by checking `SDL_DOUBLEBUF` and
other flags. The previous implementation was broken in several
ways, resulting in rendering issues on devices that support 8-bit output
directly.

Changes this mechanism to explicitly maintain buffer state per output
buffer. The new mechanism doesn't require knowledge of the number of
buffers, and thus also works correctly with triple-buffering.

Fixes #5447
2022-11-01 02:43:24 +00:00
Gleb Mazovetskiy 0498d7d3a7 Fix compilation warnings 2022-10-29 13:41:23 +01:00
Gleb Mazovetskiy 41f43ea3f5 Support unpacked MPQs from devilutionx-mpq-tools
https://github.com/diasurgical/devilutionx-mpq-tools produces an unpacked MPQ
with all the graphics converted to CLX and the unused files removed.
This is primarily useful on RAM-constrained platforms, such as PS2,
because it eliminates the MPQ overhead.

Adds a build option to load from such unpacked directories instead of the MPQ.

These directories are searched for in the same locations
where the MPQs would be searched for otherwise.

Example directory layout:

* /usr/local/share/diasurgical/devilutionx/diabdat/ -- unpacked and converted diabdat.mpq
* /usr/local/share/diasurgical/devilutionx/hellfire/ -- unpacked and converted hellfire MPQs (all of them merged into 1 directory)
* /usr/local/share/diasurgical/devilutionx/fonts/ -- unpacked fonts.mpq
* /usr/local/share/diasurgical/devilutionx/pl/ -- unpacked pl.mpq

These directory structure is produced by calling `unpack_and_minify_mpq`
2022-10-11 18:00:57 +01:00
staphen 5de080541a Ensure that the last line of text does not exceed the lower bounds of the rectangle in DrawString() 2022-10-02 08:51:24 +02:00