self depends performance trick

This commit is contained in:
2016-02-04 00:19:08 +06:00
parent 7be576f7b3
commit ba1c51fcb7
2 changed files with 42 additions and 18 deletions

View File

@@ -165,15 +165,16 @@ namespace IsoTools {
// ---------------------------------------------------------------------
public class InternalState {
public bool Dirty = false;
public bool Visited = false;
public Rect ScreenRect = new Rect();
public float Offset3d = 0.0f;
public IsoUtils.MinMax MinMax3d = IsoUtils.MinMax.zero;
public Vector2 MinSector = Vector2.zero;
public Vector2 MaxSector = Vector2.zero;
public HashSet<IsoObject> SelfDepends = new HashSet<IsoObject>();
public HashSet<IsoObject> TheirDepends = new HashSet<IsoObject>();
public bool Dirty = false;
public bool Visited = false;
public Rect ScreenRect = new Rect();
public float Offset3d = 0.0f;
public IsoUtils.MinMax MinMax3d = IsoUtils.MinMax.zero;
public Vector2 MinSector = Vector2.zero;
public Vector2 MaxSector = Vector2.zero;
public Dictionary<IsoObject, int> SelfDependsD = new Dictionary<IsoObject, int>();
public List<IsoObject> SelfDependsL = new List<IsoObject>();
public HashSet<IsoObject> TheirDepends = new HashSet<IsoObject>();
}
public InternalState Internal = new InternalState();
@@ -277,8 +278,8 @@ namespace IsoTools {
// ---------------------------------------------------------------------
void Awake() {
Internal.SelfDepends = new HashSet<IsoObject>(new IsoObject[47]);
Internal.SelfDepends.Clear();
Internal.SelfDependsD = new Dictionary<IsoObject, int>(47);
Internal.SelfDependsL = new List<IsoObject>(47);
Internal.TheirDepends = new HashSet<IsoObject>(new IsoObject[47]);
Internal.TheirDepends.Clear();
FixLastProperties();

View File

@@ -441,7 +441,12 @@ namespace IsoTools {
for ( int i = 0, e = sec.objects.Count; i < e; ++i ) {
var obj_b = sec.objects[i];
if ( obj_a != obj_b && !obj_b.Internal.Dirty && IsIsoObjectDepends(obj_a, obj_b) ) {
obj_a.Internal.SelfDepends.Add(obj_b);
var a_depends_d = obj_a.Internal.SelfDependsD;
var a_depends_l = obj_a.Internal.SelfDependsL;
if ( !a_depends_d.ContainsKey(obj_b) ) {
a_depends_d.Add(obj_b, a_depends_l.Count);
a_depends_l.Add(obj_b);
}
obj_b.Internal.TheirDepends.Add(obj_a);
}
}
@@ -454,7 +459,12 @@ namespace IsoTools {
for ( int i = 0, e = sec.objects.Count; i < e; ++i ) {
var obj_b = sec.objects[i];
if ( obj_a != obj_b && !obj_b.Internal.Dirty && IsIsoObjectDepends(obj_b, obj_a) ) {
obj_b.Internal.SelfDepends.Add(obj_a);
var b_depends_d = obj_b.Internal.SelfDependsD;
var b_depends_l = obj_b.Internal.SelfDependsL;
if ( !b_depends_d.ContainsKey(obj_a) ) {
b_depends_d.Add(obj_a, b_depends_l.Count);
b_depends_l.Add(obj_a);
}
obj_a.Internal.TheirDepends.Add(obj_b);
}
}
@@ -594,10 +604,22 @@ namespace IsoTools {
while ( their_depends_iter.MoveNext() ) {
var their_iso_object = their_depends_iter.Current;
if ( !their_iso_object.Internal.Dirty ) {
their_depends_iter.Current.Internal.SelfDepends.Remove(iso_object);
var their_depends_d = their_depends_iter.Current.Internal.SelfDependsD;
var their_depends_l = their_depends_iter.Current.Internal.SelfDependsL;
int index;
if ( their_depends_d.TryGetValue(iso_object, out index) ) {
their_depends_d.Remove(iso_object);
if ( index != their_depends_l.Count - 1 ) {
var last_obj = their_depends_l[their_depends_l.Count - 1];
their_depends_d[last_obj] = index;
their_depends_l[index] = last_obj;
}
their_depends_l.RemoveAt(their_depends_l.Count - 1);
}
}
}
iso_object.Internal.SelfDepends.Clear();
iso_object.Internal.SelfDependsD.Clear();
iso_object.Internal.SelfDependsL.Clear();
iso_object.Internal.TheirDepends.Clear();
}
@@ -626,9 +648,10 @@ namespace IsoTools {
return depth;
}
iso_object.Internal.Visited = true;
var self_depends_iter = iso_object.Internal.SelfDepends.GetEnumerator();
while ( self_depends_iter.MoveNext() ) {
depth = RecursivePlaceIsoObject(self_depends_iter.Current, depth);
var depends_l = iso_object.Internal.SelfDependsL;
for ( int i = 0, e = iso_object.Internal.SelfDependsL.Count; i < e; ++i ) {
depth = RecursivePlaceIsoObject(depends_l[i], depth);
}
if ( iso_object.mode == IsoObject.Mode.Mode3d ) {
var zoffset = iso_object.Internal.Offset3d;