Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Need some help with networking entity-component system


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
12 replies to this topic

#1 Telanor   Members   -  Reputation: 1358

Like
0Likes
Like

Posted 11 August 2013 - 11:10 PM

Currently I have an entity-component system where code will run on the server to spawn an entity from a factory method, which then sends a packet out to the clients and they create the entity locally using much of the same code. This worked fine for basic types of entities, like an arrow being shot out.

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?

Sponsor:

#2 Oralordos   Members   -  Reputation: 507

Like
0Likes
Like

Posted 12 August 2013 - 08:13 AM

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.



#3 3TATUK2   Members   -  Reputation: 730

Like
0Likes
Like

Posted 12 August 2013 - 08:39 AM

1.



#4 hplus0603   Moderators   -  Reputation: 5692

Like
0Likes
Like

Posted 12 August 2013 - 10:06 AM

Why does the "create <blah>" function (and packet) not take configuration information?

 

I e, "create arrow" "include the exploding component."


enum Bool { True, False, FileNotFound };

#5 Telanor   Members   -  Reputation: 1358

Like
1Likes
Like

Posted 12 August 2013 - 03:48 PM

How would the receiving end know what to do with the exploding component? Does the exploding component's constructor examine the entity object it's being attached to, find the Projectile component and hook itself up to the Collided event? That seems like a bit too much interconnection. Does that mean someone has to make a "mid air explosion" component now if they want to have the arrow explode on a different event?

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.

#6 3TATUK2   Members   -  Reputation: 730

Like
0Likes
Like

Posted 12 August 2013 - 04:38 PM

> only the needed info

> exploding component is needed info

> no one cares about your entity-component design mumbojumbo

 

Send needed info. Simple. xD



#7 Telanor   Members   -  Reputation: 1358

Like
0Likes
Like

Posted 12 August 2013 - 07:23 PM

Send needed info. Simple. xD


And what info do you send in order to hook up events?

#8 hplus0603   Moderators   -  Reputation: 5692

Like
0Likes
Like

Posted 12 August 2013 - 08:22 PM

What happens on the server when you create this entity? Why isn't this information also available on the client?


enum Bool { True, False, FileNotFound };

#9 Telanor   Members   -  Reputation: 1358

Like
0Likes
Like

Posted 12 August 2013 - 09:02 PM

Well the server creates the entity, assigns it an ID, creates and attaches all the components, and sets all the data values depending on the variables passed to the factory function. It can easily set up whatever event hooks it needs to, either in the factory function or the calling code itself. At the end of the factory function, it creates a packet with the needed data and sends it to the clients. On the client side, during startup, the factory functions are registered in a dictionary that translates the entityType ID into a function call. When a packet with that entityType ID is received, the function is called, which then reads the packet and runs most of the same factory code the server just ran using the values read from the packet.

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"

#10 Telanor   Members   -  Reputation: 1358

Like
0Likes
Like

Posted 12 August 2013 - 09:10 PM

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?

#11 hplus0603   Moderators   -  Reputation: 5692

Like
0Likes
Like

Posted 13 August 2013 - 10:45 AM

creates and attaches all the components


Why can't the client run the same code?

Or, to put a little more structure into my suggestion:

- There are two ways that configured objects can be created in most game engines.
- One is through a specific code path, where everything is hard coded.
- The other is through a generic code path, that loads some "data description" of entities/components/parameters.

Now, make sure that the client and server both have copies of the same code, and the same data.
To create an entity from a data configuration blob, you just need the instruction "create object given data blob 2873." This is trivial to send through the network, too, and it allows designers to edit data blobs separate from the code, so this is generally preferred.
To create an entity procedurally, you have some code that does that. This code needs to be available on both client and server, and some reference to the code needs to be sent from server to client. You can, for example, use some kind of look-up table from some identifier to an actual function to run, and send the identifier across in the message.
enum Bool { True, False, FileNotFound };

#12 3TATUK2   Members   -  Reputation: 730

Like
0Likes
Like

Posted 13 August 2013 - 05:30 PM

 

Send needed info. Simple. xD


And what info do you send in order to hook up events?

 

 

... the fact that it's explicitly an *exploding* arrow... Your code does the rest.



#13 Telanor   Members   -  Reputation: 1358

Like
0Likes
Like

Posted 13 August 2013 - 09:11 PM

The client does run the same code, but that code is just the "create arrow" code. It doesn't include the exploding part.

I've started separating the packets and factories, so I can have subtype entities reuse the same packet layout. It seems I'll have to require that any functionally-different entity has it's own set of factory methods though. Thanks for the help.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS