• 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
Telanor

Need some help with networking entity-component system

12 posts in this topic

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?
0

Share this post


Link to post
Share on other sites

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.

0

Share this post


Link to post
Share on other sites

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

 

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

0

Share this post


Link to post
Share on other sites
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.
1

Share this post


Link to post
Share on other sites

> only the needed info

> exploding component is needed info

> no one cares about your entity-component design mumbojumbo

 

Send needed info. Simple. xD

0

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites
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"
0

Share this post


Link to post
Share on other sites

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?
0

Share this post


Link to post
Share on other sites

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.
0

Share this post


Link to post
Share on other sites

 

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.

0

Share this post


Link to post
Share on other sites
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.
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