Client LuaCsForBarotrauma
NetConfig.cs
1 using Microsoft.Xna.Framework;
2 using System;
3 
4 namespace Barotrauma.Networking
5 {
6  static class NetConfig
7  {
8  public const int DefaultPort = 27015;
9  public const int DefaultQueryPort = 27016;
10 
11  public static int MaxPlayers = 256;
12 
13  public static int ServerNameMaxLength = 60;
14  public static int ServerMessageMaxLength = 2000;
15 
16  public const float MaxPhysicsBodyVelocity = 64.0f;
17  public const float MaxPhysicsBodyAngularVelocity = 16.0f;
18 
19  public static float MaxHealthUpdateInterval = 2.0f;
20  public static float MaxHealthUpdateIntervalDead = 10.0f;
21 
22  public static float HighPrioCharacterPositionUpdateDistance = 1000.0f;
23  public static float LowPrioCharacterPositionUpdateDistance = 10000.0f;
24  public static float HighPrioCharacterPositionUpdateInterval = 0.0f;
25  public static float LowPrioCharacterPositionUpdateInterval = 1.0f;
26 
27  //this should be higher than LowPrioCharacterPositionUpdateInterval,
28  //otherwise the clients may freeze characters even though the server hasn't actually stopped sending position updates
29  public static float FreezeCharacterIfPositionDataMissingDelay = 2.0f;
30  public static float DisableCharacterIfPositionDataMissingDelay = 3.5f;
31 
32  public static float DeleteDisconnectedTime = 20.0f;
33 
34  public static float ItemConditionUpdateInterval = 0.15f;
35  public static float LevelObjectUpdateInterval = 0.5f;
36  public static float HullUpdateInterval = 0.5f;
37  public static float SparseHullUpdateInterval = 5.0f;
38  public static float HullUpdateDistance = 20000.0f;
39 
40  public static int MaxEventPacketsPerUpdate = 4;
41 
45  public static float RoundStartSyncDuration = 60.0f;
46 
50  public static float EventRemovalTime = 15.0f;
51 
55  public static float OldReceivedEventKickTime = 10.0f;
56 
60  public static float OldEventKickTime = 30.0f;
61 
65  public static Vector2 InterpolateSimPositionError(Vector2 simPositionError, float? smoothingFactor = null)
66  {
67  float lengthSqr = simPositionError.LengthSquared();
68  //correct immediately if the error is very large
69  if (lengthSqr > 100.0f) { return Vector2.Zero; }
70  float positionSmoothingFactor = smoothingFactor ?? MathHelper.Lerp(0.95f, 0.8f, MathHelper.Clamp(lengthSqr, 0.0f, 1.0f));
71  return simPositionError *= positionSmoothingFactor;
72  }
73 
77  public static float InterpolateRotationError(float rotationError)
78  {
79  //correct immediately if the error is very large
80  if (rotationError > MathHelper.TwoPi) { return 0.0f; }
81  float rotationSmoothingFactor = MathHelper.Lerp(0.95f, 0.8f, Math.Min(Math.Abs(rotationError), 1.0f));
82  return rotationError *= rotationSmoothingFactor;
83  }
84 
88  public static Vector2 InterpolateCursorPositionError(Vector2 cursorPositionError)
89  {
90  float lengthSqr = cursorPositionError.LengthSquared();
91  //correct immediately if the error is very large
92  if (lengthSqr > 1000.0f) { return Vector2.Zero; }
93  return cursorPositionError *= 0.7f;
94  }
95 
96  public static Vector2 Quantize(Vector2 value, float min, float max, int numberOfBits)
97  {
98  return new Vector2(
99  Quantize(value.X, min, max, numberOfBits),
100  Quantize(value.Y, min, max, numberOfBits));
101  }
102 
103  public static float Quantize(float value, float min, float max, int numberOfBits)
104  {
105  float step = (max - min) / (1 << (numberOfBits + 1));
106  if (Math.Abs(value) < step + 0.00001f)
107  {
108  return 0.0f;
109  }
110 
111  return MathUtils.RoundTowardsClosest(MathHelper.Clamp(value, min, max), step);
112  }
113  }
114 }