turned night into a lighting mode option, added 'night' builtin custom mode
This commit is contained in:
@@ -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}
|
||||
};
|
||||
|
||||
@@ -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[] = {
|
||||
&rendermode_normal,
|
||||
&rendermode_lighting,
|
||||
&rendermode_night,
|
||||
&rendermode_smooth_lighting,
|
||||
&rendermode_spawn,
|
||||
&rendermode_cave,
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user