internal void Setup <T>(CompositeDisposable cd, IEngine engine, ILi <T> li, Func <T, object> extractor) { var lastCd = new CompositeDisposable(); var lastTargets = new List <object>(); cd.Add(lastCd); engine.Computer(cd, new object[] { li }, () => { var l = li.Read(); var targets = new List <object>(); for (int i = 0, n = l.Count; i < n; ++i) { targets.Add(extractor(l[i])); } if (targets.Count == lastTargets.Count) { bool isSame = true; for (int i = 0, n = targets.Count; i < n; ++i) { if (!ReferenceEquals(targets[i], lastTargets[i])) { isSame = false; break; } } if (isSame) { return; } } lastTargets.Clear(); lastTargets.AddRange(targets); lastCd.Dispose(); if (targets.Count > 0) { engine.Computer(lastCd, targets.ToArray(), () => { // Work around to ensure different instance of action is registerd l.GetHashCode(); inner.Fire(Empty.Instance); engine.MarkDirty(this); } ); } } ); }
public static void UncompletedCount(IEl <int> target, ILi <ITodoItem> items_) { var items = items_.Read(); int uncompletedCount = 0; for (int i = 0, n = items.Count; i < n; ++i) { if (!items[i].IsCompleted.Read()) { ++uncompletedCount; } } if (uncompletedCount != target.Read()) { target.Write(uncompletedCount); } }
public State(IEngine engine) { Ids = engine.Li(new List <string>()); Xs = engine.Li(new List <int>()); Ys = engine.Li(new List <int>()); Vxs = engine.Li(new List <int>()); Vys = engine.Li(new List <int>()); Tick = engine.MultiOp <int>(); Add = engine.MultiOp <Rigidbody>(); engine.Computer(cd, new object[] { Tick, Add }, () => { var tick = Tick.Read(); var add = Add.Read(); if (tick.Count <= 0 && add.Count <= 0) { return; } var xs = Xs.AsWrite(); var ys = Ys.AsWrite(); { var vxs = Vxs.Read(); var vys = Vys.Read(); for (int t = 0, c = tick.Count; t < c; ++t) { var dt = tick[t]; for (int i = 0, n = Ids.Read().Count; i < n; ++i) { xs[i] += vxs[i] * dt; ys[i] += vys[i] * dt; } } } if (add.Count > 0) { for (int i = 0, n = add.Count; i < n; ++i) { var r = add[i]; xs.Add(r.X); ys.Add(r.Y); } } } ); engine.Computer(cd, new object[] { Add }, () => { var add = Add.Read(); if (add.Count <= 0) { return; } var ids = Ids.AsWrite(); var vxs = Vxs.AsWrite(); var vys = Vys.AsWrite(); for (int i = 0, n = add.Count; i < n; ++i) { var r = add[i]; ids.Add(r.Id); vxs.Add(r.Vx); vys.Add(r.Vy); } } ); }
public State(IEngine engine) { Ids = engine.Li(new List <string>()); Sheets = engine.Li(new List <object>()); CurrentFrameIndexes = engine.Li(new List <int>()); TotalFrames = engine.Li(new List <int>()); Speeds = engine.Li(new List <int>()); Tick = engine.MultiOp <int>(); Add = engine.MultiOp <Sprite>(); engine.Computer(cd, new object[] { Tick, Add }, () => { var tick = Tick.Read(); var add = Add.Read(); if (tick.Count <= 0 && add.Count <= 0) { return; } var currentFrameIndexes = CurrentFrameIndexes.AsWrite(); { var totalFrames = TotalFrames.Read(); var speeds = Speeds.Read(); for (int t = 0, c = tick.Count; t < c; ++t) { var dt = tick[t]; for (int i = 0, n = Ids.Read().Count; i < n; ++i) { var current = currentFrameIndexes[i]; current = (current + dt * speeds[i]) % totalFrames[i]; currentFrameIndexes[i] = current; } } } if (add.Count > 0) { for (int i = 0, n = add.Count; i < n; ++i) { var s = add[i]; currentFrameIndexes.Add(s.CurrentFrameIndex); } } } ); engine.Computer(cd, new object[] { Add }, () => { var add = Add.Read(); if (add.Count <= 0) { return; } var ids = Ids.AsWrite(); var sheets = Sheets.AsWrite(); var totalFrames = TotalFrames.AsWrite(); var speeds = Speeds.AsWrite(); for (int i = 0, n = add.Count; i < n; ++i) { var s = add[i]; ids.Add(s.Id); sheets.Add(s.Sheet); totalFrames.Add(s.TotalFrame); speeds.Add(s.Speed); } } ); }