diff --git a/contrib/gallery.py b/contrib/gallery.py index a7882d0..b4db318 100644 --- a/contrib/gallery.py +++ b/contrib/gallery.py @@ -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] = {} diff --git a/overviewer_core/src/iterate.c b/overviewer_core/src/iterate.c index adc790d..0e91f35 100644 --- a/overviewer_core/src/iterate.c +++ b/overviewer_core/src/iterate.c @@ -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); diff --git a/overviewer_core/src/overviewer.h b/overviewer_core/src/overviewer.h index 0e45a2f..e1cbaf3 100644 --- a/overviewer_core/src/overviewer.h +++ b/overviewer_core/src/overviewer.h @@ -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; diff --git a/overviewer_core/src/rendermode-normal.c b/overviewer_core/src/rendermode-normal.c index dfa660f..4d1f6a9 100644 --- a/overviewer_core/src/rendermode-normal.c +++ b/overviewer_core/src/rendermode-normal.c @@ -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) { diff --git a/overviewer_core/textures.py b/overviewer_core/textures.py index d8965fe..6de8101 100644 --- a/overviewer_core/textures.py +++ b/overviewer_core/textures.py @@ -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, []):