Merge pull request #4611 from Mailaender/imove-crash

Fixed a crash in IMove
This commit is contained in:
Chris Forbes
2014-02-10 20:13:41 +13:00
2 changed files with 76 additions and 75 deletions

View File

@@ -15,8 +15,37 @@ using OpenRA.FileFormats;
namespace OpenRA namespace OpenRA
{ {
static class ListExts
{
public static int BinarySearchMany(this List<Actor> list, uint searchFor)
{
int start = 0;
int end = list.Count;
int mid = 0;
while (start != end)
{
mid = (start + end) / 2;
var c = list[mid].ActorID.CompareTo(searchFor);
if (c < 0)
start = mid + 1;
else
end = mid;
}
return start;
}
}
class TraitDictionary class TraitDictionary
{ {
// construct this delegate once.
static Func<Type, ITraitContainer> doCreateTraitContainer = CreateTraitContainer;
static ITraitContainer CreateTraitContainer(Type t)
{
return (ITraitContainer)typeof(TraitContainer<>).MakeGenericType(t)
.GetConstructor(Type.EmptyTypes).Invoke(null);
}
Dictionary<Type, ITraitContainer> traits = new Dictionary<Type, ITraitContainer>(); Dictionary<Type, ITraitContainer> traits = new Dictionary<Type, ITraitContainer>();
ITraitContainer InnerGet(Type t) ITraitContainer InnerGet(Type t)
@@ -31,14 +60,6 @@ namespace OpenRA
Log.Write("traitreport", "{0}: {1}", t.Key.Name, t.Value.Queries); Log.Write("traitreport", "{0}: {1}", t.Key.Name, t.Value.Queries);
} }
// construct this delegate once.
static Func<Type, ITraitContainer> doCreateTraitContainer = CreateTraitContainer;
static ITraitContainer CreateTraitContainer( Type t )
{
return (ITraitContainer)typeof( TraitContainer<> ).MakeGenericType( t )
.GetConstructor( Type.EmptyTypes ).Invoke( null );
}
public void AddTrait(Actor actor, object val) public void AddTrait(Actor actor, object val)
{ {
var t = val.GetType(); var t = val.GetType();
@@ -168,24 +189,4 @@ namespace OpenRA
} }
} }
} }
static class ListExts
{
public static int BinarySearchMany( this List<Actor> list, uint searchFor )
{
int start = 0;
int end = list.Count;
int mid = 0;
while( start != end )
{
mid = ( start + end ) / 2;
var c = list[ mid ].ActorID.CompareTo( searchFor );
if( c < 0 )
start = mid + 1;
else
end = mid;
}
return start;
}
}
} }

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA.Move
public override Activity Tick(Actor self) public override Activity Tick(Actor self)
{ {
var positionable = self.Trait<IPositionable>(); var positionable = self.Trait<IPositionable>();
var movement = self.Trait<IMove>(); var movement = self.TraitOrDefault<IMove>();
var pos = length > 1 var pos = length > 1
? WPos.Lerp(start, end, ticks, length - 1) ? WPos.Lerp(start, end, ticks, length - 1)