From f5a187dad086e5f57cd7a9a5a515b33babd7d8fc Mon Sep 17 00:00:00 2001 From: Aaron Griffith Date: Sat, 11 Jun 2011 04:27:04 -0400 Subject: [PATCH] bumped extension version, and added in a few new rendermode options --- src/overviewer.h | 2 +- src/rendermode-cave.c | 40 ++++++++++++++++++++++++--------------- src/rendermode-lighting.c | 19 ++++++++++++++++++- src/rendermodes.h | 3 +++ 4 files changed, 47 insertions(+), 17 deletions(-) diff --git a/src/overviewer.h b/src/overviewer.h index 49e70fa..a0c5316 100644 --- a/src/overviewer.h +++ b/src/overviewer.h @@ -26,7 +26,7 @@ // increment this value if you've made a change to the c extesion // and want to force users to rebuild -#define OVERVIEWER_EXTENSION_VERSION 7 +#define OVERVIEWER_EXTENSION_VERSION 8 /* Python PIL, and numpy headers */ #include diff --git a/src/rendermode-cave.c b/src/rendermode-cave.c index e4275e5..b8fc370 100644 --- a/src/rendermode-cave.c +++ b/src/rendermode-cave.c @@ -17,19 +17,16 @@ #include "overviewer.h" #include -//~ -//~ /* figures out the black_coeff 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 float calculate_darkness(unsigned char skylight, unsigned char blocklight) { - //~ return 1.0f - powf(0.8f, 15.0 - MAX(blocklight, skylight - 11)); -//~ } static int rendermode_cave_occluded(void *data, RenderState *state) { int x = state->x, y = state->y, z = state->z, dz = 0; RenderModeCave* self; self = (RenderModeCave *)data; + + /* first, check to see if it's "normally" occluded */ + if (rendermode_normal.occluded(data, state)) + return 1; /* check if the block is touching skylight */ if (z != 127) { @@ -164,12 +161,20 @@ static int rendermode_cave_start(void *data, RenderState *state, PyObject *options) { RenderModeCave* self; int ret; + PyObject *opt; self = (RenderModeCave *)data; /* first, chain up */ ret = rendermode_normal.start(data, state, options); if (ret != 0) return ret; + + opt = PyDict_GetItemString(options, "depth_tinting"); + if (opt) { + self->depth_tinting = PyObject_IsTrue(opt); + } else { + self->depth_tinting = 1; + } /* if there's skylight we are in the surface! */ self->skylight = PyObject_GetAttrString(state->self, "skylight"); @@ -213,19 +218,24 @@ rendermode_cave_draw(void *data, RenderState *state, PyObject *src, PyObject *ma /* draw the normal block */ rendermode_normal.draw(data, state, src, mask, mask_light); - /* get the colors and tint and tint */ - /* TODO TODO for a nether mode there isn't tinting! */ - r = PyInt_AsLong(PyList_GetItem(self->depth_colors, 0 + z*3)); - g = PyInt_AsLong(PyList_GetItem(self->depth_colors, 1 + z*3)); - b = PyInt_AsLong(PyList_GetItem(self->depth_colors, 2 + z*3)); - - tint_with_mask(state->img, r, g, b, 255, mask, state->imgx, state->imgy, 0, 0); + if (self->depth_tinting) { + /* get the colors and tint and tint */ + r = PyInt_AsLong(PyList_GetItem(self->depth_colors, 0 + z*3)); + g = PyInt_AsLong(PyList_GetItem(self->depth_colors, 1 + z*3)); + b = PyInt_AsLong(PyList_GetItem(self->depth_colors, 2 + z*3)); + + tint_with_mask(state->img, r, g, b, 255, mask, state->imgx, state->imgy, 0, 0); + } } +static RenderModeOption rendermode_cave_options[] = { + {"depth_tinting", "tint caves based on how deep they are (default: True)"}, +}; + RenderModeInterface rendermode_cave = { "cave", "render only caves in normal mode", - NULL, + rendermode_cave_options, &rendermode_normal, sizeof(RenderModeCave), rendermode_cave_start, diff --git a/src/rendermode-lighting.c b/src/rendermode-lighting.c index f3e529b..c4029ae 100644 --- a/src/rendermode-lighting.c +++ b/src/rendermode-lighting.c @@ -165,11 +165,13 @@ do_shading_with_mask(RenderModeLighting *self, RenderState *state, } black_coeff = get_lighting_coefficient(self, state, x, y, z, NULL); + black_coeff *= self->shade_strength; alpha_over_full(state->img, self->black_color, mask, black_coeff, state->imgx, state->imgy, 0, 0); } static int rendermode_lighting_start(void *data, RenderState *state, PyObject *options) { + PyObject *opt; RenderModeLighting* self; /* first, chain up */ @@ -178,6 +180,17 @@ rendermode_lighting_start(void *data, RenderState *state, PyObject *options) { return ret; self = (RenderModeLighting *)data; + + opt = PyDict_GetItemString(options, "shade_strength"); + if (opt) { + if (!PyNumber_Check(opt)) { + PyErr_SetString(PyExc_TypeError, "'shade_strength' must be a number"); + return 1; + } + self->shade_strength = PyFloat_AsDouble(opt); + } else { + self->shade_strength = 1.0; + } self->black_color = PyObject_GetAttrString(state->chunk, "black_color"); self->facemasks_py = PyObject_GetAttrString(state->chunk, "facemasks"); @@ -244,9 +257,13 @@ rendermode_lighting_draw(void *data, RenderState *state, PyObject *src, PyObject } } +RenderModeOption rendermode_lighting_options[] = { + {"shade_strength", "how dark to make the shadows, from 0.0 to 1.0 (default: 1.0)"}, +}; + RenderModeInterface rendermode_lighting = { "lighting", "draw shadows from the lighting data", - NULL, + rendermode_lighting_options, &rendermode_normal, sizeof(RenderModeLighting), rendermode_lighting_start, diff --git a/src/rendermodes.h b/src/rendermodes.h index 23ada4c..d5d3478 100644 --- a/src/rendermodes.h +++ b/src/rendermodes.h @@ -141,6 +141,8 @@ typedef struct { /* can be overridden in derived rendermodes to control lighting arguments are skylight, blocklight */ float (*calculate_darkness)(unsigned char, unsigned char); + + float shade_strength; } RenderModeLighting; extern RenderModeInterface rendermode_lighting; @@ -177,6 +179,7 @@ typedef struct { /* colors used for tinting */ PyObject *depth_colors; + int depth_tinting; } RenderModeCave; extern RenderModeInterface rendermode_cave;