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 *chunk_mod = NULL;
static PyObject *blockmap = NULL; static PyObject *blockmap = NULL;
static PyObject *special_blocks = NULL; static PyObject *special_blocks = NULL;
static PyObject *specialblockmap = NULL;
static PyObject *transparent_blocks = NULL; static PyObject *transparent_blocks = NULL;
PyObject *init_chunk_render(PyObject *self, PyObject *args) { 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"); special_blocks = PyObject_GetAttrString(textures, "special_blocks");
if (!special_blocks) if (!special_blocks)
return NULL; return NULL;
specialblockmap = PyObject_GetAttrString(textures, "specialblockmap");
if (!specialblockmap)
return NULL;
transparent_blocks = PyObject_GetAttrString(textures, "transparent_blocks"); transparent_blocks = PyObject_GetAttrString(textures, "transparent_blocks");
if (!transparent_blocks) if (!transparent_blocks)
return NULL; 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; state.imgy = yoff - state.x*6 + state.y*6 + 128*12 + 15*6;
for (state.z = 0; state.z < 128; state.z++) { for (state.z = 0; state.z < 128; state.z++) {
PyObject *tmp;
unsigned char ancilData;
state.imgy -= 12; state.imgy -= 12;
/* get blockid */ /* get blockid */
@@ -403,47 +402,39 @@ chunk_render(PyObject *self, PyObject *args) {
} }
blockid = PyInt_FromLong(state.block); blockid = PyInt_FromLong(state.block);
// check for occlusion /* check for occlusion */
if (render_mode_occluded(rendermode, state.x, state.y, state.z)) { if (render_mode_occluded(rendermode, state.x, state.y, state.z)) {
continue; 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 */ ancilData = getArrayByte3D(state.blockdata_expanded, state.x, state.y, state.z);
if (!PySequence_Contains(special_blocks, blockid)) { state.block_data = ancilData;
/* t = textures.blockmap[blockid] */ /* block that need pseudo ancildata:
t = PyList_GetItem(blockmap, state.block); * grass, water, glass, chest, restone wire,
* ice, fence, portal, iron bars, glass panes */
if ((state.block == 2) || (state.block == 9) ||
(state.block == 20) || (state.block == 54) ||
(state.block == 55) || (state.block == 79) ||
(state.block == 85) || (state.block == 90) ||
(state.block == 101) || (state.block == 102)) {
ancilData = generate_pseudo_data(&state, ancilData);
state.block_pdata = ancilData;
} else { } else {
PyObject *tmp; state.block_pdata = 0;
unsigned char 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,
* ice, fence, portal, iron bars, glass panes */
if ((state.block == 2) || (state.block == 9) ||
(state.block == 20) || (state.block == 54) ||
(state.block == 55) || (state.block == 79) ||
(state.block == 85) || (state.block == 90) ||
(state.block == 101) || (state.block == 102)) {
ancilData = generate_pseudo_data(&state, ancilData);
state.block_pdata = ancilData;
} else {
state.block_pdata = 0;
}
tmp = PyTuple_New(2);
Py_INCREF(blockid); /* because SetItem steals */
PyTuple_SetItem(tmp, 0, blockid);
PyTuple_SetItem(tmp, 1, PyInt_FromLong(ancilData));
/* this is a borrowed reference. no need to decref */
t = PyDict_GetItem(specialblockmap, tmp);
Py_DECREF(tmp);
} }
tmp = PyTuple_New(2);
Py_INCREF(blockid); /* because SetItem steals */
PyTuple_SetItem(tmp, 0, blockid);
PyTuple_SetItem(tmp, 1, PyInt_FromLong(ancilData));
/* this is a borrowed reference. no need to decref */
t = PyDict_GetItem(blockmap, tmp);
Py_DECREF(tmp);
/* if we found a proper texture, render it! */ /* if we found a proper texture, render it! */
if (t != NULL && t != Py_None) 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.""" Block 8, flowing water, is given a full 3 sided cube."""
watertexture = _load_image("water.png") 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") 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) lavablock = _build_block(lavatexture, lavatexture)
blockmap[10] = generate_texture_tuple(lavablock,10) lava = generate_texture_tuple(lavablock,10)
blockmap[11] = blockmap[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): def generate_opaque_mask(img):
""" Takes the alpha channel of the image and generates a mask """ 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): def generate_texture_tuple(img, blockid):
""" This takes an image and returns the needed tuple for the """ This takes an image and returns the needed tuple for the
blockmap list and specialblockmap dictionary.""" blockmap dictionary."""
return (img, generate_opaque_mask(img)) return (img, generate_opaque_mask(img))
def generate_special_texture(blockID, data): def generate_special_texture(blockID, data):
@@ -2425,7 +2432,6 @@ bgcolor = None
terrain_images = None terrain_images = None
blockmap = None blockmap = None
biome_grass_texture = None biome_grass_texture = None
specialblockmap = None
def generate(path=None,texture_size=24,bgc = (26,26,26,0),north_direction='lower-left'): def generate(path=None,texture_size=24,bgc = (26,26,26,0),north_direction='lower-left'):
global _north 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 # generate the normal blocks
global blockmap global blockmap
blockmap = _build_blockimages() blockmap = {}
for blockID, t in enumerate(_build_blockimages()):
blockmap[(blockID, 0)] = t
load_water() load_water()
# generate biome grass mask # 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) biome_grass_texture = _build_block(terrain_images[0], terrain_images[38], 2)
# generate the special blocks # generate the special blocks
global specialblockmap, special_blocks global special_blocks
specialblockmap = {}
for blockID in special_blocks: for blockID in special_blocks:
for data in special_map[blockID]: 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: if texture_size != 24:
# rescale biome textures. # rescale biome textures.
biome_grass_texture = biome_grass_texture.resize(texture_dimensions, Image.ANTIALIAS) 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 # rescale the special block images
for blockid, data in iter(specialblockmap): for blockid, data in iter(blockmap):
block = specialblockmap[(blockid,data)] block = blockmap[(blockid,data)]
if block != None: if block != None:
alpha = block[1]
block = block[0] block = block[0]
block.putalpha(alpha)
scaled_block = block.resize(texture_dimensions, Image.ANTIALIAS) 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)