Commit graph

4097 commits

Author SHA1 Message Date
Kp 44cf8b83be Advise gcc to inline morph_data::operator new
This is only used in the file where it is defined, so it can be inlined
even though the definition is not in a header.  Enabling inlining
encourages gcc to see that the `operator new`/`operator delete` calls
are not mismatched.
2022-08-22 01:24:49 +00:00
Kp c64a584bfd Use enum class for robot_gun_number
Validate gun numbers on loading object data.  Factor out and normalize
the logic for advancing to a robot's next gun.
2022-08-22 01:24:49 +00:00
Kp 0ffbc764af Store Windows HMP MIDIHDR inline in hmp_file
This avoids the need to make separate allocations for the individual
buffers, and to free them later.
2022-08-22 01:24:49 +00:00
Kp 1fb55eebc2 Use enum class for robot_animation_state 2022-08-22 01:24:49 +00:00
Kp 7ac4016f55 Remove DXX_VALPTRIDX_STATIC_CHECK
clang-14 is detected as being able to optimize out unreachable paths,
but then triggers a build error reporting an unspecified invalid use
somewhere in multi.cpp.

Remove the static check, and rely on -Wsuggest-attribute=noreturn to
report any functions which are guaranteed to fail.  This is a weaker
check, but over the course of development, the static check has been hit
rarely, if ever, so keeping it provides little value.

```
In file included from similar/main/multi.cpp:38:
In file included from common/main/game.h:32:
In file included from common/main/robot.h:34:
In file included from common/main/object.h:40:
common/include/valptridx.h:229:2: error: call to unsigned int valptridx<dcx::player>::check_index_range_size<valptridx<dcx::player>::index_range_exception, std::__1::less>(char const*, unsigned int, unsigned long, valptridx<dcx::player>::array_managed_type const*)::DXX_ALWAYS_ERROR_FUNCTION::dxx_trap_handle_index_range_error() declared with 'error' attribute: invalid index used in array subscript
    DXX_VALPTRIDX_CHECK(Compare<std::size_t>()(s, array_size), handle_index_range_error, "invalid index used in array subscript", a, s);
    ^
common/include/valptridx.h:37:3: note: expanded from macro 'DXX_VALPTRIDX_CHECK'
        DXX_VALPTRIDX_STATIC_CHECK(dxx_valptridx_check_success_condition, dxx_trap_##ERROR, FAILURE_STRING);    \
        ^
common/include/valptridx.h:20:5: note: expanded from macro 'DXX_VALPTRIDX_STATIC_CHECK'
            (DXX_ALWAYS_ERROR_FUNCTION(FAILURE_FUNCTION, FAILURE_STRING), 0)    \
             ^
build/ulinux-clang++-14-64b10d04-ogl/dxxsconf.h:84:2: note: expanded from macro 'DXX_ALWAYS_ERROR_FUNCTION'
    DXX_ALWAYS_ERROR_FUNCTION::F(); \
    ^
1 error generated.
```
2022-08-22 01:24:49 +00:00
Kp 26ab08d55f Add stub definitions of enum vertnum_t,wallnum_t
Given this code:

```
enum class X : unsigned;
X a{1};
```

gdb has an unfortunate behavior of reporting "incomplete type" and
refusing to show the underlying value of `a`, even when `a` is in scope.
Adding `enum class X : unsigned {}` fixes this and allows gdb to show
the value.
2022-08-22 01:24:49 +00:00
Tylor 6fee36638d Feat: Pitch unlocker 2022-08-21 16:16:40 -05:00
Kp 55bbc5f599 Pass std::span to multi_do_create_robot_powerups 2022-07-30 17:42:59 +00:00
Kp 4ce39a399e Pass std::span to multi_do_boss_create_robot 2022-07-30 17:42:59 +00:00
Kp c575283c5e Pass std::span to multi_do_boss_stop_gate 2022-07-30 17:42:59 +00:00
Kp b820098103 Pass std::span to multi_do_boss_start_gate 2022-07-30 17:42:59 +00:00
Kp 2b4dd444ca Pass std::span to multi_do_boss_cloak 2022-07-30 17:42:59 +00:00
Kp 6ab2068a82 Pass std::span to multi_do_boss_teleport 2022-07-30 17:42:59 +00:00
Kp 202e3309a7 Pass std::span to multi_recv_escort_goal 2022-07-30 17:42:59 +00:00
Kp 980b3080ce Pass std::span to multi_do_robot_fire 2022-07-30 17:42:59 +00:00
Kp fa0f7cef11 Pass std::span to multi_do_release_robot 2022-07-30 17:42:59 +00:00
Kp d4b047bb02 Pass std::span to multi_do_robot_position 2022-07-30 17:42:59 +00:00
Kp 0036b91084 Pass std::span to multi_do_claim_robot 2022-07-30 17:42:59 +00:00
Kp 49f608010a Pass std::span to multi_do_robot_explode 2022-07-30 17:42:59 +00:00
Kp e1269dca35 Pass std::span to multi_do_create_robot 2022-07-30 17:42:59 +00:00
Kp dc674eafe8 Replace various uses of std::enable_if with C++20 requires()
Compiler error messages are generally better when reporting a misuse
that fails a requires() versus reporting a misuse that fails a
std::enable_if.  In some cases, this also makes the code clearer, and
avoids the need for dummy template parameters as a place to invoke
std::enable_if.
2022-07-30 17:42:59 +00:00
Kp 58061b5f45 Use C++20 std::span for morph_data 2022-07-30 17:42:59 +00:00
Kp e5dcb8a505 Prefer C++20 std::span over internal span for decode_row
This generates the same code before and after.
2022-07-30 17:42:59 +00:00
Kp d9d2bac092 Use enum class for apply_damage_to_player::possibly_friendly
Also, remove a redundant invulnerability check in one caller.
apply_damage_to_player already tests for invulnerability and returns if
appropriate.
2022-07-23 20:58:10 +00:00
Kp a44f80fd64 Flatten call chain to net_udp_send_data 2022-07-23 20:58:10 +00:00
Kp f78c3989f9 Remove obsolete multi_send_data overload
All callers now supply a multi_command<>, so remove the pointer-based
overload.
2022-07-23 20:58:10 +00:00
Kp e6c510d467 Use vector read/write helpers in network messages 2022-07-23 20:58:10 +00:00
Kp 4141e04359 Pass thief stolen item storage to drop_stolen_items 2022-07-23 20:58:10 +00:00
Kp a3a2f7cc9a Pass context to drop_stolen_items
Pass the specific object fields needed, rather than the entire object.
2022-07-23 20:58:10 +00:00
Kp 801c76cbd2 Pass context to spit_powerup 2022-07-23 20:58:10 +00:00
Kp b61add4765 Pass context to drop_powerup 2022-07-23 20:58:10 +00:00
Kp 2536b6c1bc Pass player orientation matrix to multi_send_fire
The caller has the player object, and can provide the orientation matrix
from it.  Use that instead of letting multi_send_fire recompute the
object in order to get the matrix.
2022-07-23 20:58:10 +00:00
Kp 52aa9891b9 Simplify passing weapon to do_missile_firing
When the player fires a generic secondary, the choice of proximity bomb
versus super-mine is never read.  When the player specifically drops a
bomb, only that choice needs to be read.  Pass the chosen weapon as an
argument, and avoid computing the choice on the path where it is never
read.
2022-07-23 20:58:10 +00:00
Kp c0e12eee3f Push player object lookup from do_missile_firing to caller
The caller already needs the player object for other purposes, so let
the caller pass it down to do_missile_firing.
2022-07-23 20:58:10 +00:00
Kp 0dd5d6e0d5 Split guided missile release local/remote handling
Two paths are always local.  One path is always remote.  Split the
handler function to remove the locality test and rely on the caller's
knowledge of whether the affected player is local.
2022-07-23 20:58:10 +00:00
Kp 0cb0b5cdc0 Use playernum_t for guided missile player number 2022-07-23 20:58:10 +00:00
Kp 4886afdf93 Lift which_bomb from do_missile_firing to caller
Callers already have the player_info available, and will need the value
of bomb in a subsequent commit.  Lift it here.
2022-07-16 15:26:12 +00:00
Kp 1d65a83d73 Use primary_weapon_index_t for do_laser_firing weapon_id 2022-07-16 15:26:12 +00:00
Kp 9cf82a8eb5 Set multi_command code in constructor, not at send time
Rework multi_send_kill to handle the stricter construction requirements
this imposes.
2022-07-16 15:26:12 +00:00
Kp 1d23e5848f Use enumerated_array for UDP_mdata_store::pkt_num 2022-07-16 15:26:12 +00:00
Kp bfd83c6702 Use enumerated_array for UDP_mdata_store::pkt_timestamp 2022-07-16 15:26:12 +00:00
Kp efecd3507f Optimize removal of expired mdata records
Instead of sliding the entire queue down one element at a time, move the
non-expired elements in one step, and wipe all the trailing elements
in a single pass.
2022-07-16 15:26:12 +00:00
Kp 851edbbd3c Use enum class for player connected status 2022-07-16 15:26:12 +00:00
Kp 4cc1bc995b Pack player acknowledgement mask into a bitset
The only values for any given player are true/false, so use a bitset
instead of a byte per player.  Some implementations may use a uint64_t
internally, negating the space savings.  Even so, this version is
an improvement for requiring the use of playernum_t as an index.
2022-07-16 15:26:12 +00:00
Kp 7f8e074ab0 Tighten access specifiers on enumerated_bitset 2022-07-16 15:26:12 +00:00
Kp 4cff6fd9d7 Simplify multi_send_robot_frame argument sent
The function had one caller, which always passed `0`.  Inline that.
Next, observe that `sent` is only ever modified `if (!(Game_mode &
GM_NETWORK))`.  As a multiplayer function, `multi_send_robot_frame`
should never be called in single-player, so this test should always be
false.  Delete it, and observe that `sent` is now `const`.

Remove unused return value of `multi_send_robot_frame`.
2022-07-16 15:26:12 +00:00
Kp 450154452d Use enum class for multi_send_robot_position_priority
Increment all values by 1, to eliminate the increment inside
multi_send_robot_position.
2022-07-16 15:26:12 +00:00
Kp 47f622dbc4 Use std::bitset for robot_fired
This only ever tracks true/false, so use bitset to save space.
2022-07-16 15:26:12 +00:00
Kp dccebd9783 Flatten call chain to net_udp_send_mdata_direct 2022-07-16 15:26:12 +00:00
Kp b737524415 Use enum class for next_level_request_secret_flag
Instead of passing a bare `int` named `secret_flag`, define it as an
`enum class : uint8_t` to name the two special values.

Rework the passing of this value, to deal with some confusing
inconsistencies when reading the code.

Before this change:
In D1:
- Multiplayer will always go to the secret level, regardless of which
  exit door the player used.
In D2:
- Flying through a D1 secret exit in multiplayer shows the on-HUD error
  "Secret Level Teleporter disabled in multiplayer!", and does not exit
  the level.  This is at best confusing, and at worst dangerous, since
  D1 secret exits are only available during the countdown, so the player
  has little time to realize that the normal exit must be used instead.
- Like D1, multiplayer will request to go to the secret level regardless
  of the exit used.  Unlike D1, the caller ignores the flag and always
  advances to the next regular level.

After this change:
- No observable differences for the player in-game.  The questionable D2
  secret exit handling for D1 is retained.
- The code makes clearer that secret exits do not work in D2
  multiplayer, by way of `#if defined(DXX_BUILD_DESCENT_I)` guarding the
  existence of the parameter and all updates to it.
2022-07-16 15:26:12 +00:00
Kp f3d31a6d27 Use enum class for Difficulty_level_type 2022-07-16 15:26:12 +00:00
Kp 066b172963 Use enum class for Network_status 2022-07-09 13:39:29 +00:00
Kp c7bbc415f5 Remove obsolete MULTI_FIRE field nfires
As of 8f8989e049, this field is always
sent as `1`.  Remove it, and update position offsets.
2022-07-09 13:39:29 +00:00
Kp 6275353d97 Split UDP_sequence_packet into per-message types
Using `netplayer_info` in `UDP_sequence_packet` defined many unused
fields.  Replace this with per-message types that carry only the
required fields.  Make these fields `const` where possible.
2022-07-09 13:39:29 +00:00
Kp 2135328dab Use enum class for multiplayer_data_priority 2022-07-09 13:39:29 +00:00
Kp a70188e7a5 Move various static functions into anonymous namespace 2022-07-09 13:39:29 +00:00
Kp 6215ef8e06 Pass LevelSharedRobotInfoState to various functions that need it 2022-07-09 13:39:29 +00:00
Kp 37132ab887 Pass LevelSharedRobotInfoState in fvi_query 2022-07-09 13:39:29 +00:00
Kp e5425a00f3 Use forward-declaration header for robot.h 2022-07-09 13:39:29 +00:00
Kp d6c43f56af Use enum class for gun_num_t 2022-07-09 13:39:29 +00:00
Kp 0dfd462c64 Change fvi_query to pass LevelUniqueObjectState if checking objects
Remove the definition of FQ_CHECK_OBJS and all uses of it.  Add a new
fvi_query member d_level_unique_object_state *LevelUniqueObjectState.
If object checking is enabled, pass &LevelUniqueObjectState in that
member.  If object checking is disabled, pass nullptr in that member.

Change fvi_sub to use this member to decide whether to perform object
checking.
2022-07-09 13:39:29 +00:00
Kp 4bc901b0a9 fvi_sub: validate object once at start of FQ_CHECK_OBJS
If FQ_CHECK_OBJS is used, a valid object is required.  Copy the
icobjptridx_t from fvi_query into a local vcobjptridx_t to force a
validation, then use that validated copy for later work.
2022-07-09 13:39:29 +00:00
Kp 4ab619b7c2 Restructure use of fvi_query
- Make all members constant, and pass an anonymous temporary fvi_query
  to find_vector_intersection.
- Change `p0`/`p1` to `const vms_vector &`, since the positions are
  mandatory.  Callers can no longer pass `nullptr` or an uninitialized
  value here.
- Change `thisobjnum` to `icobjptridx_t`.  Calls to fvi_sub built an
  objptridx at need, so moving it to the caller allows it to be
  constructed once per find_vector_intersection call.
- Move `flags` and `rad` out of fvi_query, since calls to fvi_sub may
  use other values than the ones in fvi_query.  This prepares for
  passing fvi_query to fvi_sub.
2022-07-09 13:39:29 +00:00
Kp a690374916 Pass state to place_object 2022-07-09 13:39:29 +00:00
Kp 8ba1390947 Pass state to explode_object 2022-07-09 13:39:29 +00:00
Kp e25b476de7 Use enum for segnum_t
Add checked conversions for sites which load from external integers.
2022-07-02 18:10:45 +00:00
Kp fca59adb53 Split out creating OBJ_WEAPON objects 2022-07-02 18:10:45 +00:00
Kp e2509fc840 Move d_robot_info_array out of d_level_shared_robot_info_state
Embedding it in d_level_shared_robot_info_state is reasonable from a
relational perspective, but interferes with referencing
d_robot_info_array when only a forward declaration of
d_level_shared_robot_info_state is available.
2022-07-02 18:10:45 +00:00
Kp 25d0ae8f65 Use an explicitly defaulted exact_type<T>::operator==
clang-13 needed an operator==(const exact_type<T>&) defined to avoid an
ambiguity.  Now that C++20 mode is enabled, switch to a
compiler-generated operator== instead of manually defining the
equivalent function.
2022-07-02 18:10:45 +00:00
Kp 1bcc5c40d0 Work around clang-13 ambiguous operator==
In C++ 20 mode, clang-13 gets confused about how to handle operator==.
Rewrite the test to encourage it to pick the correct version.

```
common/include/gr.h:129:12: error: use of overloaded operator '==' is ambiguous (with operand types 'dcx::grs_main_bitmap *' and 'exact_type<dcx::grs_bitmap>')
        if (this == &r)
            ~~~~ ^  ~~
common/include/pack.h:31:17: note: candidate function (with reversed parameter order)
    constexpr bool operator==(const T *rhs) const { return p == rhs; }
                   ^
common/include/gr.h:129:12: note: built-in candidate operator==(struct dcx::grs_bitmap *, struct dcx::grs_bitmap *)
        if (this == &r)
```
2022-07-02 18:10:45 +00:00
Kp 33d938ac06 Prepare exact_type for clang-13 in C++20 mode
clang-13 in C++20 mode fails:

```
similar/main/newmenu.cpp:202:18: error: ISO C++20 considers use of overloaded operator '==' (with operand types 'exact_type<const dcx::grs_font>' and 'exact_
type<const dcx::grs_font>') to be ambiguous despite there being a unique best viable function [-Werror,-Wambiguous-reversed-operator]
    return &cv_font == &game_font ? "\202" : "\207";  // 135
	   ~~~~~~~~ ^  ~~~~~~~~~~
common/include/pack.h:31:17: note: ambiguity is between a regular call to this operator and a call with the argument order reversed
    constexpr bool operator==(const T *rhs) const { return p == rhs; }
		   ^
```

Add an operator== that exactly matches the input types so that clang
does not attempt a conversion.
2022-07-02 18:10:45 +00:00
Kp bdeca5687e Remove unused copy_diminish_palette
Fixes: f413017317 ("Delegate bald_guy_load PCX to SDL image")
2022-07-02 18:10:45 +00:00
Kp e45ff2da5e Use named enum types for netflag and netgrant 2022-07-02 18:10:45 +00:00
Kp e79af7c55f Restrict RAIIdmem to use on integral types
There are no remaining uses of RAIIdmem on structure types.  Restrict it
to integral types, to remove use of std::is_pod.
2022-07-02 18:10:45 +00:00
Kp a906f13c83 Replace deprecated std::is_pod in physfsx helpers
C++20 deprecates std::is_pod.  Expand std::is_pod to its equivalent long
form of std::is_standard_layout && std::is_trivial.
2022-07-02 18:10:45 +00:00
Kp fd7ab4388c Remove unused CALLOC code
TGA generation was the last user of CALLOC.  Remove it.
2022-07-02 18:10:45 +00:00
Kreeblah 1c8ff1ac0f
Fix gl.h include location for macOS 2022-06-24 23:06:27 -07:00
Kp a1bdd81d41 Exclude unused code from D2 non-editor build
gamedata_read_tbl is only called if (D1 || (D2 && EDITOR)).  Exclude
defining it for (D2 && !EDITOR).  From there, also exclude defining or
reading the alias list, which is only written by a function
called by gamedata_read_tbl.

Reported-by: heftig <https://github.com/dxx-rebirth/dxx-rebirth/issues/642>
2022-06-11 15:00:02 +00:00
Kp 2f78951b02 Change underlying_value to use a deleted function for the bad case
This produces a better error message than a static_assert failure, since
gcc points directly to the call which resolved to the deleted overload.
When the caller is correct, this produces the same result as the prior
version.
2022-06-11 15:00:02 +00:00
Kp 522c696af0 Remove unnecessary members in splitpath_t
splitpath_t is designed for MS-DOS paths, even though Rebirth now runs
on many platforms that never used DOS conventions.  Most of the members
of splitpath_t are unused on all platforms.  Remove them, and switch to
returning an initialized version of the structure.
2022-06-11 15:00:02 +00:00
Kp 346906ae9f Simplify UPID_QUIT_JOINING
The host only needs to check the source address.  Remove the check on
the callsign, and shrink the message accordingly.
2022-06-05 17:44:53 +00:00
Kp 9816475706 Pass Object array to object_goto_next_viewer 2022-06-05 17:44:53 +00:00
Kp c5de47b51e Add const qualifiers to some net_udp functions 2022-06-05 17:44:53 +00:00
Kp 3d7cb4abc7 Remove force_dump_ai_objects_all
It rotted because it is only ever used when PARALLAX is defined.  No one
has reported it broken, so remove it.
2022-06-05 17:44:53 +00:00
Kp e180375f97 Pass GameBitmaps to draw_object_blob 2022-06-05 17:44:52 +00:00
Kp cc2f3caa7e Split piggy.h -> fwd-piggy.h 2022-06-05 17:44:52 +00:00
Kp 6228b07b45 Fix check_header_includes=1 build of fvi.h 2022-06-05 17:44:52 +00:00
Kp 6e2ed26659 Pass object to init_player_object 2022-06-05 17:44:52 +00:00
Kp 9f207daf95 Pass player object to reset_player_object 2022-06-05 17:44:52 +00:00
Kp 11a0aae9ee Pass GameBitmaps to piggy_bitmap_page_in 2022-06-05 17:44:52 +00:00
Kp 33152640bc Remove fvi_info::hit_type
Its value is always readily available as the return value of
find_vector_intersection, so remove the structure member and rely on the
returned value.
2022-06-05 17:44:52 +00:00
Kp be7388a369 Enable repaircenter in D1
The code exists in D2, and the segment special is reserved for both
games.  Include the repaircenter code in D1, also.
2022-06-05 17:44:52 +00:00
Kp 6bd6a47612 Rework compress_segments to use segment iterators
This removes direct math on segnum_t, which will simplify later use of
`enum class segnum_t`.
2022-06-05 17:44:52 +00:00
Kp 86a32dd0ff Change enum sidenum_t to enum class sidenum_t 2022-06-05 17:44:52 +00:00
Kp 4fd412b2ea Precompute g3_draw_line GL color data 2022-06-05 17:44:52 +00:00
Kp e54338ce4e Combine canvas+color into g3_draw_line_context 2022-06-05 17:44:52 +00:00
Kp a8e7f6ad59 Use enum class for find_vector_intersection result 2022-05-24 02:32:58 +00:00
Kp d8ab3c9bd3 Remove quadint members low, high
Always access the data through the member `q`.  This makes the code
independent of architecture endian decisions.
2022-05-24 02:32:58 +00:00
Kp e154d37e5e Tighten valptridx::ptridx range checking for pointer_type constructor
Previously, the supplied pointer was converted to an array index, then
passed to valptridx::idx for validation.  If the index_type is smaller
than std::size_t, this would truncate the value before validation.
Certain out-of-range indexes would be in-range after truncation, and
incorrectly not be reported.

Reorder the check to validate the index against the array size before
truncation.
2022-05-24 02:32:58 +00:00
Kp 67705bdd7a Return checkmuldiv result in std::optional 2022-05-24 02:32:58 +00:00