From 33abcb106335ea4b1517ea819a8e0e3a60de9418 Mon Sep 17 00:00:00 2001
From: "(no author)" <(no author)@993157c7-ee19-0410-b2c4-bb4e9862e678>
Date: Tue, 17 Jul 2007 18:20:50 +0000
Subject: [PATCH] git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1297
993157c7-ee19-0410-b2c4-bb4e9862e678
---
.../OpenRa.DataStructures.csproj | 48 +++++++
OpenRa.DataStructures/PriorityQueue.cs | 133 ++++++++++++++++++
.../Properties/AssemblyInfo.cs | 35 +++++
.../Tuple.cs | 2 +-
OpenRa.FileFormats/OpenRa.FileFormats.csproj | 1 -
OpenRa.Game/Animation.cs | 9 +-
OpenRa.Game/MainWindow.cs | 1 +
OpenRa.Game/OpenRa.Game.csproj | 1 +
OpenRa.Game/Program.cs | 5 +-
OpenRa.TechTree/Item.cs | 5 +-
OpenRa.TechTree/OpenRa.TechTree.csproj | 4 +
OpenRa.TechTree/TechTree.cs | 5 +-
OpenRa.sln | 12 ++
13 files changed, 252 insertions(+), 9 deletions(-)
create mode 100644 OpenRa.DataStructures/OpenRa.DataStructures.csproj
create mode 100644 OpenRa.DataStructures/PriorityQueue.cs
create mode 100644 OpenRa.DataStructures/Properties/AssemblyInfo.cs
rename {OpenRa.FileFormats => OpenRa.DataStructures}/Tuple.cs (89%)
diff --git a/OpenRa.DataStructures/OpenRa.DataStructures.csproj b/OpenRa.DataStructures/OpenRa.DataStructures.csproj
new file mode 100644
index 0000000000..f0fddf98c3
--- /dev/null
+++ b/OpenRa.DataStructures/OpenRa.DataStructures.csproj
@@ -0,0 +1,48 @@
+
+
+ Debug
+ AnyCPU
+ 8.0.50727
+ 2.0
+ {2F9E7A23-56C0-4286-9C8E-1060A9B2F073}
+ Library
+ Properties
+ OpenRa.DataStructures
+ OpenRa.DataStructures
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OpenRa.DataStructures/PriorityQueue.cs b/OpenRa.DataStructures/PriorityQueue.cs
new file mode 100644
index 0000000000..fcb20425d8
--- /dev/null
+++ b/OpenRa.DataStructures/PriorityQueue.cs
@@ -0,0 +1,133 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Diagnostics;
+
+namespace OpenRa.DataStructures
+{
+ class PriorityQueue
+ where T : IComparable
+ {
+ List items = new List();
+ int level;
+ int index;
+
+ public PriorityQueue()
+ {
+ items.Add( new T[ 1 ] );
+ }
+
+ public void Add( T item )
+ {
+ int addLevel = level;
+ int addIndex = index;
+
+ while( addLevel >= 1 && Above( addLevel, addIndex ).CompareTo( item ) > 0 )
+ {
+ items[ addLevel ][ addIndex ] = Above( addLevel, addIndex );
+ --addLevel;
+ addIndex >>= 1;
+ }
+
+ items[ addLevel ][ addIndex ] = item;
+
+ ++index;
+ if( index >= ( 1 << level ) )
+ {
+ index = 0;
+ ++level;
+ items.Add( new T[ 1 << level ] );
+ }
+ }
+
+ T At( int level, int index )
+ {
+ return items[ level ][ index ];
+ }
+
+ T Above( int level, int index )
+ {
+ return items[ level - 1 ][ index >> 1 ];
+ }
+
+ T Last()
+ {
+ int lastLevel = level;
+ int lastIndex = index;
+ --lastIndex;
+ if( lastIndex < 0 )
+ {
+ --lastLevel;
+ lastIndex = ( 1 << lastLevel ) - 1;
+ }
+ return At( lastLevel, lastIndex );
+ }
+
+ public T Pop()
+ {
+ if( level == 0 && index == 0 )
+ throw new InvalidOperationException( "Attempting to pop empty PriorityQueue" );
+
+ T ret = At( 0, 0 );
+ BubbleInto( 0, 0, Last() );
+ --index;
+ if( index < 0 )
+ {
+ --level;
+ index = ( 1 << level ) - 1;
+ }
+
+ return ret;
+ }
+
+ public void BubbleInto( int intoLevel, int intoIndex, T val )
+ {
+ int downLevel = intoLevel + 1;
+ int downIndex = intoIndex << 1;
+
+ if( downLevel > level || ( downLevel == level && downIndex >= index ))
+ {
+ items[ intoLevel ][ intoIndex ] = val;
+ return;
+ }
+
+ if( downLevel == level && downIndex == index - 1 )
+ {
+ //Log.Write( "one-option bubble" );
+ }
+ else if( At( downLevel, downIndex ).CompareTo( At( downLevel, downIndex + 1 ) ) < 0 )
+ {
+ //Log.Write( "left bubble" );
+ }
+ else
+ {
+ //Log.Write( "right bubble" );
+ ++downIndex;
+ }
+
+ if( val.CompareTo( At( downLevel, downIndex ) ) <= 0 )
+ {
+ items[ intoLevel ][ intoIndex ] = val;
+ return;
+ }
+
+ items[ intoLevel ][ intoIndex ] = At( downLevel, downIndex );
+ BubbleInto( downLevel, downIndex, val );
+ }
+
+ //void Invariant()
+ //{
+ // for( int i = 1 ; i < level ; i++ )
+ // for( int j = 0 ; j < RowLength( i ) ; j++ )
+ // if( At( i, j ).CompareTo( Above( i, j ) ) < 0 )
+ // System.Diagnostics.Debug.Assert( At( i, j ).CompareTo( Above( i, j ) ) < 0, "At( i, j ) > Above( i, j )" );
+ //}
+
+ private int RowLength( int i )
+ {
+ if( i == level )
+ return index;
+ return ( 1 << i );
+ }
+ }
+}
diff --git a/OpenRa.DataStructures/Properties/AssemblyInfo.cs b/OpenRa.DataStructures/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000000..cf7fc180e0
--- /dev/null
+++ b/OpenRa.DataStructures/Properties/AssemblyInfo.cs
@@ -0,0 +1,35 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle( "OpenRa.DataStructures" )]
+[assembly: AssemblyDescription( "" )]
+[assembly: AssemblyConfiguration( "" )]
+[assembly: AssemblyCompany( "" )]
+[assembly: AssemblyProduct( "OpenRa.DataStructures" )]
+[assembly: AssemblyCopyright( "Copyright © 2007" )]
+[assembly: AssemblyTrademark( "" )]
+[assembly: AssemblyCulture( "" )]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible( false )]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid( "fdbd08da-dde2-4eaf-9a8c-4bc63ac5b074" )]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Revision and Build Numbers
+// by using the '*' as shown below:
+[assembly: AssemblyVersion( "1.0.0.0" )]
+[assembly: AssemblyFileVersion( "1.0.0.0" )]
diff --git a/OpenRa.FileFormats/Tuple.cs b/OpenRa.DataStructures/Tuple.cs
similarity index 89%
rename from OpenRa.FileFormats/Tuple.cs
rename to OpenRa.DataStructures/Tuple.cs
index f20cd086bd..17233884c8 100644
--- a/OpenRa.FileFormats/Tuple.cs
+++ b/OpenRa.DataStructures/Tuple.cs
@@ -2,7 +2,7 @@ using System;
using System.Collections.Generic;
using System.Text;
-namespace OpenRa.FileFormats
+namespace OpenRa.DataStructures
{
public class Tuple
{
diff --git a/OpenRa.FileFormats/OpenRa.FileFormats.csproj b/OpenRa.FileFormats/OpenRa.FileFormats.csproj
index a5d6eb0fa8..97df2ae56e 100644
--- a/OpenRa.FileFormats/OpenRa.FileFormats.csproj
+++ b/OpenRa.FileFormats/OpenRa.FileFormats.csproj
@@ -52,7 +52,6 @@
-