provided options are now checked against the available options
This commit is contained in:
@@ -148,7 +148,9 @@ class RenderNode(object):
|
|||||||
pool = FakePool()
|
pool = FakePool()
|
||||||
pool_initializer(self)
|
pool_initializer(self)
|
||||||
else:
|
else:
|
||||||
|
pool_initializer(self)
|
||||||
pool = multiprocessing.Pool(processes=procs,initializer=pool_initializer,initargs=(self,))
|
pool = multiprocessing.Pool(processes=procs,initializer=pool_initializer,initargs=(self,))
|
||||||
|
|
||||||
#warm up the pool so it reports all the worker id's
|
#warm up the pool so it reports all the worker id's
|
||||||
if logging.getLogger().level >= 10:
|
if logging.getLogger().level >= 10:
|
||||||
pool.map(bool,xrange(multiprocessing.cpu_count()),1)
|
pool.map(bool,xrange(multiprocessing.cpu_count()),1)
|
||||||
|
|||||||
@@ -26,11 +26,10 @@ static PyObject *transparent_blocks = NULL;
|
|||||||
|
|
||||||
PyObject *init_chunk_render(PyObject *self, PyObject *args) {
|
PyObject *init_chunk_render(PyObject *self, PyObject *args) {
|
||||||
|
|
||||||
/* this function only needs to be called once, anything more is an
|
/* this function only needs to be called once, anything more should be
|
||||||
* error... */
|
* ignored */
|
||||||
if (blockmap) {
|
if (blockmap) {
|
||||||
PyErr_SetString(PyExc_RuntimeError, "init_chunk_render should only be called once per process.");
|
Py_RETURN_NONE;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
textures = PyImport_ImportModule("textures");
|
textures = PyImport_ImportModule("textures");
|
||||||
|
|||||||
@@ -301,14 +301,56 @@ PyObject *get_render_mode_options(PyObject *self, PyObject *args)
|
|||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* helper to decide if a rendermode supports a given option */
|
||||||
|
static inline int
|
||||||
|
render_mode_supports_option(RenderModeInterface *iface, const char *name) {
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
if (iface->options != NULL) {
|
||||||
|
for (i = 0; iface->options[i].name != NULL; i++) {
|
||||||
|
if (strcmp(iface->options[i].name, name) == 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (iface->parent != NULL)
|
||||||
|
return render_mode_supports_option(iface->parent, name);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* python rendermode options bindings */
|
/* python rendermode options bindings */
|
||||||
PyObject *set_render_mode_options(PyObject *self, PyObject *args) {
|
PyObject *set_render_mode_options(PyObject *self, PyObject *args) {
|
||||||
const char *rendermode;
|
const char *rendermode;
|
||||||
PyObject *opts;
|
PyObject *opts, *key, *value;
|
||||||
|
Py_ssize_t pos = 0;
|
||||||
|
RenderModeInterface *iface = NULL;
|
||||||
|
unsigned int i;
|
||||||
if (!PyArg_ParseTuple(args, "sO!", &rendermode, &PyDict_Type, &opts))
|
if (!PyArg_ParseTuple(args, "sO!", &rendermode, &PyDict_Type, &opts))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* check options here */
|
for (i = 0; render_modes[i] != NULL; i++) {
|
||||||
|
if (strcmp(render_modes[i]->name, rendermode) == 0) {
|
||||||
|
iface = render_modes[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (iface == NULL) {
|
||||||
|
return PyErr_Format(PyExc_ValueError, "'%s' is not a valid rendermode name", rendermode);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* check options to make sure they're available */
|
||||||
|
while (PyDict_Next(opts, &pos, &key, &value)) {
|
||||||
|
const char *name = PyString_AsString(key);
|
||||||
|
if (name == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (!render_mode_supports_option(iface, name)) {
|
||||||
|
return PyErr_Format(PyExc_ValueError, "'%s' is not a valid option for rendermode '%s'", name, rendermode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (render_mode_options == NULL)
|
if (render_mode_options == NULL)
|
||||||
render_mode_options = PyDict_New();
|
render_mode_options = PyDict_New();
|
||||||
|
|||||||
Reference in New Issue
Block a user