From 3c4734d69a44aea133e5bd7df66a5dedb87785fb Mon Sep 17 00:00:00 2001 From: Kahrl Date: Tue, 20 Aug 2013 22:38:14 +0200 Subject: Change mainmenu texture handling + small misc changes Texture names must now be escaped in formspec elements image[], background[], image_button[], image_button_exit[]. Instead of special-case handling of texture loading (and unloading which was missing) in guiFormSpecMenu.cpp, use the newly created ISimpleTextureSource interface which is a minimal subset of ITextureSource. There is an implementation of this interface used by GUIEngine (MenuTextureSource). Fix an off-by-one bug in unescape_string; it caused requests for a texture called "\0". --- src/guiEngine.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) (limited to 'src/guiEngine.cpp') diff --git a/src/guiEngine.cpp b/src/guiEngine.cpp index f00cd039c..547f393a4 100644 --- a/src/guiEngine.cpp +++ b/src/guiEngine.cpp @@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "guiMainMenu.h" #include "sound.h" #include "sound_openal.h" +#include "clouds.h" #include #include @@ -36,6 +37,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #endif +/******************************************************************************/ +/** TextDestGuiEngine */ /******************************************************************************/ TextDestGuiEngine::TextDestGuiEngine(GUIEngine* engine) { @@ -54,6 +57,38 @@ void TextDestGuiEngine::gotText(std::wstring text) m_engine->getScriptIface()->handleMainMenuEvent(wide_to_narrow(text)); } +/******************************************************************************/ +/** MenuTextureSource */ +/******************************************************************************/ +MenuTextureSource::MenuTextureSource(video::IVideoDriver *driver) +{ + m_driver = driver; +} + +/******************************************************************************/ +MenuTextureSource::~MenuTextureSource() +{ + for (std::set::iterator it = m_to_delete.begin(); + it != m_to_delete.end(); ++it) { + const char *tname = (*it).c_str(); + video::ITexture *texture = m_driver->getTexture(tname); + m_driver->removeTexture(texture); + } +} + +/******************************************************************************/ +video::ITexture* MenuTextureSource::getTexture(const std::string &name, u32 *id) +{ + if(id) + *id = 0; + if(name.empty()) + return NULL; + m_to_delete.insert(name); + return m_driver->getTexture(name.c_str()); +} + +/******************************************************************************/ +/** MenuMusicFetcher */ /******************************************************************************/ void MenuMusicFetcher::fetchSounds(const std::string &name, std::set &dst_paths, @@ -74,6 +109,8 @@ void MenuMusicFetcher::fetchSounds(const std::string &name, dst_paths.insert(base + DIR_DELIM + name + "."+itos(i)+".ogg"); } +/******************************************************************************/ +/** GUIEngine */ /******************************************************************************/ GUIEngine::GUIEngine( irr::IrrlichtDevice* dev, gui::IGUIElement* parent, @@ -86,6 +123,7 @@ GUIEngine::GUIEngine( irr::IrrlichtDevice* dev, m_menumanager(menumgr), m_smgr(smgr), m_data(data), + m_texture_source(NULL), m_sound_manager(NULL), m_formspecgui(0), m_buttonhandler(0), @@ -105,6 +143,9 @@ GUIEngine::GUIEngine( irr::IrrlichtDevice* dev, // is deleted by guiformspec! m_buttonhandler = new TextDestGuiEngine(this); + //create texture source + m_texture_source = new MenuTextureSource(m_device->getVideoDriver()); + //create soundmanager MenuMusicFetcher soundfetcher; #if USE_SOUND @@ -132,7 +173,8 @@ GUIEngine::GUIEngine( irr::IrrlichtDevice* dev, -1, m_menumanager, 0 /* &client */, - 0 /* gamedef */); + 0 /* gamedef */, + m_texture_source); m_menu->allowClose(false); m_menu->lockSize(true,v2u32(800,600)); @@ -264,11 +306,13 @@ GUIEngine::~GUIEngine() m_irr_toplefttext->setText(L""); - //initialize texture pointers + //clean up texture pointers for (unsigned int i = 0; i < TEX_LAYER_MAX; i++) { if (m_textures[i] != 0) driver->removeTexture(m_textures[i]); } + + delete m_texture_source; if (m_cloud.clouds) m_cloud.clouds->drop(); -- cgit v1.2.3