Initial Python 3 port
Many things work, some don't. Notably, genPOI doesn't work, and there's some signedness comparison stuff going on in the C extension. This also completely drops support for Python 2, as maintaining a C extension for both Python 2 and 3 is a pain and not worth it for the 9 months that Python 2 is still going to be supported upstream. The documentation needs to be adjusted as well. All of the few tests we have pass, and rendering a map works, both with a configuration file and without. We can also use optimizeimages. Concerns #1528.
This commit is contained in:
@@ -40,7 +40,6 @@ PyObject *init_chunk_render(void) {
|
||||
if (textures) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
textures = PyImport_ImportModule("overviewer_core.textures");
|
||||
/* ensure none of these pointers are NULL */
|
||||
if ((!textures)) {
|
||||
@@ -50,13 +49,13 @@ PyObject *init_chunk_render(void) {
|
||||
tmp = PyObject_GetAttrString(textures, "max_blockid");
|
||||
if (!tmp)
|
||||
return NULL;
|
||||
max_blockid = PyInt_AsLong(tmp);
|
||||
max_blockid = PyLong_AsLong(tmp);
|
||||
Py_DECREF(tmp);
|
||||
|
||||
tmp = PyObject_GetAttrString(textures, "max_data");
|
||||
if (!tmp)
|
||||
return NULL;
|
||||
max_data = PyInt_AsLong(tmp);
|
||||
max_data = PyLong_AsLong(tmp);
|
||||
Py_DECREF(tmp);
|
||||
|
||||
/* assemble the property table */
|
||||
@@ -81,7 +80,7 @@ PyObject *init_chunk_render(void) {
|
||||
|
||||
block_properties = calloc(max_blockid, sizeof(unsigned char));
|
||||
for (i = 0; i < max_blockid; i++) {
|
||||
PyObject *block = PyInt_FromLong(i);
|
||||
PyObject *block = PyLong_FromLong(i);
|
||||
|
||||
if (PySequence_Contains(known_blocks, block))
|
||||
block_properties[i] |= 1 << KNOWN;
|
||||
@@ -177,7 +176,7 @@ int load_chunk(RenderState* state, int x, int z, unsigned char required) {
|
||||
if (!ycoord)
|
||||
continue;
|
||||
|
||||
sectiony = PyInt_AsLong(ycoord);
|
||||
sectiony = PyLong_AsLong(ycoord);
|
||||
if (sectiony >= 0 && sectiony < SECTIONS_PER_CHUNK)
|
||||
load_chunk_section(dest, sectiony, section);
|
||||
}
|
||||
@@ -487,7 +486,7 @@ generate_pseudo_data(RenderState *state, unsigned short ancilData) {
|
||||
PyObject *texrot;
|
||||
int northdir;
|
||||
texrot = PyObject_GetAttrString(state->textures, "rotation");
|
||||
northdir = PyInt_AsLong(texrot);
|
||||
northdir = PyLong_AsLong(texrot);
|
||||
|
||||
/* fix the rotation value for different northdirections */
|
||||
#define FIX_ROT(x) (((x) & ~0x3) | repair_rot[((x) & 0x3) | (northdir << 2)])
|
||||
@@ -617,8 +616,8 @@ chunk_render(PyObject *self, PyObject *args) {
|
||||
imgsize1_py = PySequence_GetItem(imgsize, 1);
|
||||
Py_DECREF(imgsize);
|
||||
|
||||
imgsize0 = PyInt_AsLong(imgsize0_py);
|
||||
imgsize1 = PyInt_AsLong(imgsize1_py);
|
||||
imgsize0 = PyLong_AsLong(imgsize0_py);
|
||||
imgsize1 = PyLong_AsLong(imgsize1_py);
|
||||
Py_DECREF(imgsize0_py);
|
||||
Py_DECREF(imgsize1_py);
|
||||
|
||||
|
||||
@@ -38,12 +38,20 @@ static PyMethodDef COverviewerMethods[] = {
|
||||
{NULL, NULL, 0, NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
static PyModuleDef COverviewerModule = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"c_overviewer",
|
||||
"", // TODO: Add documentation here.
|
||||
-1,
|
||||
COverviewerMethods
|
||||
};
|
||||
|
||||
|
||||
PyMODINIT_FUNC
|
||||
initc_overviewer(void)
|
||||
PyInit_c_overviewer(void)
|
||||
{
|
||||
PyObject *mod, *numpy;
|
||||
mod = Py_InitModule("c_overviewer", COverviewerMethods);
|
||||
mod = PyModule_Create(&COverviewerModule);
|
||||
|
||||
/* for numpy
|
||||
normally you should use import_array(), but that will break across
|
||||
@@ -57,8 +65,9 @@ initc_overviewer(void)
|
||||
if (!init_chunk_render()) {
|
||||
PyErr_Print();
|
||||
exit(1);
|
||||
return;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
init_endian();
|
||||
return mod;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
|
||||
// increment this value if you've made a change to the c extesion
|
||||
// and want to force users to rebuild
|
||||
#define OVERVIEWER_EXTENSION_VERSION 56
|
||||
#define OVERVIEWER_EXTENSION_VERSION 57
|
||||
|
||||
/* Python PIL, and numpy headers */
|
||||
#include <Python.h>
|
||||
|
||||
@@ -234,9 +234,9 @@ base_draw(void *data, RenderState *state, PyObject *src, PyObject *mask, PyObjec
|
||||
|
||||
/* look up color! */
|
||||
color = PySequence_GetItem(color_table, tabley * 256 + tablex);
|
||||
r = PyInt_AsLong(PyTuple_GET_ITEM(color, 0));
|
||||
g = PyInt_AsLong(PyTuple_GET_ITEM(color, 1));
|
||||
b = PyInt_AsLong(PyTuple_GET_ITEM(color, 2));
|
||||
r = PyLong_AsLong(PyTuple_GET_ITEM(color, 0));
|
||||
g = PyLong_AsLong(PyTuple_GET_ITEM(color, 1));
|
||||
b = PyLong_AsLong(PyTuple_GET_ITEM(color, 2));
|
||||
Py_DECREF(color);
|
||||
|
||||
/* do the after-coloration */
|
||||
|
||||
@@ -56,9 +56,9 @@ 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 = PyInt_AsLong(PyList_GetItem(self->depth_colors, 0 + y*3));
|
||||
g = PyInt_AsLong(PyList_GetItem(self->depth_colors, 1 + y*3));
|
||||
b = PyInt_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);
|
||||
}
|
||||
|
||||
@@ -52,9 +52,9 @@ hide_start(void *data, RenderState *state, PyObject *support) {
|
||||
for (i = 0; i < blocks_size; i++) {
|
||||
PyObject *block = PyList_GET_ITEM(opt, i);
|
||||
|
||||
if (PyInt_Check(block)) {
|
||||
if (PyLong_Check(block)) {
|
||||
/* format 1: just a block id */
|
||||
self->rules[i].blockid = PyInt_AsLong(block);
|
||||
self->rules[i].blockid = PyLong_AsLong(block);
|
||||
self->rules[i].has_data = 0;
|
||||
} else if (PyArg_ParseTuple(block, "Hb", &(self->rules[i].blockid), &(self->rules[i].data))) {
|
||||
/* format 2: (blockid, data) */
|
||||
|
||||
@@ -45,9 +45,9 @@ calculate_light_color_fancy(void *data,
|
||||
index = skylight + blocklight * 16;
|
||||
color = PySequence_GetItem(mode->lightcolor, index);
|
||||
|
||||
*r = PyInt_AsLong(PyTuple_GET_ITEM(color, 0));
|
||||
*g = PyInt_AsLong(PyTuple_GET_ITEM(color, 1));
|
||||
*b = PyInt_AsLong(PyTuple_GET_ITEM(color, 2));
|
||||
*r = PyLong_AsLong(PyTuple_GET_ITEM(color, 0));
|
||||
*g = PyLong_AsLong(PyTuple_GET_ITEM(color, 1));
|
||||
*b = PyLong_AsLong(PyTuple_GET_ITEM(color, 2));
|
||||
|
||||
Py_DECREF(color);
|
||||
}
|
||||
@@ -78,9 +78,9 @@ calculate_light_color_fancy_night(void *data,
|
||||
index = skylight + blocklight * 16;
|
||||
color = PySequence_GetItem(mode->lightcolor, index);
|
||||
|
||||
*r = PyInt_AsLong(PyTuple_GET_ITEM(color, 0));
|
||||
*g = PyInt_AsLong(PyTuple_GET_ITEM(color, 1));
|
||||
*b = PyInt_AsLong(PyTuple_GET_ITEM(color, 2));
|
||||
*r = PyLong_AsLong(PyTuple_GET_ITEM(color, 0));
|
||||
*g = PyLong_AsLong(PyTuple_GET_ITEM(color, 1));
|
||||
*b = PyLong_AsLong(PyTuple_GET_ITEM(color, 2));
|
||||
|
||||
Py_DECREF(color);
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ RenderPrimitive *render_primitive_create(PyObject *prim, RenderState *state) {
|
||||
pyname = PyObject_GetAttrString(prim, "name");
|
||||
if (!pyname)
|
||||
return NULL;
|
||||
name = PyString_AsString(pyname);
|
||||
name = PyUnicode_AsUTF8(pyname);
|
||||
|
||||
for (i = 0; render_primitives[i] != NULL; i++) {
|
||||
if (strcmp(render_primitives[i]->name, name) == 0) {
|
||||
@@ -204,11 +204,10 @@ int render_mode_parse_option(PyObject *support, const char *name, const char *fo
|
||||
Py_DECREF(dict);
|
||||
|
||||
if (!ret) {
|
||||
PyObject *errtype, *errvalue, *errtraceback;
|
||||
const char *errstring;
|
||||
PyObject *errtype, *errvalue, *errtraceback, *errstring;
|
||||
|
||||
PyErr_Fetch(&errtype, &errvalue, &errtraceback);
|
||||
errstring = PyString_AsString(errvalue);
|
||||
errstring = PyUnicode_AsUTF8String(errvalue);
|
||||
|
||||
PyErr_Format(PyExc_TypeError, "rendermode option \"%s\" has incorrect type (%s)", name, errstring);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user