More work on reinitialization. Fonts still not working.

This commit is contained in:
Aloshi 2013-04-10 12:29:07 -05:00
parent 05c258f515
commit b01f2705de
17 changed files with 96 additions and 29 deletions

View file

@ -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()

View file

@ -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();

View file

@ -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; }

View file

@ -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);

View file

@ -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;

View file

@ -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();
}
};

View file

@ -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)

View file

@ -1,10 +1,11 @@
#include "Window.h"
#include <iostream>
#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)

View file

@ -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()

View file

@ -32,8 +32,8 @@ public:
void render();
void onInit();
void onDeinit();
void init();
void deinit();
private:
GuiImage mBackgroundImage, mHorizontalImage, mVerticalImage, mCornerImage;

View file

@ -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)

View file

@ -26,8 +26,8 @@ public:
void update(int deltaTime);
void render();
void onInit();
void onDeinit();
void init();
void deinit();
void updateDetailData();

View file

@ -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();
}

View file

@ -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);

View file

@ -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();
}
}

View file

@ -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);

View file

@ -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