c_overviewer.render_loop now works with normal render mode
This commit is contained in:
@@ -365,8 +365,9 @@ def generate_facemasks():
|
||||
left = Image.new("L", (24,24), 0)
|
||||
whole = Image.new("L", (24,24), 0)
|
||||
|
||||
toppart = textures.transform_image_top(white)
|
||||
leftpart = textures.transform_image_side(white)
|
||||
tex = textures.Textures()
|
||||
toppart = tex.transform_image_top(white)
|
||||
leftpart = tex.transform_image_side(white)
|
||||
|
||||
# using the real PIL paste here (not alpha_over) because there is
|
||||
# no alpha channel (and it's mode "L")
|
||||
|
||||
@@ -96,6 +96,52 @@ PyObject *init_chunk_render(PyObject *self, PyObject *args) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyObject *get_chunk_data(PyObject *region_set, int x, int z, ChunkNeighborName neighbor, ChunkDataType type) {
|
||||
PyObject *chunk = NULL;
|
||||
PyObject *data = NULL;
|
||||
|
||||
switch (neighbor) {
|
||||
case CURRENT:
|
||||
break;
|
||||
case DOWN_RIGHT:
|
||||
z++;
|
||||
break;
|
||||
case DOWN_LEFT:
|
||||
x--;
|
||||
break;
|
||||
case UP_RIGHT:
|
||||
x++;
|
||||
break;
|
||||
case UP_LEFT:
|
||||
z--;
|
||||
break;
|
||||
}
|
||||
|
||||
chunk = PyObject_CallMethod(region_set, "get_chunk", "ii", x, z);
|
||||
if (chunk == NULL || chunk == Py_None)
|
||||
return chunk;
|
||||
|
||||
switch (type) {
|
||||
case BLOCKS:
|
||||
data = PyDict_GetItemString(chunk, "Blocks");
|
||||
break;
|
||||
case BLOCKDATA:
|
||||
data = PyDict_GetItemString(chunk, "Data");
|
||||
break;
|
||||
case SKYLIGHT:
|
||||
data = PyDict_GetItemString(chunk, "SkyLight");
|
||||
break;
|
||||
case BLOCKLIGHT:
|
||||
data = PyDict_GetItemString(chunk, "BlockLight");
|
||||
break;
|
||||
}
|
||||
|
||||
/* fix the borrowed reference */
|
||||
Py_INCREF(data);
|
||||
Py_DECREF(chunk);
|
||||
return data;
|
||||
}
|
||||
|
||||
unsigned char
|
||||
check_adjacent_blocks(RenderState *state, int x,int y,int z, unsigned char blockid) {
|
||||
/*
|
||||
@@ -332,7 +378,9 @@ generate_pseudo_data(RenderState *state, unsigned char ancilData) {
|
||||
PyObject*
|
||||
chunk_render(PyObject *self, PyObject *args) {
|
||||
RenderState state;
|
||||
PyObject *rendermode_py;
|
||||
PyObject *regionset;
|
||||
int chunkx, chunkz;
|
||||
const char* rendermode_name = NULL;
|
||||
PyObject *blockmap;
|
||||
|
||||
int xoff, yoff;
|
||||
@@ -350,20 +398,23 @@ chunk_render(PyObject *self, PyObject *args) {
|
||||
|
||||
PyObject *t = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "OOiiO", &state.self, &state.img, &xoff, &yoff, &state.textures, &state.blockdatas))
|
||||
if (!PyArg_ParseTuple(args, "OiiOiisO", &state.regionset, &state.chunkx, &state.chunkz, &state.img, &xoff, &yoff, &rendermode_name, &state.textures))
|
||||
return NULL;
|
||||
|
||||
/* conveniences */
|
||||
regionset = state.regionset;
|
||||
chunkx = state.chunkx;
|
||||
chunkz = state.chunkz;
|
||||
|
||||
/* set up the render mode */
|
||||
rendermode_py = PyObject_GetAttrString(state.self, "rendermode");
|
||||
state.rendermode = rendermode = render_mode_create(PyString_AsString(rendermode_py), &state);
|
||||
Py_DECREF(rendermode_py);
|
||||
state.rendermode = rendermode = render_mode_create(rendermode_name, &state);
|
||||
if (rendermode == NULL) {
|
||||
return NULL; // note that render_mode_create will
|
||||
// set PyErr. No need to set it here
|
||||
}
|
||||
|
||||
/* get the blockmap from the textures object */
|
||||
blockmap = PyObject_GetAttr(state.textures, "blockmap");
|
||||
blockmap = PyObject_GetAttrString(state.textures, "blockmap");
|
||||
if (blockmap == NULL)
|
||||
return NULL;
|
||||
if (blockmap == Py_None) {
|
||||
@@ -371,12 +422,6 @@ chunk_render(PyObject *self, PyObject *args) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* get the chunk module */
|
||||
state.chunk = PyImport_ImportModule("overviewer_core.chunk");
|
||||
if (state.chunk == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* get the image size */
|
||||
imgsize = PyObject_GetAttrString(state.img, "size");
|
||||
|
||||
@@ -390,19 +435,25 @@ chunk_render(PyObject *self, PyObject *args) {
|
||||
Py_DECREF(imgsize1_py);
|
||||
|
||||
/* get the block data directly from numpy: */
|
||||
blocks_py = PyObject_GetAttrString(state.self, "blocks");
|
||||
blocks_py = get_chunk_data(regionset, chunkx, chunkz, CURRENT, BLOCKS);
|
||||
state.blocks = blocks_py;
|
||||
if (blocks_py == Py_None) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "chunk does not exist!");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
state.blockdatas = get_chunk_data(regionset, chunkx, chunkz, CURRENT, BLOCKDATA);
|
||||
|
||||
left_blocks_py = PyObject_GetAttrString(state.self, "left_blocks");
|
||||
left_blocks_py = get_chunk_data(regionset, chunkx, chunkz, DOWN_LEFT, BLOCKS);
|
||||
state.left_blocks = left_blocks_py;
|
||||
|
||||
right_blocks_py = PyObject_GetAttrString(state.self, "right_blocks");
|
||||
right_blocks_py = get_chunk_data(regionset, chunkx, chunkz, DOWN_RIGHT, BLOCKS);
|
||||
state.right_blocks = right_blocks_py;
|
||||
|
||||
up_left_blocks_py = PyObject_GetAttrString(state.self, "up_left_blocks");
|
||||
up_left_blocks_py = get_chunk_data(regionset, chunkx, chunkz, UP_LEFT, BLOCKS);
|
||||
state.up_left_blocks = up_left_blocks_py;
|
||||
|
||||
up_right_blocks_py = PyObject_GetAttrString(state.self, "up_right_blocks");
|
||||
up_right_blocks_py = get_chunk_data(regionset, chunkx, chunkz, UP_RIGHT, BLOCKS);
|
||||
state.up_right_blocks = up_right_blocks_py;
|
||||
|
||||
/* set up the random number generator again for each chunk
|
||||
|
||||
@@ -65,20 +65,20 @@ typedef struct _RenderMode RenderMode;
|
||||
|
||||
/* in iterate.c */
|
||||
typedef struct {
|
||||
/* the ChunkRenderer object, and the chunk module */
|
||||
PyObject *self;
|
||||
PyObject *chunk;
|
||||
|
||||
/* the Texture object */
|
||||
PyObject *textures;
|
||||
|
||||
/* the current render mode in use */
|
||||
RenderMode *rendermode;
|
||||
/* the regionset object, and chunk coords */
|
||||
PyObject *regionset;
|
||||
int chunkx, chunkz;
|
||||
|
||||
/* the tile image and destination */
|
||||
PyObject *img;
|
||||
int imgx, imgy;
|
||||
|
||||
/* the current render mode in use */
|
||||
RenderMode *rendermode;
|
||||
|
||||
/* the Texture object */
|
||||
PyObject *textures;
|
||||
|
||||
/* the block position and type, and the block array */
|
||||
int x, y, z;
|
||||
unsigned char block;
|
||||
@@ -121,6 +121,24 @@ block_has_property(unsigned char b, BlockProperty prop) {
|
||||
}
|
||||
#define is_transparent(b) block_has_property((b), TRANSPARENT)
|
||||
|
||||
/* helper for getting chunk data arrays */
|
||||
typedef enum
|
||||
{
|
||||
BLOCKS,
|
||||
BLOCKDATA,
|
||||
BLOCKLIGHT,
|
||||
SKYLIGHT,
|
||||
} ChunkDataType;
|
||||
typedef enum
|
||||
{
|
||||
CURRENT,
|
||||
DOWN_RIGHT, /* 0, +1 */
|
||||
DOWN_LEFT, /* -1, 0 */
|
||||
UP_RIGHT, /* +1, 0 */
|
||||
UP_LEFT, /* 0, -1 */
|
||||
} ChunkNeighborName;
|
||||
PyObject *get_chunk_data(PyObject *region_set, int x, int z, ChunkNeighborName neighbor, ChunkDataType type);
|
||||
|
||||
/* pull in the rendermode info */
|
||||
#include "rendermodes.h"
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
static int
|
||||
rendermode_normal_start(void *data, RenderState *state, PyObject *options) {
|
||||
PyObject *chunk_x_py, *chunk_y_py, *world, *use_biomes, *worlddir;
|
||||
RenderModeNormal *self = (RenderModeNormal *)data;
|
||||
|
||||
/* load up the given options, first */
|
||||
@@ -37,28 +36,26 @@ rendermode_normal_start(void *data, RenderState *state, PyObject *options) {
|
||||
return 1;
|
||||
|
||||
self->height_fading = 0;
|
||||
if (!render_mode_parse_option(options, "height_fading", "i", &(self->height_fading)))
|
||||
return 1;
|
||||
/* XXX skip height fading */
|
||||
/*if (!render_mode_parse_option(options, "height_fading", "i", &(self->height_fading)))
|
||||
return 1;*/
|
||||
|
||||
self->nether = 0;
|
||||
if (!render_mode_parse_option(options, "nether", "i", &(self->nether)))
|
||||
return 1;
|
||||
|
||||
if (self->height_fading) {
|
||||
/*if (self->height_fading) {
|
||||
self->black_color = PyObject_GetAttrString(state->chunk, "black_color");
|
||||
self->white_color = PyObject_GetAttrString(state->chunk, "white_color");
|
||||
}
|
||||
}*/
|
||||
|
||||
/* biome-compliant grass mask (includes sides!) */
|
||||
self->grass_texture = PyObject_GetAttrString(state->textures, "biome_grass_texture");
|
||||
|
||||
chunk_x_py = PyObject_GetAttrString(state->self, "chunkX");
|
||||
chunk_y_py = PyObject_GetAttrString(state->self, "chunkY");
|
||||
|
||||
/* careful now -- C's % operator works differently from python's
|
||||
we can't just do x % 32 like we did before */
|
||||
self->chunk_x = PyInt_AsLong(chunk_x_py);
|
||||
self->chunk_y = PyInt_AsLong(chunk_y_py);
|
||||
self->chunk_x = state->chunkx;
|
||||
self->chunk_y = state->chunkz;
|
||||
|
||||
while (self->chunk_x < 0)
|
||||
self->chunk_x += 32;
|
||||
@@ -68,14 +65,8 @@ rendermode_normal_start(void *data, RenderState *state, PyObject *options) {
|
||||
self->chunk_x %= 32;
|
||||
self->chunk_y %= 32;
|
||||
|
||||
/* fetch the biome data from textures.py, if needed */
|
||||
world = PyObject_GetAttrString(state->self, "world");
|
||||
worlddir = PyObject_GetAttrString(world, "worlddir");
|
||||
use_biomes = PyObject_GetAttrString(world, "useBiomeData");
|
||||
Py_DECREF(world);
|
||||
|
||||
/* XXX ignore biomes for now :( */
|
||||
if (0/*PyObject_IsTrue(use_biomes)*/) {
|
||||
/*if (PyObject_IsTrue(use_biomes)) {
|
||||
self->biome_data = PyObject_CallMethod(state->textures, "getBiomeData", "OOO",
|
||||
worlddir, chunk_x_py, chunk_y_py);
|
||||
if (self->biome_data == Py_None) {
|
||||
@@ -93,17 +84,12 @@ rendermode_normal_start(void *data, RenderState *state, PyObject *options) {
|
||||
self->watercolor = NULL;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
} else {*/
|
||||
self->biome_data = NULL;
|
||||
self->foliagecolor = NULL;
|
||||
self->grasscolor = NULL;
|
||||
self->watercolor = NULL;
|
||||
}
|
||||
|
||||
Py_DECREF(use_biomes);
|
||||
Py_DECREF(worlddir);
|
||||
Py_DECREF(chunk_x_py);
|
||||
Py_DECREF(chunk_y_py);
|
||||
/*}*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -24,11 +24,11 @@
|
||||
that are only useful as a base for other modes. */
|
||||
static RenderModeInterface *render_modes[] = {
|
||||
&rendermode_normal,
|
||||
&rendermode_lighting,
|
||||
/*&rendermode_lighting,
|
||||
&rendermode_smooth_lighting,
|
||||
&rendermode_spawn,
|
||||
&rendermode_cave,
|
||||
&rendermode_mineral,
|
||||
&rendermode_mineral,*/
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user