From b01f2705de4963c43d67414a6d9d972ee52c15df Mon Sep 17 00:00:00 2001 From: Aloshi Date: Wed, 10 Apr 2013 12:29:07 -0500 Subject: [PATCH] More work on reinitialization. Fonts still not working. --- src/Font.cpp | 10 +++++++--- src/Font.h | 4 ++-- src/InputManager.cpp | 8 ++++++++ src/Renderer.h | 2 +- src/Renderer_init_rpi.cpp | 2 +- src/Renderer_init_sdlgl.cpp | 16 ++++++++++++++-- src/SystemData.cpp | 8 ++------ src/Window.cpp | 11 ++++++++++- src/components/GuiBox.cpp | 10 ++++++++-- src/components/GuiBox.h | 4 ++-- src/components/GuiGameList.cpp | 15 +++++++++++++-- src/components/GuiGameList.h | 4 ++-- src/components/GuiImage.cpp | 4 ++-- src/components/GuiImage.h | 4 ++-- src/components/GuiTheme.cpp | 17 +++++++++++++++++ src/components/GuiTheme.h | 3 +++ src/main.cpp | 3 ++- 17 files changed, 96 insertions(+), 29 deletions(-) diff --git a/src/Font.cpp b/src/Font.cpp index ab5848637..ddec1df0d 100644 --- a/src/Font.cpp +++ b/src/Font.cpp @@ -47,10 +47,10 @@ Font::Font(std::string path, int size) mPath = path; mSize = size; - onInit(); + init(); } -void Font::onInit() +void Font::init() { if(!libraryInitialized) initLibrary(); @@ -69,12 +69,16 @@ void Font::onInit() buildAtlas(); FT_Done_Face(face); + + std::cout << "initialized font\n"; } -void Font::onDeinit() +void Font::deinit() { if(textureID) glDeleteTextures(1, &textureID); + + std::cout << "deinitialized font\n"; } void Font::buildAtlas() diff --git a/src/Font.h b/src/Font.h index 6d7044b19..971d5128f 100644 --- a/src/Font.h +++ b/src/Font.h @@ -40,8 +40,8 @@ public: void sizeText(std::string text, int* w, int* h); //Sets the width and height of a given string to given pointers. Skipped if pointer is NULL. int getHeight(); - void onInit(); - void onDeinit(); + void init(); + void deinit(); int getSize(); diff --git a/src/InputManager.cpp b/src/InputManager.cpp index f5aef98d3..01e307970 100644 --- a/src/InputManager.cpp +++ b/src/InputManager.cpp @@ -21,6 +21,8 @@ void InputManager::init() if(mJoysticks != NULL) deinit(); + std::cout << "initializing InputManager..."; + SDL_InitSubSystem(SDL_INIT_JOYSTICK); mNumJoysticks = SDL_NumJoysticks(); @@ -42,10 +44,14 @@ void InputManager::init() mKeyboardInputConfig = new InputConfig(DEVICE_KEYBOARD); SDL_JoystickEventState(SDL_ENABLE); + + std::cout << "done\n"; } void InputManager::deinit() { + std::cout << "deinitializing InputManager..."; + SDL_JoystickEventState(SDL_DISABLE); if(!SDL_WasInit(SDL_INIT_JOYSTICK)) @@ -70,6 +76,8 @@ void InputManager::deinit() } SDL_QuitSubSystem(SDL_INIT_JOYSTICK); + + std::cout << "done\n"; } int InputManager::getNumJoysticks() { return mNumJoysticks; } diff --git a/src/Renderer.h b/src/Renderer.h index c4fa2dacb..c9f9093ab 100644 --- a/src/Renderer.h +++ b/src/Renderer.h @@ -20,7 +20,7 @@ namespace Renderer unsigned int getScreenWidth(); unsigned int getScreenHeight(); - enum FontSize { SMALL, MEDIUM, LARGE }; + enum FontSize { SMALL, MEDIUM, LARGE, FONT_SIZE_COUNT }; Font* getDefaultFont(FontSize size); void buildGLColorArray(GLubyte* ptr, unsigned int color, unsigned int vertCount); diff --git a/src/Renderer_init_rpi.cpp b/src/Renderer_init_rpi.cpp index 849dbc531..60069fa7d 100644 --- a/src/Renderer_init_rpi.cpp +++ b/src/Renderer_init_rpi.cpp @@ -31,7 +31,7 @@ namespace Renderer { LOG(LogInfo) << "Starting SDL..."; - if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO) != 0) + if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) != 0) { LOG(LogError) << "Error initializing SDL!\n " << SDL_GetError() << "\n" << "Are you in the 'video', 'audio', and 'input' groups? Is X closed? Is your firmware up to date? Are you using at least the 192/64 memory split?"; return false; diff --git a/src/Renderer_init_sdlgl.cpp b/src/Renderer_init_sdlgl.cpp index 6d15ebfba..b765391e6 100644 --- a/src/Renderer_init_sdlgl.cpp +++ b/src/Renderer_init_sdlgl.cpp @@ -21,7 +21,7 @@ namespace Renderer { LOG(LogInfo) << "Creating surface..."; - if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO) != 0) + if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) != 0) { LOG(LogError) << "Error initializing SDL!\n " << SDL_GetError(); return false; @@ -32,7 +32,7 @@ namespace Renderer SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - sdlScreen = SDL_SetVideoMode(display_width, display_height, 16, SDL_OPENGL | SDL_FULLSCREEN | SDL_DOUBLEBUF); + sdlScreen = SDL_SetVideoMode(display_width, display_height, 16, SDL_OPENGL /*| SDL_FULLSCREEN*/ | SDL_DOUBLEBUF); if(sdlScreen == NULL) { @@ -80,11 +80,23 @@ namespace Renderer glOrtho(0, display_width, display_height, 0, -1.0, 1.0); glClearColor(1.0f, 1.0f, 1.0f, 1.0f); + //initialize fonts + for(int i = 0; i < (int)FONT_SIZE_COUNT; i++) + { + getDefaultFont((FontSize)i)->init(); + } + return true; } void deinit() { + //deinitialize fonts + for(int i = 0; i < (int)FONT_SIZE_COUNT; i++) + { + getDefaultFont((FontSize)i)->deinit(); + } + destroySurface(); } }; diff --git a/src/SystemData.cpp b/src/SystemData.cpp index 8d6b5eb77..a0c0802c2 100644 --- a/src/SystemData.cpp +++ b/src/SystemData.cpp @@ -67,9 +67,7 @@ void SystemData::launchGame(Window* window, GameData* game) { LOG(LogInfo) << "Attempting to launch game..."; - AudioManager::deinit(); - window->getInputManager()->deinit(); - Renderer::deinit(); + window->deinit(); std::string command = mLaunchCommand; @@ -86,9 +84,7 @@ void SystemData::launchGame(Window* window, GameData* game) LOG(LogWarning) << "...launch terminated with nonzero exit code " << exitCode << "!"; } - Renderer::init(0, 0); - window->getInputManager()->init(); - AudioManager::init(); + window->init(); } void SystemData::populateFolder(FolderData* folder) diff --git a/src/Window.cpp b/src/Window.cpp index ccdf8e7ec..6bb15bff3 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -1,10 +1,11 @@ #include "Window.h" #include +#include "Renderer.h" +#include "AudioManager.h" Window::Window() { mInputManager = new InputManager(this); - mInputManager->init(); } Window::~Window() @@ -50,6 +51,10 @@ void Window::render() void Window::init() { + AudioManager::init(); + mInputManager->init(); + Renderer::init(0, 0); + for(unsigned int i = 0; i < mGuiStack.size(); i++) { mGuiStack.at(i)->init(); @@ -62,6 +67,10 @@ void Window::deinit() { mGuiStack.at(i)->deinit(); } + + AudioManager::deinit(); + mInputManager->deinit(); + Renderer::deinit(); } void Window::input(InputConfig* config, Input input) diff --git a/src/components/GuiBox.cpp b/src/components/GuiBox.cpp index 6b51f6dc6..f7abe8796 100644 --- a/src/components/GuiBox.cpp +++ b/src/components/GuiBox.cpp @@ -111,12 +111,18 @@ void GuiBox::render() mCornerImage.render(); } -void GuiBox::onInit() +void GuiBox::init() { + mVerticalImage.init(); + mHorizontalImage.init(); + mCornerImage.init(); } -void GuiBox::onDeinit() +void GuiBox::deinit() { + mVerticalImage.deinit(); + mHorizontalImage.deinit(); + mCornerImage.deinit(); } int GuiBox::getHorizontalBorderWidth() diff --git a/src/components/GuiBox.h b/src/components/GuiBox.h index cc164c21c..89be516d5 100644 --- a/src/components/GuiBox.h +++ b/src/components/GuiBox.h @@ -32,8 +32,8 @@ public: void render(); - void onInit(); - void onDeinit(); + void init(); + void deinit(); private: GuiImage mBackgroundImage, mHorizontalImage, mVerticalImage, mCornerImage; diff --git a/src/components/GuiGameList.cpp b/src/components/GuiGameList.cpp index 41451cf6e..9711e4e3e 100644 --- a/src/components/GuiGameList.cpp +++ b/src/components/GuiGameList.cpp @@ -125,6 +125,7 @@ void GuiGameList::input(InputConfig* config, Input input) while(mTheme->getSound("menuSelect")->isPlaying()); mSystem->launchGame(mWindow, (GameData*)file); + return; } } @@ -275,14 +276,24 @@ void GuiGameList::clearDetailData() //called when the renderer shuts down/returns //we have to manually call init/deinit on mTheme because it is not our child -void GuiGameList::onDeinit() +void GuiGameList::deinit() { + if(mDetailed) + { + mScreenshot->deinit(); + } + mTheme->deinit(); } -void GuiGameList::onInit() +void GuiGameList::init() { mTheme->init(); + + if(mDetailed) + { + mScreenshot->deinit(); + } } extern bool IGNOREGAMELIST; //defined in main.cpp (as a command line argument) diff --git a/src/components/GuiGameList.h b/src/components/GuiGameList.h index 8cb2d7d84..860a8ee23 100644 --- a/src/components/GuiGameList.h +++ b/src/components/GuiGameList.h @@ -26,8 +26,8 @@ public: void update(int deltaTime); void render(); - void onInit(); - void onDeinit(); + void init(); + void deinit(); void updateDetailData(); diff --git a/src/components/GuiImage.cpp b/src/components/GuiImage.cpp index 8c6da93fd..e8e125163 100644 --- a/src/components/GuiImage.cpp +++ b/src/components/GuiImage.cpp @@ -354,13 +354,13 @@ void GuiImage::drawImageArray(GLfloat* points, GLfloat* texs, GLubyte* colors, u glDisable(GL_BLEND); } -void GuiImage::onInit() +void GuiImage::init() { if(!mPath.empty()) loadImage(mPath); } -void GuiImage::onDeinit() +void GuiImage::deinit() { unloadImage(); } diff --git a/src/components/GuiImage.h b/src/components/GuiImage.h index e0f0d6413..ead109b95 100644 --- a/src/components/GuiImage.h +++ b/src/components/GuiImage.h @@ -32,8 +32,8 @@ public: void render(); //Image textures will be deleted on renderer deinitialization, and recreated on reinitialization (if mPath is not empty). - void onInit(); - void onDeinit(); + void init(); + void deinit(); unsigned char getOpacity(); void setOpacity(unsigned char opacity); diff --git a/src/components/GuiTheme.cpp b/src/components/GuiTheme.cpp index 7cba8db3c..8d5f6a47f 100644 --- a/src/components/GuiTheme.cpp +++ b/src/components/GuiTheme.cpp @@ -431,3 +431,20 @@ void GuiTheme::render() mComponentVector.at(i)->render(); } } + +void GuiTheme::init() +{ + for(unsigned int i = 0; i < mComponentVector.size(); i++) + { + mComponentVector.at(i)->init(); + } +} + +void GuiTheme::deinit() +{ + for(unsigned int i = 0; i < mComponentVector.size(); i++) + { + mComponentVector.at(i)->deinit(); + } +} + diff --git a/src/components/GuiTheme.h b/src/components/GuiTheme.h index 30382e495..722eee7a0 100644 --- a/src/components/GuiTheme.h +++ b/src/components/GuiTheme.h @@ -20,6 +20,9 @@ public: void render(); + void init(); + void deinit(); + unsigned int getColor(std::string name); bool getBool(std::string name); float getFloat(std::string name); diff --git a/src/main.cpp b/src/main.cpp index 75362ff28..977ab6e9d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -114,7 +114,8 @@ int main(int argc, char* argv[]) //initialize audio AudioManager::init(); - Window window; + Window window; //don't call Window.init() because we manually pass the resolution to Renderer::init + window.getInputManager()->init(); //try loading the system config file if(!fs::exists(SystemData::getConfigPath())) //if it doesn't exist, create the example and quit