modified C extension for get_chunk() raising exception on not found
This commit is contained in:
@@ -96,6 +96,10 @@ PyObject *init_chunk_render(void) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the requested chunk data from the requested chunk.
|
||||
* Returns NULL with an exception set if the requested chunk doesn't exist.
|
||||
*/
|
||||
PyObject *get_chunk_data(RenderState *state, ChunkNeighborName neighbor, ChunkDataType type) {
|
||||
int x = state->chunkx;
|
||||
int z = state->chunkz;
|
||||
@@ -120,8 +124,11 @@ PyObject *get_chunk_data(RenderState *state, ChunkNeighborName neighbor, ChunkDa
|
||||
}
|
||||
|
||||
chunk = PyObject_CallMethod(state->regionset, "get_chunk", "ii", x, z);
|
||||
if (chunk == NULL || chunk == Py_None)
|
||||
return chunk;
|
||||
if (chunk == NULL) {
|
||||
// An exception is already set. RegionSet.get_chunk sets
|
||||
// ChunkDoesntExist
|
||||
return NULL;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case BLOCKS:
|
||||
@@ -166,7 +173,7 @@ unsigned char
|
||||
unsigned char pdata=0;
|
||||
|
||||
if (state->x == 15) { /* +x direction */
|
||||
if (state->up_right_blocks != Py_None) { /* just in case we are in the end of the world */
|
||||
if (state->up_right_blocks != NULL) { /* just in case we are in the end of the world */
|
||||
if (getArrayByte3D(state->up_right_blocks, 0, y, z) == blockid) {
|
||||
pdata = pdata|(1 << 3);
|
||||
}
|
||||
@@ -178,7 +185,7 @@ unsigned char
|
||||
}
|
||||
|
||||
if (state->y == 15) { /* +y direction*/
|
||||
if (state->right_blocks != Py_None) {
|
||||
if (state->right_blocks != NULL) {
|
||||
if (getArrayByte3D(state->right_blocks, x, 0, z) == blockid) {
|
||||
pdata = pdata|(1 << 2);
|
||||
}
|
||||
@@ -190,7 +197,7 @@ unsigned char
|
||||
}
|
||||
|
||||
if (state->x == 0) { /* -x direction*/
|
||||
if (state->left_blocks != Py_None) {
|
||||
if (state->left_blocks != NULL) {
|
||||
if (getArrayByte3D(state->left_blocks, 15, y, z) == blockid) {
|
||||
pdata = pdata|(1 << 1);
|
||||
}
|
||||
@@ -202,7 +209,7 @@ unsigned char
|
||||
}
|
||||
|
||||
if (state->y == 0) { /* -y direction */
|
||||
if (state->up_left_blocks != Py_None) {
|
||||
if (state->up_left_blocks != NULL) {
|
||||
if (getArrayByte3D(state->up_left_blocks, x, 15, z) == blockid) {
|
||||
pdata = pdata|(1 << 0);
|
||||
}
|
||||
@@ -434,8 +441,7 @@ chunk_render(PyObject *self, PyObject *args) {
|
||||
/* get the block data directly from numpy: */
|
||||
blocks_py = get_chunk_data(&state, CURRENT, BLOCKS);
|
||||
state.blocks = blocks_py;
|
||||
if (blocks_py == Py_None) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "chunk does not exist!");
|
||||
if (blocks_py == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -452,6 +458,9 @@ chunk_render(PyObject *self, PyObject *args) {
|
||||
|
||||
up_right_blocks_py = get_chunk_data(&state, UP_RIGHT, BLOCKS);
|
||||
state.up_right_blocks = up_right_blocks_py;
|
||||
|
||||
// Clear any error that was set by the above calls
|
||||
PyErr_Clear();
|
||||
|
||||
/* set up the random number generator again for each chunk
|
||||
so tallgrass is in the same place, no matter what mode is used */
|
||||
|
||||
@@ -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 13
|
||||
#define OVERVIEWER_EXTENSION_VERSION 14
|
||||
|
||||
/* Python PIL, and numpy headers */
|
||||
#include <Python.h>
|
||||
|
||||
@@ -46,7 +46,7 @@ touches_light(unsigned int x, unsigned int y, unsigned int z,
|
||||
}
|
||||
|
||||
if ((x == 15)) {
|
||||
if (up_right_light != Py_None) {
|
||||
if (up_right_light) {
|
||||
if (getArrayByte3D(up_right_light, 0, y, z) != 0) {
|
||||
return 1;
|
||||
}
|
||||
@@ -58,7 +58,7 @@ touches_light(unsigned int x, unsigned int y, unsigned int z,
|
||||
}
|
||||
|
||||
if (x == 0) {
|
||||
if (left_light != Py_None) {
|
||||
if (left_light) {
|
||||
if (getArrayByte3D(left_light, 15, y, z) != 0) {
|
||||
return 1;
|
||||
}
|
||||
@@ -70,7 +70,7 @@ touches_light(unsigned int x, unsigned int y, unsigned int z,
|
||||
}
|
||||
|
||||
if (y == 15) {
|
||||
if (right_light != Py_None) {
|
||||
if (right_light) {
|
||||
if (getArrayByte3D(right_light, 0, y, z) != 0) {
|
||||
return 1;
|
||||
}
|
||||
@@ -82,7 +82,7 @@ touches_light(unsigned int x, unsigned int y, unsigned int z,
|
||||
}
|
||||
|
||||
if (y == 0) {
|
||||
if (up_left_light != Py_None) {
|
||||
if (up_left_light) {
|
||||
if (getArrayByte3D(up_left_light, 15, y, z) != 0) {
|
||||
return 1;
|
||||
}
|
||||
@@ -227,6 +227,8 @@ cave_start(void *data, RenderState *state, PyObject *support) {
|
||||
self->up_left_blocklight = get_chunk_data(state, UP_LEFT, BLOCKLIGHT);
|
||||
self->up_right_blocklight = get_chunk_data(state, UP_RIGHT, BLOCKLIGHT);
|
||||
}
|
||||
// Non-existant neighboring blocks is not an error
|
||||
PyErr_Clear();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -237,17 +239,17 @@ cave_finish(void *data, RenderState *state) {
|
||||
self = (RenderPrimitiveCave *)data;
|
||||
|
||||
Py_DECREF(self->skylight);
|
||||
Py_DECREF(self->left_skylight);
|
||||
Py_DECREF(self->right_skylight);
|
||||
Py_DECREF(self->up_left_skylight);
|
||||
Py_DECREF(self->up_right_skylight);
|
||||
Py_XDECREF(self->left_skylight);
|
||||
Py_XDECREF(self->right_skylight);
|
||||
Py_XDECREF(self->up_left_skylight);
|
||||
Py_XDECREF(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_XDECREF(self->left_blocklight);
|
||||
Py_XDECREF(self->right_blocklight);
|
||||
Py_XDECREF(self->up_left_blocklight);
|
||||
Py_XDECREF(self->up_right_blocklight);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -234,9 +234,9 @@ get_lighting_color(RenderPrimitiveLighting *self, RenderState *state,
|
||||
}
|
||||
|
||||
/* also, make sure we have enough info to correctly calculate lighting */
|
||||
if (blocks == Py_None || blocks == NULL ||
|
||||
skylight == Py_None || skylight == NULL ||
|
||||
blocklight == Py_None || blocklight == NULL) {
|
||||
if (!blocks ||
|
||||
!skylight ||
|
||||
!blocklight) {
|
||||
|
||||
self->calculate_light_color(self, 15, 0, r, g, b);
|
||||
return;
|
||||
@@ -369,6 +369,9 @@ lighting_start(void *data, RenderState *state, PyObject *support) {
|
||||
self->up_left_blocklight = get_chunk_data(state, UP_LEFT, BLOCKLIGHT);
|
||||
self->up_right_skylight = get_chunk_data(state, UP_RIGHT, SKYLIGHT);
|
||||
self->up_right_blocklight = get_chunk_data(state, UP_RIGHT, BLOCKLIGHT);
|
||||
|
||||
// Non-existant neighbor block is not an error
|
||||
PyErr_Clear();
|
||||
|
||||
if (self->night) {
|
||||
self->calculate_light_color = calculate_light_color_night;
|
||||
@@ -404,14 +407,14 @@ lighting_finish(void *data, RenderState *state) {
|
||||
|
||||
Py_DECREF(self->skylight);
|
||||
Py_DECREF(self->blocklight);
|
||||
Py_DECREF(self->left_skylight);
|
||||
Py_DECREF(self->left_blocklight);
|
||||
Py_DECREF(self->right_skylight);
|
||||
Py_DECREF(self->right_blocklight);
|
||||
Py_DECREF(self->up_left_skylight);
|
||||
Py_DECREF(self->up_left_blocklight);
|
||||
Py_DECREF(self->up_right_skylight);
|
||||
Py_DECREF(self->up_right_blocklight);
|
||||
Py_XDECREF(self->left_skylight);
|
||||
Py_XDECREF(self->left_blocklight);
|
||||
Py_XDECREF(self->right_skylight);
|
||||
Py_XDECREF(self->right_blocklight);
|
||||
Py_XDECREF(self->up_left_skylight);
|
||||
Py_XDECREF(self->up_left_blocklight);
|
||||
Py_XDECREF(self->up_right_skylight);
|
||||
Py_XDECREF(self->up_right_blocklight);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
Reference in New Issue
Block a user