Client LuaCsForBarotrauma
BarotraumaShared/SharedSource/Characters/CharacterNetworking.cs
2 using Microsoft.Xna.Framework;
3 using System;
4 using System.Collections.Generic;
5 
6 namespace Barotrauma
7 {
9  {
10  public readonly Direction Direction;
11 
12  public readonly Character SelectedCharacter;
13  public readonly Item SelectedItem, SelectedSecondaryItem;
14 
16 
17  public CharacterStateInfo(Vector2 pos, float? rotation, Vector2 velocity, float? angularVelocity, float time, Direction dir, Character selectedCharacter, Item selectedItem, Item selectedSecondaryItem, AnimController.Animation animation = AnimController.Animation.None)
18  : this(pos, rotation, velocity, angularVelocity, 0, time, dir, selectedCharacter, selectedItem, selectedSecondaryItem, animation)
19  {
20  }
21 
22  public CharacterStateInfo(Vector2 pos, float? rotation, UInt16 ID, Direction dir, Character selectedCharacter, Item selectedItem, Item selectedSecondaryItem, AnimController.Animation animation = AnimController.Animation.None)
23  : this(pos, rotation, Vector2.Zero, 0.0f, ID, 0.0f, dir, selectedCharacter, selectedItem, selectedSecondaryItem, animation)
24  {
25  }
26 
27  protected CharacterStateInfo(Vector2 pos, float? rotation, Vector2 velocity, float? angularVelocity, UInt16 ID, float time, Direction dir, Character selectedCharacter, Item selectedItem, Item selectedSecondaryItem, AnimController.Animation animation = AnimController.Animation.None)
28  : base(pos, rotation, velocity, angularVelocity, ID, time)
29  {
30  Direction = dir;
31  SelectedCharacter = selectedCharacter;
32  SelectedItem = selectedItem;
33  SelectedSecondaryItem = selectedSecondaryItem;
34 
35  Animation = animation;
36  }
37  }
38 
39  partial class Character
40  {
41  [Flags]
42  private enum InputNetFlags : ushort
43  {
44  None = 0x0,
45  Left = 0x1,
46  Right = 0x2,
47  Up = 0x4,
48  Down = 0x8,
49  FacingLeft = 0x10,
50  Run = 0x20,
51  Crouch = 0x40,
52  Select = 0x80,
53  Use = 0x100,
54  Aim = 0x200,
55  Attack = 0x400,
56  Ragdoll = 0x800,
57  Health = 0x1000,
58  Grab = 0x2000,
59  Deselect = 0x4000, // 16384
60  Shoot = 0x8000, // 32768
61 
62  MaxVal = 0xFFFF // 65535
63  //MaxVal = 0x7FFF // 32767
64  //MaxVal = 0x3FFF // 16383
65  }
66  private InputNetFlags dequeuedInput = 0;
67  private InputNetFlags prevDequeuedInput = 0;
68 
69  public UInt16 LastNetworkUpdateID = 0;
70 
74  public UInt16 LastProcessedID;
75 
76  private struct NetInputMem
77  {
78  public InputNetFlags states; //keys pressed/other boolean states at this step
79  public UInt16 intAim; //aim angle, represented as an unsigned short where 0=0º, 65535=just a bit under 360º
80  public UInt16 interact; //id of the entity being interacted with
81 
82  public UInt16 networkUpdateID;
83  }
84 
85  private readonly List<NetInputMem> memInput = new List<NetInputMem>();
86 
87  private readonly List<CharacterStateInfo> memState = new List<CharacterStateInfo>();
88  private readonly List<CharacterStateInfo> memLocalState = new List<CharacterStateInfo>();
89 
90  public float healthUpdateTimer;
91 
92  private float healthUpdateInterval;
93  public float HealthUpdateInterval
94  {
95  get { return healthUpdateInterval; }
96  set
97  {
98  healthUpdateInterval = MathHelper.Clamp(value, 0.0f, IsDead ? NetConfig.MaxHealthUpdateIntervalDead : NetConfig.MaxHealthUpdateInterval);
99  healthUpdateTimer = Math.Min(healthUpdateTimer, healthUpdateInterval);
100  }
101  }
102 
103  public bool isSynced = false;
104 
105  public List<CharacterStateInfo> MemState
106  {
107  get { return memState; }
108  }
109 
110  public List<CharacterStateInfo> MemLocalState
111  {
112  get { return memLocalState; }
113  }
114 
115  public void ResetNetState()
116  {
117  memInput.Clear();
118  memState.Clear();
119  memLocalState.Clear();
120 
122  LastProcessedID = 0;
123  }
124 
125  partial void UpdateNetInput();
126  }
127 }
UInt16 LastProcessedID
ID of the last inputs the server has processed
CharacterStateInfo(Vector2 pos, float? rotation, Vector2 velocity, float? angularVelocity, UInt16 ID, float time, Direction dir, Character selectedCharacter, Item selectedItem, Item selectedSecondaryItem, AnimController.Animation animation=AnimController.Animation.None)
CharacterStateInfo(Vector2 pos, float? rotation, UInt16 ID, Direction dir, Character selectedCharacter, Item selectedItem, Item selectedSecondaryItem, AnimController.Animation animation=AnimController.Animation.None)
CharacterStateInfo(Vector2 pos, float? rotation, Vector2 velocity, float? angularVelocity, float time, Direction dir, Character selectedCharacter, Item selectedItem, Item selectedSecondaryItem, AnimController.Animation animation=AnimController.Animation.None)