Permalink
Browse files

Create a CTextureMap in the bundler rather than in the manager - shou…

…ld allow for multiple texture names per CTextureMap
  • Loading branch information...
Jonathan Marshall
Jonathan Marshall committed May 31, 2012
1 parent 9b7d069 commit ffd3d734ef5aec9823d693bab848d1e77ed5313c
@@ -56,29 +56,27 @@ void CTextureBundle::GetTexturesFromPath(const CStdString &path, std::vector<CSt
}
}
-bool CTextureBundle::LoadTexture(const CStdString& Filename, CBaseTexture** ppTexture,
- int &width, int &height)
+bool CTextureBundle::LoadTexture(const CStdString& Filename, CTextureMap** ppTexture)
{
if (m_useXBT)
{
- return m_tbXBT.LoadTexture(Filename, ppTexture, width, height);
+ return m_tbXBT.LoadTexture(Filename, ppTexture);
}
else
{
return false;
}
}
-int CTextureBundle::LoadAnim(const CStdString& Filename, CBaseTexture*** ppTextures,
- int &width, int &height, int& nLoops, int** ppDelays)
+bool CTextureBundle::LoadAnim(const CStdString& Filename, CTextureMap** ppTexture)
{
if (m_useXBT)
{
- return m_tbXBT.LoadAnim(Filename, ppTextures, width, height, nLoops, ppDelays);
+ return m_tbXBT.LoadAnim(Filename, ppTexture);
}
else
{
- return 0;
+ return false;
}
}
@@ -37,9 +37,9 @@ class CTextureBundle
void GetTexturesFromPath(const CStdString &path, std::vector<CStdString> &textures);
static CStdString Normalize(const CStdString &name);
- bool LoadTexture(const CStdString& Filename, CBaseTexture** ppTexture, int &width, int &height);
+ bool LoadTexture(const CStdString& Filename, CTextureMap** ppTexture);
- int LoadAnim(const CStdString& Filename, CBaseTexture*** ppTextures, int &width, int &height, int& nLoops, int** ppDelays);
+ bool LoadAnim(const CStdString& Filename, CTextureMap** ppTexture);
private:
CTextureBundleXBT m_tbXBT;
@@ -23,6 +23,7 @@
#include "system.h"
#include "TextureBundleXBT.h"
#include "Texture.h"
+#include "TextureManager.h"
#include "GraphicContext.h"
#include "utils/log.h"
#include "addons/Skin.h"
@@ -132,8 +133,7 @@ void CTextureBundleXBT::GetTexturesFromPath(const CStdString &path, std::vector<
}
}
-bool CTextureBundleXBT::LoadTexture(const CStdString& Filename, CBaseTexture** ppTexture,
- int &width, int &height)
+bool CTextureBundleXBT::LoadTexture(const CStdString& Filename, CTextureMap** texture)
{
CStdString name = Normalize(Filename);
@@ -145,19 +145,19 @@ bool CTextureBundleXBT::LoadTexture(const CStdString& Filename, CBaseTexture** p
return false;
CXBTFFrame& frame = file->GetFrames().at(0);
- if (!ConvertFrameToTexture(Filename, frame, ppTexture))
+ CBaseTexture *pTexture = NULL;
+ if (!ConvertFrameToTexture(Filename, frame, &pTexture))
{
return false;
}
- width = frame.GetWidth();
- height = frame.GetHeight();
+ *texture = new CTextureMap(Filename, frame.GetWidth(), frame.GetHeight(), 0);
+ (*texture)->Add(pTexture, 100);
return true;
}
-int CTextureBundleXBT::LoadAnim(const CStdString& Filename, CBaseTexture*** ppTextures,
- int &width, int &height, int& nLoops, int** ppDelays)
+bool CTextureBundleXBT::LoadAnim(const CStdString& Filename, CTextureMap **texture)
{
CStdString name = Normalize(Filename);
@@ -168,27 +168,21 @@ int CTextureBundleXBT::LoadAnim(const CStdString& Filename, CBaseTexture*** ppTe
if (file->GetFrames().size() == 0)
return false;
- size_t nTextures = file->GetFrames().size();
- *ppTextures = new CBaseTexture*[nTextures];
- *ppDelays = new int[nTextures];
-
- for (size_t i = 0; i < nTextures; i++)
+ *texture = new CTextureMap(Filename, file->GetFrames().at(0).GetWidth(), file->GetFrames().at(0).GetHeight(), file->GetLoop());
+ for (size_t i = 0; i < file->GetFrames().size(); i++)
{
CXBTFFrame& frame = file->GetFrames().at(i);
- if (!ConvertFrameToTexture(Filename, frame, &((*ppTextures)[i])))
+ CBaseTexture *pTexture = NULL;
+ if (!ConvertFrameToTexture(Filename, frame, &pTexture))
{
+ delete texture;
return false;
}
-
- (*ppDelays)[i] = frame.GetDuration();
+ (*texture)->Add(pTexture, frame.GetDuration());
}
- width = file->GetFrames().at(0).GetWidth();
- height = file->GetFrames().at(0).GetHeight();
- nLoops = file->GetLoop();
-
- return nTextures;
+ return true;
}
bool CTextureBundleXBT::ConvertFrameToTexture(const CStdString& name, CXBTFFrame& frame, CBaseTexture** ppTexture)
@@ -26,6 +26,7 @@
#include "XBTFReader.h"
class CBaseTexture;
+class CTextureMap;
class CTextureBundleXBT
{
@@ -39,11 +40,9 @@ class CTextureBundleXBT
void GetTexturesFromPath(const CStdString &path, std::vector<CStdString> &textures);
static CStdString Normalize(const CStdString &name);
- bool LoadTexture(const CStdString& Filename, CBaseTexture** ppTexture,
- int &width, int &height);
+ bool LoadTexture(const CStdString& Filename, CTextureMap** ppTexture);
- int LoadAnim(const CStdString& Filename, CBaseTexture*** ppTextures,
- int &width, int &height, int& nLoops, int** ppDelays);
+ bool LoadAnim(const CStdString& Filename, CTextureMap** ppTexture);
private:
bool OpenBundle();
@@ -324,24 +324,11 @@ int CGUITextureManager::Load(const CStdString& strTextureName, bool checkBundleO
if (bundle >= 0)
{
- CBaseTexture **pTextures;
- int nLoops = 0, width = 0, height = 0;
- int* Delay;
- int nImages = m_TexBundle[bundle].LoadAnim(strTextureName, &pTextures, width, height, nLoops, &Delay);
- if (!nImages)
+ if (!m_TexBundle[bundle].LoadAnim(strTextureName, &pMap))
{
CLog::Log(LOGERROR, "Texture manager unable to load bundled file: %s", strTextureName.c_str());
return 0;
}
-
- pMap = new CTextureMap(strTextureName, width, height, nLoops);
- for (int iImage = 0; iImage < nImages; ++iImage)
- {
- pMap->Add(pTextures[iImage], Delay[iImage]);
- }
-
- delete [] pTextures;
- delete [] Delay;
}
else
{
@@ -393,30 +380,31 @@ int CGUITextureManager::Load(const CStdString& strTextureName, bool checkBundleO
return 1;
} // of if (strPath.Right(4).ToLower()==".gif")
- CBaseTexture *pTexture = NULL;
+ CTextureMap *texture = NULL;
int width = 0, height = 0;
if (bundle >= 0)
{
- if (FAILED(m_TexBundle[bundle].LoadTexture(strTextureName, &pTexture, width, height)))
+ if (FAILED(m_TexBundle[bundle].LoadTexture(strTextureName, &texture)))
{
CLog::Log(LOGERROR, "Texture manager unable to load bundled file: %s", strTextureName.c_str());
return 0;
}
}
else
{
- pTexture = new CTexture();
+ CTexture *pTexture = new CTexture();
if(!pTexture->LoadFromFile(strPath))
return 0;
width = pTexture->GetWidth();
height = pTexture->GetHeight();
+
+ texture = new CTextureMap(strTextureName, width, height, 0);
+ texture->Add(pTexture, 100);
}
- if (!pTexture) return 0;
+ if (!texture) return 0;
- CTextureMap* pMap = new CTextureMap(strTextureName, width, height, 0);
- pMap->Add(pTexture, 100);
- m_vecTextures.push_back(pMap);
+ m_vecTextures.push_back(texture);
#ifdef _DEBUG_TEXTURES
int64_t end, freq;

0 comments on commit ffd3d73

Please sign in to comment.