Skip to content
This repository has been archived by the owner on Oct 30, 2019. It is now read-only.

Commit

Permalink
Game.cs cleanup. Remove unneeded ApplyChanges.
Browse files Browse the repository at this point in the history
  • Loading branch information
flibitijibibo committed Apr 7, 2014
1 parent 80b47e7 commit 7aa9e27
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 213 deletions.
84 changes: 35 additions & 49 deletions MonoGame.Framework/Curve.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,60 +50,47 @@ public bool IsConstant
{
get
{
return this.keys.Count <= 1;
return Keys.Count <= 1;
}
}

[DataMember]
public CurveKeyCollection Keys
{
get
{
return this.keys;
}
get;
private set;
}

[DataMember]
public CurveLoopType PostLoop
{
get
{
return this.postLoop;
}
set
{
this.postLoop = value;
}
get;
set;
}

[DataMember]
public CurveLoopType PreLoop
{
get
{
return this.preLoop;
}
set
{
this.preLoop = value;
}
get;
set;
}

#endregion

#region Private Fields
#region Public Constructors

private CurveKeyCollection keys;
private CurveLoopType postLoop;
private CurveLoopType preLoop;
public Curve()
{
Keys = new CurveKeyCollection();
}

#endregion

#region Public Constructors
#region Private Constructors

public Curve()
private Curve(CurveKeyCollection keys)
{
this.keys = new CurveKeyCollection();
Keys = keys;
}

#endregion
Expand All @@ -112,19 +99,16 @@ public Curve()

public Curve Clone()
{
Curve curve = new Curve();

curve.keys = this.keys.Clone();
curve.preLoop = this.preLoop;
curve.postLoop = this.postLoop;

Curve curve = new Curve(Keys.Clone());
curve.PreLoop = PreLoop;
curve.PostLoop = PostLoop;
return curve;
}

public float Evaluate(float position)
{
CurveKey first = keys[0];
CurveKey last = keys[keys.Count - 1];
CurveKey first = Keys[0];
CurveKey last = Keys[Keys.Count - 1];

if (position < first.Position)
{
Expand Down Expand Up @@ -241,7 +225,7 @@ public void ComputeTangent(int keyIndex, CurveTangent tangentInType, CurveTangen
{
// See http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.curvetangent.aspx

CurveKey key = keys[keyIndex];
CurveKey key = Keys[keyIndex];

float p0, p, p1;
p0 = p = p1 = key.Position;
Expand All @@ -251,14 +235,14 @@ public void ComputeTangent(int keyIndex, CurveTangent tangentInType, CurveTangen

if (keyIndex > 0)
{
p0 = keys[keyIndex - 1].Position;
v0 = keys[keyIndex - 1].Value;
p0 = Keys[keyIndex - 1].Position;
v0 = Keys[keyIndex - 1].Value;
}

if (keyIndex < keys.Count-1)
if (keyIndex < Keys.Count-1)
{
p1 = keys[keyIndex + 1].Position;
v1 = keys[keyIndex + 1].Value;
p1 = Keys[keyIndex + 1].Position;
v1 = Keys[keyIndex + 1].Value;
}

switch (tangentInType)
Expand Down Expand Up @@ -310,8 +294,8 @@ public void ComputeTangent(int keyIndex, CurveTangent tangentInType, CurveTangen

private int GetNumberOfCycle(float position)
{
float cycle = (position - keys[0].Position) /
(keys[keys.Count - 1].Position - keys[0].Position);
float cycle = (position - Keys[0].Position) /
(Keys[Keys.Count - 1].Position - Keys[0].Position);
if (cycle < 0f)
{
cycle -= 1;
Expand All @@ -322,11 +306,11 @@ private int GetNumberOfCycle(float position)
private float GetCurvePosition(float position)
{
// only for position in curve
CurveKey prev = this.keys[0];
CurveKey prev = Keys[0];
CurveKey next;
for (int i = 1; i < this.keys.Count; i++)
for (int i = 1; i < Keys.Count; i++)
{
next = this.Keys[i];
next = Keys[i];
if (next.Position >= position)
{
if (prev.Continuity == CurveContinuity.Step)
Expand All @@ -347,10 +331,12 @@ private float GetCurvePosition(float position)
* P(t) = (2*t^3 - 3t^2 + 1)*P0 + (t^3 - 2t^2 + t)m0 + (-2t^3 + 3t^2)P1 + (t^3-t^2)m1
* with P0.value = prev.value , m0 = prev.tangentOut, P1= next.value, m1 = next.TangentIn
*/
return (2 * tss - 3 * ts + 1f) * prev.Value +
return (
(2 * tss - 3 * ts + 1f) * prev.Value +
(tss - 2 * ts + t) * prev.TangentOut +
(3 * ts - 2 * tss) * next.Value +
(tss - ts) * next.TangentIn;
(tss - ts) * next.TangentIn
);
}
prev = next;
}
Expand Down
104 changes: 35 additions & 69 deletions MonoGame.Framework/CurveKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,84 +39,48 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE

namespace Microsoft.Xna.Framework
{
[DataContract]
[DataContract]
public class CurveKey : IEquatable<CurveKey>, IComparable<CurveKey>
{
#region Public Properties

[DataMember]
public CurveContinuity Continuity
{
get
{
return this.continuity;
}
set
{
this.continuity = value;
}
get;
set;
}

[DataMember]
public float Position
{
get
{
return this.position;
}
get;
private set;
}

[DataMember]
public float TangentIn
{
get
{
return this.tangentIn;
}
set
{
this.tangentIn = value;
}
get;
set;
}

[DataMember]
public float TangentOut
{
get
{
return this.tangentOut;
}
set
{
this.tangentOut = value;
}
get;
set;
}

[DataMember]
public float Value
{
get
{
return this.value;
}
set
{
this.value = value;
}
get;
set;
}

#endregion

#region Private Fields

private CurveContinuity continuity;
private float position;
private float tangentIn;
private float tangentOut;
private float value;

#endregion

#region Public Constructors

public CurveKey(
Expand Down Expand Up @@ -152,11 +116,11 @@ public CurveKey(
float tangentOut,
CurveContinuity continuity
) {
this.position = position;
this.value = value;
this.tangentIn = tangentIn;
this.tangentOut = tangentOut;
this.continuity = continuity;
Position = position;
Value = value;
TangentIn = tangentIn;
TangentOut = tangentOut;
Continuity = continuity;
}

#endregion
Expand All @@ -166,17 +130,17 @@ CurveContinuity continuity
public CurveKey Clone()
{
return new CurveKey(
this.position,
this.value,
this.tangentIn,
this.tangentOut,
this.continuity
Position,
Value,
TangentIn,
TangentOut,
Continuity
);
}

public int CompareTo(CurveKey other)
{
return this.position.CompareTo(other.position);
return Position.CompareTo(other.Position);
}

public bool Equals(CurveKey other)
Expand Down Expand Up @@ -205,11 +169,11 @@ public bool Equals(CurveKey other)
return object.Equals(a, null);
}

return (a.position == b.position) &&
(a.value == b.value) &&
(a.tangentIn == b.tangentIn) &&
(a.tangentOut == b.tangentOut) &&
(a.continuity == b.continuity);
return ( (a.Position == b.Position) &&
(a.Value == b.Value) &&
(a.TangentIn == b.TangentIn) &&
(a.TangentOut == b.TangentOut) &&
(a.Continuity == b.Continuity) );
}

public override bool Equals(object obj)
Expand All @@ -219,12 +183,14 @@ public override bool Equals(object obj)

public override int GetHashCode()
{
return this.position.GetHashCode() ^
this.value.GetHashCode() ^
this.tangentIn.GetHashCode() ^
this.tangentOut.GetHashCode() ^
this.continuity.GetHashCode();
}
return (
Position.GetHashCode() ^
Value.GetHashCode() ^
TangentIn.GetHashCode() ^
TangentOut.GetHashCode() ^
Continuity.GetHashCode()
);
}

#endregion
}
Expand Down
1 change: 0 additions & 1 deletion MonoGame.Framework/DisplayOrientation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ public enum DisplayOrientation
Unknown = 16
}
}

3 changes: 1 addition & 2 deletions MonoGame.Framework/DrawableGameComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ public bool Visible

#region Public Constructors

public DrawableGameComponent(Game game)
: base(game)
public DrawableGameComponent(Game game) : base(game)
{
}

Expand Down
1 change: 0 additions & 1 deletion MonoGame.Framework/FrameworkDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ public static void Update()
}
}
}

Loading

0 comments on commit 7aa9e27

Please sign in to comment.