public static void ComputeItems(ILi <IStickHitItem> target, IList <Ops.Hit> hit, IList <Ops.EndHit> endHit, IStickHitItemFactory itemFactory) { if (hit.Count <= 0 && endHit.Count <= 0) { return; } var items = target.AsWrite(); for (int i = 0, n = hit.Count; i < n; ++i) { items.Add(itemFactory.Create(hit[i])); } if (endHit.Count > 0) { for (int i = items.Count - 1; i >= 0; --i) { for (int j = 0, m = endHit.Count; j < m; ++j) { var start = items[i].Hit; var end = endHit[j]; if (start.From == end.From && start.To == end.To) { itemFactory.Dispose(items[i]); items.RemoveAt(i); } } } } }
public static void Items( ILi <ITodoItem> target, IEl <int> nextId, IMultiOp <string> newItem_, IOp <Empty> deleteCompletedItems_, IMultiOp <string> deleteItem_, ITodoItemFactory factory) { var newItem = newItem_.Read(); Empty tmp; bool deleteCompletedItems = deleteCompletedItems_.TryRead(out tmp); var deleteItem = deleteItem_.Read(); if (newItem.Count <= 0 && !deleteCompletedItems && deleteItem.Count <= 0) { return; } var items = target.AsWrite(); if (newItem.Count > 0) { for (int i = 0, n = newItem.Count; i < n; ++i) { items.Add(factory.Create((nextId.Read() + i).ToString(), newItem[i])); } nextId.Write(nextId.Read() + newItem.Count); } if (deleteCompletedItems) { items.RemoveAll(it => { if (it.IsCompleted.Read()) { factory.Dispose(it); return(true); } return(false); }); } if (deleteItem.Count > 0) { items.RemoveAll(it => { if (deleteItem.Contains(it.Id)) { factory.Dispose(it); return(true); } return(false); }); } }
public static void ComputeList(ILi <IModifierItem> target, IEntity entity, IOp <Ops.Tick> tick, IList <Ops.Hit> hit, IModifierItemFactory itemFactory) { Ops.Tick t; if (!tick.TryRead(out t) && hit.Count <= 0) { return; } var items = target.AsWrite(); for (int i = 0, n = hit.Count; i < n; ++i) { var h = hit[i]; if (h.To != entity) { continue; } var a = h.From.Hitters.AddModifier; if (a == null) { continue; } for (int j = 0, m = a.Modifiers.Count; j < m; ++j) { items.Add(itemFactory.Create(a.Modifiers[j])); } } if (tick.TryRead(out t)) { items.RemoveAll(it => { if (it.Remain.Read() == 0) { itemFactory.Dispose(it); return(true); } return(false); }); } }
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); } } ); }