[update] Added debug-music-offset-beat command-line option.

This commit is contained in:
falsycat 2019-10-16 00:00:00 +00:00
parent c146ab5366
commit d98d0be7b7
5 changed files with 20 additions and 10 deletions

View File

@ -36,11 +36,16 @@ int main(string[] unparsed_args) {
private bool ParseArgs(string[] unparsed_args, out Args args) { private bool ParseArgs(string[] unparsed_args, out Args args) {
auto helpinfo = unparsed_args.getopt( auto helpinfo = unparsed_args.getopt(
"debug-music-index", &args.debug_music_index, "debug-music-offset-beat", &args.debug_music_offset_beat,
"window-size", &args.window_size "debug-music-index", &args.debug_music_index,
"window-size", &args.window_size
); );
auto valid = true; 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) { if (args.window_size <= 100) {
"invalid window size (it should be 100 or more)".writeln; "invalid window size (it should be 100 or more)".writeln;
valid = false; valid = false;

View File

@ -9,4 +9,6 @@ struct Args {
/// ///
int debug_music_index = -1; int debug_music_index = -1;
///
float debug_music_offset_beat = 0;
} }

View File

@ -35,17 +35,18 @@ class LoadingScene : SceneInterface {
} }
/// ///
void Initialize(Music music) { void Initialize(Music music, float offset_beat = 0) {
music_ = music; music_ = music;
offset_beat_ = offset_beat;
first_drawn_ = false; first_drawn_ = false;
} }
override SceneInterface Update(KeyInput input) { override SceneInterface Update(KeyInput input) {
if (first_drawn_) { if (first_drawn_) {
// TODO: parallelize contex creation // TODO: parallelize context creation
auto context = music_.CreatePlayerContext( auto context = music_.CreatePlayerContext(
vec2i(args_.window_size, args_.window_size), programs_.player); 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 play_scene_;
} }
return this; return this;
@ -67,6 +68,7 @@ class LoadingScene : SceneInterface {
LobbyWorld lobby_; LobbyWorld lobby_;
Music music_; Music music_;
float offset_beat_;
bool first_drawn_; bool first_drawn_;
} }

View File

@ -64,8 +64,9 @@ class Music {
} }
/// ///
void PlayForGame() { void PlayForGame(float offset_beat) {
sfMusic_setPlayingOffset(music_, sfMilliseconds(0)); sfMusic_setPlayingOffset(music_,
sfMilliseconds((offset_beat*bpm_ / 60f / 1e-6f).to!int));
sfMusic_play(music_); sfMusic_play(music_);
} }
/// ///

View File

@ -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; music_ = music;
context_ = context; context_ = context;
score_ = BaseScore; score_ = BaseScore;
music_.PlayForGame(); music_.PlayForGame(offset_beat);
} }
override SceneInterface Update(KeyInput input) { override SceneInterface Update(KeyInput input) {
beat_ = music_.beat; beat_ = music_.beat;