Add .clang_format
Also applies clang-format to the current code base, using command:
`find . -regex '.*\.\(c\|h\)' -exec clang-format -style=file -i {} \;`
This commit is contained in:
@@ -15,39 +15,39 @@
|
||||
* with the Overviewer. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "overviewer.h"
|
||||
#include "mc_id.h"
|
||||
#include "block_class.h"
|
||||
#include "mc_id.h"
|
||||
#include "overviewer.h"
|
||||
|
||||
static PyObject *textures = NULL;
|
||||
static PyObject* textures = NULL;
|
||||
|
||||
unsigned int max_blockid = 0;
|
||||
unsigned int max_data = 0;
|
||||
unsigned char *block_properties = NULL;
|
||||
unsigned char* block_properties = NULL;
|
||||
|
||||
static PyObject *known_blocks = NULL;
|
||||
static PyObject *transparent_blocks = NULL;
|
||||
static PyObject *solid_blocks = NULL;
|
||||
static PyObject *fluid_blocks = NULL;
|
||||
static PyObject *nospawn_blocks = NULL;
|
||||
static PyObject *nodata_blocks = NULL;
|
||||
static PyObject* known_blocks = NULL;
|
||||
static PyObject* transparent_blocks = NULL;
|
||||
static PyObject* solid_blocks = NULL;
|
||||
static PyObject* fluid_blocks = NULL;
|
||||
static PyObject* nospawn_blocks = NULL;
|
||||
static PyObject* nodata_blocks = NULL;
|
||||
|
||||
PyObject *init_chunk_render(void) {
|
||||
|
||||
PyObject *tmp = NULL;
|
||||
PyObject* init_chunk_render(void) {
|
||||
|
||||
PyObject* tmp = NULL;
|
||||
unsigned int i;
|
||||
|
||||
|
||||
/* this function only needs to be called once, anything more should be
|
||||
* ignored */
|
||||
if (textures) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
textures = PyImport_ImportModule("overviewer_core.textures");
|
||||
/* ensure none of these pointers are NULL */
|
||||
/* ensure none of these pointers are NULL */
|
||||
if ((!textures)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
tmp = PyObject_GetAttrString(textures, "max_blockid");
|
||||
if (!tmp)
|
||||
return NULL;
|
||||
@@ -79,11 +79,11 @@ PyObject *init_chunk_render(void) {
|
||||
nodata_blocks = PyObject_GetAttrString(textures, "nodata_blocks");
|
||||
if (!nodata_blocks)
|
||||
return NULL;
|
||||
|
||||
|
||||
block_properties = calloc(max_blockid, sizeof(unsigned char));
|
||||
for (i = 0; i < max_blockid; i++) {
|
||||
PyObject *block = PyLong_FromLong(i);
|
||||
|
||||
PyObject* block = PyLong_FromLong(i);
|
||||
|
||||
if (PySequence_Contains(known_blocks, block))
|
||||
block_properties[i] |= 1 << KNOWN;
|
||||
if (PySequence_Contains(transparent_blocks, block))
|
||||
@@ -96,19 +96,19 @@ PyObject *init_chunk_render(void) {
|
||||
block_properties[i] |= 1 << NOSPAWN;
|
||||
if (PySequence_Contains(nodata_blocks, block))
|
||||
block_properties[i] |= 1 << NODATA;
|
||||
|
||||
|
||||
Py_DECREF(block);
|
||||
}
|
||||
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
/* helper for load_chunk, loads a section into a chunk */
|
||||
static inline void load_chunk_section(ChunkData *dest, int i, PyObject *section) {
|
||||
dest->sections[i].blocks = (PyArrayObject*) PyDict_GetItemString(section, "Blocks");
|
||||
dest->sections[i].data = (PyArrayObject*) PyDict_GetItemString(section, "Data");
|
||||
dest->sections[i].skylight = (PyArrayObject*) PyDict_GetItemString(section, "SkyLight");
|
||||
dest->sections[i].blocklight = (PyArrayObject*) PyDict_GetItemString(section, "BlockLight");
|
||||
static inline void load_chunk_section(ChunkData* dest, int i, PyObject* section) {
|
||||
dest->sections[i].blocks = (PyArrayObject*)PyDict_GetItemString(section, "Blocks");
|
||||
dest->sections[i].data = (PyArrayObject*)PyDict_GetItemString(section, "Data");
|
||||
dest->sections[i].skylight = (PyArrayObject*)PyDict_GetItemString(section, "SkyLight");
|
||||
dest->sections[i].blocklight = (PyArrayObject*)PyDict_GetItemString(section, "BlockLight");
|
||||
Py_INCREF(dest->sections[i].blocks);
|
||||
Py_INCREF(dest->sections[i].data);
|
||||
Py_INCREF(dest->sections[i].skylight);
|
||||
@@ -122,25 +122,24 @@ static inline void load_chunk_section(ChunkData *dest, int i, PyObject *section)
|
||||
* exception and return true.
|
||||
*/
|
||||
int load_chunk(RenderState* state, int x, int z, unsigned char required) {
|
||||
ChunkData *dest = &(state->chunks[1 + x][1 + z]);
|
||||
ChunkData* dest = &(state->chunks[1 + x][1 + z]);
|
||||
int i;
|
||||
PyObject *chunk = NULL;
|
||||
PyObject *sections = NULL;
|
||||
|
||||
PyObject* chunk = NULL;
|
||||
PyObject* sections = NULL;
|
||||
|
||||
if (dest->loaded)
|
||||
return 0;
|
||||
|
||||
|
||||
/* set up reasonable defaults */
|
||||
dest->biomes = NULL;
|
||||
for (i = 0; i < SECTIONS_PER_CHUNK; i++)
|
||||
{
|
||||
for (i = 0; i < SECTIONS_PER_CHUNK; i++) {
|
||||
dest->sections[i].blocks = NULL;
|
||||
dest->sections[i].data = NULL;
|
||||
dest->sections[i].skylight = NULL;
|
||||
dest->sections[i].blocklight = NULL;
|
||||
}
|
||||
dest->loaded = 1;
|
||||
|
||||
|
||||
x += state->chunkx;
|
||||
z += state->chunkz;
|
||||
|
||||
@@ -166,31 +165,31 @@ int load_chunk(RenderState* state, int x, int z, unsigned char required) {
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
dest->biomes = (PyArrayObject*) PyDict_GetItemString(chunk, "Biomes");
|
||||
|
||||
dest->biomes = (PyArrayObject*)PyDict_GetItemString(chunk, "Biomes");
|
||||
Py_INCREF(dest->biomes);
|
||||
|
||||
|
||||
for (i = 0; i < PySequence_Fast_GET_SIZE(sections); i++) {
|
||||
PyObject *ycoord = NULL;
|
||||
PyObject* ycoord = NULL;
|
||||
int sectiony = 0;
|
||||
PyObject *section = PySequence_Fast_GET_ITEM(sections, i);
|
||||
PyObject* section = PySequence_Fast_GET_ITEM(sections, i);
|
||||
ycoord = PyDict_GetItemString(section, "Y");
|
||||
if (!ycoord)
|
||||
continue;
|
||||
|
||||
|
||||
sectiony = PyLong_AsLong(ycoord);
|
||||
if (sectiony >= 0 && sectiony < SECTIONS_PER_CHUNK)
|
||||
load_chunk_section(dest, sectiony, section);
|
||||
}
|
||||
Py_DECREF(sections);
|
||||
Py_DECREF(chunk);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* helper to unload all loaded chunks */
|
||||
static void
|
||||
unload_all_chunks(RenderState *state) {
|
||||
unload_all_chunks(RenderState* state) {
|
||||
unsigned int i, j, k;
|
||||
for (i = 0; i < 3; i++) {
|
||||
for (j = 0; j < 3; j++) {
|
||||
@@ -209,7 +208,7 @@ unload_all_chunks(RenderState *state) {
|
||||
}
|
||||
|
||||
unsigned short
|
||||
check_adjacent_blocks(RenderState *state, int x,int y,int z, unsigned short blockid) {
|
||||
check_adjacent_blocks(RenderState* state, int x, int y, int z, unsigned short blockid) {
|
||||
/*
|
||||
* Generates a pseudo ancillary data for blocks that depend of
|
||||
* what are surrounded and don't have ancillary data. This
|
||||
@@ -225,27 +224,27 @@ check_adjacent_blocks(RenderState *state, int x,int y,int z, unsigned short bloc
|
||||
* Example: if the bit1 is 1 that means that there is a block with
|
||||
* blockid in the side of the +x direction.
|
||||
*/
|
||||
|
||||
unsigned char pdata=0;
|
||||
|
||||
|
||||
unsigned char pdata = 0;
|
||||
|
||||
if (get_data(state, BLOCKS, x + 1, y, z) == blockid) {
|
||||
pdata = pdata|(1 << 3);
|
||||
}
|
||||
pdata = pdata | (1 << 3);
|
||||
}
|
||||
if (get_data(state, BLOCKS, x, y, z + 1) == blockid) {
|
||||
pdata = pdata|(1 << 2);
|
||||
pdata = pdata | (1 << 2);
|
||||
}
|
||||
if (get_data(state, BLOCKS, x - 1, y, z) == blockid) {
|
||||
pdata = pdata|(1 << 1);
|
||||
pdata = pdata | (1 << 1);
|
||||
}
|
||||
if (get_data(state, BLOCKS, x, y, z - 1) == blockid) {
|
||||
pdata = pdata|(1 << 0);
|
||||
pdata = pdata | (1 << 0);
|
||||
}
|
||||
|
||||
|
||||
return pdata;
|
||||
}
|
||||
|
||||
unsigned short
|
||||
generate_pseudo_data(RenderState *state, unsigned short ancilData) {
|
||||
generate_pseudo_data(RenderState* state, unsigned short ancilData) {
|
||||
/*
|
||||
* Generates a fake ancillary data for blocks that are drawn
|
||||
* depending on what are surrounded.
|
||||
@@ -255,23 +254,23 @@ generate_pseudo_data(RenderState *state, unsigned short ancilData) {
|
||||
|
||||
if (state->block == block_grass) { /* grass */
|
||||
/* return 0x10 if grass is covered in snow */
|
||||
if (get_data(state, BLOCKS, x, y+1, z) == 78)
|
||||
if (get_data(state, BLOCKS, x, y + 1, z) == 78)
|
||||
return 0x10;
|
||||
return ancilData;
|
||||
} else if (block_class_is_subset(state->block, (mc_block_t[]){block_flowing_water,block_water}, 2)) { /* water */
|
||||
} else if (block_class_is_subset(state->block, (mc_block_t[]){block_flowing_water, block_water}, 2)) { /* water */
|
||||
data = check_adjacent_blocks(state, x, y, z, state->block) ^ 0x0f;
|
||||
/* an aditional bit for top is added to the 4 bits of check_adjacent_blocks */
|
||||
if (get_data(state, BLOCKS, x, y+1, z) != state->block)
|
||||
if (get_data(state, BLOCKS, x, y + 1, z) != state->block)
|
||||
data |= 0x10;
|
||||
return data;
|
||||
} else if (block_class_is_subset(state->block, (mc_block_t[]){block_glass,block_ice,block_stained_glass}, 3)) { /* glass and ice and stained glass*/
|
||||
} else if (block_class_is_subset(state->block, (mc_block_t[]){block_glass, block_ice, block_stained_glass}, 3)) { /* glass and ice and stained glass*/
|
||||
/* an aditional bit for top is added to the 4 bits of check_adjacent_blocks
|
||||
* Note that stained glass encodes 16 colors using 4 bits. this pushes us over the 8-bits of an unsigned char,
|
||||
* forcing us to use an unsigned short to hold 16 bits of pseudo ancil data
|
||||
* */
|
||||
if ((get_data(state, BLOCKS, x, y+1, z) == 20) || (get_data(state, BLOCKS, x, y+1, z) == 95)) {
|
||||
if ((get_data(state, BLOCKS, x, y + 1, z) == 20) || (get_data(state, BLOCKS, x, y + 1, z) == 95)) {
|
||||
data = 0;
|
||||
} else {
|
||||
} else {
|
||||
data = 16;
|
||||
}
|
||||
data = (check_adjacent_blocks(state, x, y, z, state->block) ^ 0x0f) | data;
|
||||
@@ -279,8 +278,8 @@ generate_pseudo_data(RenderState *state, unsigned short ancilData) {
|
||||
} else if (block_class_is_subset(state->block, block_class_fence, block_class_fence_len)) { /* fences */
|
||||
/* check for fences AND fence gates */
|
||||
return check_adjacent_blocks(state, x, y, z, state->block) | check_adjacent_blocks(state, x, y, z, block_fence_gate) |
|
||||
check_adjacent_blocks(state, x, y, z, block_fence_gate) | check_adjacent_blocks(state, x, y, z, block_birch_fence_gate) | check_adjacent_blocks(state, x, y, z, block_jungle_fence_gate) |
|
||||
check_adjacent_blocks(state, x, y, z, block_dark_oak_fence_gate) | check_adjacent_blocks(state, x, y, z, block_acacia_fence_gate);
|
||||
check_adjacent_blocks(state, x, y, z, block_fence_gate) | check_adjacent_blocks(state, x, y, z, block_birch_fence_gate) | check_adjacent_blocks(state, x, y, z, block_jungle_fence_gate) |
|
||||
check_adjacent_blocks(state, x, y, z, block_dark_oak_fence_gate) | check_adjacent_blocks(state, x, y, z, block_acacia_fence_gate);
|
||||
|
||||
} else if (state->block == block_redstone_wire) { /* redstone */
|
||||
/* three addiotional bit are added, one for on/off state, and
|
||||
@@ -288,22 +287,22 @@ generate_pseudo_data(RenderState *state, unsigned short ancilData) {
|
||||
* (connection with the level y+1) */
|
||||
unsigned char above_level_data = 0, same_level_data = 0, below_level_data = 0, possibly_connected = 0, final_data = 0;
|
||||
|
||||
/* check for air in y+1, no air = no connection with upper level */
|
||||
if (get_data(state, BLOCKS, x, y+1, z) == 0) {
|
||||
above_level_data = check_adjacent_blocks(state, x, y+1, z, state->block);
|
||||
} /* else above_level_data = 0 */
|
||||
|
||||
/* check for air in y+1, no air = no connection with upper level */
|
||||
if (get_data(state, BLOCKS, x, y + 1, z) == 0) {
|
||||
above_level_data = check_adjacent_blocks(state, x, y + 1, z, state->block);
|
||||
} /* else above_level_data = 0 */
|
||||
|
||||
/* check connection with same level (other redstone and trapped chests */
|
||||
same_level_data = check_adjacent_blocks(state, x, y, z, 55) | check_adjacent_blocks(state, x, y, z, 146);
|
||||
|
||||
|
||||
/* check the posibility of connection with y-1 level, check for air */
|
||||
possibly_connected = check_adjacent_blocks(state, x, y, z, 0);
|
||||
|
||||
|
||||
/* check connection with y-1 level */
|
||||
below_level_data = check_adjacent_blocks(state, x, y-1, z, state->block);
|
||||
|
||||
below_level_data = check_adjacent_blocks(state, x, y - 1, z, state->block);
|
||||
|
||||
final_data = above_level_data | same_level_data | (below_level_data & possibly_connected);
|
||||
|
||||
|
||||
/* add the three bits */
|
||||
if (ancilData > 0) { /* powered redstone wire */
|
||||
final_data = final_data | 0x40;
|
||||
@@ -316,12 +315,12 @@ generate_pseudo_data(RenderState *state, unsigned short ancilData) {
|
||||
}
|
||||
return final_data;
|
||||
|
||||
} else if (block_class_is_subset(state->block, (mc_block_t[]){block_chest,block_trapped_chest}, 2)) {
|
||||
} else if (block_class_is_subset(state->block, (mc_block_t[]){block_chest, block_trapped_chest}, 2)) {
|
||||
/* Orientation is given by ancilData, pseudo data needed to
|
||||
* choose from single or double chest and the correct half of
|
||||
* the chest. */
|
||||
|
||||
/* Add two bits to ancilData to store single or double chest
|
||||
|
||||
/* Add two bits to ancilData to store single or double chest
|
||||
* and which half of the chest it is: bit 0x10 = second half
|
||||
* bit 0x8 = first half */
|
||||
|
||||
@@ -353,7 +352,7 @@ generate_pseudo_data(RenderState *state, unsigned short ancilData) {
|
||||
}
|
||||
return final_data;
|
||||
|
||||
} else if (block_class_is_subset(state->block, (mc_block_t[]){block_iron_bars,block_glass_pane, block_stained_glass_pane},3)) {
|
||||
} else if (block_class_is_subset(state->block, (mc_block_t[]){block_iron_bars, block_glass_pane, block_stained_glass_pane}, 3)) {
|
||||
/* iron bars and glass panes:
|
||||
* they seem to stick to almost everything but air,
|
||||
* not sure yet! Still a TODO! */
|
||||
@@ -362,7 +361,7 @@ generate_pseudo_data(RenderState *state, unsigned short ancilData) {
|
||||
data = (check_adjacent_blocks(state, x, y, z, 0) ^ 0x0f);
|
||||
return (data << 4) | (ancilData & 0xf);
|
||||
|
||||
} else if (block_class_is_subset(state->block, (mc_block_t[]){block_portal,block_nether_brick_fence}, 2)) {
|
||||
} else if (block_class_is_subset(state->block, (mc_block_t[]){block_portal, block_nether_brick_fence}, 2)) {
|
||||
/* portal and nether brick fences */
|
||||
return check_adjacent_blocks(state, x, y, z, state->block);
|
||||
|
||||
@@ -373,7 +372,7 @@ generate_pseudo_data(RenderState *state, unsigned short ancilData) {
|
||||
unsigned char data = 0;
|
||||
if ((ancilData & 0x8) == 0x8) {
|
||||
/* top door block */
|
||||
unsigned char b_data = get_data(state, DATA, x, y-1, z);
|
||||
unsigned char b_data = get_data(state, DATA, x, y - 1, z);
|
||||
if ((ancilData & 0x1) == 0x1) {
|
||||
/* hinge on the left */
|
||||
data = b_data | 0x8 | 0x10;
|
||||
@@ -382,14 +381,13 @@ generate_pseudo_data(RenderState *state, unsigned short ancilData) {
|
||||
}
|
||||
} else {
|
||||
/* bottom door block */
|
||||
unsigned char t_data = get_data(state, DATA, x, y+1, z);
|
||||
unsigned char t_data = get_data(state, DATA, x, y + 1, z);
|
||||
if ((t_data & 0x1) == 0x1) {
|
||||
/* hinge on the left */
|
||||
data = ancilData | 0x10;
|
||||
} else {
|
||||
data = ancilData;
|
||||
}
|
||||
|
||||
}
|
||||
return data;
|
||||
} else if (state->block == block_cobblestone_wall) {
|
||||
@@ -400,7 +398,7 @@ generate_pseudo_data(RenderState *state, unsigned short ancilData) {
|
||||
return check_adjacent_blocks(state, x, y, z, state->block);
|
||||
}
|
||||
} else if (state->block == block_waterlily) {
|
||||
int wx,wz,wy,rotation;
|
||||
int wx, wz, wy, rotation;
|
||||
long pr;
|
||||
/* calculate the global block coordinates of this position */
|
||||
wx = (state->chunkx * 16) + x;
|
||||
@@ -430,39 +428,39 @@ generate_pseudo_data(RenderState *state, unsigned short ancilData) {
|
||||
/* keep track of whether neighbors are stairs, and their data */
|
||||
unsigned char stairs_base[8];
|
||||
unsigned char neigh_base[8];
|
||||
unsigned char *stairs = stairs_base;
|
||||
unsigned char *neigh = neigh_base;
|
||||
unsigned char* stairs = stairs_base;
|
||||
unsigned char* neigh = neigh_base;
|
||||
|
||||
/* amount to rotate/roll to get to east, west, south, north */
|
||||
size_t rotations[] = {0,2,3,1};
|
||||
size_t rotations[] = {0, 2, 3, 1};
|
||||
|
||||
/* masks for the filled (ridge) stair quarters: */
|
||||
/* Example: the ridge for an east-ascending stair are the two east quarters */
|
||||
/* ascending: east west south north */
|
||||
unsigned char ridge_mask[] = { 0x30, 0x48, 0x60, 0x18 };
|
||||
unsigned char ridge_mask[] = {0x30, 0x48, 0x60, 0x18};
|
||||
|
||||
/* masks for the open (trench) stair quarters: */
|
||||
unsigned char trench_mask[] = { 0x48, 0x30, 0x18, 0x60 };
|
||||
unsigned char trench_mask[] = {0x48, 0x30, 0x18, 0x60};
|
||||
|
||||
/* boat analogy! up the stairs is toward the bow of the boat */
|
||||
/* masks for port and starboard, i.e. left and right sides while ascending: */
|
||||
unsigned char port_mask[] = { 0x18, 0x60, 0x30, 0x48 };
|
||||
unsigned char starboard_mask[] = { 0x60, 0x18, 0x48, 0x30 };
|
||||
unsigned char port_mask[] = {0x18, 0x60, 0x30, 0x48};
|
||||
unsigned char starboard_mask[] = {0x60, 0x18, 0x48, 0x30};
|
||||
|
||||
/* we may need to lock some quarters into place depending on neighbors */
|
||||
unsigned char lock_mask = 0;
|
||||
|
||||
unsigned char repair_rot[] = { 0, 1, 2, 3, 2, 3, 1, 0, 1, 0, 3, 2, 3, 2, 0, 1 };
|
||||
unsigned char repair_rot[] = {0, 1, 2, 3, 2, 3, 1, 0, 1, 0, 3, 2, 3, 2, 0, 1};
|
||||
|
||||
/* need to get northdirection of the render */
|
||||
/* TODO: get this just once? store in state? */
|
||||
PyObject *texrot;
|
||||
PyObject* texrot;
|
||||
int northdir;
|
||||
texrot = PyObject_GetAttrString(state->textures, "rotation");
|
||||
northdir = PyLong_AsLong(texrot);
|
||||
|
||||
/* fix the rotation value for different northdirections */
|
||||
#define FIX_ROT(x) (((x) & ~0x3) | repair_rot[((x) & 0x3) | (northdir << 2)])
|
||||
/* fix the rotation value for different northdirections */
|
||||
#define FIX_ROT(x) (((x) & ~0x3) | repair_rot[((x)&0x3) | (northdir << 2)])
|
||||
ancilData = FIX_ROT(ancilData);
|
||||
|
||||
/* fill the ancillary bits assuming normal stairs with no corner yet */
|
||||
@@ -470,16 +468,16 @@ generate_pseudo_data(RenderState *state, unsigned short ancilData) {
|
||||
|
||||
/* get block & data for neighbors in this order: east, north, west, south */
|
||||
/* so we can rotate things easily */
|
||||
stairs[0] = stairs[4] = block_class_is_subset(get_data(state, BLOCKS, x+1, y, z), block_class_stair, block_class_stair_len);
|
||||
stairs[1] = stairs[5] = block_class_is_subset(get_data(state, BLOCKS, x, y, z-1), block_class_stair, block_class_stair_len);
|
||||
stairs[2] = stairs[6] = block_class_is_subset(get_data(state, BLOCKS, x-1, y, z), block_class_stair, block_class_stair_len);
|
||||
stairs[3] = stairs[7] = block_class_is_subset(get_data(state, BLOCKS, x, y, z+1), block_class_stair, block_class_stair_len);
|
||||
neigh[0] = neigh[4] = FIX_ROT(get_data(state, DATA, x+1, y, z));
|
||||
neigh[1] = neigh[5] = FIX_ROT(get_data(state, DATA, x, y, z-1));
|
||||
neigh[2] = neigh[6] = FIX_ROT(get_data(state, DATA, x-1, y, z));
|
||||
neigh[3] = neigh[7] = FIX_ROT(get_data(state, DATA, x, y, z+1));
|
||||
stairs[0] = stairs[4] = block_class_is_subset(get_data(state, BLOCKS, x + 1, y, z), block_class_stair, block_class_stair_len);
|
||||
stairs[1] = stairs[5] = block_class_is_subset(get_data(state, BLOCKS, x, y, z - 1), block_class_stair, block_class_stair_len);
|
||||
stairs[2] = stairs[6] = block_class_is_subset(get_data(state, BLOCKS, x - 1, y, z), block_class_stair, block_class_stair_len);
|
||||
stairs[3] = stairs[7] = block_class_is_subset(get_data(state, BLOCKS, x, y, z + 1), block_class_stair, block_class_stair_len);
|
||||
neigh[0] = neigh[4] = FIX_ROT(get_data(state, DATA, x + 1, y, z));
|
||||
neigh[1] = neigh[5] = FIX_ROT(get_data(state, DATA, x, y, z - 1));
|
||||
neigh[2] = neigh[6] = FIX_ROT(get_data(state, DATA, x - 1, y, z));
|
||||
neigh[3] = neigh[7] = FIX_ROT(get_data(state, DATA, x, y, z + 1));
|
||||
|
||||
#undef FIX_ROT
|
||||
#undef FIX_ROT
|
||||
|
||||
/* Rotate the neighbors so we only have to worry about one orientation
|
||||
* No matter which way the boat is facing, the the neighbors will be:
|
||||
@@ -523,8 +521,8 @@ generate_pseudo_data(RenderState *state, unsigned short ancilData) {
|
||||
/* use bottom block data format plus one bit for top
|
||||
* block (0x8)
|
||||
*/
|
||||
if( get_data(state, BLOCKS, x, y-1, z) == block_double_plant ) {
|
||||
data = get_data(state, DATA, x, y-1, z) | 0x8;
|
||||
if (get_data(state, BLOCKS, x, y - 1, z) == block_double_plant) {
|
||||
data = get_data(state, DATA, x, y - 1, z) | 0x8;
|
||||
} else {
|
||||
data = ancilData;
|
||||
}
|
||||
@@ -535,34 +533,33 @@ generate_pseudo_data(RenderState *state, unsigned short ancilData) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* TODO triple check this to make sure reference counting is correct */
|
||||
PyObject*
|
||||
chunk_render(PyObject *self, PyObject *args) {
|
||||
chunk_render(PyObject* self, PyObject* args) {
|
||||
RenderState state;
|
||||
PyObject *modeobj;
|
||||
PyObject *blockmap;
|
||||
PyObject* modeobj;
|
||||
PyObject* blockmap;
|
||||
|
||||
int xoff, yoff;
|
||||
|
||||
|
||||
PyObject *imgsize, *imgsize0_py, *imgsize1_py;
|
||||
int imgsize0, imgsize1;
|
||||
|
||||
PyArrayObject *blocks_py;
|
||||
PyArrayObject *left_blocks_py;
|
||||
PyArrayObject *right_blocks_py;
|
||||
PyArrayObject *up_left_blocks_py;
|
||||
PyArrayObject *up_right_blocks_py;
|
||||
|
||||
RenderMode *rendermode;
|
||||
|
||||
PyArrayObject* blocks_py;
|
||||
PyArrayObject* left_blocks_py;
|
||||
PyArrayObject* right_blocks_py;
|
||||
PyArrayObject* up_left_blocks_py;
|
||||
PyArrayObject* up_right_blocks_py;
|
||||
|
||||
RenderMode* rendermode;
|
||||
|
||||
int i, j;
|
||||
|
||||
PyObject *t = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "OOiiiOiiOO", &state.world, &state.regionset, &state.chunkx, &state.chunky, &state.chunkz, &state.img, &xoff, &yoff, &modeobj, &state.textures))
|
||||
PyObject* t = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "OOiiiOiiOO", &state.world, &state.regionset, &state.chunkx, &state.chunky, &state.chunkz, &state.img, &xoff, &yoff, &modeobj, &state.textures))
|
||||
return NULL;
|
||||
|
||||
|
||||
/* set up the render mode */
|
||||
state.rendermode = rendermode = render_mode_create(modeobj, &state);
|
||||
if (rendermode == NULL) {
|
||||
@@ -581,7 +578,7 @@ chunk_render(PyObject *self, PyObject *args) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "you must call Textures.generate()");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* get the image size */
|
||||
imgsize = PyObject_GetAttrString(state.img, "size");
|
||||
|
||||
@@ -593,14 +590,14 @@ chunk_render(PyObject *self, PyObject *args) {
|
||||
imgsize1 = PyLong_AsLong(imgsize1_py);
|
||||
Py_DECREF(imgsize0_py);
|
||||
Py_DECREF(imgsize1_py);
|
||||
|
||||
|
||||
/* set all block data to unloaded */
|
||||
for (i = 0; i < 3; i++) {
|
||||
for (j = 0; j < 3; j++) {
|
||||
state.chunks[i][j].loaded = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* get the block data for the center column, erroring out if needed */
|
||||
if (load_chunk(&state, 0, 0, 1)) {
|
||||
render_mode_destroy(rendermode);
|
||||
@@ -614,7 +611,7 @@ chunk_render(PyObject *self, PyObject *args) {
|
||||
unload_all_chunks(&state);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
/* set blocks_py, state.blocks, and state.blockdatas as convenience */
|
||||
blocks_py = state.blocks = state.chunks[1][1].sections[state.chunky].blocks;
|
||||
state.blockdatas = state.chunks[1][1].sections[state.chunky].data;
|
||||
@@ -622,25 +619,25 @@ chunk_render(PyObject *self, PyObject *args) {
|
||||
/* set up the random number generator again for each chunk
|
||||
so tallgrass is in the same place, no matter what mode is used */
|
||||
srand(1);
|
||||
|
||||
|
||||
for (state.x = 15; state.x > -1; state.x--) {
|
||||
for (state.z = 0; state.z < 16; state.z++) {
|
||||
|
||||
/* set up the render coordinates */
|
||||
state.imgx = xoff + state.x*12 + state.z*12;
|
||||
state.imgx = xoff + state.x * 12 + state.z * 12;
|
||||
/* 16*12 -- offset for y direction, 15*6 -- offset for x */
|
||||
state.imgy = yoff - state.x*6 + state.z*6 + 16*12 + 15*6;
|
||||
|
||||
state.imgy = yoff - state.x * 6 + state.z * 6 + 16 * 12 + 15 * 6;
|
||||
|
||||
for (state.y = 0; state.y < 16; state.y++) {
|
||||
unsigned short ancilData;
|
||||
|
||||
|
||||
state.imgy -= 12;
|
||||
/* get blockid */
|
||||
state.block = getArrayShort3D(blocks_py, state.x, state.y, state.z);
|
||||
if (state.block == block_air || render_mode_hidden(rendermode, state.x, state.y, state.z)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
/* make sure we're rendering inside the image boundaries */
|
||||
if ((state.imgx >= imgsize0 + 24) || (state.imgx <= -24)) {
|
||||
continue;
|
||||
@@ -648,14 +645,14 @@ chunk_render(PyObject *self, PyObject *args) {
|
||||
if ((state.imgy >= imgsize1 + 24) || (state.imgy <= -24)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
/* check for occlusion */
|
||||
if (render_mode_occluded(rendermode, state.x, state.y, state.z)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
/* everything stored here will be a borrowed ref */
|
||||
|
||||
|
||||
if (block_has_property(state.block, NODATA)) {
|
||||
/* block shouldn't have data associated with it, set it to 0 */
|
||||
ancilData = 0;
|
||||
@@ -676,20 +673,19 @@ chunk_render(PyObject *self, PyObject *args) {
|
||||
state.block_pdata = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* make sure our block info is in-bounds */
|
||||
if (state.block >= max_blockid || ancilData >= max_data)
|
||||
continue;
|
||||
|
||||
|
||||
/* get the texture */
|
||||
t = PyList_GET_ITEM(blockmap, max_data * state.block + ancilData);
|
||||
/* if we don't get a texture, try it again with 0 data */
|
||||
if ((t == NULL || t == Py_None) && ancilData != 0)
|
||||
t = PyList_GET_ITEM(blockmap, max_data * state.block);
|
||||
|
||||
|
||||
/* if we found a proper texture, render it! */
|
||||
if (t != NULL && t != Py_None)
|
||||
{
|
||||
if (t != NULL && t != Py_None) {
|
||||
PyObject *src, *mask, *mask_light;
|
||||
int do_rand = (state.block == block_tallgrass /*|| state.block == block_red_flower || state.block == block_double_plant*/);
|
||||
int randx = 0, randy = 0;
|
||||
@@ -707,9 +703,9 @@ chunk_render(PyObject *self, PyObject *args) {
|
||||
state.imgx += randx;
|
||||
state.imgy += randy;
|
||||
}
|
||||
|
||||
|
||||
render_mode_draw(rendermode, src, mask, mask_light);
|
||||
|
||||
|
||||
if (do_rand) {
|
||||
/* undo the random offsets */
|
||||
state.imgx -= randx;
|
||||
@@ -722,7 +718,7 @@ chunk_render(PyObject *self, PyObject *args) {
|
||||
|
||||
/* free up the rendermode info */
|
||||
render_mode_destroy(rendermode);
|
||||
|
||||
|
||||
Py_DECREF(blockmap);
|
||||
unload_all_chunks(&state);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user