diff --git a/CMakeLists.txt b/CMakeLists.txt index 6bb4b598..8eb3992e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,7 @@ MESSAGE(STATUS "BUILD TYPE: " ${CMAKE_BUILD_TYPE}) # setup compiler options IF(CMAKE_COMPILER_IS_GNUCXX) - SET(CMAKE_CXX_FLAGS "-Wall -Wextra -Werror -Wno-unused-parameter") + SET(CMAKE_CXX_FLAGS "-Wall -Wextra -Werror -Wno-unused-parameter -std=c++0x") SET(CMAKE_CXX_FLAGS_DEBUG "-O1 -g -ggdb -fno-inline") SET(CMAKE_CXX_FLAGS_RELEASE "-O2 -Wl,-s") SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g") @@ -55,6 +55,7 @@ SET(SOURCES # framework sources src/framework/framebuffer.cpp + src/framework/fonts.cpp src/framework/textureloader.cpp src/framework/texture.cpp src/framework/texturemanager.cpp diff --git a/src/framework/fonts.cpp b/src/framework/fonts.cpp index 19f66633..20b652f0 100644 --- a/src/framework/fonts.cpp +++ b/src/framework/fonts.cpp @@ -14,8 +14,8 @@ Fonts::~Fonts() bool Fonts::load() { std::list files = g_resources.getDirectoryFiles("fonts"); - for(std::list::iterator it = files.begin(), end = files.end(); it != end; ++it) { - notice("File: %s", (*it).c_str()); + foreach(const std::string& file, files) { + notice("File: %s", file.c_str()); } return true; diff --git a/src/framework/texturemanager.cpp b/src/framework/texturemanager.cpp index 51d1ed70..a2dfc751 100644 --- a/src/framework/texturemanager.cpp +++ b/src/framework/texturemanager.cpp @@ -44,8 +44,12 @@ TexturePtr TextureManager::get(const std::string& textureFile) // check if the texture is already loaded TexturesMap::iterator it = m_texturesMap.find(textureFile); - if(it != m_texturesMap.end()) - texture = it->second; + if(it != m_texturesMap.end()) { + if(it->second.expired()) + m_texturesMap.erase(it); + else + texture = it->second.lock(); + } else { // load texture // currently only png textures are supported if(!boost::ends_with(textureFile, ".png")) { diff --git a/src/framework/texturemanager.h b/src/framework/texturemanager.h index ed4b427a..19d8a829 100644 --- a/src/framework/texturemanager.h +++ b/src/framework/texturemanager.h @@ -28,6 +28,8 @@ #include "prerequisites.h" #include "texture.h" +typedef boost::weak_ptr TextureWeakPtr; + class TextureManager { public: @@ -38,7 +40,7 @@ public: TexturePtr get(const std::string& textureFile); private: - typedef std::map TexturesMap; + typedef std::map TexturesMap; TexturesMap m_texturesMap; }; diff --git a/src/main.cpp b/src/main.cpp index 5ab26e80..ded18335 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -105,17 +105,21 @@ int main(int argc, const char *argv[]) // init engine g_engine.init(); - boost::scoped_ptr menuState(new MenuState); - g_engine.changeState(menuState.get()); - Platform::showWindow(); - //Platform::hideMouseCursor(); + // state scope + { + boost::scoped_ptr menuState(new MenuState); + g_engine.changeState(menuState.get()); - // main loop, run everything - g_engine.run(); + Platform::showWindow(); + //Platform::hideMouseCursor(); - // terminate stuff - g_engine.terminate(); + // main loop, run everything + g_engine.run(); + + // terminate stuff + g_engine.terminate(); + } // save configurations before exiting saveConfigs();