added 'only_lit' option to cave mode
This commit is contained in:
14
chunk.py
14
chunk.py
@@ -294,6 +294,13 @@ class ChunkRenderer(object):
|
|||||||
return self._up_right_skylight
|
return self._up_right_skylight
|
||||||
up_right_skylight = property(_load_up_right_skylight)
|
up_right_skylight = property(_load_up_right_skylight)
|
||||||
|
|
||||||
|
def _load_up_right_blocklight(self):
|
||||||
|
"""Loads and returns lower-right blocklight array"""
|
||||||
|
if not hasattr(self, "_up_right_blocklight"):
|
||||||
|
self._load_up_right()
|
||||||
|
return self._up_right_blocklight
|
||||||
|
up_right_blocklight = property(_load_up_right_blocklight)
|
||||||
|
|
||||||
def _load_up_left(self):
|
def _load_up_left(self):
|
||||||
"""Loads and sets data from upper-left chunk"""
|
"""Loads and sets data from upper-left chunk"""
|
||||||
chunk_path = self.world.get_region_path(self.chunkX, self.chunkY - 1)
|
chunk_path = self.world.get_region_path(self.chunkX, self.chunkY - 1)
|
||||||
@@ -321,6 +328,13 @@ class ChunkRenderer(object):
|
|||||||
return self._up_left_skylight
|
return self._up_left_skylight
|
||||||
up_left_skylight = property(_load_up_left_skylight)
|
up_left_skylight = property(_load_up_left_skylight)
|
||||||
|
|
||||||
|
def _load_up_left_blocklight(self):
|
||||||
|
"""Loads and returns lower-left blocklight array"""
|
||||||
|
if not hasattr(self, "_up_left_blocklight"):
|
||||||
|
self._load_up_left()
|
||||||
|
return self._up_left_blocklight
|
||||||
|
up_left_blocklight = property(_load_up_left_blocklight)
|
||||||
|
|
||||||
def generate_pseudo_ancildata(self,x,y,z,blockid, north_position = 0 ):
|
def generate_pseudo_ancildata(self,x,y,z,blockid, north_position = 0 ):
|
||||||
""" Generates a pseudo ancillary data for blocks that depend of
|
""" Generates a pseudo ancillary data for blocks that depend of
|
||||||
what are surrounded and don't have ancillary data
|
what are surrounded and don't have ancillary data
|
||||||
|
|||||||
@@ -18,6 +18,67 @@
|
|||||||
#include "overviewer.h"
|
#include "overviewer.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
static inline int
|
||||||
|
touches_light(unsigned int x, unsigned int y, unsigned int z,
|
||||||
|
PyObject *light, PyObject *left_light, PyObject *right_light,
|
||||||
|
PyObject *up_left_light, PyObject *up_right_light) {
|
||||||
|
|
||||||
|
|
||||||
|
if (getArrayByte3D(light, x, y, z+1) != 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((x == 15)) {
|
||||||
|
if (up_right_light != Py_None) {
|
||||||
|
if (getArrayByte3D(up_right_light, 0, y, z) != 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (getArrayByte3D(light, x+1, y, z) != 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x == 0) {
|
||||||
|
if (left_light != Py_None) {
|
||||||
|
if (getArrayByte3D(left_light, 15, y, z) != 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (getArrayByte3D(light, x-1, y, z) != 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y == 15) {
|
||||||
|
if (right_light != Py_None) {
|
||||||
|
if (getArrayByte3D(right_light, 0, y, z) != 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (getArrayByte3D(light, x, y+1, z) != 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y == 0) {
|
||||||
|
if (up_left_light != Py_None) {
|
||||||
|
if (getArrayByte3D(up_left_light, 15, y, z) != 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (getArrayByte3D(light, x, y-1, z) != 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
rendermode_cave_occluded(void *data, RenderState *state) {
|
rendermode_cave_occluded(void *data, RenderState *state) {
|
||||||
int x = state->x, y = state->y, z = state->z, dz = 0;
|
int x = state->x, y = state->y, z = state->z, dz = 0;
|
||||||
@@ -31,56 +92,12 @@ rendermode_cave_occluded(void *data, RenderState *state) {
|
|||||||
/* check if the block is touching skylight */
|
/* check if the block is touching skylight */
|
||||||
if (z != 127) {
|
if (z != 127) {
|
||||||
|
|
||||||
if (getArrayByte3D(self->skylight, x, y, z+1) != 0) {
|
if (touches_light(x, y, z, self->skylight, self->left_skylight, self->right_skylight, self->up_left_skylight, self->up_right_skylight)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((x == 15)) {
|
if (self->only_lit && !touches_light(x, y, z, self->blocklight, self->left_blocklight, self->right_blocklight, self->up_left_blocklight, self->up_right_blocklight)) {
|
||||||
if (self->up_right_skylight != Py_None) {
|
return 1;
|
||||||
if (getArrayByte3D(self->up_right_skylight, 0, y, z) != 0) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (getArrayByte3D(self->skylight, x+1, y, z) != 0) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (x == 0) {
|
|
||||||
if (self->left_skylight != Py_None) {
|
|
||||||
if (getArrayByte3D(self->left_skylight, 15, y, z) != 0) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (getArrayByte3D(self->skylight, x-1, y, z) != 0) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (y == 15) {
|
|
||||||
if (self->right_skylight != Py_None) {
|
|
||||||
if (getArrayByte3D(self->right_skylight, 0, y, z) != 0) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (getArrayByte3D(self->skylight, x, y+1, z) != 0) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (y == 0) {
|
|
||||||
if (self->up_left_skylight != Py_None) {
|
|
||||||
if (getArrayByte3D(self->up_left_skylight, 15, y, z) != 0) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (getArrayByte3D(self->skylight, x, y-1, z) != 0) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check for normal occlusion */
|
/* check for normal occlusion */
|
||||||
@@ -176,6 +193,13 @@ rendermode_cave_start(void *data, RenderState *state, PyObject *options) {
|
|||||||
self->depth_tinting = 1;
|
self->depth_tinting = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
opt = PyDict_GetItemString(options, "only_lit");
|
||||||
|
if (opt) {
|
||||||
|
self->only_lit = PyObject_IsTrue(opt);
|
||||||
|
} else {
|
||||||
|
self->only_lit = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* if there's skylight we are in the surface! */
|
/* if there's skylight we are in the surface! */
|
||||||
self->skylight = PyObject_GetAttrString(state->self, "skylight");
|
self->skylight = PyObject_GetAttrString(state->self, "skylight");
|
||||||
self->left_skylight = PyObject_GetAttrString(state->self, "left_skylight");
|
self->left_skylight = PyObject_GetAttrString(state->self, "left_skylight");
|
||||||
@@ -183,10 +207,17 @@ rendermode_cave_start(void *data, RenderState *state, PyObject *options) {
|
|||||||
self->up_left_skylight = PyObject_GetAttrString(state->self, "up_left_skylight");
|
self->up_left_skylight = PyObject_GetAttrString(state->self, "up_left_skylight");
|
||||||
self->up_right_skylight = PyObject_GetAttrString(state->self, "up_right_skylight");
|
self->up_right_skylight = PyObject_GetAttrString(state->self, "up_right_skylight");
|
||||||
|
|
||||||
|
if (self->only_lit) {
|
||||||
|
self->blocklight = PyObject_GetAttrString(state->self, "blocklight");
|
||||||
|
self->left_blocklight = PyObject_GetAttrString(state->self, "left_blocklight");
|
||||||
|
self->right_blocklight = PyObject_GetAttrString(state->self, "right_blocklight");
|
||||||
|
self->up_left_blocklight = PyObject_GetAttrString(state->self, "up_left_blocklight");
|
||||||
|
self->up_right_blocklight = PyObject_GetAttrString(state->self, "up_right_blocklight");
|
||||||
|
}
|
||||||
|
|
||||||
/* colors for tinting */
|
/* colors for tinting */
|
||||||
self->depth_colors = PyObject_GetAttrString(state->chunk, "depth_colors");
|
self->depth_colors = PyObject_GetAttrString(state->chunk, "depth_colors");
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,6 +232,14 @@ rendermode_cave_finish(void *data, RenderState *state) {
|
|||||||
Py_DECREF(self->up_left_skylight);
|
Py_DECREF(self->up_left_skylight);
|
||||||
Py_DECREF(self->up_right_skylight);
|
Py_DECREF(self->up_right_skylight);
|
||||||
|
|
||||||
|
if (self->only_lit) {
|
||||||
|
Py_DECREF(self->blocklight);
|
||||||
|
Py_DECREF(self->left_blocklight);
|
||||||
|
Py_DECREF(self->right_blocklight);
|
||||||
|
Py_DECREF(self->up_left_blocklight);
|
||||||
|
Py_DECREF(self->up_right_blocklight);
|
||||||
|
}
|
||||||
|
|
||||||
Py_DECREF(self->depth_colors);
|
Py_DECREF(self->depth_colors);
|
||||||
|
|
||||||
rendermode_normal.finish(data, state);
|
rendermode_normal.finish(data, state);
|
||||||
@@ -231,6 +270,7 @@ rendermode_cave_draw(void *data, RenderState *state, PyObject *src, PyObject *ma
|
|||||||
|
|
||||||
static RenderModeOption rendermode_cave_options[] = {
|
static RenderModeOption rendermode_cave_options[] = {
|
||||||
{"depth_tinting", "tint caves based on how deep they are (default: True)"},
|
{"depth_tinting", "tint caves based on how deep they are (default: True)"},
|
||||||
|
{"only_lit", "only render lit caves (default: False)"},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -176,10 +176,18 @@ typedef struct {
|
|||||||
PyObject *up_left_skylight;
|
PyObject *up_left_skylight;
|
||||||
PyObject *up_right_skylight;
|
PyObject *up_right_skylight;
|
||||||
|
|
||||||
|
/* data used to know where the surface is */
|
||||||
|
PyObject *blocklight;
|
||||||
|
PyObject *left_blocklight;
|
||||||
|
PyObject *right_blocklight;
|
||||||
|
PyObject *up_left_blocklight;
|
||||||
|
PyObject *up_right_blocklight;
|
||||||
|
|
||||||
/* colors used for tinting */
|
/* colors used for tinting */
|
||||||
PyObject *depth_colors;
|
PyObject *depth_colors;
|
||||||
|
|
||||||
int depth_tinting;
|
int depth_tinting;
|
||||||
|
int only_lit;
|
||||||
} RenderModeCave;
|
} RenderModeCave;
|
||||||
extern RenderModeInterface rendermode_cave;
|
extern RenderModeInterface rendermode_cave;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user