From 52a215930029dd6839b1af08fc9f622b00d0ced5 Mon Sep 17 00:00:00 2001 From: falsycat Date: Mon, 14 Oct 2019 00:00:00 +0000 Subject: [PATCH] [update] Implemented creating a context of music. --- src/main.d | 2 +- src/sj/Game.d | 5 +++-- src/sj/LoadingScene.d | 28 ++++++++++++++++++++++++++-- src/sj/Music.d | 7 +++++-- src/sj/ProgramSet.d | 13 +++++++++---- 5 files changed, 44 insertions(+), 11 deletions(-) diff --git a/src/main.d b/src/main.d index 1642094..25541f9 100644 --- a/src/main.d +++ b/src/main.d @@ -19,7 +19,7 @@ int main(string[] unparsed_args) { if (!ParseArgs(unparsed_args, args)) return 1; auto win = CreateWindow(args); - auto game = new Game; + auto game = new Game(args); scope(exit) game.destroy(); while (true) { diff --git a/src/sj/Game.d b/src/sj/Game.d index ef2a498..aa04b23 100644 --- a/src/sj/Game.d +++ b/src/sj/Game.d @@ -7,6 +7,7 @@ import std.algorithm, std.path; import sj.AbstractGame, + sj.Args, sj.FontSet, sj.LoadingScene, sj.LobbyWorld, @@ -19,7 +20,7 @@ import sj.AbstractGame, class Game : AbstractGame { public: /// - this() { + this(in ref Args args) { const path = thisExePath.dirName; const music_dir = buildPath(path, "music"); @@ -35,7 +36,7 @@ class Game : AbstractGame { title_ = new TitleScene(lobby_, programs_); select_ = new SelectScene(lobby_, programs_, fonts_, music_list_); - load_ = new LoadingScene(lobby_, programs_, fonts_); + load_ = new LoadingScene(args, lobby_, programs_, fonts_); title_ .SetupSceneDependency(select_); select_.SetupSceneDependency(title_, load_); diff --git a/src/sj/LoadingScene.d b/src/sj/LoadingScene.d index e105049..8b4e9f7 100644 --- a/src/sj/LoadingScene.d +++ b/src/sj/LoadingScene.d @@ -1,7 +1,10 @@ /// License: MIT module sj.LoadingScene; -import sj.FontSet, +import gl4d; + +import sj.Args, + sj.FontSet, sj.KeyInput, sj.LobbyWorld, sj.Music, @@ -12,7 +15,12 @@ import sj.FontSet, class LoadingScene : SceneInterface { public: /// - this(LobbyWorld lobby, ProgramSet programs, FontSet fonts) { + this( + in ref Args args, + LobbyWorld lobby, + ProgramSet programs, + FontSet fonts) { + args_ = args; lobby_ = lobby; programs_ = programs; fonts_ = fonts; @@ -26,18 +34,34 @@ class LoadingScene : SceneInterface { /// void Initialize(Music music) { + music_ = music; + + first_drawn_ = false; } override SceneInterface Update(KeyInput input) { + if (first_drawn_) { + // TODO: parallelize contex creation + // auto context = music_.CreatePlayerContext( + // vec2i(args_.window_size, args_.window_size), programs_.player); + // TODO: pass the context to play scene + } return this; } override void Draw() { lobby_.Draw(); + first_drawn_ = true; } private: + const Args args_; + LobbyWorld lobby_; ProgramSet programs_; FontSet fonts_; + + Music music_; + + bool first_drawn_; } diff --git a/src/sj/Music.d b/src/sj/Music.d index 697ed2e..85469b0 100644 --- a/src/sj/Music.d +++ b/src/sj/Music.d @@ -4,6 +4,7 @@ module sj.Music; import std.array, std.conv, std.exception, + std.file, std.json, std.path, std.string; @@ -80,8 +81,10 @@ class Music { } /// - sjplayer.Context CreatePlayerContext() const { - assert(false); // TODO: + sjplayer.Context CreatePlayerContext( + vec2i winsz, sjplayer.ProgramSet programs) const { + return sjplayer.CreateContextFromText( + script_path_.readText, winsz, programs); } /// diff --git a/src/sj/ProgramSet.d b/src/sj/ProgramSet.d index f1da5ff..e6d3d96 100644 --- a/src/sj/ProgramSet.d +++ b/src/sj/ProgramSet.d @@ -21,13 +21,13 @@ class ProgramSet { /// this() { - for_player_ = new sjplayer.ProgramSet; + player_ = new sjplayer.ProgramSet; foreach (ref p; programs_) { p = new typeof(p); } } ~this() { - for_player_.destroy(); + player_.destroy(); foreach (p; programs_) { p.destroy(); } @@ -39,12 +39,17 @@ class ProgramSet { static if (index >= 0) { return programs_[index]; } else { - return for_player_.Get!T; + return player_.Get!T; } } + /// + @property sjplayer.ProgramSet player() { + return player_; + } + private: - sjplayer.ProgramSet for_player_; + sjplayer.ProgramSet player_; Programs programs_; }