Exemplo n.º 1
0
        protected override void Prepare(AssetCompilerContext context, AssetItem assetItem, string targetUrlInStorage, AssetCompilerResult result)
        {
            var originalSourcePath = assetItem.FullPath;

            result.BuildSteps = new AssetBuildStep(assetItem);

            var urlRoot = originalSourcePath.GetParent();

            var stream = new MemoryStream(Encoding.UTF8.GetBytes(((EffectLogAsset)assetItem.Asset).Text));

            using (var recordedEffectCompile = new EffectLogStore(stream))
            {
                recordedEffectCompile.LoadNewValues();

                foreach (var entry in recordedEffectCompile.GetValues())
                {
                    result.BuildSteps.Add(EffectCompileCommand.FromRequest(context, assetItem.Package, urlRoot, entry.Key));
                }
            }
        }
Exemplo n.º 2
0
            /// <inheritdoc/>
            public override Task <ResultStatus> Execute(IExecuteContext executeContext, BuilderContext builderContext)
            {
                var steps = new List <BuildStep>();

                var urlRoot = originalSourcePath.GetParent();

                var fileStream = new FileStream(originalSourcePath.ToWindowsPath(), FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);

                using (var recordedEffectCompile = new EffectLogStore(fileStream))
                {
                    recordedEffectCompile.LoadNewValues();

                    foreach (var entry in recordedEffectCompile.GetValues())
                    {
                        steps.Add(EffectCompileCommand.FromRequest(context, package, urlRoot, entry.Key));
                    }
                }

                Steps = steps;

                return(base.Execute(executeContext, builderContext));
            }
Exemplo n.º 3
0
            /// <inheritdoc/>
            public override Task <ResultStatus> Execute(IExecuteContext executeContext, BuilderContext builderContext)
            {
                var steps = new List <BuildStep>();

                var urlRoot = originalSourcePath.GetParent();

                var stream = new MemoryStream(Encoding.UTF8.GetBytes(((EffectLogAsset)assetItem.Asset).Text));

                using (var recordedEffectCompile = new EffectLogStore(stream))
                {
                    recordedEffectCompile.LoadNewValues();

                    foreach (var entry in recordedEffectCompile.GetValues())
                    {
                        steps.Add(EffectCompileCommand.FromRequest(context, assetItem.Package, urlRoot, entry.Key));
                    }
                }

                Steps = steps;

                return(base.Execute(executeContext, builderContext));
            }
        /// <inheritdoc/>
        protected override Task <ResultStatus> DoCommandOverride(ICommandContext commandContext)
        {
            var gameSettings = context.GetGameSettingsAsset();

            // Find default scene URL
            var defaultSceneUrl = gameSettings.DefaultScene != null?AttachedReferenceManager.GetUrl(gameSettings.DefaultScene) : null;

            if (defaultSceneUrl == null)
            {
                return(Task.FromResult(ResultStatus.Successful));
            }

            var baseUrl = new UFile(defaultSceneUrl).GetParent();

            try
            {
                commandContext.Logger.Info($"Trying to compile effects for scene '{defaultSceneUrl}'");

                using (var sceneRenderer = new SceneRenderer(gameSettings))
                {
                    // Effect can be compiled asynchronously (since we don't have any fallback, they will have to be compiled in the same frame anyway)
                    // Also set the file provider to the current transaction
                    ((EffectCompilerCache)sceneRenderer.EffectSystem.Compiler).CompileEffectAsynchronously = true;
                    ((EffectCompilerCache)sceneRenderer.EffectSystem.Compiler).FileProvider = MicrothreadLocalDatabases.DatabaseFileProvider;
                    ((EffectCompilerCache)sceneRenderer.EffectSystem.Compiler).CurrentCache = EffectBytecodeCacheLoadSource.StartupCache;
                    sceneRenderer.EffectSystem.EffectUsed += (effectCompileRequest, result) => compilerResult.BuildSteps.Add(EffectCompileCommand.FromRequest(context, package, baseUrl, effectCompileRequest));

                    sceneRenderer.GameSystems.LoadContent();

                    // Load the scene
                    var scene = sceneRenderer.ContentManager.Load <Scene>(defaultSceneUrl);
                    sceneRenderer.SceneSystem.SceneInstance = new SceneInstance(sceneRenderer.Services, scene, ExecutionMode.EffectCompile);

                    // Disable culling
                    sceneRenderer.SceneSystem.SceneInstance.VisibilityGroups.CollectionChanged += (sender, e) =>
                    {
                        if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
                        {
                            ((VisibilityGroup)e.Item).DisableCulling = true;
                        }
                    };

                    // Update and draw
                    // This will force effects to be generated and saved in the object database
                    var time = new GameTime();
                    sceneRenderer.GameSystems.Update(time);
                    sceneRenderer.GraphicsContext.ResourceGroupAllocator.Reset(sceneRenderer.GraphicsContext.CommandList);
                    sceneRenderer.GameSystems.Draw(time);
                }
            }
            catch (Exception e)
            {
                commandContext.Logger.Warning($"Could not compile effects for scene '{defaultSceneUrl}': {e.Message + e.StackTrace}", e);
            }

            return(Task.FromResult(ResultStatus.Successful));
        }