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

Decoupling Network from Game/UI logic

5 posts in this topic

I am wondering what design strategies or approaches others have used to decouple networking from game and UI logic in a game client.

I considered the notion where everything that would be sent to the server endpoint would be some form of an event. Various points in the game logic code, specific events would get dispatched to an event queue. The network layer components would register during initialization for these types of events and upon receipt, perform the network action. Once the network action completes, a network layer completion handler that got invoked that would fire an event back to the event queue to be distributed the next time the event dispatcher was ticked.

One thing I like about the above is that the event dispatcher is the conduit by which any module can speak with the network layer. In fact, my design has been hinged around this being the way any subsystem in the framework can talk to one another.

Using boost asio with an io service worker thread, I can have the service event loop continually respond to read/write operations as fast as possible and update an internal queue of message packets received from the server. During the main game loop I can simply lock the queue, make a clone, clear, and unlock then process the cloned list. This is so I can maintain some order of state update during the game loop. I don't think it would be ideal to allow the io service thread to manipulate state since it has no idea where the main game loop may be during the simulation for example.

I'm curious whether there is a better approach to interfacing the network layer in the game loop besides the above? The world simulation will have a large number of various message types sent to/from the server and I'd like to find a good way to handle sending/receiving these messages effectively with minimal overhead and decent decoupling too.

EDIT: Also keep in mind, that if a proposed solution is not to use an event queue like the above, the game client maintains at most three server connections simultaneously during game play, namely the authentication service connection, chat service connection, and world simulation service connection. So I'd need to have a way to distinguish between multiple server-side endpoints.

0

Share this post


Link to post
Share on other sites
Generally the good implementations I've seen follow that basic pattern: there's a "game layer" and a "network layer" and they communicate via some form of message queueing. The details are going to vary by engine and other design considerations, but it sounds like you're on the right track.
0

Share this post


Link to post
Share on other sites
[quote name='ApochPiQ' timestamp='1354307900' post='5005832']
Generally the good implementations I've seen follow that basic pattern: there's a "game layer" and a "network layer" and they communicate via some form of message queueing. The details are going to vary by engine and other design considerations, but it sounds like you're on the right track.
[/quote]

A centralized queue would work when you're speaking about specific events like GameObjectUpdateEvent or ChatMessageEvent for example. Since I am only ever connected to a single world simulation server or chat server that is responsible for sending data to my client this makes sense.

But how would you handle network-specific event notifications such as connected, timeout, disconnected, etc? Using the event dispatch queue would be nice to keep things nicely decoupled but I also think it really breaks down when you are dealing with multiple connections unless the events have some identifier that specify which endpoint the network event is related to.

Another option would be to use some simple INetworkEventSink interface that could be registered for each object interested in network-specific events. But this would mean that some game layer objects would need access to network layer objects to register such a notification sink.

That is where I am having a hard time trying to connect the dots between the two layers. Edited by crancran
0

Share this post


Link to post
Share on other sites
I think you need to be careful that you don't try and over-develop the abstraction / decoupling.
There comes a point whereby you try and reduce the awareness of either component so much that you have inefficient and hard to maintain code.
0

Share this post


Link to post
Share on other sites
[quote name='crancran' timestamp='1354305123' post='5005809']
Using boost asio with an io service worker thread, I can have the service event loop continually respond to read/write operations as fast as possible and update an internal queue of message packets received from the server. During the main game loop I can simply lock the queue, make a clone, clear, and unlock then process the cloned list.
[/quote]

Double buffer your queue. Add two of them, one for receiving events, one for processing. When the processing queue is, well, processed, throw your lock on the manager and switch the two queues around. Much shorter lock time, I expect. Edited by CS_
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