/// <summary> /// Compiles the built-in embedded resources. /// </summary> private static void BuiltinCompile() { // Create kernel. var kernel = new StandardKernel(); kernel.Load<ProtogameAssetIoCModule>(); kernel.Load<ProtogameScriptIoCModule>(); var services = new GameServiceContainer(); var assetContentManager = new AssetContentManager(services); kernel.Bind<IAssetContentManager>().ToMethod(x => assetContentManager); kernel.Bind<IRenderBatcher>().To<NullRenderBatcher>(); // Only allow source and raw load strategies. kernel.Unbind<ILoadStrategy>(); kernel.Bind<ILoadStrategy>().To<LocalSourceLoadStrategy>(); var assetModule = new ProtogameAssetIoCModule(); assetModule.LoadRawAssetStrategies(kernel); // Set up remaining bindings. kernel.Bind<IAssetCleanup>().To<DefaultAssetCleanup>(); kernel.Bind<IAssetOutOfDateCalculator>().To<DefaultAssetOutOfDateCalculator>(); kernel.Bind<IAssetCompilationEngine>().To<DefaultAssetCompilationEngine>(); // Rebind for builtin compilation. kernel.Rebind<IRawAssetLoader>().To<BuiltinRawAssetLoader>(); // Set up the compiled asset saver. var compiledAssetSaver = new CompiledAssetSaver(); // Retrieve the asset manager. var assetManager = kernel.Get<LocalAssetManager>(); assetManager.AllowSourceOnly = true; assetManager.SkipCompilation = true; // Retrieve the transparent asset compiler. var assetCompiler = kernel.Get<ITransparentAssetCompiler>(); // Retrieve all of the asset savers. var savers = kernel.GetAll<IAssetSaver>(); var rawLoader = kernel.Get<IRawAssetLoader>(); // For each of the platforms, perform the compilation of assets. foreach (var platformName in new[] { "Android", "iOS", "Linux", "MacOSX", "Ouya", "Windows", }) { Console.WriteLine("Starting compilation for " + platformName); var platform = (TargetPlatform)Enum.Parse(typeof(TargetPlatform), platformName); var outputPath = Environment.CurrentDirectory; assetManager.RescanAssets(); // Create the output directory if it doesn't exist. if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } // Get a list of asset names that we need to recompile for this platform. var assetNames = rawLoader.ScanRawAssets(); foreach (var asset in assetNames.Select(assetManager.GetUnresolved)) { Console.Write("Compiling " + asset.Name + " for " + platform + "... "); try { assetCompiler.HandlePlatform(asset, platform, true); foreach (var saver in savers) { var canSave = false; try { canSave = saver.CanHandle(asset); } catch (Exception) { } if (canSave) { try { var result = saver.Handle(asset, AssetTarget.CompiledFile); compiledAssetSaver.SaveCompiledAsset( outputPath, asset.Name, result, result is CompiledAsset, platformName); Console.WriteLine("done."); break; } catch (Exception ex) { Console.WriteLine("failed!"); Console.WriteLine("ERROR: Unable to compile " + asset.Name + " for " + platform); Console.WriteLine("ERROR: " + ex.GetType().FullName + ": " + ex.Message); break; } } } } catch (Exception ex) { Console.WriteLine("failed!"); Console.WriteLine("ERROR: Unable to compile " + asset.Name + " for " + platform); Console.WriteLine("ERROR: " + ex.GetType().FullName + ": " + ex.Message); break; } assetManager.Dirty(asset.Name); } } }
private static void BulkCompile(List<string> assemblies, List<string> platforms, string output) { // Create kernel. var kernel = new StandardKernel(); kernel.Load<ProtogameAssetIoCModule>(); kernel.Load<ProtogameScriptIoCModule>(); var services = new GameServiceContainer(); var assetContentManager = new AssetContentManager(services); kernel.Bind<IAssetContentManager>().ToMethod(x => assetContentManager); kernel.Bind<IRenderBatcher>().To<NullRenderBatcher>(); // Only allow source and raw load strategies. kernel.Unbind<ILoadStrategy>(); kernel.Bind<ILoadStrategy>().To<LocalSourceLoadStrategy>(); var assetModule = new ProtogameAssetIoCModule(); assetModule.LoadRawAssetStrategies(kernel); // The assembly load strategy is required for references. // Assets loaded with the assembly load strategy won't have // any savers defined, so they won't ever get processed. kernel.Bind<ILoadStrategy>().To<AssemblyLoadStrategy>(); // Load additional assemblies. foreach (var filename in assemblies) { var file = new FileInfo(filename); try { var assembly = Assembly.LoadFrom(file.FullName); foreach (var type in assembly.GetTypes()) { try { if (type.IsAbstract || type.IsInterface) continue; if (type.Assembly == typeof(FontAsset).Assembly) continue; if (typeof(IAssetLoader).IsAssignableFrom(type)) { Console.WriteLine("Binding IAssetLoader: " + type.Name); kernel.Bind<IAssetLoader>().To(type); } if (typeof(IAssetSaver).IsAssignableFrom(type)) { Console.WriteLine("Binding IAssetSaver: " + type.Name); kernel.Bind<IAssetSaver>().To(type); } if (type.GetInterfaces().Any(x => x.Name == "IAssetCompiler`1")) { Console.WriteLine("Binding IAssetCompiler<>: " + type.Name); kernel.Bind(type.GetInterfaces().First(x => x.Name == "IAssetCompiler`1")).To(type); } if (typeof(ILoadStrategy).IsAssignableFrom(type)) { Console.WriteLine("Binding ILoadStrategy: " + type.Name); kernel.Bind<ILoadStrategy>().To(type); } } catch { // Might not be able to load the assembly, so just skip over it. } } } catch (Exception) { Console.WriteLine("Can't load " + file.Name); } } // Set up remaining bindings. kernel.Bind<IAssetCleanup>().To<DefaultAssetCleanup>(); kernel.Bind<IAssetOutOfDateCalculator>().To<DefaultAssetOutOfDateCalculator>(); kernel.Bind<IAssetCompilationEngine>().To<DefaultAssetCompilationEngine>(); // Get the asset compilation engine. var compilationEngine = kernel.Get<IAssetCompilationEngine>(); compilationEngine.Execute(platforms, output); }