From 34e5ddf620b18709ee401edc83ac3d4dd88a43da Mon Sep 17 00:00:00 2001 From: Aaron Griffith Date: Sun, 6 May 2012 20:19:38 -0400 Subject: [PATCH] biomes are now murky *and* smooth closes issue #708 Props to mkor for taking advantage of the existing average loop, and CounterPillow for sussing out the correct biome multiplication color. This commit is just a teensy bit more future-proof. --- overviewer_core/src/composite.c | 5 -- overviewer_core/src/overviewer.h | 7 ++- overviewer_core/src/primitives/base.c | 79 +++++++++++++++------------ 3 files changed, 50 insertions(+), 41 deletions(-) diff --git a/overviewer_core/src/composite.c b/overviewer_core/src/composite.c index 2fc1c73..3267740 100644 --- a/overviewer_core/src/composite.c +++ b/overviewer_core/src/composite.c @@ -24,11 +24,6 @@ #include "overviewer.h" -/* like (a * b + 127) / 255), but much faster on most platforms - from PIL's _imaging.c */ -#define MULDIV255(a, b, tmp) \ - (tmp = (a) * (b) + 128, ((((tmp) >> 8) + (tmp)) >> 8)) - typedef struct { PyObject_HEAD Imaging image; diff --git a/overviewer_core/src/overviewer.h b/overviewer_core/src/overviewer.h index c9b7ae6..f9091fa 100644 --- a/overviewer_core/src/overviewer.h +++ b/overviewer_core/src/overviewer.h @@ -26,13 +26,18 @@ // increment this value if you've made a change to the c extesion // and want to force users to rebuild -#define OVERVIEWER_EXTENSION_VERSION 31 +#define OVERVIEWER_EXTENSION_VERSION 32 /* Python PIL, and numpy headers */ #include #include #include +/* like (a * b + 127) / 255), but much faster on most platforms + from PIL's _imaging.c */ +#define MULDIV255(a, b, tmp) \ + (tmp = (a) * (b) + 128, ((((tmp) >> 8) + (tmp)) >> 8)) + /* macro for getting a value out of various numpy arrays the 3D arrays have interesting, swizzled coordinates because minecraft (anvil) stores blocks in y/z/x order for 3D, z/x order for 2D */ diff --git a/overviewer_core/src/primitives/base.c b/overviewer_core/src/primitives/base.c index ae93db7..d23c098 100644 --- a/overviewer_core/src/primitives/base.c +++ b/overviewer_core/src/primitives/base.c @@ -29,46 +29,53 @@ typedef struct { typedef struct { const char* name; + float temperature; float rainfall; + + unsigned int r, g, b; } Biome; /* each entry in this table is yanked *directly* out of the minecraft source * temp/rainfall are taken from what MCP calls setTemperatureRainfall * + * Some biomes, like Swamp, do a bit of post-processing by multiplying on a + * hard-coded color. The RGB tuple used follows the temp/rainfall. + * 255, 255, 255 is white, which means do nothing + * * keep in mind the x/y coordinate in the color tables is found *after* * multiplying rainfall and temperature for the second coordinate, *and* the * origin is in the lower-right. <3 biomes. */ static Biome biome_table[] = { /* 0 */ - {"Ocean", 0.5, 0.5}, - {"Plains", 0.8, 0.4}, - {"Desert", 2.0, 0.0}, - {"Extreme Hills", 0.2, 0.3}, - {"Forest", 0.7, 0.8}, + {"Ocean", 0.5, 0.5, 255, 255}, + {"Plains", 0.8, 0.4, 255, 255, 255}, + {"Desert", 2.0, 0.0, 255, 255, 255}, + {"Extreme Hills", 0.2, 0.3, 255, 255, 255}, + {"Forest", 0.7, 0.8, 255, 255, 255}, /* 5 */ - {"Taiga", 0.05, 0.8}, - {"Swampland", 0.8, 0.9}, - {"River", 0.5, 0.5}, - {"Hell", 2.0, 0.0}, - {"Sky", 0.5, 0.5}, + {"Taiga", 0.05, 0.8, 255, 255, 255}, + {"Swampland", 0.8, 0.9, 205, 128, 255}, + {"River", 0.5, 0.5, 255, 255, 255}, + {"Hell", 2.0, 0.0, 255, 255, 255}, + {"Sky", 0.5, 0.5, 255, 255, 255}, /* 10 */ - {"FrozenOcean", 0.0, 0.5}, - {"FrozenRiver", 0.0, 0.5}, - {"Ice Plains", 0.0, 0.5}, - {"Ice Mountains", 0.0, 0.5}, - {"MushroomIsland", 0.9, 1.0}, + {"FrozenOcean", 0.0, 0.5, 255, 255, 255}, + {"FrozenRiver", 0.0, 0.5, 255, 255, 255}, + {"Ice Plains", 0.0, 0.5, 255, 255, 255}, + {"Ice Mountains", 0.0, 0.5, 255, 255, 255}, + {"MushroomIsland", 0.9, 1.0, 255, 255, 255}, /* 15 */ - {"MushroomIslandShore", 0.9, 1.0}, - {"Beach", 0.8, 0.4}, - {"DesertHills", 2.0, 0.0}, - {"ForestHills", 0.7, 0.8}, - {"TaigaHills", 0.05, 0.8}, + {"MushroomIslandShore", 0.9, 1.0, 255, 255, 255}, + {"Beach", 0.8, 0.4, 255, 255, 255}, + {"DesertHills", 2.0, 0.0, 255, 255, 255}, + {"ForestHills", 0.7, 0.8, 255, 255, 255}, + {"TaigaHills", 0.05, 0.8, 255, 255, 255}, /* 20 */ - {"Extreme Hills Edge", 0.2, 0.3}, - {"Jungle", 2.0, 0.45}, /* <-- GUESS, but a good one */ - {"Jungle Mountains", 2.0, 0.45}, /* <-- also a guess */ + {"Extreme Hills Edge", 0.2, 0.3, 255, 255, 255}, + {"Jungle", 2.0, 0.45, 255, 255, 255}, /* <-- GUESS, but a good one */ + {"Jungle Mountains", 2.0, 0.45, 255, 255, 255}, /* <-- also a guess */ }; #define NUM_BIOMES (sizeof(biome_table) / sizeof(Biome)) @@ -210,6 +217,8 @@ base_draw(void *data, RenderState *state, PyObject *src, PyObject *mask, PyObjec int dx, dz; unsigned char tablex, tabley; float temp = 0.0, rain = 0.0; + unsigned int multr = 0, multg = 0, multb = 0; + int tmp; PyObject *color = NULL; if (self->use_biomes) { @@ -226,10 +235,17 @@ base_draw(void *data, RenderState *state, PyObject *src, PyObject *mask, PyObjec temp += biome_table[biome].temperature; rain += biome_table[biome].rainfall; + multr += biome_table[biome].r; + multg += biome_table[biome].g; + multb += biome_table[biome].b; } } + temp /= 9.0; rain /= 9.0; + multr /= 9; + multg /= 9; + multb /= 9; } else { /* don't use biomes, just use the default */ temp = biome_table[DEFAULT_BIOME].temperature; @@ -258,19 +274,12 @@ base_draw(void *data, RenderState *state, PyObject *src, PyObject *mask, PyObjec r = PyInt_AsLong(PyTuple_GET_ITEM(color, 0)); g = PyInt_AsLong(PyTuple_GET_ITEM(color, 1)); b = PyInt_AsLong(PyTuple_GET_ITEM(color, 2)); - - /* swamp hack - All values are guessed. They are probably somewhat odd or - completely wrong, but this looks okay for me, and I'm male, - so I can only distinct about 10 different colors anyways. - Blame my Y-Chromosone. */ - if(biome == 6) { - r = PyInt_AsLong(PyTuple_GET_ITEM(color, 0)) * 0.8; - g = PyInt_AsLong(PyTuple_GET_ITEM(color, 1)) / 2.0; - b = PyInt_AsLong(PyTuple_GET_ITEM(color, 2)) * 1.0; - } - Py_DECREF(color); + + /* do the after-coloration */ + r = MULDIV255(r, multr, tmp); + g = MULDIV255(g, multg, tmp); + b = MULDIV255(b, multb, tmp); } /* final coloration */