From d98d0be7b7f1b4a43deb4716abf2958893cd0833 Mon Sep 17 00:00:00 2001 From: falsycat Date: Wed, 16 Oct 2019 00:00:00 +0000 Subject: [PATCH] [update] Added debug-music-offset-beat command-line option. --- src/main.d | 9 +++++++-- src/sj/Args.d | 2 ++ src/sj/LoadingScene.d | 10 ++++++---- src/sj/Music.d | 5 +++-- src/sj/PlayScene.d | 4 ++-- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/main.d b/src/main.d index 842b2dc..b33624b 100644 --- a/src/main.d +++ b/src/main.d @@ -36,11 +36,16 @@ int main(string[] unparsed_args) { private bool ParseArgs(string[] unparsed_args, out Args args) { auto helpinfo = unparsed_args.getopt( - "debug-music-index", &args.debug_music_index, - "window-size", &args.window_size + "debug-music-offset-beat", &args.debug_music_offset_beat, + "debug-music-index", &args.debug_music_index, + "window-size", &args.window_size ); auto valid = true; + if (args.debug_music_offset_beat < 0) { + "invalid music offset (it should be 0 or more)".writeln; + valid = false; + } if (args.window_size <= 100) { "invalid window size (it should be 100 or more)".writeln; valid = false; diff --git a/src/sj/Args.d b/src/sj/Args.d index e3de3fe..26a1a3a 100644 --- a/src/sj/Args.d +++ b/src/sj/Args.d @@ -9,4 +9,6 @@ struct Args { /// int debug_music_index = -1; + /// + float debug_music_offset_beat = 0; } diff --git a/src/sj/LoadingScene.d b/src/sj/LoadingScene.d index a17ade6..5f4abc0 100644 --- a/src/sj/LoadingScene.d +++ b/src/sj/LoadingScene.d @@ -35,17 +35,18 @@ class LoadingScene : SceneInterface { } /// - void Initialize(Music music) { - music_ = music; + void Initialize(Music music, float offset_beat = 0) { + music_ = music; + offset_beat_ = offset_beat; first_drawn_ = false; } override SceneInterface Update(KeyInput input) { if (first_drawn_) { - // TODO: parallelize contex creation + // TODO: parallelize context creation auto context = music_.CreatePlayerContext( vec2i(args_.window_size, args_.window_size), programs_.player); - play_scene_.Initialize(music_, context); + play_scene_.Initialize(music_, context, offset_beat_); return play_scene_; } return this; @@ -67,6 +68,7 @@ class LoadingScene : SceneInterface { LobbyWorld lobby_; Music music_; + float offset_beat_; bool first_drawn_; } diff --git a/src/sj/Music.d b/src/sj/Music.d index 2f01323..f763c12 100644 --- a/src/sj/Music.d +++ b/src/sj/Music.d @@ -64,8 +64,9 @@ class Music { } /// - void PlayForGame() { - sfMusic_setPlayingOffset(music_, sfMilliseconds(0)); + void PlayForGame(float offset_beat) { + sfMusic_setPlayingOffset(music_, + sfMilliseconds((offset_beat*bpm_ / 60f / 1e-6f).to!int)); sfMusic_play(music_); } /// diff --git a/src/sj/PlayScene.d b/src/sj/PlayScene.d index febf414..150d18f 100644 --- a/src/sj/PlayScene.d +++ b/src/sj/PlayScene.d @@ -35,13 +35,13 @@ class PlayScene : SceneInterface { } /// - void Initialize(Music music, sjplayer.Context context) { + void Initialize(Music music, sjplayer.Context context, float offset_beat = 0) { music_ = music; context_ = context; score_ = BaseScore; - music_.PlayForGame(); + music_.PlayForGame(offset_beat); } override SceneInterface Update(KeyInput input) { beat_ = music_.beat;