From ccea2a7e049957caaf3b46f3972e0e01414e8dd8 Mon Sep 17 00:00:00 2001 From: Aloshi Date: Thu, 12 Dec 2013 13:48:29 -0600 Subject: [PATCH] Removed some old effects code from Window. Added a simple "LOADING" screen when ES starts up. ViewController now preloads GameListViews so there's no lag when browsing to a system for the first time. --- src/Window.cpp | 54 +++++++++--------------------------- src/Window.h | 16 ++--------- src/main.cpp | 15 ++++++++-- src/views/ViewController.cpp | 13 +++++++-- src/views/ViewController.h | 4 +++ 5 files changed, 41 insertions(+), 61 deletions(-) diff --git a/src/Window.cpp b/src/Window.cpp index c2b2e42f6..6635dca52 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -9,16 +9,17 @@ #include "views/ViewController.h" Window::Window() : mNormalizeNextUpdate(false), mFrameTimeElapsed(0), mFrameCountElapsed(0), mAverageDeltaTime(10), - mZoomFactor(1.0f), mCenterPoint(0, 0), mMatrix(Eigen::Affine3f::Identity()), mFadePercent(0.0f), mAllowSleep(true) + mAllowSleep(true) { mInputManager = new InputManager(this); mViewController = new ViewController(this); pushGui(mViewController); - setCenterPoint(Eigen::Vector2f(Renderer::getScreenWidth() / 2, Renderer::getScreenHeight() / 2)); } Window::~Window() { + delete mViewController; // this would get deleted down below, but just to be safe, delete it here + //delete all our GUIs while(peekGui()) delete peekGui(); @@ -131,13 +132,12 @@ void Window::update(int deltaTime) void Window::render() { + Eigen::Affine3f transform = Eigen::Affine3f::Identity(); for(unsigned int i = 0; i < mGuiStack.size(); i++) { - mGuiStack.at(i)->render(mMatrix); + mGuiStack.at(i)->render(transform); } - postProcess(); - if(Settings::getInstance()->getBool("DRAWFRAMERATE")) { Renderer::setMatrix(Eigen::Affine3f::Identity()); @@ -150,42 +150,6 @@ void Window::normalizeNextUpdate() mNormalizeNextUpdate = true; } -void Window::setZoomFactor(const float& zoom) -{ - mZoomFactor = zoom; - updateMatrix(); -} - -void Window::setCenterPoint(const Eigen::Vector2f& point) -{ - mCenterPoint = point; - updateMatrix(); -} - -void Window::updateMatrix() -{ - const float sw = Renderer::getScreenWidth() / mZoomFactor; - const float sh = Renderer::getScreenHeight() / mZoomFactor; - - mMatrix = Eigen::Affine3f::Identity(); - mMatrix = mMatrix.scale(Eigen::Vector3f(mZoomFactor, mZoomFactor, 1)); - mMatrix = mMatrix.translate(Eigen::Vector3f(sw / 2 - mCenterPoint.x(), sh / 2 - mCenterPoint.y(), 0)); -} - -void Window::setFadePercent(const float& perc) -{ - mFadePercent = perc; -} - -void Window::postProcess() -{ - if(mFadePercent > 0.0f) - { - Renderer::setMatrix(Eigen::Affine3f::Identity()); - Renderer::drawRect(0, 0, Renderer::getScreenWidth(), Renderer::getScreenHeight(), 0x00000000 | ((unsigned char)(mFadePercent * 255))); - } -} - bool Window::getAllowSleep() { return mAllowSleep; @@ -195,3 +159,11 @@ void Window::setAllowSleep(bool sleep) { mAllowSleep = sleep; } + +void Window::renderLoadingScreen() +{ + Renderer::setMatrix(Eigen::Affine3f::Identity()); + Renderer::drawRect(0, 0, Renderer::getScreenWidth(), Renderer::getScreenHeight(), 0x000000FF); + mDefaultFonts.at(2)->drawCenteredText("LOADING", 0, (Renderer::getScreenHeight() - mDefaultFonts.at(2)->getHeight()) / 2.0f , 0xFFFFFFFF); + Renderer::swapBuffers(); +} diff --git a/src/Window.h b/src/Window.h index 757fa2a7b..d48450806 100644 --- a/src/Window.h +++ b/src/Window.h @@ -30,14 +30,11 @@ public: void normalizeNextUpdate(); - void setZoomFactor(const float& zoom); - void setCenterPoint(const Eigen::Vector2f& point); - - void setFadePercent(const float& perc); - bool getAllowSleep(); void setAllowSleep(bool sleep); + void renderLoadingScreen(); + private: InputManager* mInputManager; ViewController* mViewController; @@ -52,15 +49,6 @@ private: bool mNormalizeNextUpdate; - float mZoomFactor; - Eigen::Vector2f mCenterPoint; - - void updateMatrix(); - Eigen::Affine3f mMatrix; - - void postProcess(); - float mFadePercent; - bool mAllowSleep; }; diff --git a/src/main.cpp b/src/main.cpp index 0921740b7..bc8c9fec9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -131,10 +131,15 @@ int main(int argc, char* argv[]) atexit(&onExit); Window window; - if(!scrape_cmdline && !window.init(width, height)) + if(!scrape_cmdline) { - LOG(LogError) << "Window failed to initialize!"; - return 1; + if(!window.init(width, height)) + { + LOG(LogError) << "Window failed to initialize!"; + return 1; + } + + window.renderLoadingScreen(); } //try loading the system config file @@ -160,6 +165,10 @@ int main(int argc, char* argv[]) //dont generate joystick events while we're loading (hopefully fixes "automatically started emulator" bug) SDL_JoystickEventState(SDL_DISABLE); + // preload what we can right away instead of waiting for the user to select it + // this makes for no delays when accessing content, but a longer startup time + window.getViewController()->preload(); + //choose which GUI to open depending on if an input configuration already exists if(fs::exists(InputManager::getConfigPath())) { diff --git a/src/views/ViewController.cpp b/src/views/ViewController.cpp index 7eb34c2c3..c5e77061d 100644 --- a/src/views/ViewController.cpp +++ b/src/views/ViewController.cpp @@ -19,7 +19,6 @@ void ViewController::goToSystemSelect() mState.viewing = SYSTEM_SELECT; mCurrentView = getSystemListView(); playViewTransition(); - LOG(LogInfo) << "going to system select"; } SystemData* getSystemCyclic(SystemData* from, bool reverse) @@ -46,7 +45,7 @@ SystemData* getSystemCyclic(SystemData* from, bool reverse) void ViewController::goToNextGameList() { - assert(mState.viewing == SYSTEM); + assert(mState.viewing == GAME_LIST); SystemData* system = mState.data.system; if(system == NULL) @@ -57,7 +56,7 @@ void ViewController::goToNextGameList() void ViewController::goToPrevGameList() { - assert(mState.viewing == SYSTEM); + assert(mState.viewing == GAME_LIST); SystemData* system = mState.data.system; if(system == NULL) @@ -213,3 +212,11 @@ void ViewController::render(const Eigen::Affine3f& parentTrans) Renderer::drawRect(0, 0, Renderer::getScreenWidth(), Renderer::getScreenHeight(), 0x00000000 | (unsigned char)(mFadeOpacity * 255)); } } + +void ViewController::preload() +{ + for(auto it = SystemData::sSystemVector.begin(); it != SystemData::sSystemVector.end(); it++) + { + getGameListView(*it); + } +} diff --git a/src/views/ViewController.h b/src/views/ViewController.h index 35cd10a7e..c9ec81ab3 100644 --- a/src/views/ViewController.h +++ b/src/views/ViewController.h @@ -10,6 +10,10 @@ class ViewController : public GuiComponent public: ViewController(Window* window); + // Try to completely populate the GameListView map. + // Caches things so there's no pauses during transitions. + void preload(); + // Navigation. void goToNextGameList(); void goToPrevGameList();