0

Merge Pull Request #1542

This commit is contained in:
Nicolas F
2019-06-25 18:21:27 +02:00
36 changed files with 1299 additions and 1372 deletions

38
.clang-format Normal file
View File

@@ -0,0 +1,38 @@
---
Language: Cpp
AlignEscapedNewlinesLeft: 'true'
AlignTrailingComments: 'true'
AllowShortBlocksOnASingleLine: 'false'
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: 'false'
AllowShortLoopsOnASingleLine: 'false'
ColumnLimit: '0'
ContinuationIndentWidth: '4'
IndentWidth: '4'
SortIncludes: true
IncludeCategories:
- Regex: '<[[:alnum:].]+>'
Priority: -1
- Regex: '\".*\"'
Priority: 1
IndentCaseLabels: false
MaxEmptyLinesToKeep: '1'
PointerAlignment: Left
SpaceBeforeAssignmentOperators: 'true'
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: 'false'
SpacesBeforeTrailingComments: '1'
SpacesInCStyleCastParentheses: 'false'
SpacesInContainerLiterals: 'false'
SpacesInParentheses: 'false'
TabWidth: '4'
BreakBeforeTernaryOperators: true
Cpp11BracedListStyle: true
BreakBeforeBraces: Custom
BraceWrapping:
BeforeElse: false
AfterEnum: false
AfterFunction: false
AfterStruct: false
AfterUnion: false
...

View File

@@ -78,22 +78,19 @@ typedef struct {
} Edge; } Edge;
static inline void static inline void
point8(Imaging im, int x, int y, int ink) point8(Imaging im, int x, int y, int ink) {
{
if (x >= 0 && x < im->xsize && y >= 0 && y < im->ysize) if (x >= 0 && x < im->xsize && y >= 0 && y < im->ysize)
im->image8[y][x] = (UINT8)ink; im->image8[y][x] = (UINT8)ink;
} }
static inline void static inline void
point32(Imaging im, int x, int y, int ink) point32(Imaging im, int x, int y, int ink) {
{
if (x >= 0 && x < im->xsize && y >= 0 && y < im->ysize) if (x >= 0 && x < im->xsize && y >= 0 && y < im->ysize)
im->image32[y][x] = ink; im->image32[y][x] = ink;
} }
static inline void static inline void
point32rgba(Imaging im, int x, int y, int ink) point32rgba(Imaging im, int x, int y, int ink) {
{
unsigned int tmp1, tmp2; unsigned int tmp1, tmp2;
if (x >= 0 && x < im->xsize && y >= 0 && y < im->ysize) { if (x >= 0 && x < im->xsize && y >= 0 && y < im->ysize) {
@@ -106,8 +103,7 @@ point32rgba(Imaging im, int x, int y, int ink)
} }
static inline void static inline void
hline8(Imaging im, int x0, int y0, int x1, int ink) hline8(Imaging im, int x0, int y0, int x1, int ink) {
{
int tmp; int tmp;
if (y0 >= 0 && y0 < im->ysize) { if (y0 >= 0 && y0 < im->ysize) {
@@ -127,8 +123,7 @@ hline8(Imaging im, int x0, int y0, int x1, int ink)
} }
static inline void static inline void
hline32(Imaging im, int x0, int y0, int x1, int ink) hline32(Imaging im, int x0, int y0, int x1, int ink) {
{
int tmp; int tmp;
INT32* p; INT32* p;
@@ -150,8 +145,7 @@ hline32(Imaging im, int x0, int y0, int x1, int ink)
} }
static inline void static inline void
hline32rgba(Imaging im, int x0, int y0, int x1, int ink) hline32rgba(Imaging im, int x0, int y0, int x1, int ink) {
{
int tmp; int tmp;
unsigned int tmp1, tmp2; unsigned int tmp1, tmp2;
@@ -173,15 +167,15 @@ hline32rgba(Imaging im, int x0, int y0, int x1, int ink)
out[0] = OV_BLEND(in[3], out[0], in[0], tmp1, tmp2); out[0] = OV_BLEND(in[3], out[0], in[0], tmp1, tmp2);
out[1] = OV_BLEND(in[3], out[1], in[1], tmp1, tmp2); out[1] = OV_BLEND(in[3], out[1], in[1], tmp1, tmp2);
out[2] = OV_BLEND(in[3], out[2], in[2], tmp1, tmp2); out[2] = OV_BLEND(in[3], out[2], in[2], tmp1, tmp2);
x0++; out += 4; x0++;
out += 4;
} }
} }
} }
} }
static inline void static inline void
line8(Imaging im, int x0, int y0, int x1, int y1, int ink) line8(Imaging im, int x0, int y0, int x1, int y1, int ink) {
{
int i, n, e; int i, n, e;
int dx, dy; int dx, dy;
int xs, ys; int xs, ys;
@@ -251,13 +245,11 @@ line8(Imaging im, int x0, int y0, int x1, int y1, int ink)
e += dx; e += dx;
y0 += ys; y0 += ys;
} }
} }
} }
static inline void static inline void
line32(Imaging im, int x0, int y0, int x1, int y1, int ink) line32(Imaging im, int x0, int y0, int x1, int y1, int ink) {
{
int i, n, e; int i, n, e;
int dx, dy; int dx, dy;
int xs, ys; int xs, ys;
@@ -327,13 +319,11 @@ line32(Imaging im, int x0, int y0, int x1, int y1, int ink)
e += dx; e += dx;
y0 += ys; y0 += ys;
} }
} }
} }
static inline void static inline void
line32rgba(Imaging im, int x0, int y0, int x1, int y1, int ink) line32rgba(Imaging im, int x0, int y0, int x1, int y1, int ink) {
{
int i, n, e; int i, n, e;
int dx, dy; int dx, dy;
int xs, ys; int xs, ys;
@@ -403,13 +393,11 @@ line32rgba(Imaging im, int x0, int y0, int x1, int y1, int ink)
e += dx; e += dx;
y0 += ys; y0 += ys;
} }
} }
} }
static int static int
x_cmp(const void *x0, const void *x1) x_cmp(const void* x0, const void* x1) {
{
float diff = *((float*)x0) - *((float*)x1); float diff = *((float*)x0) - *((float*)x1);
if (diff < 0) if (diff < 0)
return -1; return -1;
@@ -420,8 +408,7 @@ x_cmp(const void *x0, const void *x1)
} }
static inline int static inline int
polygon8(Imaging im, int n, Edge *e, int ink, int eofill) polygon8(Imaging im, int n, Edge* e, int ink, int eofill) {
{
int i, j; int i, j;
float* xx; float* xx;
int ymin, ymax; int ymin, ymax;
@@ -435,8 +422,10 @@ polygon8(Imaging im, int n, Edge *e, int ink, int eofill)
ymin = e[0].ymin; ymin = e[0].ymin;
ymax = e[0].ymax; ymax = e[0].ymax;
for (i = 1; i < n; i++) { for (i = 1; i < n; i++) {
if (e[i].ymin < ymin) ymin = e[i].ymin; if (e[i].ymin < ymin)
if (e[i].ymax > ymax) ymax = e[i].ymax; ymin = e[i].ymin;
if (e[i].ymax > ymax)
ymax = e[i].ymax;
} }
if (ymin < 0) if (ymin < 0)
@@ -477,8 +466,7 @@ polygon8(Imaging im, int n, Edge *e, int ink, int eofill)
} }
static inline int static inline int
polygon32(Imaging im, int n, Edge *e, int ink, int eofill) polygon32(Imaging im, int n, Edge* e, int ink, int eofill) {
{
int i, j; int i, j;
float* xx; float* xx;
int ymin, ymax; int ymin, ymax;
@@ -492,8 +480,10 @@ polygon32(Imaging im, int n, Edge *e, int ink, int eofill)
ymin = e[0].ymin; ymin = e[0].ymin;
ymax = e[0].ymax; ymax = e[0].ymax;
for (i = 1; i < n; i++) { for (i = 1; i < n; i++) {
if (e[i].ymin < ymin) ymin = e[i].ymin; if (e[i].ymin < ymin)
if (e[i].ymax > ymax) ymax = e[i].ymax; ymin = e[i].ymin;
if (e[i].ymax > ymax)
ymax = e[i].ymax;
} }
if (ymin < 0) if (ymin < 0)
@@ -535,8 +525,7 @@ polygon32(Imaging im, int n, Edge *e, int ink, int eofill)
} }
static inline int static inline int
polygon32rgba(Imaging im, int n, Edge *e, int ink, int eofill) polygon32rgba(Imaging im, int n, Edge* e, int ink, int eofill) {
{
int i, j; int i, j;
float* xx; float* xx;
int ymin, ymax; int ymin, ymax;
@@ -550,8 +539,10 @@ polygon32rgba(Imaging im, int n, Edge *e, int ink, int eofill)
ymin = e[0].ymin; ymin = e[0].ymin;
ymax = e[0].ymax; ymax = e[0].ymax;
for (i = 1; i < n; i++) { for (i = 1; i < n; i++) {
if (e[i].ymin < ymin) ymin = e[i].ymin; if (e[i].ymin < ymin)
if (e[i].ymax > ymax) ymax = e[i].ymax; ymin = e[i].ymin;
if (e[i].ymax > ymax)
ymax = e[i].ymax;
} }
if (ymin < 0) if (ymin < 0)
@@ -593,8 +584,7 @@ polygon32rgba(Imaging im, int n, Edge *e, int ink, int eofill)
} }
static inline void static inline void
add_edge(Edge *e, int x0, int y0, int x1, int y1) add_edge(Edge* e, int x0, int y0, int x1, int y1) {
{
/* printf("edge %d %d %d %d\n", x0, y0, x1, y1); */ /* printf("edge %d %d %d %d\n", x0, y0, x1, y1); */
if (x0 <= x1) if (x0 <= x1)
@@ -646,9 +636,7 @@ DRAW draw32rgba = { point32rgba, hline32rgba, line32rgba, polygon32rgba };
ink = INK32(ink_); \ ink = INK32(ink_); \
} }
int int ImagingDrawPoint(Imaging im, int x0, int y0, const void* ink_, int op) {
ImagingDrawPoint(Imaging im, int x0, int y0, const void* ink_, int op)
{
DRAW* draw; DRAW* draw;
INT32 ink; INT32 ink;
@@ -659,10 +647,8 @@ ImagingDrawPoint(Imaging im, int x0, int y0, const void* ink_, int op)
return 0; return 0;
} }
int int ImagingDrawLine(Imaging im, int x0, int y0, int x1, int y1, const void* ink_,
ImagingDrawLine(Imaging im, int x0, int y0, int x1, int y1, const void* ink_, int op) {
int op)
{
DRAW* draw; DRAW* draw;
INT32 ink; INT32 ink;
@@ -673,10 +659,8 @@ ImagingDrawLine(Imaging im, int x0, int y0, int x1, int y1, const void* ink_,
return 0; return 0;
} }
int int ImagingDrawWideLine(Imaging im, int x0, int y0, int x1, int y1,
ImagingDrawWideLine(Imaging im, int x0, int y0, int x1, int y1, const void* ink_, int width, int op) {
const void* ink_, int width, int op)
{
DRAW* draw; DRAW* draw;
INT32 ink; INT32 ink;
@@ -715,8 +699,6 @@ ImagingDrawWideLine(Imaging im, int x0, int y0, int x1, int y1,
return 0; return 0;
} }
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* standard shapes */ /* standard shapes */
@@ -724,7 +706,6 @@ ImagingDrawWideLine(Imaging im, int x0, int y0, int x1, int y1,
#define CHORD 1 #define CHORD 1
#define PIESLICE 2 #define PIESLICE 2
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* experimental level 2 ("arrow") graphics stuff. this implements /* experimental level 2 ("arrow") graphics stuff. this implements
@@ -744,14 +725,9 @@ struct ImagingOutlineInstance {
Edge* edges; Edge* edges;
int size; int size;
}; };
void ImagingOutlineDelete(ImagingOutline outline) {
void
ImagingOutlineDelete(ImagingOutline outline)
{
if (!outline) if (!outline)
return; return;
@@ -761,10 +737,8 @@ ImagingOutlineDelete(ImagingOutline outline)
free(outline); free(outline);
} }
static Edge* static Edge*
allocate(ImagingOutline outline, int extra) allocate(ImagingOutline outline, int extra) {
{
Edge* e; Edge* e;
if (outline->count + extra > outline->size) { if (outline->count + extra > outline->size) {
@@ -786,18 +760,14 @@ allocate(ImagingOutline outline, int extra)
return e; return e;
} }
int int ImagingOutlineMove(ImagingOutline outline, float x0, float y0) {
ImagingOutlineMove(ImagingOutline outline, float x0, float y0)
{
outline->x = outline->x0 = x0; outline->x = outline->x0 = x0;
outline->y = outline->y0 = y0; outline->y = outline->y0 = y0;
return 0; return 0;
} }
int int ImagingOutlineLine(ImagingOutline outline, float x1, float y1) {
ImagingOutlineLine(ImagingOutline outline, float x1, float y1)
{
Edge* e; Edge* e;
e = allocate(outline, 1); e = allocate(outline, 1);
@@ -812,10 +782,8 @@ ImagingOutlineLine(ImagingOutline outline, float x1, float y1)
return 0; return 0;
} }
int int ImagingOutlineCurve(ImagingOutline outline, float x1, float y1,
ImagingOutlineCurve(ImagingOutline outline, float x1, float y1, float x2, float y2, float x3, float y3) {
float x2, float y2, float x3, float y3)
{
Edge* e; Edge* e;
int i; int i;
float xo, yo; float xo, yo;
@@ -847,7 +815,6 @@ ImagingOutlineCurve(ImagingOutline outline, float x1, float y1,
add_edge(e++, xo, yo, (int)x, (int)y); add_edge(e++, xo, yo, (int)x, (int)y);
xo = x, yo = y; xo = x, yo = y;
} }
outline->x = xo; outline->x = xo;
@@ -856,10 +823,8 @@ ImagingOutlineCurve(ImagingOutline outline, float x1, float y1,
return 0; return 0;
} }
int int ImagingOutlineCurve2(ImagingOutline outline, float cx, float cy,
ImagingOutlineCurve2(ImagingOutline outline, float cx, float cy, float x3, float y3) {
float x3, float y3)
{
/* add bezier curve based on three control points (as /* add bezier curve based on three control points (as
in the Flash file format) */ in the Flash file format) */
@@ -870,19 +835,14 @@ ImagingOutlineCurve2(ImagingOutline outline, float cx, float cy,
x3, y3); x3, y3);
} }
int int ImagingOutlineClose(ImagingOutline outline) {
ImagingOutlineClose(ImagingOutline outline)
{
if (outline->x == outline->x0 && outline->y == outline->y0) if (outline->x == outline->x0 && outline->y == outline->y0)
return 0; return 0;
return ImagingOutlineLine(outline, outline->x0, outline->y0); return ImagingOutlineLine(outline, outline->x0, outline->y0);
} }
int ImagingDrawOutline(Imaging im, ImagingOutline outline, const void* ink_,
int int fill, int op) {
ImagingDrawOutline(Imaging im, ImagingOutline outline, const void* ink_,
int fill, int op)
{
DRAW* draw; DRAW* draw;
INT32 ink; INT32 ink;

View File

@@ -25,15 +25,13 @@
bool block_class_is_subset( bool block_class_is_subset(
mc_block_t block, mc_block_t block,
const mc_block_t block_class[], const mc_block_t block_class[],
size_t block_class_len size_t block_class_len) {
) {
size_t i = 0; size_t i = 0;
#ifdef __SSE2__ #ifdef __SSE2__
for (; i / 8 < block_class_len / 8; i += 8) { for (; i / 8 < block_class_len / 8; i += 8) {
const __m128i block_class_vec = _mm_loadu_si128( const __m128i block_class_vec = _mm_loadu_si128(
(__m128i*)&block_class[i] (__m128i*)&block_class[i]);
);
const __m128i block_vec = _mm_set1_epi16(block); const __m128i block_vec = _mm_set1_epi16(block);
const __m128i block_cmp = _mm_cmpeq_epi16(block_vec, block_class_vec); const __m128i block_cmp = _mm_cmpeq_epi16(block_vec, block_class_vec);
if (_mm_movemask_epi8(block_cmp)) { if (_mm_movemask_epi8(block_cmp)) {
@@ -44,8 +42,7 @@ bool block_class_is_subset(
#ifdef __MMX__ #ifdef __MMX__
for (; i / 4 < block_class_len / 4; i += 4) { for (; i / 4 < block_class_len / 4; i += 4) {
const __m64 block_class_vec = _mm_cvtsi64_m64( const __m64 block_class_vec = _mm_cvtsi64_m64(
*(uint64_t*)&block_class[i] *(uint64_t*)&block_class[i]);
);
const __m64 block_vec = _mm_set1_pi16(block); const __m64 block_vec = _mm_set1_pi16(block);
const __m64 block_cmp = _mm_cmpeq_pi16(block_vec, block_class_vec); const __m64 block_cmp = _mm_cmpeq_pi16(block_vec, block_class_vec);
if (_mm_cvtm64_si64(block_cmp)) { if (_mm_cvtm64_si64(block_cmp)) {
@@ -61,7 +58,6 @@ bool block_class_is_subset(
return false; return false;
} }
const mc_block_t block_class_stair[] = { const mc_block_t block_class_stair[] = {
block_oak_stairs, block_oak_stairs,
block_stone_stairs, block_stone_stairs,
@@ -79,8 +75,7 @@ const mc_block_t block_class_stair[] = {
block_purpur_stairs, block_purpur_stairs,
block_prismarine_stairs, block_prismarine_stairs,
block_dark_prismarine_stairs, block_dark_prismarine_stairs,
block_prismarine_brick_stairs block_prismarine_brick_stairs};
};
const size_t block_class_stair_len = COUNT_OF(block_class_stair); const size_t block_class_stair_len = COUNT_OF(block_class_stair);
const mc_block_t block_class_door[] = { const mc_block_t block_class_door[] = {
@@ -90,8 +85,7 @@ const mc_block_t block_class_door[] = {
block_birch_door, block_birch_door,
block_jungle_door, block_jungle_door,
block_acacia_door, block_acacia_door,
block_dark_oak_door block_dark_oak_door};
};
const size_t block_class_door_len = COUNT_OF(block_class_door); const size_t block_class_door_len = COUNT_OF(block_class_door);
const mc_block_t block_class_fence[] = { const mc_block_t block_class_fence[] = {
@@ -101,8 +95,7 @@ const mc_block_t block_class_fence[] = {
block_birch_fence, block_birch_fence,
block_jungle_fence, block_jungle_fence,
block_dark_oak_fence, block_dark_oak_fence,
block_acacia_fence block_acacia_fence};
};
const size_t block_class_fence_len = COUNT_OF(block_class_fence); const size_t block_class_fence_len = COUNT_OF(block_class_fence);
const mc_block_t block_class_fence_gate[] = { const mc_block_t block_class_fence_gate[] = {
@@ -111,8 +104,7 @@ const mc_block_t block_class_fence_gate[] = {
block_birch_fence_gate, block_birch_fence_gate,
block_jungle_fence_gate, block_jungle_fence_gate,
block_dark_oak_fence_gate, block_dark_oak_fence_gate,
block_acacia_fence_gate block_acacia_fence_gate};
};
const size_t block_class_fence_gate_len = COUNT_OF(block_class_fence_gate); const size_t block_class_fence_gate_len = COUNT_OF(block_class_fence_gate);
const mc_block_t block_class_ancil[] = { const mc_block_t block_class_ancil[] = {
@@ -162,8 +154,7 @@ const mc_block_t block_class_ancil[] = {
block_birch_fence, block_birch_fence,
block_jungle_fence, block_jungle_fence,
block_dark_oak_fence, block_dark_oak_fence,
block_acacia_fence block_acacia_fence};
};
const size_t block_class_ancil_len = COUNT_OF(block_class_ancil); const size_t block_class_ancil_len = COUNT_OF(block_class_ancil);
const mc_block_t block_class_alt_height[] = { const mc_block_t block_class_alt_height[] = {
@@ -206,7 +197,5 @@ const mc_block_t block_class_alt_height[] = {
block_stone_slab2, block_stone_slab2,
block_purpur_stairs, block_purpur_stairs,
block_purpur_slab, block_purpur_slab,
block_wooden_slab block_wooden_slab};
};
const size_t block_class_alt_height_len = COUNT_OF(block_class_alt_height); const size_t block_class_alt_height_len = COUNT_OF(block_class_alt_height);

View File

@@ -26,8 +26,7 @@
bool block_class_is_subset( bool block_class_is_subset(
mc_block_t block, mc_block_t block,
const mc_block_t block_class[], const mc_block_t block_class[],
size_t block_class_len size_t block_class_len);
);
extern const mc_block_t block_class_stair[]; extern const mc_block_t block_class_stair[];
extern const size_t block_class_stair_len; extern const size_t block_class_stair_len;
@@ -48,4 +47,3 @@ extern const mc_block_t block_class_alt_height[];
extern const size_t block_class_alt_height_len; extern const size_t block_class_alt_height_len;
#endif #endif

View File

@@ -30,8 +30,7 @@ typedef struct {
} ImagingObject; } ImagingObject;
inline Imaging inline Imaging
imaging_python_to_c(PyObject *obj) imaging_python_to_c(PyObject* obj) {
{
PyObject* im; PyObject* im;
Imaging image; Imaging image;
@@ -57,8 +56,7 @@ imaging_python_to_c(PyObject *obj)
in these composite functions -- even handles auto-sizing to src! */ in these composite functions -- even handles auto-sizing to src! */
static inline void static inline void
setup_source_destination(Imaging src, Imaging dest, setup_source_destination(Imaging src, Imaging dest,
int *sx, int *sy, int *dx, int *dy, int *xsize, int *ysize) int* sx, int* sy, int* dx, int* dy, int* xsize, int* ysize) {
{
/* handle negative/zero sizes appropriately */ /* handle negative/zero sizes appropriately */
if (*xsize <= 0 || *ysize <= 0) { if (*xsize <= 0 || *ysize <= 0) {
*xsize = src->xsize; *xsize = src->xsize;
@@ -231,8 +229,7 @@ alpha_over_full(PyObject *dest, PyObject *src, PyObject *mask, float overall_alp
/* wraps alpha_over so it can be called directly from python */ /* wraps alpha_over so it can be called directly from python */
/* properly refs the return value when needed: you DO need to decref the return */ /* properly refs the return value when needed: you DO need to decref the return */
PyObject* PyObject*
alpha_over_wrap(PyObject *self, PyObject *args) alpha_over_wrap(PyObject* self, PyObject* args) {
{
/* raw input python variables */ /* raw input python variables */
PyObject *dest, *src, *pos = NULL, *mask = NULL; PyObject *dest, *src, *pos = NULL, *mask = NULL;
/* destination position and size */ /* destination position and size */
@@ -421,9 +418,15 @@ draw_triangle(PyObject *dest, int inclusive,
ymax = OV_MIN(ymax, imDest->ysize); ymax = OV_MIN(ymax, imDest->ysize);
/* setup coefficients */ /* setup coefficients */
a12 = y1 - y2; b12 = x2 - x1; c12 = (x1 * y2) - (x2 * y1); a12 = y1 - y2;
a20 = y2 - y0; b20 = x0 - x2; c20 = (x2 * y0) - (x0 * y2); b12 = x2 - x1;
a01 = y0 - y1; b01 = x1 - x0; c01 = (x0 * y1) - (x1 * y0); c12 = (x1 * y2) - (x2 * y1);
a20 = y2 - y0;
b20 = x0 - x2;
c20 = (x2 * y0) - (x0 * y2);
a01 = y0 - y1;
b01 = x1 - x0;
c01 = (x0 * y1) - (x1 * y0);
/* setup normalizers */ /* setup normalizers */
alpha_norm = 1.0f / ((a12 * x0) + (b12 * y0) + c12); alpha_norm = 1.0f / ((a12 * x0) + (b12 * y0) + c12);
@@ -446,9 +449,12 @@ draw_triangle(PyObject *dest, int inclusive,
unsigned int g = alpha * g0 + beta * g1 + gamma * g2; unsigned int g = alpha * g0 + beta * g1 + gamma * g2;
unsigned int b = alpha * b0 + beta * b1 + gamma * b2; unsigned int b = alpha * b0 + beta * b1 + gamma * b2;
*out = OV_MULDIV255(*out, r, tmp); out++; *out = OV_MULDIV255(*out, r, tmp);
*out = OV_MULDIV255(*out, g, tmp); out++; out++;
*out = OV_MULDIV255(*out, b, tmp); out++; *out = OV_MULDIV255(*out, g, tmp);
out++;
*out = OV_MULDIV255(*out, b, tmp);
out++;
/* keep alpha the same */ /* keep alpha the same */
out++; out++;
@@ -482,9 +488,12 @@ draw_triangle(PyObject *dest, int inclusive,
g = alpha * g0 + beta * g1 + gamma * g2; g = alpha * g0 + beta * g1 + gamma * g2;
b = alpha * b0 + beta * b1 + gamma * b2; b = alpha * b0 + beta * b1 + gamma * b2;
*out = OV_MULDIV255(*out, r, tmp); out++; *out = OV_MULDIV255(*out, r, tmp);
*out = OV_MULDIV255(*out, g, tmp); out++; out++;
*out = OV_MULDIV255(*out, b, tmp); out++; *out = OV_MULDIV255(*out, g, tmp);
out++;
*out = OV_MULDIV255(*out, b, tmp);
out++;
} }
return dest; return dest;
@@ -572,8 +581,7 @@ resize_half(PyObject *dest, PyObject *src) {
in_row1++; in_row1++;
in_row2++; in_row2++;
if (src_has_alpha) if (src_has_alpha) {
{
a = *in_row1; a = *in_row1;
a += *in_row2; a += *in_row2;
in_row1++; in_row1++;
@@ -594,8 +602,7 @@ resize_half(PyObject *dest, PyObject *src) {
in_row1++; in_row1++;
in_row2++; in_row2++;
if (src_has_alpha) if (src_has_alpha) {
{
a += *in_row1; a += *in_row1;
a += *in_row2; a += *in_row2;
in_row1++; in_row1++;
@@ -610,8 +617,7 @@ resize_half(PyObject *dest, PyObject *src) {
*out = (UINT8)(b >> 2); *out = (UINT8)(b >> 2);
out++; out++;
if (dest_has_alpha) if (dest_has_alpha) {
{
*out = (UINT8)(a >> 2); *out = (UINT8)(a >> 2);
out++; out++;
} }
@@ -623,8 +629,7 @@ resize_half(PyObject *dest, PyObject *src) {
/* wraps resize_half so it can be called directly from python */ /* wraps resize_half so it can be called directly from python */
PyObject* PyObject*
resize_half_wrap(PyObject *self, PyObject *args) resize_half_wrap(PyObject* self, PyObject* args) {
{
/* raw input python variables */ /* raw input python variables */
PyObject *dest, *src; PyObject *dest, *src;
/* return value: dest image on success */ /* return value: dest image on success */

View File

@@ -15,9 +15,9 @@
* with the Overviewer. If not, see <http://www.gnu.org/licenses/>. * with the Overviewer. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "overviewer.h"
#include "mc_id.h"
#include "block_class.h" #include "block_class.h"
#include "mc_id.h"
#include "overviewer.h"
static PyObject* textures = NULL; static PyObject* textures = NULL;
@@ -132,8 +132,7 @@ int load_chunk(RenderState* state, int x, int z, unsigned char required) {
/* set up reasonable defaults */ /* set up reasonable defaults */
dest->biomes = NULL; dest->biomes = NULL;
for (i = 0; i < SECTIONS_PER_CHUNK; i++) for (i = 0; i < SECTIONS_PER_CHUNK; i++) {
{
dest->sections[i].blocks = NULL; dest->sections[i].blocks = NULL;
dest->sections[i].data = NULL; dest->sections[i].data = NULL;
dest->sections[i].skylight = NULL; dest->sections[i].skylight = NULL;
@@ -389,7 +388,6 @@ generate_pseudo_data(RenderState *state, unsigned short ancilData) {
} else { } else {
data = ancilData; data = ancilData;
} }
} }
return data; return data;
} else if (state->block == block_cobblestone_wall) { } else if (state->block == block_cobblestone_wall) {
@@ -535,7 +533,6 @@ generate_pseudo_data(RenderState *state, unsigned short ancilData) {
return 0; return 0;
} }
/* TODO triple check this to make sure reference counting is correct */ /* TODO triple check this to make sure reference counting is correct */
PyObject* PyObject*
chunk_render(PyObject* self, PyObject* args) { chunk_render(PyObject* self, PyObject* args) {
@@ -688,8 +685,7 @@ chunk_render(PyObject *self, PyObject *args) {
t = PyList_GET_ITEM(blockmap, max_data * state.block); t = PyList_GET_ITEM(blockmap, max_data * state.block);
/* if we found a proper texture, render it! */ /* if we found a proper texture, render it! */
if (t != NULL && t != Py_None) if (t != NULL && t != Py_None) {
{
PyObject *src, *mask, *mask_light; PyObject *src, *mask, *mask_light;
int do_rand = (state.block == block_tallgrass /*|| state.block == block_red_flower || state.block == block_double_plant*/); int do_rand = (state.block == block_tallgrass /*|| state.block == block_red_flower || state.block == block_double_plant*/);
int randx = 0, randy = 0; int randx = 0, randy = 0;

View File

@@ -43,13 +43,10 @@ static PyModuleDef COverviewerModule = {
"c_overviewer", "c_overviewer",
"", // TODO: Add documentation here. "", // TODO: Add documentation here.
-1, -1,
COverviewerMethods COverviewerMethods};
};
PyMODINIT_FUNC PyMODINIT_FUNC
PyInit_c_overviewer(void) PyInit_c_overviewer(void) {
{
PyObject *mod, *numpy; PyObject *mod, *numpy;
mod = PyModule_Create(&COverviewerModule); mod = PyModule_Create(&COverviewerModule);

View File

@@ -3,8 +3,7 @@
#include <stdint.h> #include <stdint.h>
enum mc_block_id enum mc_block_id {
{
block_air = 0, block_air = 0,
block_stone = 1, block_stone = 1,
block_grass = 2, block_grass = 2,
@@ -284,9 +283,7 @@ enum mc_block_id
typedef uint16_t mc_block_t; typedef uint16_t mc_block_t;
enum mc_item_id {
enum mc_item_id
{
item_iron_shovel = 256, item_iron_shovel = 256,
item_iron_pickaxe = 257, item_iron_pickaxe = 257,
item_iron_axe = 258, item_iron_axe = 258,

View File

@@ -24,27 +24,24 @@
#ifndef __OVERVIEWER_H_INCLUDED__ #ifndef __OVERVIEWER_H_INCLUDED__
#define __OVERVIEWER_H_INCLUDED__ #define __OVERVIEWER_H_INCLUDED__
#define WINVER 0x0601 #define WINVER 0x0601
#define _WIN32_WINNT 0x0601 #define _WIN32_WINNT 0x0601
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
// increment this value if you've made a change to the c extesion // increment this value if you've made a change to the c extesion
// and want to force users to rebuild // and want to force users to rebuild
#define OVERVIEWER_EXTENSION_VERSION 65 #define OVERVIEWER_EXTENSION_VERSION 65
/* Python PIL, and numpy headers */ /* Python PIL, and numpy headers */
#include <Imaging.h>
#include <Python.h> #include <Python.h>
#include <numpy/arrayobject.h> #include <numpy/arrayobject.h>
#include <Imaging.h>
/* Fix Pillow on mingw-w64 which includes windows.h in Imaging.h */ /* Fix Pillow on mingw-w64 which includes windows.h in Imaging.h */
#undef TRANSPARENT #undef TRANSPARENT
/* Utility macros */ /* Utility macros */
#include "utils.h" #include "utils.h"
/* macro for getting a value out of various numpy arrays the 3D arrays have /* macro for getting a value out of various numpy arrays the 3D arrays have
interesting, swizzled coordinates because minecraft (anvil) stores blocks interesting, swizzled coordinates because minecraft (anvil) stores blocks
in y/z/x order for 3D, z/x order for 2D */ in y/z/x order for 3D, z/x order for 2D */
@@ -52,7 +49,6 @@
#define getArrayShort3D(array, x, y, z) (*(unsigned short*)(PyArray_GETPTR3((array), (y), (z), (x)))) #define getArrayShort3D(array, x, y, z) (*(unsigned short*)(PyArray_GETPTR3((array), (y), (z), (x))))
#define getArrayByte2D(array, x, y) (*(unsigned char*)(PyArray_GETPTR2((array), (y), (x)))) #define getArrayByte2D(array, x, y) (*(unsigned char*)(PyArray_GETPTR2((array), (y), (x))))
/* in composite.c */ /* in composite.c */
Imaging imaging_python_to_c(PyObject* obj); Imaging imaging_python_to_c(PyObject* obj);
PyObject* alpha_over(PyObject* dest, PyObject* src, PyObject* mask, PyObject* alpha_over(PyObject* dest, PyObject* src, PyObject* mask,
@@ -123,8 +119,7 @@ PyObject *init_chunk_render(void);
/* returns true on error, x,z relative */ /* returns true on error, x,z relative */
int load_chunk(RenderState* state, int x, int z, unsigned char required); int load_chunk(RenderState* state, int x, int z, unsigned char required);
PyObject* chunk_render(PyObject* self, PyObject* args); PyObject* chunk_render(PyObject* self, PyObject* args);
typedef enum typedef enum {
{
KNOWN, KNOWN,
TRANSPARENT, TRANSPARENT,
SOLID, SOLID,
@@ -152,16 +147,14 @@ block_has_property(unsigned short b, BlockProperty prop) {
#define is_known_transparent(b) block_has_property((b), TRANSPARENT) && block_has_property((b), KNOWN) #define is_known_transparent(b) block_has_property((b), TRANSPARENT) && block_has_property((b), KNOWN)
/* helper for indexing section data possibly across section boundaries */ /* helper for indexing section data possibly across section boundaries */
typedef enum typedef enum {
{
BLOCKS, BLOCKS,
DATA, DATA,
BLOCKLIGHT, BLOCKLIGHT,
SKYLIGHT, SKYLIGHT,
BIOMES, BIOMES,
} DataType; } DataType;
static inline unsigned int get_data(RenderState *state, DataType type, int x, int y, int z) static inline unsigned int get_data(RenderState* state, DataType type, int x, int y, int z) {
{
int chunkx = 1, chunky = state->chunky, chunkz = 1; int chunkx = 1, chunky = state->chunky, chunkz = 1;
PyArrayObject* data_array = NULL; PyArrayObject* data_array = NULL;
unsigned int def = 0; unsigned int def = 0;
@@ -194,14 +187,12 @@ static inline unsigned int get_data(RenderState *state, DataType type, int x, in
if (chunky < 0 || chunky >= SECTIONS_PER_CHUNK) if (chunky < 0 || chunky >= SECTIONS_PER_CHUNK)
return def; return def;
if (!(state->chunks[chunkx][chunkz].loaded)) if (!(state->chunks[chunkx][chunkz].loaded)) {
{
if (load_chunk(state, chunkx - 1, chunkz - 1, 0)) if (load_chunk(state, chunkx - 1, chunkz - 1, 0))
return def; return def;
} }
switch (type) switch (type) {
{
case BLOCKS: case BLOCKS:
data_array = state->chunks[chunkx][chunkz].sections[chunky].blocks; data_array = state->chunks[chunkx][chunkz].sections[chunky].blocks;
break; break;

View File

@@ -15,9 +15,9 @@
* with the Overviewer. If not, see <http://www.gnu.org/licenses/>. * with the Overviewer. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "../overviewer.h"
#include "../mc_id.h"
#include "../block_class.h" #include "../block_class.h"
#include "../mc_id.h"
#include "../overviewer.h"
#include "biomes.h" #include "biomes.h"
typedef struct { typedef struct {
@@ -28,7 +28,6 @@ typedef struct {
PyObject* grass_texture; PyObject* grass_texture;
} PrimitiveBase; } PrimitiveBase;
static int static int
base_start(void* data, RenderState* state, PyObject* support) { base_start(void* data, RenderState* state, PyObject* support) {
PrimitiveBase* self = (PrimitiveBase*)data; PrimitiveBase* self = (PrimitiveBase*)data;
@@ -96,14 +95,7 @@ base_draw(void *data, RenderState *state, PyObject *src, PyObject *mask, PyObjec
*/ */
if (/* grass, but not snowgrass */ if (/* grass, but not snowgrass */
(state->block == block_grass && get_data(state, BLOCKS, state->x, state->y + 1, state->z) != 78) || (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_class_is_subset(state->block, (mc_block_t[]){block_vine, block_waterlily, block_flowing_water, block_water, block_leaves, block_leaves2},
block_vine,
block_waterlily,
block_flowing_water,
block_water,
block_leaves,
block_leaves2
},
6) || 6) ||
/* tallgrass, but not dead shrubs */ /* tallgrass, but not dead shrubs */
(state->block == block_tallgrass && state->block_data != 0) || (state->block == block_tallgrass && state->block_data != 0) ||
@@ -113,8 +105,7 @@ base_draw(void *data, RenderState *state, PyObject *src, PyObject *mask, PyObjec
/* doublePlant grass & ferns */ /* doublePlant grass & ferns */
(state->block == block_double_plant && (state->block_data == 2 || state->block_data == 3)) || (state->block == block_double_plant && (state->block_data == 2 || state->block_data == 3)) ||
/* doublePlant grass & ferns tops */ /* 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! */ /* do the biome stuff! */
PyObject* facemask = mask; PyObject* facemask = mask;
unsigned char r = 255, g = 255, b = 255; unsigned char r = 255, g = 255, b = 255;
@@ -125,28 +116,13 @@ base_draw(void *data, RenderState *state, PyObject *src, PyObject *mask, PyObjec
/* grass needs a special facemask */ /* grass needs a special facemask */
facemask = self->grass_texture; facemask = self->grass_texture;
} }
if(block_class_is_subset(state->block, (mc_block_t[]){ 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)) {
block_grass,
block_tallgrass,
block_pumpkin_stem,
block_melon_stem,
block_vine,
block_waterlily,
block_double_plant
},7)) {
color_table = self->grasscolor; 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; 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) if (state->block_data == 2) {
{
/* birch! /* birch!
birch foliage color is flipped XY-ways */ birch foliage color is flipped XY-ways */
flip_xy = 1; flip_xy = 1;
@@ -232,7 +208,8 @@ base_draw(void *data, RenderState *state, PyObject *src, PyObject *mask, PyObjec
} }
RenderPrimitiveInterface primitive_base = { RenderPrimitiveInterface primitive_base = {
"base", sizeof(PrimitiveBase), "base",
sizeof(PrimitiveBase),
base_start, base_start,
base_finish, base_finish,
base_occluded, base_occluded,

View File

@@ -15,7 +15,6 @@
* with the Overviewer. If not, see <http://www.gnu.org/licenses/>. * with the Overviewer. If not, see <http://www.gnu.org/licenses/>.
*/ */
#define DEFAULT_BIOME 4 /* forest, nice and green */ #define DEFAULT_BIOME 4 /* forest, nice and green */
typedef struct { typedef struct {
@@ -245,4 +244,3 @@ static Biome biome_table[] = {
}; };
#define NUM_BIOMES (sizeof(biome_table) / sizeof(Biome)) #define NUM_BIOMES (sizeof(biome_table) / sizeof(Biome))

View File

@@ -15,8 +15,8 @@
* with the Overviewer. If not, see <http://www.gnu.org/licenses/>. * with the Overviewer. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "../overviewer.h"
#include <math.h> #include <math.h>
#include "../overviewer.h"
typedef struct { typedef struct {
int only_lit; int only_lit;
@@ -114,7 +114,8 @@ cave_start(void *data, RenderState *state, PyObject *support) {
} }
RenderPrimitiveInterface primitive_cave = { RenderPrimitiveInterface primitive_cave = {
"cave", sizeof(RenderPrimitiveCave), "cave",
sizeof(RenderPrimitiveCave),
cave_start, cave_start,
NULL, NULL,
cave_occluded, cave_occluded,

View File

@@ -15,8 +15,8 @@
* with the Overviewer. If not, see <http://www.gnu.org/licenses/>. * with the Overviewer. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "../overviewer.h"
#include <math.h> #include <math.h>
#include "../overviewer.h"
typedef struct { typedef struct {
/* list of colors used for tinting */ /* list of colors used for tinting */
@@ -64,7 +64,8 @@ depth_tinting_draw(void *data, RenderState *state, PyObject *src, PyObject *mask
} }
RenderPrimitiveInterface primitive_depth_tinting = { RenderPrimitiveInterface primitive_depth_tinting = {
"depth-tinting", sizeof(RenderPrimitiveDepthTinting), "depth-tinting",
sizeof(RenderPrimitiveDepthTinting),
depth_tinting_start, depth_tinting_start,
depth_tinting_finish, depth_tinting_finish,
NULL, NULL,

View File

@@ -45,7 +45,8 @@ depth_hidden(void *data, RenderState *state, int x, int y, int z) {
} }
RenderPrimitiveInterface primitive_depth = { RenderPrimitiveInterface primitive_depth = {
"depth", sizeof(PrimitiveDepth), "depth",
sizeof(PrimitiveDepth),
depth_start, depth_start,
NULL, NULL,
NULL, NULL,

View File

@@ -15,9 +15,9 @@
* with the Overviewer. If not, see <http://www.gnu.org/licenses/>. * with the Overviewer. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "../overviewer.h"
#include "../mc_id.h"
#include "../block_class.h" #include "../block_class.h"
#include "../mc_id.h"
#include "../overviewer.h"
typedef struct { typedef struct {
float opacity; float opacity;
@@ -36,8 +36,7 @@ edge_lines_draw(void *data, RenderState *state, PyObject *src, PyObject *mask, P
PrimitiveEdgeLines* self = (PrimitiveEdgeLines*)data; PrimitiveEdgeLines* self = (PrimitiveEdgeLines*)data;
/* Draw some edge lines! */ /* Draw some edge lines! */
if (block_class_is_subset(state->block, (mc_block_t[]){block_stone_slab,block_snow_layer}, 2) if (block_class_is_subset(state->block, (mc_block_t[]){block_stone_slab, block_snow_layer}, 2) || !is_transparent(state->block)) {
|| !is_transparent(state->block)) {
Imaging img_i = imaging_python_to_c(state->img); Imaging img_i = imaging_python_to_c(state->img);
unsigned char ink[] = {0, 0, 0, 255 * self->opacity}; unsigned char ink[] = {0, 0, 0, 255 * self->opacity};
unsigned short side_block; unsigned short side_block;
@@ -54,9 +53,7 @@ edge_lines_draw(void *data, RenderState *state, PyObject *src, PyObject *mask, P
if (side_block != state->block && (is_transparent(side_block) || render_mode_hidden(state->rendermode, 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 */ /* 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 */ /* 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(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)))) {
&& (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 + 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); ImagingDrawLine(img_i, state->imgx + 12, state->imgy + increment, state->imgx + 22 + 1, state->imgy + 5 + increment, &ink, 1);
} }
@@ -67,9 +64,7 @@ edge_lines_draw(void *data, RenderState *state, PyObject *src, PyObject *mask, P
/* WARNING: ugly special case approaching */ /* 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 */ /* 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(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)))) {
&& (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 + 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); ImagingDrawLine(img_i, state->imgx, state->imgy + 6 + increment, state->imgx + 12 + 1, state->imgy + increment, &ink, 1);
} }
@@ -77,7 +72,8 @@ edge_lines_draw(void *data, RenderState *state, PyObject *src, PyObject *mask, P
} }
RenderPrimitiveInterface primitive_edge_lines = { RenderPrimitiveInterface primitive_edge_lines = {
"edge-lines", sizeof(PrimitiveEdgeLines), "edge-lines",
sizeof(PrimitiveEdgeLines),
edge_lines_start, edge_lines_start,
NULL, NULL,
NULL, NULL,

View File

@@ -92,7 +92,6 @@ exposed_hidden(void *data, RenderState *state, int x, int y, int z) {
* shows us if we're rendering exposed blocks * 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 */
@@ -100,7 +99,8 @@ exposed_hidden(void *data, RenderState *state, int x, int y, int z) {
} }
RenderPrimitiveInterface primitive_exposed = { RenderPrimitiveInterface primitive_exposed = {
"exposed", sizeof(PrimitiveExposed), "exposed",
sizeof(PrimitiveExposed),
exposed_start, exposed_start,
NULL, NULL,
NULL, NULL,

View File

@@ -68,7 +68,8 @@ height_fading_draw(void *data, RenderState *state, PyObject *src, PyObject *mask
} }
RenderPrimitiveInterface primitive_height_fading = { RenderPrimitiveInterface primitive_height_fading = {
"height-fading", sizeof(PrimitiveHeightFading), "height-fading",
sizeof(PrimitiveHeightFading),
height_fading_start, height_fading_start,
height_fading_finish, height_fading_finish,
NULL, NULL,

View File

@@ -15,8 +15,8 @@
* with the Overviewer. If not, see <http://www.gnu.org/licenses/>. * with the Overviewer. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "../overviewer.h"
#include "../mc_id.h" #include "../mc_id.h"
#include "../overviewer.h"
struct HideRule { struct HideRule {
unsigned short blockid; unsigned short blockid;

View File

@@ -15,11 +15,11 @@
* with the Overviewer. If not, see <http://www.gnu.org/licenses/>. * 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 <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, /* figures out the color from a given skylight and blocklight,
used in lighting calculations */ used in lighting calculations */
@@ -182,7 +182,6 @@ get_lighting_color(RenderPrimitiveLighting *self, RenderState *state,
/* the block has a bad blocklevel, estimate it from neigborhood /* the block has a bad blocklevel, estimate it from neigborhood
* use given coordinates, no local ones! */ * use given coordinates, no local ones! */
blocklevel = estimate_blocklevel(self, state, x, y, z, NULL); 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)) {
@@ -331,7 +330,8 @@ lighting_draw(void *data, RenderState *state, PyObject *src, PyObject *mask, PyO
} }
RenderPrimitiveInterface primitive_lighting = { RenderPrimitiveInterface primitive_lighting = {
"lighting", sizeof(RenderPrimitiveLighting), "lighting",
sizeof(RenderPrimitiveLighting),
lighting_start, lighting_start,
lighting_finish, lighting_finish,
NULL, NULL,

View File

@@ -15,10 +15,10 @@
* with the Overviewer. If not, see <http://www.gnu.org/licenses/>. * 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 "nether.h"
#include "../block_class.h"
#include "../mc_id.h"
#include "../overviewer.h"
static void static void
walk_chunk(RenderState* state, RenderPrimitiveNether* data) { walk_chunk(RenderState* state, RenderPrimitiveNether* data) {
@@ -62,7 +62,8 @@ nether_hidden(void *data, RenderState *state, int x, int y, int z) {
} }
RenderPrimitiveInterface primitive_nether = { RenderPrimitiveInterface primitive_nether = {
"nether", sizeof(RenderPrimitiveNether), "nether",
sizeof(RenderPrimitiveNether),
NULL, NULL,
NULL, NULL,
NULL, NULL,

View File

@@ -25,8 +25,7 @@ netherold_hidden(void *data, RenderState *state, int x, int y, int z) {
empty sections as 'solid' empty sections as 'solid'
*/ */
unsigned char missing_section = 0; 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) { if (state->chunks[1][1].sections[state->chunky + (y / 16)].blocks == NULL) {
missing_section = 1; missing_section = 1;
y += 16; y += 16;
@@ -39,8 +38,7 @@ netherold_hidden(void *data, RenderState *state, int x, int y, int z) {
missing_section = 0; missing_section = 0;
} }
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 0;
} }
y++; y++;
@@ -49,7 +47,8 @@ netherold_hidden(void *data, RenderState *state, int x, int y, int z) {
} }
RenderPrimitiveInterface primitive_nether_old = { RenderPrimitiveInterface primitive_nether_old = {
"netherold", 0, "netherold",
0,
NULL, NULL,
NULL, NULL,
NULL, NULL,

View File

@@ -28,7 +28,8 @@ no_fluids_hidden(void *data, RenderState *state, int x, int y, int z) {
} }
RenderPrimitiveInterface primitive_no_fluids = { RenderPrimitiveInterface primitive_no_fluids = {
"no-fluids", 0, "no-fluids",
0,
no_fluids_start, no_fluids_start,
NULL, NULL,
NULL, NULL,

View File

@@ -15,8 +15,8 @@
* with the Overviewer. If not, see <http://www.gnu.org/licenses/>. * with the Overviewer. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "overlay.h"
#include "biomes.h" #include "biomes.h"
#include "overlay.h"
typedef struct { typedef struct {
/* inherits from overlay */ /* inherits from overlay */
@@ -73,8 +73,7 @@ static struct BiomeColor default_biomes[] = {
{39, 255, 100, 100}, /* Mesa Plateau */ {39, 255, 100, 100}, /* Mesa Plateau */
/* end of list marker */ /* end of list marker */
{255, 0, 0, 0} {255, 0, 0, 0}};
};
static void get_color(void* data, RenderState* state, static void get_color(void* data, RenderState* state,
unsigned char* r, unsigned char* g, unsigned char* b, unsigned char* a) { unsigned char* r, unsigned char* g, unsigned char* b, unsigned char* a) {

View File

@@ -15,8 +15,8 @@
* with the Overviewer. If not, see <http://www.gnu.org/licenses/>. * with the Overviewer. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "overlay.h"
#include "../mc_id.h" #include "../mc_id.h"
#include "overlay.h"
typedef struct { typedef struct {
/* inherits from overlay */ /* inherits from overlay */
@@ -45,8 +45,7 @@ static struct MineralColor default_minerals[] = {
{block_coal_ore, 54, 54, 54}, {block_coal_ore, 54, 54, 54},
/* end of list marker */ /* end of list marker */
{0, 0, 0, 0} {0, 0, 0, 0}};
};
static void get_color(void* data, RenderState* state, static void get_color(void* data, RenderState* state,
unsigned char* r, unsigned char* g, unsigned char* b, unsigned char* a) { unsigned char* r, unsigned char* g, unsigned char* b, unsigned char* a) {

View File

@@ -15,8 +15,8 @@
* with the Overviewer. If not, see <http://www.gnu.org/licenses/>. * with the Overviewer. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "overlay.h"
#include <math.h> #include <math.h>
#include "overlay.h"
typedef struct { typedef struct {
/* inherits from overlay */ /* inherits from overlay */
@@ -66,7 +66,8 @@ static int is_slime(long long map_seed, int chunkx, int chunkz) {
(long long)(chunkx * chunkx * 0x4c1906) + (long long)(chunkx * chunkx * 0x4c1906) +
(long long)(chunkx * 0x5ac0db) + (long long)(chunkx * 0x5ac0db) +
(long long)(chunkz * chunkz * 0x4307a7LL) + (long long)(chunkz * chunkz * 0x4307a7LL) +
(long long)(chunkz * 0x5f24f)) ^ 0x3ad8025f); (long long)(chunkz * 0x5f24f)) ^
0x3ad8025f);
return (random_next_int(&seed, 10) == 0); return (random_next_int(&seed, 10) == 0);
} }

View File

@@ -15,8 +15,8 @@
* with the Overviewer. If not, see <http://www.gnu.org/licenses/>. * with the Overviewer. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "overlay.h"
#include <math.h> #include <math.h>
#include "overlay.h"
typedef struct { typedef struct {
/* inherits from overlay */ /* inherits from overlay */

View File

@@ -15,10 +15,11 @@
* with the Overviewer. If not, see <http://www.gnu.org/licenses/>. * with the Overviewer. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "overlay.h"
#include "../mc_id.h" #include "../mc_id.h"
#include "overlay.h"
typedef enum { false, true } bool; typedef enum { false,
true } bool;
typedef struct { typedef struct {
/* inherits from overlay */ /* inherits from overlay */
@@ -240,4 +241,3 @@ RenderPrimitiveInterface primitive_overlay_structure = {
NULL, NULL,
overlay_draw, overlay_draw,
}; };

View File

@@ -78,8 +78,7 @@ overlay_finish(void *data, RenderState *state) {
Py_DECREF(self->white_color); Py_DECREF(self->white_color);
} }
void void overlay_draw(void* data, RenderState* state, PyObject* src, PyObject* mask, PyObject* mask_light) {
overlay_draw(void *data, RenderState *state, PyObject *src, PyObject *mask, PyObject *mask_light) {
RenderPrimitiveOverlay* self = (RenderPrimitiveOverlay*)data; RenderPrimitiveOverlay* self = (RenderPrimitiveOverlay*)data;
unsigned char r, g, b, a; unsigned char r, g, b, a;
unsigned short top_block; unsigned short top_block;

View File

@@ -15,11 +15,11 @@
* with the Overviewer. If not, see <http://www.gnu.org/licenses/>. * 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 <math.h>
#include "../block_class.h"
#include "../mc_id.h"
#include "../overviewer.h"
#include "lighting.h"
typedef struct { typedef struct {
/* inherits from lighting */ /* inherits from lighting */
@@ -72,59 +72,37 @@ static struct SmoothLightingFace lighting_rules[] = {
/* top */ /* top */
{0, 1, 0, { {0, 1, 0, {
{0, 6, {0, 6, -1, 0, 0, 0, 0, -1},
-1, 0, 0, {12, 0, 1, 0, 0, 0, 0, -1},
0, 0, -1}, {24, 6, 1, 0, 0, 0, 0, 1},
{12, 0, {12, 12, -1, 0, 0, 0, 0, 1},
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}, top_touchups,
6},
/* left */ /* left */
{-1, 0, 0, { {-1, 0, 0, {
{0, 18, {0, 18, 0, 0, -1, 0, -1, 0},
0, 0, -1, {0, 6, 0, 0, -1, 0, 1, 0},
0, -1, 0}, {12, 12, 0, 0, 1, 0, 1, 0},
{0, 6, {12, 24, 0, 0, 1, 0, -1, 0},
0, 0, -1,
0, 1, 0},
{12, 12,
0, 0, 1,
0, 1, 0},
{12, 24,
0, 0, 1,
0, -1, 0},
}, },
NULL, 0}, NULL,
0},
/* right */ /* right */
{0, 0, 1, { {0, 0, 1, {
{24, 6, {24, 6, 1, 0, 0, 0, 1, 0},
1, 0, 0, {12, 12, -1, 0, 0, 0, 1, 0},
0, 1, 0}, {12, 24, -1, 0, 0, 0, -1, 0},
{12, 12, {24, 18, 1, 0, 0, 0, -1, 0},
-1, 0, 0,
0, 1, 0},
{12, 24,
-1, 0, 0,
0, -1, 0},
{24, 18,
1, 0, 0,
0, -1, 0},
}, },
NULL, 0}, NULL,
0},
}; };
/* helpers for indexing the rule list */ /* helpers for indexing the rule list */
enum enum {
{
FACE_TOP = 0, FACE_TOP = 0,
FACE_LEFT = 1, FACE_LEFT = 1,
FACE_RIGHT = 2, FACE_RIGHT = 2,
@@ -149,30 +127,37 @@ do_shading_with_rule(RenderPrimitiveSmoothLighting *self, RenderState *state, st
return; return;
/* calculate the lighting colors for each point */ /* 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 char r, g, b;
unsigned int rgather = 0, ggather = 0, bgather = 0; unsigned int rgather = 0, ggather = 0, bgather = 0;
get_lighting_color(lighting, state, cx, cy, cz, get_lighting_color(lighting, state, cx, cy, cz,
&r, &g, &b); &r, &g, &b);
rgather += r; ggather += g; bgather += b; rgather += r;
ggather += g;
bgather += b;
get_lighting_color(lighting, state, 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); &r, &g, &b);
rgather += r; ggather += g; bgather += b; rgather += r;
ggather += g;
bgather += b;
get_lighting_color(lighting, state, 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); &r, &g, &b);
rgather += r; ggather += g; bgather += b; rgather += r;
ggather += g;
bgather += b;
/* FIXME special far corner handling */ /* FIXME special far corner handling */
get_lighting_color(lighting, state, 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); &r, &g, &b);
rgather += r; ggather += g; bgather += b; rgather += r;
ggather += g;
bgather += b;
rgather += (255 * 4 - rgather) * comp_shade_strength; rgather += (255 * 4 - rgather) * comp_shade_strength;
ggather += (255 * 4 - ggather) * comp_shade_strength; ggather += (255 * 4 - ggather) * comp_shade_strength;
@@ -220,10 +205,7 @@ smooth_lighting_draw(void *data, RenderState *state, PyObject *src, PyObject *ma
/* special case for leaves, water 8, water 9, ice 79 /* special case for leaves, water 8, water 9, ice 79
-- these are also smooth-lit! */ -- these are also smooth-lit! */
if (!block_class_is_subset(state->block, (mc_block_t[]){ if (!block_class_is_subset(state->block, (mc_block_t[]){block_leaves, block_flowing_water, block_water, block_ice}, 4) && is_transparent(state->block)) {
block_leaves,block_flowing_water,block_water,block_ice
}, 4) && is_transparent(state->block))
{
/* transparent blocks are rendered as usual, with flat lighting */ /* transparent blocks are rendered as usual, with flat lighting */
primitive_lighting.draw(data, state, src, mask, mask_light); primitive_lighting.draw(data, state, src, mask, mask_light);
return; return;
@@ -232,8 +214,7 @@ smooth_lighting_draw(void *data, RenderState *state, PyObject *src, PyObject *ma
/* non-transparent blocks get the special smooth treatment */ /* non-transparent blocks get the special smooth treatment */
/* 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 = 0;
if (!(state->block_pdata & (1 << 1))) if (!(state->block_pdata & (1 << 1)))
@@ -251,7 +232,8 @@ smooth_lighting_draw(void *data, RenderState *state, PyObject *src, PyObject *ma
} }
RenderPrimitiveInterface primitive_smooth_lighting = { RenderPrimitiveInterface primitive_smooth_lighting = {
"smooth-lighting", sizeof(RenderPrimitiveSmoothLighting), "smooth-lighting",
sizeof(RenderPrimitiveSmoothLighting),
smooth_lighting_start, smooth_lighting_start,
smooth_lighting_finish, smooth_lighting_finish,
NULL, NULL,

View File

@@ -15,9 +15,9 @@
* with the Overviewer. If not, see <http://www.gnu.org/licenses/>. * with the Overviewer. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "overviewer.h"
#include <string.h>
#include <stdarg.h> #include <stdarg.h>
#include <string.h>
#include "overviewer.h"
/* this file defines render_primitives, /* this file defines render_primitives,
a list of all render primitives, ending in NULL a list of all render primitives, ending in NULL