By “shared methods” I’m assuming you are referring to the possibility of isolating functionality I want to share between different states as their own methods that can be used by the different states when they enter/exit or in-between those calls when the state is active.
Hadn’t thought of that. Indeed, that’s a possibility.
Having to subclass direct.fsm.FSM.FSM in a central class that gathers all methods for each state, this could end up leaving us with a big class that served only as a gatherer of methods. Even so, it is not necessarily a bad thing.
The way I see it, one could still keep all the methods in separate modules and only put everything together in the central FSM subclass. That would provide a solution that would be as tidy and modular as the one I’m using indeed, and thus making it a valid alternative.
In fact, the only drawback I see is that - and I’m only assuming it based on my own experience - this practice of creating new methods for each state based on special names doesn’t seem to be very idiomatic as far as Python practice goes (except for dunder methods, though, which do indeed force us to use special names in order to provide certain functionalities).
Yet, the possibility of using the API provided by Panda3D for FSMs is very tempting (as one doesn’t have to create and manage its own thing). As a matter of fact, as I type this very reply, I’m still a bit torn between my own solution and this possibility of using Panda3D’s FSM that you mentioned.
For now, though, the reason I’m still considering keeping my custom solution is because it is actually very, very simple and seems to be working fine so far. That is, despite my preference for relying on Panda3D when I can, my solution isn’t very disruptive nor require much maintenance.
Perhaps the only upside of my solution is that, since each state is represented by a single class and is at the same time an instance of that class, I can use such instance to store other data related to the state. In comparison, having a single FSM subclass gathering all the state-representing methods would force me to use that subclass to store data for all the state.
And to make me even more torn, having this central FSM subclass sharing data among states is not necessarily a bad thing, after all different states still have to share resources anyway.
Thus the difference between my solution and Panda3D’s FSM is just in how specifically the data, shared or not, will be managed.
Again, I’ll have to keep thinking about it to make a final decision later. But thanks again for pointing out yet another possibility, Thaumaturge. In summary, I’ll see if can visualize myself using Panda3D’s FSM for all my intended purposes in a satisfying way (satisfying here means that it is a simple and maintainable solution that an external dev not familiar with my code would be able to understand and use/modify). If I can visualize that, then I rather rely on the infrastructure that comes with Panda3D already, rather than spin my own thing.