Commit Graph

12472 Commits

Author SHA1 Message Date
Kp f92e5e900e Recover from invalid control_center_triggers.num_links
Use of `partial_range` will trap invalid counts, but will throw an
exception and terminate the program.  Change the logic to log a
diagnostic and clamp the count to the maximum legal value, so that users
can play the level.  The level may still be impossible to complete, if
the triggers within the valid range do not open an exit door.  However,
level authors always have the ability to get that wrong, so the logic
with recovery is better than the logic without it.

Also, add a new diagnostic for invalid side in a control center trigger,
and a new diagnostic for invalid segment in a control center trigger.
For the latter, add a special case to reduce the severity when playing
`Descent 2: Vertigo`, since there is a known bad trigger in a Vertigo
level, and users cannot fix it.
2023-06-03 23:13:26 +00:00
Kp 606790f1c5 Inline read-only Do_dynamic_light 2023-05-27 13:19:31 +00:00
Kp 03cedbb4cc Remove default-zero for `physfsrwops_seek` variable pos
This default-zero allowed the bug introduced in
68b47307b4 (and fixed in
4c371734b5) not to generate a compiler
warning for `-Wuninitialized`, since it was initialized to `0`.
However, `0` is not a correct starting value for this variable.  Remove
the initialization and require every code path to assign a meaningful
value.

Switch to use `std::in_range` to validate that no truncation occurs, and
trust that the compiler will optimize this out when the type passed to
`std::in_range` can represent all values that the argument can
represent.
2023-05-27 13:19:31 +00:00
Kp 695e8b9ba1 Use memcpy for font filename
Prefer memcpy with a predetermined length, rather than strncpy, which
could leave the buffer without a terminator.  No current callers could
cause the lack of a terminator, but gcc-13 warns about it, so rearrange
the code to fix the warning.
2023-05-20 16:37:26 +00:00
Kp 3330b17cdb Use enum class for gamefont_conf::font_index 2023-05-20 16:37:26 +00:00
Kp c6e14fa74f Use std::array for font filenames 2023-05-20 16:37:26 +00:00
Kp bd050d73b2 Shrink a_gamefont_conf::name
Callers always load a DOS 8.3 filename into name, so shrink it from
64 characters to 16 characters.
2023-05-20 16:37:26 +00:00
Kp 03e12fedd4 Test for overzealous -Wdangling-reference
gcc-13 was released with -Wextra implying -Wdangling-reference, but
-Wdangling-reference as released warns on cases that are safe.  Add a
configure test to detect when the compiler warns incorrectly, and
disable the warning in those cases.  When a future compiler emits fewer
false positives, the suppression of the warning should stop.

Reported-by: ziplantil <https://github.com/dxx-rebirth/dxx-rebirth/issues/718>
2023-05-20 16:37:26 +00:00
Kp 686fa1ba21 Simplify segment_object_range_t construction 2023-05-20 16:37:26 +00:00
Kp 5ca2f59619 Validate last_hitobj on game load
Testing for `object_none` is insufficient.  Games saved before the fix
for 14cdf1b352 may have a `last_hitobj` of
`0x1ff`, which triggers an exception when constructing `icobjidx_t`.
Treat any invalid object index as `object_none`.

Reported-by: Quix0r <https://github.com/dxx-rebirth/dxx-rebirth/issues/716>
2023-05-15 23:52:18 +00:00
Kp b4e3d67725 Recompute guidebot index on game load
The index of the guidebot is set by loading the level data, and this is
usually sufficient.  However, if the user kills the guidebot, then uses
cheats to create a new one, the new guidebot will often have a different
index than the original guidebot.  If such a game is saved and then
reloaded, then after the reload, the computed guidebot index will be
reverted to the index of the original dead guidebot.  This causes
various problems, including potentially a crash.  Recompute the guidebot
index after loading the objects from the save file, so that it matches
the live guidebot.

Reported-by: GitInMotion <https://github.com/dxx-rebirth/dxx-rebirth/issues/713>
2023-05-14 18:41:36 +00:00
Kp c21c317441 Reset Buddy_objnum when buddy is deleted
Various code assumes that Buddy_objnum maintains the invariants:
- If the guidebot exists, Buddy_objnum must refer to it.
- If no guidebot exists, Buddy_objnum must be object_none.

This was not enforced, so if the guidebot is killed, Buddy_objnum can
continue to refer to its last index.  That can cause spurious errors
later.  For example, when the player enters an energy center, if the
guidebot is dead and the guidebot's last goal was "Find energy center",
then the console reports:

```
BUG: buddy is object 28, but that object is type 255.
```

Fix that by clearing the guidebot index when the guidebot is killed.
2023-05-14 18:41:36 +00:00
Kp 397d582031 Use NSDMI for zero-initialized Mission members
Prefer non-static data member initializers over leaving the member
undefined in the constructor and relying on the caller to zero the
member afterward.
2023-05-14 18:41:36 +00:00
Kp da39846514 Remove unnecessary pointer in savegame_newmenu_items
The pointer is only used by the constructor, so there is no need to
store it in the object.

Rework the allocation of the trailing storage to avoid the use of
placement new on a uint8_t[].
2023-05-14 18:41:36 +00:00
Kp 26d8c2881e Move compress_objects into `#if DXX_USE_EDITOR`
This is only called in the editor build, so exclude it from being built
in the non-editor build.
2023-05-14 18:41:36 +00:00
Kp c0c4ee7049 Inline obj_link into compress_objects
This is only called in one place, so manually inline it to keep the
logic together.
2023-05-14 18:41:36 +00:00
Kp 796c387ee4 Use enum class for Mission::anarchy_only_flag 2023-05-14 18:41:36 +00:00
Kp 3c9c855779 Use enum class for descent_hog_size 2023-05-14 18:41:36 +00:00
Kp 8eec1dc810 Eliminate unnecessary string copy in PHYSFSX_addRelToSearchPath
Pass a mutable buffer from the caller, and allow
PHYSFSX_addRelToSearchPath to adjust the capitalization in that buffer,
rather than creating a copy in a stack local.  This can slightly affect
status messages that use the name, but otherwise should have no effect
on the game.
2023-05-13 15:02:55 +00:00
Kp 6a794c6b63 Use memcpy to update string in locateOneElement 2023-05-13 15:02:55 +00:00
Kp 64569e102b Move search_result_t into locateOneElement local scope 2023-05-13 15:02:55 +00:00
Kp e7d73e8493 Use RAII to manage SDL_LockAudio state 2023-05-13 15:02:55 +00:00
Kp f2e65abbdb Move d2 movie code into namespace d2x 2023-05-06 19:26:19 +00:00
Kp 1053cb532b Use std::span for MovieFileRead 2023-05-06 19:26:19 +00:00
Kp 53a9ce8823 Use enum class for MVE_sndInit argument 2023-05-06 19:26:19 +00:00
Kp 4bdc31a729 Simplify movie stream ownership
Store an owned pointer in MVEFILE instead of storing an unowned pointer
there and requiring the caller to keep the owned pointer alive for the
lifetime of the MVEFILE.
2023-05-06 19:26:19 +00:00
Kp bb87582a8a Return MVESTREAM from MVE_rmPrepMovie 2023-05-06 19:26:19 +00:00
Kp f39c5e3318 Simplify `RotateRobot` movie reset
On entry, `pMovie` is not `nullptr`, so `MVE_rmPrepMovie` will call
`mve_reset` and return success.  Inline that path into `RotateRobot`.
2023-05-06 19:26:19 +00:00
Kp 4d0a67ac14 Remove unused MVESTREAM context 2023-05-06 19:26:19 +00:00
Kp 8750b9ae20 Move mvelib timer_created into MVESTREAM 2023-05-06 19:26:19 +00:00
Kp ab56701774 Remove unused arguments to handle_mve_segment_videodata 2023-05-06 19:26:19 +00:00
Kp 7da8304093 Remove unused arguments to handle_mve_segment_setdecodingmap 2023-05-06 19:26:19 +00:00
Kp 2ee7337290 Remove unused arguments to handle_mve_segment_setpalette 2023-05-06 19:26:19 +00:00
Kp 01abb4366e Remove unused arguments to handle_mve_segment_initvideomode 2023-05-06 19:26:19 +00:00
Kp cc83ee76e3 Remove unused arguments to handle_mve_segment_audioframedata 2023-05-06 19:26:19 +00:00
Kp 4d4a66ca38 Remove unused arguments to handle_mve_segment_displayvideo 2023-05-06 19:26:19 +00:00
Kp f83361f91f Remove unused arguments to handle_mve_segment_initvideobuffers 2023-05-06 19:26:19 +00:00
Kp d69daa609b Remove unused arguments to handle_mve_segment_startstopaudio 2023-05-06 19:26:19 +00:00
Kp f33b99e22c Remove unused arguments to handle_mve_segment_initaudiobuffers 2023-05-06 19:26:19 +00:00
Kp 0905aa6002 Remove unused arguments to handle_mve_segment_createtimer 2023-05-06 19:26:19 +00:00
Kp cfda77a03e Remove unused arguments to handle_mve_segment_endofchunk 2023-05-06 19:26:19 +00:00
Kp 61268545ff Remove unused arguments to handle_mve_segment_endofstream 2023-05-06 19:26:19 +00:00
Kp 6c41168e4d Call movie handlers directly via switch
Remove the use of function pointers, since there is only one set of
destinations.
2023-05-06 19:26:19 +00:00
Kp 60a36a881f Move bmread texture_count into local scope 2023-04-29 16:10:28 +00:00
Kp e5a8393cc3 Pass context to set_texture_name 2023-04-29 16:10:28 +00:00
Kp 5b4bf16bfa Remove support for -DSWAP_0_255
This has been broken since b1c5307eb1
changed the type of gr_palette from `uint8_t[256*3]` to
`array<rgb_t, 256>`.  Remove it, since no one has reported it in 10
years.
2023-04-23 21:45:31 +00:00
Kp f37845b483 Move Descent 2 specific automap colors to d2x 2023-04-23 21:45:31 +00:00
Kp cd604744da Use explicitly defaulted destructor for MVEFILE 2023-04-23 21:45:31 +00:00
Kp d9f2d6d08c Use enum class for mve_opcode 2023-04-23 21:45:31 +00:00
Kp e85270c079 Remove unused MVE_rmPrepMovie parameter `track`
This was never inspected.  Change callers not to pass it.
2023-04-23 21:45:31 +00:00