[update] Implemented an animation of LoadingScene.
This commit is contained in:
parent
a5be4fd519
commit
b614ed2d72
@ -1,6 +1,8 @@
|
|||||||
/// License: MIT
|
/// License: MIT
|
||||||
module sj.LoadingScene;
|
module sj.LoadingScene;
|
||||||
|
|
||||||
|
import std.math;
|
||||||
|
|
||||||
import gl4d;
|
import gl4d;
|
||||||
|
|
||||||
static import sjplayer;
|
static import sjplayer;
|
||||||
@ -11,11 +13,26 @@ import sj.FontSet,
|
|||||||
sj.Music,
|
sj.Music,
|
||||||
sj.PlayScene,
|
sj.PlayScene,
|
||||||
sj.ProgramSet,
|
sj.ProgramSet,
|
||||||
sj.SceneInterface;
|
sj.SceneInterface,
|
||||||
|
sj.Text,
|
||||||
|
sj.TextProgram,
|
||||||
|
sj.util.Animation,
|
||||||
|
sj.util.Easing;
|
||||||
|
|
||||||
///
|
///
|
||||||
class LoadingScene : SceneInterface {
|
class LoadingScene : SceneInterface {
|
||||||
public:
|
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(
|
this(
|
||||||
LobbyWorld lobby,
|
LobbyWorld lobby,
|
||||||
@ -25,13 +42,23 @@ class LoadingScene : SceneInterface {
|
|||||||
lobby_ = lobby;
|
lobby_ = lobby;
|
||||||
posteffect_ = posteffect;
|
posteffect_ = posteffect;
|
||||||
programs_ = programs;
|
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() {
|
~this() {
|
||||||
|
loading_text_.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
void SetupSceneDependency(PlayScene play) { // TODO: add play scene
|
void SetupSceneDependency(PlayScene play) {
|
||||||
play_scene_ = play;
|
play_scene_ = play;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,10 +67,29 @@ class LoadingScene : SceneInterface {
|
|||||||
music_ = music;
|
music_ = music;
|
||||||
offset_beat_ = offset_beat;
|
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) {
|
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
|
// TODO: parallelize context creation
|
||||||
auto context = music_.CreatePlayerContext(posteffect_, programs_.player);
|
auto context = music_.CreatePlayerContext(posteffect_, programs_.player);
|
||||||
play_scene_.Initialize(music_, context, offset_beat_);
|
play_scene_.Initialize(music_, context, offset_beat_);
|
||||||
@ -53,7 +99,7 @@ class LoadingScene : SceneInterface {
|
|||||||
}
|
}
|
||||||
override void Draw() {
|
override void Draw() {
|
||||||
lobby_.Draw();
|
lobby_.Draw();
|
||||||
first_drawn_ = true;
|
loading_text_.Draw(lobby_.Projection, lobby_.view.Create());
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -61,14 +107,17 @@ class LoadingScene : SceneInterface {
|
|||||||
|
|
||||||
ProgramSet programs_;
|
ProgramSet programs_;
|
||||||
|
|
||||||
FontSet fonts_;
|
|
||||||
|
|
||||||
LobbyWorld lobby_;
|
LobbyWorld lobby_;
|
||||||
|
|
||||||
|
Text loading_text_;
|
||||||
|
|
||||||
PlayScene play_scene_;
|
PlayScene play_scene_;
|
||||||
|
|
||||||
Music music_;
|
Music music_;
|
||||||
float offset_beat_;
|
float offset_beat_;
|
||||||
|
|
||||||
bool first_drawn_;
|
Animation anime_;
|
||||||
|
|
||||||
|
Easing!vec4 bg_inner_ease_;
|
||||||
|
Easing!vec4 bg_outer_ease_;
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ private abstract class AbstractSceneState {
|
|||||||
enum CubeRotationSpeed = vec3(0, PI/500, 0);
|
enum CubeRotationSpeed = vec3(0, PI/500, 0);
|
||||||
enum CubeInterval = 0.005;
|
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 PlayingCubeInterval = 0.04;
|
||||||
|
|
||||||
enum LoadingCubeRotationSpeed = vec3(PI/100, PI/10, PI/100);
|
enum LoadingCubeRotationSpeed = vec3(PI/100, PI/10, PI/100);
|
||||||
@ -364,10 +364,6 @@ private class MusicPlayState : AbstractSceneState {
|
|||||||
Easing!vec3(CubeRotationSpeed, PlayingCubeRotationSpeed);
|
Easing!vec3(CubeRotationSpeed, PlayingCubeRotationSpeed);
|
||||||
cube_interval_ease_ =
|
cube_interval_ease_ =
|
||||||
Easing!float(CubeInterval, PlayingCubeInterval);
|
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) {
|
override UpdateResult Update(KeyInput input) {
|
||||||
const ratio = anime_.Update();
|
const ratio = anime_.Update();
|
||||||
@ -377,8 +373,6 @@ private class MusicPlayState : AbstractSceneState {
|
|||||||
with (owner.lobby_) {
|
with (owner.lobby_) {
|
||||||
cube_matrix.rotation += cube_rota_speed;
|
cube_matrix.rotation += cube_rota_speed;
|
||||||
cube_interval = cube_interval_;
|
cube_interval = cube_interval_;
|
||||||
|
|
||||||
background.inner_color = bg_inner_ease_.Calculate(ratio);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!input.down) {
|
if (!input.down) {
|
||||||
@ -409,7 +403,6 @@ private class MusicPlayState : AbstractSceneState {
|
|||||||
|
|
||||||
Easing!vec3 cube_rota_speed_ease_;
|
Easing!vec3 cube_rota_speed_ease_;
|
||||||
Easing!float cube_interval_ease_;
|
Easing!float cube_interval_ease_;
|
||||||
Easing!vec4 bg_inner_ease_;
|
|
||||||
}
|
}
|
||||||
///
|
///
|
||||||
private class MusicCancelPlayState : AbstractSceneState {
|
private class MusicCancelPlayState : AbstractSceneState {
|
||||||
@ -428,9 +421,6 @@ private class MusicCancelPlayState : AbstractSceneState {
|
|||||||
Easing!vec3(cube_rota_speed, CubeRotationSpeed);
|
Easing!vec3(cube_rota_speed, CubeRotationSpeed);
|
||||||
cube_interval_ease_ =
|
cube_interval_ease_ =
|
||||||
Easing!float(cube_interval, CubeInterval);
|
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) {
|
override UpdateResult Update(KeyInput input) {
|
||||||
const ratio = anime_.Update();
|
const ratio = anime_.Update();
|
||||||
@ -438,7 +428,6 @@ private class MusicCancelPlayState : AbstractSceneState {
|
|||||||
with (owner.lobby_) {
|
with (owner.lobby_) {
|
||||||
cube_matrix.rotation += cube_rota_speed_ease_.Calculate(ratio);
|
cube_matrix.rotation += cube_rota_speed_ease_.Calculate(ratio);
|
||||||
cube_interval = cube_interval_ease_ .Calculate(ratio);
|
cube_interval = cube_interval_ease_ .Calculate(ratio);
|
||||||
background.inner_color = bg_inner_ease_ .Calculate(ratio);
|
|
||||||
}
|
}
|
||||||
if (anime_.isFinished) {
|
if (anime_.isFinished) {
|
||||||
return CreateResult(music_wait_state_);
|
return CreateResult(music_wait_state_);
|
||||||
@ -458,5 +447,4 @@ private class MusicCancelPlayState : AbstractSceneState {
|
|||||||
|
|
||||||
Easing!vec3 cube_rota_speed_ease_;
|
Easing!vec3 cube_rota_speed_ease_;
|
||||||
Easing!float cube_interval_ease_;
|
Easing!float cube_interval_ease_;
|
||||||
Easing!vec4 bg_inner_ease_;
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user