0

initial update of C code to work with textures object

This commit is contained in:
Aaron Griffith
2012-01-01 20:50:20 -05:00
parent c4a183b9b0
commit f9b0f8667b
5 changed files with 43 additions and 38 deletions

View File

@@ -18,8 +18,6 @@
#include "overviewer.h"
static PyObject *textures = NULL;
static PyObject *chunk_mod = NULL;
static PyObject *blockmap = NULL;
unsigned int max_blockid = 0;
unsigned int max_data = 0;
@@ -38,7 +36,7 @@ PyObject *init_chunk_render(PyObject *self, PyObject *args) {
/* this function only needs to be called once, anything more should be
* ignored */
if (blockmap) {
if (textures) {
Py_RETURN_NONE;
}
@@ -48,16 +46,6 @@ PyObject *init_chunk_render(PyObject *self, PyObject *args) {
return NULL;
}
chunk_mod = PyImport_ImportModule("overviewer_core.chunk");
/* ensure none of these pointers are NULL */
if ((!chunk_mod)) {
return NULL;
}
blockmap = PyObject_GetAttrString(textures, "blockmap");
if (!blockmap)
return NULL;
tmp = PyObject_GetAttrString(textures, "max_blockid");
if (!tmp)
return NULL;
@@ -69,7 +57,7 @@ PyObject *init_chunk_render(PyObject *self, PyObject *args) {
return NULL;
max_data = PyInt_AsLong(tmp);
Py_DECREF(tmp);
/* assemble the property table */
known_blocks = PyObject_GetAttrString(textures, "known_blocks");
if (!known_blocks)
@@ -345,6 +333,7 @@ PyObject*
chunk_render(PyObject *self, PyObject *args) {
RenderState state;
PyObject *rendermode_py;
PyObject *blockmap;
int xoff, yoff;
@@ -361,13 +350,9 @@ chunk_render(PyObject *self, PyObject *args) {
PyObject *t = NULL;
if (!PyArg_ParseTuple(args, "OOiiO", &state.self, &state.img, &xoff, &yoff, &state.blockdata_expanded))
if (!PyArg_ParseTuple(args, "OOiiO", &state.self, &state.img, &xoff, &yoff, &state.textures, &state.blockdatas))
return NULL;
/* fill in important modules */
state.textures = textures;
state.chunk = chunk_mod;
/* set up the render mode */
rendermode_py = PyObject_GetAttrString(state.self, "rendermode");
state.rendermode = rendermode = render_mode_create(PyString_AsString(rendermode_py), &state);
@@ -377,6 +362,21 @@ chunk_render(PyObject *self, PyObject *args) {
// set PyErr. No need to set it here
}
/* get the blockmap from the textures object */
blockmap = PyObject_GetAttr(state.textures, "blockmap");
if (blockmap == NULL)
return NULL;
if (blockmap == Py_None) {
PyErr_SetString(PyExc_RuntimeError, "you must call Textures.generate()");
return NULL;
}
/* get the chunk module */
state.chunk = PyImport_ImportModule("overviewer_core.chunk");
if (state.chunk == NULL) {
return NULL;
}
/* get the image size */
imgsize = PyObject_GetAttrString(state.img, "size");
@@ -389,7 +389,6 @@ chunk_render(PyObject *self, PyObject *args) {
Py_DECREF(imgsize0_py);
Py_DECREF(imgsize1_py);
/* get the block data directly from numpy: */
blocks_py = PyObject_GetAttrString(state.self, "blocks");
state.blocks = blocks_py;
@@ -444,7 +443,7 @@ chunk_render(PyObject *self, PyObject *args) {
/* everything stored here will be a borrowed ref */
ancilData = getArrayByte3D(state.blockdata_expanded, state.x, state.y, state.z);
ancilData = getArrayByte3D(state.blockdatas, state.x, state.y, state.z);
state.block_data = ancilData;
/* block that need pseudo ancildata:
* grass, water, glass, chest, restone wire,
@@ -504,6 +503,7 @@ chunk_render(PyObject *self, PyObject *args) {
render_mode_destroy(rendermode);
Py_DECREF(blocks_py);
Py_DECREF(blockmap);
Py_XDECREF(left_blocks_py);
Py_XDECREF(right_blocks_py);
Py_XDECREF(up_left_blocks_py);

View File

@@ -65,18 +65,16 @@ typedef struct _RenderMode RenderMode;
/* in iterate.c */
typedef struct {
/* the ChunkRenderer object */
/* the ChunkRenderer object, and the chunk module */
PyObject *self;
/* important modules, for convenience */
PyObject *textures;
PyObject *chunk;
/* the Texture object */
PyObject *textures;
/* the current render mode in use */
RenderMode *rendermode;
/* the rest only make sense for occluded() and draw() !! */
/* the tile image and destination */
PyObject *img;
int imgx, imgy;
@@ -86,7 +84,9 @@ typedef struct {
unsigned char block;
unsigned char block_data;
unsigned char block_pdata;
PyObject *blockdata_expanded;
/* useful information about this, and neighboring, chunks */
PyObject *blockdatas;
PyObject *blocks;
PyObject *up_left_blocks;
PyObject *up_right_blocks;

View File

@@ -74,7 +74,8 @@ rendermode_normal_start(void *data, RenderState *state, PyObject *options) {
use_biomes = PyObject_GetAttrString(world, "useBiomeData");
Py_DECREF(world);
if (PyObject_IsTrue(use_biomes)) {
/* XXX ignore biomes for now :( */
if (0/*PyObject_IsTrue(use_biomes)*/) {
self->biome_data = PyObject_CallMethod(state->textures, "getBiomeData", "OOO",
worlddir, chunk_x_py, chunk_y_py);
if (self->biome_data == Py_None) {