[add] Added PlayScene.

This commit is contained in:
falsycat 2019-10-14 00:00:00 +00:00
parent 52a2159300
commit 021bd8eca5
4 changed files with 78 additions and 6 deletions

View File

@ -12,6 +12,7 @@ import sj.AbstractGame,
sj.LoadingScene, sj.LoadingScene,
sj.LobbyWorld, sj.LobbyWorld,
sj.Music, sj.Music,
sj.PlayScene,
sj.ProgramSet, sj.ProgramSet,
sj.SelectScene, sj.SelectScene,
sj.TitleScene; sj.TitleScene;
@ -37,10 +38,12 @@ class Game : AbstractGame {
title_ = new TitleScene(lobby_, programs_); title_ = new TitleScene(lobby_, programs_);
select_ = new SelectScene(lobby_, programs_, fonts_, music_list_); select_ = new SelectScene(lobby_, programs_, fonts_, music_list_);
load_ = new LoadingScene(args, lobby_, programs_, fonts_); load_ = new LoadingScene(args, lobby_, programs_, fonts_);
play_ = new PlayScene();
title_ .SetupSceneDependency(select_); title_ .SetupSceneDependency(select_);
select_.SetupSceneDependency(title_, load_); select_.SetupSceneDependency(title_, load_);
load_ .SetupSceneDependency(); // TODO: pass play scene load_ .SetupSceneDependency(play_);
play_ .SetupSceneDependency(); // TODO: pass result scene
title_.Initialize(); title_.Initialize();
super(title_); super(title_);
@ -50,6 +53,7 @@ class Game : AbstractGame {
title_.destroy(); title_.destroy();
select_.destroy(); select_.destroy();
load_.destroy(); load_.destroy();
play_.destroy();
lobby_.destroy(); lobby_.destroy();
@ -70,4 +74,5 @@ class Game : AbstractGame {
TitleScene title_; TitleScene title_;
SelectScene select_; SelectScene select_;
LoadingScene load_; LoadingScene load_;
PlayScene play_;
} }

View File

@ -8,6 +8,7 @@ import sj.Args,
sj.KeyInput, sj.KeyInput,
sj.LobbyWorld, sj.LobbyWorld,
sj.Music, sj.Music,
sj.PlayScene,
sj.ProgramSet, sj.ProgramSet,
sj.SceneInterface; 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) { override SceneInterface Update(KeyInput input) {
if (first_drawn_) { if (first_drawn_) {
// TODO: parallelize contex creation // TODO: parallelize contex 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);
// TODO: pass the context to play scene play_scene_.Initialize(music_, context);
return play_scene_;
} }
return this; return this;
} }
@ -55,12 +58,14 @@ class LoadingScene : SceneInterface {
private: private:
const Args args_; const Args args_;
LobbyWorld lobby_; PlayScene play_scene_;
ProgramSet programs_; ProgramSet programs_;
FontSet fonts_; FontSet fonts_;
LobbyWorld lobby_;
Music music_; Music music_;
bool first_drawn_; bool first_drawn_;

View File

@ -95,6 +95,11 @@ class Music {
@property ref const(PreviewConfig) preview() const { @property ref const(PreviewConfig) preview() const {
return preview_; return preview_;
} }
///
@property float beat() const {
const msecs = sfMusic_getPlayingOffset(music_).microseconds * 1e-6f;
return msecs / 60f * bpm_;
}
private: private:
static float GetNumericAsFloatFromJson(in JSONValue json) { static float GetNumericAsFloatFromJson(in JSONValue json) {

57
src/sj/PlayScene.d Normal file
View File

@ -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_;
}