pushed a lot of useful stuff down into IjwFramework.dll

git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1382 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
(no author)
2007-08-01 15:15:54 +00:00
parent 48e5da3945
commit 63e86e3cc6
9 changed files with 9 additions and 155 deletions

View File

@@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenRa
{
// Put globally-useful delegate types here, particularly if
// they are generic.
public delegate T Provider<T>();
public delegate T Provider<T,U>( U u );
public delegate T Provider<T,U,V>( U u, V v );
public delegate void Action();
}

View File

@@ -34,10 +34,8 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Delegates.cs" />
<Compile Include="float2.cs" />
<Compile Include="int2.cs" />
<Compile Include="PriorityQueue.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Tuple.cs" />
</ItemGroup>

View File

@@ -1,139 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
namespace OpenRa
{
public class PriorityQueue<T>
where T : IComparable<T>
{
List<T[]> items = new List<T[]>();
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;
if( items.Count <= level )
items.Add( new T[ 1 << level ] );
}
}
public bool Empty
{
get { return ( level == 0 ); }
}
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;
}
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 )" );
//}
int RowLength( int i )
{
if( i == level )
return index;
return ( 1 << i );
}
}
}

View File

@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using IjwFramework.Delegates;
namespace OpenRa.Game
{

View File

@@ -4,6 +4,7 @@ using System.Text;
using OpenRa.FileFormats;
using BluntDirectX.Direct3D;
using System.Drawing;
using IjwFramework.Delegates;
namespace OpenRa.Game
{

View File

@@ -33,6 +33,10 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\release\BluntDx.dll</HintPath>
</Reference>
<Reference Include="IjwFramework, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\IjwFramework\IjwFramework\bin\Debug\IjwFramework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Text;
using OpenRa.FileFormats;
using System.Windows.Forms;
using IjwFramework.Collections;
namespace OpenRa.Game
{

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using IjwFramework.Delegates;
namespace OpenRa.Game
{

View File

@@ -7,6 +7,7 @@ using OpenRa.FileFormats;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using IjwFramework.Delegates;
namespace OpenRa.Game
{