diff --git a/source/glest_game/facilities/logger.cpp b/source/glest_game/facilities/logger.cpp index 8d569584..73fe10e9 100644 --- a/source/glest_game/facilities/logger.cpp +++ b/source/glest_game/facilities/logger.cpp @@ -16,11 +16,13 @@ #include "core_data.h" #include "metrics.h" #include "lang.h" -#include "leak_dumper.h" #include "graphics_interface.h" +#include "leak_dumper.h" + using namespace std; using namespace Shared::Graphics; +using namespace Shared::Util; namespace Glest{ namespace Game{ @@ -37,6 +39,18 @@ Logger::Logger(){ loadingTexture=NULL; } +Logger::~Logger(){ + cleanupLoadingTexture(); +} + +void Logger::cleanupLoadingTexture() { + if(loadingTexture!=NULL) + { + delete loadingTexture; + loadingTexture=NULL; + } +} + Logger & Logger::getInstance(){ static Logger logger; return logger; @@ -71,13 +85,9 @@ void Logger::clear(){ void Logger::loadLoadingScreen(string filepath){ - Renderer &renderer= Renderer::getInstance(); - - if(loadingTexture!=NULL) - { - delete loadingTexture; - loadingTexture=NULL; - } + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + cleanupLoadingTexture(); if(filepath=="") { @@ -85,9 +95,15 @@ void Logger::loadLoadingScreen(string filepath){ } else { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] filepath = [%s]\n",__FILE__,__FUNCTION__,__LINE__,filepath.c_str()); + loadingTexture=GraphicsInterface::getInstance().getFactory()->newTexture2D(); + //loadingTexture = renderer.newTexture2D(rsGlobal); loadingTexture->setMipmap(false); loadingTexture->getPixmap()->load(filepath); + + Renderer &renderer= Renderer::getInstance(); + renderer.initTexture(rsGlobal,loadingTexture); } } diff --git a/source/glest_game/facilities/logger.h b/source/glest_game/facilities/logger.h index da885229..bcadbf16 100644 --- a/source/glest_game/facilities/logger.h +++ b/source/glest_game/facilities/logger.h @@ -45,6 +45,9 @@ private: private: Logger(); + ~Logger(); + + void cleanupLoadingTexture(); public: static Logger & getInstance(); diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 70f95ebf..89727262 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -116,9 +116,16 @@ void Game::load(){ const string path = pathList[idx]+ "/" +techName+ "/"+ "factions"+ "/"+ gameSettings.getFactionTypeName(i); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] possible loading screen dir '%s'\n",__FILE__,__FUNCTION__,path.c_str()); if(isdir(path.c_str()) == true) { - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] found loading screen '%s'\n",__FILE__,__FUNCTION__,path.c_str()); - logger.loadLoadingScreen(path+"/"+"loading_screen.tga"); - break; + string factionLogo = path + "/" + "loading_screen.tga"; + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] looking for loading screen '%s'\n",__FILE__,__FUNCTION__,factionLogo.c_str()); + + if(fileExists(factionLogo) == true) { + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] found loading screen '%s'\n",__FILE__,__FUNCTION__,factionLogo.c_str()); + + logger.loadLoadingScreen(factionLogo); + break; + } } } break; diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 741ff762..ee39c582 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -404,6 +404,14 @@ void Renderer::reloadResources(){ // ==================== engine interface ==================== +void Renderer::initTexture(ResourceScope rs, Texture *texture) { + textureManager[rs]->initTexture(texture); +} + +void Renderer::endTexture(ResourceScope rs, Texture **texture) { + textureManager[rs]->endTexture(texture); +} + Model *Renderer::newModel(ResourceScope rs){ return modelManager[rs]->newModel(); } diff --git a/source/glest_game/graphics/renderer.h b/source/glest_game/graphics/renderer.h index 6fafeb30..063a7b43 100644 --- a/source/glest_game/graphics/renderer.h +++ b/source/glest_game/graphics/renderer.h @@ -29,6 +29,7 @@ namespace Glest{ namespace Game{ +using Shared::Graphics::Texture; using Shared::Graphics::Texture2D; using Shared::Graphics::Texture3D; using Shared::Graphics::ModelRenderer; @@ -55,6 +56,7 @@ class MainMenu; class Console; class MenuBackground; class ChatManager; +class Texture; enum ResourceScope{ rsGlobal, @@ -199,6 +201,9 @@ public: void reloadResources(); //engine interface + void initTexture(ResourceScope rs, Texture *texture); + void endTexture(ResourceScope rs, Texture **texture); + Model *newModel(ResourceScope rs); Texture2D *newTexture2D(ResourceScope rs); Texture3D *newTexture3D(ResourceScope rs); diff --git a/source/shared_lib/include/graphics/texture_manager.h b/source/shared_lib/include/graphics/texture_manager.h new file mode 100644 index 00000000..2c1925ec --- /dev/null +++ b/source/shared_lib/include/graphics/texture_manager.h @@ -0,0 +1,59 @@ +// ============================================================== +// This file is part of Glest Shared Library (www.glest.org) +// +// Copyright (C) 2001-2008 Martio Figueroa +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== + +#ifndef _SHARED_GRAPHICS_TEXTUREMANAGER_H_ +#define _SHARED_GRAPHICS_TEXTUREMANAGER_H_ + +#include + +#include "texture.h" + +using std::vector; + +namespace Shared{ namespace Graphics{ + +// ===================================================== +// class TextureManager +// ===================================================== + +//manages textures, creation on request and deletion on destruction +class TextureManager{ +protected: + typedef vector TextureContainer; + +protected: + TextureContainer textures; + + Texture::Filter textureFilter; + int maxAnisotropy; + +public: + TextureManager(); + ~TextureManager(); + void init(); + void end(); + + void setFilter(Texture::Filter textureFilter); + void setMaxAnisotropy(int maxAnisotropy); + void initTexture(Texture *texture); + void endTexture(Texture **texture); + + Texture *getTexture(const string &path); + Texture1D *newTexture1D(); + Texture2D *newTexture2D(); + Texture3D *newTexture3D(); + TextureCube *newTextureCube(); +}; + + +}}//end namespace + +#endif diff --git a/source/shared_lib/sources/graphics/texture_manager.cpp b/source/shared_lib/sources/graphics/texture_manager.cpp index 17a791d8..3c4900ba 100644 --- a/source/shared_lib/sources/graphics/texture_manager.cpp +++ b/source/shared_lib/sources/graphics/texture_manager.cpp @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest Shared Library (www.glest.org) // -// Copyright (C) 2001-2008 Martiņo Figueroa +// Copyright (C) 2001-2008 Martio Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -33,6 +33,20 @@ TextureManager::~TextureManager(){ end(); } +void TextureManager::initTexture(Texture *texture) { + if(texture != NULL) { + texture->init(textureFilter, maxAnisotropy); + } +} + +void TextureManager::endTexture(Texture **texture) { + if(texture != NULL && *texture != NULL) { + (*texture)->end(); + delete (*texture); + *texture = NULL; + } +} + void TextureManager::init(){ for(int i=0; iinit(textureFilter, maxAnisotropy);