Several small optimizations; improved XML comments; added a text file for storing general ideas about the design of Nuclex.Support
git-svn-id: file:///srv/devel/repo-conversion/nusu@15 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
parent
88390bc38d
commit
7ec11b91b9
|
@ -182,6 +182,12 @@
|
||||||
<Name>WeightedProgressionWrapperCollection</Name>
|
<Name>WeightedProgressionWrapperCollection</Name>
|
||||||
</Compile>
|
</Compile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="Nuclex.Support.txt">
|
||||||
|
<XNAUseContentPipeline>false</XNAUseContentPipeline>
|
||||||
|
<Name>Nuclex.Support</Name>
|
||||||
|
</Content>
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA\Game Studio Express\v1.0\Microsoft.Xna.ContentPipeline.targets" />
|
<Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA\Game Studio Express\v1.0\Microsoft.Xna.ContentPipeline.targets" />
|
||||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA\Game Studio Express\v1.0\Microsoft.Xna.Common.targets" />
|
<Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA\Game Studio Express\v1.0\Microsoft.Xna.Common.targets" />
|
||||||
|
|
28
Nuclex.Support.txt
Normal file
28
Nuclex.Support.txt
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#if DEBUG
|
||||||
|
|
||||||
|
/// <summary>Generates a new random shuffle table</summary>
|
||||||
|
/// <param name="iterationCount">
|
||||||
|
/// Number of iterations in which to randomize the shuffle table
|
||||||
|
/// </param>
|
||||||
|
/// <returns>The new random shuffle table</returns>
|
||||||
|
public static byte[] generateShuffleTable(int iterationCount) {
|
||||||
|
byte[] shuffleTable = new byte[128];
|
||||||
|
for(int index = 0; index < 128; ++index)
|
||||||
|
shuffleTable[index] = index;
|
||||||
|
|
||||||
|
Random rng = new Random();
|
||||||
|
|
||||||
|
for(int iteration = 0; iteration < iterationCount; ++iteration) {
|
||||||
|
int firstIndex = rng.Next() % 128;
|
||||||
|
int secondIndex = rng.Next() % 128;
|
||||||
|
|
||||||
|
byte temp = shuffleTable[firstIndex];
|
||||||
|
shuffleTable[firstIndex] = shuffleTable[secondIndex];
|
||||||
|
shuffleTable[secondIndex] = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
return shuffleTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -4,6 +4,10 @@ using System.IO;
|
||||||
namespace Nuclex.Support.Collections {
|
namespace Nuclex.Support.Collections {
|
||||||
|
|
||||||
/// <summary>Specialized memory stream for ring buffers</summary>
|
/// <summary>Specialized memory stream for ring buffers</summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This ring buffer class is specialized for binary data and tries to achieve
|
||||||
|
/// optimal efficiency for storing and retrieving chunks of multiple bytes at once.
|
||||||
|
/// </remarks>
|
||||||
public class RingMemoryStream : Stream {
|
public class RingMemoryStream : Stream {
|
||||||
|
|
||||||
/// <summary>Initializes a new ring memory stream</summary>
|
/// <summary>Initializes a new ring memory stream</summary>
|
||||||
|
@ -16,7 +20,8 @@ namespace Nuclex.Support.Collections {
|
||||||
|
|
||||||
/// <summary>Maximum amount of data that will fit into the ring memory stream</summary>
|
/// <summary>Maximum amount of data that will fit into the ring memory stream</summary>
|
||||||
/// <exception cref="ArgumentOutOfRangeException">
|
/// <exception cref="ArgumentOutOfRangeException">
|
||||||
/// If the reduced capacity is too small for the ring buffer's current data
|
/// Thrown if the new capacity is too small for the data already contained
|
||||||
|
/// in the ring buffer.
|
||||||
/// </exception>
|
/// </exception>
|
||||||
public long Capacity {
|
public long Capacity {
|
||||||
get { return this.ringBuffer.Length; }
|
get { return this.ringBuffer.Length; }
|
||||||
|
|
|
@ -253,7 +253,7 @@ namespace Nuclex.Support.Collections {
|
||||||
/// This method is used to transform an item in the wrapped collection into
|
/// This method is used to transform an item in the wrapped collection into
|
||||||
/// the exposed item type whenever the user accesses an item. Expect it to
|
/// the exposed item type whenever the user accesses an item. Expect it to
|
||||||
/// be called frequently, because the TransformingReadOnlyCollection does
|
/// be called frequently, because the TransformingReadOnlyCollection does
|
||||||
/// not cache otherwise store the transformed items.
|
/// not cache or otherwise store the transformed items.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
protected abstract ExposedItemType Transform(ContainedItemType item);
|
protected abstract ExposedItemType Transform(ContainedItemType item);
|
||||||
|
|
||||||
|
|
|
@ -62,8 +62,10 @@ namespace Nuclex.Support.Tracking {
|
||||||
|
|
||||||
asyncDisconnectEvents(); // We don't need those anymore!
|
asyncDisconnectEvents(); // We don't need those anymore!
|
||||||
|
|
||||||
|
if(this.progress != 1.0f) {
|
||||||
this.progress = 1.0f;
|
this.progress = 1.0f;
|
||||||
progressUpdateCallback();
|
progressUpdateCallback();
|
||||||
|
}
|
||||||
|
|
||||||
endedCallback();
|
endedCallback();
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,12 +14,6 @@ namespace Nuclex.Support.Tracking {
|
||||||
/// <summary>Performs common initialization for the public constructors</summary>
|
/// <summary>Performs common initialization for the public constructors</summary>
|
||||||
private SetProgression() {
|
private SetProgression() {
|
||||||
this.childs = new List<ObservedProgression<ProgressionType>>();
|
this.childs = new List<ObservedProgression<ProgressionType>>();
|
||||||
|
|
||||||
this.asyncProgressUpdatedDelegate =
|
|
||||||
new ObservedProgression<ProgressionType>.ReportDelegate(asyncProgressUpdated);
|
|
||||||
|
|
||||||
this.asyncEndedDelegate =
|
|
||||||
new ObservedProgression<ProgressionType>.ReportDelegate(asyncEnded);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Initializes a new set progression</summary>
|
/// <summary>Initializes a new set progression</summary>
|
||||||
|
@ -36,7 +30,8 @@ namespace Nuclex.Support.Tracking {
|
||||||
this.childs.Add(
|
this.childs.Add(
|
||||||
new ObservedProgression<ProgressionType>(
|
new ObservedProgression<ProgressionType>(
|
||||||
new WeightedProgression<ProgressionType>(progression),
|
new WeightedProgression<ProgressionType>(progression),
|
||||||
this.asyncProgressUpdatedDelegate, this.asyncEndedDelegate
|
new ObservedProgression<ProgressionType>.ReportDelegate(asyncProgressUpdated),
|
||||||
|
new ObservedProgression<ProgressionType>.ReportDelegate(asyncEnded)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -60,7 +55,8 @@ namespace Nuclex.Support.Tracking {
|
||||||
this.childs.Add(
|
this.childs.Add(
|
||||||
new ObservedProgression<ProgressionType>(
|
new ObservedProgression<ProgressionType>(
|
||||||
progression,
|
progression,
|
||||||
this.asyncProgressUpdatedDelegate, this.asyncEndedDelegate
|
new ObservedProgression<ProgressionType>.ReportDelegate(asyncProgressUpdated),
|
||||||
|
new ObservedProgression<ProgressionType>.ReportDelegate(asyncEnded)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -160,12 +156,6 @@ namespace Nuclex.Support.Tracking {
|
||||||
/// <summary>Summed weight of all progression in the set</summary>
|
/// <summary>Summed weight of all progression in the set</summary>
|
||||||
private float totalWeight;
|
private float totalWeight;
|
||||||
|
|
||||||
/// <summary>Delegate for the asyncProgressUpdated() method</summary>
|
|
||||||
private ObservedProgression<ProgressionType>.ReportDelegate asyncProgressUpdatedDelegate;
|
|
||||||
/// <summary>Delegate for the asyncEnded() method</summary>
|
|
||||||
private ObservedProgression<ProgressionType>.ReportDelegate asyncEndedDelegate;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Nuclex.Support.Tracking
|
} // namespace Nuclex.Support.Tracking
|
||||||
|
|
Loading…
Reference in New Issue
Block a user