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

@@ -15,9 +15,9 @@ t.generate()
blocks = {}
for blockid in xrange(t.max_blockid):
for data in xrange(t.max_data):
tex = t.blockmap[blockid * t.max_data + data]
for blockid in xrange(textures.max_blockid):
for data in xrange(textures.max_data):
tex = t.blockmap[blockid * textures.max_data + data]
if tex:
if not blockid in blocks:
blocks[blockid] = {}

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

View File

@@ -48,8 +48,6 @@ class Textures(object):
# these are filled in in generate()
self.terrain_images = None
self.max_blockid = 0
self.max_data = 0
self.blockmap = []
self.biome_grass_texture = None
@@ -67,13 +65,11 @@ class Textures(object):
# generate the blocks
global blockmap_generators
global known_blocks, used_datas
self.max_blockid = max(known_blocks) + 1
self.max_data = max(used_datas) + 1
self.blockmap = [None] * self.max_blockid * self.max_data
self.blockmap = [None] * max_blockid * max_data
for (blockid, data), texgen in blockmap_generators.iteritems():
tex = texgen(self, blockid, data)
self.blockmap[blockid * self.max_data + data] = self.generate_texture_tuple(tex)
self.blockmap[blockid * max_data + data] = self.generate_texture_tuple(tex)
if self.texture_size != 24:
# rescale biome grass
@@ -660,6 +656,8 @@ blockmap_generators = {}
known_blocks = set()
used_datas = set()
max_blockid = 0
max_data = 0
transparent_blocks = set()
solid_blocks = set()
@@ -683,6 +681,7 @@ def material(blockid=[], data=[0], **kwargs):
def inner_material(func):
global blockmap_generators
global max_data, max_blockid
# create a wrapper function with a known signature
@functools.wraps(func)
@@ -690,9 +689,14 @@ def material(blockid=[], data=[0], **kwargs):
return func(texobj, blockid, data)
used_datas.update(data)
if max(data) >= max_data:
max_data = max(data) + 1
for block in blockid:
# set the property sets appropriately
known_blocks.update([block])
if block >= max_blockid:
max_blockid = block + 1
for prop in properties:
try:
if block in kwargs.get(prop, []):