bug fix to properly initialize textures dynamically loaded when loading a faction.

This commit is contained in:
Mark Vejvoda 2010-04-05 19:38:50 +00:00
parent ab1c302107
commit 1fe29664c9
7 changed files with 124 additions and 12 deletions

View File

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

View File

@ -45,6 +45,9 @@ private:
private:
Logger();
~Logger();
void cleanupLoadingTexture();
public:
static Logger & getInstance();

View File

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

View File

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

View File

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

View File

@ -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 <vector>
#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<Texture*> 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

View File

@ -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; i<textures.size(); ++i){
textures[i]->init(textureFilter, maxAnisotropy);