amethyst
amethyst copied to clipboard
Make Facet take a specific command and be composable
This lets us not send commands to things that can't take them, which lets us build global actors that can take AddEntity
and RemoveEntity
commands without adding ever increasing cost to addentity/removeentity for entities that don't care about those commands.
Example:
/**
* A [Facet] is a [System] which performs actions based on the
* [Command]s they receive.
*/
interface Facet<C : Context, T : Command<out EntityType, C>> : System<C> {
/**
* Performs the given [Command].
* @return the [Response] to the given [command].
* @see [Response] for more info.
*/
fun executeCommand(command: T): Response
}
and then the compose
function:
fun compose(other: Facet<C, Command<out EntityType, C>>): Facet<C, Command<out EntityType, C>>
This also means that facets can only take a single command. Which is a good thing.
What happens if I try and dispatch a command at runtime and an entity has no facets that intercept it?
would the API be facet.compose(otherFacet)
Or would it be better to have a CompositeFacet class that is a facet and has a constructor that takes two facets?
I'd do this similar to how Behavior
s are composed now. The reason for this is that we can take advantage of operator overloading and we can also define boolean operations like facet0 + facet1
facet0 or facet1
, things like that.
Okay. So basically. If I’m going to implement this look at how behavior composition works.
That's a good idea, yes. But first let's think about the kinds of compositions we might want to implement. +
can be used to compose but what about and
and or
? Do you think that would make sense here?
Okay. Let’s think about an example.
StairAscender StairDescender
Compose into StairTraverser. That’s an additive composition.
For And and Or compositions I can’t think of an example off the top of my head. Both I think would require the two composited facets to take the same command though. An And/Or that takes different facets doesn’t make sense to me.
So StairAscender
takes GoUp
and StairDescender
takes GoDown
so StairTraverser
takes both GoUp
and GoDown
so it is an additive composition. Job well done, we can go home, right? 😄
Yeah. I mean sure. My question was, is there a case where we’d want and/or style composition . What would that be useful for if anything?
or
/and
I think is not really meaningful here. We have it with Behavior
s and it is useful because they return a Boolean
value so we can determine whether it performed an action or not. or
short-circuits so if the first Behavior
returns true
the second is not run at all.
With Facet
s this is a bit more fuzzy because each Facet
responds to a single Command
so the composite Facet
we get with +
is just doing dynamic dispatch. As a corollary the or
/and
overloads seem useless here because if we have a Command
we already know which Facet
responds to that so there is no point in short-circuiting.
Agreed. Okay cool.
If you don’t take a cut first I’ll take a cut at it once I get back from vacation.
On Tue, May 7, 2019 at 10:43 AM Adam Arold [email protected] wrote:
and I think is not really meaningful here. We have it with Behaviors and it is useful because they return a Boolean value so we can determine whether it performed an action or not. or short-circuits so if the first Behavior returns true the second is not run at all.
With Facets this is a bit more fuzzy because each Facet responds to a single Command so the composite Facet we get with + is just doing dynamic dispatch. As a corollary the or/and overloads seem useless here because if we have a Command we already know which Facet responds to that.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Hexworks/amethyst/issues/1#issuecomment-490011504, or mute the thread https://github.com/notifications/unsubscribe-auth/AAWAGGGTANYVCLE4XWLF4OLPUFFMVANCNFSM4HJZL2KQ .