State strings

I've tinkered with different state machines definitions and I have to say that I didn't the performant realtime variants. The most simple and fastest one is defining a multidimensional array having state enums as rows and columns and the from/to state as array indices. if the array value is true, the transition is possible: simply and effective. However, defining new states on demand is very hard to maintain since one has always to insert and expand the given array. Furthermore, the definition of transitions is error-prone, too as only has to constantly look up state values, rows and columns. And I can't simply accept this. Therefore, I've decided to use a state system that works with a "string" of states the object can transition to depending on it's current state. See, the actual path and life time of an object is defined by functions that can be called on it. If the functions des not change the object's state at all, there's no need to checking for a transition. Most of the time functions have rules in which order they have to be called, though this is irrelevant in the final code if everything is called in the right order. Therefore, I can create a state for every important function and define it's path with this string of states. State null would be the state terminator, thus each state should atleast be one or greater. However, this comfort and maintainability comes at a high performance cost as one might imagine

No comments: