Author Topic: RFC rfcID limit  (Read 2762 times)

fretnoize

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 16
    • View Profile
RFC rfcID limit
« on: June 11, 2014, 01:19:02 AM »
Hi, I'd like to benefit from the efficiency of the rfcID byte, but I'm considering creating a look-up table of sorts to retain code readability as much as possible. (If there's something built in for this, feel free to let me know)

From this post (http://www.tasharen.com/forum/index.php?topic=4826.0) Aren mentions "Relative to the TNObject. Each TNObject can have up to 255 numbered functions."

I'd like to confirm what I think this means.

Let's say I have object A with the TNObject script and script A1 and script A2 attached to that object. I also have Object B with the TNObject script and Script B attached to it. Between scripts A1 and A2 I can use a total of 255 numbered functions between both of them. Script B will be able to use its own 255 numbered functions as well, not having to share with other scripts.

Is this right?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: RFC rfcID limit
« Reply #1 on: June 11, 2014, 06:14:19 AM »
Yup, that's correct.

I don't advise using that many numbered functions in any case. It just makes it more difficult to read. It's a good idea to use numbered functions for packets that you expect to be sending frequently -- more than a few times per second.

fretnoize

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: RFC rfcID limit
« Reply #2 on: June 11, 2014, 09:53:22 PM »
Well I made a quick and dirty look-up table of sorts that will retain some readability. I'm willing to bet there's probably a better approach, but I figured I'd share with others.

Basically I use an enum with byte values. The first enum I mark as reserved, since you can't use that for an rfcID. You can just add your functions after that, like I did with MyRFCFunction. Then you define the rfc and call it like I do below. It's an extra step, but I think it helps with readability. Hope someone finds this useful!

  1. public enum rfcEnumMyObject : byte
  2. {
  3.         ReservedForZero, //don't use zero as an rfcID
  4.         MyRFCFunction
  5. }
  6.  
  7. public class MyObjectScript : MonoBehaviour
  8. {
  9.         public TNObject tno;
  10.         int x = 0;
  11.  
  12.         void Update()
  13.         {
  14.                 if(x == 1)
  15.                 {
  16.                         tno.Send((byte)rfcEnumMyObject.MyRFCFunction, TNet.Target.All);
  17.                 }
  18.         }
  19.  
  20.         [RFC((byte)rfcEnumMyObject.MyRFCFunction)]
  21.         void MyRFCFunction()
  22.         {
  23.                 x = 1;
  24.         }
  25. }
  26.  

Deozaan

  • Newbie
  • *
  • Thank You
  • -Given: 44
  • -Receive: 4
  • Posts: 42
    • View Profile
    • Deozaan.com
Re: RFC rfcID limit
« Reply #3 on: June 13, 2014, 02:25:32 PM »
You know you can assign numbers to enums? So you don't have to start at 0.

  1. public enum RFCs : byte {
  2.     MyFirstRFC = 1, // don't start at zero
  3.     MySecondRFC,
  4.     MyThirdRFC,
  5.     LotsOfSpaceToAddMoreRFCsAbove = 50,
  6.     MyFiftyFirstRFC
  7. }

fretnoize

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: RFC rfcID limit
« Reply #4 on: June 15, 2014, 09:15:24 PM »
yeah, sorry I was being a little redundant.  :-[