241
TNet 3 Support / Re: Sync player states and animations
« on: May 27, 2016, 02:44:17 AM »
Sorry, you don't have to use bitpacking.
Fixed up the relevant parts for you:
But to answer your question, packedInputs <<= 16; is the same as writing packedInputs = packedInputs << 16;
The "<<" operator in this context shifts packedInputs to the left 16 bits.
More info on MSDN: https://msdn.microsoft.com/en-us/library/a1sway8w.aspx
In case you were confused by the |= operator as well, that's a bitwise OR.
The wikipedia article explains the bitwise operators really well: https://en.wikipedia.org/wiki/Bitwise_operation#OR
But the relevant part of my previous post stands: Send your inputs instead of your results. Receive the inputs and calculate the results on each client. With this, handling animations should be literally the exact same as handling it on the local player. Absolutely no distinction between the two: no extra code, nada.
Fixed up the relevant parts for you:
- IEnumerator SyncInput()
- {
- while(TNManager.isInChannel)
- {
- // note: most Input.Getblahblah calls should be made in the Update() function, GetAxis is the exception.
- short horizontalInput = Input.GetAxis("Horizontal").ToShort();
- short verticalInput = Input.GetAxis("Vertical").ToShort();
- tno.Send(NetworkManager.NETID_SYNC_INPUT, Target.OthersSaved, horizontalInput, verticalInput);
- }
- }
- [RFC(NetworkManager.NETID_SYNC_INPUT)]
- public void ReceiveInput(short horizontal, short vertical)
- {
- float horizontalInput = horizontal.ToSingle();
- float verticalInput = vertical.ToSingle();
- // set the CharacterController's values according to the input received
- }
But to answer your question, packedInputs <<= 16; is the same as writing packedInputs = packedInputs << 16;
The "<<" operator in this context shifts packedInputs to the left 16 bits.
- byte packedByte = 9;
- // packedByte bits:
- // 00001001
- // if you were to do Debug.Log(packedByte.ToString()) the output would be 9.
- packedByte = (byte)((int)packedByte << 4);
- // packedByte bits:
- // 10010000
- // if you were to do Debug.Log(packedByte.ToString()) the output would be 144.
- // you can then fit another value between 0-15 into packedByte
- // inserting the value via the OR operator
- packedByte = (byte)((int)packedByte | 6);
- // packedByte bits:
- // 10010110
- // if you were to do Debug.Log(packedByte.ToString()) the output would be 150.
- // now you have two values stored in a single byte: 9 and 6.
In case you were confused by the |= operator as well, that's a bitwise OR.
The wikipedia article explains the bitwise operators really well: https://en.wikipedia.org/wiki/Bitwise_operation#OR
But the relevant part of my previous post stands: Send your inputs instead of your results. Receive the inputs and calculate the results on each client. With this, handling animations should be literally the exact same as handling it on the local player. Absolutely no distinction between the two: no extra code, nada.