Implement anchor related annotations.

This commit is contained in:
2023-01-28 11:57:49 +08:00
parent c4b139c7a4
commit 10988847b3
3 changed files with 24 additions and 6 deletions

View File

@@ -77,7 +77,7 @@ namespace Cryville.Crtr.Event {
a_head = RegisterAnchor(_a_head);
a_tail = RegisterAnchor(_a_tail);
}
protected Anchor RegisterAnchor(int name, int propSrcCount = 0) {
public Anchor RegisterAnchor(int name, int propSrcCount = 0) {
var go = new GameObject("." + IdentifierManager.SharedInstance.Retrieve(name)).transform;
go.SetParent(gogroup, false);
var result = new Anchor(name, go, propSrcCount);
@@ -129,7 +129,15 @@ namespace Cryville.Crtr.Event {
}
static readonly SimpleObjectPool<StampedEvent.Anchor> anchorEvPool
= new SimpleObjectPool<StampedEvent.Anchor>(1024);
protected void PushAnchorEvent(double time, Anchor anchor) {
public void PushAnchorEvent(double time, int name) {
List<Anchor> anchors;
if (!Anchors.TryGetValue(name, out anchors))
throw new ArgumentException(string.Format("Specified anchor \"{0}\" not found", IdentifierManager.SharedInstance.Retrieve(name)));
if (anchors.Count != 1)
throw new InvalidOperationException(string.Format("Cannot set a static anchor \"{0}\"", IdentifierManager.SharedInstance.Retrieve(name)));
PushAnchorEvent(time, anchors[0]);
}
void PushAnchorEvent(double time, Anchor anchor) {
var tev = anchorEvPool.Rent();
tev.Time = time;
tev.Container = Container;

View File

@@ -50,7 +50,7 @@ namespace Cryville.Crtr.Event {
}
}
public byte CloneType;
private ContainerState rootPrototype = null;
public ContainerState rootPrototype = null;
private ContainerState prototype = null;
public ContainerHandler Handler {

View File

@@ -68,7 +68,7 @@ namespace Cryville.Crtr {
}
public override bool IsValueRequired { get { return false; } }
public override void ExecuteStatic(ContainerState state, RuntimeSkinContext ctx, PdtExpression exp) {
// TODO
state.Handler.RegisterAnchor(Name);
}
public override void ExecuteDynamic(ContainerState state, RuntimeSkinContext ctx, PdtExpression exp) {
throw new InvalidOperationException("Anchor creation in dynamic context is not allowed");
@@ -76,15 +76,25 @@ namespace Cryville.Crtr {
}
public class SetAnchor : SkinPropertyKey {
public int Name { get; set; }
public SetAnchor() {
_timeOp = new PropOp.Float(v => _time = v);
}
public override string ToString() {
return string.Format("@at {0}", IdentifierManager.SharedInstance.Retrieve(Name));
}
public override bool IsValueRequired { get { return true; } }
public override void ExecuteStatic(ContainerState state, RuntimeSkinContext ctx, PdtExpression exp) {
// TODO
throw new InvalidOperationException("Setting anchor in static context is not allowed");
}
float _time;
readonly PropOp _timeOp;
public override void ExecuteDynamic(ContainerState state, RuntimeSkinContext ctx, PdtExpression exp) {
// TODO
if (state.CloneType > 1) return;
var psrcs = ctx.ReadContext.PropSrcs;
if (psrcs != null) ChartPlayer.etor.ContextCascadeInsert(psrcs);
ChartPlayer.etor.Evaluate(_timeOp, exp);
if (psrcs != null) ChartPlayer.etor.ContextCascadeDiscard();
state.Handler.PushAnchorEvent(_time, Name);
}
}
}