Need some help with networking entity-component system
Now I'm working on adding various different types of special arrows, in this case an exploding one. What I planned to do was hook up an event that fires when the arrow collides which would trigger an explosion. Client side, this would just display some particle effects, while server side it would run the damage calculations and then send that out.
The problem is the code that says "spawn exploding arrow" runs only on the server, since that's where entities need to be spawned. So while the server can easily hook up that event, the client is just receiving a generic "create arrow" packet. I see two possible solutions to this, but I'm not sure which is better, or if there's perhaps a better solution.
Solution 1 would be to make a new set of factory functions with a custom packet for each type of arrow or whatever I happen to need. So instead of just "create arrow" and hooking in custom events, it'd be "create explosive arrow", "create water arrow", etc (of course I'm talking about entities that differ in the code they run rather than merely stat differences). I'm not particularly fond of this as it involves creating different packets for every single type of arrow (and whatever other entities) and possibly some other duplicate work.
Solution 2 would be to not bother trying to get the code to run on the client side and instead make another packet that the server sends out that says "hey client, create some particles here". This is probably a neater solution but I think it could lead to the explosion being delayed.
So, any thoughts on which is preferable? Or is there a better solution?
I would add some packets that allow you to make an entity from the ground up if needed. Things like an add component packet and such. Then you could create the arrow and then just add the exploding effect as a component.
Why does the "create <blah>" function (and packet) not take configuration information?
I e, "create arrow" "include the exploding component."
The system doesn't have the ability to serialize a whole entity across the network, only the update state, because of complications like this. I wasn't sure how to deal with serializing these one-time setup things (such as hooking up events), so it was designed to send only the needed info, like position, rotation, owner and entity ID, then call most of the same code the server just ran using that info. Clearly this has a bit of a flexibility problem though, as I'm now realizing.
> only the needed info
> exploding component is needed info
> no one cares about your entity-component design mumbojumbo
Send needed info. Simple. xD
Send needed info. Simple. xD
And what info do you send in order to hook up events?
What happens on the server when you create this entity? Why isn't this information also available on the client?
So if I were to make a separate factory + packet for every single entity and all its "functional variations", then the client would indeed have all the info it needs. But that seems like a less-than-ideal design to me. With the way the system is currently, the calling code on the client side won't even have access to the entity. Using "shoot bullet" as an example action: client side, the code for that action would just say "create some smoke particles at the barrel" and maybe play an animation. Server side, the same action creates a bullet entity, so it can hook up events there if it wanted.
So in essence: the client calling code doesn't have access to the entity because it's waiting for the server, and the client factory code doesn't know anything about "exploding arrows", it only knows how to create an "arrow"
I would add some packets that allow you to make an entity from the ground up if needed. Things like an add component packet and such. Then you could create the arrow and then just add the exploding effect as a component.
Sorry, somehow I completely missed this post.
That's something I've considered but still wouldn't deal with the event hooking situation. Suppose there's some entity that fires 3 events: OnSpawned, OnAttacked, OnAttack. If I want to make entity A self destruct whenever it gets hit and entity B self destruct on spawn, how would I communicate where the "explosion component" should attach itself?