Commit graph

9064 commits

Author SHA1 Message Date
Kp 495bf624d2 Shorten collide_weapon_and_controlcen hitobj test 2016-11-19 17:24:54 +00:00
Kp a4edf4817c Cache properties_init bitmap width 2016-11-19 17:24:53 +00:00
Kp 1f929796c3 Fix excess fusion reflection 2016-11-19 17:24:53 +00:00
Kp 8c4d24ea6f Shorten collide_robot_and_weapon hitobj test 2016-11-19 17:24:53 +00:00
Kp e0d24f242b Fix uninitialized signature access
`obj_get_signature()` examines all objects with a type other than
`OBJ_NONE` to find an unused signature.
`load_game_data()`->`read_object()` set an object's type before calling
`obj_get_signature()`, so `obj_get_signature()` would consider the
uninitialized signature of the newly loaded object for exclusion.
Reorder the initialization to compute the signature before the object is
given a type, then store the signature on the object after the poison
bytes (if any) are written.
2016-11-19 17:24:53 +00:00
Kp 382d337118 Switch obj_get_signature to std::any_of
Also, split the predicate into separate statements to improve the output
of analysis tools.
2016-11-19 17:24:53 +00:00
Kp 223a9dfd56 Pass grs_bitmap &to piggy_register_bitmap 2016-11-19 17:24:53 +00:00
Kp 47de4e2906 Pass grs_bitmap &to swap_0_255 2016-11-19 17:24:52 +00:00
Kp 2dd4b574c7 Use virtual function to dispatch window events 2016-11-19 17:24:52 +00:00
Kp 7f9d54a241 Combine multi_endlevel_score player flags updates 2016-11-19 17:24:52 +00:00
Kp 61c11ec4d4 Use d_enumerate for SDL joystick loops 2016-11-19 17:24:52 +00:00
Kp 716b320c34 Use utility d_enumerate for do_cloak_stuff 2016-11-19 17:24:52 +00:00
Kp bb135e546e Set Descent 1 paged out bitmaps to nullptr
Descent 2 sets nullptr in the bitmap data field.  Do the same in Descent
1 for consistency.
2016-11-19 17:24:52 +00:00
Kp 53edbee901 Propagate constant texmerge_init argument 2016-11-19 17:24:52 +00:00
Kp 6db96d1a6d Fix file.cpp -Wunused-but-set-variable
Commit 1c8ad24 removed all reads of `wind`, but did not remove its
assignment or declaration.  This breaks the build with gcc due to
-Wunused-but-set-variable.

Fixes: 1c8ad24da3 ("Check for window_event_result::deleted for ui_get_filename polling loop")
2016-11-19 17:24:51 +00:00
Kp 98afafb80f Fix gadget.cpp -Wunused-but-set-variable
Commit 917f079 removed all reads of `wind`, but did not remove its
assignment or declaration.  This breaks the build with gcc due to
-Wunused-but-set-variable.

Fixes: 917f079f02 ("Check for window_event_result::deleted in ui_dialog_do_gadgets")
2016-11-19 17:24:51 +00:00
Kp b43dcc1a52 Revert "Disable piggy_bitmap_page_out_all"
This reverts commit 3c20c24ac0.

Rebirth no longer contains the Descent memory manager, but Rebirth still
has many traces of the paging support used in the DOS version.  One of
the unfortunate and subtle traces of this support is that it allocates a
contiguous buffer for game data and loads many of the games bitmaps into
that buffer.  The buffer is large enough for most workloads, but not
all.  When the buffer is too small, it is discarded by
piggy_bitmap_page_out_all and rebuilt piecemeal to contain only what it
needs.  Fixing this would be nice, but the memory ownership rules are
messy.  The performance consequences of the legacy approach are not
sufficient to justify the effort to fix this properly.  Instead, revert
to the legacy design.
2016-11-19 17:24:51 +00:00
Chris Taylor a06316f11e Fix crash when pressing Meta key (or Command key for Macs) in editor 2016-11-15 17:20:35 +08:00
Chris Taylor 6df1b85b87 Fix error due to -Werror -Wmissing-declarations in write_mission
This error was reported for gcc. Also set file extension correctly for 'enhanced' missions (though currently unused). Also some tidying up in response to feedback.
2016-11-15 15:03:34 +08:00
Chris Taylor 0e0bc755be Write mission file when calling create_new_mission
This removes an ambiguity when loading a saved game - we need to know the mission descent version **before** calling LoadLevel in state_restore_all_sub (a chicken and egg situation if we go down the fake dummy mission path). This also creates a fully playable mission (albeit simple).
2016-11-14 21:42:35 +08:00
Kp 117d2f73e0 Merge branch github/master into master 2016-11-13 19:56:52 +00:00
Kp 8c4668179e Merge refs/pull/264/head into master 2016-11-13 17:02:26 +00:00
Chris Taylor c6f5e91f4a Saved games from editor generated levels now work
Editor generated levels use the dummy mission created by create_new_mission.
2016-11-13 17:21:45 +08:00
Chris Taylor cf0065da34 More efficiently check if editor loaded properly from within a game 2016-11-13 13:34:13 +08:00
Chris Taylor cc3f35649f Change all occurrences of "Couldn't" to "Could not" for consistency ("Could not" is more common and wins).
Not touching TXT_COULDNT because it's stored separately in hog file.
2016-11-13 13:27:18 +08:00
Chris Taylor 9183bba508 Change pads local var in init_editor to static to save on space for 64 bit systems 2016-11-13 13:09:31 +08:00
Chris Taylor 7dd21e7564 Use wallptridx in wall_dialog_handler, removing need for separate index variable 'wd' 2016-11-13 13:04:00 +08:00
Chris Taylor 1761d696fe Check if dir is empty string the more efficient way in file_getdirlist 2016-11-13 12:49:08 +08:00
Chris Taylor 5f19a3cba9 Remove redundant checks and initialisations recently added for editor 2016-11-13 12:44:53 +08:00
Chris Taylor c075d9641c Merge branch 'master' into editor_fixes 2016-11-13 12:31:27 +08:00
Chris Taylor e597f159e9 In event_process, handle the case of a window deleted in drawing loop with no previous window correctly, preventing possible crash 2016-11-13 11:47:59 +08:00
zico 336df21d2c Change/Addition to dafd4a69be, adopting vKp's proposed solution (which I was too blind to notice): Instead of initializing segnum for object syncing, test for object type instead of segnum for obj_unlink() 2016-11-13 03:42:11 +01:00
Kp 73d014c048 Tighten getaddrinfo test
To recognize getaddrinfo as supported, require that the AI_* flags
passed to it be usable:
- AI_NUMERICSERV must be defined as a number or be undefined
- If ipv6=1, then AI_V4MAPPED and AI_ALL must be defined as numbers

When getaddrinfo is used, raise _WIN32_WINNT from 0x501 to 0x600.
Otherwise, lower it to 0x500.
2016-11-12 20:58:16 +00:00
Kp fd39a752dd Factor out cloaking wall utility loops 2016-11-12 18:10:10 +00:00
Kp 38fb4c9c9e Pass cloaking_wall &to do_{,de}cloaking_wall_frame 2016-11-12 18:10:10 +00:00
Kp e8f9f22635 Factor out do_{,de}cloaking_wall_frame common head/tail 2016-11-12 18:10:10 +00:00
Kp b4b0de8801 Cache uvl pointers in do_decloaking_wall_frame 2016-11-12 18:10:10 +00:00
Kp c4a20b019e Simplify test for cloak_value change 2016-11-12 18:10:09 +00:00
Kp be08b119e6 Prepare do_cloaking_wall_frame for future work
Move the wall reference member into a structure, so that future work can
initialize front/back data in a cleaner way.
2016-11-12 18:10:09 +00:00
Kp c54948f916 Eliminate some wback tests in cloaking wall code 2016-11-12 18:10:09 +00:00
Kp f208a8490f Move do_cloaking_wall_frame demo test up 2016-11-12 18:10:09 +00:00
Kp fdc0575133 Cache goal textures
Find the index of the red/blue/hoard goal textures once when
multi_apply_goal_textures starts, instead of each time a goal segment is
found.
2016-11-12 18:10:09 +00:00
Kp 0cc020c217 Prefer DXX_CONSTANT_TRUE over DXX_HAVE_BUILTIN_CONSTANT_P 2016-11-12 18:10:09 +00:00
Kp 36f23e8d60 Use enum class for multi_send_endlevel_start 2016-11-12 18:10:09 +00:00
Kp 7a0a20d455 Remove secret-level flag in D2 MP message
It is always zero.
2016-11-12 18:10:08 +00:00
Kp f6ca0abf5f Fold multi_do_escape flag handling 2016-11-12 18:10:08 +00:00
Kp 6838ffaa95 Move Omega_recharge_delay to player_info 2016-11-12 18:10:08 +00:00
Kp 7064a56788 Track omega recharge delay as relative time
This fixes two problems on systems where sizeof(int) < sizeof(fix64)
(which applies on most systems).

Normally, the omega cannon does not charge for ~1/3 of a
second after firing stops.

The first problem is that, if (Last_omega_fire_time + 1/3 second)
exceeds 0x80000000 (about 9.1 hours), truncation issues confuse this
rule into not applying, thus allowing the omega cannon to charge
whenever energy is available, even while firing.

The second problem is that, if GameTime64 exceeds 0x8000000000000000
(about 4459701.8 years), a sanity check that attempted to compensate for
the incorrect tracking of Last_omega_fire_time would confuse the
recharge rule into deciding that the user had always fired recently,
which would prevent the omega cannon from ever recharging.  The sanity
check would reset Last_omega_fire_time when Last_omega_fire_time was in
the future relative to GameTime64.  Unfortunately, Last_omega_fire_time
was only an int, so the reset truncates off the high bits of GameTime64.
This truncation is harmless when GameTime64 is less than 0x80000000,
causes the first problem when GameTime64 is not less than 0x80000000,
but is positive, and causes the second problem when GameTime64 is
negative.

These problems were mitigated in prior releases by three factors.  First,
a hack resets GameTime64 when restoring from a saved game, so the
affected game needs to run for ~9.1 hours (or ~4459701.8 years) without
reloading.  Second, starting a new level resets GameTime64, so the game
needs to stay on a single level for ~9.1 hours (or ~4459701.8 years).
Third, the omega cannon discharges faster than it can recharge, so even
when the first bug allowed it to charge while firing, a player could
still drain Omega_charge to zero by continuous firing.  However, it
would take longer to drain due to the bug-induced concurrent recharge,
and would not be subject to the 1/3 second wait normally imposed between
depleting Omega_charge and recharge beginning.

Fix these problems by replacing Last_omega_fire_time with
Omega_recharge_delay, which is 0 when recharging is allowed or a
positive amount of frame time if recharging is disallowed due to recent
firing.  Set Omega_recharge_delay to 1/3 second when the user fires.
Decrease it by up to FrameTime when omega_recharge_frame runs.

This does not fix the preexisting problem that reloading a savegame does
not update the recharge delay, which manifests two related problems.
First, firing the omega cannon and then loading a game will bring the
delay through into the save, whether or not the user had been firing
just before saving.  Second, not firing the omega cannon and then
loading a game will allow the user to fire immediately on load, even if
the user had been firing when the game was saved.  Future work can
address the first problem by clearing the delay, but a savegame file
modification is required to address the second problem.

------------->8-------------

    #include <cstdio>

    int last_fire;
    long t64;
    /* The test program only shows the bug on 64-bit systems */
    static_assert(sizeof(last_fire) == 4, "sizeof(int) != 4");
    static_assert(sizeof(t64) == 8, "sizeof(long) != 8");

    void frame(bool expect_recharge, const unsigned line)
    /* clang does not support __builtin_LINE, so fake it with a macro
     */
    #define frame(E)    frame(E, __LINE__)
    {
	    if (last_fire > t64)
	    {
		    printf(__FILE__ ":%u:%u:                        last_fire=%8x t64=%16lx: last_fire > t64, resetting\n", __LINE__, line, last_fire, t64);
		    last_fire = t64;
	    }
	    const int time_bias = 0x5555;
	    if (last_fire + time_bias > t64)
	    {
		    printf(__FILE__ ":%u:%u: %5sexpect_recharge=%i last_fire=%8x t64=%16lx: last_fire recent (%16lx), refusing to recharge\n", __LINE__, line, expect_recharge ? "BUG: " : "", expect_recharge, last_fire, t64, static_cast<long>(last_fire + time_bias));
		    return;
	    }
	    printf(__FILE__ ":%u:%u: %5sexpect_recharge=%i last_fire=%8x t64=%16lx: last_fire old    (%16lx), recharging\n", __LINE__, line, expect_recharge ? "" : "BUG: ", expect_recharge, last_fire, t64, static_cast<long>(last_fire + time_bias));
    }

    int main(int, char **)
    {
	    frame(false);
	    t64 = 0x7fff;
	    frame(true);
	    last_fire = t64 - 4;
	    frame(false);
	    t64 = 0x7fffaaab;
	    frame(true);
	    last_fire = t64;
	    ++t64;
	    frame(false);
	    t64 = 0x7ffffffffd;
	    frame(true);
	    last_fire = t64;
	    ++t64;
	    frame(false);
	    t64 += 0x10000;
	    frame(true);
	    t64 = 0x7fffffffffffff00;
	    frame(true);
	    last_fire = t64;
	    frame(false);
	    t64 = 0x8000000000000000;
	    frame(true);
	    t64 += 0x800000000;
	    frame(true);
    }
2016-11-12 18:10:08 +00:00
Kp 72c13d101c Fold omega Next_laser_firing_time handling into do_laser_firing_player
Previously, do_laser_firing_player would update Next_laser_firing_time,
then do_omega_stuff would update it again.  OMEGA_BASE_TIME is smaller
than Weapon_info[OMEGA_ID].fire_wait, so the first store was overridden
by the second.  As a quirk, the override was skipped if the omega cannon
was unable to fire due to object limits or due to insufficient energy,
causing those rare cases to use the longer
Weapon_info[OMEGA_ID].fire_wait delay.

Fold the omega cannon handling of Next_laser_firing_time into
do_laser_firing_player to eliminate that quirk, simplify the code, and
remove the need to recompute fire_frame_overhead from
Last_omega_fire_time.
2016-11-12 18:10:08 +00:00
Kp 44867c637d Flatten creation of invalid valptridx
Constructing valptridx::basic_ptr with a known-invalid magic index does
not require an array.  Simplify the static_assert to reject uses of
factory functions with known-invalid magic index values.  Fix the two
sites that fail with the stricter static_assert.
2016-11-12 18:10:08 +00:00