Fix Python state tracker.

This commit is contained in:
Themaister 2012-11-18 21:23:34 +01:00
parent fd58a38ff2
commit e5acc803e9
3 changed files with 31 additions and 23 deletions

View File

@ -74,12 +74,12 @@ static PyObject *py_read_input(PyObject *self, PyObject *args)
g_settings.input.binds[2],
g_settings.input.binds[3],
g_settings.input.binds[4],
g_settings.input.binds[5],
g_settings.input.binds[6],
g_settings.input.binds[7],
};
int16_t res = input_input_state_func(binds, player > 1,
player > 2 ? RETRO_DEVICE_JOYPAD_MULTITAP : RETRO_DEVICE_JOYPAD,
player > 2 ? player - 2 : 0,
key);
int16_t res = input_input_state_func(binds, player - 1, RETRO_DEVICE_JOYPAD, 0, key);
return PyBool_FromLong(res);
}
@ -151,6 +151,11 @@ static void py_set_attrs(PyObject *mod)
DECL_ATTR_RARCH(SCREENSHOT);
DECL_ATTR_RARCH(DSP_CONFIG);
DECL_ATTR_RARCH(MUTE);
DECL_ATTR_RARCH(NETPLAY_FLIP);
DECL_ATTR_RARCH(SLOWMOTION);
DECL_ATTR_RARCH(ENABLE_HOTKEY);
DECL_ATTR_RARCH(VOLUME_UP);
DECL_ATTR_RARCH(VOLUME_DOWN);
}
static PyModuleDef RarchModule = {
@ -252,7 +257,7 @@ py_state_t *py_state_new(const char *script, unsigned is_file, const char *pycla
{
// Have to hack around the fact that the
// FILE struct isn't standardized across environments.
// PyRun_SimpleFile() breaks on Windows.
// PyRun_SimpleFile() breaks on Windows because it's compiled with MSVC.
char *script_ = NULL;
if (read_file(script, (void**)&script_) < 0)
@ -330,7 +335,12 @@ float py_state_get(py_state_t *handle, const char *id,
if (!ret)
{
if (!handle->warned_ret)
{
RARCH_WARN("Didn't get return value from script. Bug?\n");
PyErr_Print();
PyErr_Clear();
}
handle->warned_ret = true;
return 0.0f;
}

View File

@ -154,7 +154,6 @@ static char gl_teximage_uniforms[MAX_TEXTURES][64];
static state_tracker_t *gl_state_tracker;
static struct state_tracker_uniform_info gl_tracker_info[MAX_VARIABLES];
static unsigned gl_tracker_info_cnt;
static char gl_tracker_script[PATH_MAX];
static char gl_tracker_script_class[64];
static char *gl_script_program;
@ -517,7 +516,7 @@ static bool get_texture_image(const char *shader_path, xmlNodePtr ptr)
#ifdef HAVE_PYTHON
static bool get_script(const char *path, xmlNodePtr ptr)
{
if (*gl_tracker_script || gl_script_program)
if (gl_script_program)
{
RARCH_ERR("Script already imported.\n");
return false;
@ -540,8 +539,8 @@ static bool get_script(const char *path, xmlNodePtr ptr)
if (!script)
return false;
script = xml_replace_if_file(script, path, ptr, "src");
if (!script)
gl_script_program = xml_replace_if_file(script, path, ptr, "src");
if (!gl_script_program)
{
RARCH_ERR("Cannot find Python script.\n");
return false;
@ -1164,15 +1163,9 @@ bool gl_glsl_init(const char *path)
info.info_elem = gl_tracker_info_cnt;
#ifdef HAVE_PYTHON
if (*gl_tracker_script)
info.script = gl_tracker_script;
else if (gl_script_program)
info.script = gl_script_program;
else
info.script = NULL;
info.script = gl_script_program;
info.script_class = *gl_tracker_script_class ? gl_tracker_script_class : NULL;
info.script_is_file = *gl_tracker_script;
info.script_is_file = false;
#endif
gl_state_tracker = state_tracker_init(&info);
@ -1225,14 +1218,10 @@ void gl_glsl_deinit(void)
gl_tracker_info_cnt = 0;
memset(gl_tracker_info, 0, sizeof(gl_tracker_info));
memset(gl_tracker_script, 0, sizeof(gl_tracker_script));
memset(gl_tracker_script_class, 0, sizeof(gl_tracker_script_class));
if (gl_script_program)
{
free(gl_script_program);
gl_script_program = NULL;
}
free(gl_script_program);
gl_script_program = NULL;
if (gl_state_tracker)
{

View File

@ -92,7 +92,16 @@ state_tracker_t* state_tracker_init(const struct state_tracker_info *info)
#ifdef HAVE_PYTHON
if (info->info[i].type == RARCH_STATE_PYTHON)
{
if (!tracker->py)
{
free(tracker->info);
free(tracker);
RARCH_ERR("Python semantic was requested, but Python tracker is not loaded.\n");
return NULL;
}
tracker->info[i].py = tracker->py;
}
#endif
// If we don't have a valid pointer.