Author Topic: Coding Style Question  (Read 2030 times)

phoenix

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 49
    • View Profile
Coding Style Question
« on: September 22, 2016, 06:14:00 PM »
I was wondering why you make so much of the Client static ?

I am upgrading now and I prefer not to have a static TNManager or TNObject or TNLobby(s).

It is not too difficult for me to change it except that you are using TNManager.isPaused in the TNet/Server and I wanted to find a way to decouple the Server from the Client?

TNManager.isPaused is the only dependency in the TNet/Server


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Coding Style Question
« Reply #1 on: September 23, 2016, 03:43:12 PM »
TNet is split into stand-alone and Unity side. Stand-alone is what's used by the server, and it doesn't use singletons / statics.

Unity side of it does use statics / singletons, and is because there shouldn't be more than one TNManager in the scene. TNManager.isPaused is used to put packet processing on hold while Unity is loading the scene. To decouple it, you could simply create a boolean flag on the GameServer that you could set, but at this point I would question the reasons for doing this in the first place. Why are you trying to remove the singletons?

phoenix

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 49
    • View Profile
Re: Coding Style Question
« Reply #2 on: September 25, 2016, 12:24:24 AM »
I think I am going to refactor the Pause into the Gameserver

The reason I removed the static / singletons is to have multiple connections so  I can have a computer that hosts gameserver as well as connects to another computers gameserver at the same time.

Is there another way to have a computer have more then one gameserver?

For example something like words with friends, where I host games and other people connect to me on TNManager[0] and I connect to other peoples games on TNManager[1]

 I was thinking perhaps channels could accomplish much of this but how to both allow computers to connect to computer A channel 0
and have computer A connect to another computer on channel 1

Perhaps a further refactoring would be a TNManager[0], TNObject[0], Lobby/Sserver instance per channel where it can be passed in or spawn a new instance?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Coding Style Question
« Reply #3 on: September 25, 2016, 08:14:41 PM »
I'm not sure what multiple servers would accomplish here. You can connect to a central server instead. Connect to a central server, join one or multiple channels. Even if going with a peer-to-peer approach you can have players connect to a central lobby server where they will advertise their own game servers which other players will then connect to. You can keep a connection to the lobby server active. The lobby server is a good example of how you can create an additional server if you really wanted to -- it's minimalistic and is designed only for a specific task -- but I recommend you try my previous suggestions first.