NetworPlayerInputs struct (Experimental) #3954
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Note: To reduce the amount of code for the
NetworkPlayerControllerBase
i want to push some stand alone things.Network Player Inputs Struct
This struct is intended to transfer the most common inputs as efficiently as possible ( see diagram ) with addition of 2 functions:
Defaults passed in constructor
The goal of this feature is to allow the server to easily extend a previous tick inputs in case of partial inputs received
or no inputs received at all ( packet loss )
Extract only the changed inputs
The goal here is to allow simple extraction of changed inputs to reduce traffic significantly, especially when working with movement vectors.For example:
W
there will be no data sent to the server since nothing changedW
but moves the mouse to look then we will only send rotation information overThis will override the changed inputs of the
newInputs
.[edit]
Simplified overrides of 2 NetworkPlayerInputs structs
This is particularly usefull to reduce the code size when sending the changes over network
Usage example
note: If ticks are not used the TickNumber can be used to pass any number in the range of 0-2047
Fields:
Int TickNumber
- mutable int of 11bits ( 0-2047 ) that contains the tick the input happened on the clientVector2? MovementVector
- reduced accuracy (254 fractions) for normalized movement vector (x: -1 to 1, y:-1 to 1)Vector2? JoystickVector
- reduced accuracy (254 fractions) for normalized right joystick vector (x: -1 to 1, y:-1 to 1)Vector2? MouseVector
- Half precision mouse position vector (float16)byte[]? AdditionalInputs
- Any additional inputs required for the game to run, they are compared as a byte array and if any byte is different will be sentFor binary structure see the diagram bellow.
note: In unity in both of the controller sticks produce -1 to 1 values, they are small and can allow for lower precision. If a more precise rotation is requires it is always possible to pass them as MouseVector
Byte Structure Diagram
Summary i guess...
This is 1 of 2 structs i want to introduce to allow for a simple and coherent exchange of inputs and states between server and client.
The second one will be related for the server to send player state for comparison and reconciliation on the client.