Commit graph

11984 commits

Author SHA1 Message Date
Kp 2288f85d6a Use multi_command for multi_send_drop_marker 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 1fa56d439c Skip dropping items when host quits
If the host quits, the game ends immediately afterward, so no dropped
items could be picked up.
2022-07-16 15:26:12 +00:00
Kp db4005fca6 Hold Network_laser_track const in multi_do_fire 2022-07-16 15:26:12 +00:00
Kp d3fdfd53b7 Update comment on do_laser_firing
Fixes: 5b29428643 ("Propagate nfires within do_laser_firing")
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 8af8124839 Lift multi_send_robot_position_sub priority parameter to callers
Instead of passing a truth value and letting
multi_send_robot_position_sub pick which of two priority values to use,
let the callers pass the priority directly.  There were two callers.
One used a fixed truth value, and the other can easily use a ternary.
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 61d1ef9904 Remove obsolete and unused multi_send_data_direct
All callers now use the multi_command<C> form, so there is no need for
the form that allows a free pointer and length.
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 2eafb4a361 Simplify calling net_udp_request_game_info
All callers except one want the `lite` version of the request.  Switch
from a boolean that is selected inside the function to a reference that
is defaulted to `lite`.  Override that argument to the heavy version in
the one caller that needs it.
2022-07-09 13:39:29 +00:00
Kp 066b172963 Use enum class for Network_status 2022-07-09 13:39:29 +00:00
Kp 1cd9d18127 Compute game version rejection buffer at compile time
All the fields are constant.  Compute them at compile time.  Move the
sending function to dcx, since it is not game-specific.
2022-07-09 13:39:29 +00:00
Kp c354f9a606 Short-circuit network version mismatch tests
Once one component is known not to match, there is no reason to read the
other components from memory.
2022-07-09 13:39:29 +00:00
Kp 9af7159592 Compute game info request buffer at compile time
Its contents depend only on compile-time constants, so compute it once
and store it as a read-only variable to be sent as needed.
2022-07-09 13:39:29 +00:00
Kp a0c95c21a8 Flatten the indirection around udp socket functions
This reduces the noise from diagnostics when the function is misused,
and shrinks the code some.
2022-07-09 13:39:29 +00:00
Kp 5aaa095c14 Move Active_udp_games into netgame_list_game_menu 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 dd260f234b Use auto type for Viewer in more places 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 af05991821 Simplify thief retry loop
Instead of forcing one call, then conditionally doing 3 more, make the
loop run for 4 passes, and make the call after the conditional exit,
instead of before.
2022-07-09 13:39:29 +00:00
Kp 37132ab887 Pass LevelSharedRobotInfoState in fvi_query 2022-07-09 13:39:29 +00:00
Kp fac016c104 Split object_create_explosion_sub for with/without damage cases
Some callers create an explosion with damage forced to zero.  Others
create an explosion with damage non-zero.  Only the non-zero case needs
to examine nearby objects.  Split object_create_explosion_sub so that
the zero-damage case can skip that logic, and the arguments required to
implement it.
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 5d62df856d Pass fvi_query to fvi_sub
Many of the input parameters are available in fvi_query, so pass a
reference to that instead of copying the parameters to the stack
individually.
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 4ef75b2aed Pass state to do_endlevel_flythrough 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 192c5de4f1 Add compile-time option to disable ship wiggling
Ship wiggle is normally enabled for compatibility with the original
game.  However, during development, it can become a nuisance, so add an
option to allow disabling it.
2022-07-02 18:10:45 +00:00
Kp e80c6fb05f Rename font underline to draw_full_width_as_fg_color
This started out as underline, but one of the special drawing modes uses
it to draw an underline-width block across the entire vertical height of
the character.
2022-07-02 18:10:45 +00:00
Kp 55af651200 Pass d_level_unique_object_state context to create_omega_blobs 2022-07-02 18:10:45 +00:00
Kp a40ab08bd0 Remove write-only field fcd_data::csd
This value was written when cache entries were created, but is never
read back.
2022-07-02 18:10:45 +00:00
Kp 3230b23bb9 Rework find_connected_distance cache
- Inline MAX_FCD_CACHE into the definition of Fcd_cache, then rely on
  Fcd_cache.size() later.
- Make Fcd_index unsigned.  As an index, a negative number is invalid.
- Change flush_fcd_cache to update Last_fcd_flush_time, rather than
  requiring callers to do it.  Most callers did not update this.
- Change add_to_fcd_cache to validate and reset Fcd_index before use,
  rather than resetting after increment.  This allows Fcd_index to
  become invalid after a write, but it will be reset to a valid value
  before it is used again.
- Fix original game bug in add_to_fcd_cache that caused the cache
  expiration path to clear the wrong cache entry.
2022-07-02 18:10:45 +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