Commit Graph
365 Commits
Author SHA1 Message Date
qndel 731ad1ada5 use std::rotate (#6019) 2023-04-22 13:53:03 +02:00
staphen 3e60df5111 Apply u8path() to paths passed into std::filesystem API calls 2023-04-22 05:53:47 +02:00
Gleb Mazovetskiy f616214020 Fix suboptimal CLX encoding
See https://github.com/diasurgical/devilutionx-graphics-tools/pull/3 for
details
2023-04-10 17:42:13 +02:00
Gleb Mazovetskiy e35595a1eb StrCat improvements
1. Use `fmt::format_int` directly instead of parsing a format string.
2. Use `AppendStrView`.
3. Define the varargs versions using fold expressions when available.
4. Add tests.
2023-03-13 10:20:38 +00: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 f2cb9f0fa0 file_util: Implement RecursivelyCreateDir
With this, we no longer require `std::filesystem` support to create the
save file directory when it does not exist.

Note that by default the save file directory exists because it is
created by SDL, so this is mostly useful on platforms that override the
save directory or use `UNPACKED_SAVES`.
2023-03-11 17:47:29 +00:00
Gleb Mazovetskiy 5c3f14d661 Fix crash with locale=ja and missing fonts.mpq 2023-02-19 12:58:17 +00:00
Gleb Mazovetskiy 1a1a282d9a Use C FILE instead of C++ streams throughout
Reduces binary size by ~2 KiB and may improve compatibility with oddball
systems (e.g. PS2).
2023-02-15 18:15:07 +00:00
Gleb Mazovetskiy 37f4d0cb97 CreateHalfSizeItemSprites: Reuse surfaces
Rather than allocating surfaces on every loop iteration, reuse the same
2 surfaces.
2023-01-24 04:41:34 +00:00
Gleb Mazovetskiy 0fb9599e66 StaticVector: Replace std::aligned_storage_t
`std::aligned_*` are deprecated in C++23 per
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p1413r3.pdf
2023-01-22 22:15:07 +00:00
Gleb Mazovetskiy beb6fc2aaf CreateAulibResampler: Check the real sample rate
The requested sample rate is merely preferred and the actual rate may be
different.
2023-01-22 18:24:05 +01:00
Gleb Mazovetskiy 0e0cc9d1b0 Reduce to just STREAM_ALL_AUDIO_MIN_FILE_SIZE
This does result in a bit more code and RAM usage for soundsample when
`STREAM_ALL_AUDIO` is on, but not by much.
2023-01-22 15:19:50 +00:00
Gleb Mazovetskiy 0dd95adcd1 Add a minimum threshold for STREAM_ALL_AUDIO 2023-01-22 15:19:50 +00:00
staphen af5dc9ccb6 Add item graphics to store menus 2023-01-22 00:39:20 +01:00
Gleb Mazovetskiy 3ab2f49a92 Audio: Avoid creating same-rate resamplers
Each resampler allocates an input buffer and an output buffer.

Since we create ~100 audio stream objects (1 per `sfx_MISC` effect),
the memory cost of these buffers adds up.

Avoids creating a resampler when the audio sampler rate matches the
output sample rate. This is mostly the case when the output sample
rate is 22050.
2023-01-19 13:09:31 +01:00
Gleb Mazovetskiy 6d274c9547 UNPACKED_SAVES: Saves without MPQs
Reduces rg99 binary size by ~70 KiB.
2023-01-18 23:40:30 +00:00
Gleb Mazovetskiy f20c58c8a0 SoundSample::SetChunkStream: Log filename on error 2023-01-17 21:17:37 +00:00
Gleb Mazovetskiy 5bf9dfd7ee Demo mode: Force resolution to that of the demo 2023-01-12 03:38:29 +00:00
Gleb Mazovetskiy 8fe8023542 Create save and config directories
If a config directory did not exist, the ini file was
not saved at all.

Only implemented for targets that support `std::filesystem` or `std::experimental::filesystem`.
These are all the targets except nxdk and iOS (only supported on iOS 13+).
2023-01-12 03:28:28 +00:00
Gleb Mazovetskiy 56cd425396 Fix switching locale from English
The locale code used the `forceLocale = "en"` fallback when
the locale was set to English, so switching from English
did not actually change the language.
2022-12-26 15:46:17 +01:00
Gleb Mazovetskiy ca69237d59 Big-endian support for multiplayer
Not sure if this works but it's a start
2022-12-15 05:59:17 +01:00
Gleb Mazovetskiy 56f94c7471 Add a --lang command line argument
This allows forcing the locale without changing the settings.

The `forceLocale` option also lets us avoid changing the locale in settings if fonts.mpq is missing, fixing the following scenario:
1. System locale is ja
2. Launch the game -- fonts are missing
3. Close the game, download fonts.mpq
4. Launch the game again -- it is now in English because the settings have changed
2022-12-10 02:26:11 +00:00
Gleb Mazovetskiy c7338f2f48 language.cpp: Load whole translations file if MPQ
Fixes very slow translation loading from MPQs.

Compressed MPQs files are very slow to seek in.
If the RWops is and MPQ, load the whole file first.
2022-12-09 11:15:13 +00:00
Gleb Mazovetskiy aa9c0f9401 language.cpp: Minor cleanups 2022-12-09 11:15:13 +00:00
Gleb Mazovetskiy cffb2566df Fix timedemo on SDL1 2022-12-09 12:05:54 +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 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 4e9bb0e704 Fix gold withdrawal in SDL1
1. Unifies SDL1 and SDL2 text input handling.
2. Moves game-specific text input handling out of misc_msg.
3. Disables Unicode processing when not inputting text in SDL1.

This fixes gold withdrawal in SDL1.
2022-11-27 20:09:54 +00:00
Gleb Mazovetskiy dc3908e360 assets.cpp: Switch to C FILE for UNPACKED_MPQS
Eliminates some of the (minor) overhead of fstream.
2022-11-22 02:44:25 +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
Artur Jarosik 8bee40dca4 Fix amiga build (#5479) 2022-11-16 13:01:02 +01:00
Gleb Mazovetskiy 6dca019de2 Use function_ref instead of function
`function_ref` is a lightweight function pointer,
whereas `std::function` always involves a heap allocation.
2022-11-02 11:46:15 +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
staphen e67e4934cc Add padmapper for gamepad customization 2022-10-17 01:01:21 +02: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
Gleb Mazovetskiy 9feb3139e2 Add XDG_DATA_DIRS to MPQ search paths
Fixes #5304
2022-08-29 15:12:27 +01:00
staphen a3e94d6b55 [Switch] Bundle assets directly in romfs 2022-08-21 06:41:35 +02:00
staphen 5a2b167728 [3DS] Bundle assets directly in romfs 2022-08-21 05:41:04 +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
Anders Jenbo f6b167683c Correct some header includes (#5239) 2022-08-15 10:57:28 +09:00
Anders Jenbo 6f44b48f4e Use SDL for creating file during RW test 2022-08-13 23:58:22 +02:00
Gleb Mazovetskiy 9b65eca49b Remove Art and related functions 2022-08-08 14:29:45 +01:00
obligaron 9f5e032c7a CelToClx: Fix writing frame count with multiple groups 2022-08-06 08:16:58 +02:00
Gleb Mazovetskiy ed3747dded Add SurfaceToClx conversion function 2022-08-04 15:16:00 +02:00
Gleb Mazovetskiy ef46d99ccc Unify CLX pixel encoding code 2022-08-04 15:16:00 +02:00
Gleb Mazovetskiy ba34bafb3f Use SDL events directly
Removes redundant miniwin events and queue, using SDL events directly instead.

Demo migrated using this script: https://gist.github.com/glebm/8a73b04f695de96f344cc2e35151e03e
2022-08-03 03:50:19 +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
Vladimir Olteanu 74232f13bf Get rid of dthread 2022-08-03 02:18:54 +02:00
Gleb Mazovetskiy 5ad03478dc Missing fonts.mpq: Show an error, fall back to en
If the language is set to one of the locales that requires extra fonts
and `fonts.mpq` is missing, show an error dialog and fall back to English.
2022-07-31 15:53:26 +02:00
Andrew James fb2fae12e7 use correct attribute -_- (#5084) 2022-07-22 11:15:47 +01:00