Commit graph

5230 commits

Author SHA1 Message Date
Kp bcff9e6aaa Simplify wall flag assignment
Move the tests up and keep the flags ready to assign.
2020-04-04 19:30:22 +00:00
Kp 443f4f8c83 Avoid reloading ObjBitmapPtrs[i] 2020-04-04 19:30:22 +00:00
Arne de Bruijn a2b49a9a08 Add PIGGY_PAGE_IN to ogl_cache_polymodel_textures 2020-04-04 12:13:59 +02:00
Kp 0fb82b47f6 SDL2: fix size of letterbox sequences
andrew-strong reported that using SDL2, with the window set to full
screen, but a windowed size less than full screen, caused letterbox
sequences, such as the player ship destroyed sequence, to render in a
subwindow sized to the dimensions game would have when unmaximized, even
if the game window is maximized at the time of the sequence.

tycho suggested a change that resolves this issue, and basic testing
showed no unwanted side effects.

Reported-by: andrew-strong <https://github.com/dxx-rebirth/dxx-rebirth/issues/399>
Suggested-by: tycho <https://github.com/dxx-rebirth/dxx-rebirth/issues/399#issuecomment-583688998>
2020-03-28 17:32:34 +00:00
Kp 2e682e140d Prevent sound stacking when all primary weapons are exhausted
ziplantil reported that in Descent 1, if a player has an empty Vulcan
cannon, and no energy, then attempting to fire a weapon would play the
SOUND_ALREADY_SELECTED clip every frame until the player ceased trying
to fire.  The problem does not impact Descent 2 since Descent 2 does not
play this sound sample when trying to activate a weapon that is already
active.

If the current weapon is already LASER_INDEX, then
select_primary_weapon(LASER_INDEX) simplifies to:

```

	// Pointless, player already using this weapon
	newdemo_record_player_weapon(LASER_INDEX)
	if (Primary_weapon != LASER_INDEX) {
		// skipped, path is false
	}
	else
	{
		if (wait_for_rearm)	// true for this path
			// Bad, plays every frame
			digi_play_sample(SOUND_ALREADY_SELECTED);
	}
	// Pointless, Primary_weapon already is LASER_INDEX
	Primary_weapon = LASER_INDEX;
	if (weapon_name)
	{
		// skipped, path is false
	}

```

Skipping the call avoids two pointless statements, one bad statement,
and nothing useful.  Therefore, the simplest fix for the problem is to
call select_primary_weapon(LASER_INDEX) only if the primary weapon is
not currently LASER_INDEX.

Reported-by: ziplantil <https://github.com/dxx-rebirth/dxx-rebirth/issues/499>
2020-03-28 17:09:28 +00:00
Kp af8adaef1b Defer digi_mixer_start_sound work until it is needed
If no channel is available, the mix parameters are unused.  Move their
construction to occur after a channel for the sound is found.
2020-03-28 16:55:43 +00:00
Kp b19496ca72 Set digi_mixer channel callback once at startup
The callback is never changed, so it does not need to be reset on every
new sound.
2020-03-28 16:54:28 +00:00
Kp 6a27ae3544 Prevent copying RAIIMix_Chunk
No code tried to copy it, but if a copy was created, it would cause a
double-free later.  Prevent copying to avoid introduction of a
double-free bug.
2020-03-28 16:51:43 +00:00
Kp ed4cb636b7 Fix memory leak when deleting listbox items 2020-03-14 03:41:30 +00:00
Kp a645fd2eba Allocate morph_data vectors dynamically
This greatly reduces the size of morph_data for most uses.
2020-02-26 05:07:34 +00:00
Kp 85a9034137 Move morph_data::morph_deltas into a trailing allocation
Initially, this just makes the code more complicated.  In the end, it
will allow choosing the array size dynamically.
2020-02-26 05:07:34 +00:00
Kp 73612f6667 Move morph_data::morph_vecs into a trailing allocation
Initially, this just makes the code more complicated.  In the end, it
will allow choosing the array size dynamically.
2020-02-26 05:07:34 +00:00
Kp 74f8fd0d4d Move morph_data::morph_times into a trailing allocation
Initially, this just makes the code more complicated.  In the end, it
will allow choosing the array size dynamically.
2020-02-26 05:07:34 +00:00
Kp 00df407381 Use a custom allocation for morph_data
This will enable shrinking the morph arrays to allocate only what is
needed.
2020-02-26 05:07:34 +00:00
Kp ce7cf4f7ef Rename gauges span to avoid conflict with C++20 type of the same name 2020-02-26 05:07:34 +00:00
Kp 5a08c40878 Use zip for morph update_points 2020-02-26 05:07:34 +00:00
Kp 4ec6a13bfa Zip morph polymodel sequences 2020-02-26 05:07:34 +00:00
Kp 9db512a9d6 Simplify Descent2 briefing removal of carriage returns
Read the entire buffer at once, then remove the carriage returns and set
a null terminator.  This reduces the number of calls to PHYSFS_read from
len to 1.
2020-02-26 05:07:34 +00:00
Kp 707df7b9de Move some newdemo functions into namespace dsx 2020-02-26 05:07:34 +00:00
Kp fd134851d1 Pass context to morph_start 2020-02-26 05:07:34 +00:00
Kp d876874475 Factor out morph model header parsing 2020-02-26 05:07:34 +00:00
Kp 94401b4085 Pass LevelUniqueMorphObjectState to find_morph_data 2020-02-26 05:07:34 +00:00
Kp c088f15384 Use std::fill to overwrite poisoned ranges
gcc can replace std::fill with memset when the code would be a loop
writing byte values.
2020-02-11 04:48:14 +00:00
Kp 3f7149a346 Simplify text decoding 2020-02-11 04:48:14 +00:00
Kp 88087fbbab Move Text_string to dsx 2020-02-11 04:48:14 +00:00
Kp bcf06623a5 Disable morph processing in demo files
It reads uninitialized values, so it was barely functional before
morph_data became a dynamic allocation, and it is broken now.  Disable
it to avoid crashing the game.  The demo code should have initialized
the morph_data structure properly, but does not.

Reported-by: tycho <https://github.com/dxx-rebirth/dxx-rebirth/issues/496>
Fixes: cac5f1da56 ("Move morph_data into dynamic allocations")
2020-02-06 03:22:45 +00:00
Kp f1c6177338 Poison morph_data on allocation
Require the caller to provide sane values later.
2020-02-06 03:22:45 +00:00
Kp edc8819409 Add hint about range of bitmap indices
When building with AddressSanitizer, gcc warns that `i` may not fit,
because the compiler fails to adequately constrain the possible values
for `i`.  Add a control-flow hint to inform gcc about valid values.
2020-02-06 03:22:45 +00:00
Kp 74271443ed Add definition of d_level_shared_boss_state::D1_Boss_*_interval
These variables are used, but optimized builds eliminate all reference
to their address, so the build normally succeeds.  Unoptimized builds
retain references to the address, so a definition is required for them.

Reported-by: tycho <https://github.com/dxx-rebirth/dxx-rebirth/issues/496>
Fixes: 595c3ca086 ("Move Boss_cloak_interval to d_level_shared_boss_state")
Fixes: c61dee7e6a ("Move Boss_teleport_interval to d_level_shared_boss_state")
2020-02-06 03:22:45 +00:00
Kp 8ebb66c5c9 Remember player's hostages_on_board across secret level return
Returning from a secret level clears the player's `hostages_on_board` to
0 as part of initializing a "new" ship, but this is not desirable
behavior.  Copy the counter out before and back afterward.

    ```
    Thread 1 "d2x-rebirth-edi" hit Hardware watchpoint 1: -location d2x::LevelUniqueObjectState.Objects._M_elems[0].ctype.player_info.mission.hostages_on_board

    Old value = 5 '\005'
    New value = 0 '\000'

    #0  d2x::init_player_stats_ship (GameTime64=<optimized out>, plrobj=...) at similar/main/gameseq.cpp:613
    #1  d2x::init_player_stats_level (secret_flag=d2x::secret_restore::survived, plrobj=..., plr=...) at similar/main/gameseq.cpp:615
    #2  d2x::StartNewLevelSub (level_num=level_num@entry=3, page_in_textures=page_in_textures@entry=1, secret_flag=secret_flag@entry=d2x::secret_restore::survived) at similar/main/gameseq.cpp:1901
    #3  d2x::state_restore_all_sub (LevelSharedDestructibleLightState=..., secret=d2x::secret_restore::survived, filename=<optimized out>) at similar/main/state.cpp:1670
    #4  d2x::state_restore_all (in_game=in_game@entry=1, secret=secret@entry=d2x::secret_restore::survived, filename_override=<optimized out>, blind=blind@entry=dcx::blind_save::no) at similar/main/state.cpp:1490
    #5  d2x::ExitSecretLevel ()
    ```

Reported-by: teratorn <https://github.com/dxx-rebirth/dxx-rebirth/issues/495>
2020-02-01 22:33:31 +00:00
Kp 0ea0a5ff31 Avoid scaling morph vector by length 0 2020-02-01 22:33:31 +00:00
Kp 7c9b8d61b8 Zip morph elements for traversal
This generates code that increments a group of pointers, instead of
incrementing an index and repeatedly multiplying it to compute each
index.
2020-02-01 22:33:31 +00:00
Kp 2bbda9d92c Factor out morph bounding box setup 2020-02-01 22:33:31 +00:00
Kp 669c341147 Move d_level_unique_morph_object_state to d_level_unique_object_state 2020-02-01 22:33:31 +00:00
Kp cac5f1da56 Move morph_data into dynamic allocations
This improves poison detection, and eliminates some large static
allocations (MAX_VECS * ((2 * vms_vector) + fix)).
2020-02-01 22:33:31 +00:00
Kp c55c7d1bd6 Move morph_data to dcx
Only one member was part of dsx, and it could be dcx instead.
2020-02-01 22:33:31 +00:00
Kp ab55d26051 Zip ranges passed to rotate_point_list
This gains a range check on the output, and makes the relation of input
and output parameters clear in the function signature.
2020-02-01 22:33:31 +00:00
Kp 0db0230689 Use enumerate to manage morph index/pointer 2020-02-01 22:33:31 +00:00
Kp 25d782812c Make some update_points variables const 2020-02-01 22:33:31 +00:00
Kp f65ce8bbe4 Make some init_points variables const 2020-02-01 22:33:31 +00:00
Kp 7eaa8f03d7 Hold polymodel data const in morph code 2020-02-01 22:33:31 +00:00
Kp 0aaa263adf Use enum class for morph_data submodel_state
Name the state members, instead of using magic constants.  Also, switch
from `int` to `uint8_t`, since there are only 3 valid values.
2020-02-01 22:33:31 +00:00
Kp 5653124a43 Move MAX_VECS into morph_data 2020-02-01 22:33:31 +00:00
AlumiuN 915172478f Initial fix for doors with linked walls other than their connected side 2020-01-24 14:12:43 +13:00
Kp 4b48e0cd14 Fix Windows build break
Commit d879fc7f6b changed the type of `newpath` and updated all uses
in common code.  A Windows-only block was skipped.  Update that now.

Fixes: d879fc7f6b ("Convert file selection to use array<char, N>, not char[N]")
2020-01-19 00:33:47 +00:00
Kp 19c5f4064e Fix bogus unused variable warning from clang in inferno.cpp
Fixes: 59b94a4dcb ("Call arch_close before atexit hooks begin")
2020-01-18 22:43:19 +00:00
Kp 81e0b95e1b Merge 'thief-suppress-fix' into master 2020-01-18 21:57:47 +00:00
Kp 844e5f92b2 Fix stack buffer overruns in newdemo code
When presented with an overlong string, throw std::runtime_error instead
of corrupting memory.  Either way, the result is a crash, but this crash
is safe, deterministic, and probably easier to debug.
2020-01-18 21:57:39 +00:00
Kp 1a2cfa35ba Fix saving/loading games for missions in subdirectories
The historical savegame format cannot support finding a mission in a
subdirectory.  Add a backwards-incompatible modification to store the
full path in the savegame, and store it in a way that old versions will
fail gracefully.[1]  When loading demos, or legacy savegames, search for
the mission in all available directories.  Demos are still written with
an unqualified path because the demo loading code would crash if given
an oversized path.  Mission names sent over the network as part of
multiplayer use the guess logic now, so that guests do not need to have
the mission in the same path as the host.

[1] Versions affected by issue #486 may fail ungracefully.

Reported-by: AlumiuN <https://github.com/dxx-rebirth/dxx-rebirth/issues/491>
2020-01-18 21:57:39 +00:00
Kp 3e2d47f879 Track mission type correctly when loading mission list
- In D2X, do not accept Descent2-specific directives from Descent 1
  `.msn` files.
- Set the descent_version field correctly in the `mle`.  Previously,
  `.msn` was set to descent1 and all `.mn2` were set to descent2,
  regardless of whether the `.mn2` used `name`, `xname`, `zname`, or
  `!name`.
- Avoid rewinding the file and rereading the same line while checking
  the possible name types.
- Avoid recomputing end-of-string when it is already known.
- Avoid re-reading the mission file's version when the mission is
  chosen.  Instead, use the version that was recorded when the mission
  was loaded into the mission list.  This also fixes a bug where Descent
  1 `.msn` files would be classified as descent_version_type::descent2
  since both use `name =`, but that string has a different meaning
  depending on whether the file is `.msn` or `.mn2`.
2020-01-18 21:57:39 +00:00
Kp 3d09f4544b Remove macro Current_mission_filename 2020-01-18 21:57:39 +00:00
Kp 99356e0cdb Use enum for include/exclude anarchy mode 2020-01-18 21:57:39 +00:00
Kp d879fc7f6b Convert file selection to use array<char, N>, not char[N]
Eliminate some uses of strncpy as part of the conversion.
2020-01-18 21:57:39 +00:00
AlumiuN f98d8caea1 Make thief bot drop any map-specified items if option to suppress it is enabled 2020-01-10 19:58:54 +13:00
Kp 47a3df9fab Clean invalid robot joint data on load
Some levels have robots with n_joints=0 and an invalid offset.  If the
number of joints is zero, the offset is irrelevant.  Reset it to 0, so
that a later call to partial_range will not trap.

Reported-by: kakhome1 <https://github.com/dxx-rebirth/dxx-rebirth/issues/485>
2020-01-08 04:32:39 +00:00
Kp b0185e44ad Fix displacing players when synthesizing player start positions
TORRaven reported an issue where `Descent: First Strike` level 4 in
cooperative games would cause the player 0 ship to be unable to move.
On investigation, this occurs when the host has enabled extra player
starts, and the resulting synthesis of new player start positions moves
the player 0 start out of its origin segment.  The physics engine reacts
poorly to this situation, causing the object to be unable to move and to
report HIT_BAD_P0 in debug builds.  Add a test to cancel the
displacement if get_seg_masks reports that the center point would move
outside the origin segment.  More clever logic might be appropriate, but
since this is the first report of problems with the feature since its
introduction in 5a64ee5132, this commit just eliminates the
immediate problem.  Possible future improvements if the existing
displacement causes collisions:

- Reduce the magnitude of the existing displacement, instead of
  abandoning it entirely.
- Move the player start to the segment's center before displacing it.
- Add logic to move the player into a nearby logically connected
  segment.

Reported-by: TORRaven <https://github.com/dxx-rebirth/dxx-rebirth/issues/483>
Fixes: 5a64ee5132 ("Add experimental support for larger cooperative games")
2020-01-06 01:25:35 +00:00
Kp ffb4240710 Report failure when a mission is not found in the mission list
AlumiuN reported a crash when a save game is unable to load the
underlying mission.  The crash is because the game proceeds to load the
savegame onto whatever level was loaded before this mission, which will
usually result in fatal inconsistencies in the data.

This commit does not fix the cause of the inability to load the mission,
but instead fixes the logic so that the user gets a reasonable error
message advising that the mission failed to load.  This was
unintentionally broken in db80a88ad2 when the sense of the return
value was inverted, and the fallthrough case was not adjusted.  This
impacts all uses of `load_mission_by_name`, though in practice restoring
from a savegame is the most obvious way to hit the problem.

Reported-by: AlumiuN <https://github.com/dxx-rebirth/dxx-rebirth/issues/486> (indirectly)
Fixes: db80a88ad2 ("Improve error message on failure to load mission")
2020-01-06 01:25:35 +00:00
Kp 59b94a4dcb Call arch_close before atexit hooks begin
arch_close calls various library shutdown routines, some of which may
not be in good order after atexit hooks begin executing.  Call it before
returning from main, so that the libraries are still fully initialized.
2020-01-06 01:25:35 +00:00
Kp e2a108bbf5 Use base32 instead of base64+extended-identifiers
Extended identifiers have proved to cause more problems than they solve.
Switch to base32 which, while less commonly supported, is available in
Python and uses an alphabet that is almost a subset of the C identifier
alphabet.  Padding characters are still a problem, but can be remapped
to a valid C identifier that is not a valid base32 character.
2019-12-29 22:24:20 +00:00
Kp 05a54ef7c1 Merge pull #479 into master 2019-12-27 02:08:58 +00:00
Kp ce906560ab Use susegment for segment2_read 2019-12-27 02:02:23 +00:00
Kp 34366d84c2 Use susegment for dumpmine iteration 2019-12-27 02:02:23 +00:00
Kp c9b1b5b1ec Use susegment for WALL_IS_DOORWAY 2019-12-27 02:02:23 +00:00
ziplantil 398d9013ef Merge remote-tracking branch 'upstream/master' into vertigo-exit-fix 2019-12-24 01:49:11 +02:00
Kp dfae1c7203 Split object_move_all for game/endlevel
endlevel wants to freeze the console player's last in-mine position.
Instead of copying the position out and back, refactor the flow to let
endlevel skip the update of the position.
2019-12-22 05:34:08 +00:00
Kp 36873ec12d Simplify maybe_ai_do_actual_firing_stuff
The second parameter always points to a substructure in the first
parameter.  Remove the second parameter.
2019-12-22 05:34:08 +00:00
Kp 5dfd62c4f6 Use susegment for references introduced by valptridx conversion 2019-12-22 05:34:08 +00:00
Kp c93e7f44c3 Move object::last_pos to LevelUniqueObjectState
Only the console player's last position needs to be remembered across
frames.  Copy the console player's position out before processsing
object movement.  For all other objects, retain a temporary for use by
the position recovery code.
2019-12-22 05:34:08 +00:00
Kp 30091902af Simplify valptridx types where possible
Switch valptridx::ptr to a reference type.
Switch valptridx::ptridx to a reference type or to ::ptr.

Fix up uses of operator-> accordingly.
2019-12-22 05:34:08 +00:00
Kp c3265f6b90 Convert segment & to susegment where possible 2019-12-22 05:34:08 +00:00
Kp 00d09b2bdb Move free_object_slots predicates to dcx 2019-12-22 05:34:08 +00:00
Kp cc144647b5 Make kconfig.ui-table.cpp compile when freestanding
Special macros are used to pass information to
`generate-kconfig-udlr.py`.  Provide default definitions for these
macros in `kconfig.ui-table.cpp`, and override them in the one build
where they need to be special.  This enables `kconfig.ui-table.cpp` to
build cleanly when invoked from the command line in the compilation
database.
2019-12-22 05:34:08 +00:00
Kp f26d91bbe2 Change kconfig type/state fields to enums 2019-12-22 05:34:08 +00:00
Kp d2f2f98850 Use symbolic STATE_NONE for kconfig entries with no state bit 2019-12-22 05:34:08 +00:00
ziplantil 4cb06c43f7 revert to old load behavior when emulating D1 2019-12-21 23:42:04 +02:00
ziplantil e5c7d47199 adjust exit bitmap indexes for hatch models 2019-12-19 15:33:58 +02:00
ziplantil 0a21784aa7 some changes as per comments in #479 2019-12-18 13:44:43 +02:00
Kp 6b637e856b Copy last_hitobj to a temporary before passing it to reset_hitobj
obj_rw is a packed structure, so configurations where reset_hitobj takes
its parameter by reference (or where its parameter requires passing
through a constructor that takes its input by reference) fail because
gcc refuses to bind a reference to a member of a packed structure.  Copy
the member variable into a local, which gcc will bind.
2019-12-16 01:56:59 +00:00
Kp 3f74084c0f Include segment.h for terrain.cpp to handle over-eager instantiation
In some configurations, gcc (but not clang) instantiate
valptridx<segment>::array_managed_type too eagerly, then fail if the
sizeof(segment) is unknown.  Include segment.h so that the size is
available.
2019-12-16 01:56:59 +00:00
Kp 219a3fcd11 Move laser_info::get_last_hitobj out of line
It is only used in two places, neither of which are hot paths.  Move it
out of line so that other files do not need to parse it.
2019-12-16 01:56:59 +00:00
Kp 28d9358b00 Expand local aliases to their target variables
This makes the code easier to read, at the price of a bit of churn.
2019-12-16 01:56:59 +00:00
ziplantil 341c622e69 that verbose one is no longer needed 2019-12-12 17:42:53 +02:00
ziplantil ed88836e9d make sure there is enough space to load exit data 2019-12-12 17:34:42 +02:00
ziplantil cb2b844af3 do not free extra models when loading exit stuff on D2 2019-12-12 17:25:11 +02:00
Kp ca383c1fe7 Fix Win32 build of scores.cpp
Fixes: 0b8f32d744 ("Set player name in Players[] at single-player game start")
2019-11-19 02:42:24 +00:00
Kp b399794a53 Remove test for unconverted characters after a superx= line
Historically, Descent ignored any trailing unconverted characters.  The
logic in Descent 1 was tightened in 3368390f37, and then the logic in
Descent 2 was made to mirror Descent 1 in 19699037ce.  Restore the lax
parsing logic in both games.

Reported-by: InsanityBringer <https://github.com/dxx-rebirth/dxx-rebirth/issues/464> (issue 5)
Fixes: 3368390f37 ("Check for valid SuperX number") (for Descent 1)
Fixes: 19699037ce ("Move d2x-rebirth/main/bmread.cpp -> similar/main/bmread.cpp") (for Descent 2)
2019-11-18 00:22:34 +00:00
Kp abb000177a Move bm_read_reactor object type check into if(D1)
In Descent 2, `type` is initialized at declaration time, then never
rewritten.  At the end of the function, `Error` is called if `type` has
not been rewritten.  Originally, `type` was hard reset to
`OL_CONTROL_CENTER`, but this reinitialization was removed when
`ObjType` and related data were removed from Descent 2.

Reported-by: InsanityBringer <https://github.com/dxx-rebirth/dxx-rebirth/issues/464> (issue 3)
Fixes: ea7ba7ae87 ("remove ObjType, ObjId, ObjStrength and OL_ constants; use "object" instead of "robot" in some places; draw and place reactors with correct modelnum")
2019-11-18 00:22:34 +00:00
Kp adf12be0be Clear bm_load_sub:fname before use
Later writes do not guarantee null termination.  Clear the entire buffer
first, since it is small.

Reported-by: InsanityBringer <https://github.com/dxx-rebirth/dxx-rebirth/issues/464> (issue 2)
2019-11-18 00:22:34 +00:00
Kp ba283fb036 Sort mission directories to the top of the list, behind builtin missions
This is an observable change, but hopefully is an improvement overall.
2019-11-17 01:42:09 +00:00
Kp 6f54229f5a Sort missions in subdirectories
Mission sorting is handled in a top-level function after the missions
have been found, so that the special case to promote built-in missions
is only applied at the top level.  Unfortunately, this meant that
subdirectories were not sorted.  Add an explicit sort in a path specific
to subdirectory handling.

Reported-by: AlumiuN <https://github.com/dxx-rebirth/dxx-rebirth/issues/472>
2019-11-17 01:35:08 +00:00
Kp 600dac43d8 Only count a robot as dropped after the object is created
If object creation fails, the counter is not decreased.  This creates an
imbalance by over counting the number of robots in existence.  Avoid
this imbalance by deferring the counter update until after the robot is
created.
2019-11-16 23:14:41 +00:00
Kp c6770c3dde Fix robot accounting when robots drop robots
When a robot drops a robot, the dropped robot is not added to the
level's running accumulated_robots counter, but when the player destroys
that robot, the destruction will be counted.  This imbalance allows the
expression counting the number of not-yet-destroyed robots to underflow,
which then confuses the matcen logic into not creating new robots.

Fix this by incrementing the accumulated_robots count as each dropped
robot is created.

Reported-by: ziplantil <https://github.com/dxx-rebirth/dxx-rebirth/issues/466>
2019-11-16 23:14:41 +00:00
Kp c8c5ed9b86 Merge branch osx-build into master
This change was proposed by an external user as a claimed fix for a
failure to build.  This change has not been tested by the core team.
However, it is a simple change and at worst will break the build.

The change is based in part on advice from recurring contributor
@MaddTheSane.  Neither @MaddTheSane nor @kreatordxx have commented on
the correctness of these changes, though the original author of the
commit, @Sottises, is listed as the origin of the most recent prebuilt
OS X package offered from
<https://www.dxx-rebirth.com/download-dxx-rebirth/>.

Reported-by: Sottises <https://github.com/dxx-rebirth/dxx-rebirth/issues/455>
2019-11-16 22:46:48 +00:00
Kp 93d3793b30 Fix crash entering secret level with music on, and no songs
If music is configured as built-in, and no secret songs are configured,
then BIMSecretSongs is set to a non-null pointer to a zero-element
array.  This triggers a divide-by-zero when the array length is used in
a modulus operation.

Fix this by adding a special case that initializing from an empty vector
calls `reset()`, which causes the underlying unique_ptr to store
`nullptr` instead of `new bim_song_info[0]`.

Reported-by: Daniel-Leontiev <https://github.com/dxx-rebirth/dxx-rebirth/issues/465>
Fixes: c355e207fe ("Refactor song loading")
2019-11-02 04:36:15 +00:00
Kp f43665917e Merge branch ziplantil/win32-sdl2-cdaudio-sync into master 2019-10-28 00:45:34 +00:00
ziplantil e664d93ea4 add hack for MCI or CD driver bug (?) 2019-10-27 02:48:20 +03:00
ziplantil 2c5ab8e739 initial version of this, trying to catch MCI events 2019-10-27 02:47:45 +03:00
Kp d2640462cb Backport D2's Dont_start_sound_objects to D1
Descent 2 has a hack, present as far back as I can trace, that
suppresses starting sounds during level load.  The original reason was
not recorded, but this hack has the useful side effect that it avoids
using uninitialized data when set_sound_sources tries to use a Viewer
that has not been reset for the objects of the new level.

Descent 1 lacks this hack, so an invalid Viewer is used, which may
trigger a valptridx trap if the undefined data has an invalid segment
number, and could cause memory corruption in builds which do not
validate the segment index.  The valptridx trap:

```
terminate called after throwing an instance of 'valptridx<dcx::segment>::index_range_exception'
  what():  similar/main/digiobj.cpp:389: invalid index used in array subscript: base=(nil) size=9000 index=65021
```

The backtrace leading to the trap:
```
d1x::digi_link_sound_common (viewer=..., so=..., pos=..., forever=<optimized out>, max_volume=<optimized out>, max_distance=..., soundnum=42, segnum=...) at similar/main/digiobj.cpp:389
0x00005555555a4e2d in d1x::digi_link_sound_to_pos2 (vcobjptr=..., max_distance=..., max_volume=32768, forever=1, pos=..., sidenum=4, segnum=..., org_soundnum=121) at similar/main/digiobj.cpp:483
d1x::digi_link_sound_to_pos (soundnum=soundnum@entry=121, segnum=..., sidenum=sidenum@entry=4, pos=..., forever=forever@entry=1, max_volume=32768) at similar/main/digiobj.cpp:490
0x00005555555c140d in d1x::set_sound_sources (vcsegptridx=..., vcvertptr=...) at similar/main/gameseq.cpp:817
d1x::LoadLevel (level_num=<optimized out>, page_in_textures=1) at similar/main/gameseq.cpp:1022
0x00005555555c2654 in d1x::StartNewLevelSub (level_num=-1, page_in_textures=<optimized out>) at similar/main/gameseq.cpp:1865
```

Backport this hack into Descent 1.  Ultimately, the hack should go away
and data should be loaded in an order that does not access undefined
memory.

Reported-by: Spacecpp <https://github.com/dxx-rebirth/dxx-rebirth/issues/463>
2019-10-26 23:13:14 +00:00
Kp 15b0ec7f42 Fix externally reported Mac OS X build break
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSGeometry.h:10:9: fatal error:
	  'CoreGraphics/CGBase.h' file not found
    #import <CoreGraphics/CGBase.h>
	    ^~~~~~~~~~~~~~~~~~~~~~~
    /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSGeometry.h:10:9: note: did not
	  find header 'CGBase.h' in framework 'CoreGraphics' (loaded from
	  '/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks')
    similar/misc/physfsx.cpp:20:10: fatal error: 'HIServices/Processes.h' file not found
    #include <HIServices/Processes.h>

Since this is an OS X problem, this has only been tested by the original
reporter.

Reported-by: Sottises <https://github.com/dxx-rebirth/dxx-rebirth/issues/455>
Suggested-by: MaddTheSane <https://github.com/dxx-rebirth/dxx-rebirth/issues/455#issuecomment-536164089> # SConstruct part
2019-10-23 03:02:16 +00:00
Kp 781a7366a9 Whitelist Vertigo smelter's phoenix cannon
Reported-by: ziplantil <https://github.com/dxx-rebirth/dxx-rebirth/issues/458>
Fixes: 2bcc7bb371 ("Only create lasers for known weapon types")
2019-10-21 03:45:29 +00:00
Kp 9d22103d45 Prevent markers spinning in marker-camera-enabled games
Commit 0df57f5b0f changed markers' movement type from MT_NONE to
MT_SPINNING, since retail code assigned a spin rate, suggesting markers
were meant to spin.  However, in some anarchy games, markers are used as
player-positioned cameras.  Spinning the cameras makes them hard to use.
Resolve this by preventing markers from spinning in such games.

Fixes: 0df57f5b0f ("Fix retail bug that prevented marker spinning")
Reported-by: flpduarte <https://github.com/dxx-rebirth/dxx-rebirth/issues/456>
2019-10-02 02:06:00 +00:00
Christian Beckhäuser dafdcb8596 Rework of the Descent 2 final boss fade-to-black effect introduced in 5b18219aac4dd535e2803de9310ba26dfa7acc28: In the original game the silent 2 second countdown would lapse before the screen faded to black. In restoration, it would fade to black as the countdown started. This rework fixes this discrepancy. 2019-09-17 21:49:18 +02:00
Christian Beckhäuser 5b18219aac Restored fade to black after defeating the final Descent 2 boss which was lost along with software rendering screen fade effects. New implementation is done in similar way as the fade to white after regular countown reaches 0 while trying to restore the original effect as faithfully as possible (except that it doesn't pause the game during the effect). 2019-09-12 14:54:55 +02:00
Kp d6b2ab51a7 Merge branch 'Daivuk:axis_buttons' into master
Requested-by: Daivuk <https://github.com/dxx-rebirth/dxx-rebirth/pull/452>
2019-09-01 18:15:26 +00:00
daivuk 74ef8b02e6 Added axis buttons
Each axis can act as two buttons in both ways.
For example, a player might map slide left and slide right to J1 -A1 and J1 +A1 as button presses instead of the slide L/R axis.

This is mostly to fix XBox 360 Controller Left and Right triggers. But it can work on every axis if the player wishes to bind them.
2019-09-01 13:11:14 -04:00
Kp 183f11cc68 Do not charge player for failed primary weapon shots
Defer decreasing energy/vulcan until the object is confirmed to be
created.  This avoids charging the player for a shot that cannot be
created due to object exhaustion.

Defer updating Next_laser_fire_time, so that a player can immediately
try firing again.
2019-09-01 00:20:28 +00:00
Kp b6fd9eafd7 Do not charge player for failed secondary weapon shots
Defer decreasing energy (for flares) or secondary weapon count (for
secondaries) until the object is confirmed to be created.  This avoids
charging the player for a shot that cannot be created due to object
exhaustion.
2019-09-01 00:20:28 +00:00
Kp 275c4297fe Write back Final_boss_countdown_time on every update
Otherwise, unless FrameTime exceeds Final_boss_countdown_time in a
single frame, the time never advances and the level never ends.

Fixes: 215252b8ca ("Fold Final_boss_is_dead into Final_boss_countdown_time")
2019-09-01 00:20:28 +00:00
Kp 33c893e3e2 Make del+shift+b do fatal damage to every robot it explodes
Run through more of the normal death logic for the robots, instead of
simply deleting them from existence.
2019-09-01 00:20:28 +00:00
Kp 29c3551fa9 Fix crash loading endlevel data with no exit side
Reported-by: ziplantil <https://github.com/dxx-rebirth/dxx-rebirth/issues/450>
2019-08-31 17:31:51 +00:00
Kp 9bb6a95e90 Set player name in Players[] at single-player game load
The prior commit fixed the problem of a blank pilot name for new games,
but loading an existing save game uses a different path and still did
not set the player's callsign.  Set it on load, too.

Fixes: 0c7de10512 ("Track chosen pilot name outside Players[]")
2019-08-29 02:40:32 +00:00
Kp 0b8f32d744 Set player name in Players[] at single-player game start
Single player games relied on the quirk that the pilot's name was always
kept in Players[], even outside a game.  Commit 0c7de10512 removed
that quirk, which had the unintended consequence that single player
games are now played by the anonymous pilot.  Set the player's callsign
during game setup so that the high score entry can be attributed
correctly.

Fixes: 0c7de10512 ("Track chosen pilot name outside Players[]")
Reported-by: Neurochild247 <https://github.com/dxx-rebirth/dxx-rebirth/issues/443>
Bisected-by: zicodxx <https://github.com/dxx-rebirth/dxx-rebirth/issues/443#issuecomment-523827234>
2019-08-25 17:53:57 +00:00
Kp e7275f8a8c Align capitalization of Data directory in instructions with the code
Commit e6169f17f9 switched from searching `Data/` to searching
`data/`.  For users on case-insensitive filesystems, this is a no-op and
the instructions that reference the `Data` directory continue to work.
For users on case-sensitive filesystems, the change broke accessing the
data directory, and caused the instructions to mislead.  Given the age
of the commit, fixing the capitalization now will likely cause more
problems than it solves.  Instead, fix the capitalization of the
instructions, so that users who follow the documentation get a working
setup.

Reported-by: krux02 <https://github.com/dxx-rebirth/dxx-rebirth/issues/447>
Fixes: e6169f17f9 ("Add 'Data' subdir as a searchpath, so D2X will find descent.pig and to simplify a lot of file opening/checking/closing code")
2019-08-25 17:06:34 +00:00
Kp c355e207fe Refactor song loading
Use an RAII object to manage allocations and keep the length and pointer
together.
2019-08-25 16:43:17 +00:00
Kp 4cf4e60d25 Merge branch ziplantil:dxxrsngsecretlvl to master 2019-08-24 19:49:22 +00:00
Kp 4504f3602a Hide lives-remaining count during demo playback
The demo system does not track this, so hide it instead of showing
incorrect information.
2019-08-24 18:14:16 +00:00
Kp dd0f639176 Avoid reducing player's highest-level when replaying a non-MRU level
If the level was not the most recently played, a save is forced so that
it can be marked as most recently played.  However, the logic to force
the save also forced an update of the highest-level field, even if that
reduced it.

- Rename the parameter to clarify its meaning.
- Add comments explaining the logic to force the save.
- Only update the highest-level field when the update would increase the saved value
2019-08-24 04:32:24 +00:00
Kp 211a172c1d Tighten checks on killer_obj type
Do not assume that a type other than OBJ_ROBOT will be OBJ_WEAPON.
Check explicitly for OBJ_WEAPON.

Reported-by: Johnsondr80 <https://github.com/dxx-rebirth/dxx-rebirth/issues/437>
2019-08-21 02:54:08 +00:00
Kp 653a705e90 Test that guided missile's parent is still a player
If a guided missile is in flight, and its owning player dies, the
player's type is changed to OBJ_GHOST.  The damage that killed the
player should have put the guided missile into autonomous mode, so for
this purpose, return that the missile is not actively guided.

Reported-by: Johnsondr80 <https://github.com/dxx-rebirth/dxx-rebirth/issues/437>
2019-08-21 02:54:08 +00:00
Kp 6d0cd8513e Recompute automap subcanvas on window size change
The subcanvas is positioned based on the dimensions of the containing
window, so it must be repositioned if the outer window is resized.

Reported-by: vLKp <https://github.com/dxx-rebirth/dxx-rebirth/issues/394>
Fixes: f491059ed7 ("Enable building with SDL2")
2019-08-18 20:37:29 +00:00
ziplantil 6588bd6626 refactor secret level music code 2019-08-18 20:18:34 +03:00
ziplantil 79e0e2fdea dxx-r.sng: add !Rebirth.secret 2019-08-16 00:20:52 +03:00
Kp ade6ee4195 Move exit_segnum to d_player_unique_endlevel_state
exit_segnum is set during load_endlevel_data, which currently runs too
early for this to depend on the exit used, and thus to be player-unique.
That data should be loaded at need, when the level ends, rather than
during level setup.  This can be addressed later, when support for
multiple exits is improved.
2019-08-15 01:34:22 +00:00
Kp 2daf788b34 Move transition_segnum to d_player_unique_endlevel_state
transition_segnum is a function of how the player exited the mine, since
there could be multiple exit tunnels, although current code appears not
to handle that well in other places.  Therefore, it needs to be
per-player data, not part of the level data, where it would not depend
on the player exiting.
2019-08-15 01:34:22 +00:00
Kp 6fe1c90aef Make D2 emulate D1 homers in D1 missions 2019-08-15 01:34:22 +00:00
Kp 4f8df36129 Compact HandleDeathInput 2019-08-15 01:34:22 +00:00
Kp 9bafdc9078 Move Death_sequence_aborted to d_game_view_unique_state 2019-08-15 01:34:22 +00:00
Kp 6f9657cf9b Move controlcen_death_silence to d_level_unique_control_center_state 2019-08-15 01:34:22 +00:00
Kp 9f0b455f6d Move Reactor_strength to d_level_shared_control_center_state 2019-08-15 01:34:22 +00:00
Kp 9689a7f7d2 Move Base_control_center_explosion_time to d_level_shared_control_center_state 2019-08-15 01:34:22 +00:00
Kp e58daea0da Restrict reactor-sleep logic to D2 levels
This code was not in D1, so running it when emulating D1 on the D2
engine is incorrect.
2019-08-15 01:34:22 +00:00
Kp f2eebca6c3 Move Last_time_cc_vis_check to d_level_unique_control_center_state 2019-08-15 01:34:22 +00:00
Kp d9d536afda Move Control_center_player_been_seen to d_level_unique_control_center_state 2019-08-15 01:34:22 +00:00
Kp 0826881fa0 Move Dead_controlcen_object_num to d_level_unique_control_center_state 2019-08-15 01:34:22 +00:00
Kp d0a9d8db98 Move Control_center_present to d_level_unique_control_center_state
This could be a shared variable instead, since it cannot be directly
influenced by gameplay.  However, it is influenced by the game mode, and
keeping shared variables that are mode-specific would be more complexity
for very little savings.
2019-08-15 01:34:22 +00:00
Kp edc1ec0729 Fold multi_do_controlcen_destroy call of net_destroy_controlcen 2019-08-15 01:34:22 +00:00
Kp 11278eb153 Rename Control_center_next_fire_time to Frametime_until_next_fire
Clarify the type of the value.
2019-08-15 01:34:22 +00:00
Kp 195f5e7d9f Move Control_center_next_fire_time to d_level_unique_control_center_state 2019-08-15 01:34:22 +00:00
Kp 885296b136 Move Control_center_been_hit to d_level_unique_control_center_state 2019-08-15 01:34:22 +00:00
Kp f988948eef Move Countdown_timer to d_level_unique_control_center_state 2019-08-15 01:34:22 +00:00
Kp 21c927584b Move Total_countdown_time to d_level_unique_control_center_state 2019-08-15 01:34:22 +00:00
Kp 707b3c5b0d Move Countdown_seconds_left to d_level_unique_control_center_state 2019-08-15 01:34:22 +00:00
Kp 519edb9e16 Move Control_center_destroyed to d_level_unique_control_center_state 2019-08-15 01:34:22 +00:00
Kp 0d9e032c60 Factor out some multi net_destroy_controlcen usage 2019-08-15 01:34:22 +00:00
Kp fd09f9d36b Add is_proximity_bomb_or_any_smart_mine
Zico's commit 38fabd7c49 open-coded a test for a robot smart mine.  So
far, this is the only place it is needed, but others might arise.  Move
the test and its comment out to a static helper function.
2019-08-15 01:34:22 +00:00
Kp 8997f622bd is_proximity_bomb_or_smart_mine*: s/smart/player_smart/g
As documented in zico's commit 38fabd7c49, robot smart mines have a
different ID number than player smart mines.  Rename the test functions
to clarify that they only recognize player smart mines, but not robot
smart mines.

git grep -l is_proximity_bomb_or_smart_mine | xargs sed -i -e 's/is_proximity_bomb_or_smart_mine/is_proximity_bomb_or_player_smart_mine/g'
2019-08-15 01:34:22 +00:00
Kp b8cb819bb4 Make read_sndfile static for D1
Currently, only D2 can reread sounds.  Restore static for D1
read_sndfile.
2019-08-15 01:34:22 +00:00
ziplantil d9c113c315 load .s11,.s22 when loading D2 mission to allow custom sounds 2019-08-13 22:47:22 +03:00
Christian Beckhäuser 38fabd7c49 Fixed two issues with game's transparency effects feature (which I introduced when implementing it): First, Superprox mines dropped by enemies were made undesirably transparent since they have their own ID not considered by is_proximity_bomb_or_smart_mine(). Second, only some force field textures in D2X had transparency effects since the game has two different textures for force fields - eclip num 78 and 93 - but only the former was defined and used in is_alphablend_eclip() 2019-08-08 11:57:52 +02:00
Kp ec234e0b8e Cache intermediate values in draw_mine_exit_cover 2019-08-06 03:02:32 +00:00