From bf1c3a87fa9fe89ac8d92c758d356575e52b3920 Mon Sep 17 00:00:00 2001 From: scawful Date: Tue, 20 Aug 2024 22:47:12 -0400 Subject: [PATCH] more python cleanup --- src/base/sprite.h | 13 ----- src/py/yaze_py.cc | 136 +------------------------------------------ src/py/yaze_py.cmake | 1 + 3 files changed, 3 insertions(+), 147 deletions(-) diff --git a/src/base/sprite.h b/src/base/sprite.h index e5923566..4671dc2f 100644 --- a/src/base/sprite.h +++ b/src/base/sprite.h @@ -7,25 +7,12 @@ extern "C" { #include -/** - * @brief Sprite action. - */ -struct z3_sprite_action { - const char* name; /**< Name of the action. */ - uint8_t id; /**< ID of the action. */ - - const char** instructions; /**< Pointer to the instructions of the action. */ -}; -typedef struct z3_sprite_action z3_sprite_action; - /** * @brief Primitive of a sprite. */ struct z3_sprite { const char* name; /**< Name of the sprite. */ uint8_t id; /**< ID of the sprite. */ - - z3_sprite_action* actions; /**< Pointer to the actions of the sprite. */ }; typedef struct z3_sprite z3_sprite; diff --git a/src/py/yaze_py.cc b/src/py/yaze_py.cc index 8b7cd802..a45b37c4 100644 --- a/src/py/yaze_py.cc +++ b/src/py/yaze_py.cc @@ -1,141 +1,14 @@ #include +#include "base/extension.h" #include "base/overworld.h" #include "base/snes_color.h" #include "base/sprite.h" -#include "base/extension.h" #include "yaze.h" -class PythonYazeExtensionWrapper { - public: - PythonYazeExtensionWrapper() : ext_() { - // Initialize function pointers to nullptr or default implementations - ext_.initialize = nullptr; - ext_.cleanup = nullptr; - ext_.manipulate_rom = nullptr; - ext_.extend_ui = nullptr; - ext_.register_commands = nullptr; - ext_.register_custom_tools = nullptr; - ext_.register_event_hooks = nullptr; - } - - const char* getName() const { return ext_.name; } - - const char* getVersion() const { return ext_.version; } - - void setName(const std::string& name) { ext_.name = name.c_str(); } - - void setVersion(const std::string& version) { - ext_.version = version.c_str(); - } - - void setInitialize(boost::python::object func) { - ext_.initialize = &PythonYazeExtensionWrapper::initialize; - initializeFunc_ = func; - } - - void setCleanup(boost::python::object func) { - ext_.cleanup = &PythonYazeExtensionWrapper::cleanup; - cleanupFunc_ = func; - } - - void setManipulateRom(boost::python::object func) { - ext_.manipulate_rom = &PythonYazeExtensionWrapper::manipulate_rom; - manipulateRomFunc_ = func; - } - - void setExtendUI(boost::python::object func) { - ext_.extend_ui = &PythonYazeExtensionWrapper::extend_ui; - extendUIFunc_ = func; - } - - void setRegisterCommands(boost::python::object func) { - ext_.register_commands = &PythonYazeExtensionWrapper::register_commands; - registerCommandsFunc_ = func; - } - - void setRegisterCustomTools(boost::python::object func) { - ext_.register_custom_tools = - &PythonYazeExtensionWrapper::register_custom_tools; - registerCustomToolsFunc_ = func; - } - - void setRegisterEventHooks(boost::python::object func) { - ext_.register_event_hooks = - &PythonYazeExtensionWrapper::register_event_hooks; - registerEventHooksFunc_ = func; - } - - yaze_extension* getExtension() { return &ext_; } - - private: - static void initialize(yaze_editor_context* context) { - boost::python::call(initializeFunc_.ptr(), boost::python::ptr(context)); - } - - static void cleanup() { boost::python::call(cleanupFunc_.ptr()); } - - static void manipulate_rom(z3_rom* rom) { - boost::python::call(manipulateRomFunc_.ptr(), boost::python::ptr(rom)); - } - - static void extend_ui(yaze_editor_context* context) { - boost::python::call(extendUIFunc_.ptr(), boost::python::ptr(context)); - } - - static void register_commands() { - boost::python::call(registerCommandsFunc_.ptr()); - } - - static void register_custom_tools() { - boost::python::call(registerCustomToolsFunc_.ptr()); - } - - static void register_event_hooks(yaze_event_type event, - yaze_event_hook_func hook) { - boost::python::call(registerEventHooksFunc_.ptr(), event, hook); - } - - yaze_extension ext_; - static boost::python::object initializeFunc_; - static boost::python::object cleanupFunc_; - static boost::python::object manipulateRomFunc_; - static boost::python::object extendUIFunc_; - static boost::python::object registerCommandsFunc_; - static boost::python::object registerCustomToolsFunc_; - static boost::python::object registerEventHooksFunc_; -}; - -// Static members initialization -boost::python::object PythonYazeExtensionWrapper::initializeFunc_; -boost::python::object PythonYazeExtensionWrapper::cleanupFunc_; -boost::python::object PythonYazeExtensionWrapper::manipulateRomFunc_; -boost::python::object PythonYazeExtensionWrapper::extendUIFunc_; -boost::python::object PythonYazeExtensionWrapper::registerCommandsFunc_; -boost::python::object PythonYazeExtensionWrapper::registerCustomToolsFunc_; -boost::python::object PythonYazeExtensionWrapper::registerEventHooksFunc_; - BOOST_PYTHON_MODULE(yaze_py) { using namespace boost::python; - class_("YazeExtension") - .add_property("name", &PythonYazeExtensionWrapper::getName, - &PythonYazeExtensionWrapper::setName) - .add_property("version", &PythonYazeExtensionWrapper::getVersion, - &PythonYazeExtensionWrapper::setVersion) - .def("setInitialize", &PythonYazeExtensionWrapper::setInitialize) - .def("setCleanup", &PythonYazeExtensionWrapper::setCleanup) - .def("setManipulateRom", &PythonYazeExtensionWrapper::setManipulateRom) - .def("setExtendUI", &PythonYazeExtensionWrapper::setExtendUI) - .def("setRegisterCommands", - &PythonYazeExtensionWrapper::setRegisterCommands) - .def("setRegisterCustomTools", - &PythonYazeExtensionWrapper::setRegisterCustomTools) - .def("setRegisterEventHooks", - &PythonYazeExtensionWrapper::setRegisterEventHooks) - .def("getExtension", &PythonYazeExtensionWrapper::getExtension, - return_value_policy()); - class_("z3_rom") .def_readonly("filename", &z3_rom::filename) .def_readonly("data", &z3_rom::data) @@ -152,14 +25,9 @@ BOOST_PYTHON_MODULE(yaze_py) { .def_readonly("size", &snes_palette::size) .def_readonly("colors", &snes_palette::colors); - class_("z3_sprite_action") - .def_readonly("name", &z3_sprite_action::name) - .def_readonly("id", &z3_sprite_action::id); - class_("sprite") .def_readonly("name", &z3_sprite::name) - .def_readonly("id", &z3_sprite::id) - .def_readonly("actions", &z3_sprite::actions); + .def_readonly("id", &z3_sprite::id); class_("yaze_flags") .def_readwrite("debug", &yaze_flags::debug) diff --git a/src/py/yaze_py.cmake b/src/py/yaze_py.cmake index 2276f9b0..bc05fbad 100644 --- a/src/py/yaze_py.cmake +++ b/src/py/yaze_py.cmake @@ -1,3 +1,4 @@ +find_package(PythonLibs REQUIRED) find_package(Boost COMPONENTS python3 REQUIRED) # target x86_64 for module