Skip to content
This repository was archived by the owner on Jan 21, 2025. It is now read-only.

Commit 947ca99

Browse files
authored
Fixes map restarting bug (#12)
* Fixes note presisting bug when restarting maps * Removes unecessary wall clearing loop Walls are cleared from the track in the loop immediately above this in the code.
1 parent 0380b38 commit 947ca99

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

game/BeepSaber_Game.gd

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ var _current_note = 0;
3737
var _current_obstacle = 0;
3838
var _current_event = 0;
3939

40+
# There's an interesting issue where the AudioStreamPlayer's playback_position
41+
# doesn't immediately return to 0.0 after restarting the song_player. This
42+
# causes issues with restarting a map because the process_physics routine will
43+
# execute for a times and attempt to process the map up to the playback_position
44+
# prior to the AudioStreamPlayer restart. This bug can presents itself as notes
45+
# persisting between map restarts.
46+
# To remidy this issue, this flag is set to true when the map is restarted. The
47+
# process_physics routine won't begin processing the map until after the
48+
# AudioStreamPlayer has reset it's playback_position to zero. This flag is set
49+
# to false once the AudioStreamPlayer reset is detected.
50+
var _audio_synced_after_restart = false
4051

4152
var _high_score = 0;
4253

@@ -54,6 +65,7 @@ var cube_cuts_falloff = true
5465
var max_cutted_cubes = 32
5566

5667
func restart_map():
68+
_audio_synced_after_restart = false
5769
song_player.play(0.0);
5870
song_player.volume_db = 0.0;
5971
_in_wall = false;
@@ -80,9 +92,6 @@ func restart_map():
8092
$Track.remove_child(c);
8193
c.queue_free();
8294

83-
for w in get_tree().get_nodes_in_group("wall"):
84-
w.queue_free()
85-
8695
$MainMenu_OQ_UI2DCanvas.visible = false;
8796
$Settings_canvas.visible = false;
8897
$Online_library.visible = false;
@@ -343,9 +352,14 @@ func _update_saber_end_variabless(dt):
343352
func _physics_process(dt):
344353
if (vr.button_just_released(vr.BUTTON.ENTER)):
345354
show_pause_menu();
346-
# show_menu();
347355

348-
if (song_player.playing):
356+
if song_player.playing and not _audio_synced_after_restart:
357+
# 0.5 seconds is a pretty concervative number to use for the audio
358+
# resync check. Having this duration be this long might only be an
359+
# issue for maps that spawn notes extremely early into the song.
360+
if song_player.get_playback_position() < 0.5:
361+
_audio_synced_after_restart = true;
362+
elif song_player.playing:
349363
_process_map(dt);
350364
_update_controller_movement_aabb(left_controller);
351365
_update_controller_movement_aabb(right_controller);

0 commit comments

Comments
 (0)