Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
CurveKeyCollection.cs
Go to the documentation of this file.
1using System;
5
7
10public class CurveKeyCollection : ICollection<CurveKey>, IEnumerable<CurveKey>, IEnumerable
11{
13
14 internal float TimeRange;
15
16 internal float InvTimeRange;
17
18 internal bool IsCacheAvailable = true;
19
20 public CurveKey this[int index]
21 {
22 get
23 {
24 return Keys[index];
25 }
26 set
27 {
28 if (value == null)
29 {
30 throw new ArgumentNullException();
31 }
32 float position = Keys[index].Position;
33 if (position == value.Position)
34 {
35 Keys[index] = value;
36 return;
37 }
38 Keys.RemoveAt(index);
39 Add(value);
40 }
41 }
42
43 public int Count => Keys.Count;
44
45 public bool IsReadOnly => false;
46
47 public int IndexOf(CurveKey item)
48 {
49 return Keys.IndexOf(item);
50 }
51
52 public void RemoveAt(int index)
53 {
54 Keys.RemoveAt(index);
55 IsCacheAvailable = false;
56 }
57
58 public void Add(CurveKey item)
59 {
60 if (item == null)
61 {
62 throw new ArgumentNullException();
63 }
64 int i = Keys.BinarySearch(item);
65 if (i >= 0)
66 {
67 for (; i < Keys.Count && item.Position == Keys[i].Position; i++)
68 {
69 }
70 }
71 else
72 {
73 i = ~i;
74 }
75 Keys.Insert(i, item);
76 IsCacheAvailable = false;
77 }
78
79 public void Clear()
80 {
81 Keys.Clear();
82 TimeRange = (InvTimeRange = 0f);
83 IsCacheAvailable = false;
84 }
85
86 public bool Contains(CurveKey item)
87 {
88 return Keys.Contains(item);
89 }
90
91 public void CopyTo(CurveKey[] array, int arrayIndex)
92 {
94 IsCacheAvailable = false;
95 }
96
97 public bool Remove(CurveKey item)
98 {
99 IsCacheAvailable = false;
100 return Keys.Remove(item);
101 }
102
104 {
105 return Keys.GetEnumerator();
106 }
107
112
114 {
116 curveKeyCollection.Keys = new List<CurveKey>(Keys);
117 curveKeyCollection.InvTimeRange = InvTimeRange;
118 curveKeyCollection.TimeRange = TimeRange;
119 curveKeyCollection.IsCacheAvailable = true;
120 return curveKeyCollection;
121 }
122
123 internal void ComputeCacheValues()
124 {
125 TimeRange = (InvTimeRange = 0f);
126 if (Keys.Count > 1)
127 {
128 TimeRange = Keys[Keys.Count - 1].Position - Keys[0].Position;
129 if (TimeRange > float.Epsilon)
130 {
131 InvTimeRange = 1f / TimeRange;
132 }
133 }
134 IsCacheAvailable = true;
135 }
136}
void CopyTo(CurveKey[] array, int arrayIndex)
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
void CopyTo(KeyValuePair< TKey, TValue >[] array, int index)
bool ICollection< KeyValuePair< TKey, TValue > >. Contains(KeyValuePair< TKey, TValue > keyValuePair)
new IEnumerator< T > GetEnumerator()