/** * Reads a queue string into and builds a transformation queue from it. */ public TransformationQueue Read(string _s, bool fromHash = false) { MatchCollection queueExist = TransformationQueue.queueExistParse.Matches(_s); if (queueExist.Count == 0) { throw new Exception("Cannot read queue string " + _s); } TransformationQueue tQueue = new TransformationQueue(); MatchCollection jobExist = TransformationQueue.queueEntryParse.Matches(_s); if (jobExist.Count == 0) { Log.Out("No jobs found."); return(tQueue); } foreach (Match matchJob in jobExist) { Log.Out("Matched: " + matchJob.ToString()); tQueue.Add(TransformationJob.Read(matchJob.ToString(), fromHash)); } return(tQueue); }
/** * Adds to the queue, giving out the transformation time and the job added. */ private bool AddToQueue(TransformationData tData, out ulong time, out TransformationJob job) { time = 0; job = null; bool added = this.tQueue.Add(tData, out time, out job); return(added); }
/** * Adds a TransformationData object to the queue. Returns true, if the items were added successfully. */ public bool Add(TransformationData tData, out ulong transformTime, out TransformationJob job) { this.CreateQueueIfUndefined(); job = null; transformTime = TransformationQueue.CalculateTransformationTimeAsWorldTime(tData); if (this.QueueAlreadyHas(tData)) { return(false); } job = new TransformationJob(transformTime, tData); this.queue.Add(job); return(true); }
/** * Processes a queue job. */ private bool ProcessQueueJob(TransformationJob job, out ItemStack[] previousState) { previousState = (ItemStack[])this.items.Clone(); List <ItemStack> outputs = job.GetTransformationData().GetAllOutputsAfterProbabilityCalculation(); List <int> assignedSlots = new List <int>(); List <Tuple <int, ItemStack> > stacksToAdd = new List <Tuple <int, ItemStack> >(); bool canAddAll = true; // If there are no ouputs after probability calculation, then congrats, nothing to do, success. if (outputs.Count == 0) { return(true); } foreach (ItemStack output in outputs) { List <Tuple <int, ItemStack> > whereToAdd; if (!InventoryHelper.RoomInSlotsFor(this.items, output, ref assignedSlots, out whereToAdd)) { canAddAll = false; return(false); } stacksToAdd.AddRange(whereToAdd); } if (canAddAll) { foreach (Tuple <int, ItemStack> positionAndStack in stacksToAdd) { if (!InventoryHelper.TryAddItemToSlot(this.items, positionAndStack.Item1, positionAndStack.Item2)) { return(false); } } } return(canAddAll); }
public JobFailed(string reason, TransformationJob job) { Job = job; Reason = reason; }
/** * Queues ready transformations. */ private bool QueueReadyItems(TransformationData tData, out ulong transformationTime, out List <Tuple <int, ItemStack> > stackLocations, out TransformationJob job) { transformationTime = 0; job = null; if (!tData.HasAllInputs(InventoryHelper.GetItemStacksFromFilledSlots(this.items), out stackLocations)) { return(false); } return(this.AddToQueue(tData, out transformationTime, out job)); }
/** * Returns true if this job is the same as one passed in. */ public bool IsSameAs(TransformationJob _other) { return(this.jobHash == _other.jobHash); }
/** * Removes entry from queue if it's defined. */ public bool RemoveEntry(TransformationJob job) { return(this.queue.Remove(job)); }
/** * Adds a job object to the queue directly. */ public bool Add(TransformationJob job) { this.CreateQueueIfUndefined(); this.queue.Add(job); return(true); }
private void HandleJob(TransformationJob x) { backends[jobCounter % backends.Count].Forward(x); }