0

unified blockmap and specialblockmap (Issue #516)

This commit is contained in:
Aaron Griffith
2011-10-31 13:58:25 -04:00
parent 75858f2df8
commit 8e0a82ba62
2 changed files with 52 additions and 65 deletions

View File

@@ -21,7 +21,6 @@ static PyObject *textures = NULL;
static PyObject *chunk_mod = NULL;
static PyObject *blockmap = NULL;
static PyObject *special_blocks = NULL;
static PyObject *specialblockmap = NULL;
static PyObject *transparent_blocks = NULL;
PyObject *init_chunk_render(PyObject *self, PyObject *args) {
@@ -50,9 +49,6 @@ PyObject *init_chunk_render(PyObject *self, PyObject *args) {
special_blocks = PyObject_GetAttrString(textures, "special_blocks");
if (!special_blocks)
return NULL;
specialblockmap = PyObject_GetAttrString(textures, "specialblockmap");
if (!specialblockmap)
return NULL;
transparent_blocks = PyObject_GetAttrString(textures, "transparent_blocks");
if (!transparent_blocks)
return NULL;
@@ -380,6 +376,9 @@ chunk_render(PyObject *self, PyObject *args) {
state.imgy = yoff - state.x*6 + state.y*6 + 128*12 + 15*6;
for (state.z = 0; state.z < 128; state.z++) {
PyObject *tmp;
unsigned char ancilData;
state.imgy -= 12;
/* get blockid */
@@ -403,21 +402,14 @@ chunk_render(PyObject *self, PyObject *args) {
}
blockid = PyInt_FromLong(state.block);
// check for occlusion
/* check for occlusion */
if (render_mode_occluded(rendermode, state.x, state.y, state.z)) {
continue;
}
// everything stored here will be a borrowed ref
/* everything stored here will be a borrowed ref */
/* get the texture and mask from block type / ancil. data */
if (!PySequence_Contains(special_blocks, blockid)) {
/* t = textures.blockmap[blockid] */
t = PyList_GetItem(blockmap, state.block);
} else {
PyObject *tmp;
unsigned char ancilData = getArrayByte3D(state.blockdata_expanded, state.x, state.y, state.z);
ancilData = getArrayByte3D(state.blockdata_expanded, state.x, state.y, state.z);
state.block_data = ancilData;
/* block that need pseudo ancildata:
* grass, water, glass, chest, restone wire,
@@ -440,9 +432,8 @@ chunk_render(PyObject *self, PyObject *args) {
PyTuple_SetItem(tmp, 1, PyInt_FromLong(ancilData));
/* this is a borrowed reference. no need to decref */
t = PyDict_GetItem(specialblockmap, tmp);
t = PyDict_GetItem(blockmap, tmp);
Py_DECREF(tmp);
}
/* if we found a proper texture, render it! */
if (t != NULL && t != Py_None)

View File

@@ -496,15 +496,22 @@ def load_water():
Block 8, flowing water, is given a full 3 sided cube."""
watertexture = _load_image("water.png")
w1 = _build_block(watertexture, None)
blockmap[9] = generate_texture_tuple(w1,9)
w2 = _build_block(watertexture, watertexture)
blockmap[8] = generate_texture_tuple(w2,8)
lavatexture = _load_image("lava.png")
w1 = _build_block(watertexture, None)
w1 = generate_texture_tuple(w1,9)
w2 = _build_block(watertexture, watertexture)
w2 = generate_texture_tuple(w2,8)
lavablock = _build_block(lavatexture, lavatexture)
blockmap[10] = generate_texture_tuple(lavablock,10)
blockmap[11] = blockmap[10]
lava = generate_texture_tuple(lavablock,10)
for data in range(16):
blockmap[(9, data)] = w1
blockmap[(8, data)] = w2
blockmap[(10, data)] = lava
blockmap[(11, data)] = lava
def generate_opaque_mask(img):
""" Takes the alpha channel of the image and generates a mask
@@ -516,7 +523,7 @@ def generate_opaque_mask(img):
def generate_texture_tuple(img, blockid):
""" This takes an image and returns the needed tuple for the
blockmap list and specialblockmap dictionary."""
blockmap dictionary."""
return (img, generate_opaque_mask(img))
def generate_special_texture(blockID, data):
@@ -2425,7 +2432,6 @@ bgcolor = None
terrain_images = None
blockmap = None
biome_grass_texture = None
specialblockmap = None
def generate(path=None,texture_size=24,bgc = (26,26,26,0),north_direction='lower-left'):
global _north
@@ -2443,7 +2449,10 @@ def generate(path=None,texture_size=24,bgc = (26,26,26,0),north_direction='lower
# generate the normal blocks
global blockmap
blockmap = _build_blockimages()
blockmap = {}
for blockID, t in enumerate(_build_blockimages()):
blockmap[(blockID, 0)] = t
load_water()
# generate biome grass mask
@@ -2451,32 +2460,19 @@ def generate(path=None,texture_size=24,bgc = (26,26,26,0),north_direction='lower
biome_grass_texture = _build_block(terrain_images[0], terrain_images[38], 2)
# generate the special blocks
global specialblockmap, special_blocks
specialblockmap = {}
global special_blocks
for blockID in special_blocks:
for data in special_map[blockID]:
specialblockmap[(blockID, data)] = generate_special_texture(blockID, data)
blockmap[(blockID, data)] = generate_special_texture(blockID, data)
if texture_size != 24:
# rescale biome textures.
biome_grass_texture = biome_grass_texture.resize(texture_dimensions, Image.ANTIALIAS)
# rescale the normal block images
for i in range(len(blockmap)):
if blockmap[i] != None:
block = blockmap[i]
alpha = block[1]
block = block[0]
block.putalpha(alpha)
scaled_block = block.resize(texture_dimensions, Image.ANTIALIAS)
blockmap[i] = generate_texture_tuple(scaled_block, i)
# rescale the special block images
for blockid, data in iter(specialblockmap):
block = specialblockmap[(blockid,data)]
for blockid, data in iter(blockmap):
block = blockmap[(blockid,data)]
if block != None:
alpha = block[1]
block = block[0]
block.putalpha(alpha)
scaled_block = block.resize(texture_dimensions, Image.ANTIALIAS)
specialblockmap[(blockid,data)] = generate_texture_tuple(scaled_block, blockid)
blockmap[(blockid,data)] = generate_texture_tuple(scaled_block, blockid)