Author Topic: Multiple scene networking / channel question(s)  (Read 4237 times)

Vorrtex

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 4
    • View Profile
Multiple scene networking / channel question(s)
« on: July 22, 2014, 01:14:22 PM »
I want to preface that I'm new to network programming and methodologies as a whole, but I've been doing a lot of research on Unity networking solutions and yours seems to be the best fit for me. I've been spiking out which to use and thus, have not bought one yet.

I'm creating a multiplayer adventure game that is client hosted and contains several scenes. One of the biggest hurdles for me is multi-scene games. No example I've come across goes over this and I'm not sure if this is because they aren't possible or if the logic behind them is so simple that no one bothers. I'm looking for clarification.

So I have Player 1 (P1) and Player 2 (P2). P1 creates a game and loads Scene1. P2 joins the game and also loads Scene1. This is as far as most tutorials/examples/etc go. Let me know if any of the following is incorrect:

From here we use channels to divide the network traffic - generally 1 channel per scene and another channel for things like chat. So P1 and P2 are in channel1 together in scene1. P2 wants to go ahead and goes to the "load scene2" trigger, which then makes P2 leave channel1 and join channel2 (for scene2). Now, scene2 has some things that need to be generated on load, like which enemies to spawn - which should be done on the server/host - in this case P1.

Is it possible for P1 to be in scene1 (and channel1) while feeding state information of scene2 (over channel2) to P2? Would this be done through RFC / RPC calls? What's the best way to handle a situation like this?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Multiple scene networking / channel question(s)
« Reply #1 on: July 22, 2014, 08:03:32 PM »
When you use TNManager.LoadLevel, TNet will switch the scene for all players who are in the channel, not just your own. Newly joined players will automatically load this new scene rather than the original one.

You can, of course, treat each scene as a separate channel if you want. In games like EverQuest that would be the case -- you enter a new scene by leaving the old channel and joining a new one, and you'll never use TNManager.LoadLevel at all. It depends on what you want to do.

Vorrtex

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: Multiple scene networking / channel question(s)
« Reply #2 on: July 23, 2014, 10:57:11 AM »
Let's say I never used TNManager.LoadLevel and had one channel per scene. If P1 is hosting and P2 is in a different scene, in a separate channel, how would the host know to update the scene P2 is in?

Would P2 just have to tell P1 that it's the first/only player in the scene, so it will be taking over the reigns for that specific scene?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Multiple scene networking / channel question(s)
« Reply #3 on: July 23, 2014, 09:42:02 PM »
You would use a specific channel ID for each zone in this case. For example if you want to load level "P1" you would join channel 1. If you want to load level "P2", you would join channel 2, etc. That's what I am doing in Windward, actually. The map is a 2-dimensional grid, and each zone has an ID that's a combination of its X and Y position, resulting in a unique identifier. I use these IDs as channel IDs, so when I travel from zone A into zone B, I simply switch channels.

Deozaan

  • Newbie
  • *
  • Thank You
  • -Given: 44
  • -Receive: 4
  • Posts: 42
    • View Profile
    • Deozaan.com
Re: Multiple scene networking / channel question(s)
« Reply #4 on: July 29, 2014, 12:19:30 AM »
So I have Player 1 (P1) and Player 2 (P2). P1 creates a game and loads Scene1. P2 joins the game and also loads Scene1. This is as far as most tutorials/examples/etc go. Let me know if any of the following is incorrect:

From here we use channels to divide the network traffic - generally 1 channel per scene and another channel for things like chat. So P1 and P2 are in channel1 together in scene1. P2 wants to go ahead and goes to the "load scene2" trigger, which then makes P2 leave channel1 and join channel2 (for scene2). Now, scene2 has some things that need to be generated on load, like which enemies to spawn - which should be done on the server/host - in this case P1.

Is it possible for P1 to be in scene1 (and channel1) while feeding state information of scene2 (over channel2) to P2? Would this be done through RFC / RPC calls? What's the best way to handle a situation like this?

Let's say I [...] had one channel per scene. If P1 is hosting and P2 is in a different scene, in a separate channel, how would the host know to update the scene P2 is in?

Would P2 just have to tell P1 that it's the first/only player in the scene, so it will be taking over the reigns for that specific scene?

I'm not sure if you fully understand the difference between Server, Host, and Client as far as TNet is concerned.

Server: Software that facilitates routing packets back and forth between players over the network.
Host: The player (a client) who first joins/creates a channel. If the host leaves the channel, a new host is automatically selected from among the remaining players in the channel.
Client: Any player connected to the Server.

Note that a player can be acting as server and client/host at the same time!

In your scenario, when P1 joins Ch1, P1 will become the Host of that channel. And when P2 joins, he will be a regular client.

But once P2 joins/creates Ch2, P2 will become Host of Ch2 (assuming nobody else is already in Ch2). P1 will continue to be Host of Ch1 until he leaves that channel. Basically, each channel will have its own Host: one of the clients currently connected to that channel.

I hope that was clear. And correct. (c:
« Last Edit: July 29, 2014, 12:25:45 AM by Deozaan »

Vorrtex

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: Multiple scene networking / channel question(s)
« Reply #5 on: August 01, 2014, 07:20:00 PM »
@Deozaan that makes way more sense! So if there's enemies in a scene and the host leaves, TNet reassigns the host to a remaining player and then the game logic for the enemies' AI/Logic is performed on the new host?

Thanks for clearing that up!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Multiple scene networking / channel question(s)
« Reply #6 on: August 01, 2014, 09:47:47 PM »
Yup, and it's all seamless from your perspective, provided your AI logic is wrapped in "if (TNManager.isHosting)".