-
Notifications
You must be signed in to change notification settings - Fork 458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rethink the concept of plugins / get rid of them #1087
Comments
If a plugin is added like everything else per state, how is it still a plugin? off with its head I say... |
The way I see things, plugins should use Flixel API to perform actions. The plugin itself is instantiated and lives in the "plugin list" (wherever it is). From there, the plugin instance can perform its actions. A very rudimentary example: if a plugin needs to draw lines and squares on the screen (a debug plugin), it will most likely add a |
@Dovyski And why is it beneficial to have that plugin in a separate list instead of state.members, where every other flixel object is added to? And reduce the amount of possible instances to 1? |
If you keep plugins in a different place, they are not related to the state itself. Maybe a plugin wants to handle input and do something with that (it doesn't have to be on the screen in order to achieve that). If you keep plugins in the state, what should happen when a new state comes? Are the plugin instances removed? Are they transferred to the new state? |
The fact that plugins are not related to the state is what's creating this issue in the first place. The timer, path and tweener manager don't really work too well with substates / pausing. They have some logic to be cleared on state switches anyway. |
Quick breakdown: ProblemThe way plugins are handled makes them incompatible with substates. You use substates to pause the parent state, however, tweens, paths or timers that are created in that state are not paused because they are handled globally. The same applies to plugins like SolutionPlugins need to be attached to their state in some way. There are several ways this could be achieved, here's my proposed solution: Turn
|
I'm all for the approach of linking plugins with the state they belong to, but making them objects seems a bit strange. |
+1 for attaching plugins to a state |
@KeyMaster- Plugins already are FlxBasics, that's part of why the plugin system is confusing - requiring them to be used in a certain way seems arbirtary. You could already If you think about it, FlxGroups are also not "things in your game", they are merely containers for them, yet you can add them. @kevinresol I thought about that as well. But why is it beneficial to have "plugins" be a separate concept from everything else? It seems like they would work nicely with the already exisiting logic for state members. |
Btw, we have a similar issue with |
I agree that plugins should not be a separate concept. i think the problem is about the implementation of |
@kevinresol You're right, the concept of
Yet it has a |
I think
|
Because |
@kevinresol I guess ideally, Technically, |
Would be so much nicer in a more component based architecture. :D |
Can't those plugins monitor signals and react to them (e.g. state pushed)? |
@Dovyski I don't see how that solves the underlying problem? |
Using the If you attach plugins to the state, a developer will never be able to create a plugin that works globally on Flixel (e.g. apply visual effects to every frame). For every new state created, a developer must stop and think which plugins should be instantiated and added to that state. |
@Dovyski If you do it that way, you then you have to store the state a sprite belongs along with it in the mouse event manager. That's exactly the same as adding them to the state, you're just storing the information in a different way (a way that seems backwards to me / not preferable). For that you'd first have to figure out which state the sprite belongs to, and that's pretty tricky, as sprites in flixel don't have a concept of a parent and can be added to multiple groups (even multiple states). I don't think there should be a plugin that applies effects globally. That should be a per-camera thing. |
You have a point, @Gama11 You could fix that in That fix, however, is a re-implementation of states and entities as you mentioned. |
I can see potential order of operation issues if we add FlxTimer, FlxTween, FlxPath, and FlxMouseEventManager to the state (since they currently get updated / drawn before the state), it might not cause any issues, but we have to run some tests to make sure we don't break anything. FlxSound is not a plugin, so it shouldn't be part of this discussion. |
Putting plugins in the state as suggested is a huge change to the most common content in members. This is like asking to use non display objects in the flash api like "incompatible with substates" can be solved instead by moving a plugins collection into each FlxState and substate itself. There you could easily As Jens points out Plugins could simply be |
@impaler That's a valid concern. However, if you think about it, I don't like the idea of creating a separate plugin collection for states very much, it feels like a bit of a hack to me. Timers, tweens and paths are not really "plugins", they are an integral part of the engine. Another, signal-based solution is imaginable. |
There's another issue that has not been considered yet and applies to all solutions: The current workflow with timers, paths and tweens is pretty simple, since they manage everything themselves. However, if we allow multiple states to be active at the same time (see #1091 and #1084), this won't be possible anymore, since we have no way of knowing which state an object should be associated with. |
We could bring back the concept of "pre-update", and "post-update" as signals contained by states. And only use those for Timers / Tweens / Paths. Triggering signals is slower than doing direct function calls, but I think for objects with limited life spans, it would be OK. We'd need to evaluate performance difference though, so having a Tween / Timer performance test might not be a bad idea. |
@Gama11 most flash projects use empty sprites which act as containers like flixel uses FlxGroup, this isnt an uncommon or unpure thing. I think your battling with the deep inheritance while wanting to separate logic to particular parts. Whether you call them plugins/managers whatever, do you want one members array to update everything imaginable, or do you want to separate the display objects and the managers/plugins? It seems more of a hack like you say to put everything in one place. I think its better organization of code for them to be handled and organized separately, whether that is with signals which are just collections of callbacks, or more simple containers. |
I should probably mention that @JoeCreates is working on a solution for this (just to two people working on the same thing and duplicating efforts). |
…ixel#1087) This takes care of any substate issues with paths still being updated while the object they belong to isn't. This solution works because every object can only follow one path at a time - for timers and tweens a different solution is needed. Similar to the original AS3 Flixel API, FlxObject now has a public `path` property. Downside: it introduces a circular dependency between FlxObject and FlxPath.
Plugins are not a very useful concept. They're not different from FlxBasics, yet they behave differently - using a kind of singleton pattern where only one instance of the plugin can exist at a time. This creates some interesting issues with substates, as plugins have no concept of belonging to a state like everything else in flixel does. This means tweens in a parent state won't stop if a substate is opened, even if everything else pauses.
It would be much more flexible, intuitive and powerful if plugins were add()ed to states like everything else.
The text was updated successfully, but these errors were encountered: