1
TNet 3 Support / Re: Area of Interest
« on: February 06, 2014, 12:20:19 AM »
Turned out to not be too difficult to add this myself.
(to clarify the following, when I say TNServer I mean the actual physical server that comes with TNet, and when I say Game Server I mean a special build of my game that spins up a TNServer and joins as the host)
So I modified TNServer to add a "blacklist". So I can essentially register a TcpPlayer with a particular UID. So when the TNServer goes to send an RFC to everyone, it checks if a given player is on the blacklist for the given TNObject UID before sending.
I added a new Packet.RequestSetScope. This tells the TNServer to add or remove the given player from the blacklist of a given UID. It also generates ResponseDestroy and ResponseCreate packets if you set scope to False or True (respectively).
Then I wrapped this with a function TNObject.SetScope( TNet.Player player, bool hasScope ) which sends the RequestSetScope packet to the TNServer.
I use this for my area of interest management like this:
- Interesting Objects are sorted into a quadtree each frame.
- Interest Observers (players) query the quadtree for nearby objects within their area of interest. When new objects enter their area of interest, they call newObject.SetScope( myOwner, true ), and when objects leave their area of interest they call leavingObject.SetScope( myOwner, false ). This is performed on the Game Server (which always has all objects loaded, and never has it's own player)
Beyond an edge case (nullref exception is throwing my Game Server for a loop at the moment, nothing a little debugging can't fix), it appears to be working perfectly. If I walk away from my spawned enemy mob, they are deleted from the scene. If I return, they get re-instantiated.
So far has taken about a day.
EDIT: There's always another edge case, lol.
(to clarify the following, when I say TNServer I mean the actual physical server that comes with TNet, and when I say Game Server I mean a special build of my game that spins up a TNServer and joins as the host)
So I modified TNServer to add a "blacklist". So I can essentially register a TcpPlayer with a particular UID. So when the TNServer goes to send an RFC to everyone, it checks if a given player is on the blacklist for the given TNObject UID before sending.
I added a new Packet.RequestSetScope. This tells the TNServer to add or remove the given player from the blacklist of a given UID. It also generates ResponseDestroy and ResponseCreate packets if you set scope to False or True (respectively).
Then I wrapped this with a function TNObject.SetScope( TNet.Player player, bool hasScope ) which sends the RequestSetScope packet to the TNServer.
I use this for my area of interest management like this:
- Interesting Objects are sorted into a quadtree each frame.
- Interest Observers (players) query the quadtree for nearby objects within their area of interest. When new objects enter their area of interest, they call newObject.SetScope( myOwner, true ), and when objects leave their area of interest they call leavingObject.SetScope( myOwner, false ). This is performed on the Game Server (which always has all objects loaded, and never has it's own player)
Beyond an edge case (nullref exception is throwing my Game Server for a loop at the moment, nothing a little debugging can't fix), it appears to be working perfectly. If I walk away from my spawned enemy mob, they are deleted from the scene. If I return, they get re-instantiated.
So far has taken about a day.
EDIT: There's always another edge case, lol.

