Commit Graph
637 Commits
Author SHA1 Message Date
ephphatha da76e131e4 Add getter/setter for character levels to ensure _pNextExper stays synced 2023-08-24 05:46:44 +02:00
Gleb Mazovetskiy ebe8c6e576 Add tl::expected and use it in ParseInt
`std::expected` has been standardized for C++23.
2023-08-19 17:13:54 +09:00
Gleb Mazovetskiy d262589021 Support const inventory iterators
Previously, inventory iterators could only be used with non-const
objects, leading to suboptimal const correctness.

Adds support for `const` objects to inventory iterators via
C++17 CTAD.
2023-08-16 06:01:03 +09:00
Gleb Mazovetskiy d5446f2f01 Use std::variant in StringOrView
We also add a direct string move-assignment (`operator=(std::string &&)`),
which results in better codegen.

As a consequence, we have to replace `= {}` assignments with `= StringOrView {}`
because `= {}` is now ambiguous.
2023-08-14 10:55:02 +01:00
Gleb Mazovetskiy 8c1a847f41 Remove utils/stdcompat/string_view.hpp 2023-08-14 09:59:14 +01:00
Gleb Mazovetskiy c19bfe87fa Remove utils/stdcompat/algorithm.hpp 2023-08-14 01:54:29 +01:00
Gleb Mazovetskiy 14540164a7 Remove utils/stdcompat/optional.hpp 2023-08-14 01:54:29 +01:00
Gleb MazovetskiyandAndrew James 53db86ee9a Use std::from_chars instead of std::stoi
Adds a `ParseInt` function which uses `std::from_chars`.

From `std::from_chars` documentation:
> Unlike other parsing functions in C++ and C libraries,
> std::from_chars is locale-independent, non-allocating, and non-throwing.

Co-authored-by: Andrew James <[email protected]>
2023-08-13 21:43:53 +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
Anders Jenbo ad7020be20 Change syntax for optional and required arguments to match various CLI tools 2023-06-26 18:52:39 +02:00
Gleb Mazovetskiy 1167b92692 Remove uses of std::tolower
`std::tolower` relies on the C locale, which we try to avoid.
2023-06-18 04:55:47 +01:00
staphen c2698fc357 [Seedinfo] Display flags for quest state instead of seed 2023-06-05 08:14:56 +02:00
staphen 1cb367ab91 Move seedinfo to text commands 2023-06-04 02:36:52 +02:00
Anders Jenbo 01a7966f1d Empty cursor when closing inventory
Fixes #4205
2023-06-03 20:25:50 +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
ephphatha b102dccf81 Fix OOB array access when spawning arena pots
calling this with a full inventory would write past the end of InvList, potentially causing a crash or data corruption.
2023-05-06 14:43:21 +01:00
FluffyQuack d27eafaf15 Gradually turn durability icon from gold to red 2023-04-16 17:10:44 +02:00
ephphatha 829d6b0d4a address clang-format violations 2023-04-16 08:44:22 +02:00
ephphatha 3690759eb9 Add comments for the logic used when drawing voice buttons 2023-04-16 08:44:22 +02:00
qndel ce2ce86070 inspect players command 2023-04-14 02:40:17 +02:00
obligaron b916c8e428 Introduce Open/Close/ToggleCharPanel 2023-04-14 02:40:17 +02:00
obligaron 1522dc7031 Multiplayer: Add arena potions 2023-04-13 21:20:53 +02:00
obligaron 590c990c80 Introduce Item::getName 2023-04-13 00:07:00 +02:00
obligaron 2296bf5625 Use StashStruct::EmptyCell instead for empty stash item check 2023-03-21 14:15:00 -04:00
Eric Robinson f75f66d54b Add playerdat (#5763) 2023-02-10 12:56:28 +00:00
KPhoenix a1fbf5253f enum talk_id -> enum class TalkID 2023-02-09 13:04:01 +01:00
Gleb Mazovetskiy b61dac853b Add GetSpellData(SpellID) 2023-02-05 12:12:48 +00:00
KPhoenix d813f13700 enum spell_id -> enum class SpellID 2023-02-05 10:24:58 +00:00
Gleb Mazovetskiy 1788d2f8ec Remove miniwin
Event handling code moved to `engine/events.{hpp,cpp}`.
2023-02-01 16:06:57 +00:00
Eric Robinson ef3a57b7d9 enum spell_type -> enum class SpellType (#5674) 2023-01-28 22:25:37 +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 eeaf23168e control_presskeys: "Handle" some ASCII chars
These printable ASCII characters will result in a text input event and
should not be handled further.

Fixes #5505
2022-11-24 05:13:49 +00:00
Gleb Mazovetskiy 46e755f680 Simplify spell icon handling
Hide the internals of spell icon rendering behind simple functions.
2022-11-22 02:37:19 +01: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 17bcca539f Fix InfoString-related stack-use-after-free 2022-10-30 11:08:06 +00:00
obligaron 795a43dd89 Add Arena Support 2022-10-14 16:25:30 +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
staphen 8b6db3a678 Get rid of panelstr, pnumlines, and ClearPanel() 2022-10-02 08:51:24 +02:00
KPhoenix a1822bca8e Remove sSkillText from spelldat.cpp 2022-09-21 23:48:08 +02:00
Anders Jenbo e348fa3b1e Implement town map 2022-09-12 08:09:17 +02:00
staphen 147a13d66c Synchronize gold in player's inventories 2022-09-08 06:11:36 +02:00
Gleb Mazovetskiy 188dc79f6e Make Players a vector 2022-08-26 13:22:04 +09:00
obligaron 3f3b3d74eb Ensure AddPanelString doesn't get out of bounds 2022-08-22 16:52:37 +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 4cf0053ece Set underlying type for all the enums
Reduces rg99 binary size by 3 KiB.
2022-08-11 01:43:54 +02:00
Gleb Mazovetskiy 609b711d32 Render char panel as CLX
Converted with:
```
pcx2clx --num-sprites 6 data/panel8bucp.pcx && rm data/panel8bucp.pcx
```

Size: 112640 -> 93215 bytes, -17.2%
2022-08-04 15:16:00 +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
ephphatha 9e76cd4ab7 Use object pointer for pcursobj 2022-07-19 13:20:24 +02: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