texture manager with weak ptr
This commit is contained in:
parent
4fa659c26a
commit
c40b827828
|
@ -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
|
||||
|
|
|
@ -14,8 +14,8 @@ Fonts::~Fonts()
|
|||
bool Fonts::load()
|
||||
{
|
||||
std::list<std::string> files = g_resources.getDirectoryFiles("fonts");
|
||||
for(std::list<std::string>::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;
|
||||
|
|
|
@ -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")) {
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
#include "prerequisites.h"
|
||||
#include "texture.h"
|
||||
|
||||
typedef boost::weak_ptr<Texture> TextureWeakPtr;
|
||||
|
||||
class TextureManager
|
||||
{
|
||||
public:
|
||||
|
@ -38,7 +40,7 @@ public:
|
|||
TexturePtr get(const std::string& textureFile);
|
||||
|
||||
private:
|
||||
typedef std::map<std::string, TexturePtr> TexturesMap;
|
||||
typedef std::map<std::string, TextureWeakPtr > TexturesMap;
|
||||
TexturesMap m_texturesMap;
|
||||
};
|
||||
|
||||
|
|
|
@ -105,6 +105,9 @@ int main(int argc, const char *argv[])
|
|||
|
||||
// init engine
|
||||
g_engine.init();
|
||||
|
||||
// state scope
|
||||
{
|
||||
boost::scoped_ptr<MenuState> menuState(new MenuState);
|
||||
g_engine.changeState(menuState.get());
|
||||
|
||||
|
@ -116,6 +119,7 @@ int main(int argc, const char *argv[])
|
|||
|
||||
// terminate stuff
|
||||
g_engine.terminate();
|
||||
}
|
||||
|
||||
// save configurations before exiting
|
||||
saveConfigs();
|
||||
|
|
Loading…
Reference in New Issue