0

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:
Wunkolo
2019-06-23 18:43:32 -07:00
parent 676bf32af9
commit 8162f3f877
36 changed files with 1299 additions and 1372 deletions

View File

@@ -15,9 +15,9 @@
* 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"
#include "biomes.h"
typedef struct {
@@ -25,32 +25,31 @@ typedef struct {
/* grasscolor and foliagecolor lookup tables */
PyObject *grasscolor, *foliagecolor, *watercolor;
/* biome-compatible grass/leaf textures */
PyObject *grass_texture;
PyObject* grass_texture;
} PrimitiveBase;
static int
base_start(void *data, RenderState *state, PyObject *support) {
PrimitiveBase *self = (PrimitiveBase *)data;
base_start(void* data, RenderState* state, PyObject* support) {
PrimitiveBase* self = (PrimitiveBase*)data;
if (!render_mode_parse_option(support, "biomes", "i", &(self->use_biomes)))
return 1;
/* biome-compliant grass mask (includes sides!) */
self->grass_texture = PyObject_GetAttrString(state->textures, "biome_grass_texture");
/* color lookup tables */
self->foliagecolor = PyObject_CallMethod(state->textures, "load_foliage_color", "");
self->grasscolor = PyObject_CallMethod(state->textures, "load_grass_color", "");
self->watercolor = PyObject_CallMethod(state->textures, "load_water_color", "");
return 0;
}
static void
base_finish(void *data, RenderState *state) {
PrimitiveBase *self = (PrimitiveBase *)data;
base_finish(void* data, RenderState* state) {
PrimitiveBase* self = (PrimitiveBase*)data;
Py_DECREF(self->foliagecolor);
Py_DECREF(self->grasscolor);
Py_DECREF(self->watercolor);
@@ -58,14 +57,14 @@ base_finish(void *data, RenderState *state) {
}
static int
base_occluded(void *data, RenderState *state, int x, int y, int z) {
if ( (x != 0) && (y != 15) && (z != 15) &&
!render_mode_hidden(state->rendermode, x-1, y, z) &&
!render_mode_hidden(state->rendermode, x, y, z+1) &&
!render_mode_hidden(state->rendermode, x, y+1, 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+1, z))) {
base_occluded(void* data, RenderState* state, int x, int y, int z) {
if ((x != 0) && (y != 15) && (z != 15) &&
!render_mode_hidden(state->rendermode, x - 1, y, z) &&
!render_mode_hidden(state->rendermode, x, y, z + 1) &&
!render_mode_hidden(state->rendermode, x, y + 1, 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 + 1, z))) {
return 1;
}
@@ -73,16 +72,16 @@ base_occluded(void *data, RenderState *state, int x, int y, int z) {
}
static void
base_draw(void *data, RenderState *state, PyObject *src, PyObject *mask, PyObject *mask_light) {
PrimitiveBase *self = (PrimitiveBase *)data;
base_draw(void* data, RenderState* state, PyObject* src, PyObject* mask, PyObject* mask_light) {
PrimitiveBase* self = (PrimitiveBase*)data;
/* in order to detect top parts of doublePlant grass & ferns */
unsigned short below_block = get_data(state, BLOCKS, state->x, state->y-1, state->z);
unsigned char below_data = get_data(state, DATA, state->x, state->y-1, state->z);
unsigned short below_block = get_data(state, BLOCKS, state->x, state->y - 1, state->z);
unsigned char below_data = get_data(state, DATA, state->x, state->y - 1, state->z);
/* draw the block! */
alpha_over(state->img, src, mask, state->imgx, state->imgy, 0, 0);
/* check for biome-compatible blocks
*
* NOTES for maintainers:
@@ -95,16 +94,9 @@ base_draw(void *data, RenderState *state, PyObject *src, PyObject *mask, PyObjec
* biome-compliant ones! The tinting is now all done here.
*/
if (/* grass, but not snowgrass */
(state->block == block_grass && get_data(state, BLOCKS, state->x, state->y+1, state->z) != 78) ||
block_class_is_subset(state->block, (mc_block_t[]){
block_vine,
block_waterlily,
block_flowing_water,
block_water,
block_leaves,
block_leaves2
},
6) ||
(state->block == block_grass && get_data(state, BLOCKS, state->x, state->y + 1, state->z) != 78) ||
block_class_is_subset(state->block, (mc_block_t[]){block_vine, block_waterlily, block_flowing_water, block_water, block_leaves, block_leaves2},
6) ||
/* tallgrass, but not dead shrubs */
(state->block == block_tallgrass && state->block_data != 0) ||
/* pumpkin/melon stem, not fully grown. Fully grown stems
@@ -113,46 +105,30 @@ base_draw(void *data, RenderState *state, PyObject *src, PyObject *mask, PyObjec
/* doublePlant grass & ferns */
(state->block == block_double_plant && (state->block_data == 2 || state->block_data == 3)) ||
/* doublePlant grass & ferns tops */
(state->block == block_double_plant && below_block == block_double_plant && (below_data == 2 || below_data == 3)) )
{
(state->block == block_double_plant && below_block == block_double_plant && (below_data == 2 || below_data == 3))) {
/* do the biome stuff! */
PyObject *facemask = mask;
PyObject* facemask = mask;
unsigned char r = 255, g = 255, b = 255;
PyObject *color_table = NULL;
PyObject* color_table = NULL;
unsigned char flip_xy = 0;
if (state->block == block_grass) {
/* grass needs a special facemask */
facemask = self->grass_texture;
}
if(block_class_is_subset(state->block, (mc_block_t[]){
block_grass,
block_tallgrass,
block_pumpkin_stem,
block_melon_stem,
block_vine,
block_waterlily,
block_double_plant
},7)) {
if (block_class_is_subset(state->block, (mc_block_t[]){block_grass, block_tallgrass, block_pumpkin_stem, block_melon_stem, block_vine, block_waterlily, block_double_plant}, 7)) {
color_table = self->grasscolor;
}
else if(block_class_is_subset(state->block, (mc_block_t[]){
block_flowing_water,block_water
},2)) {
} else if (block_class_is_subset(state->block, (mc_block_t[]){block_flowing_water, block_water}, 2)) {
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;
if (state->block_data == 2)
{
if (state->block_data == 2) {
/* birch!
birch foliage color is flipped XY-ways */
flip_xy = 1;
}
}
if (color_table) {
unsigned char biome;
int dx, dz;
@@ -160,8 +136,8 @@ base_draw(void *data, RenderState *state, PyObject *src, PyObject *mask, PyObjec
float temp = 0.0, rain = 0.0;
unsigned int multr = 0, multg = 0, multb = 0;
int tmp;
PyObject *color = NULL;
PyObject* color = NULL;
if (self->use_biomes) {
/* average over all neighbors */
for (dx = -1; dx <= 1; dx++) {
@@ -173,7 +149,7 @@ base_draw(void *data, RenderState *state, PyObject *src, PyObject *mask, PyObjec
*/
biome = DEFAULT_BIOME; /* forest -- reasonable default */
}
temp += biome_table[biome].temperature;
rain += biome_table[biome].rainfall;
multr += biome_table[biome].r;
@@ -181,7 +157,7 @@ base_draw(void *data, RenderState *state, PyObject *src, PyObject *mask, PyObjec
multb += biome_table[biome].b;
}
}
temp /= 9.0;
rain /= 9.0;
multr /= 9;
@@ -195,15 +171,15 @@ base_draw(void *data, RenderState *state, PyObject *src, PyObject *mask, PyObjec
multg = biome_table[DEFAULT_BIOME].g;
multb = biome_table[DEFAULT_BIOME].b;
}
/* second coordinate is actually scaled to fit inside the triangle
so store it in rain */
rain *= temp;
/* make sure they're sane */
temp = OV_CLAMP(temp, 0.0, 1.0);
rain = OV_CLAMP(rain, 0.0, 1.0);
/* convert to x/y coordinates in color table */
tablex = 255 - (255 * temp);
tabley = 255 - (255 * rain);
@@ -212,27 +188,28 @@ base_draw(void *data, RenderState *state, PyObject *src, PyObject *mask, PyObjec
tablex = 255 - tabley;
tabley = tmp;
}
/* look up color! */
color = PySequence_GetItem(color_table, tabley * 256 + tablex);
r = PyLong_AsLong(PyTuple_GET_ITEM(color, 0));
g = PyLong_AsLong(PyTuple_GET_ITEM(color, 1));
b = PyLong_AsLong(PyTuple_GET_ITEM(color, 2));
Py_DECREF(color);
/* do the after-coloration */
r = OV_MULDIV255(r, multr, tmp);
g = OV_MULDIV255(g, multg, tmp);
b = OV_MULDIV255(b, multb, tmp);
}
/* final coloration */
tint_with_mask(state->img, r, g, b, 255, facemask, state->imgx, state->imgy, 0, 0);
}
}
RenderPrimitiveInterface primitive_base = {
"base", sizeof(PrimitiveBase),
"base",
sizeof(PrimitiveBase),
base_start,
base_finish,
base_occluded,

View File

@@ -15,7 +15,6 @@
* with the Overviewer. If not, see <http://www.gnu.org/licenses/>.
*/
#define DEFAULT_BIOME 4 /* forest, nice and green */
typedef struct {
@@ -65,7 +64,7 @@ static Biome biome_table[] = {
{"TaigaHills", 0.05, 0.8, 255, 255, 255},
/* 20 */
{"Extreme Hills Edge", 0.2, 0.3, 255, 255, 255},
/* Values below are guesses */
/* Values below are guesses */
{"Jungle", 2.0, 0.45, 255, 255, 255},
{"JungleHills", 2.0, 0.45, 255, 255, 255},
{"JungleEdge", 2.0, 0.45, 255, 255, 255},
@@ -245,4 +244,3 @@ static Biome biome_table[] = {
};
#define NUM_BIOMES (sizeof(biome_table) / sizeof(Biome))

View File

@@ -15,40 +15,40 @@
* with the Overviewer. If not, see <http://www.gnu.org/licenses/>.
*/
#include "../overviewer.h"
#include <math.h>
#include "../overviewer.h"
typedef struct {
int only_lit;
} RenderPrimitiveCave;
static inline int
touches_light(RenderState *state, DataType type, unsigned int x, unsigned int y, unsigned int z) {
if (get_data(state, type, x, y+1, z))
touches_light(RenderState* state, DataType type, unsigned int x, unsigned int y, unsigned int z) {
if (get_data(state, type, x, y + 1, z))
return 1;
if (get_data(state, type, x+1, y, z))
if (get_data(state, type, x + 1, y, z))
return 1;
if (get_data(state, type, x-1, y, z))
if (get_data(state, type, x - 1, y, z))
return 1;
if (get_data(state, type, x, y, z+1))
if (get_data(state, type, x, y, z + 1))
return 1;
if (get_data(state, type, x, y, z-1))
if (get_data(state, type, x, y, z - 1))
return 1;
return 0;
}
static int
cave_occluded(void *data, RenderState *state, int x, int y, int z) {
cave_occluded(void* data, RenderState* state, int x, int y, int z) {
/* check for normal occlusion */
/* use ajacent chunks, if not you get blocks spreaded in chunk edges */
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+1, 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 + 1, z))) {
return 1;
}
/* special handling for section boundaries */
if (x == 0 && (!(state->chunks[0][1].loaded) || state->chunks[0][1].sections[state->chunky].blocks == NULL))
return 1;
@@ -56,21 +56,21 @@ cave_occluded(void *data, RenderState *state, int x, int y, int z) {
return 1;
if (z == 15 && (!(state->chunks[1][2].loaded) || state->chunks[1][2].sections[state->chunky].blocks == NULL))
return 1;
return 0;
}
static int
cave_hidden(void *data, RenderState *state, int x, int y, int z) {
cave_hidden(void* data, RenderState* state, int x, int y, int z) {
RenderPrimitiveCave* self;
int dy = 0;
self = (RenderPrimitiveCave *)data;
self = (RenderPrimitiveCave*)data;
/* check if the block is touching skylight */
if (touches_light(state, SKYLIGHT, x, y, z)) {
return 1;
}
if (self->only_lit && !touches_light(state, BLOCKLIGHT, x, y, z)) {
return 1;
}
@@ -80,9 +80,9 @@ cave_hidden(void *data, RenderState *state, int x, int y, int z) {
* but a deep sea can be completely dark
*/
if ((getArrayShort3D(state->blocks, x, y, z) == 9) ||
(get_data(state, BLOCKS, x, y+1, z) == 9)) {
for (dy = y+1; dy < (SECTIONS_PER_CHUNK - state->chunky) * 16; dy++) {
(get_data(state, BLOCKS, x, y + 1, z) == 9)) {
for (dy = y + 1; dy < (SECTIONS_PER_CHUNK - state->chunky) * 16; dy++) {
/* go up and check for skylight */
if (get_data(state, SKYLIGHT, x, dy, z) != 0) {
return 1;
@@ -94,7 +94,7 @@ cave_hidden(void *data, RenderState *state, int x, int y, int z) {
}
}
}
/* unfortunate side-effect of lit cave mode: we need to count occluded
* blocks as hidden for the lighting to look right, since technically our
* hiding depends on occlusion as well
@@ -103,18 +103,19 @@ cave_hidden(void *data, RenderState *state, int x, int y, int z) {
}
static int
cave_start(void *data, RenderState *state, PyObject *support) {
cave_start(void* data, RenderState* state, PyObject* support) {
RenderPrimitiveCave* self;
self = (RenderPrimitiveCave *)data;
self = (RenderPrimitiveCave*)data;
if (!render_mode_parse_option(support, "only_lit", "i", &(self->only_lit)))
return 1;
return 0;
}
RenderPrimitiveInterface primitive_cave = {
"cave", sizeof(RenderPrimitiveCave),
"cave",
sizeof(RenderPrimitiveCave),
cave_start,
NULL,
cave_occluded,

View File

@@ -18,22 +18,22 @@
#include "../overviewer.h"
static int
clear_base_occluded(void *data, RenderState *state, int x, int y, int z) {
if ( (x != 0) && (y != 15) && (z != 127) &&
!render_mode_hidden(state->rendermode, x-1, y, z) &&
!render_mode_hidden(state->rendermode, x, y, z+1) &&
!render_mode_hidden(state->rendermode, x, y+1, 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+1, z))) {
clear_base_occluded(void* data, RenderState* state, int x, int y, int z) {
if ((x != 0) && (y != 15) && (z != 127) &&
!render_mode_hidden(state->rendermode, x - 1, y, z) &&
!render_mode_hidden(state->rendermode, x, y, z + 1) &&
!render_mode_hidden(state->rendermode, x, y + 1, 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 + 1, z))) {
return 1;
}
return 0;
}
static void
clear_base_draw(void *data, RenderState *state, PyObject *src, PyObject *mask, PyObject *mask_light) {
clear_base_draw(void* data, RenderState* state, PyObject* src, PyObject* mask, PyObject* mask_light) {
/* clear the draw space -- set alpha to 0 within mask */
tint_with_mask(state->img, 255, 255, 255, 0, mask, state->imgx, state->imgy, 0, 0);
}

View File

@@ -15,18 +15,18 @@
* with the Overviewer. If not, see <http://www.gnu.org/licenses/>.
*/
#include "../overviewer.h"
#include <math.h>
#include "../overviewer.h"
typedef struct {
/* list of colors used for tinting */
PyObject *depth_colors;
PyObject* depth_colors;
} RenderPrimitiveDepthTinting;
static int
depth_tinting_start(void *data, RenderState *state, PyObject *support) {
depth_tinting_start(void* data, RenderState* state, PyObject* support) {
RenderPrimitiveDepthTinting* self;
self = (RenderPrimitiveDepthTinting *)data;
self = (RenderPrimitiveDepthTinting*)data;
self->depth_colors = PyObject_GetAttrString(support, "depth_colors");
if (self->depth_colors == NULL)
@@ -36,35 +36,36 @@ depth_tinting_start(void *data, RenderState *state, PyObject *support) {
}
static void
depth_tinting_finish(void *data, RenderState *state) {
depth_tinting_finish(void* data, RenderState* state) {
RenderPrimitiveDepthTinting* self;
self = (RenderPrimitiveDepthTinting *)data;
self = (RenderPrimitiveDepthTinting*)data;
Py_DECREF(self->depth_colors);
}
static void
depth_tinting_draw(void *data, RenderState *state, PyObject *src, PyObject *mask, PyObject *mask_light) {
depth_tinting_draw(void* data, RenderState* state, PyObject* src, PyObject* mask, PyObject* mask_light) {
RenderPrimitiveDepthTinting* self;
int y, r, g, b;
self = (RenderPrimitiveDepthTinting *)data;
self = (RenderPrimitiveDepthTinting*)data;
y = state->chunky * 16 + state->y;
r = 0, g = 0, b = 0;
/* the colors array assumes y is between 0 and 127, so we scale it */
y = (y * 128) / (16 * SECTIONS_PER_CHUNK);
/* get the colors and tint and tint */
r = PyLong_AsLong(PyList_GetItem(self->depth_colors, 0 + y*3));
g = PyLong_AsLong(PyList_GetItem(self->depth_colors, 1 + y*3));
b = PyLong_AsLong(PyList_GetItem(self->depth_colors, 2 + y*3));
r = PyLong_AsLong(PyList_GetItem(self->depth_colors, 0 + y * 3));
g = PyLong_AsLong(PyList_GetItem(self->depth_colors, 1 + y * 3));
b = PyLong_AsLong(PyList_GetItem(self->depth_colors, 2 + y * 3));
tint_with_mask(state->img, r, g, b, 255, mask, state->imgx, state->imgy, 0, 0);
}
RenderPrimitiveInterface primitive_depth_tinting = {
"depth-tinting", sizeof(RenderPrimitiveDepthTinting),
"depth-tinting",
sizeof(RenderPrimitiveDepthTinting),
depth_tinting_start,
depth_tinting_finish,
NULL,

View File

@@ -23,9 +23,9 @@ typedef struct {
} PrimitiveDepth;
static int
depth_start(void *data, RenderState *state, PyObject *support) {
PrimitiveDepth *self = (PrimitiveDepth *)data;
depth_start(void* data, RenderState* state, PyObject* support) {
PrimitiveDepth* self = (PrimitiveDepth*)data;
if (!render_mode_parse_option(support, "min", "I", &(self->min)))
return 1;
if (!render_mode_parse_option(support, "max", "I", &(self->max)))
@@ -35,8 +35,8 @@ depth_start(void *data, RenderState *state, PyObject *support) {
}
static int
depth_hidden(void *data, RenderState *state, int x, int y, int z) {
PrimitiveDepth *self = (PrimitiveDepth *)data;
depth_hidden(void* data, RenderState* state, int x, int y, int z) {
PrimitiveDepth* self = (PrimitiveDepth*)data;
y += 16 * state->chunky;
if (y > self->max || y < self->min) {
return 1;
@@ -45,7 +45,8 @@ depth_hidden(void *data, RenderState *state, int x, int y, int z) {
}
RenderPrimitiveInterface primitive_depth = {
"depth", sizeof(PrimitiveDepth),
"depth",
sizeof(PrimitiveDepth),
depth_start,
NULL,
NULL,

View File

@@ -15,69 +15,65 @@
* 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"
typedef struct {
float opacity;
} PrimitiveEdgeLines;
static int
edge_lines_start(void *data, RenderState *state, PyObject *support) {
PrimitiveEdgeLines *self = (PrimitiveEdgeLines *)data;
edge_lines_start(void* data, RenderState* state, PyObject* support) {
PrimitiveEdgeLines* self = (PrimitiveEdgeLines*)data;
if (!render_mode_parse_option(support, "opacity", "f", &(self->opacity)))
return 1;
return 0;
}
static void
edge_lines_draw(void *data, RenderState *state, PyObject *src, PyObject *mask, PyObject *mask_light) {
PrimitiveEdgeLines *self = (PrimitiveEdgeLines *)data;
edge_lines_draw(void* data, RenderState* state, PyObject* src, PyObject* mask, PyObject* mask_light) {
PrimitiveEdgeLines* self = (PrimitiveEdgeLines*)data;
/* Draw some edge lines! */
if (block_class_is_subset(state->block, (mc_block_t[]){block_stone_slab,block_snow_layer}, 2)
|| !is_transparent(state->block)) {
if (block_class_is_subset(state->block, (mc_block_t[]){block_stone_slab, block_snow_layer}, 2) || !is_transparent(state->block)) {
Imaging img_i = imaging_python_to_c(state->img);
unsigned char ink[] = {0, 0, 0, 255 * self->opacity};
unsigned short side_block;
int x = state->x, y = state->y, z = state->z;
int increment=0;
if (block_class_is_subset(state->block, (mc_block_t[]){block_wooden_slab,block_stone_slab}, 2) && ((state->block_data & 0x8) == 0 )) // half-steps BUT no upsidown half-steps
increment=6;
else if (block_class_is_subset(state->block, (mc_block_t[]){block_snow_layer,block_unpowered_repeater,block_powered_repeater}, 3)) // snow, redstone repeaters (on and off)
increment=9;
int increment = 0;
if (block_class_is_subset(state->block, (mc_block_t[]){block_wooden_slab, block_stone_slab}, 2) && ((state->block_data & 0x8) == 0)) // half-steps BUT no upsidown half-steps
increment = 6;
else if (block_class_is_subset(state->block, (mc_block_t[]){block_snow_layer, block_unpowered_repeater, block_powered_repeater}, 3)) // snow, redstone repeaters (on and off)
increment = 9;
/* +X side */
side_block = get_data(state, BLOCKS, x+1, y, z);
if (side_block != state->block && (is_transparent(side_block) || render_mode_hidden(state->rendermode, x+1, y, z)) &&
side_block = get_data(state, BLOCKS, x + 1, y, z);
if (side_block != state->block && (is_transparent(side_block) || render_mode_hidden(state->rendermode, x + 1, y, z)) &&
/* WARNING: ugly special case approaching */
/* if the block is a slab and the side block is a stair don't draw anything, it can give very ugly results */
!(block_class_is_subset(state->block, (mc_block_t[]){block_wooden_slab, block_stone_slab}, 2)
&& (block_class_is_subset(side_block, block_class_stair, block_class_stair_len))
)) {
ImagingDrawLine(img_i, state->imgx+12, state->imgy+1+increment, state->imgx+22+1, state->imgy+5+1+increment, &ink, 1);
ImagingDrawLine(img_i, state->imgx+12, state->imgy+increment, state->imgx+22+1, state->imgy+5+increment, &ink, 1);
!(block_class_is_subset(state->block, (mc_block_t[]){block_wooden_slab, block_stone_slab}, 2) && (block_class_is_subset(side_block, block_class_stair, block_class_stair_len)))) {
ImagingDrawLine(img_i, state->imgx + 12, state->imgy + 1 + increment, state->imgx + 22 + 1, state->imgy + 5 + 1 + increment, &ink, 1);
ImagingDrawLine(img_i, state->imgx + 12, state->imgy + increment, state->imgx + 22 + 1, state->imgy + 5 + increment, &ink, 1);
}
/* -Z side */
side_block = get_data(state, BLOCKS, x, y, z-1);
if (side_block != state->block && (is_transparent(side_block) || render_mode_hidden(state->rendermode, x, y, z-1)) &&
side_block = get_data(state, BLOCKS, x, y, z - 1);
if (side_block != state->block && (is_transparent(side_block) || render_mode_hidden(state->rendermode, x, y, z - 1)) &&
/* WARNING: ugly special case approaching */
/* if the block is a slab and the side block is a stair don't draw anything, it can give very ugly results */
!(
block_class_is_subset(state->block, (mc_block_t[]){block_stone_slab,block_wooden_slab}, 2)
&& (block_class_is_subset(side_block, block_class_stair, block_class_stair_len))
)) {
ImagingDrawLine(img_i, state->imgx, state->imgy+6+1+increment, state->imgx+12+1, state->imgy+1+increment, &ink, 1);
ImagingDrawLine(img_i, state->imgx, state->imgy+6+increment, state->imgx+12+1, state->imgy+increment, &ink, 1);
block_class_is_subset(state->block, (mc_block_t[]){block_stone_slab, block_wooden_slab}, 2) && (block_class_is_subset(side_block, block_class_stair, block_class_stair_len)))) {
ImagingDrawLine(img_i, state->imgx, state->imgy + 6 + 1 + increment, state->imgx + 12 + 1, state->imgy + 1 + increment, &ink, 1);
ImagingDrawLine(img_i, state->imgx, state->imgy + 6 + increment, state->imgx + 12 + 1, state->imgy + increment, &ink, 1);
}
}
}
RenderPrimitiveInterface primitive_edge_lines = {
"edge-lines", sizeof(PrimitiveEdgeLines),
"edge-lines",
sizeof(PrimitiveEdgeLines),
edge_lines_start,
NULL,
NULL,

View File

@@ -22,19 +22,19 @@ typedef struct {
} PrimitiveExposed;
static int
exposed_start(void *data, RenderState *state, PyObject *support) {
PrimitiveExposed *self = (PrimitiveExposed *)data;
exposed_start(void* data, RenderState* state, PyObject* support) {
PrimitiveExposed* self = (PrimitiveExposed*)data;
if (!render_mode_parse_option(support, "mode", "I", &(self->mode)))
return 1;
return 0;
}
static int
exposed_hidden(void *data, RenderState *state, int x, int y, int z) {
PrimitiveExposed *self = (PrimitiveExposed *)data;
exposed_hidden(void* data, RenderState* state, int x, int y, int z) {
PrimitiveExposed* self = (PrimitiveExposed*)data;
/* Unset these flags if seeming exposure from any of these directions would
* be due to not having data there.
*/
@@ -53,54 +53,54 @@ exposed_hidden(void *data, RenderState *state, int x, int y, int z) {
/* No data in -x direction */
validMinusX = 0;
}
if (x == 15 && (!(state->chunks[2][1].loaded) || state->chunks[2][1].sections[state->chunky].blocks == NULL)) {
/* No data in +x direction */
validPlusX = 0;
}
if (y == 0 && (state->chunky - 1 < 0 || state->chunks[1][1].sections[state->chunky - 1].blocks == NULL)) {
/* No data in -y direction */
validMinusY = 0;
}
if (y == 15 && (state->chunky + 1 >= SECTIONS_PER_CHUNK || state->chunks[1][1].sections[state->chunky + 1].blocks == NULL)) {
/* No data in +y direction */
validPlusY = 0;
}
if (z == 0 && (!(state->chunks[1][0].loaded) || state->chunks[1][0].sections[state->chunky].blocks == NULL)) {
/* No data in -z direction */
validMinusZ = 0;
}
if (z == 15 && (!(state->chunks[1][2].loaded) || state->chunks[1][2].sections[state->chunky].blocks == NULL)) {
/* No data in +z direction */
validPlusZ = 0;
}
/* If any of the 6 blocks adjacent to us are transparent, we're exposed */
if( (validMinusX && is_transparent(get_data(state, BLOCKS, x-1, y, z))) ||
(validPlusX && is_transparent(get_data(state, BLOCKS, x+1, y, z))) ||
(validMinusY && is_transparent(get_data(state, BLOCKS, x, y-1, z))) ||
(validPlusY && is_transparent(get_data(state, BLOCKS, x, y+1, z))) ||
(validMinusZ && is_transparent(get_data(state, BLOCKS, x, y, z-1))) ||
(validPlusZ && is_transparent(get_data(state, BLOCKS, x, y, z+1 ))) ) {
if ((validMinusX && is_transparent(get_data(state, BLOCKS, x - 1, y, z))) ||
(validPlusX && is_transparent(get_data(state, BLOCKS, x + 1, y, z))) ||
(validMinusY && is_transparent(get_data(state, BLOCKS, x, y - 1, z))) ||
(validPlusY && is_transparent(get_data(state, BLOCKS, x, y + 1, z))) ||
(validMinusZ && is_transparent(get_data(state, BLOCKS, x, y, z - 1))) ||
(validPlusZ && is_transparent(get_data(state, BLOCKS, x, y, z + 1)))) {
/* Block is exposed */
/* Returns 1 and hides us if we're rendering unexposed blocks, 0 and
* shows us if we're rendering exposed blocks
*/
return self->mode;
return self->mode;
}
/* We have no valid evidence that the block is exposed */
/* We have no valid evidence that the block is exposed */
return !(self->mode); /* Hide in normal mode, reveal in inverted mode */
}
RenderPrimitiveInterface primitive_exposed = {
"exposed", sizeof(PrimitiveExposed),
"exposed",
sizeof(PrimitiveExposed),
exposed_start,
NULL,
NULL,

View File

@@ -18,57 +18,58 @@
#include "../overviewer.h"
typedef struct {
PyObject *black_color;
PyObject *white_color;
PyObject* black_color;
PyObject* white_color;
unsigned int sealevel;
} PrimitiveHeightFading;
static int
height_fading_start(void *data, RenderState *state, PyObject *support) {
PrimitiveHeightFading *self = (PrimitiveHeightFading *)data;
height_fading_start(void* data, RenderState* state, PyObject* support) {
PrimitiveHeightFading* self = (PrimitiveHeightFading*)data;
if (!render_mode_parse_option(support, "sealevel", "I", &(self->sealevel)))
return 1;
self->black_color = PyObject_GetAttrString(support, "black_color");
self->white_color = PyObject_GetAttrString(support, "white_color");
return 0;
}
static void
height_fading_finish(void *data, RenderState *state) {
PrimitiveHeightFading *self = (PrimitiveHeightFading *)data;
height_fading_finish(void* data, RenderState* state) {
PrimitiveHeightFading* self = (PrimitiveHeightFading*)data;
Py_DECREF(self->black_color);
Py_DECREF(self->white_color);
}
static void
height_fading_draw(void *data, RenderState *state, PyObject *src, PyObject *mask, PyObject *mask_light) {
height_fading_draw(void* data, RenderState* state, PyObject* src, PyObject* mask, PyObject* mask_light) {
float alpha;
PrimitiveHeightFading *self = (PrimitiveHeightFading *)data;
PrimitiveHeightFading* self = (PrimitiveHeightFading*)data;
int y = 16 * state->chunky + state->y;
/* do some height fading */
PyObject *height_color = self->white_color;
PyObject* height_color = self->white_color;
/* current formula requires y to be between 0 and 127, so scale it */
y = (y * 128) / (2 * self->sealevel);
/* negative alpha => darkness, positive => light */
alpha = (1.0 / (1 + expf((70 - y) / 11.0))) * 0.6 - 0.55;
if (alpha < 0.0) {
alpha *= -1;
height_color = self->black_color;
}
alpha_over_full(state->img, height_color, mask_light, alpha, state->imgx, state->imgy, 0, 0);
}
RenderPrimitiveInterface primitive_height_fading = {
"height-fading", sizeof(PrimitiveHeightFading),
"height-fading",
sizeof(PrimitiveHeightFading),
height_fading_start,
height_fading_finish,
NULL,

View File

@@ -15,8 +15,8 @@
* with the Overviewer. If not, see <http://www.gnu.org/licenses/>.
*/
#include "../overviewer.h"
#include "../mc_id.h"
#include "../overviewer.h"
struct HideRule {
unsigned short blockid;
@@ -29,21 +29,21 @@ typedef struct {
} RenderPrimitiveHide;
static int
hide_start(void *data, RenderState *state, PyObject *support) {
PyObject *opt;
RenderPrimitiveHide* self = (RenderPrimitiveHide *)data;
hide_start(void* data, RenderState* state, PyObject* support) {
PyObject* opt;
RenderPrimitiveHide* self = (RenderPrimitiveHide*)data;
self->rules = NULL;
if (!render_mode_parse_option(support, "blocks", "O", &(opt)))
return 1;
if (opt && opt != Py_None) {
Py_ssize_t blocks_size = 0, i;
if (!PyList_Check(opt)) {
PyErr_SetString(PyExc_TypeError, "'blocks' must be a list");
return 1;
}
blocks_size = PyList_GET_SIZE(opt);
self->rules = calloc(blocks_size + 1, sizeof(struct HideRule));
if (self->rules == NULL) {
@@ -51,8 +51,8 @@ hide_start(void *data, RenderState *state, PyObject *support) {
}
for (i = 0; i < blocks_size; i++) {
PyObject *block = PyList_GET_ITEM(opt, i);
PyObject* block = PyList_GET_ITEM(opt, i);
if (PyLong_Check(block)) {
/* format 1: just a block id */
self->rules[i].blockid = PyLong_AsLong(block);
@@ -68,42 +68,42 @@ hide_start(void *data, RenderState *state, PyObject *support) {
}
}
}
return 0;
}
static void
hide_finish(void *data, RenderState *state) {
RenderPrimitiveHide *self = (RenderPrimitiveHide *)data;
hide_finish(void* data, RenderState* state) {
RenderPrimitiveHide* self = (RenderPrimitiveHide*)data;
if (self->rules) {
free(self->rules);
}
}
static int
hide_hidden(void *data, RenderState *state, int x, int y, int z) {
RenderPrimitiveHide *self = (RenderPrimitiveHide *)data;
hide_hidden(void* data, RenderState* state, int x, int y, int z) {
RenderPrimitiveHide* self = (RenderPrimitiveHide*)data;
unsigned int i;
unsigned short block;
if (self->rules == NULL)
return 0;
block = get_data(state, BLOCKS, x, y, z);
for (i = 0; self->rules[i].blockid != block_air; i++) {
if (block == self->rules[i].blockid) {
unsigned char data;
if (!(self->rules[i].has_data))
return 1;
data = get_data(state, DATA, x, y, z);
if (data == self->rules[i].data)
return 1;
}
}
return 0;
}

View File

@@ -15,18 +15,18 @@
* with the Overviewer. If not, see <http://www.gnu.org/licenses/>.
*/
#include "../overviewer.h"
#include "../mc_id.h"
#include "../block_class.h"
#include "lighting.h"
#include <math.h>
#include "lighting.h"
#include "../block_class.h"
#include "../mc_id.h"
#include "../overviewer.h"
/* figures out the color from a given skylight and blocklight,
used in lighting calculations */
static void
calculate_light_color(void *data,
calculate_light_color(void* data,
unsigned char skylight, unsigned char blocklight,
unsigned char *r, unsigned char *g, unsigned char *b) {
unsigned char* r, unsigned char* g, unsigned char* b) {
unsigned char v = 255 * powf(0.8f, 15.0 - OV_MAX(blocklight, skylight));
*r = v;
*g = v;
@@ -35,22 +35,22 @@ calculate_light_color(void *data,
/* fancy version that uses the colored light texture */
static void
calculate_light_color_fancy(void *data,
calculate_light_color_fancy(void* data,
unsigned char skylight, unsigned char blocklight,
unsigned char *r, unsigned char *g, unsigned char *b) {
RenderPrimitiveLighting *mode = (RenderPrimitiveLighting *)(data);
unsigned char* r, unsigned char* g, unsigned char* b) {
RenderPrimitiveLighting* mode = (RenderPrimitiveLighting*)(data);
unsigned int index;
PyObject *color;
PyObject* color;
blocklight = OV_MAX(blocklight, skylight);
index = skylight + blocklight * 16;
color = PySequence_GetItem(mode->lightcolor, index);
*r = PyLong_AsLong(PyTuple_GET_ITEM(color, 0));
*g = PyLong_AsLong(PyTuple_GET_ITEM(color, 1));
*b = PyLong_AsLong(PyTuple_GET_ITEM(color, 2));
Py_DECREF(color);
}
@@ -59,9 +59,9 @@ calculate_light_color_fancy(void *data,
(the "skylight - 11" part)
*/
static void
calculate_light_color_night(void *data,
calculate_light_color_night(void* data,
unsigned char skylight, unsigned char blocklight,
unsigned char *r, unsigned char *g, unsigned char *b) {
unsigned char* r, unsigned char* g, unsigned char* b) {
unsigned char v = 255 * powf(0.8f, 15.0 - OV_MAX(blocklight, skylight - 11));
*r = v;
*g = v;
@@ -70,20 +70,20 @@ calculate_light_color_night(void *data,
/* fancy night version that uses the colored light texture */
static void
calculate_light_color_fancy_night(void *data,
calculate_light_color_fancy_night(void* data,
unsigned char skylight, unsigned char blocklight,
unsigned char *r, unsigned char *g, unsigned char *b) {
RenderPrimitiveLighting *mode = (RenderPrimitiveLighting *)(data);
unsigned char* r, unsigned char* g, unsigned char* b) {
RenderPrimitiveLighting* mode = (RenderPrimitiveLighting*)(data);
unsigned int index;
PyObject *color;
PyObject* color;
index = skylight + blocklight * 16;
color = PySequence_GetItem(mode->lightcolor, index);
*r = PyLong_AsLong(PyTuple_GET_ITEM(color, 0));
*g = PyLong_AsLong(PyTuple_GET_ITEM(color, 1));
*b = PyLong_AsLong(PyTuple_GET_ITEM(color, 2));
Py_DECREF(color);
}
@@ -98,8 +98,8 @@ calculate_light_color_fancy_night(void *data,
*/
unsigned char
estimate_blocklevel(RenderPrimitiveLighting *self, RenderState *state,
int x, int y, int z, int *authoratative) {
estimate_blocklevel(RenderPrimitiveLighting* self, RenderState* state,
int x, int y, int z, int* authoratative) {
/* placeholders for later data arrays, coordinates */
unsigned short block;
@@ -109,19 +109,19 @@ estimate_blocklevel(RenderPrimitiveLighting *self, RenderState *state,
/* defaults to "guess" until told otherwise */
if (authoratative)
*authoratative = 0;
block = get_data(state, BLOCKS, x, y, z);
if (authoratative == NULL) {
int auth;
/* iterate through all surrounding blocks to take an average */
int dx, dy, dz, local_block;
for (dx = -1; dx <= 1; dx += 2) {
for (dy = -1; dy <= 1; dy += 2) {
for (dz = -1; dz <= 1; dz += 2) {
coeff = estimate_blocklevel(self, state, x+dx, y+dy, z+dz, &auth);
local_block = get_data(state, BLOCKS, x+dx, y+dy, z+dz);
coeff = estimate_blocklevel(self, state, x + dx, y + dy, z + dz, &auth);
local_block = get_data(state, BLOCKS, x + dx, y + dy, z + dz);
/* only add if the block is transparent, this seems to look better than
using every block */
if (auth && is_transparent(local_block)) {
@@ -132,45 +132,45 @@ estimate_blocklevel(RenderPrimitiveLighting *self, RenderState *state,
}
}
}
/* only return the average if at least one was authoratative */
if (average_count > 0) {
return average_gather / average_count;
}
blocklevel = get_data(state, BLOCKLIGHT, x, y, z);
/* no longer a guess */
if (!block_class_is_subset(block, block_class_alt_height, block_class_alt_height_len) && authoratative) {
*authoratative = 1;
}
return blocklevel;
}
inline void
get_lighting_color(RenderPrimitiveLighting *self, RenderState *state,
get_lighting_color(RenderPrimitiveLighting* self, RenderState* state,
int x, int y, int z,
unsigned char *r, unsigned char *g, unsigned char *b) {
unsigned char* r, unsigned char* g, unsigned char* b) {
/* placeholders for later data arrays, coordinates */
unsigned short block;
unsigned char skylevel, blocklevel;
block = get_data(state, BLOCKS, x, y, z);
skylevel = get_data(state, SKYLIGHT, x, y, z);
blocklevel = get_data(state, BLOCKLIGHT, x, y, z);
/* special half-step handling, stairs handling */
/* Anvil also needs to be here, blockid 145 */
if ( block_class_is_subset(block, block_class_alt_height, block_class_alt_height_len) || block == block_anvil) {
if (block_class_is_subset(block, block_class_alt_height, block_class_alt_height_len) || block == block_anvil) {
unsigned int upper_block;
/* stairs and half-blocks take the skylevel from the upper block if it's transparent */
int upper_counter = 0;
/* but if the upper_block is one of these special half-steps, we need to look at *its* upper_block */
do {
upper_counter++;
upper_counter++;
upper_block = get_data(state, BLOCKS, x, y + upper_counter, z);
} while (block_class_is_subset(upper_block, block_class_alt_height, block_class_alt_height_len));
if (is_transparent(upper_block)) {
@@ -178,31 +178,30 @@ get_lighting_color(RenderPrimitiveLighting *self, RenderState *state,
} else {
skylevel = 15;
}
/* the block has a bad blocklevel, estimate it from neigborhood
* use given coordinates, no local ones! */
blocklevel = estimate_blocklevel(self, state, x, y, z, NULL);
}
if (block_class_is_subset(block, (mc_block_t[]){block_flowing_lava,block_lava}, 2)) {
if (block_class_is_subset(block, (mc_block_t[]){block_flowing_lava, block_lava}, 2)) {
/* lava blocks should always be lit! */
*r = 255;
*g = 255;
*b = 255;
return;
}
self->calculate_light_color(self, OV_MIN(skylevel, 15), OV_MIN(blocklevel, 15), r, g, b);
}
/* does per-face occlusion checking for do_shading_with_mask */
inline int
lighting_is_face_occluded(RenderState *state, int skip_sides, int x, int y, int z) {
lighting_is_face_occluded(RenderState* state, int skip_sides, int x, int y, int z) {
/* 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) {
unsigned short block = getArrayShort3D(state->blocks, 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 */
return 1;
@@ -214,7 +213,7 @@ lighting_is_face_occluded(RenderState *state, int skip_sides, int x, int y, int
ugly black doted line between chunks in night rendermode.
This wouldn't be necessary if the textures were truly
tessellate-able */
return 1;
return 1;
}
}
return 0;
@@ -223,30 +222,30 @@ lighting_is_face_occluded(RenderState *state, int skip_sides, int x, int y, int
/* shades the drawn block with the given facemask, based on the
lighting results from (x, y, z) */
static inline void
do_shading_with_mask(RenderPrimitiveLighting *self, RenderState *state,
int x, int y, int z, PyObject *mask) {
do_shading_with_mask(RenderPrimitiveLighting* self, RenderState* state,
int x, int y, int z, PyObject* mask) {
unsigned char r, g, b;
float comp_strength;
/* check occlusion */
if (lighting_is_face_occluded(state, self->skip_sides, x, y, z))
return;
get_lighting_color(self, state, x, y, z, &r, &g, &b);
comp_strength = 1.0 - self->strength;
r += (255 - r) * comp_strength;
g += (255 - g) * comp_strength;
b += (255 - b) * comp_strength;
tint_with_mask(state->img, r, g, b, 255, mask, state->imgx, state->imgy, 0, 0);
}
static int
lighting_start(void *data, RenderState *state, PyObject *support) {
lighting_start(void* data, RenderState* state, PyObject* support) {
RenderPrimitiveLighting* self;
self = (RenderPrimitiveLighting *)data;
self = (RenderPrimitiveLighting*)data;
/* don't skip sides by default */
self->skip_sides = 0;
@@ -256,19 +255,19 @@ lighting_start(void *data, RenderState *state, PyObject *support) {
return 1;
if (!render_mode_parse_option(support, "color", "i", &(self->color)))
return 1;
self->facemasks_py = PyObject_GetAttrString(support, "facemasks");
// borrowed references, don't need to be decref'd
self->facemasks[0] = PyTuple_GetItem(self->facemasks_py, 0);
self->facemasks[1] = PyTuple_GetItem(self->facemasks_py, 1);
self->facemasks[2] = PyTuple_GetItem(self->facemasks_py, 2);
if (self->night) {
self->calculate_light_color = calculate_light_color_night;
} else {
self->calculate_light_color = calculate_light_color;
}
if (self->color) {
self->lightcolor = PyObject_CallMethod(state->textures, "load_light_color", "");
if (self->lightcolor == Py_None) {
@@ -285,37 +284,37 @@ lighting_start(void *data, RenderState *state, PyObject *support) {
} else {
self->lightcolor = NULL;
}
return 0;
}
static void
lighting_finish(void *data, RenderState *state) {
RenderPrimitiveLighting *self = (RenderPrimitiveLighting *)data;
lighting_finish(void* data, RenderState* state) {
RenderPrimitiveLighting* self = (RenderPrimitiveLighting*)data;
Py_DECREF(self->facemasks_py);
}
static void
lighting_draw(void *data, RenderState *state, PyObject *src, PyObject *mask, PyObject *mask_light) {
lighting_draw(void* data, RenderState* state, PyObject* src, PyObject* mask, PyObject* mask_light) {
RenderPrimitiveLighting* self;
int x, y, z;
self = (RenderPrimitiveLighting *)data;
self = (RenderPrimitiveLighting*)data;
x = state->x, y = state->y, z = state->z;
if (block_class_is_subset(state->block, (mc_block_t[]){block_flowing_water,block_water}, 2)) { /* special case for water */
if (block_class_is_subset(state->block, (mc_block_t[]){block_flowing_water, block_water}, 2)) { /* special case for water */
/* looks like we need a new case for lighting, there are
* blocks that are transparent for occlusion calculations and
* need per-face shading if the face is drawn. */
if ((state->block_pdata & 16) == 16) {
do_shading_with_mask(self, state, x, y+1, z, self->facemasks[0]);
do_shading_with_mask(self, state, x, y + 1, z, self->facemasks[0]);
}
if ((state->block_pdata & 2) == 2) { /* bottom left */
do_shading_with_mask(self, state, x-1, y, z, self->facemasks[1]);
do_shading_with_mask(self, state, x - 1, y, z, self->facemasks[1]);
}
if ((state->block_pdata & 4) == 4) { /* bottom right */
do_shading_with_mask(self, state, x, y, z+1, self->facemasks[2]);
do_shading_with_mask(self, state, x, y, z + 1, self->facemasks[2]);
}
/* leaves and ice are transparent for occlusion calculations but they
* per face-shading to look as in game */
@@ -324,14 +323,15 @@ lighting_draw(void *data, RenderState *state, PyObject *src, PyObject *mask, PyO
do_shading_with_mask(self, state, x, y, z, mask_light);
} else {
/* opaque: do per-face shading */
do_shading_with_mask(self, state, x, y+1, z, self->facemasks[0]);
do_shading_with_mask(self, state, x-1, y, z, self->facemasks[1]);
do_shading_with_mask(self, state, x, y, z+1, self->facemasks[2]);
do_shading_with_mask(self, state, x, y + 1, z, self->facemasks[0]);
do_shading_with_mask(self, state, x - 1, y, z, self->facemasks[1]);
do_shading_with_mask(self, state, x, y, z + 1, self->facemasks[2]);
}
}
RenderPrimitiveInterface primitive_lighting = {
"lighting", sizeof(RenderPrimitiveLighting),
"lighting",
sizeof(RenderPrimitiveLighting),
lighting_start,
lighting_finish,
NULL,

View File

@@ -18,21 +18,21 @@
#include "../overviewer.h"
typedef struct {
PyObject *facemasks_py;
PyObject *facemasks[3];
PyObject* facemasks_py;
PyObject* facemasks[3];
/* light color image, loaded if color_light is True */
PyObject *lightcolor;
PyObject* lightcolor;
/* can be overridden in derived rendermodes to control lighting
arguments are data, skylight, blocklight, return RGB */
void (*calculate_light_color)(void *, unsigned char, unsigned char, unsigned char *, unsigned char *, unsigned char *);
void (*calculate_light_color)(void*, unsigned char, unsigned char, unsigned char*, unsigned char*, unsigned char*);
/* 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
*/
int skip_sides;
float strength;
int color;
int night;
@@ -40,7 +40,7 @@ typedef struct {
/* exposed so that smooth-lighting can use them */
extern RenderPrimitiveInterface primitive_lighting;
int lighting_is_face_occluded(RenderState *state, int skip_sides, int x, int y, int z);
void get_lighting_color(RenderPrimitiveLighting *self, RenderState *state,
int lighting_is_face_occluded(RenderState* state, int skip_sides, int x, int y, int z);
void get_lighting_color(RenderPrimitiveLighting* self, RenderState* state,
int x, int y, int z,
unsigned char *r, unsigned char *g, unsigned char *b);
unsigned char* r, unsigned char* g, unsigned char* b);

View File

@@ -15,13 +15,13 @@
* with the Overviewer. If not, see <http://www.gnu.org/licenses/>.
*/
#include "../overviewer.h"
#include "../mc_id.h"
#include "../block_class.h"
#include "nether.h"
#include "../block_class.h"
#include "../mc_id.h"
#include "../overviewer.h"
static void
walk_chunk(RenderState *state, RenderPrimitiveNether *data) {
walk_chunk(RenderState* state, RenderPrimitiveNether* data) {
int x, y, z;
int id;
@@ -29,16 +29,16 @@ walk_chunk(RenderState *state, RenderPrimitiveNether *data) {
for (z = -1; z < DEPTH + 1; z++) {
id = get_data(state, BLOCKS, x, NETHER_ROOF - (state->chunky * 16), z);
if (id == block_bedrock) {
data->remove_block[x+1][NETHER_ROOF][z+1] = 1;
data->remove_block[x + 1][NETHER_ROOF][z + 1] = 1;
id = get_data(state, BLOCKS, x, (NETHER_ROOF + 1) - (state->chunky * 16), z);
if (id == block_brown_mushroom || id == block_red_mushroom)
data->remove_block[x+1][NETHER_ROOF + 1][z+1] = 1;
data->remove_block[x + 1][NETHER_ROOF + 1][z + 1] = 1;
}
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);
if (block_class_is_subset(id, (mc_block_t[]){block_bedrock,block_netherrack,block_quartz_ore,block_lava}, 4))
data->remove_block[x+1][y][z+1] = 1;
if (block_class_is_subset(id, (mc_block_t[]){block_bedrock, block_netherrack, block_quartz_ore, block_lava}, 4))
data->remove_block[x + 1][y][z + 1] = 1;
else
break;
}
@@ -48,21 +48,22 @@ walk_chunk(RenderState *state, RenderPrimitiveNether *data) {
}
static int
nether_hidden(void *data, RenderState *state, int x, int y, int z) {
nether_hidden(void* data, RenderState* state, int x, int y, int z) {
RenderPrimitiveNether* self;
int real_y;
self = (RenderPrimitiveNether *)data;
self = (RenderPrimitiveNether*)data;
if (!(self->walked_chunk))
walk_chunk(state, self);
real_y = y + (state->chunky * 16);
return self->remove_block[x+1][real_y][z+1];
return self->remove_block[x + 1][real_y][z + 1];
}
RenderPrimitiveInterface primitive_nether = {
"nether", sizeof(RenderPrimitiveNether),
"nether",
sizeof(RenderPrimitiveNether),
NULL,
NULL,
NULL,

View File

@@ -27,6 +27,6 @@
typedef struct {
int walked_chunk;
int remove_block[WIDTH+2][HEIGHT][DEPTH+2];
int remove_block[WIDTH + 2][HEIGHT][DEPTH + 2];
} RenderPrimitiveNether;

View File

@@ -18,15 +18,14 @@
#include "../overviewer.h"
static int
netherold_hidden(void *data, RenderState *state, int x, int y, int z) {
netherold_hidden(void* data, RenderState* state, int x, int y, int z) {
/* hide all blocks above all air blocks
due to how the nether is currently generated, this will also count
empty sections as 'solid'
*/
unsigned char missing_section = 0;
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) {
missing_section = 1;
y += 16;
@@ -38,18 +37,18 @@ netherold_hidden(void *data, RenderState *state, int x, int y, int z) {
return 0;
missing_section = 0;
}
if (!missing_section && get_data(state, BLOCKS, x, y, z) == 0)
{
return 0;
}
if (!missing_section && get_data(state, BLOCKS, x, y, z) == 0) {
return 0;
}
y++;
}
return 1;
}
RenderPrimitiveInterface primitive_nether_old = {
"netherold", 0,
"netherold",
0,
NULL,
NULL,
NULL,

View File

@@ -18,17 +18,18 @@
#include "../overviewer.h"
static int
no_fluids_start(void *data, RenderState *state, PyObject *support) {
no_fluids_start(void* data, RenderState* state, PyObject* support) {
return 0;
}
static int
no_fluids_hidden(void *data, RenderState *state, int x, int y, int z) {
no_fluids_hidden(void* data, RenderState* state, int x, int y, int z) {
return block_has_property(state->block, FLUID);
}
RenderPrimitiveInterface primitive_no_fluids = {
"no-fluids", 0,
"no-fluids",
0,
no_fluids_start,
NULL,
NULL,

View File

@@ -15,14 +15,14 @@
* with the Overviewer. If not, see <http://www.gnu.org/licenses/>.
*/
#include "overlay.h"
#include "biomes.h"
#include "overlay.h"
typedef struct {
/* inherits from overlay */
RenderPrimitiveOverlay parent;
void *biomes;
void* biomes;
} RenderPrimitiveBiomes;
struct BiomeColor {
@@ -31,65 +31,64 @@ struct BiomeColor {
};
static struct BiomeColor default_biomes[] = {
{0, 135, 106, 150}, /* Ocean */
{1, 98, 238, 240}, /* Plains */
{2, 227, 107, 0}, /* Desert */
{3, 255, 55, 55}, /* Extreme Hills */
{4, 10, 200, 200}, /* Forest */
{5, 10, 100, 240}, /* Taiga */
{6, 200, 100, 100}, /* Swampland */
{7, 70, 170, 0}, /* River */
{8, 255, 0, 0}, /* Hell */
{9, 255, 255, 255}, /* Sky */
{10, 155, 55, 255}, /* FrozenOcean */
{11, 255, 55, 255}, /* FrozenRiver */
{0, 135, 106, 150}, /* Ocean */
{1, 98, 238, 240}, /* Plains */
{2, 227, 107, 0}, /* Desert */
{3, 255, 55, 55}, /* Extreme Hills */
{4, 10, 200, 200}, /* Forest */
{5, 10, 100, 240}, /* Taiga */
{6, 200, 100, 100}, /* Swampland */
{7, 70, 170, 0}, /* River */
{8, 255, 0, 0}, /* Hell */
{9, 255, 255, 255}, /* Sky */
{10, 155, 55, 255}, /* FrozenOcean */
{11, 255, 55, 255}, /* FrozenRiver */
{12, 155, 255, 255}, /* Ice Plains */
{13, 205, 205, 255}, /* Ice Mountains */
{14, 255, 0, 155}, /* MushroomIsland */
{15, 255, 75, 175}, /* MushroomIslandShore */
{16, 255, 255, 0}, /* Beach */
{17, 240, 155, 0}, /* DesertHills */
{14, 255, 0, 155}, /* MushroomIsland */
{15, 255, 75, 175}, /* MushroomIslandShore */
{16, 255, 255, 0}, /* Beach */
{17, 240, 155, 0}, /* DesertHills */
{18, 100, 200, 200}, /* ForestHills */
{19, 100, 100, 240}, /* TaigaHills */
{20, 255, 25, 15}, /* Extreme Hills Edge */
{21, 155, 155, 55}, /* Jungle */
{22, 175, 255, 55}, /* Jungle Hills */
{23, 135, 255, 55}, /* Jungle Edge */
{20, 255, 25, 15}, /* Extreme Hills Edge */
{21, 155, 155, 55}, /* Jungle */
{22, 175, 255, 55}, /* Jungle Hills */
{23, 135, 255, 55}, /* Jungle Edge */
{24, 135, 106, 150}, /* Deep Ocean */
{25, 255, 25, 15}, /* Stone Beach */
{25, 255, 25, 15}, /* Stone Beach */
{26, 155, 255, 255}, /* Cold Beach */
{27, 10, 200, 200}, /* Birch Forest */
{28, 10, 200, 200}, /* Birch Forest Edge */
{29, 10, 200, 200}, /* Roofed Forest */
{27, 10, 200, 200}, /* Birch Forest */
{28, 10, 200, 200}, /* Birch Forest Edge */
{29, 10, 200, 200}, /* Roofed Forest */
{30, 155, 255, 255}, /* Cold Taiga */
{31, 155, 200, 255}, /* Cold Taiga Hills */
{32, 10, 100, 240}, /* Mega Taiga */
{33, 10, 100, 240}, /* Mega Taiga Hills*/
{34, 255, 55, 55}, /* Extreme Hills+ */
{35, 227, 107, 0}, /* Savanna */
{36, 227, 107, 0}, /* Savanna Plateau */
{32, 10, 100, 240}, /* Mega Taiga */
{33, 10, 100, 240}, /* Mega Taiga Hills*/
{34, 255, 55, 55}, /* Extreme Hills+ */
{35, 227, 107, 0}, /* Savanna */
{36, 227, 107, 0}, /* Savanna Plateau */
{37, 255, 100, 100}, /* Mesa */
{38, 255, 100, 100}, /* Mesa Plateau F */
{39, 255, 100, 100}, /* Mesa Plateau */
/* end of list marker */
{255, 0, 0, 0}
};
{255, 0, 0, 0}};
static void get_color(void *data, RenderState *state,
unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a) {
static void get_color(void* data, RenderState* state,
unsigned char* r, unsigned char* g, unsigned char* b, unsigned char* a) {
unsigned char biome;
int x = state->x, z = state->z, y_max, y;
int max_i = -1;
RenderPrimitiveBiomes* self = (RenderPrimitiveBiomes *)data;
struct BiomeColor *biomes = (struct BiomeColor *)(self->biomes);
RenderPrimitiveBiomes* self = (RenderPrimitiveBiomes*)data;
struct BiomeColor* biomes = (struct BiomeColor*)(self->biomes);
*a = 0;
y_max = state->y + 1;
for (y = state->chunky * -16; y <= y_max; y++) {
int i, tmp;
biome = get_data(state, BIOMES, x, y, z);
biome = get_data(state, BIOMES, x, y, z);
if (biome >= NUM_BIOMES) {
biome = DEFAULT_BIOME;
@@ -97,7 +96,7 @@ static void get_color(void *data, RenderState *state,
for (i = 0; (max_i == -1 || i < max_i) && biomes[i].biome != 255; i++) {
if (biomes[i].biome == biome) {
//printf("(%d, %d, %d), %d, %s\n", x, y, z, biomes[i].biome, biome_table[biomes[i].biome].name);
//printf("(%d, %d, %d), %d, %s\n", x, y, z, biomes[i].biome, biome_table[biomes[i].biome].name);
*r = biomes[i].r;
*g = biomes[i].g;
*b = biomes[i].b;
@@ -112,10 +111,10 @@ static void get_color(void *data, RenderState *state,
}
static int
overlay_biomes_start(void *data, RenderState *state, PyObject *support) {
PyObject *opt;
overlay_biomes_start(void* data, RenderState* state, PyObject* support) {
PyObject* opt;
RenderPrimitiveBiomes* self;
unsigned char alpha_tmp=0;
unsigned char alpha_tmp = 0;
/* first, chain up */
int ret = primitive_overlay.start(data, state, support);
@@ -123,13 +122,13 @@ overlay_biomes_start(void *data, RenderState *state, PyObject *support) {
return ret;
/* now do custom initializations */
self = (RenderPrimitiveBiomes *)data;
self = (RenderPrimitiveBiomes*)data;
// opt is a borrowed reference. do not deref
if (!render_mode_parse_option(support, "biomes", "O", &(opt)))
return 1;
if (opt && opt != Py_None) {
struct BiomeColor *biomes = NULL;
struct BiomeColor* biomes = NULL;
Py_ssize_t biomes_size = 0, i;
/* create custom biomes */
@@ -145,8 +144,8 @@ overlay_biomes_start(void *data, RenderState *state, PyObject *support) {
}
for (i = 0; i < biomes_size; i++) {
PyObject *biome = PyList_GET_ITEM(opt, i);
char *tmpname = NULL;
PyObject* biome = PyList_GET_ITEM(opt, i);
char* tmpname = NULL;
int j = 0;
if (!PyArg_ParseTuple(biome, "s(bbb)", &tmpname, &(biomes[i].r), &(biomes[i].g), &(biomes[i].b))) {
@@ -157,15 +156,15 @@ overlay_biomes_start(void *data, RenderState *state, PyObject *support) {
//printf("%s, (%d, %d, %d) ->", tmpname, biomes[i].r, biomes[i].g, biomes[i].b);
for (j = 0; j < NUM_BIOMES; j++) {
if (strncmp(biome_table[j].name, tmpname, strlen(tmpname))==0) {
if (strncmp(biome_table[j].name, tmpname, strlen(tmpname)) == 0) {
//printf("biome_table index=%d", j);
biomes[i].biome = j;
break;
}
}
//printf("\n");
//printf("\n");
}
biomes[biomes_size].biome = 255; //Because 0 is a valid biome, have to use 255 as the end of list marker instead. Fragile!
biomes[biomes_size].biome = 255; //Because 0 is a valid biome, have to use 255 as the end of list marker instead. Fragile!
} else {
self->biomes = default_biomes;
@@ -174,10 +173,10 @@ overlay_biomes_start(void *data, RenderState *state, PyObject *support) {
if (!render_mode_parse_option(support, "alpha", "b", &(alpha_tmp))) {
if (PyErr_Occurred()) {
PyErr_Clear();
alpha_tmp = 240;
alpha_tmp = 240;
}
self->parent.color->a = alpha_tmp;
self->parent.color->a = alpha_tmp;
}
/* setup custom color */
self->parent.get_color = get_color;
@@ -186,9 +185,9 @@ overlay_biomes_start(void *data, RenderState *state, PyObject *support) {
}
static void
overlay_biomes_finish(void *data, RenderState *state) {
overlay_biomes_finish(void* data, RenderState* state) {
/* first free all *our* stuff */
RenderPrimitiveBiomes* self = (RenderPrimitiveBiomes *)data;
RenderPrimitiveBiomes* self = (RenderPrimitiveBiomes*)data;
if (self->biomes && self->biomes != default_biomes) {
free(self->biomes);

View File

@@ -15,14 +15,14 @@
* with the Overviewer. If not, see <http://www.gnu.org/licenses/>.
*/
#include "overlay.h"
#include "../mc_id.h"
#include "overlay.h"
typedef struct {
/* inherits from overlay */
RenderPrimitiveOverlay parent;
void *minerals;
void* minerals;
} RenderPrimitiveMineral;
struct MineralColor {
@@ -33,7 +33,7 @@ struct MineralColor {
/* put more valuable ores first -- they take precedence */
static struct MineralColor default_minerals[] = {
{block_mossy_cobblestone, 31, 153, 9},
{block_diamond_ore, 32, 230, 220},
{block_lapis_ore, 0, 23, 176},
@@ -43,34 +43,33 @@ static struct MineralColor default_minerals[] = {
{block_redstone_ore, 186, 0, 0},
{block_lit_redstone_ore, 186, 0, 0},
{block_coal_ore, 54, 54, 54},
/* end of list marker */
{0, 0, 0, 0}
};
static void get_color(void *data, RenderState *state,
unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a) {
/* end of list marker */
{0, 0, 0, 0}};
static void get_color(void* data, RenderState* state,
unsigned char* r, unsigned char* g, unsigned char* b, unsigned char* a) {
int x = state->x, z = state->z, y_max, y;
int max_i = -1;
RenderPrimitiveMineral* self = (RenderPrimitiveMineral *)data;
struct MineralColor *minerals = (struct MineralColor *)(self->minerals);
RenderPrimitiveMineral* self = (RenderPrimitiveMineral*)data;
struct MineralColor* minerals = (struct MineralColor*)(self->minerals);
*a = 0;
y_max = state->y + 1;
for (y = state->chunky * -16; y <= y_max; y++) {
int i, tmp;
unsigned short blockid = get_data(state, BLOCKS, x, y, z);
for (i = 0; (max_i == -1 || i < max_i) && minerals[i].blockid != block_air; i++) {
if (minerals[i].blockid == blockid) {
*r = minerals[i].r;
*g = minerals[i].g;
*b = minerals[i].b;
tmp = (128 - y_max + y) * 2 - 40;
*a = OV_MIN(OV_MAX(0, tmp), 255);
max_i = i;
break;
}
@@ -79,39 +78,39 @@ static void get_color(void *data, RenderState *state,
}
static int
overlay_mineral_start(void *data, RenderState *state, PyObject *support) {
PyObject *opt;
overlay_mineral_start(void* data, RenderState* state, PyObject* support) {
PyObject* opt;
RenderPrimitiveMineral* self;
/* first, chain up */
int ret = primitive_overlay.start(data, state, support);
if (ret != 0)
return ret;
/* now do custom initializations */
self = (RenderPrimitiveMineral *)data;
// opt is a borrowed reference. do not deref
self = (RenderPrimitiveMineral*)data;
// opt is a borrowed reference. do not deref
if (!render_mode_parse_option(support, "minerals", "O", &(opt)))
return 1;
if (opt && opt != Py_None) {
struct MineralColor *minerals = NULL;
struct MineralColor* minerals = NULL;
Py_ssize_t minerals_size = 0, i;
/* create custom minerals */
if (!PyList_Check(opt)) {
PyErr_SetString(PyExc_TypeError, "'minerals' must be a list");
return 1;
}
minerals_size = PyList_GET_SIZE(opt);
minerals = self->minerals = calloc(minerals_size + 1, sizeof(struct MineralColor));
if (minerals == NULL) {
return 1;
}
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))) {
free(minerals);
self->minerals = NULL;
@@ -121,22 +120,22 @@ overlay_mineral_start(void *data, RenderState *state, PyObject *support) {
} else {
self->minerals = default_minerals;
}
/* setup custom color */
self->parent.get_color = get_color;
return 0;
}
static void
overlay_mineral_finish(void *data, RenderState *state) {
overlay_mineral_finish(void* data, RenderState* state) {
/* first free all *our* stuff */
RenderPrimitiveMineral* self = (RenderPrimitiveMineral *)data;
RenderPrimitiveMineral* self = (RenderPrimitiveMineral*)data;
if (self->minerals && self->minerals != default_minerals) {
free(self->minerals);
}
/* now, chain up */
primitive_overlay.finish(data, state);
}

View File

@@ -15,8 +15,8 @@
* with the Overviewer. If not, see <http://www.gnu.org/licenses/>.
*/
#include "overlay.h"
#include <math.h>
#include "overlay.h"
typedef struct {
/* inherits from overlay */
@@ -30,28 +30,28 @@ typedef struct {
* 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(long long* seed, long long new_seed) {
*seed = (new_seed ^ 0x5deece66dLL) & ((1LL << 48) - 1);
}
static int random_next(long long *seed, int bits) {
static int random_next(long long* seed, int bits) {
*seed = (*seed * 0x5deece66dLL + 0xbL) & ((1LL << 48) - 1);
return (int)(*seed >> (48 - bits));
}
static int random_next_int(long long *seed, int n) {
static int random_next_int(long long* seed, int n) {
int bits, val;
if (n <= 0) {
/* invalid */
return 0;
}
if ((n & -n) == n) {
/* n is a power of two */
return (int)((n * (long long)random_next(seed, 31)) >> 31);
}
do {
bits = random_next(seed, 31);
val = bits % n;
@@ -66,14 +66,15 @@ static int is_slime(long long map_seed, int chunkx, int chunkz) {
(long long)(chunkx * chunkx * 0x4c1906) +
(long long)(chunkx * 0x5ac0db) +
(long long)(chunkz * chunkz * 0x4307a7LL) +
(long long)(chunkz * 0x5f24f)) ^ 0x3ad8025f);
(long long)(chunkz * 0x5f24f)) ^
0x3ad8025f);
return (random_next_int(&seed, 10) == 0);
}
static void get_color(void *data, RenderState *state,
unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a) {
RenderPrimitiveSlime *self = (RenderPrimitiveSlime *)data;
static void get_color(void* data, RenderState* state,
unsigned char* r, unsigned char* g, unsigned char* b, unsigned char* a) {
RenderPrimitiveSlime* self = (RenderPrimitiveSlime*)data;
/* set a nice, pretty green color */
*r = self->parent.color->r;
*g = self->parent.color->g;
@@ -81,7 +82,7 @@ static void get_color(void *data, RenderState *state,
/* default to no overlay, until told otherwise */
*a = 0;
if (is_slime(self->seed, state->chunkx, state->chunkz)) {
/* slimes can spawn! */
*a = self->parent.color->a;
@@ -89,24 +90,24 @@ static void get_color(void *data, RenderState *state,
}
static int
overlay_slime_start(void *data, RenderState *state, PyObject *support) {
RenderPrimitiveSlime *self;
PyObject *pyseed;
overlay_slime_start(void* data, RenderState* state, PyObject* support) {
RenderPrimitiveSlime* self;
PyObject* pyseed;
/* first, chain up */
int ret = primitive_overlay.start(data, state, support);
if (ret != 0)
return ret;
/* now do custom initializations */
self = (RenderPrimitiveSlime *)data;
self = (RenderPrimitiveSlime*)data;
self->parent.get_color = get_color;
self->parent.default_color.r = 40;
self->parent.default_color.g = 230;
self->parent.default_color.b = 40;
self->parent.default_color.a = 240;
pyseed = PyObject_GetAttrString(state->world, "seed");
if (!pyseed)
return 1;
@@ -114,12 +115,12 @@ overlay_slime_start(void *data, RenderState *state, PyObject *support) {
Py_DECREF(pyseed);
if (PyErr_Occurred())
return 1;
return 0;
}
static void
overlay_slime_finish(void *data, RenderState *state) {
overlay_slime_finish(void* data, RenderState* state) {
/* chain up */
primitive_overlay.finish(data, state);
}

View File

@@ -15,37 +15,37 @@
* with the Overviewer. If not, see <http://www.gnu.org/licenses/>.
*/
#include "overlay.h"
#include <math.h>
#include "overlay.h"
typedef struct {
/* inherits from overlay */
RenderPrimitiveOverlay parent;
} RenderPrimitiveSpawn;
static void get_color(void *data, RenderState *state,
unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a) {
RenderPrimitiveSpawn* self = (RenderPrimitiveSpawn *)data;
static void get_color(void* data, RenderState* state,
unsigned char* r, unsigned char* g, unsigned char* b, unsigned char* a) {
RenderPrimitiveSpawn* self = (RenderPrimitiveSpawn*)data;
int x = state->x, y = state->y, z = state->z;
int y_light = y + 1;
unsigned char blocklight, skylight;
/* set a nice, pretty red color */
*r = self->parent.color->r;
*g = self->parent.color->g;
*b = self->parent.color->b;
/* default to no overlay, until told otherwise */
*a = 0;
if (block_has_property(state->block, NOSPAWN)) {
/* nothing can spawn on this */
return;
}
blocklight = get_data(state, BLOCKLIGHT, x, y_light, z);
skylight = get_data(state, SKYLIGHT, x, y_light, z);
if (OV_MAX(blocklight, skylight) <= 7) {
/* hostile mobs spawn in daylight */
*a = 240;
@@ -56,28 +56,28 @@ static void get_color(void *data, RenderState *state,
}
static int
overlay_spawn_start(void *data, RenderState *state, PyObject *support) {
overlay_spawn_start(void* data, RenderState* state, PyObject* support) {
RenderPrimitiveSpawn* self;
/* first, chain up */
int ret = primitive_overlay.start(data, state, support);
if (ret != 0)
return ret;
/* now do custom initializations */
self = (RenderPrimitiveSpawn *)data;
self = (RenderPrimitiveSpawn*)data;
self->parent.get_color = get_color;
self->parent.default_color.r = 229;
self->parent.default_color.g = 36;
self->parent.default_color.b = 38;
self->parent.default_color.a = 0;
return 0;
}
static void
overlay_spawn_finish(void *data, RenderState *state) {
overlay_spawn_finish(void* data, RenderState* state) {
/* chain up */
primitive_overlay.finish(data, state);
}

View File

@@ -15,42 +15,43 @@
* with the Overviewer. If not, see <http://www.gnu.org/licenses/>.
*/
#include "overlay.h"
#include "../mc_id.h"
#include "overlay.h"
typedef enum { false, true } bool;
typedef enum { false,
true } bool;
typedef struct {
/* inherits from overlay */
RenderPrimitiveOverlay parent;
void *structures;
void* structures;
int numcolors;
} RenderPrimitiveStructure;
struct Condition{
struct Condition {
int relx, rely, relz;
unsigned short block;
};
struct Color {
int numconds;
struct Condition *conditions;
struct Condition* conditions;
unsigned char r, g, b, a;
};
static void get_color(void *data,
RenderState *state,
unsigned char *r,
unsigned char *g,
unsigned char *b,
unsigned char *a) {
static void get_color(void* data,
RenderState* state,
unsigned char* r,
unsigned char* g,
unsigned char* b,
unsigned char* a) {
/**
* Calculate the color at the current position and store the values to r,g,b,a.
**/
RenderPrimitiveStructure *self = (RenderPrimitiveStructure *)data;
RenderPrimitiveStructure* self = (RenderPrimitiveStructure*)data;
int x = state->x, z = state->z, y_max, y, col, cond;
struct Color *structures = (struct Color *)(self->structures);
struct Condition * c = NULL;
struct Color* structures = (struct Color*)(self->structures);
struct Condition* c = NULL;
bool all = true;
y_max = state->y + 1;
@@ -59,20 +60,20 @@ static void get_color(void *data,
* If all conditions are met for one y level set r,b,g,a accordingly.
**/
// iterate over all the colors
for ( col = 0; col < self->numcolors; col++) {
for (col = 0; col < self->numcolors; col++) {
// iterate over all y levels
for (y = state->chunky * -16; y <= y_max; y++) {
// iterate over all the conditions
for (cond = 0; cond < structures[col].numconds; cond++) {
all = true;
c = (struct Condition *)&structures[col].conditions[cond];
c = (struct Condition*)&structures[col].conditions[cond];
// check if the condition does apply and break from the conditions loop if not.
if(!(c->block == get_data(state, BLOCKS, x+c->relx, y+c->rely, z+c->relz))) {
if (!(c->block == get_data(state, BLOCKS, x + c->relx, y + c->rely, z + c->relz))) {
all = false;
break;
}
}
if (all){
if (all) {
// set the color
*r = structures[col].r;
*g = structures[col].g;
@@ -85,12 +86,12 @@ static void get_color(void *data,
return;
}
static int overlay_structure_start(void *data, RenderState *state, PyObject *support) {
static int overlay_structure_start(void* data, RenderState* state, PyObject* support) {
/**
* 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.
**/
PyObject *opt;
PyObject* opt;
RenderPrimitiveStructure* self;
/* first, chain up */
@@ -99,7 +100,7 @@ static int overlay_structure_start(void *data, RenderState *state, PyObject *sup
return ret;
/* now do custom initializations */
self = (RenderPrimitiveStructure *)data;
self = (RenderPrimitiveStructure*)data;
// opt is a borrowed reference. do not deref
// store the structures python object into opt.
@@ -110,8 +111,8 @@ static int overlay_structure_start(void *data, RenderState *state, PyObject *sup
* Check if a sane option was passed.
**/
if (opt && opt != Py_None) {
struct Color *structures = NULL;
struct Condition *cond = NULL;
struct Color* structures = NULL;
struct Condition* cond = NULL;
Py_ssize_t structures_size = 0, i, cond_size = 0, n = 0;
bool cont = true;
@@ -135,11 +136,11 @@ static int overlay_structure_start(void *data, RenderState *state, PyObject *sup
**/
if (cont) {
for (i = 0; i < structures_size; i++) {
PyObject *structure = PyList_GET_ITEM(opt, i);
PyObject* structure = PyList_GET_ITEM(opt, i);
// condspy holding the conditions tuple of variable length (python object)
PyObject *condspy;
PyObject* condspy;
// colorpy holding the 4 tuple with r g b a values of the color
PyObject *colorpy;
PyObject* colorpy;
// getting the condspy and colorpy out of the structures.
if (!PyArg_ParseTuple(structure, "OO", &condspy, &colorpy)) {
@@ -150,11 +151,11 @@ static int overlay_structure_start(void *data, RenderState *state, PyObject *sup
}
// Parse colorpy into a c-struct.
if (!PyArg_ParseTuple( colorpy, "bbbb",
&structures[i].r,
&structures[i].g,
&structures[i].b,
&structures[i].a)) {
if (!PyArg_ParseTuple(colorpy, "bbbb",
&structures[i].r,
&structures[i].g,
&structures[i].b,
&structures[i].a)) {
free(structures);
self->structures = NULL;
return 1;
@@ -162,7 +163,7 @@ static int overlay_structure_start(void *data, RenderState *state, PyObject *sup
// Convert condspy to a fast sequence
condspy = PySequence_Fast(condspy, "Failed to parse conditions");
if(condspy == NULL) {
if (condspy == NULL) {
free(structures);
self->structures = NULL;
return 1;
@@ -183,14 +184,14 @@ static int overlay_structure_start(void *data, RenderState *state, PyObject *sup
// iterate over all the conditions and read them.
for (n = 0; n < structures[i].numconds; n++) {
PyObject *ccond = PySequence_Fast_GET_ITEM(condspy, n);
if(!PyArg_ParseTuple( ccond, "iiib",
PyObject* ccond = PySequence_Fast_GET_ITEM(condspy, n);
if (!PyArg_ParseTuple(ccond, "iiib",
&cond[n].relx,
&cond[n].rely,
&cond[n].relz,
&cond[n].block)){
&cond[n].block)) {
int x = 0;
for(x = 0; x < structures_size; x++){
for (x = 0; x < structures_size; x++) {
free(structures[x].conditions);
}
free(structures);
@@ -208,16 +209,16 @@ static int overlay_structure_start(void *data, RenderState *state, PyObject *sup
return 0;
}
static void overlay_structure_finish(void *data, RenderState *state) {
static void overlay_structure_finish(void* data, RenderState* state) {
/* first free all *our* stuff */
RenderPrimitiveStructure* self = (RenderPrimitiveStructure *)data;
RenderPrimitiveStructure* self = (RenderPrimitiveStructure*)data;
int i = 0;
if(self->structures) {
if (self->structures) {
// freeing the nested structure
struct Color * m = self->structures;
for(i = 0; i < self->numcolors; i++){
if(m[i].conditions)
struct Color* m = self->structures;
for (i = 0; i < self->numcolors; i++) {
if (m[i].conditions)
free(m[i].conditions);
}
}
@@ -240,4 +241,3 @@ RenderPrimitiveInterface primitive_overlay_structure = {
NULL,
overlay_draw,
};

View File

@@ -18,9 +18,9 @@
#include "overlay.h"
#include "../mc_id.h"
static void get_color(void *data, RenderState *state,
unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a) {
RenderPrimitiveOverlay* self = (RenderPrimitiveOverlay *)data;
static void get_color(void* data, RenderState* state,
unsigned char* r, unsigned char* g, unsigned char* b, unsigned char* a) {
RenderPrimitiveOverlay* self = (RenderPrimitiveOverlay*)data;
*r = self->color->r;
*g = self->color->g;
@@ -29,35 +29,35 @@ static void get_color(void *data, RenderState *state,
}
static int
overlay_start(void *data, RenderState *state, PyObject *support) {
PyObject *opt = NULL;
OverlayColor *color = NULL;
RenderPrimitiveOverlay *self = (RenderPrimitiveOverlay *)data;
overlay_start(void* data, RenderState* state, PyObject* support) {
PyObject* opt = NULL;
OverlayColor* color = NULL;
RenderPrimitiveOverlay* self = (RenderPrimitiveOverlay*)data;
self->facemask_top = PyObject_GetAttrString(support, "facemask_top");
self->white_color = PyObject_GetAttrString(support, "whitecolor");
self->get_color = get_color;
color = self->color = calloc(1, sizeof(OverlayColor));
if (color == NULL) {
return 1;
}
self->default_color.r = 200;
self->default_color.g = 200;
self->default_color.b = 255;
self->default_color.a = 155;
if(!render_mode_parse_option(support, "overlay_color", "bbbb", &(color->r), &(color->g), &(color->b), &(color->a))) {
if(PyErr_Occurred())
if (!render_mode_parse_option(support, "overlay_color", "bbbb", &(color->r), &(color->g), &(color->b), &(color->a))) {
if (PyErr_Occurred())
PyErr_Clear();
free(color);
self->color = &self->default_color;
// Check if it is None, if it is, continue and use the default, if it isn't, return an error
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(opt && opt != Py_None) {
if (opt && opt != Py_None) {
return 1;
}
}
@@ -67,56 +67,55 @@ overlay_start(void *data, RenderState *state, PyObject *support) {
}
static void
overlay_finish(void *data, RenderState *state) {
RenderPrimitiveOverlay *self = (RenderPrimitiveOverlay *)data;
overlay_finish(void* data, RenderState* state) {
RenderPrimitiveOverlay* self = (RenderPrimitiveOverlay*)data;
if (self->color && self->color != &self->default_color) {
free(self->color);
}
Py_DECREF(self->facemask_top);
Py_DECREF(self->white_color);
}
void
overlay_draw(void *data, RenderState *state, PyObject *src, PyObject *mask, PyObject *mask_light) {
RenderPrimitiveOverlay *self = (RenderPrimitiveOverlay *)data;
void overlay_draw(void* data, RenderState* state, PyObject* src, PyObject* mask, PyObject* mask_light) {
RenderPrimitiveOverlay* self = (RenderPrimitiveOverlay*)data;
unsigned char r, g, b, a;
unsigned short top_block;
// exactly analogous to edge-line code for these special blocks
int increment=0;
if (state->block == block_stone_slab) // half-step
increment=6;
int increment = 0;
if (state->block == block_stone_slab) // half-step
increment = 6;
else if (state->block == block_snow_layer) // snow
increment=9;
increment = 9;
/* skip rendering the overlay if we can't see it */
top_block = get_data(state, BLOCKS, state->x, state->y+1, state->z);
top_block = get_data(state, BLOCKS, state->x, state->y + 1, state->z);
if (!is_transparent(top_block)) {
return;
}
/* check to be sure this block is solid/fluid */
if (block_has_property(top_block, SOLID) || block_has_property(top_block, FLUID)) {
/* top block is fluid or solid, skip drawing */
return;
}
/* check to be sure this block is solid/fluid */
if (!block_has_property(state->block, SOLID) && !block_has_property(state->block, FLUID)) {
/* not fluid or solid, skip drawing the overlay */
return;
}
/* get our color info */
self->get_color(data, state, &r, &g, &b, &a);
/* do the overlay */
if (a > 0) {
alpha_over_full(state->img, self->white_color, self->facemask_top, a/255.f, state->imgx, state->imgy + increment, 0, 0);
alpha_over_full(state->img, self->white_color, self->facemask_top, a / 255.f, state->imgx, state->imgy + increment, 0, 0);
tint_with_mask(state->img, r, g, b, 255, self->facemask_top, state->imgx, state->imgy + increment, 0, 0);
}
}

View File

@@ -27,14 +27,14 @@ typedef struct {
/* color will be a pointer to either the default_color object below or
to a specially allocated color object that is instantiated from the
settings file */
OverlayColor *color;
OverlayColor* color;
OverlayColor default_color;
/* can be overridden in derived classes to control
overlay alpha and color
last four vars are r, g, b, a out */
void (*get_color)(void *, RenderState *,
unsigned char *, unsigned char *, unsigned char *, unsigned char *);
void (*get_color)(void*, RenderState*,
unsigned char*, unsigned char*, unsigned char*, unsigned char*);
} RenderPrimitiveOverlay;
extern RenderPrimitiveInterface primitive_overlay;
void overlay_draw(void *data, RenderState *state, PyObject *src, PyObject *mask, PyObject *mask_light);
void overlay_draw(void* data, RenderState* state, PyObject* src, PyObject* mask, PyObject* mask_light);

View File

@@ -15,11 +15,11 @@
* with the Overviewer. If not, see <http://www.gnu.org/licenses/>.
*/
#include "../overviewer.h"
#include "../mc_id.h"
#include "../block_class.h"
#include "lighting.h"
#include <math.h>
#include "../block_class.h"
#include "../mc_id.h"
#include "../overviewer.h"
#include "lighting.h"
typedef struct {
/* inherits from lighting */
@@ -30,7 +30,7 @@ typedef struct {
struct SmoothLightingCorner {
/* where this corner shows up on each block texture */
int imgx, imgy;
/* the two block offsets that (together) determine the 4 blocks to use */
int dx1, dy1, dz1;
int dx2, dy2, dz2;
@@ -41,12 +41,12 @@ struct SmoothLightingFace {
/* offset from current coordinate to the block this face points towards
used for occlusion calculations, and as a base for later */
int dx, dy, dz;
/* the points that form the corners of this face */
struct SmoothLightingCorner corners[4];
/* pairs of (x,y) in order, as touch-up points, or NULL for none */
int *touch_up_points;
int* touch_up_points;
unsigned int num_touch_up_points;
};
@@ -69,73 +69,51 @@ static struct SmoothLightingFace lighting_rules[] = {
// ...
*/
/* top */
{0, 1, 0, {
{0, 6,
-1, 0, 0,
0, 0, -1},
{12, 0,
1, 0, 0,
0, 0, -1},
{24, 6,
1, 0, 0,
0, 0, 1},
{12, 12,
-1, 0, 0,
0, 0, 1},
},
top_touchups, 6},
{0, 6, -1, 0, 0, 0, 0, -1},
{12, 0, 1, 0, 0, 0, 0, -1},
{24, 6, 1, 0, 0, 0, 0, 1},
{12, 12, -1, 0, 0, 0, 0, 1},
},
top_touchups,
6},
/* left */
{-1, 0, 0, {
{0, 18,
0, 0, -1,
0, -1, 0},
{0, 6,
0, 0, -1,
0, 1, 0},
{12, 12,
0, 0, 1,
0, 1, 0},
{12, 24,
0, 0, 1,
0, -1, 0},
},
NULL, 0},
{0, 18, 0, 0, -1, 0, -1, 0},
{0, 6, 0, 0, -1, 0, 1, 0},
{12, 12, 0, 0, 1, 0, 1, 0},
{12, 24, 0, 0, 1, 0, -1, 0},
},
NULL,
0},
/* right */
{0, 0, 1, {
{24, 6,
1, 0, 0,
0, 1, 0},
{12, 12,
-1, 0, 0,
0, 1, 0},
{12, 24,
-1, 0, 0,
0, -1, 0},
{24, 18,
1, 0, 0,
0, -1, 0},
},
NULL, 0},
{24, 6, 1, 0, 0, 0, 1, 0},
{12, 12, -1, 0, 0, 0, 1, 0},
{12, 24, -1, 0, 0, 0, -1, 0},
{24, 18, 1, 0, 0, 0, -1, 0},
},
NULL,
0},
};
/* helpers for indexing the rule list */
enum
{
enum {
FACE_TOP = 0,
FACE_LEFT = 1,
FACE_RIGHT = 2,
};
static void
do_shading_with_rule(RenderPrimitiveSmoothLighting *self, RenderState *state, struct SmoothLightingFace face) {
do_shading_with_rule(RenderPrimitiveSmoothLighting* self, RenderState* state, struct SmoothLightingFace face) {
int i;
RenderPrimitiveLighting *lighting = (RenderPrimitiveLighting *)self;
RenderPrimitiveLighting* lighting = (RenderPrimitiveLighting*)self;
int x = state->imgx, y = state->imgy;
struct SmoothLightingCorner *pts = face.corners;
struct SmoothLightingCorner* pts = face.corners;
float comp_shade_strength = 1.0 - lighting->strength;
unsigned char pts_r[4] = {0, 0, 0, 0};
unsigned char pts_g[4] = {0, 0, 0, 0};
@@ -143,97 +121,100 @@ do_shading_with_rule(RenderPrimitiveSmoothLighting *self, RenderState *state, st
int cx = state->x + face.dx;
int cy = state->y + face.dy;
int cz = state->z + face.dz;
/* first, check for occlusion if the block is in the local chunk */
if (lighting_is_face_occluded(state, 0, cx, cy, cz))
return;
/* calculate the lighting colors for each point */
for (i = 0; i < 4; i++)
{
for (i = 0; i < 4; i++) {
unsigned char r, g, b;
unsigned int rgather = 0, ggather = 0, bgather = 0;
get_lighting_color(lighting, state, cx, cy, cz,
&r, &g, &b);
rgather += r; ggather += g; bgather += b;
rgather += r;
ggather += g;
bgather += b;
get_lighting_color(lighting, state,
cx+pts[i].dx1, cy+pts[i].dy1, cz+pts[i].dz1,
cx + pts[i].dx1, cy + pts[i].dy1, cz + pts[i].dz1,
&r, &g, &b);
rgather += r; ggather += g; bgather += b;
rgather += r;
ggather += g;
bgather += b;
get_lighting_color(lighting, state,
cx+pts[i].dx2, cy+pts[i].dy2, cz+pts[i].dz2,
cx + pts[i].dx2, cy + pts[i].dy2, cz + pts[i].dz2,
&r, &g, &b);
rgather += r; ggather += g; bgather += b;
rgather += r;
ggather += g;
bgather += b;
/* FIXME special far corner handling */
get_lighting_color(lighting, state,
cx+pts[i].dx1+pts[i].dx2, cy+pts[i].dy1+pts[i].dy2, cz+pts[i].dz1+pts[i].dz2,
cx + pts[i].dx1 + pts[i].dx2, cy + pts[i].dy1 + pts[i].dy2, cz + pts[i].dz1 + pts[i].dz2,
&r, &g, &b);
rgather += r; ggather += g; bgather += b;
rgather += (255*4 - rgather) * comp_shade_strength;
ggather += (255*4 - ggather) * comp_shade_strength;
bgather += (255*4 - bgather) * comp_shade_strength;
rgather += r;
ggather += g;
bgather += b;
rgather += (255 * 4 - rgather) * comp_shade_strength;
ggather += (255 * 4 - ggather) * comp_shade_strength;
bgather += (255 * 4 - bgather) * comp_shade_strength;
pts_r[i] = rgather / 4;
pts_g[i] = ggather / 4;
pts_b[i] = bgather / 4;
}
/* draw the face */
draw_triangle(state->img, 1,
x+pts[0].imgx, y+pts[0].imgy, pts_r[0], pts_g[0], pts_b[0],
x+pts[1].imgx, y+pts[1].imgy, pts_r[1], pts_g[1], pts_b[1],
x+pts[2].imgx, y+pts[2].imgy, pts_r[2], pts_g[2], pts_b[2],
x + pts[0].imgx, y + pts[0].imgy, pts_r[0], pts_g[0], pts_b[0],
x + pts[1].imgx, y + pts[1].imgy, pts_r[1], pts_g[1], pts_b[1],
x + pts[2].imgx, y + pts[2].imgy, pts_r[2], pts_g[2], pts_b[2],
x, y, face.touch_up_points, face.num_touch_up_points);
draw_triangle(state->img, 0,
x+pts[0].imgx, y+pts[0].imgy, pts_r[0], pts_g[0], pts_b[0],
x+pts[2].imgx, y+pts[2].imgy, pts_r[2], pts_g[2], pts_b[2],
x+pts[3].imgx, y+pts[3].imgy, pts_r[3], pts_g[3], pts_b[3],
x + pts[0].imgx, y + pts[0].imgy, pts_r[0], pts_g[0], pts_b[0],
x + pts[2].imgx, y + pts[2].imgy, pts_r[2], pts_g[2], pts_b[2],
x + pts[3].imgx, y + pts[3].imgy, pts_r[3], pts_g[3], pts_b[3],
x, y, NULL, 0);
}
static int
smooth_lighting_start(void *data, RenderState *state, PyObject *support) {
smooth_lighting_start(void* data, RenderState* state, PyObject* support) {
/* first, chain up */
int ret = primitive_lighting.start(data, state, support);
if (ret != 0)
return ret;
return ret;
return 0;
}
static void
smooth_lighting_finish(void *data, RenderState *state) {
smooth_lighting_finish(void* data, RenderState* state) {
/* nothing special to do */
primitive_lighting.finish(data, state);
}
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) {
int light_top = 1;
int light_left = 1;
int light_right = 1;
RenderPrimitiveSmoothLighting *self = (RenderPrimitiveSmoothLighting *)data;
RenderPrimitiveSmoothLighting* self = (RenderPrimitiveSmoothLighting*)data;
/* special case for leaves, water 8, water 9, ice 79
-- these are also smooth-lit! */
if (!block_class_is_subset(state->block, (mc_block_t[]){
block_leaves,block_flowing_water,block_water,block_ice
}, 4) && is_transparent(state->block))
{
if (!block_class_is_subset(state->block, (mc_block_t[]){block_leaves, block_flowing_water, block_water, block_ice}, 4) && is_transparent(state->block)) {
/* transparent blocks are rendered as usual, with flat lighting */
primitive_lighting.draw(data, state, src, mask, mask_light);
return;
}
/* non-transparent blocks get the special smooth treatment */
/* special code for water */
if (state->block == block_water)
{
if (state->block == block_water) {
if (!(state->block_pdata & (1 << 4)))
light_top = 0;
if (!(state->block_pdata & (1 << 1)))
@@ -241,7 +222,7 @@ smooth_lighting_draw(void *data, RenderState *state, PyObject *src, PyObject *ma
if (!(state->block_pdata & (1 << 2)))
light_right = 0;
}
if (light_top)
do_shading_with_rule(self, state, lighting_rules[FACE_TOP]);
if (light_left)
@@ -251,7 +232,8 @@ smooth_lighting_draw(void *data, RenderState *state, PyObject *src, PyObject *ma
}
RenderPrimitiveInterface primitive_smooth_lighting = {
"smooth-lighting", sizeof(RenderPrimitiveSmoothLighting),
"smooth-lighting",
sizeof(RenderPrimitiveSmoothLighting),
smooth_lighting_start,
smooth_lighting_finish,
NULL,