-
Notifications
You must be signed in to change notification settings - Fork 3
/
FlightCtrlStateBuffer.cs
82 lines (71 loc) · 2.61 KB
/
FlightCtrlStateBuffer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace RemoteTech
{
//used to delay ctrl inputs by saving FlightCtrlStates between the time they are entered
//by the user and the time they are applied to the craft
public class FlightCtrlStateBuffer
{
Queue<TimedCtrlState> states = new Queue<TimedCtrlState>();
public float pitch, roll, yaw;
//save the flight control state entered at a given time
public void push(FlightCtrlState state, double time)
{
TimedCtrlState savedCopy = new TimedCtrlState();
savedCopy.flightCtrlState = new FlightCtrlState();
savedCopy.flightCtrlState.CopyFrom(state);
savedCopy.ActTime = time;
states.Enqueue(savedCopy);
// this saves the current attitude control values to a sepperate controlstate, that way attitude control is allways accesible without delay
pitch = state.pitch;
roll = state.roll;
yaw = state.yaw;
}
public void setNeutral(FlightCtrlState s)
{
s.fastThrottle = 0;
s.gearDown = false;
s.gearUp = false;
s.headlight = false;
s.killRot = false;
s.mainThrottle = 0;
s.pitch = 0;
s.pitchTrim = 0;
s.roll = 0;
s.rollTrim = 0;
s.X = 0;
s.Y = 0;
s.yaw = 0;
s.yawTrim = 0;
s.Z = 0;
s.wheelSteer = 0;
s.wheelSteerTrim = 0;
s.wheelThrottle = 0;
s.wheelThrottleTrim = 0;
}
//retrieve the flight control state entered at a given time
public void pop(FlightCtrlState controls, double time)
{
if (states.Count == 0 || states.Peek().ActTime > time)
{
setNeutral(controls);
return; //returns neutral if no controls are entered or the entered controls are not within the signal delay
}
TimedCtrlState popState = states.Peek();
while (states.Peek().ActTime < time)
{
popState = states.Dequeue();
}
controls.CopyFrom(popState.flightCtrlState);
if (controls.killRot) // this overrides the delay in attitute control if SAS is activated. Thereby allowing SAS to make control changes without delay
{
controls.pitch = pitch;
controls.roll = roll;
controls.yaw = yaw;
}
}
}
}