diff options
| author | Magnus Auvinen <magnus.auvinen@gmail.com> | 2007-11-18 12:03:59 +0000 |
|---|---|---|
| committer | Magnus Auvinen <magnus.auvinen@gmail.com> | 2007-11-18 12:03:59 +0000 |
| commit | dda8f6b33ee05acdf23883c91a0897a464b84061 (patch) | |
| tree | 7058eb2de2b55db067957f0a67bfcb1c43f5b93d /src/game/client/cl_skin.cpp | |
| parent | 7efefe27163548b7f61c516d6b650258a3c7d033 (diff) | |
| download | zcatch-dda8f6b33ee05acdf23883c91a0897a464b84061.tar.gz zcatch-dda8f6b33ee05acdf23883c91a0897a464b84061.zip | |
fixed skin selector and some other mindor stuff
Diffstat (limited to 'src/game/client/cl_skin.cpp')
| -rw-r--r-- | src/game/client/cl_skin.cpp | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/src/game/client/cl_skin.cpp b/src/game/client/cl_skin.cpp new file mode 100644 index 00000000..6e450b4f --- /dev/null +++ b/src/game/client/cl_skin.cpp @@ -0,0 +1,82 @@ +#include <string.h> +#include <stdio.h> +#include <engine/system.h> +#include <engine/interface.h> +#include "cl_skin.h" +#include "../math.h" + +enum +{ + MAX_SKINS=256, +}; + +static skin skins[MAX_SKINS] = {{-1, -1, {0}, {0}}}; +static int num_skins = 0; + +static void skinscan(const char *name, int is_dir, void *user) +{ + int l = strlen(name); + if(l < 4 || is_dir || num_skins == MAX_SKINS) + return; + if(strcmp(name+l-4, ".png") != 0) + return; + + char buf[512]; + sprintf(buf, "data/skins/%s", name); + IMAGE_INFO info; + if(!gfx_load_png(&info, buf)) + { + dbg_msg("game", "failed to load skin from %s", name); + return; + } + + skins[num_skins].org_texture = gfx_load_texture_raw(info.width, info.height, info.format, info.data); + + // create colorless version + unsigned char *d = (unsigned char *)info.data; + int step = info.format == IMG_RGBA ? 4 : 3; + + for(int i = 0; i < info.width*info.height; i++) + { + int v = (d[i*step]+d[i*step+1]+d[i*step+2])/3; + d[i*step] = v; + d[i*step+1] = v; + d[i*step+2] = v; + } + + skins[num_skins].color_texture = gfx_load_texture_raw(info.width, info.height, info.format, info.data); + mem_free(info.data); + + // set skin data + strncpy(skins[num_skins].name, name, min((int)sizeof(skins[num_skins].name),l-4)); + dbg_msg("game", "load skin %s", skins[num_skins].name); + num_skins++; +} + + +void skin_init() +{ + // load skins + fs_listdir("data/skins", skinscan, 0); +} + +int skin_num() +{ + return num_skins; +} + +const skin *skin_get(int index) +{ + return &skins[index%num_skins]; +} + +int skin_find(const char *name) +{ + for(int i = 0; i < num_skins; i++) + { + if(strcmp(skins[i].name, name) == 0) + return i; + } + return -1; +} + |