ddnet/src/game/client/gc_map_image.cpp

125 lines
2.8 KiB
C++
Raw Normal View History

2007-11-25 19:42:40 +00:00
/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
2007-12-15 10:24:49 +00:00
#include <engine/e_system.h>
#include <engine/e_interface.h>
#include <game/g_mapitems.h>
#include "gc_map_image.h"
2007-05-22 15:03:32 +00:00
static int map_textures[64] = {0};
static int count = 0;
2007-07-22 11:46:25 +00:00
/*
static void calc_mipmaps(void *data_in, unsigned width, unsigned height, void *data_out)
{
unsigned char *src = (unsigned char*)data_in;
unsigned char *dst = (unsigned char*)data_out;
unsigned mip_w = width;
unsigned mip_h = height;
unsigned prev_w;
unsigned prev_h;
// Highest level - no mod
for(unsigned x = 0; x < mip_w; x++)
{
for(unsigned y = 0; y < mip_h; y++)
{
unsigned i = (y * mip_w + x)<<2;
for(unsigned j = 0; j < 4; j++)
dst[i+j] = src[i+j];
}
}
src = dst;
dst += mip_w * mip_h * 4;
prev_w = mip_w;
prev_h = mip_h;
mip_w = mip_w>>1;
mip_h = mip_h>>1;
while(mip_w > 0 && mip_h > 0)
{
for(unsigned x = 0; x < mip_w; x++)
{
for(unsigned y = 0; y < mip_h; y++)
{
unsigned i = (y * mip_w + x)<<2;
unsigned r = 0;
unsigned g = 0;
unsigned b = 0;
unsigned a = 0;
2007-05-22 15:03:32 +00:00
2007-07-22 11:46:25 +00:00
r += src[(((y<<1) * prev_w + (x<<1))<<2)];
g += src[(((y<<1) * prev_w + (x<<1))<<2)+1];
b += src[(((y<<1) * prev_w + (x<<1))<<2)+2];
a += src[(((y<<1) * prev_w + (x<<1))<<2)+3];
r += src[(((y<<1) * prev_w + ((x+1)<<1))<<2)];
g += src[(((y<<1) * prev_w + ((x+1)<<1))<<2)+1];
b += src[(((y<<1) * prev_w + ((x+1)<<1))<<2)+2];
a += src[(((y<<1) * prev_w + ((x+1)<<1))<<2)+3];
r += src[((((y+1)<<1) * prev_w + (x<<1))<<2)];
g += src[((((y+1)<<1) * prev_w + (x<<1))<<2)+1];
b += src[((((y+1)<<1) * prev_w + (x<<1))<<2)+2];
a += src[((((y+1)<<1) * prev_w + (x<<1))<<2)+3];
r += src[((((y+1)<<1) * prev_w + ((x+1)<<1))<<2)];
g += src[((((y+1)<<1) * prev_w + ((x+1)<<1))<<2)+1];
b += src[((((y+1)<<1) * prev_w + ((x+1)<<1))<<2)+2];
a += src[((((y+1)<<1) * prev_w + ((x+1)<<1))<<2)+3];
dst[i] = r>>2;
dst[i+1] = g>>2;
dst[i+2] = b>>2;
dst[i+3] = a>>2;
}
}
src = dst;
dst = dst + mip_w*mip_h*4;
prev_w = mip_w;
prev_h = mip_h;
mip_w = mip_w>>1;
mip_h = mip_h>>1;
}
}
2007-07-22 09:15:34 +00:00
extern int DEBUGTEST_MAPIMAGE;
*/
2007-07-22 09:15:34 +00:00
2007-05-22 15:03:32 +00:00
int img_init()
{
int start, count;
map_get_type(MAPITEMTYPE_IMAGE, &start, &count);
dbg_msg("image", "start=%d count=%d", start, count);
2007-05-22 15:03:32 +00:00
for(int i = 0; i < 64; i++)
{
if(map_textures[i])
{
gfx_unload_texture(map_textures[i]);
map_textures[i] = 0;
}
}
2007-07-22 11:46:25 +00:00
//void *data_res = (void*)mem_alloc(1024*1024*4*2, 16);
2007-05-22 15:03:32 +00:00
for(int i = 0; i < count; i++)
{
MAPITEM_IMAGE *img = (MAPITEM_IMAGE *)map_get_item(start+i, 0, 0);
2007-05-22 15:03:32 +00:00
void *data = map_get_data(img->image_data);
2008-01-11 16:48:34 +00:00
map_textures[i] = gfx_load_texture_raw(img->width, img->height, IMG_RGBA, data, IMG_RGBA);
map_unload_data(img->image_data);
2007-05-22 15:03:32 +00:00
}
2007-07-22 11:46:25 +00:00
2007-05-22 15:03:32 +00:00
return count;
}
int img_num()
{
return count;
}
int img_get(int index)
{
return map_textures[index];
}