Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 27 Jun 2012
Offline Last Active Apr 15 2014 02:45 AM

Posts I've Made

In Topic: Entity-component system and networking

20 March 2014 - 06:35 AM

I have just been over this same issue, although my game features a small number of Networked Entities which all need to know about each other constantly ( It is a FPS Based Arena Game ). 


As I don't have to deal with Area based Syncing it becomes much simpler but this is essentially the way I do it. 


I have a Component on the server version of the Entity that essentially sends out a Sync Update Packet after a specified elapsed time, which is currently about half a second. 

On the Client the Packet is Received and stuffed into an Entity Update Message that is sent via the Entity Messaging System to the Entity with the Unique ID and there is another component that basically waits for the Entity Update Messages and then applies them to the Entities Data, whether that is by interpolating the movement or just setting some flags i.e. Casting a Spell.


This is a pretty simple method and seems to work for me, although this one component does need to know about a lot of the Entities Data.


An alternative method would be to create a component that does the same thing but for each set of Data for the Entity.

So If you have Damage Data and Position Data, you could create a PositionSyncUpdate Component and a DamageDataSyncUpdate Component. This is much more fitting but involves creating a lot of Components. This method would be better if your Entities change their Components a lot and is much more reusable. I may potentially change to this method at some point. 


Oh as a note, in my system a Component is a class that defines one set of functionality on sets of Data.


Hope this helps somewhat and I haven't completely missed the point smile.png


But how does the component access the networking part of the application? How does the server component access NetworkServer?


How do you handle it on the client end? Do you read the package and then send it directly to the component on the given entity?

In Topic: Entity-component system and networking

20 March 2014 - 02:25 AM

I think you misunderstood. I'm not wondering how to structure my packets or what to put in them. I'm wondering how I should handle the data on the client side.

Whats the cleanest way from receive data to processing it and updating entities?


What my clients send and doesn't send is more suited in a new topic I think.

In Topic: Threading and networking

19 March 2014 - 02:40 PM

Other than to beware of concurrent edits (e.g. network thread adding to the queue while the processing thread is removing from the queue) yes, that can work quite well. The network is just a data transfer medium. You are right to want to keep it simple. Write data, read data, that's it.


The interesting part is what you do with that data inside the game.


Well, I'm locking the queues while I'm reading or writing to them. The current mechanism tries to;


Network thread --

Lock incoming queue and write to it, then unlock

Lock outgoing queue and send packages, then unlock


Game thread --

Lock outgoing thread and write to it, then unlock

Lock incoming queue and read from it, then unlock.


Just to minimize locking. Probably not perfect, but it works so far and I'm happy.




If any of you have any experience regarding entity-component-systems and how to integrate network to them easily while still keeping them flexible/extendable, the whole point of a entity-component-system, then please drop by in my other thread.

In Topic: Threading and networking

19 March 2014 - 01:57 PM

Okey, so I implemented something that seems to work well;


2 threads and 2 queues. 

1 thread for handling networking, 1 for the game.

1 queue for incoming data, 1 for outgoing data.


Does this seem like a reasonable design? I don't want to get hung up on this, but on the other hand I don't want to make a lot code smell -- Like, I don't want to spend a month later rewriting the entire network only because my prototype implementation was bad.

In Topic: How to fight lag?

23 March 2013 - 09:01 AM

So what I should do is, the second I get some data, I chech if my interpolated entitys position isn't too far away from the position I just received. If it is; snap it in place. Then I start using the new velocity I just received?


How does this go for clients shooting at each other, or shooting at a AI?


And this method is applyable when using Box2d or some other physics engine on the server side?