From 5184c8d3212f7e4850adfb4ab0c784a368f9113a Mon Sep 17 00:00:00 2001 From: Adam Novak Date: Tue, 24 Apr 2012 17:04:51 -0700 Subject: [PATCH 1/6] Added and documented the "exposed" render mode primitive. --- CONTRIBUTORS.rst | 1 + docs/config.rst | 8 +++ overviewer_core/rendermodes.py | 6 ++ overviewer_core/src/primitives/exposed.c | 91 ++++++++++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 overviewer_core/src/primitives/exposed.c diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index ff8eb83..6c8da67 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -69,6 +69,7 @@ feature. * Ryan McCue * Zach McCullough * Mike + * Adam Novak * Morlok8k * Richard Pastrick * Ryan Rector diff --git a/docs/config.rst b/docs/config.rst index 042ae0d..ef4dbed 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -611,6 +611,14 @@ Depth max highest level of blocks to render. Default: 255 +Exposed + Only renders blocks that are exposed (adjacent to a transparent block). + + **Options** + + mode + when set to 1, inverts the render mode, only drawing unexposed blocks. Default: 0 + EdgeLines Draw edge lines on the back side of blocks, to help distinguish them from the background. diff --git a/overviewer_core/rendermodes.py b/overviewer_core/rendermodes.py index e1adc9c..2f5d3c8 100644 --- a/overviewer_core/rendermodes.py +++ b/overviewer_core/rendermodes.py @@ -62,6 +62,12 @@ class Depth(RenderPrimitive): "min": ("lowest level of blocks to render", 0), "max": ("highest level of blocks to render", 255), } + +class Exposed(RenderPrimitive): + name = "exposed" + options = { + "mode": ("0 = exposed blocks only, 1 = unexposed blocks only", 0), + } class EdgeLines(RenderPrimitive): name = "edge-lines" diff --git a/overviewer_core/src/primitives/exposed.c b/overviewer_core/src/primitives/exposed.c new file mode 100644 index 0000000..d05ac66 --- /dev/null +++ b/overviewer_core/src/primitives/exposed.c @@ -0,0 +1,91 @@ +/* + * 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" + +typedef struct { + unsigned int mode; /* 0 = exposed only, 1 = unexposed only */ +} PrimitiveExposed; + +static int +exposed_start(void *data, RenderState *state, PyObject *support) { + PrimitiveExposed *self = (PrimitiveExposed *)data; + + if (!render_mode_parse_option(support, "mode", "I", &(self->mode))) + return 1; + + return 0; +} + +static int +exposed_hidden(void *data, RenderState *state, int x, int y, int z) { + PrimitiveExposed *self = (PrimitiveExposed *)data; + + /* Unset these flags if seeming exposure from any of these directions would + * be due to not having data there. + */ + int validMinusX = 1; + int validPlusY = 1; + int validPlusZ = 1; + + /* special handling for section boundaries */ + /* If the neighboring section has no block data, ignore exposure from that + * direction + */ + if (x == 0 && (!(state->chunks[0][1].loaded) || state->chunks[0][1].sections[state->chunky].blocks == NULL)) { + /* No data in -x direction */ + validMinusX = 0; + } + + if (y == 15 && (state->chunky + 1 >= SECTIONS_PER_CHUNK || state->chunks[1][1].sections[state->chunky + 1].blocks == NULL)) { + /* No data in +y direction */ + validPlusY = 0; + } + + if (z == 15 && (!(state->chunks[1][2].loaded) || state->chunks[1][2].sections[state->chunky].blocks == NULL)) { + /* No data in +z direction */ + validPlusZ = 0; + } + + /* If any of the 6 blocks adjacent to us are transparent, we're exposed */ + if( (validMinusX && is_transparent(get_data(state, BLOCKS, x-1, y, z))) || + is_transparent(get_data(state, BLOCKS, x+1, y, z)) || + is_transparent(get_data(state, BLOCKS, x, y-1, z)) || + (validPlusY && is_transparent(get_data(state, BLOCKS, x, y+1, z))) || + is_transparent(get_data(state, BLOCKS, x, y, z-1)) || + (validPlusZ && is_transparent(get_data(state, BLOCKS, x, y, z+1 ))) ) { + + /* Block is exposed */ + /* Returns 1 and hides us if we're rendering unexposed blocks, 0 and + * shows us if we're rendering exposed blocks + */ + return self->mode; + + } + + /* We have no valid evidence that the block is exposed */ + return !(self->mode); /* Hide in normal mode, reveal in inverted mode */ +} + +RenderPrimitiveInterface primitive_exposed = { + "exposed", sizeof(PrimitiveExposed), + exposed_start, + NULL, + NULL, + exposed_hidden, + NULL, +}; From 9df14462769eab275128a82fe30983ee3062e438 Mon Sep 17 00:00:00 2001 From: Adam Novak Date: Tue, 24 Apr 2012 20:29:27 -0700 Subject: [PATCH 2/6] Added a NoFluids render mode primitive, and documented it. --- docs/config.rst | 3 ++ overviewer_core/rendermodes.py | 3 ++ overviewer_core/src/primitives/no-fluids.c | 44 ++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 overviewer_core/src/primitives/no-fluids.c diff --git a/docs/config.rst b/docs/config.rst index ef4dbed..9bc38d8 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -618,6 +618,9 @@ Exposed mode when set to 1, inverts the render mode, only drawing unexposed blocks. Default: 0 + +NoFluids + Don't render fluid blocks (water, lava). EdgeLines Draw edge lines on the back side of blocks, to help distinguish them from diff --git a/overviewer_core/rendermodes.py b/overviewer_core/rendermodes.py index 2f5d3c8..a161656 100644 --- a/overviewer_core/rendermodes.py +++ b/overviewer_core/rendermodes.py @@ -68,6 +68,9 @@ class Exposed(RenderPrimitive): options = { "mode": ("0 = exposed blocks only, 1 = unexposed blocks only", 0), } + +class NoFluids(RenderPrimitive): + name = "no-fluids" class EdgeLines(RenderPrimitive): name = "edge-lines" diff --git a/overviewer_core/src/primitives/no-fluids.c b/overviewer_core/src/primitives/no-fluids.c new file mode 100644 index 0000000..1f6cc16 --- /dev/null +++ b/overviewer_core/src/primitives/no-fluids.c @@ -0,0 +1,44 @@ +/* + * 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" + +typedef struct { +} PrimitiveNoFluids; + +static int +no_fluids_start(void *data, RenderState *state, PyObject *support) { + PrimitiveNoFluids *self = (PrimitiveNoFluids *)data; + + return 0; +} + +static int +no_fluids_hidden(void *data, RenderState *state, int x, int y, int z) { + PrimitiveNoFluids *self = (PrimitiveNoFluids *)data; + + return !block_has_property(state->block, FLUID); +} + +RenderPrimitiveInterface primitive_no_fluids = { + "no-fluids", sizeof(PrimitiveNoFluids), + no_fluids_start, + NULL, + NULL, + no_fluids_hidden, + NULL, +}; From b1e4b09ab68bfb31e4cdf790ed9bcc3deffeb3d6 Mon Sep 17 00:00:00 2001 From: Adam Novak Date: Tue, 24 Apr 2012 20:35:00 -0700 Subject: [PATCH 3/6] Removing unused struct. --- overviewer_core/src/primitives/no-fluids.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/overviewer_core/src/primitives/no-fluids.c b/overviewer_core/src/primitives/no-fluids.c index 1f6cc16..fe1c704 100644 --- a/overviewer_core/src/primitives/no-fluids.c +++ b/overviewer_core/src/primitives/no-fluids.c @@ -17,25 +17,18 @@ #include "../overviewer.h" -typedef struct { -} PrimitiveNoFluids; - static int no_fluids_start(void *data, RenderState *state, PyObject *support) { - PrimitiveNoFluids *self = (PrimitiveNoFluids *)data; - return 0; } static int no_fluids_hidden(void *data, RenderState *state, int x, int y, int z) { - PrimitiveNoFluids *self = (PrimitiveNoFluids *)data; - return !block_has_property(state->block, FLUID); } RenderPrimitiveInterface primitive_no_fluids = { - "no-fluids", sizeof(PrimitiveNoFluids), + "no-fluids", 0, no_fluids_start, NULL, NULL, From 915aa1a653991f7469a995573a7de5bdc7e4ff47 Mon Sep 17 00:00:00 2001 From: Adam Novak Date: Tue, 24 Apr 2012 20:40:39 -0700 Subject: [PATCH 4/6] Inverting sense of no-fluids to be correct. --- overviewer_core/src/primitives/no-fluids.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/overviewer_core/src/primitives/no-fluids.c b/overviewer_core/src/primitives/no-fluids.c index fe1c704..cb6428a 100644 --- a/overviewer_core/src/primitives/no-fluids.c +++ b/overviewer_core/src/primitives/no-fluids.c @@ -24,7 +24,7 @@ no_fluids_start(void *data, RenderState *state, PyObject *support) { static int no_fluids_hidden(void *data, RenderState *state, int x, int y, int z) { - return !block_has_property(state->block, FLUID); + return block_has_property(state->block, FLUID); } RenderPrimitiveInterface primitive_no_fluids = { From e0c4137eb49b4bfe3b07801e0a034c9109159a54 Mon Sep 17 00:00:00 2001 From: Adam Novak Date: Wed, 25 Apr 2012 00:02:20 -0700 Subject: [PATCH 5/6] Checking for missing data on all sides. --- overviewer_core/src/primitives/exposed.c | 26 ++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/overviewer_core/src/primitives/exposed.c b/overviewer_core/src/primitives/exposed.c index d05ac66..1047beb 100644 --- a/overviewer_core/src/primitives/exposed.c +++ b/overviewer_core/src/primitives/exposed.c @@ -39,7 +39,10 @@ exposed_hidden(void *data, RenderState *state, int x, int y, int z) { * be due to not having data there. */ int validMinusX = 1; + int validPlusX = 1; + int validMinusY = 1; int validPlusY = 1; + int validMinusZ = 1; int validPlusZ = 1; /* special handling for section boundaries */ @@ -50,12 +53,27 @@ exposed_hidden(void *data, RenderState *state, int x, int y, int z) { /* No data in -x direction */ validMinusX = 0; } + + if (x == 15 && (!(state->chunks[2][1].loaded) || state->chunks[2][1].sections[state->chunky].blocks == NULL)) { + /* No data in +x direction */ + validPlusX = 0; + } + + if (y == 0 && (state->chunky - 1 < 0 || state->chunks[1][1].sections[state->chunky - 1].blocks == NULL)) { + /* No data in -y direction */ + validMinusY = 0; + } if (y == 15 && (state->chunky + 1 >= SECTIONS_PER_CHUNK || state->chunks[1][1].sections[state->chunky + 1].blocks == NULL)) { /* No data in +y direction */ validPlusY = 0; } + if (z == 0 && (!(state->chunks[1][0].loaded) || state->chunks[1][0].sections[state->chunky].blocks == NULL)) { + /* No data in -z direction */ + validMinusZ = 0; + } + if (z == 15 && (!(state->chunks[1][2].loaded) || state->chunks[1][2].sections[state->chunky].blocks == NULL)) { /* No data in +z direction */ validPlusZ = 0; @@ -63,10 +81,10 @@ exposed_hidden(void *data, RenderState *state, int x, int y, int z) { /* If any of the 6 blocks adjacent to us are transparent, we're exposed */ if( (validMinusX && is_transparent(get_data(state, BLOCKS, x-1, y, z))) || - is_transparent(get_data(state, BLOCKS, x+1, y, z)) || - is_transparent(get_data(state, BLOCKS, x, y-1, z)) || - (validPlusY && is_transparent(get_data(state, BLOCKS, x, y+1, z))) || - is_transparent(get_data(state, BLOCKS, x, y, z-1)) || + (validPlusX && is_transparent(get_data(state, BLOCKS, x+1, y, z))) || + (validMinusY && is_transparent(get_data(state, BLOCKS, x, y-1, z))) || + (validPlusY && is_transparent(get_data(state, BLOCKS, x, y+1, z))) || + (validMinusZ && is_transparent(get_data(state, BLOCKS, x, y, z-1))) || (validPlusZ && is_transparent(get_data(state, BLOCKS, x, y, z+1 ))) ) { /* Block is exposed */ From 1f29ff5fa18ad2c1910c187259fa94d4c028d9fc Mon Sep 17 00:00:00 2001 From: Adam Novak Date: Wed, 25 Apr 2012 13:04:46 -0700 Subject: [PATCH 6/6] Fixed contributors ordering. --- CONTRIBUTORS.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index 6c8da67..4df9493 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -69,8 +69,8 @@ feature. * Ryan McCue * Zach McCullough * Mike - * Adam Novak * Morlok8k + * Adam Novak * Richard Pastrick * Ryan Rector * Jason Scheirer