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:
parent
676bf32af9
commit
8162f3f877
|
@ -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
|
||||
...
|
|
@ -59,8 +59,8 @@
|
|||
|
||||
#include <math.h>
|
||||
|
||||
#define CEIL(v) (int) ceil(v)
|
||||
#define FLOOR(v) ((v) >= 0.0 ? (int) (v) : (int) floor(v))
|
||||
#define CEIL(v) (int)ceil(v)
|
||||
#define FLOOR(v) ((v) >= 0.0 ? (int)(v) : (int)floor(v))
|
||||
|
||||
#define INK8(ink) (*(UINT8*)ink)
|
||||
#define INK32(ink) (*(INT32*)ink)
|
||||
|
@ -78,27 +78,24 @@ typedef struct {
|
|||
} Edge;
|
||||
|
||||
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)
|
||||
im->image8[y][x] = (UINT8) ink;
|
||||
im->image8[y][x] = (UINT8)ink;
|
||||
}
|
||||
|
||||
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)
|
||||
im->image32[y][x] = ink;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (x >= 0 && x < im->xsize && y >= 0 && y < im->ysize) {
|
||||
UINT8* out = (UINT8*) im->image[y]+x*4;
|
||||
UINT8* in = (UINT8*) &ink;
|
||||
UINT8* out = (UINT8*)im->image[y] + x * 4;
|
||||
UINT8* in = (UINT8*)&ink;
|
||||
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[2] = OV_BLEND(in[3], out[2], in[2], tmp1, tmp2);
|
||||
|
@ -106,8 +103,7 @@ point32rgba(Imaging im, int x, int y, int ink)
|
|||
}
|
||||
|
||||
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;
|
||||
|
||||
if (y0 >= 0 && y0 < im->ysize) {
|
||||
|
@ -120,15 +116,14 @@ hline8(Imaging im, int x0, int y0, int x1, int ink)
|
|||
if (x1 < 0)
|
||||
return;
|
||||
else if (x1 >= im->xsize)
|
||||
x1 = im->xsize-1;
|
||||
x1 = im->xsize - 1;
|
||||
if (x0 <= x1)
|
||||
memset(im->image8[y0] + x0, (UINT8) ink, x1 - x0 + 1);
|
||||
memset(im->image8[y0] + x0, (UINT8)ink, x1 - x0 + 1);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
INT32* p;
|
||||
|
||||
|
@ -142,7 +137,7 @@ hline32(Imaging im, int x0, int y0, int x1, int ink)
|
|||
if (x1 < 0)
|
||||
return;
|
||||
else if (x1 >= im->xsize)
|
||||
x1 = im->xsize-1;
|
||||
x1 = im->xsize - 1;
|
||||
p = im->image32[y0];
|
||||
while (x0 <= x1)
|
||||
p[x0++] = ink;
|
||||
|
@ -150,8 +145,7 @@ hline32(Imaging im, int x0, int y0, int x1, int ink)
|
|||
}
|
||||
|
||||
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;
|
||||
unsigned int tmp1, tmp2;
|
||||
|
||||
|
@ -165,34 +159,34 @@ hline32rgba(Imaging im, int x0, int y0, int x1, int ink)
|
|||
if (x1 < 0)
|
||||
return;
|
||||
else if (x1 >= im->xsize)
|
||||
x1 = im->xsize-1;
|
||||
x1 = im->xsize - 1;
|
||||
if (x0 <= x1) {
|
||||
UINT8* out = (UINT8*) im->image[y0]+x0*4;
|
||||
UINT8* in = (UINT8*) &ink;
|
||||
UINT8* out = (UINT8*)im->image[y0] + x0 * 4;
|
||||
UINT8* in = (UINT8*)&ink;
|
||||
while (x0 <= x1) {
|
||||
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[2] = OV_BLEND(in[3], out[2], in[2], tmp1, tmp2);
|
||||
x0++; out += 4;
|
||||
x0++;
|
||||
out += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 dx, dy;
|
||||
int xs, ys;
|
||||
|
||||
/* normalize coordinates */
|
||||
dx = x1-x0;
|
||||
dx = x1 - x0;
|
||||
if (dx < 0)
|
||||
dx = -dx, xs = -1;
|
||||
else
|
||||
xs = 1;
|
||||
dy = y1-y0;
|
||||
dy = y1 - y0;
|
||||
if (dy < 0)
|
||||
dy = -dy, ys = -1;
|
||||
else
|
||||
|
@ -251,24 +245,22 @@ line8(Imaging im, int x0, int y0, int x1, int y1, int ink)
|
|||
e += dx;
|
||||
y0 += ys;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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 dx, dy;
|
||||
int xs, ys;
|
||||
|
||||
/* normalize coordinates */
|
||||
dx = x1-x0;
|
||||
dx = x1 - x0;
|
||||
if (dx < 0)
|
||||
dx = -dx, xs = -1;
|
||||
else
|
||||
xs = 1;
|
||||
dy = y1-y0;
|
||||
dy = y1 - y0;
|
||||
if (dy < 0)
|
||||
dy = -dy, ys = -1;
|
||||
else
|
||||
|
@ -327,24 +319,22 @@ line32(Imaging im, int x0, int y0, int x1, int y1, int ink)
|
|||
e += dx;
|
||||
y0 += ys;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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 dx, dy;
|
||||
int xs, ys;
|
||||
|
||||
/* normalize coordinates */
|
||||
dx = x1-x0;
|
||||
dx = x1 - x0;
|
||||
if (dx < 0)
|
||||
dx = -dx, xs = -1;
|
||||
else
|
||||
xs = 1;
|
||||
dy = y1-y0;
|
||||
dy = y1 - y0;
|
||||
if (dy < 0)
|
||||
dy = -dy, ys = -1;
|
||||
else
|
||||
|
@ -403,13 +393,11 @@ line32rgba(Imaging im, int x0, int y0, int x1, int y1, int ink)
|
|||
e += dx;
|
||||
y0 += ys;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
x_cmp(const void *x0, const void *x1)
|
||||
{
|
||||
x_cmp(const void* x0, const void* x1) {
|
||||
float diff = *((float*)x0) - *((float*)x1);
|
||||
if (diff < 0)
|
||||
return -1;
|
||||
|
@ -420,10 +408,9 @@ x_cmp(const void *x0, const void *x1)
|
|||
}
|
||||
|
||||
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;
|
||||
float *xx;
|
||||
float* xx;
|
||||
int ymin, ymax;
|
||||
float y;
|
||||
|
||||
|
@ -435,14 +422,16 @@ polygon8(Imaging im, int n, Edge *e, int ink, int eofill)
|
|||
ymin = e[0].ymin;
|
||||
ymax = e[0].ymax;
|
||||
for (i = 1; i < n; i++) {
|
||||
if (e[i].ymin < ymin) ymin = e[i].ymin;
|
||||
if (e[i].ymax > ymax) ymax = e[i].ymax;
|
||||
if (e[i].ymin < ymin)
|
||||
ymin = e[i].ymin;
|
||||
if (e[i].ymax > ymax)
|
||||
ymax = e[i].ymax;
|
||||
}
|
||||
|
||||
if (ymin < 0)
|
||||
ymin = 0;
|
||||
if (ymax >= im->ysize)
|
||||
ymax = im->ysize-1;
|
||||
ymax = im->ysize - 1;
|
||||
|
||||
/* Process polygon edges */
|
||||
|
||||
|
@ -450,24 +439,24 @@ polygon8(Imaging im, int n, Edge *e, int ink, int eofill)
|
|||
if (!xx)
|
||||
return -1;
|
||||
|
||||
for (;ymin <= ymax; ymin++) {
|
||||
y = ymin+0.5F;
|
||||
for (; ymin <= ymax; ymin++) {
|
||||
y = ymin + 0.5F;
|
||||
for (i = j = 0; i < n; i++)
|
||||
if (y >= e[i].ymin && y <= e[i].ymax) {
|
||||
if (e[i].d == 0)
|
||||
hline8(im, e[i].xmin, ymin, e[i].xmax, ink);
|
||||
else
|
||||
xx[j++] = (y-e[i].y0) * e[i].dx + e[i].x0;
|
||||
xx[j++] = (y - e[i].y0) * e[i].dx + e[i].x0;
|
||||
}
|
||||
if (j == 2) {
|
||||
if (xx[0] < xx[1])
|
||||
hline8(im, CEIL(xx[0]-0.5), ymin, FLOOR(xx[1]+0.5), ink);
|
||||
hline8(im, CEIL(xx[0] - 0.5), ymin, FLOOR(xx[1] + 0.5), ink);
|
||||
else
|
||||
hline8(im, CEIL(xx[1]-0.5), ymin, FLOOR(xx[0]+0.5), ink);
|
||||
hline8(im, CEIL(xx[1] - 0.5), ymin, FLOOR(xx[0] + 0.5), ink);
|
||||
} else {
|
||||
qsort(xx, j, sizeof(float), x_cmp);
|
||||
for (i = 0; i < j-1 ; i += 2)
|
||||
hline8(im, CEIL(xx[i]-0.5), ymin, FLOOR(xx[i+1]+0.5), ink);
|
||||
for (i = 0; i < j - 1; i += 2)
|
||||
hline8(im, CEIL(xx[i] - 0.5), ymin, FLOOR(xx[i + 1] + 0.5), ink);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -477,10 +466,9 @@ polygon8(Imaging im, int n, Edge *e, int ink, int eofill)
|
|||
}
|
||||
|
||||
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;
|
||||
float *xx;
|
||||
float* xx;
|
||||
int ymin, ymax;
|
||||
float y;
|
||||
|
||||
|
@ -492,14 +480,16 @@ polygon32(Imaging im, int n, Edge *e, int ink, int eofill)
|
|||
ymin = e[0].ymin;
|
||||
ymax = e[0].ymax;
|
||||
for (i = 1; i < n; i++) {
|
||||
if (e[i].ymin < ymin) ymin = e[i].ymin;
|
||||
if (e[i].ymax > ymax) ymax = e[i].ymax;
|
||||
if (e[i].ymin < ymin)
|
||||
ymin = e[i].ymin;
|
||||
if (e[i].ymax > ymax)
|
||||
ymax = e[i].ymax;
|
||||
}
|
||||
|
||||
if (ymin < 0)
|
||||
ymin = 0;
|
||||
if (ymax >= im->ysize)
|
||||
ymax = im->ysize-1;
|
||||
ymax = im->ysize - 1;
|
||||
|
||||
/* Process polygon edges */
|
||||
|
||||
|
@ -507,25 +497,25 @@ polygon32(Imaging im, int n, Edge *e, int ink, int eofill)
|
|||
if (!xx)
|
||||
return -1;
|
||||
|
||||
for (;ymin <= ymax; ymin++) {
|
||||
y = ymin+0.5F;
|
||||
for (; ymin <= ymax; ymin++) {
|
||||
y = ymin + 0.5F;
|
||||
for (i = j = 0; i < n; i++) {
|
||||
if (y >= e[i].ymin && y <= e[i].ymax) {
|
||||
if (e[i].d == 0)
|
||||
hline32(im, e[i].xmin, ymin, e[i].xmax, ink);
|
||||
else
|
||||
xx[j++] = (y-e[i].y0) * e[i].dx + e[i].x0;
|
||||
xx[j++] = (y - e[i].y0) * e[i].dx + e[i].x0;
|
||||
}
|
||||
}
|
||||
if (j == 2) {
|
||||
if (xx[0] < xx[1])
|
||||
hline32(im, CEIL(xx[0]-0.5), ymin, FLOOR(xx[1]+0.5), ink);
|
||||
hline32(im, CEIL(xx[0] - 0.5), ymin, FLOOR(xx[1] + 0.5), ink);
|
||||
else
|
||||
hline32(im, CEIL(xx[1]-0.5), ymin, FLOOR(xx[0]+0.5), ink);
|
||||
hline32(im, CEIL(xx[1] - 0.5), ymin, FLOOR(xx[0] + 0.5), ink);
|
||||
} else {
|
||||
qsort(xx, j, sizeof(float), x_cmp);
|
||||
for (i = 0; i < j-1 ; i += 2)
|
||||
hline32(im, CEIL(xx[i]-0.5), ymin, FLOOR(xx[i+1]+0.5), ink);
|
||||
for (i = 0; i < j - 1; i += 2)
|
||||
hline32(im, CEIL(xx[i] - 0.5), ymin, FLOOR(xx[i + 1] + 0.5), ink);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -535,10 +525,9 @@ polygon32(Imaging im, int n, Edge *e, int ink, int eofill)
|
|||
}
|
||||
|
||||
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;
|
||||
float *xx;
|
||||
float* xx;
|
||||
int ymin, ymax;
|
||||
float y;
|
||||
|
||||
|
@ -550,14 +539,16 @@ polygon32rgba(Imaging im, int n, Edge *e, int ink, int eofill)
|
|||
ymin = e[0].ymin;
|
||||
ymax = e[0].ymax;
|
||||
for (i = 1; i < n; i++) {
|
||||
if (e[i].ymin < ymin) ymin = e[i].ymin;
|
||||
if (e[i].ymax > ymax) ymax = e[i].ymax;
|
||||
if (e[i].ymin < ymin)
|
||||
ymin = e[i].ymin;
|
||||
if (e[i].ymax > ymax)
|
||||
ymax = e[i].ymax;
|
||||
}
|
||||
|
||||
if (ymin < 0)
|
||||
ymin = 0;
|
||||
if (ymax >= im->ysize)
|
||||
ymax = im->ysize-1;
|
||||
ymax = im->ysize - 1;
|
||||
|
||||
/* Process polygon edges */
|
||||
|
||||
|
@ -565,25 +556,25 @@ polygon32rgba(Imaging im, int n, Edge *e, int ink, int eofill)
|
|||
if (!xx)
|
||||
return -1;
|
||||
|
||||
for (;ymin <= ymax; ymin++) {
|
||||
y = ymin+0.5F;
|
||||
for (; ymin <= ymax; ymin++) {
|
||||
y = ymin + 0.5F;
|
||||
for (i = j = 0; i < n; i++) {
|
||||
if (y >= e[i].ymin && y <= e[i].ymax) {
|
||||
if (e[i].d == 0)
|
||||
hline32rgba(im, e[i].xmin, ymin, e[i].xmax, ink);
|
||||
else
|
||||
xx[j++] = (y-e[i].y0) * e[i].dx + e[i].x0;
|
||||
xx[j++] = (y - e[i].y0) * e[i].dx + e[i].x0;
|
||||
}
|
||||
}
|
||||
if (j == 2) {
|
||||
if (xx[0] < xx[1])
|
||||
hline32rgba(im, CEIL(xx[0]-0.5), ymin, FLOOR(xx[1]+0.5), ink);
|
||||
hline32rgba(im, CEIL(xx[0] - 0.5), ymin, FLOOR(xx[1] + 0.5), ink);
|
||||
else
|
||||
hline32rgba(im, CEIL(xx[1]-0.5), ymin, FLOOR(xx[0]+0.5), ink);
|
||||
hline32rgba(im, CEIL(xx[1] - 0.5), ymin, FLOOR(xx[0] + 0.5), ink);
|
||||
} else {
|
||||
qsort(xx, j, sizeof(float), x_cmp);
|
||||
for (i = 0; i < j-1 ; i += 2)
|
||||
hline32rgba(im, CEIL(xx[i]-0.5), ymin, FLOOR(xx[i+1]+0.5), ink);
|
||||
for (i = 0; i < j - 1; i += 2)
|
||||
hline32rgba(im, CEIL(xx[i] - 0.5), ymin, FLOOR(xx[i + 1] + 0.5), ink);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -593,8 +584,7 @@ polygon32rgba(Imaging im, int n, Edge *e, int ink, int eofill)
|
|||
}
|
||||
|
||||
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); */
|
||||
|
||||
if (x0 <= x1)
|
||||
|
@ -611,7 +601,7 @@ add_edge(Edge *e, int x0, int y0, int x1, int y1)
|
|||
e->d = 0;
|
||||
e->dx = 0.0;
|
||||
} else {
|
||||
e->dx = ((float)(x1-x0)) / (y1-y0);
|
||||
e->dx = ((float)(x1 - x0)) / (y1 - y0);
|
||||
if (y0 == e->ymin)
|
||||
e->d = 1;
|
||||
else
|
||||
|
@ -626,29 +616,27 @@ typedef struct {
|
|||
void (*point)(Imaging im, int x, int y, int ink);
|
||||
void (*hline)(Imaging im, int x0, int y0, int x1, int ink);
|
||||
void (*line)(Imaging im, int x0, int y0, int x1, int y1, int ink);
|
||||
int (*polygon)(Imaging im, int n, Edge *e, int ink, int eofill);
|
||||
int (*polygon)(Imaging im, int n, Edge* e, int ink, int eofill);
|
||||
} DRAW;
|
||||
|
||||
DRAW draw8 = { point8, hline8, line8, polygon8 };
|
||||
DRAW draw32 = { point32, hline32, line32, polygon32 };
|
||||
DRAW draw32rgba = { point32rgba, hline32rgba, line32rgba, polygon32rgba };
|
||||
DRAW draw8 = {point8, hline8, line8, polygon8};
|
||||
DRAW draw32 = {point32, hline32, line32, polygon32};
|
||||
DRAW draw32rgba = {point32rgba, hline32rgba, line32rgba, polygon32rgba};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* Interface */
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
#define DRAWINIT()\
|
||||
if (im->image8) {\
|
||||
draw = &draw8;\
|
||||
ink = INK8(ink_);\
|
||||
} else {\
|
||||
#define DRAWINIT() \
|
||||
if (im->image8) { \
|
||||
draw = &draw8; \
|
||||
ink = INK8(ink_); \
|
||||
} else { \
|
||||
draw = (op) ? &draw32rgba : &draw32; \
|
||||
ink = INK32(ink_);\
|
||||
ink = INK32(ink_); \
|
||||
}
|
||||
|
||||
int
|
||||
ImagingDrawPoint(Imaging im, int x0, int y0, const void* ink_, int op)
|
||||
{
|
||||
int ImagingDrawPoint(Imaging im, int x0, int y0, const void* ink_, int op) {
|
||||
DRAW* draw;
|
||||
INT32 ink;
|
||||
|
||||
|
@ -659,10 +647,8 @@ ImagingDrawPoint(Imaging im, int x0, int y0, const void* ink_, int op)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
ImagingDrawLine(Imaging im, int x0, int y0, int x1, int y1, const void* ink_,
|
||||
int op)
|
||||
{
|
||||
int ImagingDrawLine(Imaging im, int x0, int y0, int x1, int y1, const void* ink_,
|
||||
int op) {
|
||||
DRAW* draw;
|
||||
INT32 ink;
|
||||
|
||||
|
@ -673,10 +659,8 @@ ImagingDrawLine(Imaging im, int x0, int y0, int x1, int y1, const void* ink_,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
ImagingDrawWideLine(Imaging im, int x0, int y0, int x1, int y1,
|
||||
const void* ink_, int width, int op)
|
||||
{
|
||||
int ImagingDrawWideLine(Imaging im, int x0, int y0, int x1, int y1,
|
||||
const void* ink_, int width, int op) {
|
||||
DRAW* draw;
|
||||
INT32 ink;
|
||||
|
||||
|
@ -692,31 +676,29 @@ ImagingDrawWideLine(Imaging im, int x0, int y0, int x1, int y1,
|
|||
return 0;
|
||||
}
|
||||
|
||||
dx = x1-x0;
|
||||
dy = y1-y0;
|
||||
dx = x1 - x0;
|
||||
dy = y1 - y0;
|
||||
|
||||
if (dx == 0 && dy == 0) {
|
||||
draw->point(im, x0, y0, ink);
|
||||
return 0;
|
||||
}
|
||||
|
||||
d = width / sqrt((float) (dx*dx + dy*dy)) / 2.0;
|
||||
d = width / sqrt((float)(dx * dx + dy * dy)) / 2.0;
|
||||
|
||||
dx = (int) floor(d * (y1-y0) + 0.5);
|
||||
dy = (int) floor(d * (x1-x0) + 0.5);
|
||||
dx = (int)floor(d * (y1 - y0) + 0.5);
|
||||
dy = (int)floor(d * (x1 - x0) + 0.5);
|
||||
|
||||
add_edge(e+0, x0 - dx, y0 + dy, x1 - dx, y1 + dy);
|
||||
add_edge(e+1, x1 - dx, y1 + dy, x1 + dx, y1 - dy);
|
||||
add_edge(e+2, x1 + dx, y1 - dy, x0 + dx, y0 - dy);
|
||||
add_edge(e+3, x0 + dx, y0 - dy, x0 - dx, y0 + dy);
|
||||
add_edge(e + 0, x0 - dx, y0 + dy, x1 - dx, y1 + dy);
|
||||
add_edge(e + 1, x1 - dx, y1 + dy, x1 + dx, y1 - dy);
|
||||
add_edge(e + 2, x1 + dx, y1 - dy, x0 + dx, y0 - dy);
|
||||
add_edge(e + 3, x0 + dx, y0 - dy, x0 - dx, y0 + dy);
|
||||
|
||||
draw->polygon(im, 4, e, ink, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* standard shapes */
|
||||
|
||||
|
@ -724,7 +706,6 @@ ImagingDrawWideLine(Imaging im, int x0, int y0, int x1, int y1,
|
|||
#define CHORD 1
|
||||
#define PIESLICE 2
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
/* experimental level 2 ("arrow") graphics stuff. this implements
|
||||
|
@ -741,17 +722,12 @@ struct ImagingOutlineInstance {
|
|||
float x, y;
|
||||
|
||||
int count;
|
||||
Edge *edges;
|
||||
Edge* edges;
|
||||
|
||||
int size;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
void
|
||||
ImagingOutlineDelete(ImagingOutline outline)
|
||||
{
|
||||
void ImagingOutlineDelete(ImagingOutline outline) {
|
||||
if (!outline)
|
||||
return;
|
||||
|
||||
|
@ -761,10 +737,8 @@ ImagingOutlineDelete(ImagingOutline outline)
|
|||
free(outline);
|
||||
}
|
||||
|
||||
|
||||
static Edge*
|
||||
allocate(ImagingOutline outline, int extra)
|
||||
{
|
||||
allocate(ImagingOutline outline, int extra) {
|
||||
Edge* e;
|
||||
|
||||
if (outline->count + extra > outline->size) {
|
||||
|
@ -786,25 +760,21 @@ allocate(ImagingOutline outline, int extra)
|
|||
return e;
|
||||
}
|
||||
|
||||
int
|
||||
ImagingOutlineMove(ImagingOutline outline, float x0, float y0)
|
||||
{
|
||||
int ImagingOutlineMove(ImagingOutline outline, float x0, float y0) {
|
||||
outline->x = outline->x0 = x0;
|
||||
outline->y = outline->y0 = y0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
ImagingOutlineLine(ImagingOutline outline, float x1, float y1)
|
||||
{
|
||||
int ImagingOutlineLine(ImagingOutline outline, float x1, float y1) {
|
||||
Edge* e;
|
||||
|
||||
e = allocate(outline, 1);
|
||||
if (!e)
|
||||
return -1; /* out of memory */
|
||||
|
||||
add_edge(e, (int) outline->x, (int) outline->y, (int) x1, (int) y1);
|
||||
add_edge(e, (int)outline->x, (int)outline->y, (int)x1, (int)y1);
|
||||
|
||||
outline->x = x1;
|
||||
outline->y = y1;
|
||||
|
@ -812,10 +782,8 @@ ImagingOutlineLine(ImagingOutline outline, float x1, float y1)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
ImagingOutlineCurve(ImagingOutline outline, float x1, float y1,
|
||||
float x2, float y2, float x3, float y3)
|
||||
{
|
||||
int ImagingOutlineCurve(ImagingOutline outline, float x1, float y1,
|
||||
float x2, float y2, float x3, float y3) {
|
||||
Edge* e;
|
||||
int i;
|
||||
float xo, yo;
|
||||
|
@ -833,21 +801,20 @@ ImagingOutlineCurve(ImagingOutline outline, float x1, float y1,
|
|||
|
||||
for (i = 1; i <= STEPS; i++) {
|
||||
|
||||
float t = ((float) i) / STEPS;
|
||||
float t2 = t*t;
|
||||
float t3 = t2*t;
|
||||
float t = ((float)i) / STEPS;
|
||||
float t2 = t * t;
|
||||
float t3 = t2 * t;
|
||||
|
||||
float u = 1.0F - t;
|
||||
float u2 = u*u;
|
||||
float u3 = u2*u;
|
||||
float u2 = u * u;
|
||||
float u3 = u2 * u;
|
||||
|
||||
float x = outline->x*u3 + 3*(x1*t*u2 + x2*t2*u) + x3*t3 + 0.5;
|
||||
float y = outline->y*u3 + 3*(y1*t*u2 + y2*t2*u) + y3*t3 + 0.5;
|
||||
float x = outline->x * u3 + 3 * (x1 * t * u2 + x2 * t2 * u) + x3 * t3 + 0.5;
|
||||
float y = outline->y * u3 + 3 * (y1 * t * u2 + y2 * t2 * u) + y3 * t3 + 0.5;
|
||||
|
||||
add_edge(e++, xo, yo, (int) x, (int) y);
|
||||
add_edge(e++, xo, yo, (int)x, (int)y);
|
||||
|
||||
xo = x, yo = y;
|
||||
|
||||
}
|
||||
|
||||
outline->x = xo;
|
||||
|
@ -856,33 +823,26 @@ ImagingOutlineCurve(ImagingOutline outline, float x1, float y1,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
ImagingOutlineCurve2(ImagingOutline outline, float cx, float cy,
|
||||
float x3, float y3)
|
||||
{
|
||||
int ImagingOutlineCurve2(ImagingOutline outline, float cx, float cy,
|
||||
float x3, float y3) {
|
||||
/* add bezier curve based on three control points (as
|
||||
in the Flash file format) */
|
||||
|
||||
return ImagingOutlineCurve(
|
||||
outline,
|
||||
(outline->x + cx + cx)/3, (outline->y + cy + cy)/3,
|
||||
(cx + cx + x3)/3, (cy + cy + y3)/3,
|
||||
(outline->x + cx + cx) / 3, (outline->y + cy + cy) / 3,
|
||||
(cx + cx + x3) / 3, (cy + cy + y3) / 3,
|
||||
x3, y3);
|
||||
}
|
||||
|
||||
int
|
||||
ImagingOutlineClose(ImagingOutline outline)
|
||||
{
|
||||
int ImagingOutlineClose(ImagingOutline outline) {
|
||||
if (outline->x == outline->x0 && outline->y == outline->y0)
|
||||
return 0;
|
||||
return ImagingOutlineLine(outline, outline->x0, outline->y0);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
ImagingDrawOutline(Imaging im, ImagingOutline outline, const void* ink_,
|
||||
int fill, int op)
|
||||
{
|
||||
int ImagingDrawOutline(Imaging im, ImagingOutline outline, const void* ink_,
|
||||
int fill, int op) {
|
||||
DRAW* draw;
|
||||
INT32 ink;
|
||||
|
||||
|
|
|
@ -25,17 +25,15 @@
|
|||
bool block_class_is_subset(
|
||||
mc_block_t block,
|
||||
const mc_block_t block_class[],
|
||||
size_t block_class_len
|
||||
) {
|
||||
size_t block_class_len) {
|
||||
size_t i = 0;
|
||||
|
||||
#ifdef __SSE2__
|
||||
for (; i / 8 < block_class_len / 8; i += 8) {
|
||||
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_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)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -44,10 +42,9 @@ bool block_class_is_subset(
|
|||
#ifdef __MMX__
|
||||
for (; i / 4 < block_class_len / 4; i += 4) {
|
||||
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_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)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -61,7 +58,6 @@ bool block_class_is_subset(
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
const mc_block_t block_class_stair[] = {
|
||||
block_oak_stairs,
|
||||
block_stone_stairs,
|
||||
|
@ -79,8 +75,7 @@ const mc_block_t block_class_stair[] = {
|
|||
block_purpur_stairs,
|
||||
block_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 mc_block_t block_class_door[] = {
|
||||
|
@ -90,8 +85,7 @@ const mc_block_t block_class_door[] = {
|
|||
block_birch_door,
|
||||
block_jungle_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 mc_block_t block_class_fence[] = {
|
||||
|
@ -101,8 +95,7 @@ const mc_block_t block_class_fence[] = {
|
|||
block_birch_fence,
|
||||
block_jungle_fence,
|
||||
block_dark_oak_fence,
|
||||
block_acacia_fence
|
||||
};
|
||||
block_acacia_fence};
|
||||
const size_t block_class_fence_len = COUNT_OF(block_class_fence);
|
||||
|
||||
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_jungle_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 mc_block_t block_class_ancil[] = {
|
||||
|
@ -162,8 +154,7 @@ const mc_block_t block_class_ancil[] = {
|
|||
block_birch_fence,
|
||||
block_jungle_fence,
|
||||
block_dark_oak_fence,
|
||||
block_acacia_fence
|
||||
};
|
||||
block_acacia_fence};
|
||||
const size_t block_class_ancil_len = COUNT_OF(block_class_ancil);
|
||||
|
||||
const mc_block_t block_class_alt_height[] = {
|
||||
|
@ -206,7 +197,5 @@ const mc_block_t block_class_alt_height[] = {
|
|||
block_stone_slab2,
|
||||
block_purpur_stairs,
|
||||
block_purpur_slab,
|
||||
block_wooden_slab
|
||||
};
|
||||
block_wooden_slab};
|
||||
const size_t block_class_alt_height_len = COUNT_OF(block_class_alt_height);
|
||||
|
||||
|
|
|
@ -26,8 +26,7 @@
|
|||
bool block_class_is_subset(
|
||||
mc_block_t block,
|
||||
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 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;
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -30,9 +30,8 @@ typedef struct {
|
|||
} ImagingObject;
|
||||
|
||||
inline Imaging
|
||||
imaging_python_to_c(PyObject *obj)
|
||||
{
|
||||
PyObject *im;
|
||||
imaging_python_to_c(PyObject* obj) {
|
||||
PyObject* im;
|
||||
Imaging image;
|
||||
|
||||
/* first, get the 'im' attribute */
|
||||
|
@ -48,7 +47,7 @@ imaging_python_to_c(PyObject *obj)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
image = ((ImagingObject *)im)->image;
|
||||
image = ((ImagingObject*)im)->image;
|
||||
Py_DECREF(im);
|
||||
return image;
|
||||
}
|
||||
|
@ -57,8 +56,7 @@ imaging_python_to_c(PyObject *obj)
|
|||
in these composite functions -- even handles auto-sizing to src! */
|
||||
static inline void
|
||||
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 */
|
||||
if (*xsize <= 0 || *ysize <= 0) {
|
||||
*xsize = src->xsize;
|
||||
|
@ -93,7 +91,7 @@ setup_source_destination(Imaging src, Imaging dest,
|
|||
}
|
||||
|
||||
/* convenience alpha_over with 1.0 as overall_alpha */
|
||||
inline PyObject* alpha_over(PyObject *dest, PyObject *src, PyObject *mask,
|
||||
inline PyObject* alpha_over(PyObject* dest, PyObject* src, PyObject* mask,
|
||||
int dx, int dy, int xsize, int ysize) {
|
||||
return alpha_over_full(dest, src, mask, 1.0f, dx, dy, xsize, ysize);
|
||||
}
|
||||
|
@ -103,8 +101,8 @@ inline PyObject* alpha_over(PyObject *dest, PyObject *src, PyObject *mask,
|
|||
* if xsize, ysize are negative, they are instead set to the size of the image in src
|
||||
* returns NULL on error, dest on success. You do NOT need to decref the return!
|
||||
*/
|
||||
inline PyObject *
|
||||
alpha_over_full(PyObject *dest, PyObject *src, PyObject *mask, float overall_alpha,
|
||||
inline PyObject*
|
||||
alpha_over_full(PyObject* dest, PyObject* src, PyObject* mask, float overall_alpha,
|
||||
int dx, int dy, int xsize, int ysize) {
|
||||
/* libImaging handles */
|
||||
Imaging imDest, imSrc, imMask;
|
||||
|
@ -173,10 +171,10 @@ alpha_over_full(PyObject *dest, PyObject *src, PyObject *mask, float overall_alp
|
|||
}
|
||||
|
||||
for (y = 0; y < ysize; y++) {
|
||||
UINT8 *out = (UINT8 *)imDest->image[dy + y] + dx * 4;
|
||||
UINT8 *outmask = (UINT8 *)imDest->image[dy + y] + dx * 4 + 3;
|
||||
UINT8 *in = (UINT8 *)imSrc->image[sy + y] + sx * (imSrc->pixelsize);
|
||||
UINT8 *inmask = (UINT8 *)imMask->image[sy + y] + sx * mask_stride + mask_offset;
|
||||
UINT8* out = (UINT8*)imDest->image[dy + y] + dx * 4;
|
||||
UINT8* outmask = (UINT8*)imDest->image[dy + y] + dx * 4 + 3;
|
||||
UINT8* in = (UINT8*)imSrc->image[sy + y] + sx * (imSrc->pixelsize);
|
||||
UINT8* inmask = (UINT8*)imMask->image[sy + y] + sx * mask_stride + mask_offset;
|
||||
|
||||
for (x = 0; x < xsize; x++) {
|
||||
UINT8 in_alpha;
|
||||
|
@ -230,15 +228,14 @@ alpha_over_full(PyObject *dest, PyObject *src, PyObject *mask, float overall_alp
|
|||
|
||||
/* 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 */
|
||||
PyObject *
|
||||
alpha_over_wrap(PyObject *self, PyObject *args)
|
||||
{
|
||||
PyObject*
|
||||
alpha_over_wrap(PyObject* self, PyObject* args) {
|
||||
/* raw input python variables */
|
||||
PyObject *dest, *src, *pos = NULL, *mask = NULL;
|
||||
/* destination position and size */
|
||||
int dx, dy, xsize, ysize;
|
||||
/* return value: dest image on success */
|
||||
PyObject *ret;
|
||||
PyObject* ret;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "OO|OO", &dest, &src, &pos, &mask))
|
||||
return NULL;
|
||||
|
@ -277,10 +274,10 @@ alpha_over_wrap(PyObject *self, PyObject *args)
|
|||
/* like alpha_over, but instead of src image it takes a source color
|
||||
* also, it multiplies instead of doing an over operation
|
||||
*/
|
||||
PyObject *
|
||||
tint_with_mask(PyObject *dest, unsigned char sr, unsigned char sg,
|
||||
PyObject*
|
||||
tint_with_mask(PyObject* dest, unsigned char sr, unsigned char sg,
|
||||
unsigned char sb, unsigned char sa,
|
||||
PyObject *mask, int dx, int dy, int xsize, int ysize) {
|
||||
PyObject* mask, int dx, int dy, int xsize, int ysize) {
|
||||
/* libImaging handles */
|
||||
Imaging imDest, imMask;
|
||||
/* cached blend properties */
|
||||
|
@ -326,8 +323,8 @@ tint_with_mask(PyObject *dest, unsigned char sr, unsigned char sg,
|
|||
}
|
||||
|
||||
for (y = 0; y < ysize; y++) {
|
||||
UINT8 *out = (UINT8 *)imDest->image[dy + y] + dx * 4;
|
||||
UINT8 *inmask = (UINT8 *)imMask->image[sy + y] + sx * mask_stride + mask_offset;
|
||||
UINT8* out = (UINT8*)imDest->image[dy + y] + dx * 4;
|
||||
UINT8* inmask = (UINT8*)imMask->image[sy + y] + sx * mask_stride + mask_offset;
|
||||
|
||||
for (x = 0; x < xsize; x++) {
|
||||
/* special cases */
|
||||
|
@ -373,15 +370,15 @@ tint_with_mask(PyObject *dest, unsigned char sr, unsigned char sg,
|
|||
* (or at least, the version poorly reproduced here:
|
||||
* http://www.gidforums.com/t-20838.html )
|
||||
*/
|
||||
PyObject *
|
||||
draw_triangle(PyObject *dest, int inclusive,
|
||||
PyObject*
|
||||
draw_triangle(PyObject* dest, int inclusive,
|
||||
int x0, int y0,
|
||||
unsigned char r0, unsigned char g0, unsigned char b0,
|
||||
int x1, int y1,
|
||||
unsigned char r1, unsigned char g1, unsigned char b1,
|
||||
int x2, int y2,
|
||||
unsigned char r2, unsigned char g2, unsigned char b2,
|
||||
int tux, int tuy, int *touchups, unsigned int num_touchups) {
|
||||
int tux, int tuy, int* touchups, unsigned int num_touchups) {
|
||||
|
||||
/* destination image */
|
||||
Imaging imDest;
|
||||
|
@ -421,9 +418,15 @@ draw_triangle(PyObject *dest, int inclusive,
|
|||
ymax = OV_MIN(ymax, imDest->ysize);
|
||||
|
||||
/* setup coefficients */
|
||||
a12 = y1 - y2; b12 = x2 - x1; 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);
|
||||
a12 = y1 - y2;
|
||||
b12 = x2 - x1;
|
||||
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 */
|
||||
alpha_norm = 1.0f / ((a12 * x0) + (b12 * y0) + c12);
|
||||
|
@ -432,7 +435,7 @@ draw_triangle(PyObject *dest, int inclusive,
|
|||
|
||||
/* iterate over the destination rect */
|
||||
for (y = ymin; y < ymax; y++) {
|
||||
UINT8 *out = (UINT8 *)imDest->image[y] + xmin * 4;
|
||||
UINT8* out = (UINT8*)imDest->image[y] + xmin * 4;
|
||||
|
||||
for (x = xmin; x < xmax; x++) {
|
||||
float alpha, beta, gamma;
|
||||
|
@ -446,9 +449,12 @@ draw_triangle(PyObject *dest, int inclusive,
|
|||
unsigned int g = alpha * g0 + beta * g1 + gamma * g2;
|
||||
unsigned int b = alpha * b0 + beta * b1 + gamma * b2;
|
||||
|
||||
*out = OV_MULDIV255(*out, r, tmp); out++;
|
||||
*out = OV_MULDIV255(*out, g, tmp); out++;
|
||||
*out = OV_MULDIV255(*out, b, tmp); out++;
|
||||
*out = OV_MULDIV255(*out, r, tmp);
|
||||
out++;
|
||||
*out = OV_MULDIV255(*out, g, tmp);
|
||||
out++;
|
||||
*out = OV_MULDIV255(*out, b, tmp);
|
||||
out++;
|
||||
|
||||
/* keep alpha the same */
|
||||
out++;
|
||||
|
@ -462,7 +468,7 @@ draw_triangle(PyObject *dest, int inclusive,
|
|||
while (num_touchups > 0) {
|
||||
float alpha, beta, gamma;
|
||||
unsigned int r, g, b;
|
||||
UINT8 *out;
|
||||
UINT8* out;
|
||||
|
||||
x = touchups[0] + tux;
|
||||
y = touchups[1] + tuy;
|
||||
|
@ -472,7 +478,7 @@ draw_triangle(PyObject *dest, int inclusive,
|
|||
if (x < 0 || x >= imDest->xsize || y < 0 || y >= imDest->ysize)
|
||||
continue;
|
||||
|
||||
out = (UINT8 *)imDest->image[y] + x * 4;
|
||||
out = (UINT8*)imDest->image[y] + x * 4;
|
||||
|
||||
alpha = alpha_norm * ((a12 * x) + (b12 * y) + c12);
|
||||
beta = beta_norm * ((a20 * x) + (b20 * y) + c20);
|
||||
|
@ -482,9 +488,12 @@ draw_triangle(PyObject *dest, int inclusive,
|
|||
g = alpha * g0 + beta * g1 + gamma * g2;
|
||||
b = alpha * b0 + beta * b1 + gamma * b2;
|
||||
|
||||
*out = OV_MULDIV255(*out, r, tmp); out++;
|
||||
*out = OV_MULDIV255(*out, g, tmp); out++;
|
||||
*out = OV_MULDIV255(*out, b, tmp); out++;
|
||||
*out = OV_MULDIV255(*out, r, tmp);
|
||||
out++;
|
||||
*out = OV_MULDIV255(*out, g, tmp);
|
||||
out++;
|
||||
*out = OV_MULDIV255(*out, b, tmp);
|
||||
out++;
|
||||
}
|
||||
|
||||
return dest;
|
||||
|
@ -492,8 +501,8 @@ draw_triangle(PyObject *dest, int inclusive,
|
|||
|
||||
/* scales the image to half size
|
||||
*/
|
||||
inline PyObject *
|
||||
resize_half(PyObject *dest, PyObject *src) {
|
||||
inline PyObject*
|
||||
resize_half(PyObject* dest, PyObject* src) {
|
||||
/* libImaging handles */
|
||||
Imaging imDest, imSrc;
|
||||
/* alpha properties */
|
||||
|
@ -547,14 +556,14 @@ resize_half(PyObject *dest, PyObject *src) {
|
|||
}
|
||||
|
||||
/* set to fully opaque if source has no alpha channel */
|
||||
if(!src_has_alpha)
|
||||
if (!src_has_alpha)
|
||||
a = 0xFF << 2;
|
||||
|
||||
for (y = 0; y < dest_height; y++) {
|
||||
|
||||
UINT8 *out = (UINT8 *)imDest->image[y];
|
||||
UINT8 *in_row1 = (UINT8 *)imSrc->image[y * 2];
|
||||
UINT8 *in_row2 = (UINT8 *)imSrc->image[y * 2 + 1];
|
||||
UINT8* out = (UINT8*)imDest->image[y];
|
||||
UINT8* in_row1 = (UINT8*)imSrc->image[y * 2];
|
||||
UINT8* in_row2 = (UINT8*)imSrc->image[y * 2 + 1];
|
||||
|
||||
for (x = 0; x < dest_width; x++) {
|
||||
|
||||
|
@ -572,8 +581,7 @@ resize_half(PyObject *dest, PyObject *src) {
|
|||
in_row1++;
|
||||
in_row2++;
|
||||
|
||||
if (src_has_alpha)
|
||||
{
|
||||
if (src_has_alpha) {
|
||||
a = *in_row1;
|
||||
a += *in_row2;
|
||||
in_row1++;
|
||||
|
@ -594,8 +602,7 @@ resize_half(PyObject *dest, PyObject *src) {
|
|||
in_row1++;
|
||||
in_row2++;
|
||||
|
||||
if (src_has_alpha)
|
||||
{
|
||||
if (src_has_alpha) {
|
||||
a += *in_row1;
|
||||
a += *in_row2;
|
||||
in_row1++;
|
||||
|
@ -610,8 +617,7 @@ resize_half(PyObject *dest, PyObject *src) {
|
|||
*out = (UINT8)(b >> 2);
|
||||
out++;
|
||||
|
||||
if (dest_has_alpha)
|
||||
{
|
||||
if (dest_has_alpha) {
|
||||
*out = (UINT8)(a >> 2);
|
||||
out++;
|
||||
}
|
||||
|
@ -622,13 +628,12 @@ resize_half(PyObject *dest, PyObject *src) {
|
|||
}
|
||||
|
||||
/* wraps resize_half so it can be called directly from python */
|
||||
PyObject *
|
||||
resize_half_wrap(PyObject *self, PyObject *args)
|
||||
{
|
||||
PyObject*
|
||||
resize_half_wrap(PyObject* self, PyObject* args) {
|
||||
/* raw input python variables */
|
||||
PyObject *dest, *src;
|
||||
/* return value: dest image on success */
|
||||
PyObject *ret;
|
||||
PyObject* ret;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "OO", &dest, &src))
|
||||
return NULL;
|
||||
|
|
|
@ -15,26 +15,26 @@
|
|||
* with the Overviewer. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "overviewer.h"
|
||||
#include "mc_id.h"
|
||||
#include "block_class.h"
|
||||
#include "mc_id.h"
|
||||
#include "overviewer.h"
|
||||
|
||||
static PyObject *textures = NULL;
|
||||
static PyObject* textures = NULL;
|
||||
|
||||
unsigned int max_blockid = 0;
|
||||
unsigned int max_data = 0;
|
||||
unsigned char *block_properties = NULL;
|
||||
unsigned char* block_properties = NULL;
|
||||
|
||||
static PyObject *known_blocks = NULL;
|
||||
static PyObject *transparent_blocks = NULL;
|
||||
static PyObject *solid_blocks = NULL;
|
||||
static PyObject *fluid_blocks = NULL;
|
||||
static PyObject *nospawn_blocks = NULL;
|
||||
static PyObject *nodata_blocks = NULL;
|
||||
static PyObject* known_blocks = NULL;
|
||||
static PyObject* transparent_blocks = NULL;
|
||||
static PyObject* solid_blocks = NULL;
|
||||
static PyObject* fluid_blocks = NULL;
|
||||
static PyObject* nospawn_blocks = NULL;
|
||||
static PyObject* nodata_blocks = NULL;
|
||||
|
||||
PyObject *init_chunk_render(void) {
|
||||
PyObject* init_chunk_render(void) {
|
||||
|
||||
PyObject *tmp = NULL;
|
||||
PyObject* tmp = NULL;
|
||||
unsigned int i;
|
||||
|
||||
/* this function only needs to be called once, anything more should be
|
||||
|
@ -82,7 +82,7 @@ PyObject *init_chunk_render(void) {
|
|||
|
||||
block_properties = calloc(max_blockid, sizeof(unsigned char));
|
||||
for (i = 0; i < max_blockid; i++) {
|
||||
PyObject *block = PyLong_FromLong(i);
|
||||
PyObject* block = PyLong_FromLong(i);
|
||||
|
||||
if (PySequence_Contains(known_blocks, block))
|
||||
block_properties[i] |= 1 << KNOWN;
|
||||
|
@ -104,11 +104,11 @@ PyObject *init_chunk_render(void) {
|
|||
}
|
||||
|
||||
/* helper for load_chunk, loads a section into a chunk */
|
||||
static inline void load_chunk_section(ChunkData *dest, int i, PyObject *section) {
|
||||
dest->sections[i].blocks = (PyArrayObject*) PyDict_GetItemString(section, "Blocks");
|
||||
dest->sections[i].data = (PyArrayObject*) PyDict_GetItemString(section, "Data");
|
||||
dest->sections[i].skylight = (PyArrayObject*) PyDict_GetItemString(section, "SkyLight");
|
||||
dest->sections[i].blocklight = (PyArrayObject*) PyDict_GetItemString(section, "BlockLight");
|
||||
static inline void load_chunk_section(ChunkData* dest, int i, PyObject* section) {
|
||||
dest->sections[i].blocks = (PyArrayObject*)PyDict_GetItemString(section, "Blocks");
|
||||
dest->sections[i].data = (PyArrayObject*)PyDict_GetItemString(section, "Data");
|
||||
dest->sections[i].skylight = (PyArrayObject*)PyDict_GetItemString(section, "SkyLight");
|
||||
dest->sections[i].blocklight = (PyArrayObject*)PyDict_GetItemString(section, "BlockLight");
|
||||
Py_INCREF(dest->sections[i].blocks);
|
||||
Py_INCREF(dest->sections[i].data);
|
||||
Py_INCREF(dest->sections[i].skylight);
|
||||
|
@ -122,18 +122,17 @@ static inline void load_chunk_section(ChunkData *dest, int i, PyObject *section)
|
|||
* exception and return true.
|
||||
*/
|
||||
int load_chunk(RenderState* state, int x, int z, unsigned char required) {
|
||||
ChunkData *dest = &(state->chunks[1 + x][1 + z]);
|
||||
ChunkData* dest = &(state->chunks[1 + x][1 + z]);
|
||||
int i;
|
||||
PyObject *chunk = NULL;
|
||||
PyObject *sections = NULL;
|
||||
PyObject* chunk = NULL;
|
||||
PyObject* sections = NULL;
|
||||
|
||||
if (dest->loaded)
|
||||
return 0;
|
||||
|
||||
/* set up reasonable defaults */
|
||||
dest->biomes = NULL;
|
||||
for (i = 0; i < SECTIONS_PER_CHUNK; i++)
|
||||
{
|
||||
for (i = 0; i < SECTIONS_PER_CHUNK; i++) {
|
||||
dest->sections[i].blocks = NULL;
|
||||
dest->sections[i].data = NULL;
|
||||
dest->sections[i].skylight = NULL;
|
||||
|
@ -167,13 +166,13 @@ int load_chunk(RenderState* state, int x, int z, unsigned char required) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
dest->biomes = (PyArrayObject*) PyDict_GetItemString(chunk, "Biomes");
|
||||
dest->biomes = (PyArrayObject*)PyDict_GetItemString(chunk, "Biomes");
|
||||
Py_INCREF(dest->biomes);
|
||||
|
||||
for (i = 0; i < PySequence_Fast_GET_SIZE(sections); i++) {
|
||||
PyObject *ycoord = NULL;
|
||||
PyObject* ycoord = NULL;
|
||||
int sectiony = 0;
|
||||
PyObject *section = PySequence_Fast_GET_ITEM(sections, i);
|
||||
PyObject* section = PySequence_Fast_GET_ITEM(sections, i);
|
||||
ycoord = PyDict_GetItemString(section, "Y");
|
||||
if (!ycoord)
|
||||
continue;
|
||||
|
@ -190,7 +189,7 @@ int load_chunk(RenderState* state, int x, int z, unsigned char required) {
|
|||
|
||||
/* helper to unload all loaded chunks */
|
||||
static void
|
||||
unload_all_chunks(RenderState *state) {
|
||||
unload_all_chunks(RenderState* state) {
|
||||
unsigned int i, j, k;
|
||||
for (i = 0; i < 3; i++) {
|
||||
for (j = 0; j < 3; j++) {
|
||||
|
@ -209,7 +208,7 @@ unload_all_chunks(RenderState *state) {
|
|||
}
|
||||
|
||||
unsigned short
|
||||
check_adjacent_blocks(RenderState *state, int x,int y,int z, unsigned short blockid) {
|
||||
check_adjacent_blocks(RenderState* state, int x, int y, int z, unsigned short blockid) {
|
||||
/*
|
||||
* Generates a pseudo ancillary data for blocks that depend of
|
||||
* what are surrounded and don't have ancillary data. This
|
||||
|
@ -226,26 +225,26 @@ check_adjacent_blocks(RenderState *state, int x,int y,int z, unsigned short bloc
|
|||
* blockid in the side of the +x direction.
|
||||
*/
|
||||
|
||||
unsigned char pdata=0;
|
||||
unsigned char pdata = 0;
|
||||
|
||||
if (get_data(state, BLOCKS, x + 1, y, z) == blockid) {
|
||||
pdata = pdata|(1 << 3);
|
||||
pdata = pdata | (1 << 3);
|
||||
}
|
||||
if (get_data(state, BLOCKS, x, y, z + 1) == blockid) {
|
||||
pdata = pdata|(1 << 2);
|
||||
pdata = pdata | (1 << 2);
|
||||
}
|
||||
if (get_data(state, BLOCKS, x - 1, y, z) == blockid) {
|
||||
pdata = pdata|(1 << 1);
|
||||
pdata = pdata | (1 << 1);
|
||||
}
|
||||
if (get_data(state, BLOCKS, x, y, z - 1) == blockid) {
|
||||
pdata = pdata|(1 << 0);
|
||||
pdata = pdata | (1 << 0);
|
||||
}
|
||||
|
||||
return pdata;
|
||||
}
|
||||
|
||||
unsigned short
|
||||
generate_pseudo_data(RenderState *state, unsigned short ancilData) {
|
||||
generate_pseudo_data(RenderState* state, unsigned short ancilData) {
|
||||
/*
|
||||
* Generates a fake ancillary data for blocks that are drawn
|
||||
* depending on what are surrounded.
|
||||
|
@ -255,21 +254,21 @@ generate_pseudo_data(RenderState *state, unsigned short ancilData) {
|
|||
|
||||
if (state->block == block_grass) { /* grass */
|
||||
/* return 0x10 if grass is covered in snow */
|
||||
if (get_data(state, BLOCKS, x, y+1, z) == 78)
|
||||
if (get_data(state, BLOCKS, x, y + 1, z) == 78)
|
||||
return 0x10;
|
||||
return ancilData;
|
||||
} else if (block_class_is_subset(state->block, (mc_block_t[]){block_flowing_water,block_water}, 2)) { /* water */
|
||||
} else if (block_class_is_subset(state->block, (mc_block_t[]){block_flowing_water, block_water}, 2)) { /* water */
|
||||
data = check_adjacent_blocks(state, x, y, z, state->block) ^ 0x0f;
|
||||
/* an aditional bit for top is added to the 4 bits of check_adjacent_blocks */
|
||||
if (get_data(state, BLOCKS, x, y+1, z) != state->block)
|
||||
if (get_data(state, BLOCKS, x, y + 1, z) != state->block)
|
||||
data |= 0x10;
|
||||
return data;
|
||||
} else if (block_class_is_subset(state->block, (mc_block_t[]){block_glass,block_ice,block_stained_glass}, 3)) { /* glass and ice and stained glass*/
|
||||
} else if (block_class_is_subset(state->block, (mc_block_t[]){block_glass, block_ice, block_stained_glass}, 3)) { /* glass and ice and stained glass*/
|
||||
/* an aditional bit for top is added to the 4 bits of check_adjacent_blocks
|
||||
* Note that stained glass encodes 16 colors using 4 bits. this pushes us over the 8-bits of an unsigned char,
|
||||
* forcing us to use an unsigned short to hold 16 bits of pseudo ancil data
|
||||
* */
|
||||
if ((get_data(state, BLOCKS, x, y+1, z) == 20) || (get_data(state, BLOCKS, x, y+1, z) == 95)) {
|
||||
if ((get_data(state, BLOCKS, x, y + 1, z) == 20) || (get_data(state, BLOCKS, x, y + 1, z) == 95)) {
|
||||
data = 0;
|
||||
} else {
|
||||
data = 16;
|
||||
|
@ -289,8 +288,8 @@ generate_pseudo_data(RenderState *state, unsigned short ancilData) {
|
|||
unsigned char above_level_data = 0, same_level_data = 0, below_level_data = 0, possibly_connected = 0, final_data = 0;
|
||||
|
||||
/* check for air in y+1, no air = no connection with upper level */
|
||||
if (get_data(state, BLOCKS, x, y+1, z) == 0) {
|
||||
above_level_data = check_adjacent_blocks(state, x, y+1, z, state->block);
|
||||
if (get_data(state, BLOCKS, x, y + 1, z) == 0) {
|
||||
above_level_data = check_adjacent_blocks(state, x, y + 1, z, state->block);
|
||||
} /* else above_level_data = 0 */
|
||||
|
||||
/* check connection with same level (other redstone and trapped chests */
|
||||
|
@ -300,7 +299,7 @@ generate_pseudo_data(RenderState *state, unsigned short ancilData) {
|
|||
possibly_connected = check_adjacent_blocks(state, x, y, z, 0);
|
||||
|
||||
/* check connection with y-1 level */
|
||||
below_level_data = check_adjacent_blocks(state, x, y-1, z, state->block);
|
||||
below_level_data = check_adjacent_blocks(state, x, y - 1, z, state->block);
|
||||
|
||||
final_data = above_level_data | same_level_data | (below_level_data & possibly_connected);
|
||||
|
||||
|
@ -316,7 +315,7 @@ generate_pseudo_data(RenderState *state, unsigned short ancilData) {
|
|||
}
|
||||
return final_data;
|
||||
|
||||
} else if (block_class_is_subset(state->block, (mc_block_t[]){block_chest,block_trapped_chest}, 2)) {
|
||||
} else if (block_class_is_subset(state->block, (mc_block_t[]){block_chest, block_trapped_chest}, 2)) {
|
||||
/* Orientation is given by ancilData, pseudo data needed to
|
||||
* choose from single or double chest and the correct half of
|
||||
* the chest. */
|
||||
|
@ -353,7 +352,7 @@ generate_pseudo_data(RenderState *state, unsigned short ancilData) {
|
|||
}
|
||||
return final_data;
|
||||
|
||||
} else if (block_class_is_subset(state->block, (mc_block_t[]){block_iron_bars,block_glass_pane, block_stained_glass_pane},3)) {
|
||||
} else if (block_class_is_subset(state->block, (mc_block_t[]){block_iron_bars, block_glass_pane, block_stained_glass_pane}, 3)) {
|
||||
/* iron bars and glass panes:
|
||||
* they seem to stick to almost everything but air,
|
||||
* not sure yet! Still a TODO! */
|
||||
|
@ -362,7 +361,7 @@ generate_pseudo_data(RenderState *state, unsigned short ancilData) {
|
|||
data = (check_adjacent_blocks(state, x, y, z, 0) ^ 0x0f);
|
||||
return (data << 4) | (ancilData & 0xf);
|
||||
|
||||
} else if (block_class_is_subset(state->block, (mc_block_t[]){block_portal,block_nether_brick_fence}, 2)) {
|
||||
} else if (block_class_is_subset(state->block, (mc_block_t[]){block_portal, block_nether_brick_fence}, 2)) {
|
||||
/* portal and nether brick fences */
|
||||
return check_adjacent_blocks(state, x, y, z, state->block);
|
||||
|
||||
|
@ -373,7 +372,7 @@ generate_pseudo_data(RenderState *state, unsigned short ancilData) {
|
|||
unsigned char data = 0;
|
||||
if ((ancilData & 0x8) == 0x8) {
|
||||
/* top door block */
|
||||
unsigned char b_data = get_data(state, DATA, x, y-1, z);
|
||||
unsigned char b_data = get_data(state, DATA, x, y - 1, z);
|
||||
if ((ancilData & 0x1) == 0x1) {
|
||||
/* hinge on the left */
|
||||
data = b_data | 0x8 | 0x10;
|
||||
|
@ -382,14 +381,13 @@ generate_pseudo_data(RenderState *state, unsigned short ancilData) {
|
|||
}
|
||||
} else {
|
||||
/* bottom door block */
|
||||
unsigned char t_data = get_data(state, DATA, x, y+1, z);
|
||||
unsigned char t_data = get_data(state, DATA, x, y + 1, z);
|
||||
if ((t_data & 0x1) == 0x1) {
|
||||
/* hinge on the left */
|
||||
data = ancilData | 0x10;
|
||||
} else {
|
||||
data = ancilData;
|
||||
}
|
||||
|
||||
}
|
||||
return data;
|
||||
} else if (state->block == block_cobblestone_wall) {
|
||||
|
@ -400,7 +398,7 @@ generate_pseudo_data(RenderState *state, unsigned short ancilData) {
|
|||
return check_adjacent_blocks(state, x, y, z, state->block);
|
||||
}
|
||||
} else if (state->block == block_waterlily) {
|
||||
int wx,wz,wy,rotation;
|
||||
int wx, wz, wy, rotation;
|
||||
long pr;
|
||||
/* calculate the global block coordinates of this position */
|
||||
wx = (state->chunkx * 16) + x;
|
||||
|
@ -430,39 +428,39 @@ generate_pseudo_data(RenderState *state, unsigned short ancilData) {
|
|||
/* keep track of whether neighbors are stairs, and their data */
|
||||
unsigned char stairs_base[8];
|
||||
unsigned char neigh_base[8];
|
||||
unsigned char *stairs = stairs_base;
|
||||
unsigned char *neigh = neigh_base;
|
||||
unsigned char* stairs = stairs_base;
|
||||
unsigned char* neigh = neigh_base;
|
||||
|
||||
/* amount to rotate/roll to get to east, west, south, north */
|
||||
size_t rotations[] = {0,2,3,1};
|
||||
size_t rotations[] = {0, 2, 3, 1};
|
||||
|
||||
/* masks for the filled (ridge) stair quarters: */
|
||||
/* Example: the ridge for an east-ascending stair are the two east quarters */
|
||||
/* ascending: east west south north */
|
||||
unsigned char ridge_mask[] = { 0x30, 0x48, 0x60, 0x18 };
|
||||
unsigned char ridge_mask[] = {0x30, 0x48, 0x60, 0x18};
|
||||
|
||||
/* masks for the open (trench) stair quarters: */
|
||||
unsigned char trench_mask[] = { 0x48, 0x30, 0x18, 0x60 };
|
||||
unsigned char trench_mask[] = {0x48, 0x30, 0x18, 0x60};
|
||||
|
||||
/* boat analogy! up the stairs is toward the bow of the boat */
|
||||
/* masks for port and starboard, i.e. left and right sides while ascending: */
|
||||
unsigned char port_mask[] = { 0x18, 0x60, 0x30, 0x48 };
|
||||
unsigned char starboard_mask[] = { 0x60, 0x18, 0x48, 0x30 };
|
||||
unsigned char port_mask[] = {0x18, 0x60, 0x30, 0x48};
|
||||
unsigned char starboard_mask[] = {0x60, 0x18, 0x48, 0x30};
|
||||
|
||||
/* we may need to lock some quarters into place depending on neighbors */
|
||||
unsigned char lock_mask = 0;
|
||||
|
||||
unsigned char repair_rot[] = { 0, 1, 2, 3, 2, 3, 1, 0, 1, 0, 3, 2, 3, 2, 0, 1 };
|
||||
unsigned char repair_rot[] = {0, 1, 2, 3, 2, 3, 1, 0, 1, 0, 3, 2, 3, 2, 0, 1};
|
||||
|
||||
/* need to get northdirection of the render */
|
||||
/* TODO: get this just once? store in state? */
|
||||
PyObject *texrot;
|
||||
PyObject* texrot;
|
||||
int northdir;
|
||||
texrot = PyObject_GetAttrString(state->textures, "rotation");
|
||||
northdir = PyLong_AsLong(texrot);
|
||||
|
||||
/* fix the rotation value for different northdirections */
|
||||
#define FIX_ROT(x) (((x) & ~0x3) | repair_rot[((x) & 0x3) | (northdir << 2)])
|
||||
/* fix the rotation value for different northdirections */
|
||||
#define FIX_ROT(x) (((x) & ~0x3) | repair_rot[((x)&0x3) | (northdir << 2)])
|
||||
ancilData = FIX_ROT(ancilData);
|
||||
|
||||
/* fill the ancillary bits assuming normal stairs with no corner yet */
|
||||
|
@ -470,16 +468,16 @@ generate_pseudo_data(RenderState *state, unsigned short ancilData) {
|
|||
|
||||
/* get block & data for neighbors in this order: east, north, west, south */
|
||||
/* so we can rotate things easily */
|
||||
stairs[0] = stairs[4] = block_class_is_subset(get_data(state, BLOCKS, x+1, y, z), block_class_stair, block_class_stair_len);
|
||||
stairs[1] = stairs[5] = block_class_is_subset(get_data(state, BLOCKS, x, y, z-1), block_class_stair, block_class_stair_len);
|
||||
stairs[2] = stairs[6] = block_class_is_subset(get_data(state, BLOCKS, x-1, y, z), block_class_stair, block_class_stair_len);
|
||||
stairs[3] = stairs[7] = block_class_is_subset(get_data(state, BLOCKS, x, y, z+1), block_class_stair, block_class_stair_len);
|
||||
neigh[0] = neigh[4] = FIX_ROT(get_data(state, DATA, x+1, y, z));
|
||||
neigh[1] = neigh[5] = FIX_ROT(get_data(state, DATA, x, y, z-1));
|
||||
neigh[2] = neigh[6] = FIX_ROT(get_data(state, DATA, x-1, y, z));
|
||||
neigh[3] = neigh[7] = FIX_ROT(get_data(state, DATA, x, y, z+1));
|
||||
stairs[0] = stairs[4] = block_class_is_subset(get_data(state, BLOCKS, x + 1, y, z), block_class_stair, block_class_stair_len);
|
||||
stairs[1] = stairs[5] = block_class_is_subset(get_data(state, BLOCKS, x, y, z - 1), block_class_stair, block_class_stair_len);
|
||||
stairs[2] = stairs[6] = block_class_is_subset(get_data(state, BLOCKS, x - 1, y, z), block_class_stair, block_class_stair_len);
|
||||
stairs[3] = stairs[7] = block_class_is_subset(get_data(state, BLOCKS, x, y, z + 1), block_class_stair, block_class_stair_len);
|
||||
neigh[0] = neigh[4] = FIX_ROT(get_data(state, DATA, x + 1, y, z));
|
||||
neigh[1] = neigh[5] = FIX_ROT(get_data(state, DATA, x, y, z - 1));
|
||||
neigh[2] = neigh[6] = FIX_ROT(get_data(state, DATA, x - 1, y, z));
|
||||
neigh[3] = neigh[7] = FIX_ROT(get_data(state, DATA, x, y, z + 1));
|
||||
|
||||
#undef FIX_ROT
|
||||
#undef FIX_ROT
|
||||
|
||||
/* Rotate the neighbors so we only have to worry about one orientation
|
||||
* No matter which way the boat is facing, the the neighbors will be:
|
||||
|
@ -523,8 +521,8 @@ generate_pseudo_data(RenderState *state, unsigned short ancilData) {
|
|||
/* use bottom block data format plus one bit for top
|
||||
* block (0x8)
|
||||
*/
|
||||
if( get_data(state, BLOCKS, x, y-1, z) == block_double_plant ) {
|
||||
data = get_data(state, DATA, x, y-1, z) | 0x8;
|
||||
if (get_data(state, BLOCKS, x, y - 1, z) == block_double_plant) {
|
||||
data = get_data(state, DATA, x, y - 1, z) | 0x8;
|
||||
} else {
|
||||
data = ancilData;
|
||||
}
|
||||
|
@ -535,30 +533,29 @@ generate_pseudo_data(RenderState *state, unsigned short ancilData) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* TODO triple check this to make sure reference counting is correct */
|
||||
PyObject*
|
||||
chunk_render(PyObject *self, PyObject *args) {
|
||||
chunk_render(PyObject* self, PyObject* args) {
|
||||
RenderState state;
|
||||
PyObject *modeobj;
|
||||
PyObject *blockmap;
|
||||
PyObject* modeobj;
|
||||
PyObject* blockmap;
|
||||
|
||||
int xoff, yoff;
|
||||
|
||||
PyObject *imgsize, *imgsize0_py, *imgsize1_py;
|
||||
int imgsize0, imgsize1;
|
||||
|
||||
PyArrayObject *blocks_py;
|
||||
PyArrayObject *left_blocks_py;
|
||||
PyArrayObject *right_blocks_py;
|
||||
PyArrayObject *up_left_blocks_py;
|
||||
PyArrayObject *up_right_blocks_py;
|
||||
PyArrayObject* blocks_py;
|
||||
PyArrayObject* left_blocks_py;
|
||||
PyArrayObject* right_blocks_py;
|
||||
PyArrayObject* up_left_blocks_py;
|
||||
PyArrayObject* up_right_blocks_py;
|
||||
|
||||
RenderMode *rendermode;
|
||||
RenderMode* rendermode;
|
||||
|
||||
int i, j;
|
||||
|
||||
PyObject *t = NULL;
|
||||
PyObject* t = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "OOiiiOiiOO", &state.world, &state.regionset, &state.chunkx, &state.chunky, &state.chunkz, &state.img, &xoff, &yoff, &modeobj, &state.textures))
|
||||
return NULL;
|
||||
|
@ -627,9 +624,9 @@ chunk_render(PyObject *self, PyObject *args) {
|
|||
for (state.z = 0; state.z < 16; state.z++) {
|
||||
|
||||
/* set up the render coordinates */
|
||||
state.imgx = xoff + state.x*12 + state.z*12;
|
||||
state.imgx = xoff + state.x * 12 + state.z * 12;
|
||||
/* 16*12 -- offset for y direction, 15*6 -- offset for x */
|
||||
state.imgy = yoff - state.x*6 + state.z*6 + 16*12 + 15*6;
|
||||
state.imgy = yoff - state.x * 6 + state.z * 6 + 16 * 12 + 15 * 6;
|
||||
|
||||
for (state.y = 0; state.y < 16; state.y++) {
|
||||
unsigned short ancilData;
|
||||
|
@ -688,8 +685,7 @@ chunk_render(PyObject *self, PyObject *args) {
|
|||
t = PyList_GET_ITEM(blockmap, max_data * state.block);
|
||||
|
||||
/* if we found a proper texture, render it! */
|
||||
if (t != NULL && t != Py_None)
|
||||
{
|
||||
if (t != NULL && t != Py_None) {
|
||||
PyObject *src, *mask, *mask_light;
|
||||
int do_rand = (state.block == block_tallgrass /*|| state.block == block_red_flower || state.block == block_double_plant*/);
|
||||
int randx = 0, randy = 0;
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
#include "overviewer.h"
|
||||
|
||||
PyObject *get_extension_version(PyObject *self, PyObject *args) {
|
||||
PyObject* get_extension_version(PyObject* self, PyObject* args) {
|
||||
|
||||
return Py_BuildValue("i", OVERVIEWER_EXTENSION_VERSION);
|
||||
}
|
||||
|
@ -43,13 +43,10 @@ static PyModuleDef COverviewerModule = {
|
|||
"c_overviewer",
|
||||
"", // TODO: Add documentation here.
|
||||
-1,
|
||||
COverviewerMethods
|
||||
};
|
||||
|
||||
COverviewerMethods};
|
||||
|
||||
PyMODINIT_FUNC
|
||||
PyInit_c_overviewer(void)
|
||||
{
|
||||
PyInit_c_overviewer(void) {
|
||||
PyObject *mod, *numpy;
|
||||
mod = PyModule_Create(&COverviewerModule);
|
||||
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
enum mc_block_id
|
||||
{
|
||||
enum mc_block_id {
|
||||
block_air = 0,
|
||||
block_stone = 1,
|
||||
block_grass = 2,
|
||||
|
@ -284,9 +283,7 @@ enum mc_block_id
|
|||
|
||||
typedef uint16_t mc_block_t;
|
||||
|
||||
|
||||
enum mc_item_id
|
||||
{
|
||||
enum mc_item_id {
|
||||
item_iron_shovel = 256,
|
||||
item_iron_pickaxe = 257,
|
||||
item_iron_axe = 258,
|
||||
|
|
|
@ -24,55 +24,51 @@
|
|||
#ifndef __OVERVIEWER_H_INCLUDED__
|
||||
#define __OVERVIEWER_H_INCLUDED__
|
||||
|
||||
|
||||
#define WINVER 0x0601
|
||||
#define _WIN32_WINNT 0x0601
|
||||
|
||||
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
|
||||
|
||||
|
||||
// increment this value if you've made a change to the c extesion
|
||||
// and want to force users to rebuild
|
||||
#define OVERVIEWER_EXTENSION_VERSION 65
|
||||
|
||||
/* Python PIL, and numpy headers */
|
||||
#include <Imaging.h>
|
||||
#include <Python.h>
|
||||
#include <numpy/arrayobject.h>
|
||||
#include <Imaging.h>
|
||||
/* Fix Pillow on mingw-w64 which includes windows.h in Imaging.h */
|
||||
#undef TRANSPARENT
|
||||
/* Utility macros */
|
||||
#include "utils.h"
|
||||
|
||||
|
||||
/* macro for getting a value out of various numpy arrays the 3D arrays have
|
||||
interesting, swizzled coordinates because minecraft (anvil) stores blocks
|
||||
in y/z/x order for 3D, z/x order for 2D */
|
||||
#define getArrayByte3D(array, x,y,z) (*(unsigned char *)(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 getArrayByte3D(array, x, y, z) (*(unsigned char*)(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))))
|
||||
|
||||
/* in composite.c */
|
||||
Imaging imaging_python_to_c(PyObject *obj);
|
||||
PyObject *alpha_over(PyObject *dest, PyObject *src, PyObject *mask,
|
||||
Imaging imaging_python_to_c(PyObject* obj);
|
||||
PyObject* alpha_over(PyObject* dest, PyObject* src, PyObject* mask,
|
||||
int dx, int dy, int xsize, int ysize);
|
||||
PyObject *alpha_over_full(PyObject *dest, PyObject *src, PyObject *mask, float overall_alpha,
|
||||
PyObject* alpha_over_full(PyObject* dest, PyObject* src, PyObject* mask, float overall_alpha,
|
||||
int dx, int dy, int xsize, int ysize);
|
||||
PyObject *alpha_over_wrap(PyObject *self, PyObject *args);
|
||||
PyObject *tint_with_mask(PyObject *dest, unsigned char sr, unsigned char sg,
|
||||
PyObject* alpha_over_wrap(PyObject* self, PyObject* args);
|
||||
PyObject* tint_with_mask(PyObject* dest, unsigned char sr, unsigned char sg,
|
||||
unsigned char sb, unsigned char sa,
|
||||
PyObject *mask, int dx, int dy, int xsize, int ysize);
|
||||
PyObject *draw_triangle(PyObject *dest, int inclusive,
|
||||
PyObject* mask, int dx, int dy, int xsize, int ysize);
|
||||
PyObject* draw_triangle(PyObject* dest, int inclusive,
|
||||
int x0, int y0,
|
||||
unsigned char r0, unsigned char g0, unsigned char b0,
|
||||
int x1, int y1,
|
||||
unsigned char r1, unsigned char g1, unsigned char b1,
|
||||
int x2, int y2,
|
||||
unsigned char r2, unsigned char g2, unsigned char b2,
|
||||
int tux, int tuy, int *touchups, unsigned int num_touchups);
|
||||
PyObject *resize_half(PyObject *dest, PyObject *src);
|
||||
PyObject *resize_half_wrap(PyObject *self, PyObject *args);
|
||||
int tux, int tuy, int* touchups, unsigned int num_touchups);
|
||||
PyObject* resize_half(PyObject* dest, PyObject* src);
|
||||
PyObject* resize_half_wrap(PyObject* self, PyObject* args);
|
||||
|
||||
/* forward declaration of RenderMode object */
|
||||
typedef struct _RenderMode RenderMode;
|
||||
|
@ -83,7 +79,7 @@ typedef struct {
|
|||
/* whether this chunk is loaded: use load_chunk to load */
|
||||
int loaded;
|
||||
/* chunk biome array */
|
||||
PyArrayObject *biomes;
|
||||
PyArrayObject* biomes;
|
||||
/* all the sections in a given chunk */
|
||||
struct {
|
||||
/* all there is to know about each section */
|
||||
|
@ -92,19 +88,19 @@ typedef struct {
|
|||
} ChunkData;
|
||||
typedef struct {
|
||||
/* the regionset object, and chunk coords */
|
||||
PyObject *world;
|
||||
PyObject *regionset;
|
||||
PyObject* world;
|
||||
PyObject* regionset;
|
||||
int chunkx, chunky, chunkz;
|
||||
|
||||
/* the tile image and destination */
|
||||
PyObject *img;
|
||||
PyObject* img;
|
||||
int imgx, imgy;
|
||||
|
||||
/* the current render mode in use */
|
||||
RenderMode *rendermode;
|
||||
RenderMode* rendermode;
|
||||
|
||||
/* the Texture object */
|
||||
PyObject *textures;
|
||||
PyObject* textures;
|
||||
|
||||
/* the block position and type, and the block array */
|
||||
int x, y, z;
|
||||
|
@ -113,18 +109,17 @@ typedef struct {
|
|||
unsigned short block_pdata;
|
||||
|
||||
/* useful information about this, and neighboring, chunks */
|
||||
PyArrayObject *blockdatas;
|
||||
PyArrayObject *blocks;
|
||||
PyArrayObject* blockdatas;
|
||||
PyArrayObject* blocks;
|
||||
|
||||
/* 3x3 array of this and neighboring chunk columns */
|
||||
ChunkData chunks[3][3];
|
||||
} RenderState;
|
||||
PyObject *init_chunk_render(void);
|
||||
PyObject* init_chunk_render(void);
|
||||
/* returns true on error, x,z relative */
|
||||
int load_chunk(RenderState* state, int x, int z, unsigned char required);
|
||||
PyObject *chunk_render(PyObject *self, PyObject *args);
|
||||
typedef enum
|
||||
{
|
||||
PyObject* chunk_render(PyObject* self, PyObject* args);
|
||||
typedef enum {
|
||||
KNOWN,
|
||||
TRANSPARENT,
|
||||
SOLID,
|
||||
|
@ -136,7 +131,7 @@ typedef enum
|
|||
in block_has_property */
|
||||
extern unsigned int max_blockid;
|
||||
extern unsigned int max_data;
|
||||
extern unsigned char *block_properties;
|
||||
extern unsigned char* block_properties;
|
||||
static inline int
|
||||
block_has_property(unsigned short b, BlockProperty prop) {
|
||||
if (b >= max_blockid || !(block_properties[b] & (1 << KNOWN))) {
|
||||
|
@ -152,18 +147,16 @@ block_has_property(unsigned short b, BlockProperty prop) {
|
|||
#define is_known_transparent(b) block_has_property((b), TRANSPARENT) && block_has_property((b), KNOWN)
|
||||
|
||||
/* helper for indexing section data possibly across section boundaries */
|
||||
typedef enum
|
||||
{
|
||||
typedef enum {
|
||||
BLOCKS,
|
||||
DATA,
|
||||
BLOCKLIGHT,
|
||||
SKYLIGHT,
|
||||
BIOMES,
|
||||
} 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;
|
||||
PyArrayObject *data_array = NULL;
|
||||
PyArrayObject* data_array = NULL;
|
||||
unsigned int def = 0;
|
||||
if (type == SKYLIGHT)
|
||||
def = 15;
|
||||
|
@ -194,14 +187,12 @@ static inline unsigned int get_data(RenderState *state, DataType type, int x, in
|
|||
if (chunky < 0 || chunky >= SECTIONS_PER_CHUNK)
|
||||
return def;
|
||||
|
||||
if (!(state->chunks[chunkx][chunkz].loaded))
|
||||
{
|
||||
if (!(state->chunks[chunkx][chunkz].loaded)) {
|
||||
if (load_chunk(state, chunkx - 1, chunkz - 1, 0))
|
||||
return def;
|
||||
}
|
||||
|
||||
switch (type)
|
||||
{
|
||||
switch (type) {
|
||||
case BLOCKS:
|
||||
data_array = state->chunks[chunkx][chunkz].sections[chunky].blocks;
|
||||
break;
|
||||
|
|
|
@ -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,13 +25,12 @@ 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;
|
||||
|
@ -48,8 +47,8 @@ base_start(void *data, RenderState *state, PyObject *support) {
|
|||
}
|
||||
|
||||
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);
|
||||
|
@ -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,12 +72,12 @@ 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);
|
||||
|
@ -95,15 +94,8 @@ 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
|
||||
},
|
||||
(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) ||
|
||||
|
@ -113,40 +105,24 @@ 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;
|
||||
|
@ -160,7 +136,7 @@ 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 */
|
||||
|
@ -232,7 +208,8 @@ base_draw(void *data, RenderState *state, PyObject *src, PyObject *mask, PyObjec
|
|||
}
|
||||
|
||||
RenderPrimitiveInterface primitive_base = {
|
||||
"base", sizeof(PrimitiveBase),
|
||||
"base",
|
||||
sizeof(PrimitiveBase),
|
||||
base_start,
|
||||
base_finish,
|
||||
base_occluded,
|
||||
|
|
|
@ -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 {
|
||||
|
@ -245,4 +244,3 @@ static Biome biome_table[] = {
|
|||
};
|
||||
|
||||
#define NUM_BIOMES (sizeof(biome_table) / sizeof(Biome))
|
||||
|
||||
|
|
|
@ -15,37 +15,37 @@
|
|||
* 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;
|
||||
}
|
||||
|
||||
|
@ -61,10 +61,10 @@ cave_occluded(void *data, RenderState *state, int x, int y, int z) {
|
|||
}
|
||||
|
||||
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)) {
|
||||
|
@ -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)) {
|
||||
(get_data(state, BLOCKS, x, y + 1, z) == 9)) {
|
||||
|
||||
for (dy = y+1; dy < (SECTIONS_PER_CHUNK - state->chunky) * 16; dy++) {
|
||||
for (dy = y + 1; dy < (SECTIONS_PER_CHUNK - state->chunky) * 16; dy++) {
|
||||
/* go up and check for skylight */
|
||||
if (get_data(state, SKYLIGHT, x, dy, z) != 0) {
|
||||
return 1;
|
||||
|
@ -103,9 +103,9 @@ 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;
|
||||
|
@ -114,7 +114,8 @@ cave_start(void *data, RenderState *state, PyObject *support) {
|
|||
}
|
||||
|
||||
RenderPrimitiveInterface primitive_cave = {
|
||||
"cave", sizeof(RenderPrimitiveCave),
|
||||
"cave",
|
||||
sizeof(RenderPrimitiveCave),
|
||||
cave_start,
|
||||
NULL,
|
||||
cave_occluded,
|
||||
|
|
|
@ -18,14 +18,14 @@
|
|||
#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;
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ clear_base_occluded(void *data, RenderState *state, int x, int y, int z) {
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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,18 +36,18 @@ 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;
|
||||
|
@ -56,15 +56,16 @@ depth_tinting_draw(void *data, RenderState *state, PyObject *src, PyObject *mask
|
|||
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,
|
||||
|
|
|
@ -23,8 +23,8 @@ 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;
|
||||
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -22,8 +22,8 @@ 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;
|
||||
|
@ -32,8 +32,8 @@ exposed_start(void *data, RenderState *state, PyObject *support) {
|
|||
}
|
||||
|
||||
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.
|
||||
|
@ -80,19 +80,18 @@ exposed_hidden(void *data, RenderState *state, int x, int y, int z) {
|
|||
}
|
||||
|
||||
/* 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;
|
||||
|
||||
}
|
||||
|
||||
/* 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 = {
|
||||
"exposed", sizeof(PrimitiveExposed),
|
||||
"exposed",
|
||||
sizeof(PrimitiveExposed),
|
||||
exposed_start,
|
||||
NULL,
|
||||
NULL,
|
||||
|
|
|
@ -18,14 +18,14 @@
|
|||
#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;
|
||||
|
@ -37,21 +37,21 @@ height_fading_start(void *data, RenderState *state, PyObject *support) {
|
|||
}
|
||||
|
||||
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);
|
||||
|
@ -68,7 +68,8 @@ height_fading_draw(void *data, RenderState *state, PyObject *src, PyObject *mask
|
|||
}
|
||||
|
||||
RenderPrimitiveInterface primitive_height_fading = {
|
||||
"height-fading", sizeof(PrimitiveHeightFading),
|
||||
"height-fading",
|
||||
sizeof(PrimitiveHeightFading),
|
||||
height_fading_start,
|
||||
height_fading_finish,
|
||||
NULL,
|
||||
|
|
|
@ -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,9 +29,9 @@ 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)))
|
||||
|
@ -51,7 +51,7 @@ 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 */
|
||||
|
@ -73,8 +73,8 @@ hide_start(void *data, RenderState *state, PyObject *support) {
|
|||
}
|
||||
|
||||
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);
|
||||
|
@ -82,8 +82,8 @@ hide_finish(void *data, RenderState *state) {
|
|||
}
|
||||
|
||||
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;
|
||||
|
||||
|
|
|
@ -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,12 +35,12 @@ 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);
|
||||
|
||||
|
@ -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,12 +70,12 @@ 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);
|
||||
|
@ -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;
|
||||
|
@ -120,8 +120,8 @@ estimate_blocklevel(RenderPrimitiveLighting *self, RenderState *state,
|
|||
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)) {
|
||||
|
@ -149,9 +149,9 @@ estimate_blocklevel(RenderPrimitiveLighting *self, RenderState *state,
|
|||
}
|
||||
|
||||
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;
|
||||
|
@ -163,7 +163,7 @@ get_lighting_color(RenderPrimitiveLighting *self, RenderState *state,
|
|||
|
||||
/* 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 */
|
||||
|
@ -182,10 +182,9 @@ get_lighting_color(RenderPrimitiveLighting *self, RenderState *state,
|
|||
/* 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;
|
||||
|
@ -198,7 +197,7 @@ get_lighting_color(RenderPrimitiveLighting *self, RenderState *state,
|
|||
|
||||
/* 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);
|
||||
|
@ -223,8 +222,8 @@ 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;
|
||||
|
||||
|
@ -243,9 +242,9 @@ do_shading_with_mask(RenderPrimitiveLighting *self, RenderState *state,
|
|||
}
|
||||
|
||||
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;
|
||||
|
@ -290,32 +289,32 @@ lighting_start(void *data, RenderState *state, PyObject *support) {
|
|||
}
|
||||
|
||||
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,
|
||||
|
|
|
@ -18,15 +18,15 @@
|
|||
#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
|
||||
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
@ -39,8 +38,7 @@ netherold_hidden(void *data, RenderState *state, int x, int y, int z) {
|
|||
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;
|
||||
}
|
||||
y++;
|
||||
|
@ -49,7 +47,8 @@ netherold_hidden(void *data, RenderState *state, int x, int y, int z) {
|
|||
}
|
||||
|
||||
RenderPrimitiveInterface primitive_nether_old = {
|
||||
"netherold", 0,
|
||||
"netherold",
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 {
|
||||
|
@ -73,17 +73,16 @@ static struct BiomeColor default_biomes[] = {
|
|||
{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;
|
||||
|
@ -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,7 +156,7 @@ 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;
|
||||
|
@ -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);
|
||||
|
|
|
@ -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 {
|
||||
|
@ -45,16 +45,15 @@ static struct MineralColor default_minerals[] = {
|
|||
{block_coal_ore, 54, 54, 54},
|
||||
|
||||
/* end of list marker */
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
{0, 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) {
|
||||
|
||||
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;
|
||||
|
@ -79,8 +78,8 @@ 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 */
|
||||
|
@ -89,13 +88,13 @@ overlay_mineral_start(void *data, RenderState *state, PyObject *support) {
|
|||
return ret;
|
||||
|
||||
/* now do custom initializations */
|
||||
self = (RenderPrimitiveMineral *)data;
|
||||
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 */
|
||||
|
||||
|
@ -111,7 +110,7 @@ overlay_mineral_start(void *data, RenderState *state, PyObject *support) {
|
|||
}
|
||||
|
||||
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;
|
||||
|
@ -129,9 +128,9 @@ overlay_mineral_start(void *data, RenderState *state, PyObject *support) {
|
|||
}
|
||||
|
||||
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);
|
||||
|
|
|
@ -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,16 +30,16 @@ 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) {
|
||||
|
@ -66,13 +66,14 @@ 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;
|
||||
|
@ -89,9 +90,9 @@ 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);
|
||||
|
@ -99,7 +100,7 @@ overlay_slime_start(void *data, RenderState *state, PyObject *support) {
|
|||
return ret;
|
||||
|
||||
/* now do custom initializations */
|
||||
self = (RenderPrimitiveSlime *)data;
|
||||
self = (RenderPrimitiveSlime*)data;
|
||||
self->parent.get_color = get_color;
|
||||
|
||||
self->parent.default_color.r = 40;
|
||||
|
@ -119,7 +120,7 @@ overlay_slime_start(void *data, RenderState *state, PyObject *support) {
|
|||
}
|
||||
|
||||
static void
|
||||
overlay_slime_finish(void *data, RenderState *state) {
|
||||
overlay_slime_finish(void* data, RenderState* state) {
|
||||
/* chain up */
|
||||
primitive_overlay.finish(data, state);
|
||||
}
|
||||
|
|
|
@ -15,17 +15,17 @@
|
|||
* 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;
|
||||
|
@ -56,7 +56,7 @@ 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 */
|
||||
|
@ -65,7 +65,7 @@ overlay_spawn_start(void *data, RenderState *state, PyObject *support) {
|
|||
return ret;
|
||||
|
||||
/* now do custom initializations */
|
||||
self = (RenderPrimitiveSpawn *)data;
|
||||
self = (RenderPrimitiveSpawn*)data;
|
||||
self->parent.get_color = get_color;
|
||||
|
||||
self->parent.default_color.r = 229;
|
||||
|
@ -77,7 +77,7 @@ overlay_spawn_start(void *data, RenderState *state, PyObject *support) {
|
|||
}
|
||||
|
||||
static void
|
||||
overlay_spawn_finish(void *data, RenderState *state) {
|
||||
overlay_spawn_finish(void* data, RenderState* state) {
|
||||
/* chain up */
|
||||
primitive_overlay.finish(data, state);
|
||||
}
|
||||
|
|
|
@ -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,7 +151,7 @@ static int overlay_structure_start(void *data, RenderState *state, PyObject *sup
|
|||
}
|
||||
|
||||
// Parse colorpy into a c-struct.
|
||||
if (!PyArg_ParseTuple( colorpy, "bbbb",
|
||||
if (!PyArg_ParseTuple(colorpy, "bbbb",
|
||||
&structures[i].r,
|
||||
&structures[i].g,
|
||||
&structures[i].b,
|
||||
|
@ -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,
|
||||
};
|
||||
|
||||
|
|
|
@ -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,10 +29,10 @@ 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");
|
||||
|
@ -49,15 +49,15 @@ overlay_start(void *data, RenderState *state, PyObject *support) {
|
|||
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,8 +67,8 @@ 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);
|
||||
|
@ -78,21 +78,20 @@ overlay_finish(void *data, RenderState *state) {
|
|||
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;
|
||||
int increment = 0;
|
||||
if (state->block == block_stone_slab) // half-step
|
||||
increment=6;
|
||||
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;
|
||||
}
|
||||
|
@ -116,7 +115,7 @@ overlay_draw(void *data, RenderState *state, PyObject *src, PyObject *mask, PyOb
|
|||
|
||||
/* 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 */
|
||||
|
@ -46,7 +46,7 @@ struct SmoothLightingFace {
|
|||
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;
|
||||
};
|
||||
|
||||
|
@ -72,70 +72,48 @@ 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},
|
||||
{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},
|
||||
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},
|
||||
{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},
|
||||
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},
|
||||
{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},
|
||||
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};
|
||||
|
@ -149,34 +127,41 @@ do_shading_with_rule(RenderPrimitiveSmoothLighting *self, RenderState *state, st
|
|||
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 += 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 += (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;
|
||||
|
@ -185,19 +170,19 @@ do_shading_with_rule(RenderPrimitiveSmoothLighting *self, RenderState *state, st
|
|||
|
||||
/* 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)
|
||||
|
@ -206,24 +191,21 @@ smooth_lighting_start(void *data, RenderState *state, PyObject *support) {
|
|||
}
|
||||
|
||||
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;
|
||||
|
@ -232,8 +214,7 @@ smooth_lighting_draw(void *data, RenderState *state, PyObject *src, PyObject *ma
|
|||
/* 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)))
|
||||
|
@ -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,
|
||||
|
|
|
@ -15,9 +15,9 @@
|
|||
* with the Overviewer. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "overviewer.h"
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include "overviewer.h"
|
||||
|
||||
/* this file defines render_primitives,
|
||||
a list of all render primitives, ending in NULL
|
||||
|
@ -30,11 +30,11 @@
|
|||
/* rendermode encapsulation */
|
||||
|
||||
/* helper to create a single primitive */
|
||||
RenderPrimitive *render_primitive_create(PyObject *prim, RenderState *state) {
|
||||
RenderPrimitive *ret = NULL;
|
||||
RenderPrimitiveInterface *iface = NULL;
|
||||
RenderPrimitive* render_primitive_create(PyObject* prim, RenderState* state) {
|
||||
RenderPrimitive* ret = NULL;
|
||||
RenderPrimitiveInterface* iface = NULL;
|
||||
unsigned int i;
|
||||
PyObject *pyname;
|
||||
PyObject* pyname;
|
||||
const char* name;
|
||||
|
||||
pyname = PyObject_GetAttrString(prim, "name");
|
||||
|
@ -51,18 +51,18 @@ RenderPrimitive *render_primitive_create(PyObject *prim, RenderState *state) {
|
|||
Py_DECREF(pyname);
|
||||
|
||||
if (iface == NULL)
|
||||
return (RenderPrimitive *)PyErr_Format(PyExc_RuntimeError, "invalid primitive name: %s", name);
|
||||
return (RenderPrimitive*)PyErr_Format(PyExc_RuntimeError, "invalid primitive name: %s", name);
|
||||
|
||||
ret = calloc(1, sizeof(RenderPrimitive));
|
||||
if (ret == NULL) {
|
||||
return (RenderPrimitive *)PyErr_Format(PyExc_RuntimeError, "Failed to alloc a render primitive");
|
||||
return (RenderPrimitive*)PyErr_Format(PyExc_RuntimeError, "Failed to alloc a render primitive");
|
||||
}
|
||||
|
||||
if (iface->data_size > 0) {
|
||||
ret->primitive = calloc(1, iface->data_size);
|
||||
if (ret->primitive == NULL) {
|
||||
free(ret);
|
||||
return (RenderPrimitive *)PyErr_Format(PyExc_RuntimeError, "Failed to alloc render primitive data");
|
||||
return (RenderPrimitive*)PyErr_Format(PyExc_RuntimeError, "Failed to alloc render primitive data");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,9 +79,9 @@ RenderPrimitive *render_primitive_create(PyObject *prim, RenderState *state) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
RenderMode *render_mode_create(PyObject *mode, RenderState *state) {
|
||||
RenderMode *ret = NULL;
|
||||
PyObject *mode_fast = NULL;
|
||||
RenderMode* render_mode_create(PyObject* mode, RenderState* state) {
|
||||
RenderMode* ret = NULL;
|
||||
PyObject* mode_fast = NULL;
|
||||
unsigned int i;
|
||||
|
||||
mode_fast = PySequence_Fast(mode, "Mode is not a sequence type");
|
||||
|
@ -93,8 +93,8 @@ RenderMode *render_mode_create(PyObject *mode, RenderState *state) {
|
|||
ret->num_primitives = PySequence_Length(mode);
|
||||
ret->primitives = calloc(ret->num_primitives, sizeof(RenderPrimitive*));
|
||||
for (i = 0; i < ret->num_primitives; i++) {
|
||||
PyObject *pyprim = PySequence_Fast_GET_ITEM(mode_fast, i);
|
||||
RenderPrimitive *prim = render_primitive_create(pyprim, state);
|
||||
PyObject* pyprim = PySequence_Fast_GET_ITEM(mode_fast, i);
|
||||
RenderPrimitive* prim = render_primitive_create(pyprim, state);
|
||||
|
||||
if (!prim) {
|
||||
render_mode_destroy(ret);
|
||||
|
@ -108,11 +108,11 @@ RenderMode *render_mode_create(PyObject *mode, RenderState *state) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
void render_mode_destroy(RenderMode *self) {
|
||||
void render_mode_destroy(RenderMode* self) {
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < self->num_primitives; i++) {
|
||||
RenderPrimitive *prim = self->primitives[i];
|
||||
RenderPrimitive* prim = self->primitives[i];
|
||||
/* we may be destroying a half-constructed mode, so we need this
|
||||
check */
|
||||
if (prim) {
|
||||
|
@ -129,11 +129,11 @@ void render_mode_destroy(RenderMode *self) {
|
|||
free(self);
|
||||
}
|
||||
|
||||
int render_mode_occluded(RenderMode *self, int x, int y, int z) {
|
||||
int render_mode_occluded(RenderMode* self, int x, int y, int z) {
|
||||
unsigned int i;
|
||||
int occluded = 0;
|
||||
for (i = 0; i < self->num_primitives; i++) {
|
||||
RenderPrimitive *prim = self->primitives[i];
|
||||
RenderPrimitive* prim = self->primitives[i];
|
||||
if (prim->iface->occluded) {
|
||||
occluded |= prim->iface->occluded(prim->primitive, self->state, x, y, z);
|
||||
}
|
||||
|
@ -144,11 +144,11 @@ int render_mode_occluded(RenderMode *self, int x, int y, int z) {
|
|||
return occluded;
|
||||
}
|
||||
|
||||
int render_mode_hidden(RenderMode *self, int x, int y, int z) {
|
||||
int render_mode_hidden(RenderMode* self, int x, int y, int z) {
|
||||
unsigned int i;
|
||||
int hidden = 0;
|
||||
for (i = 0; i < self->num_primitives; i++) {
|
||||
RenderPrimitive *prim = self->primitives[i];
|
||||
RenderPrimitive* prim = self->primitives[i];
|
||||
if (prim->iface->hidden) {
|
||||
hidden |= prim->iface->hidden(prim->primitive, self->state, x, y, z);
|
||||
}
|
||||
|
@ -159,10 +159,10 @@ int render_mode_hidden(RenderMode *self, int x, int y, int z) {
|
|||
return hidden;
|
||||
}
|
||||
|
||||
void render_mode_draw(RenderMode *self, PyObject *img, PyObject *mask, PyObject *mask_light) {
|
||||
void render_mode_draw(RenderMode* self, PyObject* img, PyObject* mask, PyObject* mask_light) {
|
||||
unsigned int i;
|
||||
for (i = 0; i < self->num_primitives; i++) {
|
||||
RenderPrimitive *prim = self->primitives[i];
|
||||
RenderPrimitive* prim = self->primitives[i];
|
||||
if (prim->iface->draw) {
|
||||
prim->iface->draw(prim->primitive, self->state, img, mask, mask_light);
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ void render_mode_draw(RenderMode *self, PyObject *img, PyObject *mask, PyObject
|
|||
}
|
||||
|
||||
/* options parse helper */
|
||||
int render_mode_parse_option(PyObject *support, const char *name, const char *format, ...) {
|
||||
int render_mode_parse_option(PyObject* support, const char* name, const char* format, ...) {
|
||||
va_list ap;
|
||||
PyObject *item, *dict;
|
||||
int ret;
|
||||
|
|
|
@ -47,20 +47,20 @@
|
|||
/* render primitive interface */
|
||||
typedef struct {
|
||||
/* the name of this mode */
|
||||
const char *name;
|
||||
const char* name;
|
||||
/* the size of the local storage for this rendermode */
|
||||
unsigned int data_size;
|
||||
|
||||
/* may return non-zero on error, last arg is the python support object */
|
||||
int (*start)(void *, RenderState *, PyObject *);
|
||||
void (*finish)(void *, RenderState *);
|
||||
int (*start)(void*, RenderState*, PyObject*);
|
||||
void (*finish)(void*, RenderState*);
|
||||
/* returns non-zero to skip rendering this block because it's not visible */
|
||||
int (*occluded)(void *, RenderState *, int, int, int);
|
||||
int (*occluded)(void*, RenderState*, int, int, int);
|
||||
/* returns non-zero to skip rendering this block because the user doesn't
|
||||
* want it visible */
|
||||
int (*hidden)(void *, RenderState *, int, int, int);
|
||||
int (*hidden)(void*, RenderState*, int, int, int);
|
||||
/* last two arguments are img and mask, from texture lookup */
|
||||
void (*draw)(void *, RenderState *, PyObject *, PyObject *, PyObject *);
|
||||
void (*draw)(void*, RenderState*, PyObject*, PyObject*, PyObject*);
|
||||
} RenderPrimitiveInterface;
|
||||
|
||||
/* A quick note about the difference between occluded and hidden:
|
||||
|
@ -80,26 +80,26 @@ typedef struct {
|
|||
|
||||
/* convenience wrapper for a single primitive + interface */
|
||||
typedef struct {
|
||||
void *primitive;
|
||||
RenderPrimitiveInterface *iface;
|
||||
void* primitive;
|
||||
RenderPrimitiveInterface* iface;
|
||||
} RenderPrimitive;
|
||||
|
||||
/* wrapper for passing around rendermodes */
|
||||
struct _RenderMode {
|
||||
unsigned int num_primitives;
|
||||
RenderPrimitive **primitives;
|
||||
RenderState *state;
|
||||
RenderPrimitive** primitives;
|
||||
RenderState* state;
|
||||
};
|
||||
|
||||
/* functions for creating / using rendermodes */
|
||||
RenderMode *render_mode_create(PyObject *mode, RenderState *state);
|
||||
void render_mode_destroy(RenderMode *self);
|
||||
int render_mode_occluded(RenderMode *self, int x, int y, int z);
|
||||
int render_mode_hidden(RenderMode *self, int x, int y, int z);
|
||||
void render_mode_draw(RenderMode *self, PyObject *img, PyObject *mask, PyObject *mask_light);
|
||||
RenderMode* render_mode_create(PyObject* mode, RenderState* state);
|
||||
void render_mode_destroy(RenderMode* self);
|
||||
int render_mode_occluded(RenderMode* self, int x, int y, int z);
|
||||
int render_mode_hidden(RenderMode* self, int x, int y, int z);
|
||||
void render_mode_draw(RenderMode* self, PyObject* img, PyObject* mask, PyObject* mask_light);
|
||||
|
||||
/* helper function for reading in rendermode options
|
||||
works like PyArg_ParseTuple on a support object */
|
||||
int render_mode_parse_option(PyObject *support, const char *name, const char *format, ...);
|
||||
int render_mode_parse_option(PyObject* support, const char* name, const char* format, ...);
|
||||
|
||||
#endif /* __RENDERMODES_H_INCLUDED__ */
|
||||
|
|
|
@ -8,10 +8,10 @@
|
|||
|
||||
/* like (a * b + 127) / 255), but much faster on most platforms
|
||||
from PIL's _imaging.c */
|
||||
#define OV_MULDIV255(a, b, tmp)\
|
||||
#define OV_MULDIV255(a, b, tmp) \
|
||||
(tmp = (a) * (b) + 128, ((((tmp) >> 8) + (tmp)) >> 8))
|
||||
|
||||
#define OV_BLEND(mask, in1, in2, tmp1, tmp2)\
|
||||
#define OV_BLEND(mask, in1, in2, tmp1, tmp2) \
|
||||
(OV_MULDIV255(in1, 255 - mask, tmp1) + OV_MULDIV255(in2, mask, tmp2))
|
||||
|
||||
#define COUNT_OF(array) \
|
||||
|
|
Loading…
Reference in New Issue