private async Task HandleResources(IEnvironment environment, ResourceCollector resources) { var add = resources.GetRenderablesToAdd().ToHashSet(); var rem = resources.GetRenderablesToRemove().ToHashSet(); foreach (var r in add) { _engine.Value.Add(r); } foreach (var r in add.OfType <IUpdateable>()) { _engine.Value.Add(r); } foreach (var r in rem.OfType <IUpdateable>()) { _engine.Value.Remove(r); } foreach (var r in rem) { _engine.Value.Remove(r); } await _resourceCollection.Upload(environment, resources); }
public async Task Convert(MapDocument document, SceneBuilder builder, IEnumerable <IMapObject> affected, ResourceCollector resourceCollector) { var objs = document.Map.Root.FindAll(); if (affected != null) { var groups = affected.Select(x => x.ID / 200).ToHashSet(); foreach (var g in groups) { resourceCollector.RemoveRenderables(builder.GetRenderablesForGroup(g)); builder.DeleteGroup(g); } objs = objs.Where(x => groups.Contains(x.ID / 200)).ToList(); } var converters = _converters.Select(x => x.Value).OrderBy(x => (int)x.Priority).ToList(); var groupConverters = _groupConverters.Select(x => x.Value).OrderBy(x => (int)x.Priority).ToList(); foreach (var g in objs.GroupBy(x => x.ID / 200)) { builder.EnsureGroupExists(g.Key); var buffer = builder.GetBufferForGroup(g.Key); var collector = new ResourceCollector(); foreach (var gc in groupConverters) { gc.Convert(buffer, document, g, collector); } foreach (var obj in g) { foreach (var converter in converters) { if (!converter.Supports(obj)) { continue; } await converter.Convert(buffer, document, obj, collector); if (converter.ShouldStopProcessing(document, obj)) { break; } } } builder.RemoveRenderablesFromGroup(g.Key, collector.GetRenderablesToRemove()); builder.AddRenderablesToGroup(g.Key, collector.GetRenderablesToAdd()); resourceCollector.Merge(collector); } builder.Complete(); }