From 021bd8eca5bae49527587e100f18f72b770e5167 Mon Sep 17 00:00:00 2001 From: falsycat Date: Mon, 14 Oct 2019 00:00:00 +0000 Subject: [PATCH] [add] Added PlayScene. --- src/sj/Game.d | 7 +++++- src/sj/LoadingScene.d | 15 ++++++++---- src/sj/Music.d | 5 ++++ src/sj/PlayScene.d | 57 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 src/sj/PlayScene.d diff --git a/src/sj/Game.d b/src/sj/Game.d index aa04b23..ddd96c4 100644 --- a/src/sj/Game.d +++ b/src/sj/Game.d @@ -12,6 +12,7 @@ import sj.AbstractGame, sj.LoadingScene, sj.LobbyWorld, sj.Music, + sj.PlayScene, sj.ProgramSet, sj.SelectScene, sj.TitleScene; @@ -37,10 +38,12 @@ class Game : AbstractGame { title_ = new TitleScene(lobby_, programs_); select_ = new SelectScene(lobby_, programs_, fonts_, music_list_); load_ = new LoadingScene(args, lobby_, programs_, fonts_); + play_ = new PlayScene(); title_ .SetupSceneDependency(select_); select_.SetupSceneDependency(title_, load_); - load_ .SetupSceneDependency(); // TODO: pass play scene + load_ .SetupSceneDependency(play_); + play_ .SetupSceneDependency(); // TODO: pass result scene title_.Initialize(); super(title_); @@ -50,6 +53,7 @@ class Game : AbstractGame { title_.destroy(); select_.destroy(); load_.destroy(); + play_.destroy(); lobby_.destroy(); @@ -70,4 +74,5 @@ class Game : AbstractGame { TitleScene title_; SelectScene select_; LoadingScene load_; + PlayScene play_; } diff --git a/src/sj/LoadingScene.d b/src/sj/LoadingScene.d index 8b4e9f7..a17ade6 100644 --- a/src/sj/LoadingScene.d +++ b/src/sj/LoadingScene.d @@ -8,6 +8,7 @@ import sj.Args, sj.KeyInput, sj.LobbyWorld, sj.Music, + sj.PlayScene, sj.ProgramSet, sj.SceneInterface; @@ -29,7 +30,8 @@ class LoadingScene : SceneInterface { } /// - void SetupSceneDependency() { // TODO: add play scene + void SetupSceneDependency(PlayScene play) { // TODO: add play scene + play_scene_ = play; } /// @@ -41,9 +43,10 @@ class LoadingScene : SceneInterface { 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 + auto context = music_.CreatePlayerContext( + vec2i(args_.window_size, args_.window_size), programs_.player); + play_scene_.Initialize(music_, context); + return play_scene_; } return this; } @@ -55,12 +58,14 @@ class LoadingScene : SceneInterface { private: const Args args_; - LobbyWorld lobby_; + PlayScene play_scene_; ProgramSet programs_; FontSet fonts_; + LobbyWorld lobby_; + Music music_; bool first_drawn_; diff --git a/src/sj/Music.d b/src/sj/Music.d index 85469b0..2f01323 100644 --- a/src/sj/Music.d +++ b/src/sj/Music.d @@ -95,6 +95,11 @@ class Music { @property ref const(PreviewConfig) preview() const { return preview_; } + /// + @property float beat() const { + const msecs = sfMusic_getPlayingOffset(music_).microseconds * 1e-6f; + return msecs / 60f * bpm_; + } private: static float GetNumericAsFloatFromJson(in JSONValue json) { diff --git a/src/sj/PlayScene.d b/src/sj/PlayScene.d new file mode 100644 index 0000000..ae5239a --- /dev/null +++ b/src/sj/PlayScene.d @@ -0,0 +1,57 @@ +/// License: MIT +module sj.PlayScene; + +import gl4d; + +static import sjplayer; + +import sj.KeyInput, + sj.Music, + sj.SceneInterface; + +/// +class PlayScene : SceneInterface { + public: + /// + this() { + } + ~this() { + context_.destroy(); + } + + /// + void SetupSceneDependency() { // TODO: add result scene + } + + /// + void Initialize(Music music, sjplayer.Context context) { + music_ = music; + context_ = context; + + music_.PlayForGame(); + } + override SceneInterface Update(KeyInput input) { + context_.OperateScheduledControllers(music_.beat); + + // TODO: actor accelaration + + context_.actor.Update(); + context_.posteffect.Update(); + + // TODO: damage calculation + return this; + } + override void Draw() { + context_.StartDrawing(); + + context_.DrawBackground(); + context_.DrawElements(); + context_.DrawActor(); + + context_.EndDrawing(); + } + + private: + Music music_; + sjplayer.Context context_; +}