]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
streamline demoseeking a lot with menu_cmd isdemo
authordrjaska <drjaska83@gmail.com>
Fri, 8 Dec 2023 07:41:38 +0000 (09:41 +0200)
committerdrjaska <drjaska83@gmail.com>
Fri, 8 Dec 2023 07:41:38 +0000 (09:41 +0200)
demoseeking.cfg

index 3379343068be4e16c745587007a89b06e07cd64e..1b3de41ee55ee488cc696a4ebc26515f0889b13f 100644 (file)
@@ -3,13 +3,11 @@
 //
 // Setup:
 //
-// Add "exec input-demoseeking.cfg" and the following cl_hook_gamestart_all
-// hook to autoexec.cfg. If you already have a cl_hook_gamestart_all hook, add
-// the quoted command to your hook, separated with a semicolon:
+// Add either of the following to your autoexec.cfg:
+//
+//     exec input-demoseeking.cfg
 //
 //     exec demoseeking.cfg
-//     alias cl_hook_gamestart_all "demoseeking_game_started"
-//     alias cl_hook_demostart "demoseeking_demo_started"
 //
 // Usage:
 //     1. start a demo (ply/playdemo command or menu), and
 //
 // Variables:
 //
-// _demo_is_playing
-//     Indicates whether a demo is currently playing. Should be set to 1 by
-//     cl_hook_demostart when a demo starts playing.
-//     Note: the setup above is needed to reset this reliably.
 // _current_demo_name
 //     The name of the latest played demo. Same as the argument passed to the
 //     last playdemo command. If playdemo fails to start the demo (e.g. when
@@ -71,16 +65,10 @@ set _demoseeking_fast_speed 80
 set _demoseeking_speed_factor 10
 
 // state initialization
-alias _demoseeking_init_vars "set _demoseeking_vars_loaded 1; set _demo_is_playing 0; set _current_demo_name \"\"; set _demoseeking_is_seeking 0; set _seekdemo_state idle; set _seekdemo_target 0; alias seekdemo_hook_seek_end"
+alias _demoseeking_init_vars "set _demoseeking_vars_loaded 1; set _seekdemo_demo_is_playing 0; set _current_demo_name \"\"; set _demoseeking_is_seeking 0; set _seekdemo_state idle; set _seekdemo_target 0; alias seekdemo_hook_seek_end"
 alias _demoseeking_init_vars1 ""
 _demoseeking_init_vars${_demoseeking_vars_loaded ?}
 
-// Hook into game start to reset seekdemo state. This prevents reloading the
-// last demo when seekdemo is accidentally called during an actual game.
-// Also hook into demo start to set _demo_is_playing properly.
-alias demoseeking_game_started "set _demo_is_playing 0; set _current_demo_name \"\""
-alias demoseeking_demo_started "set _demo_is_playing 1"
-
 // Hook into "playdemo" command. This alias runs immediately after the actual
 // "playdemo" command runs. Needed for seekdemo to restart the demo when
 // seeking backwards.
@@ -122,13 +110,13 @@ alias _demoseeking_restore_seeking "_seekdemo_check_time"
 // check if seek should start or if target time should be adjusted instead
 alias seekdemo "_seekdemo_checkstate_$_seekdemo_state ${* q}"
 // before starting seek, verify demo is playing first
-alias _seekdemo_checkstate_idle "set _seekdemo_demo_is_playing 0; cl_cmd rpn /_seekdemo_demo_is_playing _demo_is_playing 0 != def; _seekdemo_checkstart ${* q}"
+alias _seekdemo_checkstate_idle "menu_cmd isdemo _seekdemo_demo_is_playing; _seekdemo_checkstart ${* q}"
 // when already seeking, only update the variable holding the target time
 alias _seekdemo_checkstate_starting "_seekdemo_checkstate_seeking ${* q}"
 alias _seekdemo_checkstate_seeking "rpn /_seekdemo_target _seekdemo_target \"$1\" add def"
 
 alias _seekdemo_checkstart "_seekdemo_checkstart_$_seekdemo_demo_is_playing ${* q}"
-alias _seekdemo_checkstart_0 "echo \"no demo currently playing\""
+alias _seekdemo_checkstart_0 "set _current_demo_name \"\";echo \"no demo currently playing\""
 // start new seek
 alias _seekdemo_checkstart_1 "cl_cmd rpn /_seekdemo_target time \"$1\" add def; set _demoseeking_is_seeking 1; set _seekdemo_state starting; _seekdemo_save_options; _seekdemo_start_seek"