• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
phayer

Entity-component system and networking

9 posts in this topic

Got some problems with coming up with how the state replication mechanics should work in a "entity component system"-design.

I'm using the C++ port of artemis from vinova. No problems there, works great so far. For networking I'm using enet and I have a basic system up and going. I can send a "entity created with these components"-message, and the client creates a new entity which is identified by a unique ID(sent with the "entity created"-message).

 

All this is good, but the problem comes when I want to synchronize states across the network. How should I implement that on the server? Should there be a system that loops over and creates a packet for all the states that needs syncing? How should I implement this on the client? 

 

My ideas so far;

Server --

Since the server only sends states for object close to client I am currently;

 

Loop over all entites:

1. Check with all players, is the entity close?

1a. If so, does it need syncing?

1b. Yes; send a packet with the new state.

 

 

Client --

No idea..

 

If anyone have some tips, ideas, or could share how they solved this it would be great.

 

0

Share this post


Link to post
Share on other sites

Your client shouldn't be sending state to the server. The client should just send inputs from the player. The server validates the inputs, applies them to the player's entity (on the server) and then sends the state back to the client (as well as other nearby clients). Your client should immediately apply the input locally and then make corrections based on the returned state from the server to keep the client in sync. Anyway, this is how my system works and it works well for me.

0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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 :)

0

Share this post


Link to post
Share on other sites

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?

0

Share this post


Link to post
Share on other sites

I usually add a writePacket and readPacket method to the networked objects. The objects can also mark themselves for a network update. After the game loop the server will loop through all objects to check if they're marked, and if so, it will give the object the chance to write data by calling the writePacket method. This is obviously a very simple explained but you get the idea, I just hope I interpreted your question correctly.

0

Share this post


Link to post
Share on other sites

 

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 my Implementation the Component for sending the Network Update Packets has access to the Network Server via one of it's data members. 

 

1. So within that Component the only thing that is happening is all the data for that entity being packaged up into a Network Packet and then Calling the Network Server BroadcastPacket function to send the Packet to the clients. 

 

2. On the Client I receive all Packets through one PacketHandler Class which then takes the raw Packet and Creates a Message with just the relevant data and sends the Message to the specified Entity. 

 

So the Raw Packet Data comes across with things like Packet ID, Timestamp, Entity Unique ID and Position Data. This is then created into an Update Message which will have the Position Data and sent to the Entity using the Unique ID. This way the component will only have the information that it needs i.e. the Position Data. 

 

This is only the way I'm currently doing it and it may not suite your specific needs but hopefully it's a good basis :)

0

Share this post


Link to post
Share on other sites

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.

 

The two are very intimately related.

 

How you handle the data on either side is entirely dependent on what you put in them. 

 

The network is just a way to transmit data from point to point. In many ways it is the same as a file system or the same as an event system. One side writes data and the other side reads it. 

 

Your client receives information. Exactly how you deal with that information is unique to your app and your protocol.  Maybe you take a packet-based system and dump the events directly on a communication bus to be picked up by any interested listeners. Maybe you have a giant if/else tree or switch statement and handle each one directly. Maybe you plug the results directly into some stream reading system. Maybe you do some combination of all of them. The usage will depend entirely on what data you are sending.

0

Share this post


Link to post
Share on other sites

I've used two kinds of systems for sending and receiving network data. Nowadays I prefer the latter for its genericity.

 

1) like suggested above, manually implement writeMessage & readMessage functions into every component. For network use, this typically needs bitfields to optimally tell what has changed, because a network message might not modify nearly all attributes of a component at once.

 

2) implement an attribute introspection system for components. For each component type you will be able to enumerate their attributes and with some suitable template code or "variant" variable mechanism, can loop the attributes generically for any component to process network writes and reads, and keep track of whether a value has changed since last update and actually needs to be sent. For example a 3D transform component might have 3 attributes: position (Vector3), rotation (Quaternion), scale (Vector3)

 

Generally, you could think of the network client as an external "editor" acting over your scene, ie. change that entity's position, spawn that entity, delete that entity, according to instructions from the server. By thinking this way, the entities or components don't even need to know there's networking going on, rather the server or client accesses them.

 

You probably need interpolation or extrapolation too so it's not exactly that simple, but those could be handled by a dedicated system.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0