ddnet/src/game/client/components/mapimages.cpp

64 lines
1.7 KiB
C++
Raw Normal View History

2010-11-20 10:37:14 +00:00
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
2010-05-29 07:25:38 +00:00
#include <engine/graphics.h>
#include <engine/map.h>
2010-10-06 21:07:35 +00:00
#include <engine/storage.h>
2010-05-29 07:25:38 +00:00
#include <game/client/component.h>
#include <game/mapitems.h>
2008-09-01 05:54:00 +00:00
2010-05-29 07:25:38 +00:00
#include "mapimages.h"
2008-09-01 05:54:00 +00:00
2010-05-29 07:25:38 +00:00
CMapImages::CMapImages()
2008-09-01 05:54:00 +00:00
{
2010-05-29 07:25:38 +00:00
m_Count = 0;
2011-03-16 12:48:16 +00:00
m_EntitiesTextures = -1;
2008-09-01 05:54:00 +00:00
}
2010-05-29 07:25:38 +00:00
void CMapImages::OnMapLoad()
2008-09-01 05:54:00 +00:00
{
2010-05-29 07:25:38 +00:00
IMap *pMap = Kernel()->RequestInterface<IMap>();
2008-09-01 05:54:00 +00:00
// unload all textures
2010-05-29 07:25:38 +00:00
for(int i = 0; i < m_Count; i++)
2008-09-01 05:54:00 +00:00
{
2010-05-29 07:25:38 +00:00
Graphics()->UnloadTexture(m_aTextures[i]);
m_aTextures[i] = -1;
2008-09-01 05:54:00 +00:00
}
2010-05-29 07:25:38 +00:00
m_Count = 0;
2008-09-01 05:54:00 +00:00
2010-05-29 07:25:38 +00:00
int Start;
pMap->GetType(MAPITEMTYPE_IMAGE, &Start, &m_Count);
2008-09-01 05:54:00 +00:00
// load new textures
2010-05-29 07:25:38 +00:00
for(int i = 0; i < m_Count; i++)
2008-09-01 05:54:00 +00:00
{
2010-05-29 07:25:38 +00:00
m_aTextures[i] = 0;
2008-09-01 05:54:00 +00:00
2010-05-29 07:25:38 +00:00
CMapItemImage *pImg = (CMapItemImage *)pMap->GetItem(Start+i, 0, 0);
if(pImg->m_External)
2008-09-01 05:54:00 +00:00
{
2010-05-29 07:25:38 +00:00
char Buf[256];
char *pName = (char *)pMap->GetData(pImg->m_ImageName);
str_format(Buf, sizeof(Buf), "mapres/%s.png", pName);
2010-10-06 21:07:35 +00:00
m_aTextures[i] = Graphics()->LoadTexture(Buf, IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
2008-09-01 05:54:00 +00:00
}
else
{
2010-05-29 07:25:38 +00:00
void *pData = pMap->GetData(pImg->m_ImageData);
m_aTextures[i] = Graphics()->LoadTextureRaw(pImg->m_Width, pImg->m_Height, CImageInfo::FORMAT_RGBA, pData, CImageInfo::FORMAT_RGBA, 0);
pMap->UnloadData(pImg->m_ImageData);
2008-09-01 05:54:00 +00:00
}
}
}
2011-03-16 12:48:16 +00:00
int CMapImages::GetEntities()
{
if(m_EntitiesTextures == -1)
{
m_EntitiesTextures = Graphics()->LoadTexture("editor/entities_clear.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
if(m_EntitiesTextures == -1)
m_EntitiesTextures = Graphics()->LoadTexture("editor/entities.png", IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, 0);
}
return m_EntitiesTextures;
}