diff --git a/src/Scene.cpp b/src/Scene.cpp index c01fa4e..a16506a 100644 --- a/src/Scene.cpp +++ b/src/Scene.cpp @@ -20,3 +20,5 @@ Scene::Scene() {} Scene::~Scene() {} + +void Scene::render(SDL_Rect rect, double dTime) {} diff --git a/src/Scene.hpp b/src/Scene.hpp index 32e3fdc..7b0e903 100644 --- a/src/Scene.hpp +++ b/src/Scene.hpp @@ -17,10 +17,14 @@ #pragma once +#include + using namespace std; class Scene { public: Scene(); - ~Scene(); + virtual ~Scene(); + + virtual void render(SDL_Rect rect, double dTime); }; diff --git a/src/SceneDirector.cpp b/src/SceneDirector.cpp index ca22b5b..c575e33 100644 --- a/src/SceneDirector.cpp +++ b/src/SceneDirector.cpp @@ -48,9 +48,29 @@ SceneDirector::SceneDirector() { _now = SDL_GetPerformanceCounter(); _last = 0; + _allDoneScene = NULL; + _appUpdateScene = NULL; + _downloadingAppScene = NULL; + _downloadingPackageScene = NULL; + _packageSelectScene = NULL; } SceneDirector::~SceneDirector() { + if (_allDoneScene != NULL) + delete _allDoneScene; + + if (_appUpdateScene != NULL) + delete _appUpdateScene; + + if (_downloadingAppScene != NULL) + delete _downloadingAppScene; + + if (_downloadingPackageScene != NULL) + delete _downloadingPackageScene; + + if (_packageSelectScene != NULL) + delete _packageSelectScene; + if (SceneDirector::renderer != NULL) SDL_DestroyRenderer(SceneDirector::renderer); @@ -73,29 +93,94 @@ bool SceneDirector::direct() { hidScanInput(); u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO); - if (kDown & KEY_A) - return false; + + // TODO: Handle touch controls AssetManager::setRenderColor(AssetManager::background); SDL_RenderClear(SceneDirector::renderer); + // Unload previous scenes switch(SceneDirector::currentScene) { - case SCENE_APP_UPDATE: - break; - - case SCENE_DOWNLOADING_APP: - break; - case SCENE_PACKAGE_SELECT: - break; - case SCENE_DOWNLOADING_PACKAGE: + if (_appUpdateScene != NULL) { + delete _appUpdateScene; + _appUpdateScene = NULL; + } + + if (_downloadingAppScene != NULL) { + delete _downloadingAppScene; + _downloadingAppScene = NULL; + } break; case SCENE_ALL_DONE: + if (_appUpdateScene != NULL) { + delete _appUpdateScene; + _appUpdateScene = NULL; + } + + if (_downloadingAppScene != NULL) { + delete _downloadingAppScene; + _downloadingAppScene = NULL; + } + + if (_packageSelectScene != NULL) { + delete _packageSelectScene; + _packageSelectScene = NULL; + } + + if (_downloadingPackageScene != NULL) { + delete _downloadingPackageScene; + _downloadingPackageScene = NULL; + } + break; + + default: + /* Do Nothing */ break; } + // Load new scenes + switch(SceneDirector::currentScene) { + case SCENE_APP_UPDATE: + if (_appUpdateScene == NULL) + _appUpdateScene = new AppUpdateScene(); + + _currentScene = _appUpdateScene; + break; + + case SCENE_DOWNLOADING_APP: + if (_downloadingAppScene == NULL) + _downloadingAppScene = new DownloadingAppScene(); + + _currentScene = _downloadingAppScene; + break; + + case SCENE_PACKAGE_SELECT: + if (_packageSelectScene == NULL) + _packageSelectScene = new PackageSelectScene(); + + _currentScene = _packageSelectScene; + break; + + case SCENE_DOWNLOADING_PACKAGE: + if (_downloadingPackageScene == NULL) + _downloadingPackageScene = new DownloadingPackageScene(); + + _currentScene = _downloadingPackageScene; + break; + + case SCENE_ALL_DONE: + if (_allDoneScene == NULL) + _allDoneScene = new AllDoneScene(); + + _currentScene = _allDoneScene; + break; + } + + _currentScene->render({ 0, 0, 1280, 720 }, dTime); + SDL_RenderPresent(SceneDirector::renderer); return !SceneDirector::exitApp; diff --git a/src/SceneDirector.hpp b/src/SceneDirector.hpp index bc08249..e9a0b21 100644 --- a/src/SceneDirector.hpp +++ b/src/SceneDirector.hpp @@ -19,8 +19,13 @@ #include #include "AssetManager.hpp" -#include "views/HeaderView.hpp" -#include "views/FooterView.hpp" +#include "Scene.hpp" + +#include "scenes/AllDoneScene.hpp" +#include "scenes/AppUpdateScene.hpp" +#include "scenes/DownloadingAppScene.hpp" +#include "scenes/DownloadingPackageScene.hpp" +#include "scenes/PackageSelectScene.hpp" typedef enum { SCENE_APP_UPDATE, @@ -47,4 +52,11 @@ class SceneDirector { private: Uint64 _now; Uint64 _last; + + Scene * _currentScene; + AllDoneScene * _allDoneScene; + AppUpdateScene * _appUpdateScene; + DownloadingAppScene * _downloadingAppScene; + DownloadingPackageScene * _downloadingPackageScene; + PackageSelectScene * _packageSelectScene; }; \ No newline at end of file diff --git a/src/scenes/AllDoneScene.cpp b/src/scenes/AllDoneScene.cpp index d39e601..318072b 100644 --- a/src/scenes/AllDoneScene.cpp +++ b/src/scenes/AllDoneScene.cpp @@ -20,3 +20,7 @@ AllDoneScene::AllDoneScene() {} AllDoneScene::~AllDoneScene() {} + +void AllDoneScene::render(SDL_Rect rect, double dTime) { + +} diff --git a/src/scenes/AllDoneScene.hpp b/src/scenes/AllDoneScene.hpp index b8b6c45..f0dbe32 100644 --- a/src/scenes/AllDoneScene.hpp +++ b/src/scenes/AllDoneScene.hpp @@ -23,6 +23,8 @@ class AllDoneScene : public Scene { public: AllDoneScene(); ~AllDoneScene(); + + void render(SDL_Rect rect, double dTime); private: }; diff --git a/src/scenes/AppUpdateScene.cpp b/src/scenes/AppUpdateScene.cpp index dc953ba..1b72fa3 100644 --- a/src/scenes/AppUpdateScene.cpp +++ b/src/scenes/AppUpdateScene.cpp @@ -20,3 +20,7 @@ AppUpdateScene::AppUpdateScene() {} AppUpdateScene::~AppUpdateScene() {} + +void AppUpdateScene::render(SDL_Rect rect, double dTime) { + +} diff --git a/src/scenes/AppUpdateScene.hpp b/src/scenes/AppUpdateScene.hpp index 912276b..3bd0e05 100644 --- a/src/scenes/AppUpdateScene.hpp +++ b/src/scenes/AppUpdateScene.hpp @@ -23,6 +23,8 @@ class AppUpdateScene : public Scene { public: AppUpdateScene(); ~AppUpdateScene(); + + void render(SDL_Rect rect, double dTime); private: }; diff --git a/src/scenes/DownloadingAppScene.cpp b/src/scenes/DownloadingAppScene.cpp index bcc808a..656ced6 100644 --- a/src/scenes/DownloadingAppScene.cpp +++ b/src/scenes/DownloadingAppScene.cpp @@ -20,3 +20,7 @@ DownloadingAppScene::DownloadingAppScene() {} DownloadingAppScene::~DownloadingAppScene() {} + +void DownloadingAppScene::render(SDL_Rect rect, double dTime) { + +} diff --git a/src/scenes/DownloadingAppScene.hpp b/src/scenes/DownloadingAppScene.hpp index 2af44f7..d515078 100644 --- a/src/scenes/DownloadingAppScene.hpp +++ b/src/scenes/DownloadingAppScene.hpp @@ -23,6 +23,8 @@ class DownloadingAppScene : public Scene { public: DownloadingAppScene(); ~DownloadingAppScene(); + + void render(SDL_Rect rect, double dTime); private: }; diff --git a/src/scenes/DownloadingPackageScene.cpp b/src/scenes/DownloadingPackageScene.cpp index e1b66e5..a6184ce 100644 --- a/src/scenes/DownloadingPackageScene.cpp +++ b/src/scenes/DownloadingPackageScene.cpp @@ -20,3 +20,7 @@ DownloadingPackageScene::DownloadingPackageScene() {} DownloadingPackageScene::~DownloadingPackageScene() {} + +void DownloadingPackageScene::render(SDL_Rect rect, double dTime) { + +} diff --git a/src/scenes/DownloadingPackageScene.hpp b/src/scenes/DownloadingPackageScene.hpp index 3d7f404..73d2bed 100644 --- a/src/scenes/DownloadingPackageScene.hpp +++ b/src/scenes/DownloadingPackageScene.hpp @@ -23,6 +23,8 @@ class DownloadingPackageScene : public Scene { public: DownloadingPackageScene(); ~DownloadingPackageScene(); + + void render(SDL_Rect rect, double dTime); private: }; diff --git a/src/scenes/PackageSelectScene.cpp b/src/scenes/PackageSelectScene.cpp index 4da24b2..7f144f5 100644 --- a/src/scenes/PackageSelectScene.cpp +++ b/src/scenes/PackageSelectScene.cpp @@ -20,3 +20,7 @@ PackageSelectScene::PackageSelectScene() {} PackageSelectScene::~PackageSelectScene() {} + +void PackageSelectScene::render(SDL_Rect rect, double dTime) { + +} diff --git a/src/scenes/PackageSelectScene.hpp b/src/scenes/PackageSelectScene.hpp index ed6b509..7a38834 100644 --- a/src/scenes/PackageSelectScene.hpp +++ b/src/scenes/PackageSelectScene.hpp @@ -24,5 +24,7 @@ class PackageSelectScene : public Scene { PackageSelectScene(); ~PackageSelectScene(); + void render(SDL_Rect rect, double dTime); + private: };