[update] Re-implemented the scene transitions.
This commit is contained in:
		| @@ -11,15 +11,13 @@ class AbstractGame { | |||||||
|  public: |  public: | ||||||
|   /// |   /// | ||||||
|   this(SceneInterface first_scene) in (first_scene) { |   this(SceneInterface first_scene) in (first_scene) { | ||||||
|     scene_ = first_scene; |     next_scene_ = first_scene; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   /// |   /// | ||||||
|   void Update(KeyInput input) { |   void Update(KeyInput input) { | ||||||
|     if (auto next = scene_.TakeNextScene()) { |     scene_      = next_scene_; | ||||||
|       scene_ = next; |     next_scene_ = scene_.Update(input); | ||||||
|     } |  | ||||||
|     scene_.Update(input); |  | ||||||
|   } |   } | ||||||
|   /// |   /// | ||||||
|   void Draw() { |   void Draw() { | ||||||
| @@ -29,4 +27,6 @@ class AbstractGame { | |||||||
|  |  | ||||||
|  private: |  private: | ||||||
|   SceneInterface scene_; |   SceneInterface scene_; | ||||||
|  |  | ||||||
|  |   SceneInterface next_scene_; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,31 +0,0 @@ | |||||||
| /// License: MIT |  | ||||||
| module sj.AbstractScene; |  | ||||||
|  |  | ||||||
| import sj.KeyInput, |  | ||||||
|        sj.SceneInterface; |  | ||||||
|  |  | ||||||
| /// |  | ||||||
| class AbstractScene : SceneInterface { |  | ||||||
|  public: |  | ||||||
|   /// |  | ||||||
|   this() { |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   abstract override { |  | ||||||
|     void Update(KeyInput input); |  | ||||||
|     void Draw(); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   override SceneInterface TakeNextScene() { |  | ||||||
|     scope(exit) next_ = null; |  | ||||||
|     return next_; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|  protected: |  | ||||||
|   void GoNextScene(SceneInterface next) in (next) { |  | ||||||
|     next_ = next; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|  private: |  | ||||||
|   SceneInterface next_; |  | ||||||
| } |  | ||||||
| @@ -24,6 +24,7 @@ class Game : AbstractGame { | |||||||
|     title_.SetupSceneDependency(select_); |     title_.SetupSceneDependency(select_); | ||||||
|     select_.SetupSceneDependency(title_); |     select_.SetupSceneDependency(title_); | ||||||
|  |  | ||||||
|  |     title_.Initialize(); | ||||||
|     super(title_); |     super(title_); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -7,10 +7,7 @@ import sj.KeyInput; | |||||||
| interface SceneInterface { | interface SceneInterface { | ||||||
|  public: |  public: | ||||||
|   /// |   /// | ||||||
|   void Update(KeyInput input); |   SceneInterface Update(KeyInput input); | ||||||
|   /// |   /// | ||||||
|   void Draw(); |   void Draw(); | ||||||
|  |  | ||||||
|   /// |  | ||||||
|   SceneInterface TakeNextScene(); |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -3,15 +3,15 @@ module sj.SelectScene; | |||||||
|  |  | ||||||
| import derelict.sfml2.audio; | import derelict.sfml2.audio; | ||||||
|  |  | ||||||
| import sj.AbstractScene, | import sj.KeyInput, | ||||||
|        sj.KeyInput, |  | ||||||
|        sj.LobbyWorld, |        sj.LobbyWorld, | ||||||
|        sj.ProgramSet, |        sj.ProgramSet, | ||||||
|        sj.SceneInterface, |        sj.SceneInterface, | ||||||
|  |        sj.TitleScene, | ||||||
|        sj.util.audio; |        sj.util.audio; | ||||||
|  |  | ||||||
| /// | /// | ||||||
| class SelectScene : AbstractScene { | class SelectScene : SceneInterface { | ||||||
|  public: |  public: | ||||||
|  |  | ||||||
|   /// |   /// | ||||||
| @@ -27,12 +27,19 @@ class SelectScene : AbstractScene { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   /// |   /// | ||||||
|   void SetupSceneDependency(SceneInterface title_scene) { |   void SetupSceneDependency(TitleScene title_scene) { | ||||||
|     title_scene_ = title_scene; |     title_scene_ = title_scene; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   override void Update(KeyInput input) { |   /// | ||||||
|     if (input.up) GoNextScene(title_scene_); |   void Initialize() { | ||||||
|  |   } | ||||||
|  |   override SceneInterface Update(KeyInput input) { | ||||||
|  |     if (input.up) { | ||||||
|  |       title_scene_.Initialize(); | ||||||
|  |       return title_scene_; | ||||||
|  |     } | ||||||
|  |     return this; | ||||||
|   } |   } | ||||||
|   override void Draw() { |   override void Draw() { | ||||||
|     lobby_.Draw(); |     lobby_.Draw(); | ||||||
| @@ -53,7 +60,7 @@ class SelectScene : AbstractScene { | |||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   SceneInterface title_scene_; |   TitleScene title_scene_; | ||||||
|  |  | ||||||
|   LobbyWorld lobby_; |   LobbyWorld lobby_; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -5,15 +5,15 @@ import std.math; | |||||||
|  |  | ||||||
| import gl4d; | import gl4d; | ||||||
|  |  | ||||||
| import sj.AbstractScene, | import sj.KeyInput, | ||||||
|        sj.KeyInput, |  | ||||||
|        sj.LobbyWorld, |        sj.LobbyWorld, | ||||||
|        sj.ProgramSet, |        sj.ProgramSet, | ||||||
|  |        sj.SelectScene, | ||||||
|        sj.SceneInterface, |        sj.SceneInterface, | ||||||
|        sj.TitleTextProgram; |        sj.TitleTextProgram; | ||||||
|  |  | ||||||
| /// | /// | ||||||
| class TitleScene : AbstractScene { | class TitleScene : SceneInterface { | ||||||
|  public: |  public: | ||||||
|   /// |   /// | ||||||
|   enum TitleMatrix = { |   enum TitleMatrix = { | ||||||
| @@ -26,20 +26,40 @@ class TitleScene : AbstractScene { | |||||||
|   /// |   /// | ||||||
|   this(LobbyWorld lobby, ProgramSet program) { |   this(LobbyWorld lobby, ProgramSet program) { | ||||||
|     lobby_ = lobby; |     lobby_ = lobby; | ||||||
|     SetupLobby(lobby); |  | ||||||
|  |  | ||||||
|     title_ = program.Get!TitleTextProgram; |     title_ = program.Get!TitleTextProgram; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   /// |   /// | ||||||
|   void SetupSceneDependency(SceneInterface next_scene) { |   void SetupSceneDependency(SelectScene select) { | ||||||
|     next_scene_ = next_scene; |     select_scene_ = select; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   override void Update(KeyInput input) { |   /// | ||||||
|  |   void Initialize() { | ||||||
|  |     lobby_.view.pos    = vec3(0, -0.15, -1); | ||||||
|  |     lobby_.view.target = vec3(0, -0.15, 0); | ||||||
|  |     lobby_.view.up     = vec3(0, 1, 0); | ||||||
|  |  | ||||||
|  |     lobby_.background.inner_color = vec4(0.9, 0.9, 0.9, 1); | ||||||
|  |     lobby_.background.outer_color = vec4(-0.1, -0.1, -0.1, 1); | ||||||
|  |  | ||||||
|  |     lobby_.light_pos                    = vec3(0, 9, -1); | ||||||
|  |     lobby_.cube_material.diffuse_color  = vec3(0.1, 0.1, 0.1); | ||||||
|  |     lobby_.cube_material.light_color    = vec3(1, 0.8, 0.8); | ||||||
|  |     lobby_.cube_material.light_power    = vec3(100, 100, 100); | ||||||
|  |     lobby_.cube_material.ambient_color  = vec3(0.2, 0.2, 0.2); | ||||||
|  |     lobby_.cube_material.specular_color = vec3(0.5, 0.2, 0.2); | ||||||
|  |  | ||||||
|  |     frame_ = 0; | ||||||
|  |   } | ||||||
|  |   override SceneInterface Update(KeyInput input) { | ||||||
|     lobby_.cube_matrix.rotation += vec3(PI/600, PI/600, PI/600); |     lobby_.cube_matrix.rotation += vec3(PI/600, PI/600, PI/600); | ||||||
|  |  | ||||||
|     if (input.down) GoNextScene(next_scene_); |     if (input.down) { | ||||||
|  |       select_scene_.Initialize(); | ||||||
|  |       return select_scene_; | ||||||
|  |     } | ||||||
|  |     return this; | ||||||
|   } |   } | ||||||
|   override void Draw() { |   override void Draw() { | ||||||
|     lobby_.Draw(); |     lobby_.Draw(); | ||||||
| @@ -47,23 +67,7 @@ class TitleScene : AbstractScene { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|  private: |  private: | ||||||
|   static void SetupLobby(LobbyWorld lobby) { |   SelectScene select_scene_; | ||||||
|     lobby.view.pos    = vec3(0, -0.15, -1); |  | ||||||
|     lobby.view.target = vec3(0, -0.15, 0); |  | ||||||
|     lobby.view.up     = vec3(0, 1, 0); |  | ||||||
|  |  | ||||||
|     lobby.background.inner_color = vec4(0.9, 0.9, 0.9, 1); |  | ||||||
|     lobby.background.outer_color = vec4(-0.1, -0.1, -0.1, 1); |  | ||||||
|  |  | ||||||
|     lobby.light_pos                    = vec3(0, 9, -1); |  | ||||||
|     lobby.cube_material.diffuse_color  = vec3(0.1, 0.1, 0.1); |  | ||||||
|     lobby.cube_material.light_color    = vec3(1, 0.8, 0.8); |  | ||||||
|     lobby.cube_material.light_power    = vec3(100, 100, 100); |  | ||||||
|     lobby.cube_material.ambient_color  = vec3(0.2, 0.2, 0.2); |  | ||||||
|     lobby.cube_material.specular_color = vec3(0.5, 0.2, 0.2); |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   SceneInterface next_scene_; |  | ||||||
|  |  | ||||||
|   LobbyWorld lobby_; |   LobbyWorld lobby_; | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user