Commit Graph
70 Commits
Author SHA1 Message Date
Gleb Mazovetskiy 8c1a847f41 Remove utils/stdcompat/string_view.hpp 2023-08-14 09:59:14 +01:00
Gleb Mazovetskiy e9b5ec77f9 Remove AppendStrView 2023-08-14 01:54:29 +01:00
Gleb Mazovetskiy 74755c8be7 Remove utils/stdcompat/cstddef.hpp 2023-08-14 01:54:29 +01: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 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 5c3f14d661 Fix crash with locale=ja and missing fonts.mpq 2023-02-19 12:58:17 +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 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 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 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 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 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
Gleb Mazovetskiy 04c3d85179 Remove MAX_PATH
Rather than using the Windows-like `MAX_PATH`, what we really want is 2
things:

1. Maximum path of a file in an MPQ. This is now `MaxMpqPathSize`.
2. Max size for the known monster paths. This is now 64 for sounds and
   TRNs, which is more than enough (picked arbitrarily).
2022-07-16 11:14:16 +01:00
Gleb Mazovetskiy 643c707c55 Remove strncmp 2022-07-16 10:59:40 +01:00
Anders Jenbo 3ae834148a Split event handeling from general miniwin features 2022-07-10 21:13:39 +02:00
Gleb Mazovetskiy 254806e027 Optimize translation RAM usage
1. Store all key data and all values data as 2 char arrays.
2. Change map keys to char pointers.
3. Change map values to offsets into the values array.

Example savings for Russian: 460 KiB -> 374.2 KiB (-85.8 KiB)

* Map: 68.5 KiB (with `string_view` keys it would be 101.5 KiB)
* Keys array: 108.7 KiB
* Values array: 197.0 KiB
2022-07-08 11:52:18 +01:00
Gleb Mazovetskiy 779ccaca17 Overhaul translation fetching
1. Do not modify the map after loading. Instead, return string views
   (guaranteed to be null-terminated) from look up functions and return
   the key directly if not found.
2. Use an `unorded_map` instead of `map` where available (C++20).
   Saves a bit of RAM (~50 KiB) and improves lookup performance.
2022-06-14 12:46:36 +01:00
staphen 695851666e Fix crash when switching to English 2022-06-05 00:59:57 +02:00
widelec-BB 9fdebdce7a Fix loading tranlations on big endian platforms 2022-04-24 16:19:49 +02:00
Gleb Mazovetskiy 127615c33f Fix conversion of C-string literal to char* 2022-04-14 05:11:37 +02:00
Anders Jenbo 122ec0ac9d Fix crash when switching to English 2022-04-13 04:52:49 +02:00
Gleb Mazovetskiy 8138121e39 Fix endianness handling in language.cpp 2022-04-05 08:56:31 +01:00
Anders Jenbo d11eeaa9ec Log uninplemented plural expressions (#4017) 2022-02-01 08:30:08 +01:00
ephphatha 6a1091ce09 Rename Korean/Romanian translation files so they are used in fallback resolution 2022-01-04 23:20:53 +01:00
Andrew James e1d01aad7c Replace en_US code with en when searching for user preferred languages (#3859) 2021-12-30 04:12:17 +01:00
Gleb Mazovetskiy 02902e5188 language.cpp: Fix -Wwrite-strings 2021-12-16 19:32:27 +00:00
ephphatha a1652bd5d6 Interleave non-regional fallback locales after last regional variation 2021-12-14 07:07:38 +01:00
ephphatha c0ec4a845a Restore fallback for non-regional translation
Also adds an explicit check for en given this the base translation for the application and will never have a .mo/.gmo file.
2021-12-14 07:07:38 +01:00
Gleb Mazovetskiy a4bc8fea7d Fix warnings: -Wsign-compare, -Wnarrowing 2021-12-08 23:03:20 +00:00
obligaron 945ee04f62 Add OptionEntry Language 2021-11-28 19:08:10 +01:00
obligaron 0ac065dbaa Make LanguageInitialize() reentry capable 2021-11-28 19:08:10 +01:00
Gleb Mazovetskiy c57644970f Move UiFlags and UiPanels into their own files
The first breaks circular dependency between `DiabloUI` and `text_render`.
The latter one moves `UiPanels` to a more appropriate place.
2021-11-25 12:22:27 +01:00
Gleb MazovetskiyandAnders Jenbo 7e1fea6f76 clang-format all files in {Source,test}/
Also includes a few manual tweaks to comments and newlines for better results.

Co-authored-by: Anders Jenbo <[email protected]>
2021-11-24 23:44:12 +01:00
Gleb Mazovetskiy 4f64b87330 Fix talk/store text overlap for Chinese and Japanese
We ensure that selectable lines are placed at the same vertical
coordinates but space out unselectable text lines at the cost
of reduced heigh of empty space between the store items.

We also have to move the back button in scrollable lists to the
lower right.

This can definitely be improved further but at least it solves
the problem for now.

Refs #3162
2021-11-20 02:31:21 +00:00
Gleb Mazovetskiy fa90679416 game_assets.* -> assets.* 2021-11-17 11:49:57 +01:00
Gleb Mazovetskiy 3d308983a8 Migrate to libmpq
libmpq is a much simpler alternative to StormLib for reading MPQ archives.

We use our own fork of libmpq: https://github.com/diasurgical/libmpq

Impact:

* DevilutionX is now a lot more portable. Unlike StormLib, libmpq only
  needs platform-specific code for Windows.
* Locks around file access **removed** (instead we duplicate the file descriptor for streamed audio only).
* RAM usage is **300 KiB** lower than StormLib.
* Stripped release linux_x86_64 binary is **32 KiB** smaller.
* Amiga build now hangs instead of crashing.
2021-11-06 23:51:42 +00:00
Anders Jenbo f1efc205ff Add support for Romanian plural forms 2021-10-25 16:15:30 +02:00
Anders Jenbo 3b229a8275 Check for translation in the same place as they are loaded from 2021-10-24 16:03:26 +02:00
Gleb Mazovetskiy 3448eab2d3 Translations: Restore support for ".mo" files
Note that they now need to go into the "assets/" subdirectory of the
build directory.
2021-10-23 20:04:34 +02:00
Gleb Mazovetskiy 5e675dcd6a Handle translations like other assets
Load translations from the MPQ or the assets directory, same as we do
with other DevilutionX assets.
2021-10-23 20:04:34 +02:00
Anders Jenbo f77d0b3665 Close translation-file handler 2021-10-20 21:52:59 +02:00
Anders Jenbo d88a8f401f Fix parsing of translation file header 2021-10-17 05:50:24 +02:00
Anders Jenbo dd5ec18ca7 Remove dead code from translation parser 2021-10-17 05:50:24 +02:00
Anders Jenbo af046864de Properly handle plural forms for Czech and Polish 2021-10-16 17:53:43 +02:00
Anders Jenbo 704a04ae4d Add support for Unicode fonts 2021-09-24 03:03:58 +02:00
Anders Jenbo 671fdbd125 Implement contextural translation (pgettext)
Fixes #2369
Fixes #2790
2021-09-20 04:18:35 +02:00
Anders Jenbo 370e573209 Prefer test versions of translations 2021-08-08 21:58:05 +02:00
Ivan Epifanov cf5ab583d5 Open translations as read-only 2021-08-08 16:17:27 +02:00