-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathVesselState.cs
41 lines (34 loc) · 1.34 KB
/
VesselState.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
using System;
using System.Reflection;
using KRPC.MechJeb.ExtensionMethods;
namespace KRPC.MechJeb {
internal class VesselState {
internal const string MechJebType = "MuMech.VesselState";
// Fields and methods
private static FieldInfo time;
private static FieldInfo celestialLongitudeField;
private static FieldInfo latitudeField;
private static FieldInfo longitudeField;
// Instance objects
private object instance;
private object celestialLongitude;
private object latitude;
private object longitude;
internal static void InitType(Type type) {
time = type.GetCheckedField("time");
celestialLongitudeField = type.GetCheckedField("celestialLongitude");
latitudeField = type.GetCheckedField("latitude");
longitudeField = type.GetCheckedField("longitude");
}
internal void InitInstance(object instance) {
this.instance = instance;
this.celestialLongitude = celestialLongitudeField.GetInstanceValue(instance);
this.latitude = latitudeField.GetInstanceValue(instance);
this.longitude = longitudeField.GetInstanceValue(instance);
}
public double Time => (double)time.GetInstanceValue(this.instance);
public double CelestialLongitude => MovingAverage.Get(this.celestialLongitude);
public double Latitude => MovingAverage.Get(this.latitude);
public double Longitude => MovingAverage.Get(this.longitude);
}
}