turned night into a lighting mode option, added 'night' builtin custom mode
This commit is contained in:
@@ -87,6 +87,24 @@ from overviewer_core.configParser import ConfigOptionParser
|
|||||||
from overviewer_core import optimizeimages, world, quadtree
|
from overviewer_core import optimizeimages, world, quadtree
|
||||||
from overviewer_core import googlemap, rendernode
|
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 = """
|
helptext = """
|
||||||
%prog [OPTIONS] <World # / Name / Path to World> <tiles dest dir>"""
|
%prog [OPTIONS] <World # / Name / Path to World> <tiles dest dir>"""
|
||||||
@@ -145,6 +163,8 @@ def main():
|
|||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
# setup c_overviewer rendermode customs / options
|
# 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:
|
for mode in options.custom_rendermodes:
|
||||||
c_overviewer.add_custom_render_mode(mode, options.custom_rendermodes[mode])
|
c_overviewer.add_custom_render_mode(mode, options.custom_rendermodes[mode])
|
||||||
for mode in options.rendermode_options:
|
for mode in options.rendermode_options:
|
||||||
|
|||||||
@@ -51,6 +51,39 @@ calculate_light_color_fancy(void *data,
|
|||||||
Py_DECREF(color);
|
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)
|
/* loads the appropriate light data for the given (possibly non-local)
|
||||||
* coordinates, and returns a black_coeff this is exposed, so other (derived)
|
* coordinates, and returns a black_coeff this is exposed, so other (derived)
|
||||||
* rendermodes can use it
|
* 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)))
|
if (!render_mode_parse_option(options, "shade_strength", "f", &(self->shade_strength)))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
self->night = 0;
|
||||||
|
if (!render_mode_parse_option(options, "night", "i", &(self->night)))
|
||||||
|
return 1;
|
||||||
|
|
||||||
self->color_light = 0;
|
self->color_light = 0;
|
||||||
if (!render_mode_parse_option(options, "color_light", "i", &(self->color_light)))
|
if (!render_mode_parse_option(options, "color_light", "i", &(self->color_light)))
|
||||||
return 1;
|
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_skylight = PyObject_GetAttrString(state->self, "up_right_skylight");
|
||||||
self->up_right_blocklight = PyObject_GetAttrString(state->self, "up_right_blocklight");
|
self->up_right_blocklight = PyObject_GetAttrString(state->self, "up_right_blocklight");
|
||||||
|
|
||||||
|
if (self->night) {
|
||||||
|
self->calculate_light_color = calculate_light_color_night;
|
||||||
|
} else {
|
||||||
self->calculate_light_color = calculate_light_color;
|
self->calculate_light_color = calculate_light_color;
|
||||||
|
}
|
||||||
|
|
||||||
if (self->color_light) {
|
if (self->color_light) {
|
||||||
self->lightcolor = PyObject_CallMethod(state->textures, "loadLightColor", "");
|
self->lightcolor = PyObject_CallMethod(state->textures, "loadLightColor", "");
|
||||||
@@ -348,9 +389,13 @@ rendermode_lighting_start(void *data, RenderState *state, PyObject *options) {
|
|||||||
Py_DECREF(self->lightcolor);
|
Py_DECREF(self->lightcolor);
|
||||||
self->lightcolor = NULL;
|
self->lightcolor = NULL;
|
||||||
self->color_light = 0;
|
self->color_light = 0;
|
||||||
|
} else {
|
||||||
|
if (self->night) {
|
||||||
|
self->calculate_light_color = calculate_light_color_fancy_night;
|
||||||
} else {
|
} else {
|
||||||
self->calculate_light_color = calculate_light_color_fancy;
|
self->calculate_light_color = calculate_light_color_fancy;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
self->lightcolor = NULL;
|
self->lightcolor = NULL;
|
||||||
}
|
}
|
||||||
@@ -430,6 +475,7 @@ rendermode_lighting_draw(void *data, RenderState *state, PyObject *src, PyObject
|
|||||||
|
|
||||||
const RenderModeOption rendermode_lighting_options[] = {
|
const RenderModeOption rendermode_lighting_options[] = {
|
||||||
{"shade_strength", "how dark to make the shadows, from 0.0 to 1.0 (default: 1.0)"},
|
{"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)"},
|
{"color_light", "whether to use colored light (default: False)"},
|
||||||
{NULL, NULL}
|
{NULL, 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "overviewer.h"
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
/* 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,
|
|
||||||
};
|
|
||||||
@@ -25,7 +25,6 @@
|
|||||||
static RenderModeInterface *render_modes[] = {
|
static RenderModeInterface *render_modes[] = {
|
||||||
&rendermode_normal,
|
&rendermode_normal,
|
||||||
&rendermode_lighting,
|
&rendermode_lighting,
|
||||||
&rendermode_night,
|
|
||||||
&rendermode_smooth_lighting,
|
&rendermode_smooth_lighting,
|
||||||
&rendermode_spawn,
|
&rendermode_spawn,
|
||||||
&rendermode_cave,
|
&rendermode_cave,
|
||||||
|
|||||||
@@ -182,6 +182,7 @@ typedef struct {
|
|||||||
|
|
||||||
float shade_strength;
|
float shade_strength;
|
||||||
int color_light;
|
int color_light;
|
||||||
|
int night;
|
||||||
} RenderModeLighting;
|
} RenderModeLighting;
|
||||||
extern RenderModeInterface rendermode_lighting;
|
extern RenderModeInterface rendermode_lighting;
|
||||||
|
|
||||||
@@ -193,13 +194,6 @@ void get_lighting_color(RenderModeLighting *self, RenderState *state,
|
|||||||
int x, int y, int z,
|
int x, int y, int z,
|
||||||
unsigned char *r, unsigned char *g, unsigned char *b);
|
unsigned char *r, unsigned char *g, unsigned char *b);
|
||||||
|
|
||||||
/* NIGHT */
|
|
||||||
typedef struct {
|
|
||||||
/* inherits from lighting */
|
|
||||||
RenderModeLighting parent;
|
|
||||||
} RenderModeNight;
|
|
||||||
extern RenderModeInterface rendermode_night;
|
|
||||||
|
|
||||||
/* SMOOTH LIGHTING */
|
/* SMOOTH LIGHTING */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/* inherits from lighting */
|
/* inherits from lighting */
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -149,7 +149,7 @@ except:
|
|||||||
|
|
||||||
|
|
||||||
# used to figure out what files to compile
|
# 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 = ['main.c', 'composite.c', 'iterate.c', 'endian.c', 'rendermodes.c']
|
||||||
c_overviewer_files += map(lambda mode: 'rendermode-%s.c' % (mode,), render_modes)
|
c_overviewer_files += map(lambda mode: 'rendermode-%s.c' % (mode,), render_modes)
|
||||||
|
|||||||
Reference in New Issue
Block a user