// apply deferred requests for a vessel and synchronize the new amount in the vessel public void Sync(Vessel v, double elapsed_s) { // execute all possible recipes bool executing = true; while (executing) { executing = false; for (int i = 0; i < recipes.Count; ++i) { Resource_recipe recipe = recipes[i]; if (recipe.left > double.Epsilon) { executing |= recipe.Execute(v, this); } } } // forget the recipes recipes.Clear(); // apply all deferred requests and synchronize to vessel foreach (var pair in resources) { pair.Value.Sync(v, elapsed_s); } }
// register deferred execution of a recipe (shortcut) public static void Transform(Vessel v, Resource_recipe recipe) { Get(v).Transform(recipe); }
// record deferred execution of a recipe public void Transform(Resource_recipe recipe) { recipes.Add(recipe); }