Esempio n. 1
0
TextureManager::TextureManager()
{
	CacheTexture( "cat", "../Assets/cat.png" );
	CacheTexture( "mouse", "../Assets/mouse.png" );
	CacheTexture( "yarn", "../Assets/yarn.png" );
	
}
Esempio n. 2
0
LTBOOL CScreenSpriteMgr::CacheSprite(CScreenSprite * pSprite, char * pFile)
{
	ILTStream * pStream;
	char buf[1024];

	pSprite->m_pName = strdup(pFile);

	g_pLTClient->OpenFile(pFile, &pStream);
	if (pStream)
	{
		int nFrames;
		int nFrameRate;
		int bTransparency;
		int bTranslucency;
		int iChromakey;

		pStream->Read(&nFrames, 4);
		pSprite->m_nFrames = nFrames;

		pStream->Read(&nFrameRate, 4);
		pSprite->m_nFrameRate = nFrameRate;
		pSprite->m_fOneFrameTime = 1.0f / (float)nFrameRate;

		pStream->Read(&bTransparency, 4);
		pStream->Read(&bTranslucency, 4);
		pStream->Read(&iChromakey, 4);

		if (nFrames < 1 && nFrames > 64)
		{
			// We have an error.
			// FIXME report it
			pStream->Release();
			return LTFALSE;
		}
		for (int i = 0; i < nFrames; i++)
		{
			short iLen;
			pStream->Read(&iLen, 2);
			if (iLen < 1 || iLen > 1023)
			{
				// We have an error.
				// FIXME report it
				pStream->Release();
				return LTFALSE;
			}
			memset(buf,0,1024);
			pStream->Read(&buf, iLen);

			int iFrameID = CacheTexture(buf);
			pSprite->m_FrameArray.push_back(m_FrameArray[iFrameID]);
		}
		pStream->Release();

		return LTTRUE;
	}
	return (LTFALSE);
}
Esempio n. 3
0
bool CTextureCacheJob::DoWork()
{
  if (ShouldCancel(0, 0))
    return false;
  if (ShouldCancel(1, 0)) // HACK: second check is because we cancel the job in the first callback, but we don't detect it
    return false;         //       until the second

  // check whether we need cache the job anyway
  bool needsRecaching = false;
  CStdString path(CTextureCache::Get().CheckCachedImage(m_url, false, needsRecaching));
  if (!path.IsEmpty() && !needsRecaching)
    return false;
  return CacheTexture();
}
Esempio n. 4
0
bool CScreenSpriteMgr::GiveSpriteResources(CScreenSprite * pSprite, char * pFile)
{
/*
	if (!m_bInitialized)
		Init();

	// Do a quick check to see if this sprite already exists in the array
	ScreenSpriteArray::iterator iter = m_SpriteArray.begin();
	while (iter != m_SpriteArray.end())
	{
		if (pSprite == *iter)
			return LTTRUE;
		iter++;
	}
*/
	// See if it's a texture (DTX)
	if (strnicmp(&pFile[strlen(pFile) - 4], ".dtx", 4) == 0)
	{
		int iFrameID = CacheTexture(pFile);
		if (iFrameID == -1)
			return (LTFALSE);

		pSprite->m_FrameArray.push_back(m_FrameArray[iFrameID]);
		pSprite->m_pName = strdup(pFile);

//		m_SpriteArray.push_back(pSprite);
		return LTTRUE;
	}

	// See if it's an SPR file
	if (strnicmp(&pFile[strlen(pFile) - 4], ".spr", 4) == 0)
	{
		// Cache the textures
		if (CacheSprite(pSprite, pFile))
		{
			// then add it to the array
//			m_SpriteArray.push_back(pSprite);
			return (LTTRUE);
		}
	}

	return LTFALSE;
}