Entity System - Networking

Heya,

I know

etc. etc. :smiley:

Anyway, maybe someone can give me some insight to this. I’m using Artemis Entity System (http://gamadu.com/artemis/) which is pretty easy to setup and use and I have really become a big fan of it. Now I have implemented the most simple client/server using Kryonet (server trusts the clients, clients just send positional updates at ~30 times per second, server distributes updates to the other clients, you know the drill), which also works fine.

But here comes the “problem”. I’m not 100% sure about my way of implementation in regards to the entity system, because what I do now is:

  • Client and Server both have their own entity system world (server runs on another thread).
  • Client sends positional update to the server (I know, I know :D).
  • Server receives update and updates the corresponding entity (the player) the moment it receives the update.
  • Server sends the update to the clients and they update the entity the moment they receive it

Now the last 2 parts are what concerns me. I don’t know if that is the right way to go about networking in an entity system. If you tried an entity system you know the systems iterate through their components on every frame and then do their magic. I’m just not sure how to implement an “this-entity-received-an-update-so-update-it-on-the-next-turn” system.

I know it doesn’t really matter in “the most simple client-server-game-thing”, performance-wise, but I want to know the “correct” way to go about this.

Maybe someone here has done something like this before and can give some insight into this?

Thanks a lot :slight_smile:

So… I’m not using Artemis Entity System because I created my own…

Basically, whenever I create a specific type of entity, I add it to a tree. Both in Client and Server. Works the same way.
When you receive a package that applies “Move X to the right”, search for the entity in the tree and make your changes to it. Remember to always use thread-safe collections and consider that your networking events shouldn’t change the order of the updates or change whatever is already built…

Not sure if I was clear.

Yep, so you update the entities the moment they’re received on the client/server, not during the component-update-iteration loop. It’s what I do too, I was just wondering if it’s the “right way”.

Thanks tho :slight_smile:

Vanilla artemis hasn’t been updated for quite some time and has a number of bugs. You’re better off using a fork, like mine or this one.

I am using yours <3 :smiley:
Just didn’t mention it :slight_smile:

Btw. I just update the components the moment they’re received now via


entity.getComponent(Component.class).field = updatedField;

Don’t think it has a huge performance impact anyway. Shouldn’t be much slower than adding it to a queue and have the component update on the next system-iteration. Listening to myself, it’s probably faster :stuck_out_tongue: