Files
crtr/Assets/Cryville/Crtr/StampedEvent.cs

87 lines
2.1 KiB
C#

using System;
using System.Collections.Generic;
using CAnchor = Cryville.Crtr.Anchor;
namespace Cryville.Crtr {
public class StampedEvent : IComparable<StampedEvent> {
public double Time;
public ChartEvent Unstamped;
public EventContainer Container;
public StampedEvent Origin;
public List<StampedEvent> Coevents;
public double Duration {
get {
if (Unstamped == null) return 0;
if (Unstamped.IsLong)
return ReleaseEvent.Time - Time;
else return 0;
}
}
public virtual int Priority {
get {
if (Unstamped != null) return Unstamped.Priority;
throw new NotImplementedException();
}
}
public class Temporary : StampedEvent, IComparable<Temporary> {
public bool CanDiscard;
public int CompareTo(Temporary other) {
return base.CompareTo(other);
}
}
public class Anchor : Temporary {
public CAnchor Target;
int m_priority;
public override int Priority { get { return m_priority; } }
public void SetPriority(int value) { m_priority = value; }
}
public class ClipBehind : StampedEvent {
public override int Priority {
get { return Origin.Priority - 0x8000; }
}
}
public class ClipAhead : StampedEvent {
public override int Priority {
get { return 0x7fff - Origin.Priority; }
}
}
StampedEvent relev = null;
public StampedEvent ReleaseEvent {
get { return relev; }
set {
if (relev != null) throw new InvalidOperationException("Release event already set");
relev = value;
}
}
public override string ToString() {
if (Unstamped == null)
return string.Format("stmpev at {0} {1}", Time, this.GetType().Name);
return string.Format("stmpev at {0} {1}", Time, Unstamped.GetType().Name);
}
public int CompareTo(StampedEvent other) {
int u = this.Time.CompareTo(other.Time);
if (u != 0) return u;
u = this.Priority.CompareTo(other.Priority);
if (u != 0) return u;
u = this.Duration.CompareTo(other.Duration);
if (u != 0) return u;
u = CompareExtra(other);
if (u != 0) return u;
return GetHashCode().CompareTo(other.GetHashCode());
}
protected virtual int CompareExtra(StampedEvent other) {
return 0;
}
}
}