Commit graph

5328 commits

Author SHA1 Message Date
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 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 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 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 f37845b483 Move Descent 2 specific automap colors to d2x 2023-04-23 21:45:31 +00:00
Kp 03a06d71d5 Merge branch 'd2-superlaser-no-penalty' into master 2023-04-22 15:02:12 +00:00
Kp 5534e10d74 Add further comments around the laser damage penalty logic
Due to original game bugs, which Rebirth intentionally replicates in
order to match the balance of the original game, the logic looks odd.
Add comments explaining that the oddity is intentional.
2023-04-22 15:02:12 +00:00
Kp c98b30ca23 Reduce console colors to in-range values
`gr_find_closest_color` takes inputs in the range [0, 63].  Clamp input
values to fit in that range.
2023-04-22 14:56:35 +00:00
AlumiuN d93787d942 Fix inaccurate handling of D2 super laser damage with quad-lasers (as D2 was bugged and didn't apply the intended penalty to them) 2023-04-21 12:16:54 +12:00
Kp 0b066d23b4 Use enum class for load_palette arguments 2023-04-15 19:11:14 +00:00
Kp f10a79f157 Pass menu_filename to nm_draw_background1 2023-04-15 19:11:14 +00:00
Kp c49598d5f5 Merge commit 'clang-warnings' into master 2023-04-08 20:12:32 +00:00
Kreeblah 980c03b9ae
Fix Apple Clang errors and warnings 2023-04-06 16:42:49 -07:00
Kp ae3f4ab533 Return computed filename from removeext 2023-04-02 10:15:20 +00:00
Kp 89e89c8afb Move global constants from mglobal.cpp to cglobal.cpp
These constants can be useful in unit tests, so move them out to their
own file.
2023-03-12 10:40:25 +00:00
Kp 114cdef1d2 Remove unused argument to parse_bmhd
clang-15 warns for a write-only parameter.  The parameter is only used
in a debug print, which has been commented out since the code was
originally imported.  Remove the parameter and the commented print.
2023-02-26 18:42:12 +00:00
Kp 452a50f80b Move WID_* constants into wall_is_doorway_result
This allows them to be reported symbolically in a debugger when a
variable is of type wall_is_doorway_result.
2023-02-18 14:30:59 +00:00
Kp 1f5e9808e5 Pass std::span to rotate_list 2023-02-04 19:21:25 +00:00
Kp a582b4ee82 Remove write-only g3d_interp_outline 2023-02-04 19:21:25 +00:00
Kp 0e1219a66b Factor out texture setup to get_texture 2023-01-29 20:42:03 +00:00
Kp 4f37720882 Use enumerated_array for ambient sound depth tracking 2023-01-29 20:42:03 +00:00
Kp fecc1f102f Use enum class for clwallnum_t 2023-01-29 20:42:03 +00:00
Kp 031a4b166c Use enum class for wall_is_doorway_result 2023-01-29 20:42:03 +00:00
Kp 132612de35 Use enum class for wall_is_doorway_mask 2023-01-29 20:42:03 +00:00
Kp df0772ae1c Use variable template for CollisionResult initialization 2023-01-29 20:42:03 +00:00
Kp 5e52d11fc6 Discourage spurious gcc warning
gcc-12 can issue `-Warray-bounds` warnings for code inlined from system
headers, and warns about `std::sort()` on a small array (
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107986> split from
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104165>).  Per a comment
in a related Fedora report
<https://bugzilla.redhat.com/show_bug.cgi?id=2051783#c3>, and local
testing, adding an explicit unreachable on the impossible case that the
end iterator exceeds the end of the array will discourage gcc from
warning without needing to disable -Warray-bounds.

This failure was previously observed in early testing with gcc-12, and
was set aside in the hope that gcc-12 would be fixed before it came into
widespread use.  That has not happened, and JoeNotCharles reported
<2644e0cb93>
this independently.  JoeNotCharles proposed disabling the warning for
the call to `std::sort`.  This commit instead leaves the warning
enabled, but encourages gcc to see that the bad path is impossible,
allowing gcc to delete the bad path before the warning is issued.
2023-01-14 19:05:37 +00:00
Kp 27586fe0b9 Track newmenu return value using std::shared_ptr
JoeNotCharles reports that gcc-12 (architecture unspecified) warns
because `newmenu::process_until_closed` stores the address of a stack
local into a heap-allocated structure.  Switch to a less efficient
implementation that does not provoke a compiler warning:

- Store `shared_ptr<int>`, not `int *`, in the `newmenu`
- `shared_ptr::operator*()` and `shared_ptr::operator bool()` allow most
  use sites to be unchanged relative to a bare pointer
- Load the return value from the `shared_ptr<int>`.  If the newmenu
  terminated before return, as should always happen, this is a slightly
  less efficient version of the same code as before.  If the newmenu was
  still open despite its `exists` flag claiming otherwise, then the
  returned value may be incorrect, but the read will be well-formed, the
  `newmenu`'s eventual write will write to the heap-backed int (rather
  than writing into the stack allocated to
  `newmenu::process_until_closed`), and the memory will be freed when
  both `process_until_closed` has returned and the `newmenu` has been
  destroyed.

Reported-by: JoeNotCharles <10a2b2d337>
2023-01-14 19:05:37 +00:00
Kp 407ab585a8 Move window existence flag to a mixin, and track using std::shared_ptr
gcc-12 does enough escape analysis to notice that
newmenu::process_until_closed stores the address of a stack local into a
heap-allocated structure, but not enough analysis to notice that the
stack variable always outlives the escaped address.  The compiler then
warns about the address escaping the local scope.  Reworking the calling
code not to do this is somewhat invasive, and gcc seems unlikely to
change behavior.  Switch to a less efficient implementation that does
not provoke a compiler warning:

- Store a shared_ptr<bool> in the object
- In the object's destructor, write through the pointer to clear the
  shared boolean
- In the caller, store a copy of the shared_ptr<bool> as a local, and
  use that copy to monitor the shared boolean

This is similar to a change proposed by JoeNotCharles
<10a2b2d337>,
but differs in its details.  Among other things, this version takes the
opportunity to move the variable out to a mixin, so that only windows
which expect to be tracked can be tracked.  Previously, all windows were
capable of this, even though most never needed it.
2023-01-14 19:05:37 +00:00
Kp b6ce89eb54 Add compile-time sanity check on multi_send_data_direct length
JoeNotCharles reported
<1f1903a3b9>
an overflow in `net_udp_send_mdata_direct`.  This overflow is impossible
as currently written, because it can occur only if
`multi_send_data_direct` passes an oversized buffer to
`net_udp_send_mdata_direct`, and no messages are large enough to trigger
this.  JoeNotCharles proposed adding a runtime check to abort the
program if this happens.  Instead, this commit adds a compile-time check
to detect use of an excessively large input buffer.
2023-01-14 19:05:37 +00:00
Kp b8f25c9d1e Fix off-by-strlen(sep) in buffer capacity check
JoeNotCharles reports that gcc-12 (architecture unspecified) warns about
a possible truncation when constructing a path.  This would only occur
if the user had a path that was almost PATH_MAX deep (4096 bytes on most
platforms).  Add safety checks around this, and around an underflow if
this path were somehow reached while `newpath` was shorter than `sep`.
This is loosely based on a proposed commit by JoeNotCharles, but
rewritten to update comments and adjust the code flow.

Reported-by: JoeNotCharles <edfb3c4b77>
2023-01-14 19:05:37 +00:00
Kp 99b98bb555 Rework convert_integer to return result in some cases
Prefer returning the result in a std::optional<T> over returning a flag
value and taking a non-const reference to the result.
2023-01-14 19:05:37 +00:00
Kp 97c8a7a081 Remove macro wrapper around nm_messagebox
Construct the nm_messagebox_tie directly, without use of a macro.  This
produces simpler compiler error messages when nm_messagebox is called
incorrectly.
2023-01-14 19:05:37 +00:00
Kp 28bb251eea Remove unused return value for select_mission 2023-01-14 19:05:37 +00:00
Kp 8538a96451 Remove write-only multi_protocol 2023-01-14 19:05:37 +00:00
Kp 2790c5b14a Use run_blocking_newmenu for newdemo save-as dialog 2023-01-14 19:05:37 +00:00
Kp 43470c09bd Use run_blocking_newmenu for newdemo error dialog 2023-01-14 19:05:37 +00:00
Kp dfce7ed40d Simplify SDL_QUIT handling
Remove the global `Quitting` and instead run the window close loop
immediately upon receiving SDL_QUIT.
2023-01-14 19:05:37 +00:00
Kp 7a087702d0 Remove Mac-specific Command-Q handler
Per SDL documentation, SDL will generate an SDL_QUIT event when
Command-Q is used.  Rebirth already handles SDL_QUIT, so there is no
need to explicitly detect Command-Q.
2023-01-14 19:05:37 +00:00
Kp 820ba19883 Move vclip id validation down into paging_touch_vclip
This avoids repeating the ID in every caller's test, and centralizes the
definition of a valid vclip id.
2023-01-14 19:05:37 +00:00
Kp 28a83aa43f Harden D2 loading of D1 texture numbers 2023-01-07 22:17:31 +00:00