private void doPlayerReconciliation(ClientPlayer player, NetworkingData.PlayerStateData playerState) { var reconciledPosition = playerState.Position; var max = player.reconciliationInputs.Count; if (player.reconciliationInputs.Count > 100) { Debug.LogError($"We seem to be leaking reconciliation inputs (count: {player.reconciliationInputs.Count}"); } for (int x = 0; x < max; x++) { var nextInput = player.reconciliationInputs.Dequeue(); if (nextInput.InputSeq >= playerState.LastProcessedInput) { reconciledPosition = PlayerMovement.MovePlayer(nextInput, reconciledPosition, nextInput.DeltaTime); } var renderPosition = player.transform.localPosition; if (Vector2.Distance(new Vector2(renderPosition.x, renderPosition.y), reconciledPosition) > 0.05f) { //TODO may want to really, really re-verify this reconciliation logic isn't causing issues/popping/choppy rendering //TODO remove me Debug.Log($"reconciling position from rendered position: {renderPosition.x}, {renderPosition.y} to server position: {reconciledPosition.X}, {reconciledPosition.Y}"); player.transform.localPosition = new Vector3(reconciledPosition.X, reconciledPosition.Y, 0); } } }
void OnGazeData(double x, double y, double timestamp) { _curPos.X = MovingAverageWeight * (float)x + (1 - MovingAverageWeight) * _curPos.X; _curPos.Y = MovingAverageWeight * (float)y + (1 - MovingAverageWeight) * _curPos.Y; if (Vec2.Distance(_curPos, _lastWarpPoint) > _warpPointRadius) { _lastWarpPoint = _curPos; } if (_enableDebugLogs) { Console.WriteLine("New Position: ({0},{1})", _curPos.X, _curPos.Y); } if (_moveKeyPressed) { SetMousePosition(); } }
/// <summary> /// Returns the first walkable adjacent node that is closest to pRefPoint. /// </summary> public Vector2?GetClosestWalkable(Vector2 pPoint, Vector2 pRefPoint) { if (IsWalkable(pPoint)) { return(pPoint); } List <Node> neighbours = new List <Node>(); const int max_steps = 3; //todo: make dependent on input parameter? for (int dist = 1; dist < max_steps; dist++) { neighbours = GetNodesInDistance(GetNode(pPoint), dist, true); if (IsAnyWalkable(neighbours)) { break; } else { neighbours.Clear(); } } //sort ascending based on distance to pRefPoint neighbours.Sort((a, b) => Vector2.Distance(a.Center, pRefPoint) .CompareTo(Vector2.Distance(b.Center, pRefPoint))); foreach (var n in neighbours) { if (n.Walkable) { return(n.Center); } } return(null); }
[MethodImpl(MethodImplOptions.AggressiveInlining)] public static FLOAT Distance(VECTOR a, VECTOR b) { return(VECTOR.Distance(a, b)); }