diff --git a/setup.py b/setup.py index 497b5ac..284795d 100644 --- a/setup.py +++ b/setup.py @@ -55,7 +55,7 @@ except: pil_include = [] # used to figure out what files to compile -render_modes = ['normal', 'overlay', 'lighting', 'night', 'spawn', 'cave'] +render_modes = ['normal', 'overlay', 'lighting', 'night', 'spawn', 'cave', 'mineral'] c_overviewer_files = ['src/main.c', 'src/composite.c', 'src/iterate.c', 'src/endian.c', 'src/rendermodes.c'] c_overviewer_files += map(lambda mode: 'src/rendermode-%s.c' % (mode,), render_modes) diff --git a/src/overviewer.h b/src/overviewer.h index 55243a5..05f657c 100644 --- a/src/overviewer.h +++ b/src/overviewer.h @@ -26,7 +26,7 @@ // increment this value if you've made a change to the c extesion // and want to force users to rebuild -#define OVERVIEWER_EXTENSION_VERSION 5 +#define OVERVIEWER_EXTENSION_VERSION 6 /* Python PIL, and numpy headers */ #include diff --git a/src/rendermode-mineral.c b/src/rendermode-mineral.c new file mode 100644 index 0000000..a45bbf2 --- /dev/null +++ b/src/rendermode-mineral.c @@ -0,0 +1,104 @@ +/* + * This file is part of the Minecraft Overviewer. + * + * Minecraft Overviewer is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as published + * by the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Minecraft Overviewer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with the Overviewer. If not, see . + */ + +#include "overviewer.h" + +struct OreColor { + unsigned char blockid; + unsigned char r, g, b, a; +}; + +/* put more valuable ores first -- they take precedence */ +static struct OreColor orecolors[] = { + {56 /* Diamond Ore */, 32, 230, 220, 200}, + + /* end of list marker */ + {0, 0, 0, 0, 0} +}; + +static void get_color(void *data, RenderState *state, + unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a) { + + int x = state->x, y = state->y, z_max = state->z, z; + //RenderModeMineral* self = (RenderModeMineral *)data; + *a = 0; + + for (z = 0; z <= z_max; z++) { + int i, max_i = sizeof(orecolors) / sizeof(struct OreColor); + unsigned char blockid = getArrayByte3D(state->blocks, x, y, z); + + for (i = 0; i < max_i && orecolors[i].blockid != 0; i++) { + if (orecolors[i].blockid == blockid) { + *r = orecolors[i].r; + *g = orecolors[i].g; + *b = orecolors[i].b; + *a = orecolors[i].a; + max_i = i; + break; + } + } + } +} + +static int +rendermode_mineral_start(void *data, RenderState *state) { + RenderModeMineral* self; + + /* first, chain up */ + int ret = rendermode_overlay.start(data, state); + if (ret != 0) + return ret; + + /* now do custom initializations */ + self = (RenderModeMineral *)data; + + /* setup custom color */ + self->parent.get_color = get_color; + + return 0; +} + +static void +rendermode_mineral_finish(void *data, RenderState *state) { + /* first free all *our* stuff */ + //RenderModeMineral* self = (RenderModeMineral *)data; + + /* now, chain up */ + rendermode_overlay.finish(data, state); +} + +static int +rendermode_mineral_occluded(void *data, RenderState *state) { + /* no special occlusion here */ + return rendermode_overlay.occluded(data, state); +} + +static void +rendermode_mineral_draw(void *data, RenderState *state, PyObject *src, PyObject *mask) { + /* draw normally */ + rendermode_overlay.draw(data, state, src, mask); +} + +RenderModeInterface rendermode_mineral = { + "mineral", "draws a colored overlay showing where ores are located", + &rendermode_overlay, + sizeof(RenderModeMineral), + rendermode_mineral_start, + rendermode_mineral_finish, + rendermode_mineral_occluded, + rendermode_mineral_draw, +}; diff --git a/src/rendermodes.c b/src/rendermodes.c index 43658e1..2d1f8d1 100644 --- a/src/rendermodes.c +++ b/src/rendermodes.c @@ -27,6 +27,7 @@ static RenderModeInterface *render_modes[] = { &rendermode_night, &rendermode_spawn, &rendermode_cave, + &rendermode_mineral, NULL }; diff --git a/src/rendermodes.h b/src/rendermodes.h index fd0b479..9e731b1 100644 --- a/src/rendermodes.h +++ b/src/rendermodes.h @@ -156,4 +156,11 @@ typedef struct { } RenderModeCave; extern RenderModeInterface rendermode_cave; +/* MINERAL */ +typedef struct { + /* inherits from overlay */ + RenderModeOverlay parent; +} RenderModeMineral; +extern RenderModeInterface rendermode_mineral; + #endif /* __RENDERMODES_H_INCLUDED__ */