Improve lathe queue performance (#38583)
* Use an actual Queue * Store ProtoIds instead of prototypes * Network as NetListAsArray * Remove Serializable & NetSerializable from LatheRecipePrototype * Convert CurrentlyProducing too * No point using NetListAsArray<T> if you're going to .ToArray() it anyways. --------- Co-authored-by: PJB3005 <pieterjan.briers+git@gmail.com>
This commit is contained in:
@@ -183,7 +183,7 @@ namespace Content.Server.Lathe
|
||||
|
||||
_materialStorage.TryChangeMaterialAmount(uid, mat, adjustedAmount);
|
||||
}
|
||||
component.Queue.Add(recipe);
|
||||
component.Queue.Enqueue(recipe);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -195,8 +195,8 @@ namespace Content.Server.Lathe
|
||||
if (component.CurrentRecipe != null || component.Queue.Count <= 0 || !this.IsPowered(uid, EntityManager))
|
||||
return false;
|
||||
|
||||
var recipe = component.Queue.First();
|
||||
component.Queue.RemoveAt(0);
|
||||
var recipeProto = component.Queue.Dequeue();
|
||||
var recipe = _proto.Index(recipeProto);
|
||||
|
||||
var time = _reagentSpeed.ApplySpeed(uid, recipe.CompleteTime) * component.TimeMultiplier;
|
||||
|
||||
@@ -226,13 +226,14 @@ namespace Content.Server.Lathe
|
||||
|
||||
if (comp.CurrentRecipe != null)
|
||||
{
|
||||
if (comp.CurrentRecipe.Result is { } resultProto)
|
||||
var currentRecipe = _proto.Index(comp.CurrentRecipe.Value);
|
||||
if (currentRecipe.Result is { } resultProto)
|
||||
{
|
||||
var result = Spawn(resultProto, Transform(uid).Coordinates);
|
||||
_stack.TryMergeToContacts(result);
|
||||
}
|
||||
|
||||
if (comp.CurrentRecipe.ResultReagents is { } resultReagents &&
|
||||
if (currentRecipe.ResultReagents is { } resultReagents &&
|
||||
comp.ReagentOutputSlotId is { } slotId)
|
||||
{
|
||||
var toAdd = new Solution(
|
||||
@@ -269,9 +270,11 @@ namespace Content.Server.Lathe
|
||||
if (!Resolve(uid, ref component))
|
||||
return;
|
||||
|
||||
var producing = component.CurrentRecipe ?? component.Queue.FirstOrDefault();
|
||||
var producing = component.CurrentRecipe;
|
||||
if (producing == null && component.Queue.TryPeek(out var next))
|
||||
producing = next;
|
||||
|
||||
var state = new LatheUpdateState(GetAvailableRecipes(uid, component), component.Queue, producing);
|
||||
var state = new LatheUpdateState(GetAvailableRecipes(uid, component), component.Queue.ToArray(), producing);
|
||||
_uiSys.SetUiState(uid, LatheUiKey.Key, state);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user