public CompressedElement Write(CompressedElement ce, byte[] bytes, ref int bitposition, BitCullingLevel bcl = BitCullingLevel.NoCulling) { if (!cached) { CacheValues(); } if (cache_isUniformScale) { uint c = (uint)ucrusher.Write(ce.cUniform, bytes, ref bitposition, bcl); return(new CompressedElement(this, c, cache_uBits[(int)bcl])); } else if (TRSType == TRSType.Quaternion) { ulong c = qcrusher.Write(ce.cQuat, bytes, ref bitposition); return(new CompressedElement(this, c, cache_qBits)); } //Debug.Log("CX write " + ce.cx); //else if (cache_mustCorrectRotationX) // v3 = FloatCrusherUtilities.GetXCorrectedEuler(v3); //Debug.Log("Writing Scale " + ce.cx); return(new CompressedElement( this, (uint)(cache_xEnabled ? (uint)xcrusher.Write(ce.cx, bytes, ref bitposition, bcl) : 0), (uint)(cache_yEnabled ? (uint)ycrusher.Write(ce.cy, bytes, ref bitposition, bcl) : 0), (uint)(cache_zEnabled ? (uint)zcrusher.Write(ce.cz, bytes, ref bitposition, bcl) : 0), cache_xBits[(int)bcl], cache_yBits[(int)bcl], cache_zBits[(int)bcl])); }
/// <summary> /// Write/Pack all of the values we want to network into a bitstream /// </summary> /// <param name="bitstream"></param> public void SerializeValuesToBitstream(byte[] bitstream, ref int writepos) { /// Write the NetId of the player this update belongs to. bitstream.Write((ulong)NetId, ref writepos, 32); /// Compress(crush) and serialize the values of the meter disk and the player color. meterCrusher.Write(meterval, bitstream, ref writepos); colorCrusher.Write(color.r, bitstream, ref writepos); colorCrusher.Write(color.g, bitstream, ref writepos); colorCrusher.Write(color.b, bitstream, ref writepos); /// Compress this objects current transform to the CompressedMatrix. sharedCrusher.Crusher.Compress(compMatrix, transform); /// For this example we compare the new CompressedMatrix with the previously sent one to see if anything has changed. /// If the compressed value has not changed, we will not send a compressed transform this tick. The == operator is overloaded /// for CompressedElement and CompressedMatrix, so == actually is running a.Equals(b) behind the scenes letting you compare the /// classes as if they were structs. if (compMatrix != sentCompMatrix) { /// Single true bit flag to indicate a compressed transform follows bitstream.WriteBool(true, ref writepos); /// Pass the bitstream to the TransformCrusher to serialize in the value of compMatrix. sharedCrusher.Crusher.Write(compMatrix, bitstream, ref writepos); /// Copy the values of of cm for comparison next tick. sentCompMatrix.CopyFrom(compMatrix); } else { /// Single false bit flag to indicate a compressed transform doesn't follow bitstream.WriteBool(false, ref writepos); } // as long as the bitstream isn't full, you can append other data as well onto the bitstream. // Bools only use one bit of traffic. bitstream.WriteBool(flasherIsOn, ref writepos); }