10 Replies - 399 Views - Last Post: 15 October 2013 - 11:54 AM Rate Topic: -----

#1 Rhino1111  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 96
  • View blog
  • Posts: 220
  • Joined: 28-August 13

Networked Game, Injecting Updates, Opinions wanted.

Posted 14 October 2013 - 11:27 AM

I'm still in the planning phase of a lot of my systems/concepts, so I don't have any actual code to show you guys, more-so a concept I'm planning to use to "inject" updates into my game, and was wondering if something like this would work as expected, if there would be a better way to go about it, or any possible flaws about the system I have in mind.

Basically the networking components and the actual game will be seperate systems. They will both be running concurrently but they will be unaware of each other. The thing is that the networking system will be receiving game state updates from the server, and these updates will need to be applied into various area's of the game(such as game objects, other players movements, messages in chat, etc.)

This is a basic outline of the system I have in mind....

Posted Image

Breakdown-

The networking component just listens for data, when it receives data it passes it to a different networking class responsible for processing the byte data, it then returns to listen for more data.

The component responsible for processing the data will also be responsible for passing any relevant updates into a sort of "mediator" class, the Update Manager. The "Update Manager" gets called once every x seconds in the game's update cycle(still deciding on how often to "inject" updates). I plan to use synchronization here, in the form of locks. I plan to lock the data structures in the "Update Manager" when it begins its update cycle in the game loop, so the networking side of the game isn't corrupting data during the process(such as passing in new data while i'm iterating over it).


Do you guys see any potential pitfalls with this system? Do you think there would be a better way to do this? Any flaws with what I have in mind?

Is This A Good Question/Topic? 0
  • +

Replies To: Networked Game, Injecting Updates, Opinions wanted.

#2 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1134
  • View blog
  • Posts: 7,094
  • Joined: 07-September 06

Re: Networked Game, Injecting Updates, Opinions wanted.

Posted 14 October 2013 - 11:57 AM

If you are making a real-time online game, I'd suggest just processing and updating the game objects as they are sent out by the server instead of once every X seconds. This will mean that you have a bit more to do each loop, but will also reduce the possibility of having a TON of stuff to do sometimes and barely anything others. So, I'd suggest doing the work as it comes in, that'll make the game move "living".

I'd also suggest a process flow closer to this (NOTE - there are only a few differences):
                                Main program
                               /       |    \
                       /-------        |     ------------\
              Game Loop         Update Manager           Networking
               Thread               Thread                 Thread
                  |                    |                      |
                 / \                  / \                    / \
             Draw   Update-Lock->Check   Update<-Lock-Send to   Wait for data
                 \_/                  \_/             Manager\_/(data obtained)
                                                           Process



Hopefully there you can tell that we have 3 (minimum) separate threads. The first being the game loop, the second being the update manager (which I am assuming will also be doing other things, such as user input (keyboard, mouse, etc.)), and the final one being the networking. When the networking thread gets data it processes it and passes it over to the update manager then listens for more data. The update manager waits for the update from the network (or keyboard, etc.) and just stores the information. The game updates and polls the update manager for any updates, then draws them.

Do note that this method makes all calls to the update manager blocking, so if the network is writing data to the update manager and the game loop wants to poll the update manager, the game loop will have to wait until the network write is done, and same for the other direction. So it may make some sense to have a shared data structure between the network and update manager which is write only for the network and read only for the updater in such a way that a read and write can be happening at the same time (such as a linked list that locks to get the head and tail of the list then unlocks -- quick 2 functions) and just loops through the known head and tail then deletes all of the read nodes. In the meantime the list can be getting written to from the network and updating the tail->next nodes without a problem (just an example).
Was This Post Helpful? 1
  • +
  • -

#3 Rhino1111  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 96
  • View blog
  • Posts: 220
  • Joined: 28-August 13

Re: Networked Game, Injecting Updates, Opinions wanted.

Posted 15 October 2013 - 07:58 AM

bump, looking for some more opinions.

definately like your idea Betawar, I've never actually worked with linked lists directly, so I would need to look into that.

This post has been edited by Rhino1111: 15 October 2013 - 08:06 AM

Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8897
  • View blog
  • Posts: 33,364
  • Joined: 12-June 08

Re: Networked Game, Injecting Updates, Opinions wanted.

Posted 15 October 2013 - 08:12 AM

Explain what these 'updates' are.. as in new characters, code fixes, or what?
Was This Post Helpful? 0
  • +
  • -

#5 Rhino1111  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 96
  • View blog
  • Posts: 220
  • Joined: 28-August 13

Re: Networked Game, Injecting Updates, Opinions wanted.

Posted 15 October 2013 - 08:25 AM

View Postmodi123_1, on 15 October 2013 - 08:12 AM, said:

Explain what these 'updates' are.. as in new characters, code fixes, or what?


they aren't code updates, content updates, or any of the sort.
They are "game state updates" from the server. For example, if NPC 1 moves left, the server sends out that positional update to all clients on that map. Or, if player1 changes maps, the server sends out all relevant information to that client so it can "load" the map state correctly (such as NPC positions, other players positions, etc). Those kind of updates.

I'm pretty sure I mentioned they were gamestate updates in my original post, but I might have not.
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8897
  • View blog
  • Posts: 33,364
  • Joined: 12-June 08

Re: Networked Game, Injecting Updates, Opinions wanted.

Posted 15 October 2013 - 09:07 AM

No - you did not mention that.

Sending data to the server, and receiving data back, should be part of your client's normal game loop. I am confused on what benefit it would be to have some sort of whole new thread and then push data out of it and squirt the updates into the game. Why not just have that be a step in the engine?

Posted Image

Posted Image

Side note - a previous thread and a research topic to look into:

http://www.dreaminco...ticking-events/

http://www.gabrielga...a.com/fpm2.html
http://www.gamasutra...ne_.php?print=1
http://buildnewgames...me-multiplayer/
Was This Post Helpful? 2
  • +
  • -

#7 Rhino1111  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 96
  • View blog
  • Posts: 220
  • Joined: 28-August 13

Re: Networked Game, Injecting Updates, Opinions wanted.

Posted 15 October 2013 - 09:41 AM

Well shouldn't the game loop only be worried about updating, rendering the game, and sending data to the server when required(such as when the player moves, sends a message in chat, etc)? I don't see why the game loop would care about when data is received, processing that data, then updating what needs updating, when all it should really be concerned about is applying the updates?

This is why I decided to separate the two systems. The game loop will still be applying the updates every update cycle, but it won't ever need to think about receiving data and processing it. All it needs to worry about is grabbing the updates and applying them.

Maybe i'm mistaken in my thinking?

Good links btw, Gonna read through a couple now.
Was This Post Helpful? 0
  • +
  • -

#8 novakasss  Icon User is offline

  • D.I.C Regular

Reputation: 3
  • View blog
  • Posts: 347
  • Joined: 11-July 12

Re: Networked Game, Injecting Updates, Opinions wanted.

Posted 15 October 2013 - 10:39 AM

View Postmodi123_1, on 15 October 2013 - 09:07 AM, said:



Thank you for this amazing tutorial, but I still want to ask you something, before starting to work with my project.
So, Client should only contain the canvas with the graphics and get inputs from the player? All game logic should be done by the server?(Except that client prediction)
Was This Post Helpful? 0
  • +
  • -

#9 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8897
  • View blog
  • Posts: 33,364
  • Joined: 12-June 08

Re: Networked Game, Injecting Updates, Opinions wanted.

Posted 15 October 2013 - 11:19 AM

For the most part - yes that is the prevailing theme. Remember - a multiplayer game must not only track NPCs but players well. The only sure way of not bungling the whole thing is to have one "Truth" of that from the game server.. Sure the clients can do some predictive movement and actions, but to know 'exactly' where everyone is synced you need only one place to look.

More reading:

http://trac.bookofho...GameProgramming
http://www.cs.kent.e...s-2004/03_2.pdf
Was This Post Helpful? 1
  • +
  • -

#10 novakasss  Icon User is offline

  • D.I.C Regular

Reputation: 3
  • View blog
  • Posts: 347
  • Joined: 11-July 12

Re: Networked Game, Injecting Updates, Opinions wanted.

Posted 15 October 2013 - 11:33 AM

View Postmodi123_1, on 15 October 2013 - 11:19 AM, said:

For the most part - yes that is the prevailing theme. Remember - a multiplayer game must not only track NPCs but players well. The only sure way of not bungling the whole thing is to have one "Truth" of that from the game server.. Sure the clients can do some predictive movement and actions, but to know 'exactly' where everyone is synced you need only one place to look.

More reading:

http://trac.bookofho...GameProgramming
http://www.cs.kent.e...s-2004/03_2.pdf

I guess, even if client predicts the players movement, the original state should be set by the server yes? How about the other player predictions? I mean how can u predict the things you do not actually see. (What button the other player will press).
Was This Post Helpful? 0
  • +
  • -

#11 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8897
  • View blog
  • Posts: 33,364
  • Joined: 12-June 08

Re: Networked Game, Injecting Updates, Opinions wanted.

Posted 15 October 2013 - 11:54 AM

I think that is addressed in that other thread I posted, but you can tune your game to make educated guesses about basic things. If once player is going at a specific speed and direction you can make some assumptions that will continue for the short term.. etc.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1