Author Topic: Question about GameServer  (Read 3942 times)

Knightmare

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 8
    • View Profile
Question about GameServer
« on: January 29, 2015, 01:20:17 AM »
So I start the server right in Unity and I've noticed that it's Multi-threaded. I have just finished up some Pathfinding code and it's pretty greedy and sucks up a few some performance on the main thread. So before I start delving into threading alongside TNet, is there anything I should know outside the typical issues with Unity. What sort of things do you recommend to work in conjunction with TNet whilst keeping in client.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Question about GameServer
« Reply #1 on: January 29, 2015, 01:30:52 PM »
TNet's packets all arrive on different threads. Processing of said packets is done on the main thread however -- in your Update(). When working with Unity anything that interacts with any Unity object must be executed on the main thread as Unity itself is not multi-thread safe. So from your point of view it will be as if TNet is not actually multi-threaded.

In Windward I wrote my own pathfinding script that does its logic on a separate worker thread, then posts the result to the main thread. I check in the Update -- are there any pathfinding results ready? If so, run through them and execute the associated delegate functions.

Knightmare

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: Question about GameServer
« Reply #2 on: January 29, 2015, 08:38:34 PM »
Thanks for the reply, and in fact that's exactly how I have my Pathfinding module setup where I have my worker threads that won't touch Unity's api until completion of the batched queued tasks. My issue is that I have heard of issues with multiple scripts working with Threading and Unity as some things can't be used in conjunction with Unity such as Thread Pool class.

So I guess I my question was more related to having two separate script pooling threads such as my Thread Manager and TNet. Maybe it's just my own ignorance of how System.Threading works with others pieces of code and if it plays nicely I suppose.

Either way, my separate path finding module works very well with my Thread Manager. My path finding basically uses your typical Dijkstra but with NxN sized characters on a 1x1 grid to obtain all possible tiles with a set movement cost which is a bit costly because its not just your typical A* which I later use if its within the closedset returned from dijkstra.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Question about GameServer
« Reply #3 on: January 30, 2015, 03:14:52 PM »
Well as I said, the threading aspect of TNet is completely invisible to users. TNet's callbacks always get executed from the main thread like the rest of Unity's Update() functions.

Knightmare

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: Question about GameServer
« Reply #4 on: January 30, 2015, 09:32:44 PM »
Right, I was mainly asking if I can have my own threading system alongside TNet and it appears I can. Thanks, I was just worried about some unforeseen conflict with two things calling System.Threading if it were the case.