diff --git a/overviewer.py b/overviewer.py index 3399424..9e1df17 100755 --- a/overviewer.py +++ b/overviewer.py @@ -87,6 +87,24 @@ from overviewer_core.configParser import ConfigOptionParser from overviewer_core import optimizeimages, world, quadtree from overviewer_core import googlemap, rendernode +# definitions of built-in custom modes +# usually because what used to be a mode became an option +# for example, night mode +builtin_custom_rendermodes = { + 'night' : { + 'parent' : 'lighting', + 'label' : 'Night', + 'description' : 'like "lighting", except at night', + 'options' : {'night' : True} + }, + + 'smooth-night' : { + 'parent' : 'smooth-lighting', + 'label' : 'Smooth Night', + 'description' : 'like "lighting", except smooth and at night', + 'options' : {'night' : True} + }, +} helptext = """ %prog [OPTIONS] """ @@ -145,6 +163,8 @@ def main(): sys.exit(0) # setup c_overviewer rendermode customs / options + for mode in builtin_custom_rendermodes: + c_overviewer.add_custom_render_mode(mode, builtin_custom_rendermodes[mode]) for mode in options.custom_rendermodes: c_overviewer.add_custom_render_mode(mode, options.custom_rendermodes[mode]) for mode in options.rendermode_options: diff --git a/overviewer_core/src/rendermode-lighting.c b/overviewer_core/src/rendermode-lighting.c index 925b7d6..6a984da 100644 --- a/overviewer_core/src/rendermode-lighting.c +++ b/overviewer_core/src/rendermode-lighting.c @@ -51,6 +51,39 @@ calculate_light_color_fancy(void *data, Py_DECREF(color); } +/* figures out the color from a given skylight and blocklight, used in + lighting calculations -- note this is *different* from the one above + (the "skylight - 11" part) +*/ +static void +calculate_light_color_night(void *data, + unsigned char skylight, unsigned char blocklight, + unsigned char *r, unsigned char *g, unsigned char *b) { + unsigned char v = 255 * powf(0.8f, 15.0 - MAX(blocklight, skylight - 11)); + *r = v; + *g = v; + *b = v; +} + +/* fancy night version that uses the colored light texture */ +static void +calculate_light_color_fancy_night(void *data, + unsigned char skylight, unsigned char blocklight, + unsigned char *r, unsigned char *g, unsigned char *b) { + RenderModeLighting *mode = (RenderModeLighting *)(data); + unsigned int index; + PyObject *color; + + index = skylight + blocklight * 16; + color = PySequence_GetItem(mode->lightcolor, index); + + *r = PyInt_AsLong(PyTuple_GET_ITEM(color, 0)); + *g = PyInt_AsLong(PyTuple_GET_ITEM(color, 1)); + *b = PyInt_AsLong(PyTuple_GET_ITEM(color, 2)); + + Py_DECREF(color); +} + /* loads the appropriate light data for the given (possibly non-local) * coordinates, and returns a black_coeff this is exposed, so other (derived) * rendermodes can use it @@ -319,6 +352,10 @@ rendermode_lighting_start(void *data, RenderState *state, PyObject *options) { if (!render_mode_parse_option(options, "shade_strength", "f", &(self->shade_strength))) return 1; + self->night = 0; + if (!render_mode_parse_option(options, "night", "i", &(self->night))) + return 1; + self->color_light = 0; if (!render_mode_parse_option(options, "color_light", "i", &(self->color_light))) return 1; @@ -340,7 +377,11 @@ rendermode_lighting_start(void *data, RenderState *state, PyObject *options) { self->up_right_skylight = PyObject_GetAttrString(state->self, "up_right_skylight"); self->up_right_blocklight = PyObject_GetAttrString(state->self, "up_right_blocklight"); - self->calculate_light_color = calculate_light_color; + if (self->night) { + self->calculate_light_color = calculate_light_color_night; + } else { + self->calculate_light_color = calculate_light_color; + } if (self->color_light) { self->lightcolor = PyObject_CallMethod(state->textures, "loadLightColor", ""); @@ -349,7 +390,11 @@ rendermode_lighting_start(void *data, RenderState *state, PyObject *options) { self->lightcolor = NULL; self->color_light = 0; } else { - self->calculate_light_color = calculate_light_color_fancy; + if (self->night) { + self->calculate_light_color = calculate_light_color_fancy_night; + } else { + self->calculate_light_color = calculate_light_color_fancy; + } } } else { self->lightcolor = NULL; @@ -430,6 +475,7 @@ rendermode_lighting_draw(void *data, RenderState *state, PyObject *src, PyObject const RenderModeOption rendermode_lighting_options[] = { {"shade_strength", "how dark to make the shadows, from 0.0 to 1.0 (default: 1.0)"}, + {"night", "whether to use nighttime skylight settings (default: False)"}, {"color_light", "whether to use colored light (default: False)"}, {NULL, NULL} }; diff --git a/overviewer_core/src/rendermode-night.c b/overviewer_core/src/rendermode-night.c deleted file mode 100644 index d4c1e6c..0000000 --- a/overviewer_core/src/rendermode-night.c +++ /dev/null @@ -1,106 +0,0 @@ -/* - * 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" -#include - -/* figures out the color from a given skylight and blocklight, used in - lighting calculations -- note this is *different* from the one in - rendermode-lighting.c (the "skylight - 11" part) */ -static void -calculate_light_color(void *data, - unsigned char skylight, unsigned char blocklight, - unsigned char *r, unsigned char *g, unsigned char *b) { - unsigned char v = 255 * powf(0.8f, 15.0 - MAX(blocklight, skylight - 11)); - *r = v; - *g = v; - *b = v; -} - -/* fancy version that uses the colored light texture */ -static void -calculate_light_color_fancy(void *data, - unsigned char skylight, unsigned char blocklight, - unsigned char *r, unsigned char *g, unsigned char *b) { - RenderModeLighting *mode = (RenderModeLighting *)(data); - unsigned int index; - PyObject *color; - - index = skylight + blocklight * 16; - color = PySequence_GetItem(mode->lightcolor, index); - - *r = PyInt_AsLong(PyTuple_GET_ITEM(color, 0)); - *g = PyInt_AsLong(PyTuple_GET_ITEM(color, 1)); - *b = PyInt_AsLong(PyTuple_GET_ITEM(color, 2)); - - Py_DECREF(color); -} - -static int -rendermode_night_start(void *data, RenderState *state, PyObject *options) { - RenderModeNight* self; - - /* first, chain up */ - int ret = rendermode_lighting.start(data, state, options); - if (ret != 0) - return ret; - - /* override the darkness function with our night version! */ - self = (RenderModeNight *)data; - self->parent.calculate_light_color = calculate_light_color; - if (self->parent.color_light) - self->parent.calculate_light_color = calculate_light_color_fancy; - - return 0; -} - -static void -rendermode_night_finish(void *data, RenderState *state) { - /* nothing special to do */ - rendermode_lighting.finish(data, state); -} - -static int -rendermode_night_occluded(void *data, RenderState *state, int x, int y, int z) { - /* no special occlusion here */ - return rendermode_lighting.occluded(data, state, x, y, z); -} - -static int -rendermode_night_hidden(void *data, RenderState *state, int x, int y, int z) { - /* no special hiding here */ - return rendermode_lighting.hidden(data, state, x, y, z); -} - -static void -rendermode_night_draw(void *data, RenderState *state, PyObject *src, PyObject *mask, PyObject *mask_light) { - /* nothing special to do */ - rendermode_lighting.draw(data, state, src, mask, mask_light); -} - -RenderModeInterface rendermode_night = { - "night", "Night", - "like \"lighting\", except at night", - NULL, - &rendermode_lighting, - sizeof(RenderModeNight), - rendermode_night_start, - rendermode_night_finish, - rendermode_night_occluded, - rendermode_night_hidden, - rendermode_night_draw, -}; diff --git a/overviewer_core/src/rendermodes.c b/overviewer_core/src/rendermodes.c index 31acdb7..dd0848f 100644 --- a/overviewer_core/src/rendermodes.c +++ b/overviewer_core/src/rendermodes.c @@ -25,7 +25,6 @@ static RenderModeInterface *render_modes[] = { &rendermode_normal, &rendermode_lighting, - &rendermode_night, &rendermode_smooth_lighting, &rendermode_spawn, &rendermode_cave, diff --git a/overviewer_core/src/rendermodes.h b/overviewer_core/src/rendermodes.h index ca9a390..5084cd8 100644 --- a/overviewer_core/src/rendermodes.h +++ b/overviewer_core/src/rendermodes.h @@ -182,6 +182,7 @@ typedef struct { float shade_strength; int color_light; + int night; } RenderModeLighting; extern RenderModeInterface rendermode_lighting; @@ -193,13 +194,6 @@ void get_lighting_color(RenderModeLighting *self, RenderState *state, int x, int y, int z, unsigned char *r, unsigned char *g, unsigned char *b); -/* NIGHT */ -typedef struct { - /* inherits from lighting */ - RenderModeLighting parent; -} RenderModeNight; -extern RenderModeInterface rendermode_night; - /* SMOOTH LIGHTING */ typedef struct { /* inherits from lighting */ diff --git a/setup.py b/setup.py index a881f9c..7714874 100755 --- a/setup.py +++ b/setup.py @@ -149,7 +149,7 @@ except: # used to figure out what files to compile -render_modes = ['normal', 'overlay', 'lighting', 'night', 'smooth-lighting', 'spawn', 'cave', 'mineral'] +render_modes = ['normal', 'overlay', 'lighting', 'smooth-lighting', 'spawn', 'cave', 'mineral'] c_overviewer_files = ['main.c', 'composite.c', 'iterate.c', 'endian.c', 'rendermodes.c'] c_overviewer_files += map(lambda mode: 'rendermode-%s.c' % (mode,), render_modes)