private void SpawnBelt(Vector2 offset, bool down) { var wayPoints = new Vector2[BeltLength + 1]; for (int i = 0; i < BeltLength + 1; i++) { wayPoints[i] = offset + new Vector2(0, -(down ? i : (BeltLength - i))); } var spritePositions = new Vector2[BeltLength]; for (int i = 0; i < BeltLength; i++) { spritePositions[i] = offset + new Vector2(0, -.5f - (down ? i : (BeltLength - 1 - i))); } wayPoints[wayPoints.Length - 1] = offset + new Vector2(0, down ? -BeltLength : 0); var beltSystem = new BeltSystem(wayPoints, spritePositions) { Down = down }; for (int i = 1; i < BeltLength - 1; i++) { beltSystem.PushItemRaw(new ItemOnBelt(i)); } Manager.Belts.Add(beltSystem); Manager.Objects.Insert(beltSystem); }
private void UpdatePack(int packIndex, int totalPacks) { float from = (float)packIndex / totalPacks; float to = (float)(packIndex + 1) / totalPacks; for (int i = (int)(Belts.Count * from); i < (int)(Belts.Count * to); i++) { BeltSystem beltSystem = Belts[i]; for (int j = 0; j < beltSystem.Items.Count - beltSystem.StuckItems; j++) { var items = beltSystem.Items; float progress = items[j].Progress + multithreadedDeltaTime; if (progress > beltSystem.WayPoints.Length - 1.176f - beltSystem.StuckItems * .33f) { progress = beltSystem.WayPoints.Length - 1.16f - beltSystem.StuckItems * .33f; beltSystem.StuckItems++; } items[j] = new ItemOnBelt(progress); } } updatingBarrier.SignalAndWait(); for (int i = (int)(Hands.Count * from); i < (int)(Hands.Count * to); i++) { Hand hand = Hands[i]; if (hand.ItemOnBelt.HasValue) { var item = hand.ItemOnBelt.Value; float progress = item.Progress + multithreadedDeltaTime; if (progress >= 1) { item.Progress = hand.ToProgress; if (hand.To.PushItem(item)) { hand.ItemOnBelt = null; } } else { item.Progress = progress; hand.ItemOnBelt = item; } } else { var item = hand.From.PopItem(hand.FromProgress); if (item.HasValue) { ItemOnBelt itemValue = item.Value; itemValue.Progress = 0; hand.ItemOnBelt = itemValue; } } } }