diff --git a/src/sj/LoadingScene.d b/src/sj/LoadingScene.d index 1130983..591355a 100644 --- a/src/sj/LoadingScene.d +++ b/src/sj/LoadingScene.d @@ -1,6 +1,8 @@ /// License: MIT module sj.LoadingScene; +import std.math; + import gl4d; static import sjplayer; @@ -11,11 +13,26 @@ import sj.FontSet, sj.Music, sj.PlayScene, sj.ProgramSet, - sj.SceneInterface; + sj.SceneInterface, + sj.Text, + sj.TextProgram, + sj.util.Animation, + sj.util.Easing; /// class LoadingScene : SceneInterface { public: + /// + enum AnimeFrames = 300; + /// + enum CubeRotationSpeed = vec3(PI/200, PI/20, PI/200); + /// + enum LoadingTextScale = vec3(-0.1, 0.1, 0.1); + /// + enum LoadingTextTranslation = vec3(0, -0.3, 0); + /// + enum LoadingTextColor = vec4(0.2, 0.2, 0.2, 1); + /// this( LobbyWorld lobby, @@ -25,13 +42,23 @@ class LoadingScene : SceneInterface { lobby_ = lobby; posteffect_ = posteffect; programs_ = programs; - fonts_ = fonts; + + loading_text_ = new Text(programs.Get!TextProgram); + with (loading_text_) { + auto w = LoadGlyphs( + vec2i(128, 32), "Loading...", vec2i(16, 0), fonts.gothic); + matrix.scale = LoadingTextScale; + matrix.translation = + LoadingTextTranslation + vec3(-w/2*matrix.scale.x, 0, 0); + color = LoadingTextColor; + } } ~this() { + loading_text_.destroy(); } /// - void SetupSceneDependency(PlayScene play) { // TODO: add play scene + void SetupSceneDependency(PlayScene play) { play_scene_ = play; } @@ -40,10 +67,29 @@ class LoadingScene : SceneInterface { music_ = music; offset_beat_ = offset_beat; - first_drawn_ = false; + anime_ = Animation(AnimeFrames); + + with (lobby_) { + bg_inner_ease_ = Easing!vec4( + music.preview.bg_inner_color, background.inner_color/2); + bg_outer_ease_ = Easing!vec4( + music.preview.bg_outer_color, background.outer_color/2); + } } override SceneInterface Update(KeyInput input) { - if (first_drawn_) { + const ratio = anime_.Update(); + + with (lobby_) { + cube_matrix.rotation += CubeRotationSpeed; + + background.inner_color = bg_inner_ease_.Calculate(ratio); + background.outer_color = bg_outer_ease_.Calculate(ratio); + } + + posteffect_.clip_lefttop.y = 1-pow(1-ratio, 4); + posteffect_.clip_rightbottom.y = 1-pow(1-ratio, 4); + + if (anime_.isFinished) { // TODO: parallelize context creation auto context = music_.CreatePlayerContext(posteffect_, programs_.player); play_scene_.Initialize(music_, context, offset_beat_); @@ -53,7 +99,7 @@ class LoadingScene : SceneInterface { } override void Draw() { lobby_.Draw(); - first_drawn_ = true; + loading_text_.Draw(lobby_.Projection, lobby_.view.Create()); } private: @@ -61,14 +107,17 @@ class LoadingScene : SceneInterface { ProgramSet programs_; - FontSet fonts_; - LobbyWorld lobby_; + Text loading_text_; + PlayScene play_scene_; Music music_; float offset_beat_; - bool first_drawn_; + Animation anime_; + + Easing!vec4 bg_inner_ease_; + Easing!vec4 bg_outer_ease_; } diff --git a/src/sj/SelectScene.d b/src/sj/SelectScene.d index 3d8b4ad..288b204 100644 --- a/src/sj/SelectScene.d +++ b/src/sj/SelectScene.d @@ -133,7 +133,7 @@ private abstract class AbstractSceneState { enum CubeRotationSpeed = vec3(0, PI/500, 0); enum CubeInterval = 0.005; - enum PlayingCubeRotationSpeed = vec3(PI/100, PI/10, PI/100); + enum PlayingCubeRotationSpeed = vec3(PI/200, PI/20, PI/200); enum PlayingCubeInterval = 0.04; enum LoadingCubeRotationSpeed = vec3(PI/100, PI/10, PI/100); @@ -364,10 +364,6 @@ private class MusicPlayState : AbstractSceneState { Easing!vec3(CubeRotationSpeed, PlayingCubeRotationSpeed); cube_interval_ease_ = Easing!float(CubeInterval, PlayingCubeInterval); - - bg_inner_ease_ = - Easing!vec4(owner.lobby_.background.inner_color, - owner.lobby_.background.inner_color*2); } override UpdateResult Update(KeyInput input) { const ratio = anime_.Update(); @@ -377,8 +373,6 @@ private class MusicPlayState : AbstractSceneState { with (owner.lobby_) { cube_matrix.rotation += cube_rota_speed; cube_interval = cube_interval_; - - background.inner_color = bg_inner_ease_.Calculate(ratio); } if (!input.down) { @@ -409,7 +403,6 @@ private class MusicPlayState : AbstractSceneState { Easing!vec3 cube_rota_speed_ease_; Easing!float cube_interval_ease_; - Easing!vec4 bg_inner_ease_; } /// private class MusicCancelPlayState : AbstractSceneState { @@ -428,17 +421,13 @@ private class MusicCancelPlayState : AbstractSceneState { Easing!vec3(cube_rota_speed, CubeRotationSpeed); cube_interval_ease_ = Easing!float(cube_interval, CubeInterval); - - bg_inner_ease_ = Easing!vec4( - owner.lobby_.background.inner_color, music.preview.bg_inner_color); } override UpdateResult Update(KeyInput input) { const ratio = anime_.Update(); with (owner.lobby_) { - cube_matrix.rotation += cube_rota_speed_ease_.Calculate(ratio); - cube_interval = cube_interval_ease_ .Calculate(ratio); - background.inner_color = bg_inner_ease_ .Calculate(ratio); + cube_matrix.rotation += cube_rota_speed_ease_.Calculate(ratio); + cube_interval = cube_interval_ease_ .Calculate(ratio); } if (anime_.isFinished) { return CreateResult(music_wait_state_); @@ -458,5 +447,4 @@ private class MusicCancelPlayState : AbstractSceneState { Easing!vec3 cube_rota_speed_ease_; Easing!float cube_interval_ease_; - Easing!vec4 bg_inner_ease_; }