Restructure event/container system.
This commit is contained in:
@@ -40,8 +40,8 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void EndUpdate(ContainerState s) {
|
public override void EndLogicalUpdate(ContainerState s) {
|
||||||
base.EndUpdate(s);
|
base.EndLogicalUpdate(s);
|
||||||
// TODO End of chart
|
// TODO End of chart
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -148,13 +148,13 @@ namespace Cryville.Crtr {
|
|||||||
actualRenderStep = step;
|
actualRenderStep = step;
|
||||||
|
|
||||||
nbus.ForwardStepByTime(clippingDist, step);
|
nbus.ForwardStepByTime(clippingDist, step);
|
||||||
nbus.BroadcastEndUpdate();
|
nbus.EndPreGraphicalUpdate();
|
||||||
nbus.Anchor();
|
nbus.Anchor();
|
||||||
|
|
||||||
tbus.StripTempEvents();
|
tbus.StripTempEvents();
|
||||||
tbus.ForwardStepByTime(clippingDist, step);
|
tbus.ForwardStepByTime(clippingDist, step);
|
||||||
tbus.ForwardStepByTime(renderDist, step);
|
tbus.ForwardStepByTime(renderDist, step);
|
||||||
tbus.BroadcastEndUpdate();
|
tbus.EndGraphicalUpdate();
|
||||||
UnityEngine.Profiling.Profiler.EndSample();
|
UnityEngine.Profiling.Profiler.EndSample();
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
|
@@ -4,6 +4,7 @@ using Cryville.Crtr.Components;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Cryville.Crtr.Event {
|
namespace Cryville.Crtr.Event {
|
||||||
@@ -46,8 +47,20 @@ namespace Cryville.Crtr.Event {
|
|||||||
public Vector3 Position { get; protected set; }
|
public Vector3 Position { get; protected set; }
|
||||||
public Quaternion Rotation { get; protected set; }
|
public Quaternion Rotation { get; protected set; }
|
||||||
public bool Alive { get; private set; }
|
public bool Alive { get; private set; }
|
||||||
public bool Awoken { get; private set; }
|
bool PreGraphicalActive;
|
||||||
public bool Disposed { get; private set; }
|
public void SetPreGraphicalActive(bool value, ContainerState s) {
|
||||||
|
if (PreGraphicalActive == value) return;
|
||||||
|
PreGraphicalActive = value;
|
||||||
|
if (PreGraphicalActive) StartPreGraphicalUpdate(s);
|
||||||
|
else EndPreGraphicalUpdate(s);
|
||||||
|
}
|
||||||
|
bool GraphicalActive;
|
||||||
|
public void SetGraphicalActive(bool value, ContainerState s) {
|
||||||
|
if (GraphicalActive == value) return;
|
||||||
|
GraphicalActive = value;
|
||||||
|
if (GraphicalActive) StartGraphicalUpdate(s);
|
||||||
|
else EndGraphicalUpdate(s);
|
||||||
|
}
|
||||||
|
|
||||||
public EventContainer Container {
|
public EventContainer Container {
|
||||||
get { return cs.Container; }
|
get { return cs.Container; }
|
||||||
@@ -114,34 +127,27 @@ namespace Cryville.Crtr.Event {
|
|||||||
gogroup.gameObject.SetActive(false);
|
gogroup.gameObject.SetActive(false);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
protected virtual void PreAwake(ContainerState s) {
|
#region Start methods
|
||||||
if (gogroup) {
|
public virtual void StartPhysicalUpdate(ContainerState s) {
|
||||||
gogroup.gameObject.SetActive(true);
|
if (s.CloneType < 16) Alive = true;
|
||||||
OpenAnchor(a_head);
|
else if (s.CloneType == 17) Init();
|
||||||
}
|
|
||||||
Awoken = true; Alive = true;
|
|
||||||
}
|
}
|
||||||
protected virtual void Awake(ContainerState s) {
|
public virtual void StartLogicalUpdate(ContainerState s) { }
|
||||||
if (gogroup) CloseAnchor();
|
public virtual void StartPreGraphicalUpdate(ContainerState s) { }
|
||||||
}
|
public virtual void StartGraphicalUpdate(ContainerState s) {
|
||||||
public virtual void StartUpdate(ContainerState s) {
|
if (gogroup) gogroup.gameObject.SetActive(true);
|
||||||
if (s.CloneType >= 2 && s.CloneType < 16) {
|
|
||||||
PreAwake(s);
|
|
||||||
Awake(s);
|
|
||||||
}
|
|
||||||
else if (s.CloneType == 17) {
|
|
||||||
Init();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
public virtual void Update(ContainerState s, StampedEvent ev) {
|
public virtual void Update(ContainerState s, StampedEvent ev) {
|
||||||
bool flag = !Awoken && s.CloneType >= 2 && s.CloneType < 16;
|
if (s.CloneType == 3) SetPreGraphicalActive(true, s);
|
||||||
if (flag) PreAwake(s);
|
else if (ev is StampedEvent.Anchor) {
|
||||||
if (gogroup && s.CloneType <= 2) skinContainer.MatchDynamic(s);
|
|
||||||
if (flag) Awake(s);
|
|
||||||
}
|
|
||||||
public virtual void ExUpdate(ContainerState s, StampedEvent ev) {
|
|
||||||
if (ev is StampedEvent.Anchor) {
|
|
||||||
var tev = (StampedEvent.Anchor)ev;
|
var tev = (StampedEvent.Anchor)ev;
|
||||||
|
if (tev.Target == a_head) {
|
||||||
|
SetGraphicalActive(true, s);
|
||||||
|
}
|
||||||
|
else if (tev.Target == a_tail) {
|
||||||
|
SetGraphicalActive(false, s);
|
||||||
|
}
|
||||||
if (gogroup) {
|
if (gogroup) {
|
||||||
OpenAnchor(tev.Target);
|
OpenAnchor(tev.Target);
|
||||||
#if UNITY_5_6_OR_NEWER
|
#if UNITY_5_6_OR_NEWER
|
||||||
@@ -155,28 +161,31 @@ namespace Cryville.Crtr.Event {
|
|||||||
}
|
}
|
||||||
anchorEvPool.Return(tev);
|
anchorEvPool.Return(tev);
|
||||||
}
|
}
|
||||||
|
else if (gogroup && s.CloneType <= 2) skinContainer.MatchDynamic(s);
|
||||||
}
|
}
|
||||||
public virtual void MotionUpdate(byte ct, Chart.Motion ev) { }
|
#region End methods
|
||||||
public virtual void EndUpdate(ContainerState s) {
|
public virtual void EndGraphicalUpdate(ContainerState s) { }
|
||||||
if (s.CloneType < 16) {
|
public virtual void EndPreGraphicalUpdate(ContainerState s) { }
|
||||||
Awoken = false;
|
public virtual void EndLogicalUpdate(ContainerState s) { }
|
||||||
if (gogroup && s.CloneType <= 2) {
|
public virtual void EndPhysicalUpdate(ContainerState s) { }
|
||||||
OpenAnchor(a_tail);
|
|
||||||
skinContainer.MatchDynamic(s);
|
|
||||||
CloseAnchor();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public virtual void Dispose() {
|
public virtual void Dispose() {
|
||||||
if (gogroup)
|
if (gogroup)
|
||||||
GameObject.Destroy(gogroup.gameObject);
|
GameObject.Destroy(gogroup.gameObject);
|
||||||
Alive = false;
|
Alive = false;
|
||||||
}
|
}
|
||||||
public virtual void DisposeAll() { }
|
public virtual void DisposeAll() { }
|
||||||
|
#endregion
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
protected static bool CanDoGraphicalUpdate(ContainerState s) { return s.CloneType >= 2 && s.CloneType < 16; }
|
||||||
#region Anchor
|
#region Anchor
|
||||||
public virtual void Anchor() {
|
public virtual void Anchor() {
|
||||||
skinContainer.MatchDynamic(cs);
|
skinContainer.MatchDynamic(cs);
|
||||||
if (cs.Working) PushAnchorEvent(cs.Time, a_cur);
|
if (cs.Active) PushAnchorEvent(cs.Time, a_cur);
|
||||||
|
if (Alive) {
|
||||||
|
PushAnchorEvent(cs.StampedContainer.Time, a_head, -1, true);
|
||||||
|
PushAnchorEvent(cs.StampedContainer.Time + cs.StampedContainer.Duration, a_tail, 1, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
static readonly SimpleObjectPool<StampedEvent.Anchor> anchorEvPool
|
static readonly SimpleObjectPool<StampedEvent.Anchor> anchorEvPool
|
||||||
= new SimpleObjectPool<StampedEvent.Anchor>(1024);
|
= new SimpleObjectPool<StampedEvent.Anchor>(1024);
|
||||||
public void PushAnchorEvent(double time, int name) {
|
public void PushAnchorEvent(double time, int name) {
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
using Cryville.Common;
|
using Cryville.Common;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Cryville.Crtr.Event {
|
namespace Cryville.Crtr.Event {
|
||||||
@@ -16,9 +17,7 @@ namespace Cryville.Crtr.Event {
|
|||||||
|
|
||||||
public Dictionary<EventContainer, ContainerState> Children
|
public Dictionary<EventContainer, ContainerState> Children
|
||||||
= new Dictionary<EventContainer, ContainerState>();
|
= new Dictionary<EventContainer, ContainerState>();
|
||||||
readonly HashSet<EventContainer> WorkingChildren
|
HashSet<EventContainer> ActiveChildren
|
||||||
= new HashSet<EventContainer>();
|
|
||||||
readonly HashSet<EventContainer> InvalidatedChildren
|
|
||||||
= new HashSet<EventContainer>();
|
= new HashSet<EventContainer>();
|
||||||
public Dictionary<Type, List<ContainerState>> TypedChildren
|
public Dictionary<Type, List<ContainerState>> TypedChildren
|
||||||
= new Dictionary<Type, List<ContainerState>>();
|
= new Dictionary<Type, List<ContainerState>>();
|
||||||
@@ -30,26 +29,45 @@ namespace Cryville.Crtr.Event {
|
|||||||
return Children[ev];
|
return Children[ev];
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotifyWorkingChanged(EventContainer key) {
|
private bool m_active;
|
||||||
InvalidatedChildren.Add(key);
|
public bool Active {
|
||||||
}
|
get { return m_active; }
|
||||||
void ValidateChildren() {
|
private set {
|
||||||
foreach (var cev in InvalidatedChildren)
|
if (m_active == value) return;
|
||||||
if (Children[cev].Working && !WorkingChildren.Contains(cev)) WorkingChildren.Add(cev);
|
m_active = value;
|
||||||
else if (!Children[cev].Working && WorkingChildren.Contains(cev)) WorkingChildren.Remove(cev);
|
if (!m_active && CloneType == 1) Dispose();
|
||||||
InvalidatedChildren.Clear();
|
if (Parent != null) {
|
||||||
}
|
if (m_active) Parent.ActiveChildren.Add(Container);
|
||||||
|
else Parent.ActiveChildren.Remove(Container);
|
||||||
public bool Active { get; set; }
|
}
|
||||||
private bool m_Working;
|
Bus.NotifyActiveChanged(this);
|
||||||
public bool Working {
|
|
||||||
get { return m_Working; }
|
|
||||||
set {
|
|
||||||
m_Working = value;
|
|
||||||
if (Parent != null) Parent.NotifyWorkingChanged(Container);
|
|
||||||
Bus.NotifyWorkingChanged(this);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private bool m_lActive;
|
||||||
|
public bool LogicalActive {
|
||||||
|
get { return m_lActive; }
|
||||||
|
set {
|
||||||
|
if (m_lActive == value) return;
|
||||||
|
m_lActive = value;
|
||||||
|
UpdateActive();
|
||||||
|
if (m_lActive) Handler.StartLogicalUpdate(this);
|
||||||
|
else Handler.EndLogicalUpdate(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private bool m_pActive;
|
||||||
|
public bool PhysicalActive {
|
||||||
|
get { return m_pActive; }
|
||||||
|
set {
|
||||||
|
if (m_pActive == value) return;
|
||||||
|
m_pActive = value;
|
||||||
|
UpdateActive();
|
||||||
|
if (m_pActive) Handler.StartPhysicalUpdate(this);
|
||||||
|
else Handler.EndPhysicalUpdate(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
void UpdateActive() { Active = m_lActive || m_pActive; }
|
||||||
|
|
||||||
public byte CloneType;
|
public byte CloneType;
|
||||||
public ContainerState rootPrototype = null;
|
public ContainerState rootPrototype = null;
|
||||||
private ContainerState prototype = null;
|
private ContainerState prototype = null;
|
||||||
@@ -112,6 +130,8 @@ namespace Cryville.Crtr.Event {
|
|||||||
AddChild(child.Key, cc, r);
|
AddChild(child.Key, cc, r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r.ActiveChildren = new HashSet<EventContainer>();
|
||||||
|
|
||||||
var pms = new Dictionary<StampedEvent, RealtimeMotionValue>(Math.Max(4, PlayingMotions.Count));
|
var pms = new Dictionary<StampedEvent, RealtimeMotionValue>(Math.Max(4, PlayingMotions.Count));
|
||||||
foreach (var m in PlayingMotions)
|
foreach (var m in PlayingMotions)
|
||||||
pms.Add(m.Key, m.Value);
|
pms.Add(m.Key, m.Value);
|
||||||
@@ -128,7 +148,10 @@ namespace Cryville.Crtr.Event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void CopyTo(byte ct, ContainerState dest) {
|
public void CopyTo(byte ct, ContainerState dest) {
|
||||||
dest.Working = Working;
|
dest.m_lActive = m_lActive;
|
||||||
|
dest.m_pActive = m_pActive;
|
||||||
|
dest.m_active = m_active;
|
||||||
|
if (dest.m_active) dest.Bus.NotifyActiveChanged(dest);
|
||||||
|
|
||||||
foreach (var mv in Values) {
|
foreach (var mv in Values) {
|
||||||
RealtimeMotionValue dv;
|
RealtimeMotionValue dv;
|
||||||
@@ -145,11 +168,15 @@ namespace Cryville.Crtr.Event {
|
|||||||
cv.Value.CopyTo(dv);
|
cv.Value.CopyTo(dv);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ct != 1) foreach (var cev in WorkingChildren)
|
foreach (var cev in dest.ActiveChildren) {
|
||||||
|
if (!ActiveChildren.Contains(cev))
|
||||||
|
Children[cev].CopyTo(ct, dest.Children[cev]);
|
||||||
|
}
|
||||||
|
dest.ActiveChildren.Clear();
|
||||||
|
foreach (var cev in ActiveChildren) {
|
||||||
|
dest.ActiveChildren.Add(cev);
|
||||||
Children[cev].CopyTo(ct, dest.Children[cev]);
|
Children[cev].CopyTo(ct, dest.Children[cev]);
|
||||||
else foreach (var child in Children)
|
}
|
||||||
child.Value.CopyTo(ct, dest.Children[child.Key]);
|
|
||||||
dest.ValidateChildren();
|
|
||||||
|
|
||||||
dest.PlayingMotions.Clear();
|
dest.PlayingMotions.Clear();
|
||||||
foreach (var m in PlayingMotions) dest.PlayingMotions.Add(m.Key, m.Value);
|
foreach (var m in PlayingMotions) dest.PlayingMotions.Add(m.Key, m.Value);
|
||||||
@@ -312,9 +339,9 @@ namespace Cryville.Crtr.Event {
|
|||||||
bool breakflag = false;
|
bool breakflag = false;
|
||||||
|
|
||||||
public void Break() {
|
public void Break() {
|
||||||
Handler.EndUpdate(this);
|
// Handler.EndLogicalUpdate(this);
|
||||||
breakflag = true;
|
breakflag = true;
|
||||||
Working = false;
|
// LogicalActive = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Discard(StampedEvent ev) {
|
public void Discard(StampedEvent ev) {
|
||||||
@@ -339,33 +366,26 @@ namespace Cryville.Crtr.Event {
|
|||||||
else if (ev.Unstamped is EventContainer) {
|
else if (ev.Unstamped is EventContainer) {
|
||||||
var cev = (EventContainer)ev.Unstamped;
|
var cev = (EventContainer)ev.Unstamped;
|
||||||
var ccs = GetChild(cev);
|
var ccs = GetChild(cev);
|
||||||
ccs.Working = true;
|
ccs.LogicalActive = true;
|
||||||
ccs.StartUpdate();
|
|
||||||
UpdateMotions();
|
UpdateMotions();
|
||||||
if (!cev.IsLong) {
|
if (!cev.IsLong) {
|
||||||
ccs.Working = false;
|
ccs.LogicalActive = false;
|
||||||
ccs.BroadcastEndUpdate();
|
|
||||||
if (CloneType == 1) ccs.Dispose();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (ev.Unstamped is InstantEvent) {
|
else if (ev.Unstamped is ReleaseEvent) {
|
||||||
var tev = (InstantEvent)ev.Unstamped;
|
var tev = (ReleaseEvent)ev.Unstamped;
|
||||||
if (tev.IsRelease) {
|
var nev = tev.Original;
|
||||||
var nev = tev.Original;
|
if (nev is Chart.Motion) {
|
||||||
if (nev is Chart.Motion) {
|
Update(ev);
|
||||||
Update(ev);
|
var mv = PlayingMotions[ev.Origin];
|
||||||
var mv = PlayingMotions[ev.Origin];
|
if (mv.CloneTypeFlag == CloneType) RMVPool.Return(mv);
|
||||||
if (mv.CloneTypeFlag == CloneType) RMVPool.Return(mv);
|
PlayingMotions.Remove(ev.Origin);
|
||||||
PlayingMotions.Remove(ev.Origin);
|
}
|
||||||
}
|
else if (nev is EventContainer) {
|
||||||
else if (nev is EventContainer) {
|
var cev = (EventContainer)ev.Origin.Unstamped;
|
||||||
var cev = (EventContainer)ev.Origin.Unstamped;
|
var ccs = GetChild(cev);
|
||||||
var ccs = GetChild(cev);
|
UpdateMotions();
|
||||||
UpdateMotions();
|
ccs.LogicalActive = false;
|
||||||
ccs.Working = false;
|
|
||||||
ccs.BroadcastEndUpdate();
|
|
||||||
if (CloneType == 1) ccs.Dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Update(ev.Unstamped == null || ev.Unstamped.Priority >= 0 ? ev : null);
|
Update(ev.Unstamped == null || ev.Unstamped.Priority >= 0 ? ev : null);
|
||||||
@@ -373,12 +393,10 @@ namespace Cryville.Crtr.Event {
|
|||||||
else Update(null);
|
else Update(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
void Update(StampedEvent ev) {
|
void Update(StampedEvent ev) {
|
||||||
UpdateMotions();
|
UpdateMotions();
|
||||||
if (ev == null || ev.Unstamped != null) Handler.Update(this, ev);
|
Handler.Update(this, ev);
|
||||||
else Handler.ExUpdate(this, ev);
|
|
||||||
foreach (var m in PlayingMotions)
|
|
||||||
Handler.MotionUpdate(CloneType, (Chart.Motion)m.Key.Unstamped);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateMotions() {
|
private void UpdateMotions() {
|
||||||
@@ -423,14 +441,17 @@ namespace Cryville.Crtr.Event {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StartUpdate() {
|
public void EndPreGraphicalUpdate() {
|
||||||
Handler.StartUpdate(this);
|
Handler.SetPreGraphicalActive(false, this);
|
||||||
|
foreach (var ls in ActiveChildren) {
|
||||||
|
Children[ls].EndPreGraphicalUpdate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void BroadcastEndUpdate() {
|
public void EndGraphicalUpdate() {
|
||||||
Handler.EndUpdate(this);
|
Handler.SetGraphicalActive(false, this);
|
||||||
foreach (var ls in Children.Values) {
|
foreach (var ls in ActiveChildren) {
|
||||||
if (ls.Working) ls.BroadcastEndUpdate();
|
Children[ls].EndGraphicalUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -84,15 +84,34 @@ namespace Cryville.Crtr.Event {
|
|||||||
Container = con
|
Container = con
|
||||||
};
|
};
|
||||||
if (ev is EventContainer) {
|
if (ev is EventContainer) {
|
||||||
stateMap[(EventContainer)ev].StampedContainer = sev;
|
var tev = (EventContainer)ev;
|
||||||
|
stateMap[tev].StampedContainer = sev;
|
||||||
|
stampedEvents.Add(new StampedEvent.ClipBehind {
|
||||||
|
Container = con,
|
||||||
|
Origin = sev,
|
||||||
|
Time = etime + tev.Clip.Behind,
|
||||||
|
});
|
||||||
|
if (!ev.IsLong) {
|
||||||
|
stampedEvents.Add(new StampedEvent.ClipAhead {
|
||||||
|
Container = con,
|
||||||
|
Origin = sev,
|
||||||
|
Time = etime + tev.Clip.Ahead,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (ev is InstantEvent) {
|
|
||||||
if (ev is ReleaseEvent) {
|
if (ev is ReleaseEvent) {
|
||||||
var tev = (ReleaseEvent)ev;
|
var tev = (ReleaseEvent)ev;
|
||||||
var oev = tev.Original;
|
var oev = tev.Original;
|
||||||
var pev = map[oev];
|
var pev = map[oev];
|
||||||
pev.ReleaseEvent = sev;
|
pev.ReleaseEvent = sev;
|
||||||
sev.Origin = pev;
|
sev.Origin = pev;
|
||||||
|
if (oev is EventContainer) {
|
||||||
|
stampedEvents.Add(new StampedEvent.ClipAhead {
|
||||||
|
Container = con,
|
||||||
|
Origin = pev,
|
||||||
|
Time = etime + ((EventContainer)oev).Clip.Ahead,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (con != null && coevents.Contains(ev)) {
|
if (con != null && coevents.Contains(ev)) {
|
||||||
List<StampedEvent> cevs;
|
List<StampedEvent> cevs;
|
||||||
|
@@ -11,31 +11,27 @@ namespace Cryville.Crtr.Event {
|
|||||||
|
|
||||||
Dictionary<EventContainer, ContainerState> states
|
Dictionary<EventContainer, ContainerState> states
|
||||||
= new Dictionary<EventContainer, ContainerState>();
|
= new Dictionary<EventContainer, ContainerState>();
|
||||||
HashSet<EventContainer> activeContainers
|
HashSet<ContainerState> activeStates
|
||||||
= new HashSet<EventContainer>();
|
|
||||||
HashSet<ContainerState> workingStates
|
|
||||||
= new HashSet<ContainerState>();
|
= new HashSet<ContainerState>();
|
||||||
HashSet<ContainerState> invalidatedStates
|
HashSet<ContainerState> invalidatedStates
|
||||||
= new HashSet<ContainerState>();
|
= new HashSet<ContainerState>();
|
||||||
|
public int ActiveStateCount { get { return activeStates.Count; } }
|
||||||
|
|
||||||
public EventBus(ContainerState root, List<EventBatch> b) : base(b) {
|
public EventBus(ContainerState root, List<EventBatch> b) : base(b) {
|
||||||
RootState = root;
|
RootState = root;
|
||||||
Expand();
|
Expand();
|
||||||
AttachBus();
|
AttachBus();
|
||||||
RootState.Working = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public EventBus Clone(byte ct, float offsetTime = 0) {
|
public EventBus Clone(byte ct, float offsetTime = 0) {
|
||||||
var r = (EventBus)MemberwiseClone();
|
var r = (EventBus)MemberwiseClone();
|
||||||
r.prototype = this;
|
r.prototype = this;
|
||||||
r.states = new Dictionary<EventContainer, ContainerState>();
|
r.states = new Dictionary<EventContainer, ContainerState>();
|
||||||
r.activeContainers = new HashSet<EventContainer>();
|
r.activeStates = new HashSet<ContainerState>();
|
||||||
r.workingStates = new HashSet<ContainerState>();
|
|
||||||
r.invalidatedStates = new HashSet<ContainerState>();
|
r.invalidatedStates = new HashSet<ContainerState>();
|
||||||
r.tempEvents = new List<StampedEvent>();
|
r.tempEvents = new List<StampedEvent.Temporary>();
|
||||||
r.Time += offsetTime;
|
r.Time += offsetTime;
|
||||||
r.RootState = RootState.Clone(ct);
|
r.RootState = RootState.Clone(ct);
|
||||||
r.RootState.StartUpdate();
|
|
||||||
r.Expand();
|
r.Expand();
|
||||||
r.AttachBus();
|
r.AttachBus();
|
||||||
foreach (var s in r.states) r.invalidatedStates.Add(s.Value);
|
foreach (var s in r.states) r.invalidatedStates.Add(s.Value);
|
||||||
@@ -45,18 +41,9 @@ namespace Cryville.Crtr.Event {
|
|||||||
|
|
||||||
public void CopyTo(byte ct, EventBus dest) {
|
public void CopyTo(byte ct, EventBus dest) {
|
||||||
base.CopyTo(dest);
|
base.CopyTo(dest);
|
||||||
dest.workingStates.Clear();
|
dest.activeStates.Clear();
|
||||||
dest.invalidatedStates.Clear();
|
dest.invalidatedStates.Clear();
|
||||||
RootState.CopyTo(ct, dest.RootState);
|
RootState.CopyTo(ct, dest.RootState);
|
||||||
if (ct >= 2) {
|
|
||||||
dest.activeContainers.Clear();
|
|
||||||
foreach (var c in activeContainers) {
|
|
||||||
if (states[c].Working) {
|
|
||||||
states[c].CopyTo(ct, dest.states[c]);
|
|
||||||
dest.activeContainers.Add(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dest.ValidateStates();
|
dest.ValidateStates();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,7 +54,7 @@ namespace Cryville.Crtr.Event {
|
|||||||
RootState.DisposeAll();
|
RootState.DisposeAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void NotifyWorkingChanged(ContainerState state) {
|
public void NotifyActiveChanged(ContainerState state) {
|
||||||
if (!invalidatedStates.Contains(state)) invalidatedStates.Add(state);
|
if (!invalidatedStates.Contains(state)) invalidatedStates.Add(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,22 +73,6 @@ namespace Cryville.Crtr.Event {
|
|||||||
s.Bus = this;
|
s.Bus = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EnsureActivity(EventContainer c) {
|
|
||||||
if (activeContainers.Contains(c)) return;
|
|
||||||
var state = states[c];
|
|
||||||
if (state.Parent != null) EnsureActivity(state.Parent.Container);
|
|
||||||
if (RootState.CloneType >= 2) prototype.states[c].CopyTo(RootState.CloneType, state);
|
|
||||||
state.Active = true;
|
|
||||||
activeContainers.Add(c);
|
|
||||||
|
|
||||||
if (state.StampedContainer.Coevents == null) return;
|
|
||||||
foreach (var cev in state.StampedContainer.Coevents) {
|
|
||||||
if (cev.Container == null) continue;
|
|
||||||
EnsureActivity(cev.Container);
|
|
||||||
states[cev.Container].Handle(cev);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AttachBus() {
|
void AttachBus() {
|
||||||
foreach (var s in states.Values)
|
foreach (var s in states.Values)
|
||||||
s.Bus = this;
|
s.Bus = this;
|
||||||
@@ -145,18 +116,26 @@ namespace Cryville.Crtr.Event {
|
|||||||
double time0 = Math.Min(time1, time2);
|
double time0 = Math.Min(time1, time2);
|
||||||
if (time0 <= toTime && time0 != double.PositiveInfinity) {
|
if (time0 <= toTime && time0 != double.PositiveInfinity) {
|
||||||
Time = time0;
|
Time = time0;
|
||||||
foreach (var s in workingStates) s.Handle(null);
|
foreach (var s in activeStates) s.Handle(null);
|
||||||
ValidateStates();
|
ValidateStates();
|
||||||
if (time1 == time0) {
|
if (time1 == time0) {
|
||||||
var batch = Events[EventId];
|
var batch = Events[EventId];
|
||||||
for (var i = 0; i < batch.Count; i++) {
|
for (var i = 0; i < batch.Count; i++) {
|
||||||
var ev = batch[i];
|
var ev = batch[i];
|
||||||
if (ev.Container != null) {
|
if (ev is StampedEvent.ClipBehind) {
|
||||||
if (ev.Unstamped is EventContainer) EnsureActivity((EventContainer)ev.Unstamped);
|
var cevs = ev.Origin.Coevents;
|
||||||
else EnsureActivity(ev.Container);
|
if (cevs != null) foreach (var cev in cevs) {
|
||||||
|
if (cev.Container == null) continue;
|
||||||
|
states[cev.Container].Handle(cev);
|
||||||
|
}
|
||||||
|
states[(EventContainer)ev.Origin.Unstamped].PhysicalActive = true;
|
||||||
|
}
|
||||||
|
else if (ev is StampedEvent.ClipAhead) {
|
||||||
|
states[(EventContainer)ev.Origin.Unstamped].PhysicalActive = false;
|
||||||
|
}
|
||||||
|
else if (ev.Container != null) {
|
||||||
states[ev.Container].Handle(ev);
|
states[ev.Container].Handle(ev);
|
||||||
}
|
}
|
||||||
else if (ev.Coevents != null) EnsureActivity((EventContainer)ev.Unstamped);
|
|
||||||
}
|
}
|
||||||
EventId++;
|
EventId++;
|
||||||
}
|
}
|
||||||
@@ -165,25 +144,23 @@ namespace Cryville.Crtr.Event {
|
|||||||
var ev = tempEvents[0];
|
var ev = tempEvents[0];
|
||||||
if (ev.Time != time0) break;
|
if (ev.Time != time0) break;
|
||||||
if (ev.Container != null) {
|
if (ev.Container != null) {
|
||||||
EnsureActivity(ev.Container);
|
|
||||||
states[ev.Container].Handle(ev);
|
states[ev.Container].Handle(ev);
|
||||||
}
|
}
|
||||||
tempEvents.RemoveAt(0);
|
tempEvents.RemoveAt(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ValidateStates();
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Time = toTime;
|
Time = toTime;
|
||||||
foreach (var s in workingStates) s.Handle(null);
|
foreach (var s in activeStates) s.Handle(null);
|
||||||
ValidateStates();
|
|
||||||
}
|
}
|
||||||
|
ValidateStates();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ValidateStates() {
|
private void ValidateStates() {
|
||||||
foreach (var s in invalidatedStates)
|
foreach (var s in invalidatedStates)
|
||||||
if (s.Working && !workingStates.Contains(s)) workingStates.Add(s);
|
if (s.Active && !activeStates.Contains(s)) activeStates.Add(s);
|
||||||
else if (!s.Working && workingStates.Contains(s)) workingStates.Remove(s);
|
else if (!s.Active && activeStates.Contains(s)) activeStates.Remove(s);
|
||||||
invalidatedStates.Clear();
|
invalidatedStates.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,8 +171,11 @@ namespace Cryville.Crtr.Event {
|
|||||||
RootState.BroadcastPostInit();
|
RootState.BroadcastPostInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void BroadcastEndUpdate() {
|
public void EndPreGraphicalUpdate() {
|
||||||
RootState.BroadcastEndUpdate();
|
RootState.EndPreGraphicalUpdate();
|
||||||
|
}
|
||||||
|
public void EndGraphicalUpdate() {
|
||||||
|
RootState.EndGraphicalUpdate();
|
||||||
foreach (var ev in tempEvents) {
|
foreach (var ev in tempEvents) {
|
||||||
if (ev.Container != null) {
|
if (ev.Container != null) {
|
||||||
states[ev.Container].Discard(ev);
|
states[ev.Container].Discard(ev);
|
||||||
|
@@ -59,19 +59,17 @@ namespace Cryville.Crtr {
|
|||||||
sgos = gogroup.GetComponentsInChildren<SectionalGameObject>();
|
sgos = gogroup.GetComponentsInChildren<SectionalGameObject>();
|
||||||
foreach (var judge in judges.Values) judge.InitPropSrcs();
|
foreach (var judge in judges.Values) judge.InitPropSrcs();
|
||||||
}
|
}
|
||||||
protected override void PreAwake(ContainerState s) {
|
|
||||||
base.PreAwake(s);
|
public override void StartPhysicalUpdate(ContainerState s) {
|
||||||
#if UNITY_5_6_OR_NEWER
|
base.StartPhysicalUpdate(s);
|
||||||
a_head.Transform.SetPositionAndRotation(Position = GetFramePoint(s.Parent, s.Track), Rotation = GetFrameRotation(s.Parent, s.Track));
|
|
||||||
#else
|
|
||||||
a_head.Transform.position = Position = GetFramePoint(s.Parent, s.Track);
|
|
||||||
a_head.Transform.rotation = Rotation = GetFrameRotation(s.Parent, s.Track);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
protected override void Awake(ContainerState s) {
|
|
||||||
base.Awake(s);
|
|
||||||
if (s.CloneType == 2) {
|
if (s.CloneType == 2) {
|
||||||
if (!gogroup) return;
|
TransformAwake(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override void StartGraphicalUpdate(ContainerState s) {
|
||||||
|
base.StartGraphicalUpdate(s);
|
||||||
|
TransformAwake(s);
|
||||||
|
if (gogroup) {
|
||||||
if (Event.IsLong) {
|
if (Event.IsLong) {
|
||||||
foreach (var i in sgos) {
|
foreach (var i in sgos) {
|
||||||
i.Reset();
|
i.Reset();
|
||||||
@@ -88,17 +86,18 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void TransformAwake(ContainerState s) {
|
||||||
|
Position = GetFramePoint(s.Parent, s.Track);
|
||||||
|
Rotation = GetFrameRotation(s.Parent, s.Track);
|
||||||
|
}
|
||||||
|
|
||||||
public override void Update(ContainerState s, StampedEvent ev) {
|
public override void Update(ContainerState s, StampedEvent ev) {
|
||||||
base.Update(s, ev);
|
base.Update(s, ev);
|
||||||
if (s.CloneType <= 2) {
|
if (s.CloneType <= 2) {
|
||||||
Position = GetFramePoint(s.Parent, s.Track);
|
Position = GetFramePoint(s.Parent, s.Track);
|
||||||
Rotation = GetFrameRotation(s.Parent, s.Track);
|
Rotation = GetFrameRotation(s.Parent, s.Track);
|
||||||
}
|
if (s.CloneType == 2) {
|
||||||
if (s.CloneType == 2) {
|
if (!gogroup || !Event.IsLong) return;
|
||||||
if (!gogroup) return;
|
|
||||||
Chart.Note tev = Event;
|
|
||||||
if (tev.IsLong) {
|
|
||||||
foreach (var i in sgos)
|
foreach (var i in sgos)
|
||||||
i.AppendPoint(Position, Rotation);
|
i.AppendPoint(Position, Rotation);
|
||||||
}
|
}
|
||||||
@@ -116,22 +115,11 @@ namespace Cryville.Crtr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Anchor() {
|
public override void EndGraphicalUpdate(ContainerState s) {
|
||||||
base.Anchor();
|
if (gogroup) {
|
||||||
// TODO Push Dynamic Anchor Events
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void EndUpdate(ContainerState s) {
|
|
||||||
if (s.CloneType == 2 && gogroup) {
|
|
||||||
foreach (var i in sgos) i.Seal();
|
foreach (var i in sgos) i.Seal();
|
||||||
#if UNITY_5_6_OR_NEWER
|
|
||||||
a_tail.Transform.SetPositionAndRotation(GetFramePoint(ts.Parent, ts.Track), Quaternion.Euler(ts.Direction));
|
|
||||||
#else
|
|
||||||
a_tail.Transform.position = GetFramePoint(ts.Parent, ts.Track);
|
|
||||||
a_tail.Transform.rotation = Quaternion.Euler(ts.Direction);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
base.EndUpdate(s);
|
base.EndGraphicalUpdate(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 GetFramePoint(ContainerState state, float track) {
|
Vector3 GetFramePoint(ContainerState state, float track) {
|
||||||
|
@@ -39,8 +39,16 @@ namespace Cryville.Crtr {
|
|||||||
public override int Priority { get { return m_priority; } }
|
public override int Priority { get { return m_priority; } }
|
||||||
public void SetPriority(int value) { m_priority = value; }
|
public void SetPriority(int value) { m_priority = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class ClipBehind : StampedEvent {
|
||||||
public override int Priority {
|
public override int Priority {
|
||||||
get { return 0; }
|
get { return Origin.Priority - 0x8000; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ClipAhead : StampedEvent {
|
||||||
|
public override int Priority {
|
||||||
|
get { return 0x7fff - Origin.Priority; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -21,34 +21,37 @@ namespace Cryville.Crtr {
|
|||||||
SectionalGameObject[] sgos;
|
SectionalGameObject[] sgos;
|
||||||
Vector3 bpos; Quaternion brot;
|
Vector3 bpos; Quaternion brot;
|
||||||
Vector3 spos;
|
Vector3 spos;
|
||||||
protected override void PreAwake(ContainerState s) {
|
public override void StartPhysicalUpdate(ContainerState s) {
|
||||||
base.PreAwake(s);
|
base.StartPhysicalUpdate(s);
|
||||||
|
if (CanDoGraphicalUpdate(s)) {
|
||||||
|
TransformAwake(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override void StartPreGraphicalUpdate(ContainerState s) {
|
||||||
|
base.StartPreGraphicalUpdate(s);
|
||||||
|
TransformAwake(s);
|
||||||
|
}
|
||||||
|
public override void StartGraphicalUpdate(ContainerState s) {
|
||||||
|
base.StartGraphicalUpdate(s);
|
||||||
|
if (gogroup) {
|
||||||
|
TransformAwake(s);
|
||||||
|
var p = GetCurrentWorldPoint();
|
||||||
|
foreach (var i in sgos) {
|
||||||
|
i.Reset();
|
||||||
|
i.AppendPoint(p, s.QuatDir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void TransformAwake(ContainerState s) {
|
||||||
pwp = Vector3.zero;
|
pwp = Vector3.zero;
|
||||||
cpt = s.ScreenPoint;
|
cpt = s.ScreenPoint;
|
||||||
ptime = s.Time;
|
ptime = s.Time;
|
||||||
if (s.CloneType == 2) {
|
if (s.CloneType == 3) {
|
||||||
#if UNITY_5_6_OR_NEWER
|
|
||||||
a_head.Transform.SetPositionAndRotation(GetCurrentWorldPoint(), Quaternion.Euler(s.Direction));
|
|
||||||
#else
|
|
||||||
a_head.Transform.position = GetCurrentWorldPoint();
|
|
||||||
a_head.Transform.rotation = Quaternion.Euler(s.Direction);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else if (s.CloneType == 3) {
|
|
||||||
spos = Vector3.zero;
|
spos = Vector3.zero;
|
||||||
bpos = cpt;
|
bpos = cpt;
|
||||||
brot = Quaternion.Euler(s.Direction);
|
brot = Quaternion.Euler(s.Direction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protected override void Awake(ContainerState s) {
|
|
||||||
base.Awake(s);
|
|
||||||
if (!gogroup) return;
|
|
||||||
var p = GetCurrentWorldPoint();
|
|
||||||
foreach (var i in sgos) {
|
|
||||||
i.Reset();
|
|
||||||
i.AppendPoint(p, s.QuatDir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector3 cpt; // Current point
|
Vector3 cpt; // Current point
|
||||||
Vector3 ppt = Vector3.zero; // Previous point
|
Vector3 ppt = Vector3.zero; // Previous point
|
||||||
@@ -58,7 +61,7 @@ namespace Cryville.Crtr {
|
|||||||
|
|
||||||
public override void Update(ContainerState s, StampedEvent ev) {
|
public override void Update(ContainerState s, StampedEvent ev) {
|
||||||
base.Update(s, ev);
|
base.Update(s, ev);
|
||||||
if (s.CloneType == 2 || s.CloneType == 3) {
|
if (CanDoGraphicalUpdate(s)) {
|
||||||
var tpt = s.ScreenPoint;
|
var tpt = s.ScreenPoint;
|
||||||
var tsv = s.ScrollVelocity;
|
var tsv = s.ScrollVelocity;
|
||||||
|
|
||||||
@@ -102,24 +105,14 @@ namespace Cryville.Crtr {
|
|||||||
spos = bpos - GetCurrentWorldPoint();
|
spos = bpos - GetCurrentWorldPoint();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void EndUpdate(ContainerState s) {
|
public override void EndGraphicalUpdate(ContainerState s) {
|
||||||
base.EndUpdate(s);
|
base.EndGraphicalUpdate(s);
|
||||||
if (s.CloneType == 0 || s.CloneType == 2) {
|
EndUpdatePosition(s);
|
||||||
EndUpdatePosition(ts);
|
var p = GetCurrentWorldPoint();
|
||||||
var p = GetCurrentWorldPoint();
|
foreach (var i in sgos) {
|
||||||
foreach (var i in sgos) {
|
i.AppendPoint(p, s.QuatDir);
|
||||||
i.AppendPoint(p, s.QuatDir);
|
i.Seal();
|
||||||
i.Seal();
|
|
||||||
}
|
|
||||||
#if UNITY_5_6_OR_NEWER
|
|
||||||
a_tail.Transform.SetPositionAndRotation(GetCurrentWorldPoint(), Quaternion.Euler(ts.Direction));
|
|
||||||
#else
|
|
||||||
a_tail.Transform.position = GetCurrentWorldPoint();
|
|
||||||
a_tail.Transform.rotation = Quaternion.Euler(ts.Direction);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else if (s.CloneType == 3) EndUpdatePosition(ns);
|
|
||||||
else if (s.CloneType >= 16) EndUpdatePosition(ps);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EndUpdatePosition(ContainerState s) {
|
void EndUpdatePosition(ContainerState s) {
|
||||||
|
Reference in New Issue
Block a user