Aug 30/31 updates. Tinkering with shared_ptr. Working towards exposing UI objects to Python UI. Color object updated for shared_ptr structure that will be repeated for the rest of the UI objects. Still a lot of open questions, but committing here to get back on track after a few hours wasted trying to solve this problem too generally via templates.

This commit is contained in:
John McCardle 2023-08-31 13:51:56 -04:00
commit 50d926fe37
11 changed files with 293 additions and 137 deletions

View file

@ -3,6 +3,7 @@
#include "GameEngine.h"
#include "Grid.h"
#include "UI.h"
#include "Resources.h"
// static class members...?
std::map<std::string, UIMenu*> McRFPy_API::menus;
@ -99,6 +100,8 @@ static PyMethodDef mcrfpyMethods[] = {
{"camFollow", McRFPy_API::_camFollow, METH_VARARGS, ""},
{"sceneUI", McRFPy_API::_sceneUI, METH_VARARGS, "sceneUI(scene) - Returns a list of UI elements"},
{NULL, NULL, 0, NULL}
};
@ -118,14 +121,17 @@ PyObject* PyInit_mcrfpy()
}
// This code runs, but Python segfaults when accessing the UIFrame type.
std::cout << "Adding UIFrame object to module\n";
//std::cout << "Adding UIFrame object to module\n";
PyModule_AddType(m, &mcrfpydef::PyColorType);
/*
if (PyModule_AddType(m, &mcrfpydef::PyUIFrameType) < 0)
{
std::cout << "Error adding UIFrame type to module; aborting" << std::endl;
Py_DECREF(&mcrfpydef::PyUIFrameType);
return NULL;
}
*/
return m;
}
@ -1115,3 +1121,14 @@ PyObject* McRFPy_API::_camFollow(PyObject* self, PyObject* args) {
Py_INCREF(Py_None);
return Py_None;
}
//McRFPy_API::_sceneUI
PyObject* McRFPy_API::_sceneUI(PyObject* self, PyObject* args) {
const char *scene_cstr;
if (!PyArg_ParseTuple(args, "s", &scene_cstr)) return NULL;
auto ui = Resources::game->scene_ui("uitest");
if(ui) std::cout << "vector returned has size=" << ui->size() << std::endl;
Py_INCREF(Py_None);
return Py_None;
}