Commit graph

9119 commits

Author SHA1 Message Date
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
Kp 61567eeed0 Move player::KillGoalCount to player_info 2016-11-12 18:10:07 +00:00
Kp 1060c8fabb Move player::net_kills_total to player_info 2016-11-12 18:10:07 +00:00
Kp 411b623aa7 Move player::net_killed_total to player_info 2016-11-12 18:10:07 +00:00
zico ad638539d6 Setting version number to 0.59.100 for upcoming public BETA. 2016-11-12 16:07:21 +01:00
zico 8258532693 Do not process tracker timeout if we're a client (which doesn't get any ACKs) 2016-11-12 15:56:49 +01:00
zico b508e2a294 Restrict powerup repopulation for Multiplayer as well as sending and processing of inventory packets to NETSTAT_PLAYING consistently. 2016-11-12 15:55:37 +01:00
zico dafd4a69be Fixed and revamped 30f9233b36e9e546a7479fd152331b7b0d689d47: initialize segnum for objects during object syncing only. Should only be required for OBJ_NONE but since net_udp_read_object_packet() does only process changed objects and setting segnum in init_objects() isn't desired, this initialization is applied to all objects (except the host player object) before the sync process. 2016-11-12 15:52:16 +01:00
Chris Taylor 6757d89238 Fix crash in editor when trying to unlink a door that isn't linked 2016-11-12 17:30:36 +08:00
Chris Taylor eeb3303b95 Fix crash in editor when trying to link wall with no Markedsegp 2016-11-12 17:28:26 +08:00
Chris Taylor 95fcee9474 Fix crash when removing a wall in the editor
Only update wall_num if != wall_none.
2016-11-12 17:19:38 +08:00
Chris Taylor 4568bbae11 Don't crash when building segment bridge in editor the wrong way
Check if there is Markedsegp and replacing an Assert with a LevelError.
2016-11-12 16:41:54 +08:00
Chris Taylor ac52a30214 Fix spurious exploding wall and crash when playing a level loaded with the editor
When File->'Play in 320x200' is chosen, use StartNewGame(Current_level_num). For now use create_new_mission and Current_level_num = 1 every time. Also remove the now redundant hacks GM_EDITOR and editor_reset_stuff_on_level.
2016-11-12 15:38:38 +08:00
Chris Taylor 2d5d24cedc Fix freeze when clicking on 'Help' menu in editor
The functions med-mark-start and med-mark-end don't exist - that's fine, still read the rest of the menus, so it can actually properly 'hide' the help menu after it's clicked on.
2016-11-11 18:11:14 +08:00
Chris Taylor bae558b2e1 Fix selection in the game view for the editor
build_segment_list and build_object_lists are now required for _search_mode as well (i.e. required for every frame), as the segment list is no longer a set of global variables.
2016-11-11 16:09:57 +08:00
Chris Taylor ac438f4cc2 Allow the user to carry on as usual if any of the editor files are missing (i.e. before editor was loaded).
If a game was playing, continue playing. If it was in the main menu, return to the main menu. (If all files are put in place the editor can load again.)
2016-11-11 16:09:57 +08:00
Chris Taylor 46abf5f31f Set Game_wind to nullptr at the start of responding to EVENT_WINDOW_CLOSE in game_handler
This prevents newdemo_stop_playback from attempting to close Game_wind, which results in it being freed twice - in particular when switching to the editor (via delete-E) when playing a demo.
2016-11-11 16:09:57 +08:00
Chris Taylor b8b19baa92 Make sure wall dialog and hostage dialog close properly
When responding to EVENT_WINDOW_CLOSE, set MainWindow to nullptr - fixing multiple issues with these dialogs including the inability to re-open them and a crash on exiting the editor.
2016-11-11 16:09:57 +08:00
Chris Taylor 396f1e47f0 Do Wall Dialog now works with no wall selected 2016-11-11 16:09:57 +08:00
Chris Taylor e29a4513b6 Allow empty string to be passed to file_getdirlist
This allows the open/save dialogs to work in the editor when a filename without a path separator is passed (which is the default)
2016-11-11 16:09:57 +08:00
Chris Taylor d41146bcbd Set default object index for object dialog
This prevents the Object Editor from crashing when no object is selected (Cur_object_index == object_none).
2016-11-11 16:09:57 +08:00
Chris Taylor 46297c151e Remove ui_gadget_delete_all
As the UI_DIALOG client is now responsible for freeing all gadgets (via unique_ptr's), this function now causes issues where it attempts to access freed gadgets (resulting in std::runtime_error("unknown gadget kind") exception when closing the AI Properties dialog on my Macbook, for example). Removing the offending function fixes the issue.
2016-11-11 16:09:57 +08:00
Chris Taylor b7bbb37885 Fixes freeze when starting new game or editor
Fixes freeze introduced by 9511f65 where event_process wouldn't go to the next window if it's hidden.
2016-11-11 16:09:57 +08:00
Kp b19e93cc04 Skip tracking idx in obj_get_signature 2016-11-10 04:22:19 +00:00
Kp 930c4c6a99 Remove write-only variable multi_goto_secret
multi_goto_secret is read only to decide whether to write a new value to
it, but never to change other control flow.
2016-11-10 04:22:19 +00:00
Kp ce193812d8 Reset Omega_charge when loading save games
If loading an pre-v22 save game, or loading any save where the player
died on the secret level, clear Omega_charge instead of retaining
whatever value the prior game used.
2016-11-10 04:22:18 +00:00
Kp 188ef99536 Assert that newly allocated objects are type OBJ_NONE 2016-11-10 04:22:18 +00:00
zico 30f9233b36 Reverted 2e6aa0f081 and partially reverted 7064fcccba to still allow segnum and signature init for multiplayer games, keeping consistency during object sync. 2016-11-08 14:16:26 +01:00
zico 5f21bdd71f In net_udp_game_connect, moved test for dl->gameid above test for timer. In udp_tracker_process_game removed redundant location of IP/Port delimiter, added another byte for termination of sIP, added size checks for sIP and sPort before actully copying them and added failsafe check for reading TrackerGameID. 2016-11-08 13:18:51 +01:00
Chris Taylor 709a2c3d2a Fixes freeze when starting new game or editor
Fixes freeze introduced by 9511f65 where event_process wouldn't go to the next window if it's hidden.
2016-11-07 09:32:06 +08:00
Kp 1cb04cb64b Merge branch derhass:patches/GLES_GL_extension_unification into master 2016-11-06 19:24:52 +00:00
Kp a59de2860e Poison more undefined variables 2016-11-06 17:12:03 +00:00
Kp 7ccd537362 Fix build break from 30f9233
Commit 30f9233b36 introduced a test for
Game_Mode, which does not exist, rather than Game_mode, which does
exist.  However, the test for game mode is unnecessary.  Objects of type
OBJ_NONE are always in segment_none and no object of any other type
should be in segment_none.  Use that fact to test obj->type instead of
obj->segnum during multiplayer object clobber, so that multiplayer can
overwrite unallocated objects without accessing any undefined fields and
without making object::segnum a defined field.

Fixes: 30f9233b36 ("Reverted 2e6aa0f081 and partially reverted 7064fcccba to still allow segnum and signature init for multiplayer games, keeping consistency during object sync.")
2016-11-06 17:12:03 +00:00
Kp e231fb7d3a Restructure object linkage checks
Move the main part of obj_link into obj_link_unchecked.  Implement
obj_link as sanity check assertions followed by a call to
obj_link_unchecked.  Remove caller-side writes that were present solely
to bypass the assertions, since the assertions can now be bypassed by
calling obj_link_unchecked directly.
2016-11-06 17:12:03 +00:00
Chris Taylor 143ed30fee Merging in unification/master, resolving conflict in similar/main/kmatrix.cpp 2016-11-06 14:20:18 +08:00
Chris Taylor 219cf31381 Change joy_*_handler definitions back to macros for no joystick build in response to feedback 2016-11-06 14:04:04 +08:00
Chris Taylor 8a8f11dc89 Include cstdint in common/include/fwd-event.h instead of pstypes.h to only include required uint8_t 2016-11-06 13:44:29 +08:00
Kp 46b1ea8fd5 Give full Omega_charge when omega cannon is granted 2016-11-05 21:22:44 +00:00
Kp e33f298b5f Fix build with max_hats_per_joystick=0
Reported-by: kreatordxx <https://github.com/dxx-rebirth/dxx-rebirth/issues/258>
2016-11-05 21:22:43 +00:00
Kp 5f6d60bb7c Fix menu.cpp build when max_joysticks=0
menu.cpp always needs SDL.h, but included it only as a side effect of
joy.h including SDL.h.  joy.h only includes SDL.h when max_joysticks!=0.

Reported-by: kreatordxx <https://github.com/dxx-rebirth/dxx-rebirth/issues/258>
2016-11-05 21:22:43 +00:00
Kp 560cc2aa65 Fix -Wempty-body warnings when max_joysticks=0 2016-11-05 21:22:43 +00:00
derhass 1fe4f1ed67 clean up ogl_extensions.cpp as suggested by vLKp 2016-11-05 19:16:30 +01:00
derhass 551570d29b Unify OpenGL extension handling between OpenGL and OpenGL ES code paths.
Split ogl_get_verinfo() into ogl_tune_for_current() and
ogl_extensions_init(), and consolidate all the OpenGL extension handling
into ogl_extensions.cpp. Unify the code paths for texture anisotropy and
GPU synchronization for OpenGL and OpenGL ES.

Currently, our renderer only uses GLES 1.0, so no real world implementation
will support sync objects for such an old context, but the logic is valid,
and this way, the GLES specific code paths are reduced.

This patch also fixes an issue where the old ogl_get_verinfo() did modify
the texture filtering mode if no anisotropic filter was available. This
was some leftover from the time when the anisotropic filter was a just
a specific CGameConfig.TexFilt mode, and not a separate, orthogonal setting
CGameCfg.TexAnisotropy that it is now.
2016-11-03 21:59:11 +01:00
Kp a0cd8360bc Request v4-mapped v6 addresses instead of native v4 addresses 2016-11-02 03:58:25 +00:00
zico 730879d733 Updated handling of data sent by tracker. Added support for handling ACKs from tracker and Hole punching between game clients via tracker. Changed udp_dns_filladdr to not perform DNS lookup if requested which is used for broadcasts and IPs sent by tracker. Added text display on NETGAMES menu to indicating if a connection is in progress. Fixed issue allowing to select an invalid game on NETGAMES list. Upon cancelling a forming netgame, made sure tracke runregister packet is sent. Added function to verify tracker address to make sure incoming packets originate from expected trtacker address (and port). Slightly improved handling game data from tracker to be less prone to crash if receiving unexpected data. 2016-11-02 04:20:41 +01:00
zico dc46fb9528 Fixed compile-time error of software rendering build. 2016-10-31 11:44:22 +01:00