Skip to content

Commit

Permalink
Fixes map restarting bug (#12)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
hankedan000 authored Apr 13, 2021
1 parent 0380b38 commit 947ca99
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions game/BeepSaber_Game.gd
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ var _current_note = 0;
var _current_obstacle = 0;
var _current_event = 0;

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

var _high_score = 0;

Expand All @@ -54,6 +65,7 @@ var cube_cuts_falloff = true
var max_cutted_cubes = 32

func restart_map():
_audio_synced_after_restart = false
song_player.play(0.0);
song_player.volume_db = 0.0;
_in_wall = false;
Expand All @@ -80,9 +92,6 @@ func restart_map():
$Track.remove_child(c);
c.queue_free();

for w in get_tree().get_nodes_in_group("wall"):
w.queue_free()

$MainMenu_OQ_UI2DCanvas.visible = false;
$Settings_canvas.visible = false;
$Online_library.visible = false;
Expand Down Expand Up @@ -343,9 +352,14 @@ func _update_saber_end_variabless(dt):
func _physics_process(dt):
if (vr.button_just_released(vr.BUTTON.ENTER)):
show_pause_menu();
# show_menu();

if (song_player.playing):
if song_player.playing and not _audio_synced_after_restart:
# 0.5 seconds is a pretty concervative number to use for the audio
# resync check. Having this duration be this long might only be an
# issue for maps that spawn notes extremely early into the song.
if song_player.get_playback_position() < 0.5:
_audio_synced_after_restart = true;
elif song_player.playing:
_process_map(dt);
_update_controller_movement_aabb(left_controller);
_update_controller_movement_aabb(right_controller);
Expand Down

0 comments on commit 947ca99

Please sign in to comment.