Commit Graph
112 Commits
Author SHA1 Message Date
obligaron 95940a4c7e Fix MSVC warnings in engine\render\* 2023-11-08 17:03:19 +01:00
Gleb Mazovetskiy e02dc1f9dd Console input: Word-wrap-related cursor fixes
1. Handle word breaks in the prompt, e.g. `"> " -> "\n"`.
2. Handle word breaks in the original newline for all whitespace, not just `"\n"`.
2023-11-06 21:42:58 +00:00
Gleb Mazovetskiy b30b712cbb Lua: Add basic autocomplete in the console 2023-11-03 19:19:45 +00:00
Gleb Mazovetskiy dbfa204944 Lua: Set warn function
Previously, warnings went nowhere.
2023-11-02 15:16:31 +01:00
Gleb Mazovetskiy 17d5f05ada Fix some compilation warnings 2023-11-02 00:42:44 +00:00
Gleb Mazovetskiy 3ea4996367 Add a basic Quake-style console
Enabled only in Debug mode.

Runs Lua similar to the `lua` CLI.
Supports multiline input with Shift+Enter.

Missing features:
1. Scrollback.
2. Input history on up/down.

Open with backtick, close with Esc.
2023-10-31 23:19:56 +00:00
Gleb Mazovetskiy 55b0fc5c26 Text inputs: Selection, copy, cut
Adds shift selection, Ctrl+C, and Ctrl+X handling.

Also fixes left-right movement for non-ASCII characters.
2023-10-30 20:34:12 +00:00
Gleb Mazovetskiy e5881688f4 text_render: Replace optional args with struct
4 options args are a bit unwieldy, especially when you want
to pass only the first and the last one.

With a struct, there is no need to specify the default values
for the args in between.
2023-10-25 09:19:14 +01:00
Gleb Mazovetskiy fdb5738815 Add cursor support to DiabloUI and chat
Supports move left/right/home/end, backspace, delete, and Ctrl+V.
2023-10-24 01:56:54 +01:00
staphen 61e51f2349 Additional cleanup for WordWrapString() 2023-10-15 12:42:39 +02:00
staphen 99bf0e4e3c Insert newline for words longer than width in WordWrapString() 2023-10-15 12:42:39 +02:00
Gleb Mazovetskiy cbf51cd5ab DrawStringFormatArg: Use std::variant 2023-08-18 02:14:01 +09:00
Gleb Mazovetskiy 8c1a847f41 Remove utils/stdcompat/string_view.hpp 2023-08-14 09:59:14 +01:00
Gleb Mazovetskiy 14540164a7 Remove utils/stdcompat/optional.hpp 2023-08-14 01:54:29 +01:00
Gleb Mazovetskiy 7a5e5f73e6 Support language-specific font variants
Refs #3538
2023-08-12 17:44:30 +02:00
Gleb Mazovetskiy 8101e2c0ba Add c_any_of and friends
Adds handy helpers for performing algorithms on the entire container.
They're prefixed with `c_` for container.

This naming convention is identical to some popular C++ libraries, such
as Abseil.
2023-08-12 16:24:01 +01:00
Gleb Mazovetskiy d6b7949dab Fonts: Use pre-cropped CLX sprites
Built-in font size decreased by 121,587 bytes
(2,287,332 -> 2,165,745).

Fixes #6361
2023-07-16 06:02:19 +02:00
Anders Jenbo e8910bb3d7 Do not crash on missing fonts 2023-06-24 03:26:13 +02:00
Gleb Mazovetskiy 4fa3732526 Add missing <cstdint> includes
Done with the following script:

```ruby
Dir["Source/**/*.{h,c,cc,cpp,hpp}"].each do |path|
  v = File.read(path)
  next if !v.include?("uint32_t") || v.include?("cstdint")

  lines = v.lines
  line_num = if lines[2].start_with?(" *")
    lines.index { |l| l.start_with?(" */") } + 3
  else
    3
  end

  lines.insert(line_num, "#include <cstdint>\n")

  File.write(path, lines.join(""))
end
```

then fixed-up manually
2023-05-10 13:50:12 +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
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
Anders Jenbo e50e21e0e4 Use outline for spell icon texts 2023-01-12 11:04:53 +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 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 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 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
staphen e580c26a1f Ensure that vertically aligned text does not exceed the upper bounds of the rectangle in DrawString() 2022-10-02 08:51:24 +02:00
Gleb Mazovetskiy 6327e713e0 Lowercase all file paths
We want to be able to use unpacked MPQs on low-end platforms
(PS2/rg99/etc).

This is tricky on case-sensitive filesystems. Avoids case issues by
lowercasing all paths in the code (then we'll just need lowercased
listfiles).
2022-08-20 23:49:23 +01:00
Gleb Mazovetskiy 9b65eca49b Remove Art and related functions 2022-08-08 14:29:45 +01:00
Gleb Mazovetskiy d71a54dba8 Render main panel buttons as CLX
Converted with:

```
pcx2clx --num-sprites 3 data/talkbutton.pcx && rm data/talkbutton.pcx
```

Sizes:

```
Surface(63, 114) -> CLX	7296 -> 5336	-26.9%
Surface(53, 48) -> CLX	2688 -> 2324	-13.5%
```
2022-08-04 15:16:00 +02:00
Gleb Mazovetskiy 8f7dd16ac3 Show an error on outdated devilutionx/font.mpq 2022-08-03 16:37:04 +02:00
Gleb Mazovetskiy 17a97450bc Convert assets to CLX
Converted using the following commands:

```
cd Packaging/resources/assets
pcx2clx --transparent-color 1 --num-sprites 256 fonts/*.pcx && rm fonts/*.pcx
pcx2clx --num-sprites 2 ui_art/dvl_but_sml.pcx && rm ui_art/dvl_but_sml.pcx
pcx2clx --transparent-color 1 data/hintbox.pcx data/hintboxbackground.pcx && rm data/hintbox.pcx data/hintboxbackground.pcx
pcx2clx --transparent-color 1 --num-sprites 6 data/hinticons.pcx && rm data/hinticons.pcx
pcx2clx --num-sprites 2 data/panel8buc.pcx data/dirtybuc.pcx data/dirtybucp.pcx && rm data/panel8buc.pcx data/dirtybuc.pcx data/dirtybucp.pcx
pcx2clx --transparent-color 1 data/healthbox.pcx && rm data/healthbox.pcx
pcx2clx --transparent-color 1 --num-sprites 6 data/resistance.pcx && rm data/resistance.pcx
pcx2clx --transparent-color 1 --num-sprites 5 data/monstertags.pcx && rm data/monstertags.pcx
pcx2clx --transparent-color 1 data/stash.pcx && rm data/stash.pcx
pcx2clx --transparent-color 1 --num-sprites 5 data/stashnavbtns.pcx && rm data/stashnavbtns.pcx
pcx2clx **/*.pcx && rm **/*.pcx
git checkout master -- ui_art/black_diablo.pcx ui_art/black_hellfire.pcx data/charbg.pcx data/talkbutton.pcx data/panel8bucp.pcx
rm ui_art/black_diablo.clx ui_art/black_hellfire.clx data/charbg.clx data/talkbutton.clx data/panel8bucp.clx
```
2022-08-03 16:37:04 +02:00
Gleb Mazovetskiy 961866e1c4 CLX: A new graphics format
The format is almost identical to CL2, except it uses the frame header
to store frame width and height instead of 5 32-line offsets.

This means we always have access to frame dimensions, so we can use it
as an on-disk format for our graphics as well.

Additionally, we may be able to optimize the rendering even more
in the future now that we have guaranteed knowledge of frame dimensions.
2022-08-03 02:38:55 +02:00
Gleb Mazovetskiy 0cd035ef61 Load PCX as CL2
Similar to #5059, which converted CEL to CL2 at load time,
we now do the same for PCX.

Some size stats: https://gist.github.com/glebm/067bf1ec73f9d14514932cfe237e4e8e

Notably, fonts RAM usage is decreased by ~35%.
2022-07-20 22:58:15 +01:00
Gleb Mazovetskiy 8ca71272b8 Load all CEL as CL2
Convert CEL files to CL2 at load time. CL2 format is more efficient and is about as fast to render.

CEL vs CL2 sizes, on dLvl 5: https://gist.github.com/glebm/9bbdd76962abcd4fd2405ecd3379af97

Memory:

* Peak memory (while loading): -300 KiB
* Memory in-game (dLvl5): -700 KiB
* RG99 binary size: -15 KiB (1333096 -> 1317192)

Performance on rg99:

* On average, -1 FPS in town.
* Same FPS in dungeon (20 FPS on dLvl 1).
2022-07-19 10:59:35 +02:00
Gleb Mazovetskiy d152d2c0fb Add OptionalOwnedCelSprite 2022-07-03 12:26:39 +01:00
Gleb Mazovetskiy 3178dd5158 Replace most uses of sprintf with fmt (#4837) 2022-07-01 17:02:56 +02:00
Anders Jenbo 72656b3011 Move path and palette to the engine folder 2022-06-24 16:34:20 +02:00
Gleb Mazovetskiy 8e9c9e0238 Reduced the size of OwnedCelSprite* by 8 bytes
`OwnedCelSpriteWithFrameHeight`: 40 -> 32
2022-06-20 01:11:22 +02:00
Gleb Mazovetskiy 02d448267a Render fonts as PCX (-420 KiB RAM)
Reduces peak memory consuption in game by ~420 KiB.

This is because the PCX renderer applies the palette on the fly while
rendering, meaning we do not need to duplicate the font for different
palettes.

This approach is also a bit slower than precomposed palettes (still
plenty fast).
2022-06-15 16:59:59 +02:00
Gleb Mazovetskiy 1fc8ecb6f6 Add fmt::runtime annotations for C++20 support
`fmt` requires non-contexpr format string arguments to be wrapped in
`fmt::runtime` in C++20.
2022-06-14 12:46:36 +01:00
qndel f84c35d2dc fix typos 2022-06-01 17:12:22 +02:00
Gleb Mazovetskiy 961e1b584b Always load fonts as CEL
There appear to be no drawbacks, only advantages.
2022-04-25 05:31:26 +01:00
Gleb Mazovetskiy 978bae1a15 Add a helper for loading PCX as CEL from path 2022-04-25 05:31:26 +01:00
Gleb Mazovetskiy 2b161e5535 An option to convert fonts to CEL in-memory
Reduced RAM usage by 200 KiB with no performance drop, perhaps even an
improvement.
2022-04-25 05:31:26 +01:00
Gleb Mazovetskiy a66ca44695 Zero-based frame indexing
Index frames starting at 0 instead of 1.
2022-04-14 04:39:26 +01:00
Gleb Mazovetskiy ade8aba822 Fix some more warnings 2022-04-14 01:26:29 +02:00
ephphatha 93068de918 Address type conversion warnings in WordWrapString 2022-04-03 14:56:01 +02:00