Yeah, and the last one just went outside… mentioning just one solution to the exclusion of all others seems quite close to endorsing.
But enough of that silliness. There was indeed useful advice, it just didn’t stand out well enough as such:
@normen said:
Not putting the logic into the AppStates. If you have e.g. An entity system all your logic and data is in there. AppStates are a tool to access the update loop, nothing else.
Well, it's not true in that general wording.
Not if you take the "App" in AppState at face value and really put the logic inside AppStates.
Also, not if you take the precedents set by FlyCamAppstate and StatsAppState, which certainly do contain all the logic needed for them.
But it's certainly valid for some other designs. I can see how one can design an application to use AppStates just as service providers. And I can also see how useless a goTo() function would be in such a context.
A better alternative would be a static function that switched between sets of AppStates, avoiding detaching/attaching AppStates that are supposed to be active in both old and new state. That thing would be useful to both designs: Those that control the AppState configuration from inside AppStates and those that control it from the outside.
Then I took a step back and asked myself: "Why did I even build the thing?"
And the answer was: "Because detaching and reattaching an AppState puts it through stateDetached, cleanup, stateAttached, initialize, which needlessly reinitializes the AppState."
So... maybe detach+attach, if it happens while inside the same cycle of the update loop, should really be a null operation.
Maybe. It might mess with the semantics of code that purposely detaches and reattaches an AppState just to reinitialize it.
Which means that enable and disable are already doing everything that's needed.
Which normen has been saying all along, actually. He just didn't explain why, so it remained unclear under which circumstances that advice should be followed and under which other circumstances it should be checked whether it applies.
In fact I routinely refuse to follow advice that I can't check for validity. I've seen too many things crash and burn horribly. Hey, one of the more egregious examples happened just last week to one of our webhosting customers - I'll be posting that to thedailywtf.com one of these days. Watch out for a story involving CNAME.
Back to the issue at hand - maybe a better explanation of the roles of attach/detach and enable/disable will be in order.
If there's any interest, I'll check the Javadocs and/or tutorials and write something up.
To make that happen, I want a "yes we'll consider adding it if it matches facts" from a dev (any dev). I don't want to be stonewalled and spend another couple of evenings of useless arguments until I finally find out what exactly isn't right, that's too much of a waste of time.
(For those who have really followed this: Yes, it's an attempt at contributing back. I'm just a hopeless optimist, it seems.)