Added quaternion serialization; serialization methods now always work on references to improve performance; removed dead code from CygonRectanglePacker; improved commenting on Progression framework
git-svn-id: file:///srv/devel/repo-conversion/nusu@29 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
parent
979e6328fb
commit
991fab9721
|
@ -107,7 +107,7 @@ namespace Nuclex.Support.Packing {
|
||||||
return fits;
|
return fits;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Finds the best position for a rectangle of the given width</summary>
|
/// <summary>Finds the best position for a rectangle of the given dimensions</summary>
|
||||||
/// <param name="rectangleWidth">Width of the rectangle to find a position for</param>
|
/// <param name="rectangleWidth">Width of the rectangle to find a position for</param>
|
||||||
/// <param name="rectangleHeight">Height of the rectangle to find a position for</param>
|
/// <param name="rectangleHeight">Height of the rectangle to find a position for</param>
|
||||||
/// <param name="placement">Received the best placement found for the rectangle</param>
|
/// <param name="placement">Received the best placement found for the rectangle</param>
|
||||||
|
@ -116,9 +116,6 @@ namespace Nuclex.Support.Packing {
|
||||||
int rectangleWidth, int rectangleHeight, out Point placement
|
int rectangleWidth, int rectangleHeight, out Point placement
|
||||||
) {
|
) {
|
||||||
|
|
||||||
// Total surface area of the rectangle
|
|
||||||
int rectangleArea = rectangleWidth * rectangleHeight;
|
|
||||||
|
|
||||||
// Slice index, vertical position and score of the best placement we could find
|
// Slice index, vertical position and score of the best placement we could find
|
||||||
int bestSliceIndex = -1; // Slice index where the best placement was found
|
int bestSliceIndex = -1; // Slice index where the best placement was found
|
||||||
int bestSliceY = 0; // Y position of the best placement found
|
int bestSliceY = 0; // Y position of the best placement found
|
||||||
|
@ -254,6 +251,7 @@ namespace Nuclex.Support.Packing {
|
||||||
|
|
||||||
} else { // No direct hit, rectangle ends inside another slice
|
} else { // No direct hit, rectangle ends inside another slice
|
||||||
|
|
||||||
|
// Make index from negative BinarySearch() result
|
||||||
endSlice = ~endSlice;
|
endSlice = ~endSlice;
|
||||||
|
|
||||||
// Find out to which height we need to return at the right end of
|
// Find out to which height we need to return at the right end of
|
||||||
|
|
|
@ -24,8 +24,6 @@ using System.Reflection;
|
||||||
|
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
|
|
||||||
using Nuclex.Support.Serialization;
|
|
||||||
|
|
||||||
namespace Nuclex.Support.Serialization {
|
namespace Nuclex.Support.Serialization {
|
||||||
|
|
||||||
/// <summary>Utility class for serializating objects into binary data</summary>
|
/// <summary>Utility class for serializating objects into binary data</summary>
|
||||||
|
@ -119,7 +117,7 @@ namespace Nuclex.Support.Serialization {
|
||||||
/// <summary>Serializes a matrix into a binary data stream</summary>
|
/// <summary>Serializes a matrix into a binary data stream</summary>
|
||||||
/// <param name="writer">BinaryWriter to serialize the matrix into</param>
|
/// <param name="writer">BinaryWriter to serialize the matrix into</param>
|
||||||
/// <param name="matrix">Matrix to be serialized</param>
|
/// <param name="matrix">Matrix to be serialized</param>
|
||||||
public static void Save(BinaryWriter writer, Matrix matrix) {
|
public static void Save(BinaryWriter writer, ref Matrix matrix) {
|
||||||
writer.Write(matrix.M11);
|
writer.Write(matrix.M11);
|
||||||
writer.Write(matrix.M12);
|
writer.Write(matrix.M12);
|
||||||
writer.Write(matrix.M13);
|
writer.Write(matrix.M13);
|
||||||
|
@ -156,7 +154,7 @@ namespace Nuclex.Support.Serialization {
|
||||||
/// <summary>Serializes a vector into a binary data stream</summary>
|
/// <summary>Serializes a vector into a binary data stream</summary>
|
||||||
/// <param name="writer">BinaryWriter to serialize the vector into</param>
|
/// <param name="writer">BinaryWriter to serialize the vector into</param>
|
||||||
/// <param name="vector">Vector to be serialized</param>
|
/// <param name="vector">Vector to be serialized</param>
|
||||||
public static void Save(BinaryWriter writer, Vector2 vector) {
|
public static void Save(BinaryWriter writer, ref Vector2 vector) {
|
||||||
writer.Write(vector.X);
|
writer.Write(vector.X);
|
||||||
writer.Write(vector.Y);
|
writer.Write(vector.Y);
|
||||||
}
|
}
|
||||||
|
@ -177,7 +175,7 @@ namespace Nuclex.Support.Serialization {
|
||||||
/// <summary>Serializes a vector into a binary data stream</summary>
|
/// <summary>Serializes a vector into a binary data stream</summary>
|
||||||
/// <param name="writer">BinaryWriter to serialize the vector into</param>
|
/// <param name="writer">BinaryWriter to serialize the vector into</param>
|
||||||
/// <param name="vector">Vector to be serialized</param>
|
/// <param name="vector">Vector to be serialized</param>
|
||||||
public static void Save(BinaryWriter writer, Vector3 vector) {
|
public static void Save(BinaryWriter writer, ref Vector3 vector) {
|
||||||
writer.Write(vector.X);
|
writer.Write(vector.X);
|
||||||
writer.Write(vector.Y);
|
writer.Write(vector.Y);
|
||||||
writer.Write(vector.Z);
|
writer.Write(vector.Z);
|
||||||
|
@ -200,14 +198,38 @@ namespace Nuclex.Support.Serialization {
|
||||||
/// <summary>Serializes a vector into a binary data stream</summary>
|
/// <summary>Serializes a vector into a binary data stream</summary>
|
||||||
/// <param name="writer">BinaryWriter to serialize the vector into</param>
|
/// <param name="writer">BinaryWriter to serialize the vector into</param>
|
||||||
/// <param name="vector">Vector to be serialized</param>
|
/// <param name="vector">Vector to be serialized</param>
|
||||||
public static void Save(BinaryWriter writer, Vector4 vector) {
|
public static void Save(BinaryWriter writer, ref Vector4 vector) {
|
||||||
writer.Write(vector.X);
|
writer.Write(vector.X);
|
||||||
writer.Write(vector.Y);
|
writer.Write(vector.Y);
|
||||||
writer.Write(vector.Z);
|
writer.Write(vector.Z);
|
||||||
writer.Write(vector.W);
|
writer.Write(vector.W);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion // Microsoft.Xna.Framework.Vector3
|
#endregion // Microsoft.Xna.Framework.Quaternion
|
||||||
|
|
||||||
|
#region Microsoft.Xna.Framework.Quaternion
|
||||||
|
|
||||||
|
/// <summary>Loads a quaternion from its serialized representation</summary>
|
||||||
|
/// <param name="reader">Reader to use for reading the quaternion</param>
|
||||||
|
/// <param name="quaternion">Quaternion to be deserialized</param>
|
||||||
|
public static void Load(BinaryReader reader, out Quaternion quaternion) {
|
||||||
|
quaternion.X = reader.ReadSingle();
|
||||||
|
quaternion.Y = reader.ReadSingle();
|
||||||
|
quaternion.Z = reader.ReadSingle();
|
||||||
|
quaternion.W = reader.ReadSingle();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Serializes a quaternion into a binary data stream</summary>
|
||||||
|
/// <param name="writer">BinaryWriter to serialize the quaternion into</param>
|
||||||
|
/// <param name="quaternion">Quaternion to be serialized</param>
|
||||||
|
public static void Save(BinaryWriter writer, ref Quaternion quaternion) {
|
||||||
|
writer.Write(quaternion.X);
|
||||||
|
writer.Write(quaternion.Y);
|
||||||
|
writer.Write(quaternion.Z);
|
||||||
|
writer.Write(quaternion.W);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion // Microsoft.Xna.Framework.Quaternion
|
||||||
|
|
||||||
} // class BinarySerializer
|
} // class BinarySerializer
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,15 @@ namespace Nuclex.Support.Tracking {
|
||||||
|
|
||||||
asyncDisconnectEvents(); // We don't need those anymore!
|
asyncDisconnectEvents(); // We don't need those anymore!
|
||||||
|
|
||||||
|
// If the progress hasn't reached 1.0 yet, make a fake report so that even
|
||||||
|
// when a progression doesn't report any progress at all, the set of queue
|
||||||
|
// owning us will have a percentage of progressions completed.
|
||||||
|
//
|
||||||
|
// There is the possibility of a race condition here, as a final progress
|
||||||
|
// report could have been generated by some other thread that was preempted
|
||||||
|
// by this thread reporting the end of the progression. This is not a problem,
|
||||||
|
// however, since the progress is inteded only for informal purposes and
|
||||||
|
// not to be used for controlling program flow.
|
||||||
if(this.progress != 1.0f) {
|
if(this.progress != 1.0f) {
|
||||||
this.progress = 1.0f;
|
this.progress = 1.0f;
|
||||||
progressUpdateCallback();
|
progressUpdateCallback();
|
||||||
|
@ -94,11 +103,10 @@ namespace Nuclex.Support.Tracking {
|
||||||
/// <param name="e">Contains the updated progress</param>
|
/// <param name="e">Contains the updated progress</param>
|
||||||
private void asyncProgressUpdated(object sender, ProgressUpdateEventArgs e) {
|
private void asyncProgressUpdated(object sender, ProgressUpdateEventArgs e) {
|
||||||
this.progress = e.Progress;
|
this.progress = e.Progress;
|
||||||
|
|
||||||
this.progressUpdateCallback();
|
this.progressUpdateCallback();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Unscribes from all events of the observed progression</summary>
|
/// <summary>Unsubscribes from all events of the observed progression</summary>
|
||||||
private void asyncDisconnectEvents() {
|
private void asyncDisconnectEvents() {
|
||||||
|
|
||||||
// Make use of the double check locking idiom to avoid the costly lock when
|
// Make use of the double check locking idiom to avoid the costly lock when
|
||||||
|
|
|
@ -85,7 +85,7 @@ namespace Nuclex.Support.Tracking {
|
||||||
//
|
//
|
||||||
// We can *not* optimize this lock away since we absolutely must not create
|
// We can *not* optimize this lock away since we absolutely must not create
|
||||||
// two doneEvents -- someone might call .WaitOne() on the first one when only
|
// two doneEvents -- someone might call .WaitOne() on the first one when only
|
||||||
// the second one is assigned to this.doneEvent and gets set in the end.
|
// the second one is assigned to this.doneEvent and thus gets set in the end.
|
||||||
if(this.doneEvent == null) {
|
if(this.doneEvent == null) {
|
||||||
|
|
||||||
lock(this.syncRoot) {
|
lock(this.syncRoot) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user