0

Implement standard C boolean type

This commit is contained in:
Wunkolo
2019-06-25 14:19:12 -07:00
parent d738c21852
commit 5b212dc585
26 changed files with 216 additions and 225 deletions

View File

@@ -121,14 +121,14 @@ static inline void load_chunk_section(ChunkData* dest, int32_t i, PyObject* sect
* if required is true, failure to load the chunk will raise a python * if required is true, failure to load the chunk will raise a python
* exception and return true. * exception and return true.
*/ */
int32_t load_chunk(RenderState* state, int32_t x, int32_t z, uint8_t required) { bool load_chunk(RenderState* state, int32_t x, int32_t z, uint8_t required) {
ChunkData* dest = &(state->chunks[1 + x][1 + z]); ChunkData* dest = &(state->chunks[1 + x][1 + z]);
int32_t i; int32_t i;
PyObject* chunk = NULL; PyObject* chunk = NULL;
PyObject* sections = NULL; PyObject* sections = NULL;
if (dest->loaded) if (dest->loaded)
return 0; return false;
/* set up reasonable defaults */ /* set up reasonable defaults */
dest->biomes = NULL; dest->biomes = NULL;
@@ -150,7 +150,7 @@ int32_t load_chunk(RenderState* state, int32_t x, int32_t z, uint8_t required) {
if (!required) { if (!required) {
PyErr_Clear(); PyErr_Clear();
} }
return 1; return true;
} }
sections = PyDict_GetItemString(chunk, "Sections"); sections = PyDict_GetItemString(chunk, "Sections");
@@ -163,7 +163,7 @@ int32_t load_chunk(RenderState* state, int32_t x, int32_t z, uint8_t required) {
if (!required) { if (!required) {
PyErr_Clear(); PyErr_Clear();
} }
return 1; return true;
} }
dest->biomes = (PyArrayObject*)PyDict_GetItemString(chunk, "Biomes"); dest->biomes = (PyArrayObject*)PyDict_GetItemString(chunk, "Biomes");
@@ -184,7 +184,7 @@ int32_t load_chunk(RenderState* state, int32_t x, int32_t z, uint8_t required) {
Py_DECREF(sections); Py_DECREF(sections);
Py_DECREF(chunk); Py_DECREF(chunk);
return 0; return false;
} }
/* helper to unload all loaded chunks */ /* helper to unload all loaded chunks */

View File

@@ -121,7 +121,7 @@ typedef struct {
} RenderState; } RenderState;
PyObject* init_chunk_render(void); PyObject* init_chunk_render(void);
/* returns true on error, x,z relative */ /* returns true on error, x,z relative */
int32_t load_chunk(RenderState* state, int32_t x, int32_t z, uint8_t required); bool load_chunk(RenderState* state, int32_t x, int32_t z, uint8_t required);
PyObject* chunk_render(PyObject* self, PyObject* args); PyObject* chunk_render(PyObject* self, PyObject* args);
typedef enum { typedef enum {
KNOWN, KNOWN,
@@ -141,8 +141,8 @@ block_has_property(mc_block_t b, BlockProperty prop) {
if (b >= max_blockid || !(block_properties[b] & (1 << KNOWN))) { if (b >= max_blockid || !(block_properties[b] & (1 << KNOWN))) {
/* block is unknown, return defaults */ /* block is unknown, return defaults */
if (prop == TRANSPARENT) if (prop == TRANSPARENT)
return 1; return true;
return 0; return false;
} }
return block_properties[b] & (1 << prop); return block_properties[b] & (1 << prop);

View File

@@ -28,12 +28,12 @@ typedef struct {
PyObject* grass_texture; PyObject* grass_texture;
} PrimitiveBase; } PrimitiveBase;
static int32_t static bool
base_start(void* data, RenderState* state, PyObject* support) { base_start(void* data, RenderState* state, PyObject* support) {
PrimitiveBase* self = (PrimitiveBase*)data; PrimitiveBase* self = (PrimitiveBase*)data;
if (!render_mode_parse_option(support, "biomes", "i", &(self->use_biomes))) if (!render_mode_parse_option(support, "biomes", "i", &(self->use_biomes)))
return 1; return true;
/* biome-compliant grass mask (includes sides!) */ /* biome-compliant grass mask (includes sides!) */
self->grass_texture = PyObject_GetAttrString(state->textures, "biome_grass_texture"); self->grass_texture = PyObject_GetAttrString(state->textures, "biome_grass_texture");
@@ -43,7 +43,7 @@ base_start(void* data, RenderState* state, PyObject* support) {
self->grasscolor = PyObject_CallMethod(state->textures, "load_grass_color", ""); self->grasscolor = PyObject_CallMethod(state->textures, "load_grass_color", "");
self->watercolor = PyObject_CallMethod(state->textures, "load_water_color", ""); self->watercolor = PyObject_CallMethod(state->textures, "load_water_color", "");
return 0; return false;
} }
static void static void
@@ -56,7 +56,7 @@ base_finish(void* data, RenderState* state) {
Py_DECREF(self->grass_texture); Py_DECREF(self->grass_texture);
} }
static int32_t static bool
base_occluded(void* data, RenderState* state, int32_t x, int32_t y, int32_t z) { base_occluded(void* data, RenderState* state, int32_t x, int32_t y, int32_t z) {
if ((x != 0) && (y != 15) && (z != 15) && if ((x != 0) && (y != 15) && (z != 15) &&
!render_mode_hidden(state->rendermode, x - 1, y, z) && !render_mode_hidden(state->rendermode, x - 1, y, z) &&
@@ -65,10 +65,10 @@ base_occluded(void* data, RenderState* state, int32_t x, int32_t y, int32_t z) {
!is_transparent(getArrayShort3D(state->blocks, x - 1, y, z)) && !is_transparent(getArrayShort3D(state->blocks, x - 1, y, z)) &&
!is_transparent(getArrayShort3D(state->blocks, x, y, z + 1)) && !is_transparent(getArrayShort3D(state->blocks, x, y, z + 1)) &&
!is_transparent(getArrayShort3D(state->blocks, x, y + 1, z))) { !is_transparent(getArrayShort3D(state->blocks, x, y + 1, z))) {
return 1; return true;
} }
return 0; return false;
} }
static void static void
@@ -110,7 +110,7 @@ base_draw(void* data, RenderState* state, PyObject* src, PyObject* mask, PyObjec
PyObject* facemask = mask; PyObject* facemask = mask;
uint8_t r = 255, g = 255, b = 255; uint8_t r = 255, g = 255, b = 255;
PyObject* color_table = NULL; PyObject* color_table = NULL;
uint8_t flip_xy = 0; bool flip_xy = false;
if (state->block == block_grass) { if (state->block == block_grass) {
/* grass needs a special facemask */ /* grass needs a special facemask */
@@ -122,11 +122,8 @@ base_draw(void* data, RenderState* state, PyObject* src, PyObject* mask, PyObjec
color_table = self->watercolor; color_table = self->watercolor;
} else if (block_class_is_subset(state->block, (mc_block_t[]){block_leaves, block_leaves2}, 2)) { } else if (block_class_is_subset(state->block, (mc_block_t[]){block_leaves, block_leaves2}, 2)) {
color_table = self->foliagecolor; color_table = self->foliagecolor;
if (state->block_data == 2) { /* birch foliage color is flipped XY-ways */
/* birch! flip_xy = state->block_data == 2;
birch foliage color is flipped XY-ways */
flip_xy = 1;
}
} }
if (color_table) { if (color_table) {

View File

@@ -22,23 +22,22 @@ typedef struct {
int32_t only_lit; int32_t only_lit;
} RenderPrimitiveCave; } RenderPrimitiveCave;
static inline int32_t static inline bool
touches_light(RenderState* state, DataType type, uint32_t x, uint32_t y, uint32_t z) { touches_light(RenderState* state, DataType type, uint32_t x, uint32_t y, uint32_t z) {
if (get_data(state, type, x, y + 1, z)) if (get_data(state, type, x, y + 1, z))
return 1; return true;
if (get_data(state, type, x + 1, y, z)) if (get_data(state, type, x + 1, y, z))
return 1; return true;
if (get_data(state, type, x - 1, y, z)) if (get_data(state, type, x - 1, y, z))
return 1; return true;
if (get_data(state, type, x, y, z + 1)) if (get_data(state, type, x, y, z + 1))
return 1; return true;
if (get_data(state, type, x, y, z - 1)) if (get_data(state, type, x, y, z - 1))
return 1; return true;
return 0; return false;
} }
static int32_t static bool
cave_occluded(void* data, RenderState* state, int32_t x, int32_t y, int32_t z) { cave_occluded(void* data, RenderState* state, int32_t x, int32_t y, int32_t z) {
/* check for normal occlusion */ /* check for normal occlusion */
/* use ajacent chunks, if not you get blocks spreaded in chunk edges */ /* use ajacent chunks, if not you get blocks spreaded in chunk edges */
@@ -46,21 +45,21 @@ cave_occluded(void* data, RenderState* state, int32_t x, int32_t y, int32_t z) {
if (!is_known_transparent(get_data(state, BLOCKS, x - 1, y, z)) && if (!is_known_transparent(get_data(state, BLOCKS, x - 1, y, z)) &&
!is_known_transparent(get_data(state, BLOCKS, x, y, z + 1)) && !is_known_transparent(get_data(state, BLOCKS, x, y, z + 1)) &&
!is_known_transparent(get_data(state, BLOCKS, x, y + 1, z))) { !is_known_transparent(get_data(state, BLOCKS, x, y + 1, z))) {
return 1; return true;
} }
/* special handling for section boundaries */ /* special handling for section boundaries */
if (x == 0 && (!(state->chunks[0][1].loaded) || state->chunks[0][1].sections[state->chunky].blocks == NULL)) if (x == 0 && (!(state->chunks[0][1].loaded) || state->chunks[0][1].sections[state->chunky].blocks == NULL))
return 1; return true;
if (y == 15 && (state->chunky + 1 >= SECTIONS_PER_CHUNK || state->chunks[1][1].sections[state->chunky + 1].blocks == NULL)) if (y == 15 && (state->chunky + 1 >= SECTIONS_PER_CHUNK || state->chunks[1][1].sections[state->chunky + 1].blocks == NULL))
return 1; return true;
if (z == 15 && (!(state->chunks[1][2].loaded) || state->chunks[1][2].sections[state->chunky].blocks == NULL)) if (z == 15 && (!(state->chunks[1][2].loaded) || state->chunks[1][2].sections[state->chunky].blocks == NULL))
return 1; return true;
return 0; return false;
} }
static int32_t static bool
cave_hidden(void* data, RenderState* state, int32_t x, int32_t y, int32_t z) { cave_hidden(void* data, RenderState* state, int32_t x, int32_t y, int32_t z) {
RenderPrimitiveCave* self; RenderPrimitiveCave* self;
int32_t dy = 0; int32_t dy = 0;
@@ -68,11 +67,11 @@ cave_hidden(void* data, RenderState* state, int32_t x, int32_t y, int32_t z) {
/* check if the block is touching skylight */ /* check if the block is touching skylight */
if (touches_light(state, SKYLIGHT, x, y, z)) { if (touches_light(state, SKYLIGHT, x, y, z)) {
return 1; return true;
} }
if (self->only_lit && !touches_light(state, BLOCKLIGHT, x, y, z)) { if (self->only_lit && !touches_light(state, BLOCKLIGHT, x, y, z)) {
return 1; return true;
} }
/* check for lakes and seas and don't render them /* check for lakes and seas and don't render them
@@ -85,7 +84,7 @@ cave_hidden(void* data, RenderState* state, int32_t x, int32_t y, int32_t z) {
for (dy = y + 1; dy < (SECTIONS_PER_CHUNK - state->chunky) * 16; dy++) { for (dy = y + 1; dy < (SECTIONS_PER_CHUNK - state->chunky) * 16; dy++) {
/* go up and check for skylight */ /* go up and check for skylight */
if (get_data(state, SKYLIGHT, x, dy, z) != 0) { if (get_data(state, SKYLIGHT, x, dy, z) != 0) {
return 1; return true;
} }
if (get_data(state, BLOCKS, x, dy, z) != 9) { if (get_data(state, BLOCKS, x, dy, z) != 9) {
/* we are out of the water! and there's no skylight /* we are out of the water! and there's no skylight
@@ -102,15 +101,15 @@ cave_hidden(void* data, RenderState* state, int32_t x, int32_t y, int32_t z) {
return cave_occluded(data, state, x, y, z); return cave_occluded(data, state, x, y, z);
} }
static int32_t static bool
cave_start(void* data, RenderState* state, PyObject* support) { cave_start(void* data, RenderState* state, PyObject* support) {
RenderPrimitiveCave* self; RenderPrimitiveCave* self;
self = (RenderPrimitiveCave*)data; self = (RenderPrimitiveCave*)data;
if (!render_mode_parse_option(support, "only_lit", "i", &(self->only_lit))) if (!render_mode_parse_option(support, "only_lit", "i", &(self->only_lit)))
return 1; return true;
return 0; return false;
} }
RenderPrimitiveInterface primitive_cave = { RenderPrimitiveInterface primitive_cave = {

View File

@@ -17,7 +17,7 @@
#include "../overviewer.h" #include "../overviewer.h"
static int32_t static bool
clear_base_occluded(void* data, RenderState* state, int32_t x, int32_t y, int32_t z) { clear_base_occluded(void* data, RenderState* state, int32_t x, int32_t y, int32_t z) {
if ((x != 0) && (y != 15) && (z != 127) && if ((x != 0) && (y != 15) && (z != 127) &&
!render_mode_hidden(state->rendermode, x - 1, y, z) && !render_mode_hidden(state->rendermode, x - 1, y, z) &&
@@ -26,10 +26,10 @@ clear_base_occluded(void* data, RenderState* state, int32_t x, int32_t y, int32_
!is_transparent(getArrayShort3D(state->blocks, x - 1, y, z)) && !is_transparent(getArrayShort3D(state->blocks, x - 1, y, z)) &&
!is_transparent(getArrayShort3D(state->blocks, x, y, z + 1)) && !is_transparent(getArrayShort3D(state->blocks, x, y, z + 1)) &&
!is_transparent(getArrayShort3D(state->blocks, x, y + 1, z))) { !is_transparent(getArrayShort3D(state->blocks, x, y + 1, z))) {
return 1; return true;
} }
return 0; return false;
} }
static void static void

View File

@@ -23,16 +23,16 @@ typedef struct {
PyObject* depth_colors; PyObject* depth_colors;
} RenderPrimitiveDepthTinting; } RenderPrimitiveDepthTinting;
static int32_t static bool
depth_tinting_start(void* data, RenderState* state, PyObject* support) { depth_tinting_start(void* data, RenderState* state, PyObject* support) {
RenderPrimitiveDepthTinting* self; RenderPrimitiveDepthTinting* self;
self = (RenderPrimitiveDepthTinting*)data; self = (RenderPrimitiveDepthTinting*)data;
self->depth_colors = PyObject_GetAttrString(support, "depth_colors"); self->depth_colors = PyObject_GetAttrString(support, "depth_colors");
if (self->depth_colors == NULL) if (self->depth_colors == NULL)
return 1; return true;
return 0; return false;
} }
static void static void

View File

@@ -22,26 +22,26 @@ typedef struct {
uint32_t max; uint32_t max;
} PrimitiveDepth; } PrimitiveDepth;
static int32_t static bool
depth_start(void* data, RenderState* state, PyObject* support) { depth_start(void* data, RenderState* state, PyObject* support) {
PrimitiveDepth* self = (PrimitiveDepth*)data; PrimitiveDepth* self = (PrimitiveDepth*)data;
if (!render_mode_parse_option(support, "min", "I", &(self->min))) if (!render_mode_parse_option(support, "min", "I", &(self->min)))
return 1; return true;
if (!render_mode_parse_option(support, "max", "I", &(self->max))) if (!render_mode_parse_option(support, "max", "I", &(self->max)))
return 1; return true;
return 0; return false;
} }
static int32_t static bool
depth_hidden(void* data, RenderState* state, int32_t x, int32_t y, int32_t z) { depth_hidden(void* data, RenderState* state, int32_t x, int32_t y, int32_t z) {
PrimitiveDepth* self = (PrimitiveDepth*)data; PrimitiveDepth* self = (PrimitiveDepth*)data;
y += 16 * state->chunky; y += 16 * state->chunky;
if (y > self->max || y < self->min) { if (y > self->max || y < self->min) {
return 1; return true;
} }
return 0; return false;
} }
RenderPrimitiveInterface primitive_depth = { RenderPrimitiveInterface primitive_depth = {

View File

@@ -23,12 +23,12 @@ typedef struct {
float opacity; float opacity;
} PrimitiveEdgeLines; } PrimitiveEdgeLines;
static int32_t static bool
edge_lines_start(void* data, RenderState* state, PyObject* support) { edge_lines_start(void* data, RenderState* state, PyObject* support) {
PrimitiveEdgeLines* self = (PrimitiveEdgeLines*)data; PrimitiveEdgeLines* self = (PrimitiveEdgeLines*)data;
if (!render_mode_parse_option(support, "opacity", "f", &(self->opacity))) if (!render_mode_parse_option(support, "opacity", "f", &(self->opacity)))
return 1; return true;
return 0; return false;
} }
static void static void

View File

@@ -21,29 +21,29 @@ typedef struct {
uint32_t mode; /* 0 = exposed only, 1 = unexposed only */ uint32_t mode; /* 0 = exposed only, 1 = unexposed only */
} PrimitiveExposed; } PrimitiveExposed;
static int32_t static bool
exposed_start(void* data, RenderState* state, PyObject* support) { exposed_start(void* data, RenderState* state, PyObject* support) {
PrimitiveExposed* self = (PrimitiveExposed*)data; PrimitiveExposed* self = (PrimitiveExposed*)data;
if (!render_mode_parse_option(support, "mode", "I", &(self->mode))) if (!render_mode_parse_option(support, "mode", "I", &(self->mode)))
return 1; return true;
return 0; return false;
} }
static int32_t static bool
exposed_hidden(void* data, RenderState* state, int32_t x, int32_t y, int32_t z) { exposed_hidden(void* data, RenderState* state, int32_t x, int32_t y, int32_t z) {
PrimitiveExposed* self = (PrimitiveExposed*)data; PrimitiveExposed* self = (PrimitiveExposed*)data;
/* Unset these flags if seeming exposure from any of these directions would /* Unset these flags if seeming exposure from any of these directions would
* be due to not having data there. * be due to not having data there.
*/ */
int32_t validMinusX = 1; bool validMinusX = true;
int32_t validPlusX = 1; bool validPlusX = true;
int32_t validMinusY = 1; bool validMinusY = true;
int32_t validPlusY = 1; bool validPlusY = true;
int32_t validMinusZ = 1; bool validMinusZ = true;
int32_t validPlusZ = 1; bool validPlusZ = true;
/* special handling for section boundaries */ /* special handling for section boundaries */
/* If the neighboring section has no block data, ignore exposure from that /* If the neighboring section has no block data, ignore exposure from that
@@ -51,32 +51,32 @@ exposed_hidden(void* data, RenderState* state, int32_t x, int32_t y, int32_t z)
*/ */
if (x == 0 && (!(state->chunks[0][1].loaded) || state->chunks[0][1].sections[state->chunky].blocks == NULL)) { if (x == 0 && (!(state->chunks[0][1].loaded) || state->chunks[0][1].sections[state->chunky].blocks == NULL)) {
/* No data in -x direction */ /* No data in -x direction */
validMinusX = 0; validMinusX = false;
} }
if (x == 15 && (!(state->chunks[2][1].loaded) || state->chunks[2][1].sections[state->chunky].blocks == NULL)) { if (x == 15 && (!(state->chunks[2][1].loaded) || state->chunks[2][1].sections[state->chunky].blocks == NULL)) {
/* No data in +x direction */ /* No data in +x direction */
validPlusX = 0; validPlusX = false;
} }
if (y == 0 && (state->chunky - 1 < 0 || state->chunks[1][1].sections[state->chunky - 1].blocks == NULL)) { if (y == 0 && (state->chunky - 1 < 0 || state->chunks[1][1].sections[state->chunky - 1].blocks == NULL)) {
/* No data in -y direction */ /* No data in -y direction */
validMinusY = 0; validMinusY = false;
} }
if (y == 15 && (state->chunky + 1 >= SECTIONS_PER_CHUNK || state->chunks[1][1].sections[state->chunky + 1].blocks == NULL)) { if (y == 15 && (state->chunky + 1 >= SECTIONS_PER_CHUNK || state->chunks[1][1].sections[state->chunky + 1].blocks == NULL)) {
/* No data in +y direction */ /* No data in +y direction */
validPlusY = 0; validPlusY = false;
} }
if (z == 0 && (!(state->chunks[1][0].loaded) || state->chunks[1][0].sections[state->chunky].blocks == NULL)) { if (z == 0 && (!(state->chunks[1][0].loaded) || state->chunks[1][0].sections[state->chunky].blocks == NULL)) {
/* No data in -z direction */ /* No data in -z direction */
validMinusZ = 0; validMinusZ = false;
} }
if (z == 15 && (!(state->chunks[1][2].loaded) || state->chunks[1][2].sections[state->chunky].blocks == NULL)) { if (z == 15 && (!(state->chunks[1][2].loaded) || state->chunks[1][2].sections[state->chunky].blocks == NULL)) {
/* No data in +z direction */ /* No data in +z direction */
validPlusZ = 0; validPlusZ = false;
} }
/* If any of the 6 blocks adjacent to us are transparent, we're exposed */ /* If any of the 6 blocks adjacent to us are transparent, we're exposed */

View File

@@ -23,17 +23,17 @@ typedef struct {
uint32_t sealevel; uint32_t sealevel;
} PrimitiveHeightFading; } PrimitiveHeightFading;
static int32_t static bool
height_fading_start(void* data, RenderState* state, PyObject* support) { height_fading_start(void* data, RenderState* state, PyObject* support) {
PrimitiveHeightFading* self = (PrimitiveHeightFading*)data; PrimitiveHeightFading* self = (PrimitiveHeightFading*)data;
if (!render_mode_parse_option(support, "sealevel", "I", &(self->sealevel))) if (!render_mode_parse_option(support, "sealevel", "I", &(self->sealevel)))
return 1; return true;
self->black_color = PyObject_GetAttrString(support, "black_color"); self->black_color = PyObject_GetAttrString(support, "black_color");
self->white_color = PyObject_GetAttrString(support, "white_color"); self->white_color = PyObject_GetAttrString(support, "white_color");
return 0; return false;
} }
static void static void

View File

@@ -28,26 +28,26 @@ typedef struct {
struct HideRule* rules; struct HideRule* rules;
} RenderPrimitiveHide; } RenderPrimitiveHide;
static int32_t static bool
hide_start(void* data, RenderState* state, PyObject* support) { hide_start(void* data, RenderState* state, PyObject* support) {
PyObject* opt; PyObject* opt;
RenderPrimitiveHide* self = (RenderPrimitiveHide*)data; RenderPrimitiveHide* self = (RenderPrimitiveHide*)data;
self->rules = NULL; self->rules = NULL;
if (!render_mode_parse_option(support, "blocks", "O", &(opt))) if (!render_mode_parse_option(support, "blocks", "O", &(opt)))
return 1; return true;
if (opt && opt != Py_None) { if (opt && opt != Py_None) {
Py_ssize_t blocks_size = 0, i; Py_ssize_t blocks_size = 0, i;
if (!PyList_Check(opt)) { if (!PyList_Check(opt)) {
PyErr_SetString(PyExc_TypeError, "'blocks' must be a list"); PyErr_SetString(PyExc_TypeError, "'blocks' must be a list");
return 1; return true;
} }
blocks_size = PyList_GET_SIZE(opt); blocks_size = PyList_GET_SIZE(opt);
self->rules = calloc(blocks_size + 1, sizeof(struct HideRule)); self->rules = calloc(blocks_size + 1, sizeof(struct HideRule));
if (self->rules == NULL) { if (self->rules == NULL) {
return 1; return true;
} }
for (i = 0; i < blocks_size; i++) { for (i = 0; i < blocks_size; i++) {
@@ -64,12 +64,12 @@ hide_start(void* data, RenderState* state, PyObject* support) {
/* format not recognized */ /* format not recognized */
free(self->rules); free(self->rules);
self->rules = NULL; self->rules = NULL;
return 1; return true;
} }
} }
} }
return 0; return false;
} }
static void static void
@@ -81,14 +81,14 @@ hide_finish(void* data, RenderState* state) {
} }
} }
static int32_t static bool
hide_hidden(void* data, RenderState* state, int32_t x, int32_t y, int32_t z) { hide_hidden(void* data, RenderState* state, int32_t x, int32_t y, int32_t z) {
RenderPrimitiveHide* self = (RenderPrimitiveHide*)data; RenderPrimitiveHide* self = (RenderPrimitiveHide*)data;
uint32_t i; uint32_t i;
mc_block_t block; mc_block_t block;
if (self->rules == NULL) if (self->rules == NULL)
return 0; return false;
block = get_data(state, BLOCKS, x, y, z); block = get_data(state, BLOCKS, x, y, z);
for (i = 0; self->rules[i].blockid != block_air; i++) { for (i = 0; self->rules[i].blockid != block_air; i++) {
@@ -96,15 +96,15 @@ hide_hidden(void* data, RenderState* state, int32_t x, int32_t y, int32_t z) {
uint8_t data; uint8_t data;
if (!(self->rules[i].has_data)) if (!(self->rules[i].has_data))
return 1; return true;
data = get_data(state, DATA, x, y, z); data = get_data(state, DATA, x, y, z);
if (data == self->rules[i].data) if (data == self->rules[i].data)
return 1; return true;
} }
} }
return 0; return false;
} }
RenderPrimitiveInterface primitive_hide = { RenderPrimitiveInterface primitive_hide = {

View File

@@ -99,7 +99,7 @@ calculate_light_color_fancy_night(void* data,
uint8_t uint8_t
estimate_blocklevel(RenderPrimitiveLighting* self, RenderState* state, estimate_blocklevel(RenderPrimitiveLighting* self, RenderState* state,
int32_t x, int32_t y, int32_t z, int* authoratative) { int32_t x, int32_t y, int32_t z, bool* authoratative) {
/* placeholders for later data arrays, coordinates */ /* placeholders for later data arrays, coordinates */
mc_block_t block; mc_block_t block;
@@ -108,12 +108,12 @@ estimate_blocklevel(RenderPrimitiveLighting* self, RenderState* state,
/* defaults to "guess" until told otherwise */ /* defaults to "guess" until told otherwise */
if (authoratative) if (authoratative)
*authoratative = 0; *authoratative = false;
block = get_data(state, BLOCKS, x, y, z); block = get_data(state, BLOCKS, x, y, z);
if (authoratative == NULL) { if (authoratative == NULL) {
int32_t auth; bool auth;
/* iterate through all surrounding blocks to take an average */ /* iterate through all surrounding blocks to take an average */
int32_t dx, dy, dz, local_block; int32_t dx, dy, dz, local_block;
@@ -196,15 +196,15 @@ get_lighting_color(RenderPrimitiveLighting* self, RenderState* state,
} }
/* does per-face occlusion checking for do_shading_with_mask */ /* does per-face occlusion checking for do_shading_with_mask */
inline int32_t inline bool
lighting_is_face_occluded(RenderState* state, int32_t skip_sides, int32_t x, int32_t y, int32_t z) { lighting_is_face_occluded(RenderState* state, bool skip_sides, int32_t x, int32_t y, int32_t z) {
/* first, check for occlusion if the block is in the local chunk */ /* first, check for occlusion if the block is in the local chunk */
if (x >= 0 && x < 16 && y >= 0 && y < 16 && z >= 0 && z < 16) { if (x >= 0 && x < 16 && y >= 0 && y < 16 && z >= 0 && z < 16) {
mc_block_t block = getArrayShort3D(state->blocks, x, y, z); mc_block_t block = getArrayShort3D(state->blocks, x, y, z);
if (!is_transparent(block) && !render_mode_hidden(state->rendermode, x, y, z)) { if (!is_transparent(block) && !render_mode_hidden(state->rendermode, x, y, z)) {
/* this face isn't visible, so don't draw anything */ /* this face isn't visible, so don't draw anything */
return 1; return true;
} }
} else if (!skip_sides) { } else if (!skip_sides) {
mc_block_t block = get_data(state, BLOCKS, x, y, z); mc_block_t block = get_data(state, BLOCKS, x, y, z);
@@ -213,10 +213,10 @@ lighting_is_face_occluded(RenderState* state, int32_t skip_sides, int32_t x, int
ugly black doted line between chunks in night rendermode. ugly black doted line between chunks in night rendermode.
This wouldn't be necessary if the textures were truly This wouldn't be necessary if the textures were truly
tessellate-able */ tessellate-able */
return 1; return true;
} }
} }
return 0; return false;
} }
/* shades the drawn block with the given facemask, based on the /* shades the drawn block with the given facemask, based on the
@@ -247,14 +247,14 @@ lighting_start(void* data, RenderState* state, PyObject* support) {
self = (RenderPrimitiveLighting*)data; self = (RenderPrimitiveLighting*)data;
/* don't skip sides by default */ /* don't skip sides by default */
self->skip_sides = 0; self->skip_sides = false;
if (!render_mode_parse_option(support, "strength", "f", &(self->strength))) if (!render_mode_parse_option(support, "strength", "f", &(self->strength)))
return 1; return true;
if (!render_mode_parse_option(support, "night", "i", &(self->night))) if (!render_mode_parse_option(support, "night", "p", &(self->night)))
return 1; return true;
if (!render_mode_parse_option(support, "color", "i", &(self->color))) if (!render_mode_parse_option(support, "color", "p", &(self->color)))
return 1; return true;
self->facemasks_py = PyObject_GetAttrString(support, "facemasks"); self->facemasks_py = PyObject_GetAttrString(support, "facemasks");
// borrowed references, don't need to be decref'd // borrowed references, don't need to be decref'd
@@ -273,7 +273,7 @@ lighting_start(void* data, RenderState* state, PyObject* support) {
if (self->lightcolor == Py_None) { if (self->lightcolor == Py_None) {
Py_DECREF(self->lightcolor); Py_DECREF(self->lightcolor);
self->lightcolor = NULL; self->lightcolor = NULL;
self->color = 0; self->color = false;
} else { } else {
if (self->night) { if (self->night) {
self->calculate_light_color = calculate_light_color_fancy_night; self->calculate_light_color = calculate_light_color_fancy_night;
@@ -285,7 +285,7 @@ lighting_start(void* data, RenderState* state, PyObject* support) {
self->lightcolor = NULL; self->lightcolor = NULL;
} }
return 0; return false;
} }
static void static void

View File

@@ -31,7 +31,7 @@ typedef struct {
/* can be set to 0 in derived modes to indicate that lighting the chunk /* can be set to 0 in derived modes to indicate that lighting the chunk
* sides is actually important. Right now, this is used in cave mode * sides is actually important. Right now, this is used in cave mode
*/ */
int32_t skip_sides; bool skip_sides;
float strength; float strength;
int32_t color; int32_t color;
@@ -40,7 +40,7 @@ typedef struct {
/* exposed so that smooth-lighting can use them */ /* exposed so that smooth-lighting can use them */
extern RenderPrimitiveInterface primitive_lighting; extern RenderPrimitiveInterface primitive_lighting;
int32_t lighting_is_face_occluded(RenderState* state, int32_t skip_sides, int32_t x, int32_t y, int32_t z); bool lighting_is_face_occluded(RenderState* state, bool skip_sides, int32_t x, int32_t y, int32_t z);
void get_lighting_color(RenderPrimitiveLighting* self, RenderState* state, void get_lighting_color(RenderPrimitiveLighting* self, RenderState* state,
int32_t x, int32_t y, int32_t z, int32_t x, int32_t y, int32_t z,
uint8_t* r, uint8_t* g, uint8_t* b); uint8_t* r, uint8_t* g, uint8_t* b);

View File

@@ -23,31 +23,31 @@
static void static void
walk_chunk(RenderState* state, RenderPrimitiveNether* data) { walk_chunk(RenderState* state, RenderPrimitiveNether* data) {
int32_t x, y, z; int32_t x, y, z;
int32_t id; mc_block_t blockid;
for (x = -1; x < WIDTH + 1; x++) { for (x = -1; x < WIDTH + 1; x++) {
for (z = -1; z < DEPTH + 1; z++) { for (z = -1; z < DEPTH + 1; z++) {
id = get_data(state, BLOCKS, x, NETHER_ROOF - (state->chunky * 16), z); blockid = get_data(state, BLOCKS, x, NETHER_ROOF - (state->chunky * 16), z);
if (id == block_bedrock) { if (blockid == block_bedrock) {
data->remove_block[x + 1][NETHER_ROOF][z + 1] = 1; data->remove_block[x + 1][NETHER_ROOF][z + 1] = true;
id = get_data(state, BLOCKS, x, (NETHER_ROOF + 1) - (state->chunky * 16), z); blockid = get_data(state, BLOCKS, x, (NETHER_ROOF + 1) - (state->chunky * 16), z);
if (id == block_brown_mushroom || id == block_red_mushroom) if (blockid == block_brown_mushroom || blockid == block_red_mushroom)
data->remove_block[x + 1][NETHER_ROOF + 1][z + 1] = 1; data->remove_block[x + 1][NETHER_ROOF + 1][z + 1] = true;
} }
for (y = NETHER_ROOF - 1; y >= 0; y--) { for (y = NETHER_ROOF - 1; y >= 0; y--) {
id = get_data(state, BLOCKS, x, y - (state->chunky * 16), z); blockid = get_data(state, BLOCKS, x, y - (state->chunky * 16), z);
if (block_class_is_subset(id, (mc_block_t[]){block_bedrock, block_netherrack, block_quartz_ore, block_lava}, 4)) if (block_class_is_subset(blockid, (mc_block_t[]){block_bedrock, block_netherrack, block_quartz_ore, block_lava}, 4))
data->remove_block[x + 1][y][z + 1] = 1; data->remove_block[x + 1][y][z + 1] = true;
else else
break; break;
} }
} }
} }
data->walked_chunk = 1; data->walked_chunk = true;
} }
static int32_t static bool
nether_hidden(void* data, RenderState* state, int32_t x, int32_t y, int32_t z) { nether_hidden(void* data, RenderState* state, int32_t x, int32_t y, int32_t z) {
RenderPrimitiveNether* self; RenderPrimitiveNether* self;
int32_t real_y; int32_t real_y;

View File

@@ -25,8 +25,8 @@
// add two to these because the primative functions should expect to // add two to these because the primative functions should expect to
// deal with x and z values of -1 and 16 // deal with x and z values of -1 and 16
typedef struct { typedef struct {
int32_t walked_chunk; bool walked_chunk;
int32_t remove_block[WIDTH + 2][HEIGHT][DEPTH + 2]; bool remove_block[WIDTH + 2][HEIGHT][DEPTH + 2];
} RenderPrimitiveNether; } RenderPrimitiveNether;

View File

@@ -17,33 +17,33 @@
#include "../overviewer.h" #include "../overviewer.h"
static int32_t static bool
netherold_hidden(void* data, RenderState* state, int32_t x, int32_t y, int32_t z) { netherold_hidden(void* data, RenderState* state, int32_t x, int32_t y, int32_t z) {
/* hide all blocks above all air blocks /* hide all blocks above all air blocks
due to how the nether is currently generated, this will also count due to how the nether is currently generated, this will also count
empty sections as 'solid' empty sections as 'solid'
*/ */
uint8_t missing_section = 0; bool missing_section = false;
while (y < (SECTIONS_PER_CHUNK - state->chunky) * 16) { while (y < (SECTIONS_PER_CHUNK - state->chunky) * 16) {
if (state->chunks[1][1].sections[state->chunky + (y / 16)].blocks == NULL) { if (state->chunks[1][1].sections[state->chunky + (y / 16)].blocks == NULL) {
missing_section = 1; missing_section = true;
y += 16; y += 16;
continue; continue;
} else { } else {
/* if we passed through a missing section, but now are back in, /* if we passed through a missing section, but now are back in,
that counts as air */ that counts as air */
if (missing_section) if (missing_section)
return 0; return false;
missing_section = 0; missing_section = true;
} }
if (!missing_section && get_data(state, BLOCKS, x, y, z) == 0) { if (!missing_section && get_data(state, BLOCKS, x, y, z) == 0) {
return 0; return false;
} }
y++; y++;
} }
return 1; return true;
} }
RenderPrimitiveInterface primitive_nether_old = { RenderPrimitiveInterface primitive_nether_old = {

View File

@@ -17,12 +17,12 @@
#include "../overviewer.h" #include "../overviewer.h"
static int32_t static bool
no_fluids_start(void* data, RenderState* state, PyObject* support) { no_fluids_start(void* data, RenderState* state, PyObject* support) {
return 0; return false;
} }
static int32_t static bool
no_fluids_hidden(void* data, RenderState* state, int32_t x, int32_t y, int32_t z) { no_fluids_hidden(void* data, RenderState* state, int32_t x, int32_t y, int32_t z) {
return block_has_property(state->block, FLUID); return block_has_property(state->block, FLUID);
} }

View File

@@ -110,15 +110,15 @@ static void get_color(void* data, RenderState* state,
} }
} }
static int32_t static bool
overlay_biomes_start(void* data, RenderState* state, PyObject* support) { overlay_biomes_start(void* data, RenderState* state, PyObject* support) {
PyObject* opt; PyObject* opt;
RenderPrimitiveBiomes* self; RenderPrimitiveBiomes* self;
uint8_t alpha_tmp = 0; uint8_t alpha_tmp = 0;
/* first, chain up */ /* first, chain up */
int32_t ret = primitive_overlay.start(data, state, support); bool ret = primitive_overlay.start(data, state, support);
if (ret != 0) if (ret != false)
return ret; return ret;
/* now do custom initializations */ /* now do custom initializations */
@@ -126,7 +126,7 @@ overlay_biomes_start(void* data, RenderState* state, PyObject* support) {
// opt is a borrowed reference. do not deref // opt is a borrowed reference. do not deref
if (!render_mode_parse_option(support, "biomes", "O", &(opt))) if (!render_mode_parse_option(support, "biomes", "O", &(opt)))
return 1; return true;
if (opt && opt != Py_None) { if (opt && opt != Py_None) {
struct BiomeColor* biomes = NULL; struct BiomeColor* biomes = NULL;
Py_ssize_t biomes_size = 0, i; Py_ssize_t biomes_size = 0, i;
@@ -134,13 +134,13 @@ overlay_biomes_start(void* data, RenderState* state, PyObject* support) {
if (!PyList_Check(opt)) { if (!PyList_Check(opt)) {
PyErr_SetString(PyExc_TypeError, "'biomes' must be a list"); PyErr_SetString(PyExc_TypeError, "'biomes' must be a list");
return 1; return true;
} }
biomes_size = PyList_GET_SIZE(opt); biomes_size = PyList_GET_SIZE(opt);
biomes = self->biomes = calloc(biomes_size + 1, sizeof(struct BiomeColor)); biomes = self->biomes = calloc(biomes_size + 1, sizeof(struct BiomeColor));
if (biomes == NULL) { if (biomes == NULL) {
return 1; return true;
} }
for (i = 0; i < biomes_size; i++) { for (i = 0; i < biomes_size; i++) {
@@ -151,7 +151,7 @@ overlay_biomes_start(void* data, RenderState* state, PyObject* support) {
if (!PyArg_ParseTuple(biome, "s(bbb)", &tmpname, &(biomes[i].r), &(biomes[i].g), &(biomes[i].b))) { if (!PyArg_ParseTuple(biome, "s(bbb)", &tmpname, &(biomes[i].r), &(biomes[i].g), &(biomes[i].b))) {
free(biomes); free(biomes);
self->biomes = NULL; self->biomes = NULL;
return 1; return true;
} }
//printf("%s, (%d, %d, %d) ->", tmpname, biomes[i].r, biomes[i].g, biomes[i].b); //printf("%s, (%d, %d, %d) ->", tmpname, biomes[i].r, biomes[i].g, biomes[i].b);
@@ -181,7 +181,7 @@ overlay_biomes_start(void* data, RenderState* state, PyObject* support) {
/* setup custom color */ /* setup custom color */
self->parent.get_color = get_color; self->parent.get_color = get_color;
return 0; return false;
} }
static void static void

View File

@@ -26,7 +26,7 @@ typedef struct {
} RenderPrimitiveMineral; } RenderPrimitiveMineral;
struct MineralColor { struct MineralColor {
uint8_t blockid; mc_block_t block;
uint8_t r, g, b; uint8_t r, g, b;
}; };
@@ -59,10 +59,10 @@ static void get_color(void* data, RenderState* state,
y_max = state->y + 1; y_max = state->y + 1;
for (y = state->chunky * -16; y <= y_max; y++) { for (y = state->chunky * -16; y <= y_max; y++) {
int32_t i, tmp; int32_t i, tmp;
mc_block_t blockid = get_data(state, BLOCKS, x, y, z); mc_block_t block = get_data(state, BLOCKS, x, y, z);
for (i = 0; (max_i == -1 || i < max_i) && minerals[i].blockid != block_air; i++) { for (i = 0; (max_i == -1 || i < max_i) && minerals[i].block != block_air; i++) {
if (minerals[i].blockid == blockid) { if (minerals[i].block == block) {
*r = minerals[i].r; *r = minerals[i].r;
*g = minerals[i].g; *g = minerals[i].g;
*b = minerals[i].b; *b = minerals[i].b;
@@ -77,14 +77,14 @@ static void get_color(void* data, RenderState* state,
} }
} }
static int32_t static bool
overlay_mineral_start(void* data, RenderState* state, PyObject* support) { overlay_mineral_start(void* data, RenderState* state, PyObject* support) {
PyObject* opt; PyObject* opt;
RenderPrimitiveMineral* self; RenderPrimitiveMineral* self;
/* first, chain up */ /* first, chain up */
int32_t ret = primitive_overlay.start(data, state, support); bool ret = primitive_overlay.start(data, state, support);
if (ret != 0) if (ret != false)
return ret; return ret;
/* now do custom initializations */ /* now do custom initializations */
@@ -92,7 +92,7 @@ overlay_mineral_start(void* data, RenderState* state, PyObject* support) {
// opt is a borrowed reference. do not deref // opt is a borrowed reference. do not deref
if (!render_mode_parse_option(support, "minerals", "O", &(opt))) if (!render_mode_parse_option(support, "minerals", "O", &(opt)))
return 1; return true;
if (opt && opt != Py_None) { if (opt && opt != Py_None) {
struct MineralColor* minerals = NULL; struct MineralColor* minerals = NULL;
Py_ssize_t minerals_size = 0, i; Py_ssize_t minerals_size = 0, i;
@@ -100,21 +100,21 @@ overlay_mineral_start(void* data, RenderState* state, PyObject* support) {
if (!PyList_Check(opt)) { if (!PyList_Check(opt)) {
PyErr_SetString(PyExc_TypeError, "'minerals' must be a list"); PyErr_SetString(PyExc_TypeError, "'minerals' must be a list");
return 1; return true;
} }
minerals_size = PyList_GET_SIZE(opt); minerals_size = PyList_GET_SIZE(opt);
minerals = self->minerals = calloc(minerals_size + 1, sizeof(struct MineralColor)); minerals = self->minerals = calloc(minerals_size + 1, sizeof(struct MineralColor));
if (minerals == NULL) { if (minerals == NULL) {
return 1; return true;
} }
for (i = 0; i < minerals_size; i++) { for (i = 0; i < minerals_size; i++) {
PyObject* mineral = PyList_GET_ITEM(opt, i); PyObject* mineral = PyList_GET_ITEM(opt, i);
if (!PyArg_ParseTuple(mineral, "b(bbb)", &(minerals[i].blockid), &(minerals[i].r), &(minerals[i].g), &(minerals[i].b))) { if (!PyArg_ParseTuple(mineral, "b(bbb)", &(minerals[i].block), &(minerals[i].r), &(minerals[i].g), &(minerals[i].b))) {
free(minerals); free(minerals);
self->minerals = NULL; self->minerals = NULL;
return 1; return true;
} }
} }
} else { } else {
@@ -124,7 +124,7 @@ overlay_mineral_start(void* data, RenderState* state, PyObject* support) {
/* setup custom color */ /* setup custom color */
self->parent.get_color = get_color; self->parent.get_color = get_color;
return 0; return false;
} }
static void static void

View File

@@ -21,7 +21,7 @@
typedef struct { typedef struct {
/* inherits from overlay */ /* inherits from overlay */
RenderPrimitiveOverlay parent; RenderPrimitiveOverlay parent;
long long seed; // needs to be at least 64-bits int64_t seed; // needs to be at least 64-bits
} RenderPrimitiveSlime; } RenderPrimitiveSlime;
/* /*
@@ -30,43 +30,38 @@ typedef struct {
* http://docs.oracle.com/javase/1.4.2/docs/api/java/util/Random.html * http://docs.oracle.com/javase/1.4.2/docs/api/java/util/Random.html
*/ */
static void random_set_seed(long long* seed, long long new_seed) { static void random_set_seed(int64_t* seed, int64_t new_seed) {
*seed = (new_seed ^ 0x5deece66dLL) & ((1LL << 48) - 1); *seed = (new_seed ^ 0x5deece66dLL) & ((1LL << 48) - 1);
} }
static int32_t random_next(long long* seed, int32_t bits) { static int64_t random_next(int64_t* seed, int32_t bits) {
*seed = (*seed * 0x5deece66dLL + 0xbL) & ((1LL << 48) - 1); *seed = (*seed * 0x5deece66dLL + 0xbL) & ((1LL << 48) - 1);
return (int)(*seed >> (48 - bits)); return (int64_t)(*seed >> (48 - bits));
} }
static int32_t random_next_int(long long* seed, int32_t n) { static int64_t random_next_int(int64_t* seed, uint32_t modulo) {
int32_t bits, val; int64_t bits, val;
if (n <= 0) { if ((modulo & -modulo) == modulo) {
/* invalid */ /* modulo is a power of two */
return 0; return (int64_t)((modulo * (int64_t)random_next(seed, 31)) >> 31);
}
if ((n & -n) == n) {
/* n is a power of two */
return (int)((n * (long long)random_next(seed, 31)) >> 31);
} }
do { do {
bits = random_next(seed, 31); bits = random_next(seed, 31);
val = bits % n; val = bits % modulo;
} while (bits - val + (n - 1) < 0); } while (bits - val + (modulo - 1) < 0);
return val; return val;
} }
static int32_t is_slime(long long map_seed, int32_t chunkx, int32_t chunkz) { static bool is_slime(int64_t map_seed, int32_t chunkx, int32_t chunkz) {
/* lots of magic numbers, but they're all correct! I swear! */ /* lots of magic numbers, but they're all correct! I swear! */
long long seed; int64_t seed;
random_set_seed(&seed, (map_seed + random_set_seed(&seed, (map_seed +
(long long)(chunkx * chunkx * 0x4c1906) + (int64_t)(chunkx * chunkx * 0x4c1906) +
(long long)(chunkx * 0x5ac0db) + (int64_t)(chunkx * 0x5ac0db) +
(long long)(chunkz * chunkz * 0x4307a7LL) + (int64_t)(chunkz * chunkz * 0x4307a7LL) +
(long long)(chunkz * 0x5f24f)) ^ (int64_t)(chunkz * 0x5f24f)) ^
0x3ad8025f); 0x3ad8025f);
return (random_next_int(&seed, 10) == 0); return (random_next_int(&seed, 10) == 0);
} }
@@ -89,14 +84,14 @@ static void get_color(void* data, RenderState* state,
} }
} }
static int32_t static bool
overlay_slime_start(void* data, RenderState* state, PyObject* support) { overlay_slime_start(void* data, RenderState* state, PyObject* support) {
RenderPrimitiveSlime* self; RenderPrimitiveSlime* self;
PyObject* pyseed; PyObject* pyseed;
/* first, chain up */ /* first, chain up */
int32_t ret = primitive_overlay.start(data, state, support); bool ret = primitive_overlay.start(data, state, support);
if (ret != 0) if (ret != false)
return ret; return ret;
/* now do custom initializations */ /* now do custom initializations */
@@ -110,13 +105,13 @@ overlay_slime_start(void* data, RenderState* state, PyObject* support) {
pyseed = PyObject_GetAttrString(state->world, "seed"); pyseed = PyObject_GetAttrString(state->world, "seed");
if (!pyseed) if (!pyseed)
return 1; return true;
self->seed = PyLong_AsLongLong(pyseed); self->seed = PyLong_AsLongLong(pyseed);
Py_DECREF(pyseed); Py_DECREF(pyseed);
if (PyErr_Occurred()) if (PyErr_Occurred())
return 1; return true;
return 0; return false;
} }
static void static void

View File

@@ -55,13 +55,13 @@ static void get_color(void* data, RenderState* state,
} }
} }
static int32_t static bool
overlay_spawn_start(void* data, RenderState* state, PyObject* support) { overlay_spawn_start(void* data, RenderState* state, PyObject* support) {
RenderPrimitiveSpawn* self; RenderPrimitiveSpawn* self;
/* first, chain up */ /* first, chain up */
int32_t ret = primitive_overlay.start(data, state, support); bool ret = primitive_overlay.start(data, state, support);
if (ret != 0) if (ret != false)
return ret; return ret;
/* now do custom initializations */ /* now do custom initializations */
@@ -73,7 +73,7 @@ overlay_spawn_start(void* data, RenderState* state, PyObject* support) {
self->parent.default_color.b = 38; self->parent.default_color.b = 38;
self->parent.default_color.a = 0; self->parent.default_color.a = 0;
return 0; return false;
} }
static void static void

View File

@@ -83,7 +83,7 @@ static void get_color(void* data,
return; return;
} }
static int32_t overlay_structure_start(void* data, RenderState* state, PyObject* support) { static bool overlay_structure_start(void* data, RenderState* state, PyObject* support) {
/** /**
* Initializing the search for structures by parsing the arguments and storing them into * Initializing the search for structures by parsing the arguments and storing them into
* appropriate structures. If no arguments are passed create and use default values. * appropriate structures. If no arguments are passed create and use default values.
@@ -92,8 +92,8 @@ static int32_t overlay_structure_start(void* data, RenderState* state, PyObject*
RenderPrimitiveStructure* self; RenderPrimitiveStructure* self;
/* first, chain up */ /* first, chain up */
int32_t ret = primitive_overlay.start(data, state, support); bool ret = primitive_overlay.start(data, state, support);
if (ret != 0) if (ret != false)
return ret; return ret;
/* now do custom initializations */ /* now do custom initializations */
@@ -102,7 +102,7 @@ static int32_t overlay_structure_start(void* data, RenderState* state, PyObject*
// opt is a borrowed reference. do not deref // opt is a borrowed reference. do not deref
// store the structures python object into opt. // store the structures python object into opt.
if (!render_mode_parse_option(support, "structures", "O", &(opt))) if (!render_mode_parse_option(support, "structures", "O", &(opt)))
return 1; return true;
/** /**
* Check if a sane option was passed. * Check if a sane option was passed.
@@ -116,7 +116,7 @@ static int32_t overlay_structure_start(void* data, RenderState* state, PyObject*
opt = PySequence_Fast(opt, "expected a sequence"); opt = PySequence_Fast(opt, "expected a sequence");
if (!opt) { if (!opt) {
PyErr_SetString(PyExc_TypeError, "'structures' must be a a sequence"); PyErr_SetString(PyExc_TypeError, "'structures' must be a a sequence");
return 1; return true;
} }
structures_size = PySequence_Fast_GET_SIZE(opt); structures_size = PySequence_Fast_GET_SIZE(opt);
@@ -125,7 +125,7 @@ static int32_t overlay_structure_start(void* data, RenderState* state, PyObject*
self->numcolors = structures_size; self->numcolors = structures_size;
if (structures == NULL) { if (structures == NULL) {
PyErr_SetString(PyExc_MemoryError, "failed to allocate memory"); PyErr_SetString(PyExc_MemoryError, "failed to allocate memory");
return 1; return true;
} }
/** /**
@@ -144,7 +144,7 @@ static int32_t overlay_structure_start(void* data, RenderState* state, PyObject*
// Exception set automatically // Exception set automatically
free(structures); free(structures);
self->structures = NULL; self->structures = NULL;
return 1; return true;
} }
// Parse colorpy into a c-struct. // Parse colorpy into a c-struct.
@@ -155,7 +155,7 @@ static int32_t overlay_structure_start(void* data, RenderState* state, PyObject*
&structures[i].a)) { &structures[i].a)) {
free(structures); free(structures);
self->structures = NULL; self->structures = NULL;
return 1; return true;
} }
// Convert condspy to a fast sequence // Convert condspy to a fast sequence
@@ -163,7 +163,7 @@ static int32_t overlay_structure_start(void* data, RenderState* state, PyObject*
if (condspy == NULL) { if (condspy == NULL) {
free(structures); free(structures);
self->structures = NULL; self->structures = NULL;
return 1; return true;
} }
// get the number of conditions. // get the number of conditions.
@@ -176,7 +176,7 @@ static int32_t overlay_structure_start(void* data, RenderState* state, PyObject*
PyErr_SetString(PyExc_MemoryError, "failed to allocate memory"); PyErr_SetString(PyExc_MemoryError, "failed to allocate memory");
free(structures); free(structures);
self->structures = NULL; self->structures = NULL;
return 1; return true;
} }
// iterate over all the conditions and read them. // iterate over all the conditions and read them.
@@ -193,7 +193,7 @@ static int32_t overlay_structure_start(void* data, RenderState* state, PyObject*
} }
free(structures); free(structures);
self->structures = NULL; self->structures = NULL;
return 1; return true;
} }
} }
} }
@@ -203,7 +203,7 @@ static int32_t overlay_structure_start(void* data, RenderState* state, PyObject*
/* setup custom color */ /* setup custom color */
self->parent.get_color = get_color; self->parent.get_color = get_color;
return 0; return false;
} }
static void overlay_structure_finish(void* data, RenderState* state) { static void overlay_structure_finish(void* data, RenderState* state) {

View File

@@ -41,7 +41,7 @@ overlay_start(void* data, RenderState* state, PyObject* support) {
color = self->color = calloc(1, sizeof(OverlayColor)); color = self->color = calloc(1, sizeof(OverlayColor));
if (color == NULL) { if (color == NULL) {
return 1; return true;
} }
self->default_color.r = 200; self->default_color.r = 200;
@@ -58,12 +58,12 @@ overlay_start(void* data, RenderState* state, PyObject* support) {
if (render_mode_parse_option(support, "overlay_color", "O", &(opt))) { if (render_mode_parse_option(support, "overlay_color", "O", &(opt))) {
// If it is an object, check to see if it is None, if it is, use the default. // If it is an object, check to see if it is None, if it is, use the default.
if (opt && opt != Py_None) { if (opt && opt != Py_None) {
return 1; return true;
} }
} }
} }
return 0; return false;
} }
static void static void

View File

@@ -181,13 +181,13 @@ do_shading_with_rule(RenderPrimitiveSmoothLighting* self, RenderState* state, st
x, y, NULL, 0); x, y, NULL, 0);
} }
static int32_t static bool
smooth_lighting_start(void* data, RenderState* state, PyObject* support) { smooth_lighting_start(void* data, RenderState* state, PyObject* support) {
/* first, chain up */ /* first, chain up */
int32_t ret = primitive_lighting.start(data, state, support); bool ret = primitive_lighting.start(data, state, support);
if (ret != 0) if (ret != false)
return ret; return ret;
return 0; return false;
} }
static void static void
@@ -198,9 +198,9 @@ smooth_lighting_finish(void* data, RenderState* state) {
static void static void
smooth_lighting_draw(void* data, RenderState* state, PyObject* src, PyObject* mask, PyObject* mask_light) { smooth_lighting_draw(void* data, RenderState* state, PyObject* src, PyObject* mask, PyObject* mask_light) {
int32_t light_top = 1; bool light_top = true;
int32_t light_left = 1; bool light_left = true;
int32_t light_right = 1; bool light_right = true;
RenderPrimitiveSmoothLighting* self = (RenderPrimitiveSmoothLighting*)data; RenderPrimitiveSmoothLighting* self = (RenderPrimitiveSmoothLighting*)data;
/* special case for leaves, water 8, water 9, ice 79 /* special case for leaves, water 8, water 9, ice 79
@@ -216,11 +216,11 @@ smooth_lighting_draw(void* data, RenderState* state, PyObject* src, PyObject* ma
/* special code for water */ /* special code for water */
if (state->block == block_water) { if (state->block == block_water) {
if (!(state->block_pdata & (1 << 4))) if (!(state->block_pdata & (1 << 4)))
light_top = 0; light_top = false;
if (!(state->block_pdata & (1 << 1))) if (!(state->block_pdata & (1 << 1)))
light_left = 0; light_left = false;
if (!(state->block_pdata & (1 << 2))) if (!(state->block_pdata & (1 << 2)))
light_right = 0; light_right = false;
} }
if (light_top) if (light_top)

View File

@@ -129,9 +129,9 @@ void render_mode_destroy(RenderMode* self) {
free(self); free(self);
} }
int32_t render_mode_occluded(RenderMode* self, int32_t x, int32_t y, int32_t z) { bool render_mode_occluded(RenderMode* self, int32_t x, int32_t y, int32_t z) {
uint32_t i; uint32_t i;
int32_t occluded = 0; bool occluded = false;
for (i = 0; i < self->num_primitives; i++) { for (i = 0; i < self->num_primitives; i++) {
RenderPrimitive* prim = self->primitives[i]; RenderPrimitive* prim = self->primitives[i];
if (prim->iface->occluded) { if (prim->iface->occluded) {
@@ -144,9 +144,9 @@ int32_t render_mode_occluded(RenderMode* self, int32_t x, int32_t y, int32_t z)
return occluded; return occluded;
} }
int32_t render_mode_hidden(RenderMode* self, int32_t x, int32_t y, int32_t z) { bool render_mode_hidden(RenderMode* self, int32_t x, int32_t y, int32_t z) {
uint32_t i; uint32_t i;
int32_t hidden = 0; bool hidden = false;
for (i = 0; i < self->num_primitives; i++) { for (i = 0; i < self->num_primitives; i++) {
RenderPrimitive* prim = self->primitives[i]; RenderPrimitive* prim = self->primitives[i];
if (prim->iface->hidden) { if (prim->iface->hidden) {
@@ -170,22 +170,22 @@ void render_mode_draw(RenderMode* self, PyObject* img, PyObject* mask, PyObject*
} }
/* options parse helper */ /* options parse helper */
int32_t render_mode_parse_option(PyObject* support, const char* name, const char* format, ...) { bool render_mode_parse_option(PyObject* support, const char* name, const char* format, ...) {
va_list ap; va_list ap;
PyObject *item, *dict; PyObject *item, *dict;
int32_t ret; bool ret;
if (support == NULL || name == NULL) if (support == NULL || name == NULL)
return 0; return false;
dict = PyObject_GetAttrString(support, "option_values"); dict = PyObject_GetAttrString(support, "option_values");
if (!dict) if (!dict)
return 0; return false;
item = PyDict_GetItemString(dict, name); item = PyDict_GetItemString(dict, name);
if (item == NULL) { if (item == NULL) {
Py_DECREF(dict); Py_DECREF(dict);
return 0; return false;
}; };
/* make sure the item we're parsing is a tuple /* make sure the item we're parsing is a tuple

View File

@@ -51,14 +51,14 @@ typedef struct {
/* the size of the local storage for this rendermode */ /* the size of the local storage for this rendermode */
uint32_t data_size; uint32_t data_size;
/* may return non-zero on error, last arg is the python support object */ /* may return true on error, last arg is the python support object */
int32_t (*start)(void*, RenderState*, PyObject*); bool (*start)(void*, RenderState*, PyObject*);
void (*finish)(void*, RenderState*); void (*finish)(void*, RenderState*);
/* returns non-zero to skip rendering this block because it's not visible */ /* returns true to skip rendering this block because it's not visible */
int32_t (*occluded)(void*, RenderState*, int, int, int); bool (*occluded)(void*, RenderState*, int, int, int);
/* returns non-zero to skip rendering this block because the user doesn't /* returns true to skip rendering this block because the user doesn't
* want it visible */ * want it visible */
int32_t (*hidden)(void*, RenderState*, int, int, int); bool (*hidden)(void*, RenderState*, int, int, int);
/* last two arguments are img and mask, from texture lookup */ /* last two arguments are img and mask, from texture lookup */
void (*draw)(void*, RenderState*, PyObject*, PyObject*, PyObject*); void (*draw)(void*, RenderState*, PyObject*, PyObject*, PyObject*);
} RenderPrimitiveInterface; } RenderPrimitiveInterface;
@@ -94,12 +94,12 @@ struct _RenderMode {
/* functions for creating / using rendermodes */ /* functions for creating / using rendermodes */
RenderMode* render_mode_create(PyObject* mode, RenderState* state); RenderMode* render_mode_create(PyObject* mode, RenderState* state);
void render_mode_destroy(RenderMode* self); void render_mode_destroy(RenderMode* self);
int32_t render_mode_occluded(RenderMode* self, int32_t x, int32_t y, int32_t z); bool render_mode_occluded(RenderMode* self, int32_t x, int32_t y, int32_t z);
int32_t render_mode_hidden(RenderMode* self, int32_t x, int32_t y, int32_t z); bool render_mode_hidden(RenderMode* self, int32_t x, int32_t y, int32_t z);
void render_mode_draw(RenderMode* self, PyObject* img, PyObject* mask, PyObject* mask_light); void render_mode_draw(RenderMode* self, PyObject* img, PyObject* mask, PyObject* mask_light);
/* helper function for reading in rendermode options /* helper function for reading in rendermode options
works like PyArg_ParseTuple on a support object */ works like PyArg_ParseTuple on a support object */
int32_t render_mode_parse_option(PyObject* support, const char* name, const char* format, ...); bool render_mode_parse_option(PyObject* support, const char* name, const char* format, ...);
#endif /* __RENDERMODES_H_INCLUDED__ */ #endif /* __RENDERMODES_H_INCLUDED__ */