From f5f99e34e4f0a64de71a4a6bf8c9406f6713c65e Mon Sep 17 00:00:00 2001 From: Aaron Griffith Date: Mon, 2 May 2011 18:30:19 -0400 Subject: [PATCH 1/4] added basic mineral overlay right now, it only highlights diamond ore --- setup.py | 2 +- src/overviewer.h | 2 +- src/rendermode-mineral.c | 104 +++++++++++++++++++++++++++++++++++++++ src/rendermodes.c | 1 + src/rendermodes.h | 7 +++ 5 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 src/rendermode-mineral.c 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__ */ From 4b7bc18926c77590e3c8bd70fb7e658465af20d1 Mon Sep 17 00:00:00 2001 From: Aaron Griffith Date: Mon, 2 May 2011 18:38:36 -0400 Subject: [PATCH 2/4] added more ores to mineral overlay --- src/rendermode-mineral.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/rendermode-mineral.c b/src/rendermode-mineral.c index a45bbf2..ab9cc95 100644 --- a/src/rendermode-mineral.c +++ b/src/rendermode-mineral.c @@ -24,7 +24,16 @@ struct OreColor { /* put more valuable ores first -- they take precedence */ static struct OreColor orecolors[] = { - {56 /* Diamond Ore */, 32, 230, 220, 200}, + {56 /* Diamond Ore */, 32, 230, 220, 200}, + + {14 /* Gold Ore */, 255, 234, 0, 200}, + {21 /* Lapis Lazuli */, 0, 23, 176, 200}, + + {15 /* Iron Ore */, 204, 204, 204, 200}, + {16 /* Coal Ore */, 54, 54, 54, 200}, + + {73 /* Redstone */, 186, 0, 0, 200}, + {74 /* Lit Redstone */, 186, 0, 0, 200}, /* end of list marker */ {0, 0, 0, 0, 0} From 1d858cd9e213fc1432eb7e762c10c1075d49343c Mon Sep 17 00:00:00 2001 From: Aaron Griffith Date: Mon, 2 May 2011 18:50:07 -0400 Subject: [PATCH 3/4] added alpha fading based on height --- src/rendermode-mineral.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/rendermode-mineral.c b/src/rendermode-mineral.c index ab9cc95..00aef49 100644 --- a/src/rendermode-mineral.c +++ b/src/rendermode-mineral.c @@ -19,24 +19,24 @@ struct OreColor { unsigned char blockid; - unsigned char r, g, b, a; + unsigned char r, g, b; }; /* put more valuable ores first -- they take precedence */ static struct OreColor orecolors[] = { - {56 /* Diamond Ore */, 32, 230, 220, 200}, + {56 /* Diamond Ore */, 32, 230, 220}, - {14 /* Gold Ore */, 255, 234, 0, 200}, - {21 /* Lapis Lazuli */, 0, 23, 176, 200}, + {14 /* Gold Ore */, 255, 234, 0}, + {21 /* Lapis Lazuli */, 0, 23, 176}, - {15 /* Iron Ore */, 204, 204, 204, 200}, - {16 /* Coal Ore */, 54, 54, 54, 200}, + {15 /* Iron Ore */, 204, 204, 204}, + {16 /* Coal Ore */, 54, 54, 54}, - {73 /* Redstone */, 186, 0, 0, 200}, - {74 /* Lit Redstone */, 186, 0, 0, 200}, + {73 /* Redstone */, 186, 0, 0}, + {74 /* Lit Redstone */, 186, 0, 0}, /* end of list marker */ - {0, 0, 0, 0, 0} + {0, 0, 0, 0} }; static void get_color(void *data, RenderState *state, @@ -47,7 +47,7 @@ static void get_color(void *data, RenderState *state, *a = 0; for (z = 0; z <= z_max; z++) { - int i, max_i = sizeof(orecolors) / sizeof(struct OreColor); + int i, tmp, 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++) { @@ -55,7 +55,10 @@ static void get_color(void *data, RenderState *state, *r = orecolors[i].r; *g = orecolors[i].g; *b = orecolors[i].b; - *a = orecolors[i].a; + + tmp = (128 - z_max + z) * 2 - 40; + *a = MIN(MAX(0, tmp), 255); + max_i = i; break; } From b1bb1975b58df6553b34f6b2d884b7cead57ee16 Mon Sep 17 00:00:00 2001 From: Aaron Griffith Date: Wed, 4 May 2011 14:08:59 -0400 Subject: [PATCH 4/4] added mossy cobble to mineral overlay, reordered priorities --- src/rendermode-mineral.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/rendermode-mineral.c b/src/rendermode-mineral.c index 00aef49..ea9b313 100644 --- a/src/rendermode-mineral.c +++ b/src/rendermode-mineral.c @@ -24,16 +24,17 @@ struct OreColor { /* put more valuable ores first -- they take precedence */ static struct OreColor orecolors[] = { + {48 /* Mossy Stone */, 31, 153, 9}, + {56 /* Diamond Ore */, 32, 230, 220}, - {14 /* Gold Ore */, 255, 234, 0}, {21 /* Lapis Lazuli */, 0, 23, 176}, + {14 /* Gold Ore */, 255, 234, 0}, {15 /* Iron Ore */, 204, 204, 204}, - {16 /* Coal Ore */, 54, 54, 54}, - {73 /* Redstone */, 186, 0, 0}, {74 /* Lit Redstone */, 186, 0, 0}, + {16 /* Coal Ore */, 54, 54, 54}, /* end of list marker */ {0, 0, 0, 0}