Commit graph

12000 commits

Author SHA1 Message Date
Kp c03b772ce7 Use caller supplied object for player_info in Flare_create
The caller supplies the local player, so use that instead of computing
it again.
2022-07-23 20:58:10 +00:00
Kp 68681d462c Fire flare from local player, not from ConsoleObject
The local player object was already computed above, and so is free to
reuse here.
2022-07-23 20:58:10 +00:00
Kp a0dc1b4283 Use union of multi_command<> for multi_send_fire message
Switch to a union of the possible multi_command<> types, and eliminate
the explicit length parameter passed to multi_send_data.
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 b4fcb9c305 Simplify do_missile_firing test for whether to autoselect
If `drop_bomb` is false, then `weapon == player_info.Secondary_weapon`.
If `drop_bomb` is true, then `weapon == bomb`.
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 3139445f02 Cache player object in do_missile_firing
Resolve the object to a vmobjptridx once, and use it as needed.  Replace
some uses of ConsoleObject with the local player, since those should be
the same, and local player is already computed.
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 cbab79a56a Simplify multi_send_fire handling of is_bomb_objnum
Only one caller passes a value other than `object_none` for
`is_bomb_objnum`.  That one caller uses an equivalent predicate to the
one that `multi_send_fire` uses for deciding whether to use
`MULTI_FIRE_BOMB`.  Therefore, if `is_bomb_objnum != object_none` is
true, the weapon is guaranteed to be a proximity bomb or smart mine, and
`multi_send_fire` can use `MULTI_FIRE_BOMB` without retesting the object
id.
2022-07-16 15:26:12 +00:00
Kp f22b627949 Simplify do_missile_firing lookup of track_goal
Commit 81dd23b151 ("Only charge player for weapons that fire successfully")
added an early return when `objnum == object_none`, so if execution
reaches the call to `multi_send_fire`, then the object is guaranteed to
exist.  Access the track_goal without rechecking whether the object
exists.
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 ea18bd074c Use multi_command for multi_send_message 2022-07-16 15:26:12 +00:00
Kp 2ea48475e3 Use multi_command for robot_fire_buf 2022-07-16 15:26:12 +00:00
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