2009-10-27 14:38:53 +00:00
|
|
|
#include <engine/client/graphics.h>
|
2008-09-01 05:54:00 +00:00
|
|
|
#include <game/client/component.hpp>
|
|
|
|
#include <game/mapitems.hpp>
|
|
|
|
|
|
|
|
#include "mapimages.hpp"
|
|
|
|
|
|
|
|
MAPIMAGES::MAPIMAGES()
|
|
|
|
{
|
|
|
|
count = 0;
|
|
|
|
}
|
|
|
|
|
2008-10-06 18:05:01 +00:00
|
|
|
void MAPIMAGES::on_mapload()
|
2008-09-01 05:54:00 +00:00
|
|
|
{
|
|
|
|
// unload all textures
|
|
|
|
for(int i = 0; i < count; i++)
|
|
|
|
{
|
2009-10-27 14:38:53 +00:00
|
|
|
Graphics()->UnloadTexture(textures[i]);
|
2008-09-01 05:54:00 +00:00
|
|
|
textures[i] = -1;
|
|
|
|
}
|
|
|
|
count = 0;
|
|
|
|
|
|
|
|
int start;
|
|
|
|
map_get_type(MAPITEMTYPE_IMAGE, &start, &count);
|
|
|
|
|
|
|
|
// load new textures
|
|
|
|
for(int i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
textures[i] = 0;
|
|
|
|
|
|
|
|
MAPITEM_IMAGE *img = (MAPITEM_IMAGE *)map_get_item(start+i, 0, 0);
|
|
|
|
if(img->external)
|
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
char *name = (char *)map_get_data(img->image_name);
|
2008-10-01 17:16:22 +00:00
|
|
|
str_format(buf, sizeof(buf), "mapres/%s.png", name);
|
2009-10-27 14:38:53 +00:00
|
|
|
textures[i] = Graphics()->LoadTexture(buf, IMG_AUTO, 0);
|
2008-09-01 05:54:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
void *data = map_get_data(img->image_data);
|
2009-10-27 14:38:53 +00:00
|
|
|
textures[i] = Graphics()->LoadTextureRaw(img->width, img->height, IMG_RGBA, data, IMG_RGBA, 0);
|
2008-09-01 05:54:00 +00:00
|
|
|
map_unload_data(img->image_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|