Author Topic: Target.OthersSaved  (Read 2590 times)

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 9
  • Posts: 226
    • View Profile
Target.OthersSaved
« on: August 28, 2016, 08:59:57 AM »
I understand what this does, but can someone quickly describe how this works? I'm thinking that the same object that has many changes applied (eg switch or door) could result in a lot of redundant messages being sent to new players, and a big, memory hogging list being generated. Or is OthersSaved smarter than that?

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: Target.OthersSaved
« Reply #1 on: August 28, 2016, 08:48:14 PM »
When an RFC is sent a UID is generated for that RFC. This is a combination of the sending TNObject's ID (which itself is unique) and the RFC ID (or function name).
Serverside, when a forwarded packet that's designated to be saved is received, it iterates the channel's saved RFCs searching for the UID. If the UID is found then the value is updated, if it's not then a new saved RFC is created.

In short, the value will be updated if the RFC has been seen before. So, no redundant messages or big lists :)

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 9
  • Posts: 226
    • View Profile
Re: Target.OthersSaved
« Reply #2 on: August 30, 2016, 02:04:12 PM »
Good to know, although that also means an overhead in searching for existing UIDs, so ideally I guess it's to be avoided if one can. At least as an optimisation.

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: Target.OthersSaved
« Reply #3 on: August 30, 2016, 09:01:22 PM »
Hardly any overhead at all:
  1. for (int i = 0; i < rfcs.size; ++i)
  2. {
  3.         RFC r = rfcs[i];
  4.  
  5.         if (r.uid == inID && r.functionName == funcName)
  6.         {
  7.                 if (r.buffer != null) r.buffer.Recycle();
  8.                 r.buffer = b;
  9.                 return;
  10.         }
  11. }
  12.  

As someone that often optimizes *too* much, I wouldn't bother limiting OthersSaved usage. The utility it provides is extremely valuable, and its cost is practically nil.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Target.OthersSaved
« Reply #4 on: August 30, 2016, 09:49:27 PM »
What cmifwdll said. There is pretty much no cost, although if you're really worried you can use IDs instead of function names to eliminate string comparisons.