initial update of C code to work with textures object
This commit is contained in:
@@ -15,9 +15,9 @@ t.generate()
|
|||||||
|
|
||||||
blocks = {}
|
blocks = {}
|
||||||
|
|
||||||
for blockid in xrange(t.max_blockid):
|
for blockid in xrange(textures.max_blockid):
|
||||||
for data in xrange(t.max_data):
|
for data in xrange(textures.max_data):
|
||||||
tex = t.blockmap[blockid * t.max_data + data]
|
tex = t.blockmap[blockid * textures.max_data + data]
|
||||||
if tex:
|
if tex:
|
||||||
if not blockid in blocks:
|
if not blockid in blocks:
|
||||||
blocks[blockid] = {}
|
blocks[blockid] = {}
|
||||||
|
|||||||
@@ -18,8 +18,6 @@
|
|||||||
#include "overviewer.h"
|
#include "overviewer.h"
|
||||||
|
|
||||||
static PyObject *textures = NULL;
|
static PyObject *textures = NULL;
|
||||||
static PyObject *chunk_mod = NULL;
|
|
||||||
static PyObject *blockmap = NULL;
|
|
||||||
|
|
||||||
unsigned int max_blockid = 0;
|
unsigned int max_blockid = 0;
|
||||||
unsigned int max_data = 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
|
/* this function only needs to be called once, anything more should be
|
||||||
* ignored */
|
* ignored */
|
||||||
if (blockmap) {
|
if (textures) {
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,16 +46,6 @@ PyObject *init_chunk_render(PyObject *self, PyObject *args) {
|
|||||||
return NULL;
|
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");
|
tmp = PyObject_GetAttrString(textures, "max_blockid");
|
||||||
if (!tmp)
|
if (!tmp)
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -69,7 +57,7 @@ PyObject *init_chunk_render(PyObject *self, PyObject *args) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
max_data = PyInt_AsLong(tmp);
|
max_data = PyInt_AsLong(tmp);
|
||||||
Py_DECREF(tmp);
|
Py_DECREF(tmp);
|
||||||
|
|
||||||
/* assemble the property table */
|
/* assemble the property table */
|
||||||
known_blocks = PyObject_GetAttrString(textures, "known_blocks");
|
known_blocks = PyObject_GetAttrString(textures, "known_blocks");
|
||||||
if (!known_blocks)
|
if (!known_blocks)
|
||||||
@@ -345,6 +333,7 @@ PyObject*
|
|||||||
chunk_render(PyObject *self, PyObject *args) {
|
chunk_render(PyObject *self, PyObject *args) {
|
||||||
RenderState state;
|
RenderState state;
|
||||||
PyObject *rendermode_py;
|
PyObject *rendermode_py;
|
||||||
|
PyObject *blockmap;
|
||||||
|
|
||||||
int xoff, yoff;
|
int xoff, yoff;
|
||||||
|
|
||||||
@@ -361,13 +350,9 @@ chunk_render(PyObject *self, PyObject *args) {
|
|||||||
|
|
||||||
PyObject *t = NULL;
|
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;
|
return NULL;
|
||||||
|
|
||||||
/* fill in important modules */
|
|
||||||
state.textures = textures;
|
|
||||||
state.chunk = chunk_mod;
|
|
||||||
|
|
||||||
/* set up the render mode */
|
/* set up the render mode */
|
||||||
rendermode_py = PyObject_GetAttrString(state.self, "rendermode");
|
rendermode_py = PyObject_GetAttrString(state.self, "rendermode");
|
||||||
state.rendermode = rendermode = render_mode_create(PyString_AsString(rendermode_py), &state);
|
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
|
// 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 */
|
/* get the image size */
|
||||||
imgsize = PyObject_GetAttrString(state.img, "size");
|
imgsize = PyObject_GetAttrString(state.img, "size");
|
||||||
|
|
||||||
@@ -389,7 +389,6 @@ chunk_render(PyObject *self, PyObject *args) {
|
|||||||
Py_DECREF(imgsize0_py);
|
Py_DECREF(imgsize0_py);
|
||||||
Py_DECREF(imgsize1_py);
|
Py_DECREF(imgsize1_py);
|
||||||
|
|
||||||
|
|
||||||
/* get the block data directly from numpy: */
|
/* get the block data directly from numpy: */
|
||||||
blocks_py = PyObject_GetAttrString(state.self, "blocks");
|
blocks_py = PyObject_GetAttrString(state.self, "blocks");
|
||||||
state.blocks = blocks_py;
|
state.blocks = blocks_py;
|
||||||
@@ -444,7 +443,7 @@ chunk_render(PyObject *self, PyObject *args) {
|
|||||||
|
|
||||||
/* everything stored here will be a borrowed ref */
|
/* 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;
|
state.block_data = ancilData;
|
||||||
/* block that need pseudo ancildata:
|
/* block that need pseudo ancildata:
|
||||||
* grass, water, glass, chest, restone wire,
|
* grass, water, glass, chest, restone wire,
|
||||||
@@ -504,6 +503,7 @@ chunk_render(PyObject *self, PyObject *args) {
|
|||||||
render_mode_destroy(rendermode);
|
render_mode_destroy(rendermode);
|
||||||
|
|
||||||
Py_DECREF(blocks_py);
|
Py_DECREF(blocks_py);
|
||||||
|
Py_DECREF(blockmap);
|
||||||
Py_XDECREF(left_blocks_py);
|
Py_XDECREF(left_blocks_py);
|
||||||
Py_XDECREF(right_blocks_py);
|
Py_XDECREF(right_blocks_py);
|
||||||
Py_XDECREF(up_left_blocks_py);
|
Py_XDECREF(up_left_blocks_py);
|
||||||
|
|||||||
@@ -65,18 +65,16 @@ typedef struct _RenderMode RenderMode;
|
|||||||
|
|
||||||
/* in iterate.c */
|
/* in iterate.c */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/* the ChunkRenderer object */
|
/* the ChunkRenderer object, and the chunk module */
|
||||||
PyObject *self;
|
PyObject *self;
|
||||||
|
|
||||||
/* important modules, for convenience */
|
|
||||||
PyObject *textures;
|
|
||||||
PyObject *chunk;
|
PyObject *chunk;
|
||||||
|
|
||||||
|
/* the Texture object */
|
||||||
|
PyObject *textures;
|
||||||
|
|
||||||
/* the current render mode in use */
|
/* the current render mode in use */
|
||||||
RenderMode *rendermode;
|
RenderMode *rendermode;
|
||||||
|
|
||||||
/* the rest only make sense for occluded() and draw() !! */
|
|
||||||
|
|
||||||
/* the tile image and destination */
|
/* the tile image and destination */
|
||||||
PyObject *img;
|
PyObject *img;
|
||||||
int imgx, imgy;
|
int imgx, imgy;
|
||||||
@@ -86,7 +84,9 @@ typedef struct {
|
|||||||
unsigned char block;
|
unsigned char block;
|
||||||
unsigned char block_data;
|
unsigned char block_data;
|
||||||
unsigned char block_pdata;
|
unsigned char block_pdata;
|
||||||
PyObject *blockdata_expanded;
|
|
||||||
|
/* useful information about this, and neighboring, chunks */
|
||||||
|
PyObject *blockdatas;
|
||||||
PyObject *blocks;
|
PyObject *blocks;
|
||||||
PyObject *up_left_blocks;
|
PyObject *up_left_blocks;
|
||||||
PyObject *up_right_blocks;
|
PyObject *up_right_blocks;
|
||||||
|
|||||||
@@ -74,7 +74,8 @@ rendermode_normal_start(void *data, RenderState *state, PyObject *options) {
|
|||||||
use_biomes = PyObject_GetAttrString(world, "useBiomeData");
|
use_biomes = PyObject_GetAttrString(world, "useBiomeData");
|
||||||
Py_DECREF(world);
|
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",
|
self->biome_data = PyObject_CallMethod(state->textures, "getBiomeData", "OOO",
|
||||||
worlddir, chunk_x_py, chunk_y_py);
|
worlddir, chunk_x_py, chunk_y_py);
|
||||||
if (self->biome_data == Py_None) {
|
if (self->biome_data == Py_None) {
|
||||||
|
|||||||
@@ -48,8 +48,6 @@ class Textures(object):
|
|||||||
|
|
||||||
# these are filled in in generate()
|
# these are filled in in generate()
|
||||||
self.terrain_images = None
|
self.terrain_images = None
|
||||||
self.max_blockid = 0
|
|
||||||
self.max_data = 0
|
|
||||||
self.blockmap = []
|
self.blockmap = []
|
||||||
self.biome_grass_texture = None
|
self.biome_grass_texture = None
|
||||||
|
|
||||||
@@ -67,13 +65,11 @@ class Textures(object):
|
|||||||
# generate the blocks
|
# generate the blocks
|
||||||
global blockmap_generators
|
global blockmap_generators
|
||||||
global known_blocks, used_datas
|
global known_blocks, used_datas
|
||||||
self.max_blockid = max(known_blocks) + 1
|
self.blockmap = [None] * max_blockid * max_data
|
||||||
self.max_data = max(used_datas) + 1
|
|
||||||
self.blockmap = [None] * self.max_blockid * self.max_data
|
|
||||||
|
|
||||||
for (blockid, data), texgen in blockmap_generators.iteritems():
|
for (blockid, data), texgen in blockmap_generators.iteritems():
|
||||||
tex = texgen(self, blockid, data)
|
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:
|
if self.texture_size != 24:
|
||||||
# rescale biome grass
|
# rescale biome grass
|
||||||
@@ -660,6 +656,8 @@ blockmap_generators = {}
|
|||||||
|
|
||||||
known_blocks = set()
|
known_blocks = set()
|
||||||
used_datas = set()
|
used_datas = set()
|
||||||
|
max_blockid = 0
|
||||||
|
max_data = 0
|
||||||
|
|
||||||
transparent_blocks = set()
|
transparent_blocks = set()
|
||||||
solid_blocks = set()
|
solid_blocks = set()
|
||||||
@@ -683,6 +681,7 @@ def material(blockid=[], data=[0], **kwargs):
|
|||||||
|
|
||||||
def inner_material(func):
|
def inner_material(func):
|
||||||
global blockmap_generators
|
global blockmap_generators
|
||||||
|
global max_data, max_blockid
|
||||||
|
|
||||||
# create a wrapper function with a known signature
|
# create a wrapper function with a known signature
|
||||||
@functools.wraps(func)
|
@functools.wraps(func)
|
||||||
@@ -690,9 +689,14 @@ def material(blockid=[], data=[0], **kwargs):
|
|||||||
return func(texobj, blockid, data)
|
return func(texobj, blockid, data)
|
||||||
|
|
||||||
used_datas.update(data)
|
used_datas.update(data)
|
||||||
|
if max(data) >= max_data:
|
||||||
|
max_data = max(data) + 1
|
||||||
|
|
||||||
for block in blockid:
|
for block in blockid:
|
||||||
# set the property sets appropriately
|
# set the property sets appropriately
|
||||||
known_blocks.update([block])
|
known_blocks.update([block])
|
||||||
|
if block >= max_blockid:
|
||||||
|
max_blockid = block + 1
|
||||||
for prop in properties:
|
for prop in properties:
|
||||||
try:
|
try:
|
||||||
if block in kwargs.get(prop, []):
|
if block in kwargs.get(prop, []):
|
||||||
|
|||||||
Reference in New Issue
Block a user