-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVehicleScheduleData.Measurement.cs
67 lines (59 loc) · 2.15 KB
/
VehicleScheduleData.Measurement.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
using System;
using VoxelTycoon;
using VoxelTycoon.Serialization;
using VoxelTycoon.Tracks;
using VoxelTycoon.Tracks.Tasks;
namespace ScheduleStopwatch
{
public partial class VehicleScheduleData
{
private abstract class Measurement
{
protected VehicleScheduleData _vehicleScheduleData;
public DateTime? startTime, endTime;
public RootTask Task { get; protected set; }
public bool IsFinished { get; private set; }
public TimeSpan measuredTime
{
get
{
if (IsFinished)
{
return endTime.Value - startTime.Value;
}
throw new InvalidOperationException("Measurement is not finished");
}
}
public Measurement(VehicleScheduleData data, RootTask task)
{
startTime = TimeManager.Current.DateTime;
this.Task = task;
_vehicleScheduleData = data;
}
public virtual void Finish()
{
endTime = TimeManager.Current.DateTime;
IsFinished = true;
OnFinished();
}
public abstract void OnFinished();
internal virtual void Write(StateBinaryWriter writer)
{
writer.WriteInt(Task.GetIndex());
MeasurementSurrogate.Write(writer, this);
writer.WriteLong(startTime.Value.Ticks);
}
internal static Measurement Read(StateBinaryReader reader, VehicleSchedule schedule, VehicleScheduleData data)
{
RootTask task = schedule.GetTasks()[reader.ReadInt()];
Measurement result = MeasurementSurrogate.Read(reader, data, task);
result.DoRead(reader, schedule, data);
return result;
}
protected virtual void DoRead(StateBinaryReader reader, VehicleSchedule schedule, VehicleScheduleData data)
{
startTime = new DateTime(reader.ReadLong());
}
}
}
}