Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

WritePackedIntDelta diff is negative when expecting positive.

Discussion in 'Unity Transport' started by PolarTron, Feb 13, 2022.

  1. PolarTron

    PolarTron

    Joined:
    Jun 21, 2013
    Posts:
    88
    Let's say I have a value 10 and a baseline of 4. I expect the diff between these two to be 6 but the calculation of the diff makes it -6.

    Code (CSharp):
    1. int diff = (int)(baseline - value);
    Is this intended? Is it better for compression or something?
     
  2. simon-lemay-unity

    simon-lemay-unity

    Unity Technologies

    Joined:
    Jul 19, 2021
    Posts:
    416
    Good question! I'm not sure what the original rationale was for this choice, but my understanding of the code is that ultimately it shouldn't matter too much since negative values are interleaved with positive ones in the packed representation of integers (sequence is 0, -1, 1, -2, 2...).

    In your example, -6 ends up being stored in the stream as unsigned integer 11, whereas positive 6 would end up being stored as unsigned integer 12.
     
    PolarTron likes this.