Author Topic: Delay syncing for joining players?  (Read 8723 times)

dartboy

  • Guest
Delay syncing for joining players?
« on: November 26, 2013, 02:41:28 PM »
Hi,

I'm trying to figure out the best solution for handling the syncing of players when they join a game in progress. I've got calls using TNManager.Create to handle the creation of the players' characters, but creating the characters is dependent on the map objects in the scene to finish setting up first. Everything works fine for players that are connected prior to the game starting, since they're all waiting for the loading to complete before sending out the calls to spawn. The issue I'm running into is that it seems that for players that join after the game starts, all the queued spawn calls get executed as soon as the new player connects, regardless of whether the map has finished loading or not. This, naturally, causes problems with the spawning and synchronizing for the new players. I suppose one valid solution would be to put the spawning code in a coroutine that yields for the map setup, but I was wondering if there's some other flag or option in TNet to the effect of "don't process all these queued calls until ready"?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Delay syncing for joining players?
« Reply #1 on: November 27, 2013, 12:43:11 AM »
What you can do is actually Application.LoadLevel first, and only then JoinChannel with 'null' specified for the level name. This will use the current level.

dartboy

  • Guest
Re: Delay syncing for joining players?
« Reply #2 on: November 27, 2013, 08:54:57 PM »
That is actually something I'm already doing, mainly because I'm using Application.LoadLevelAsync along with a nice loading screen. The problem I'm facing with this is that my map isn't just a static scene, but something that can be procedurally generated from a group of smaller tiles. So I still need some sort of message from the host listing how to construct the level and letting that finish before going through and placing the characters. I wonder, would another option be something like set up multiple channels, using Target.AllSaved to store the calls, and have one channel that players join first being the map setup, then have them join a second channel where the game action is taking place?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Delay syncing for joining players?
« Reply #3 on: November 28, 2013, 01:41:34 AM »
Is your level generation happening in a separate thread or something? Because if not, simply setting your level gen script to execute before other scripts will ensure that it generates the level before everything else has a chance to run. Just change the script execution order.

danfoo

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 93
    • View Profile
Re: Delay syncing for joining players?
« Reply #4 on: September 12, 2017, 11:50:10 AM »
Sorry for resurrecting this topic. However, I have a similar issue:
The procedural world creation takes a while and is based on ienumerators and updates the player on the world creation process.
As such I would like object in instantiation / syncing to occur after that process is done, not immediately when joining the session.
Any way to accomplish this? Thanks!

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: Delay syncing for joining players?
« Reply #5 on: September 12, 2017, 09:41:06 PM »
dartboy's reply would probably work. Channel#1 has a saved RFC for transmitting whatever data you need for your procedural generation and when that's complete you join Channel#2 for gameplay stuff. Back in 2013 TNet didn't have multi-channel support. Seems well suited to this task now.