more C code fixes. Activated caching.
Also removed some code that I accidentially left in. Also added a traceback printing decorator around get_chunk() because the C code can potentially swallow those exceptions.
This commit is contained in:
@@ -99,8 +99,11 @@ PyObject *init_chunk_render(void) {
|
||||
/*
|
||||
* Returns the requested chunk data from the requested chunk.
|
||||
* Returns NULL with an exception set if the requested chunk doesn't exist.
|
||||
* If clearexception is true, clears the exception before returning NULL (for
|
||||
* soft failures)
|
||||
*/
|
||||
PyObject *get_chunk_data(RenderState *state, ChunkNeighborName neighbor, ChunkDataType type) {
|
||||
PyObject *get_chunk_data(RenderState *state, ChunkNeighborName neighbor, ChunkDataType type,
|
||||
unsigned char clearexception) {
|
||||
int x = state->chunkx;
|
||||
int z = state->chunkz;
|
||||
PyObject *chunk = NULL;
|
||||
@@ -127,6 +130,9 @@ PyObject *get_chunk_data(RenderState *state, ChunkNeighborName neighbor, ChunkDa
|
||||
if (chunk == NULL) {
|
||||
// An exception is already set. RegionSet.get_chunk sets
|
||||
// ChunkDoesntExist
|
||||
if (clearexception) {
|
||||
PyErr_Clear();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -439,28 +445,25 @@ chunk_render(PyObject *self, PyObject *args) {
|
||||
Py_DECREF(imgsize1_py);
|
||||
|
||||
/* get the block data directly from numpy: */
|
||||
blocks_py = get_chunk_data(&state, CURRENT, BLOCKS);
|
||||
blocks_py = get_chunk_data(&state, CURRENT, BLOCKS, 0);
|
||||
state.blocks = blocks_py;
|
||||
if (blocks_py == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
state.blockdatas = get_chunk_data(&state, CURRENT, BLOCKDATA);
|
||||
state.blockdatas = get_chunk_data(&state, CURRENT, BLOCKDATA, 1);
|
||||
|
||||
left_blocks_py = get_chunk_data(&state, DOWN_LEFT, BLOCKS);
|
||||
left_blocks_py = get_chunk_data(&state, DOWN_LEFT, BLOCKS, 1);
|
||||
state.left_blocks = left_blocks_py;
|
||||
|
||||
right_blocks_py = get_chunk_data(&state, DOWN_RIGHT, BLOCKS);
|
||||
right_blocks_py = get_chunk_data(&state, DOWN_RIGHT, BLOCKS, 1);
|
||||
state.right_blocks = right_blocks_py;
|
||||
|
||||
up_left_blocks_py = get_chunk_data(&state, UP_LEFT, BLOCKS);
|
||||
up_left_blocks_py = get_chunk_data(&state, UP_LEFT, BLOCKS, 1);
|
||||
state.up_left_blocks = up_left_blocks_py;
|
||||
|
||||
up_right_blocks_py = get_chunk_data(&state, UP_RIGHT, BLOCKS);
|
||||
up_right_blocks_py = get_chunk_data(&state, UP_RIGHT, BLOCKS, 1);
|
||||
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 15
|
||||
#define OVERVIEWER_EXTENSION_VERSION 16
|
||||
|
||||
/* Python PIL, and numpy headers */
|
||||
#include <Python.h>
|
||||
@@ -137,7 +137,8 @@ typedef enum
|
||||
UP_RIGHT, /* +1, 0 */
|
||||
UP_LEFT, /* 0, -1 */
|
||||
} ChunkNeighborName;
|
||||
PyObject *get_chunk_data(RenderState *state, ChunkNeighborName neighbor, ChunkDataType type);
|
||||
PyObject *get_chunk_data(RenderState *state, ChunkNeighborName neighbor, ChunkDataType type,
|
||||
unsigned char clearexception);
|
||||
|
||||
/* pull in the rendermode info */
|
||||
#include "rendermodes.h"
|
||||
|
||||
@@ -214,21 +214,19 @@ cave_start(void *data, RenderState *state, PyObject *support) {
|
||||
return 1;
|
||||
|
||||
/* if there's skylight we are in the surface! */
|
||||
self->skylight = get_chunk_data(state, CURRENT, SKYLIGHT);
|
||||
self->left_skylight = get_chunk_data(state, DOWN_LEFT, SKYLIGHT);
|
||||
self->right_skylight = get_chunk_data(state, DOWN_RIGHT, SKYLIGHT);
|
||||
self->up_left_skylight = get_chunk_data(state, UP_LEFT, SKYLIGHT);
|
||||
self->up_right_skylight = get_chunk_data(state, UP_RIGHT, SKYLIGHT);
|
||||
self->skylight = get_chunk_data(state, CURRENT, SKYLIGHT, 1);
|
||||
self->left_skylight = get_chunk_data(state, DOWN_LEFT, SKYLIGHT, 1);
|
||||
self->right_skylight = get_chunk_data(state, DOWN_RIGHT, SKYLIGHT, 1);
|
||||
self->up_left_skylight = get_chunk_data(state, UP_LEFT, SKYLIGHT, 1);
|
||||
self->up_right_skylight = get_chunk_data(state, UP_RIGHT, SKYLIGHT, 1);
|
||||
|
||||
if (self->only_lit) {
|
||||
self->blocklight = get_chunk_data(state, CURRENT, BLOCKLIGHT);
|
||||
self->left_blocklight = get_chunk_data(state, DOWN_LEFT, BLOCKLIGHT);
|
||||
self->right_blocklight = get_chunk_data(state, DOWN_RIGHT, BLOCKLIGHT);
|
||||
self->up_left_blocklight = get_chunk_data(state, UP_LEFT, BLOCKLIGHT);
|
||||
self->up_right_blocklight = get_chunk_data(state, UP_RIGHT, BLOCKLIGHT);
|
||||
self->blocklight = get_chunk_data(state, CURRENT, BLOCKLIGHT, 1);
|
||||
self->left_blocklight = get_chunk_data(state, DOWN_LEFT, BLOCKLIGHT, 1);
|
||||
self->right_blocklight = get_chunk_data(state, DOWN_RIGHT, BLOCKLIGHT, 1);
|
||||
self->up_left_blocklight = get_chunk_data(state, UP_LEFT, BLOCKLIGHT, 1);
|
||||
self->up_right_blocklight = get_chunk_data(state, UP_RIGHT, BLOCKLIGHT, 1);
|
||||
}
|
||||
// Non-existant neighboring blocks is not an error
|
||||
PyErr_Clear();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -359,20 +359,17 @@ lighting_start(void *data, RenderState *state, PyObject *support) {
|
||||
self->facemasks[1] = PyTuple_GetItem(self->facemasks_py, 1);
|
||||
self->facemasks[2] = PyTuple_GetItem(self->facemasks_py, 2);
|
||||
|
||||
self->skylight = get_chunk_data(state, CURRENT, SKYLIGHT);
|
||||
self->blocklight = get_chunk_data(state, CURRENT, BLOCKLIGHT);
|
||||
self->left_skylight = get_chunk_data(state, DOWN_LEFT, SKYLIGHT);
|
||||
self->left_blocklight = get_chunk_data(state, DOWN_LEFT, BLOCKLIGHT);
|
||||
self->right_skylight = get_chunk_data(state, DOWN_RIGHT, SKYLIGHT);
|
||||
self->right_blocklight = get_chunk_data(state, DOWN_RIGHT, BLOCKLIGHT);
|
||||
self->up_left_skylight = get_chunk_data(state, UP_LEFT, SKYLIGHT);
|
||||
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);
|
||||
self->skylight = get_chunk_data(state, CURRENT, SKYLIGHT, 1);
|
||||
self->blocklight = get_chunk_data(state, CURRENT, BLOCKLIGHT, 1);
|
||||
self->left_skylight = get_chunk_data(state, DOWN_LEFT, SKYLIGHT, 1);
|
||||
self->left_blocklight = get_chunk_data(state, DOWN_LEFT, BLOCKLIGHT, 1);
|
||||
self->right_skylight = get_chunk_data(state, DOWN_RIGHT, SKYLIGHT, 1);
|
||||
self->right_blocklight = get_chunk_data(state, DOWN_RIGHT, BLOCKLIGHT, 1);
|
||||
self->up_left_skylight = get_chunk_data(state, UP_LEFT, SKYLIGHT, 1);
|
||||
self->up_left_blocklight = get_chunk_data(state, UP_LEFT, BLOCKLIGHT, 1);
|
||||
self->up_right_skylight = get_chunk_data(state, UP_RIGHT, SKYLIGHT, 1);
|
||||
self->up_right_blocklight = get_chunk_data(state, UP_RIGHT, BLOCKLIGHT, 1);
|
||||
|
||||
// Non-existant neighbor block is not an error
|
||||
PyErr_Clear();
|
||||
|
||||
if (self->night) {
|
||||
self->calculate_light_color = calculate_light_color_night;
|
||||
} else {
|
||||
|
||||
@@ -69,8 +69,8 @@ rendermode_spawn_start(void *data, RenderState *state, PyObject *options) {
|
||||
|
||||
/* now do custom initializations */
|
||||
self = (RenderModeSpawn *)data;
|
||||
self->blocklight = get_chunk_data(state, CURRENT, BLOCKLIGHT);
|
||||
self->skylight = get_chunk_data(state, CURRENT, SKYLIGHT);
|
||||
self->blocklight = get_chunk_data(state, CURRENT, BLOCKLIGHT, 1);
|
||||
self->skylight = get_chunk_data(state, CURRENT, SKYLIGHT, 1);
|
||||
|
||||
/* setup custom color */
|
||||
self->parent.get_color = get_color;
|
||||
|
||||
Reference in New Issue
Block a user