[update] Implemented creating a context of music.

This commit is contained in:
falsycat 2019-10-14 00:00:00 +00:00
parent a6ad04b8d2
commit 52a2159300
5 changed files with 44 additions and 11 deletions

View File

@ -19,7 +19,7 @@ int main(string[] unparsed_args) {
if (!ParseArgs(unparsed_args, args)) return 1; if (!ParseArgs(unparsed_args, args)) return 1;
auto win = CreateWindow(args); auto win = CreateWindow(args);
auto game = new Game; auto game = new Game(args);
scope(exit) game.destroy(); scope(exit) game.destroy();
while (true) { while (true) {

View File

@ -7,6 +7,7 @@ import std.algorithm,
std.path; std.path;
import sj.AbstractGame, import sj.AbstractGame,
sj.Args,
sj.FontSet, sj.FontSet,
sj.LoadingScene, sj.LoadingScene,
sj.LobbyWorld, sj.LobbyWorld,
@ -19,7 +20,7 @@ import sj.AbstractGame,
class Game : AbstractGame { class Game : AbstractGame {
public: public:
/// ///
this() { this(in ref Args args) {
const path = thisExePath.dirName; const path = thisExePath.dirName;
const music_dir = buildPath(path, "music"); const music_dir = buildPath(path, "music");
@ -35,7 +36,7 @@ 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(lobby_, programs_, fonts_); load_ = new LoadingScene(args, lobby_, programs_, fonts_);
title_ .SetupSceneDependency(select_); title_ .SetupSceneDependency(select_);
select_.SetupSceneDependency(title_, load_); select_.SetupSceneDependency(title_, load_);

View File

@ -1,7 +1,10 @@
/// License: MIT /// License: MIT
module sj.LoadingScene; module sj.LoadingScene;
import sj.FontSet, import gl4d;
import sj.Args,
sj.FontSet,
sj.KeyInput, sj.KeyInput,
sj.LobbyWorld, sj.LobbyWorld,
sj.Music, sj.Music,
@ -12,7 +15,12 @@ import sj.FontSet,
class LoadingScene : SceneInterface { class LoadingScene : SceneInterface {
public: public:
/// ///
this(LobbyWorld lobby, ProgramSet programs, FontSet fonts) { this(
in ref Args args,
LobbyWorld lobby,
ProgramSet programs,
FontSet fonts) {
args_ = args;
lobby_ = lobby; lobby_ = lobby;
programs_ = programs; programs_ = programs;
fonts_ = fonts; fonts_ = fonts;
@ -26,18 +34,34 @@ class LoadingScene : SceneInterface {
/// ///
void Initialize(Music music) { void Initialize(Music music) {
music_ = music;
first_drawn_ = false;
} }
override SceneInterface Update(KeyInput input) { 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; return this;
} }
override void Draw() { override void Draw() {
lobby_.Draw(); lobby_.Draw();
first_drawn_ = true;
} }
private: private:
const Args args_;
LobbyWorld lobby_; LobbyWorld lobby_;
ProgramSet programs_; ProgramSet programs_;
FontSet fonts_; FontSet fonts_;
Music music_;
bool first_drawn_;
} }

View File

@ -4,6 +4,7 @@ module sj.Music;
import std.array, import std.array,
std.conv, std.conv,
std.exception, std.exception,
std.file,
std.json, std.json,
std.path, std.path,
std.string; std.string;
@ -80,8 +81,10 @@ class Music {
} }
/// ///
sjplayer.Context CreatePlayerContext() const { sjplayer.Context CreatePlayerContext(
assert(false); // TODO: vec2i winsz, sjplayer.ProgramSet programs) const {
return sjplayer.CreateContextFromText(
script_path_.readText, winsz, programs);
} }
/// ///

View File

@ -21,13 +21,13 @@ class ProgramSet {
/// ///
this() { this() {
for_player_ = new sjplayer.ProgramSet; player_ = new sjplayer.ProgramSet;
foreach (ref p; programs_) { foreach (ref p; programs_) {
p = new typeof(p); p = new typeof(p);
} }
} }
~this() { ~this() {
for_player_.destroy(); player_.destroy();
foreach (p; programs_) { foreach (p; programs_) {
p.destroy(); p.destroy();
} }
@ -39,12 +39,17 @@ class ProgramSet {
static if (index >= 0) { static if (index >= 0) {
return programs_[index]; return programs_[index];
} else { } else {
return for_player_.Get!T; return player_.Get!T;
} }
} }
///
@property sjplayer.ProgramSet player() {
return player_;
}
private: private:
sjplayer.ProgramSet for_player_; sjplayer.ProgramSet player_;
Programs programs_; Programs programs_;
} }