0

bumped extension version, and added in a few new rendermode options

This commit is contained in:
Aaron Griffith
2011-06-11 04:27:04 -04:00
parent bd9b1873e3
commit f5a187dad0
4 changed files with 47 additions and 17 deletions

View File

@@ -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 <Python.h>

View File

@@ -17,19 +17,16 @@
#include "overviewer.h"
#include <math.h>
//~
//~ /* 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,

View File

@@ -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,

View File

@@ -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;