The longer I think about it the more I’m convinced that for proper Python support a tight integration with Godot is required:
- as a module.
- Python version: ideally 3.14+ with GIL disabled
- Custom GC behaviour and tunning or even custom GC like one for GO (but 3.14 GC might be enough)
- Memory hooks connected to Godot’s memory allocators (profiling etc.)
- Unified refcounting so cycles across Godot-Python boundary can be cleared and Godot can use Python’s objects safely
Cycles across boundary could also be prevented by manually in/decrementing every time it’s necessary but I think this is the reason why touilleMan/godot-python never got ready for 4.X
GIL-less python extends standard refcounting to two counters - one for owner thread and second one for other threads. - Pybind-11 for minimal binding and LibCST for boilerplate generation but also for scanning and transforming user code, with opt-out, to automagically replace known performance killers and/or give warnings
- buffer structures to limit costly copying
I want to do this with integrating StateCharts into the engine in mind:
I think that StateCharts are a must for working with complex UIs that* utilize a lot of microbehaviours.
- I would like to also use them in Python and proper StateCharts will require hooking into Godot’s main loop. (timer event spawning after scene node process loop)
- I think humans require graph/transition-centric definition to work with StateCharts efficiently but natural way of executing it requires node-centric definition.
- I want to emulate how Xstate is doing this for JS.
- Machine consists of:
** state/transition/action/guards definition
** action/guard calls mapping
** active state reference for each level (including parallel) and context - Machine reacts to events that are propagated through state layers until one of the states reacts to it or will get ignored by every state
- It might be really beneficial to automagically replace simple guards in Python with native equivalents that will be hotswapped back to Python calls if original object will be replaced.
- (node-centric paradigm) Native runtime executing StateChart from it’s transition definition compiled into continuous memory block based on relative offsets (shared); another memory block of hot-swappable action, guard call mappings (per machine) and mutable current machine state definition - active states for each machine level and context.
Blocks might be possibly created with flatbuffer. - (graph/transition-centric paradigm) User layer with machine definition in Python.
- (graph/transition-centric paradigm) Graphical graph tool for visualization and editing that uses LibCST to read and write machine definition in Python so we keep SSOT.
Maybe it is beneficial to always go via native flatbuffer form so other languages can benefit from this functionality. - Parts of graph tool can be reused for RT visualization and debugging
- LibCST could be used to replace simple Python calls