コード例 #1
0
        static void Main(string[] args)
        {
            PerfTracker.StartupEvent("Entered main");
            Event.AddEventsFromAssembly(Assembly.GetAssembly(typeof(UAlbion.Api.Event)));
            Event.AddEventsFromAssembly(Assembly.GetAssembly(typeof(UAlbion.Core.Events.HelpEvent)));
            Event.AddEventsFromAssembly(Assembly.GetAssembly(typeof(UAlbion.Core.Veldrid.Events.InputEvent)));
            Event.AddEventsFromAssembly(Assembly.GetAssembly(typeof(UAlbion.Editor.EditorSetPropertyEvent)));
            Event.AddEventsFromAssembly(Assembly.GetAssembly(typeof(UAlbion.Formats.ScriptEvents.PartyMoveEvent)));
            Event.AddEventsFromAssembly(Assembly.GetAssembly(typeof(UAlbion.Game.Events.StartEvent)));
            Event.AddEventsFromAssembly(Assembly.GetAssembly(typeof(UAlbion.Game.Veldrid.Debugging.HideDebugWindowEvent)));
            Event.AddEventsFromAssembly(Assembly.GetAssembly(typeof(IsoYawEvent)));
            PerfTracker.StartupEvent("Built event parsers");

            var commandLine = new CommandLineOptions(args);

            if (commandLine.Mode == ExecutionMode.Exit)
            {
                return;
            }

            PerfTracker.StartupEvent($"Running as {commandLine.Mode}");
            var disk     = new FileSystem();
            var jsonUtil = new FormatJsonUtil();

            var baseDir = ConfigUtil.FindBasePath(disk);

            if (baseDir == null)
            {
                throw new InvalidOperationException("No base directory could be found.");
            }

            PerfTracker.StartupEvent($"Found base directory {baseDir}");

            if (commandLine.Mode == ExecutionMode.ConvertAssets)
            {
                ConvertAssets.Convert(
                    disk,
                    jsonUtil,
                    commandLine.ConvertFrom,
                    commandLine.ConvertTo,
                    commandLine.DumpIds,
                    commandLine.DumpAssetTypes,
                    commandLine.ConvertFilePattern);
                return;
            }

            var(exchange, services) = AssetSystem.SetupAsync(baseDir, disk, jsonUtil).Result;
            if (commandLine.NeedsEngine)
            {
                BuildEngine(commandLine, exchange);
            }
            services.Add(new StdioConsoleReader());

            var assets = exchange.Resolve <IAssetManager>();

            AutodetectLanguage(exchange, assets);

            switch (commandLine.Mode) // ConvertAssets handled above as it requires a specialised asset system setup
            {
            case ExecutionMode.Game: Albion.RunGame(exchange, services, baseDir, commandLine); break;

            case ExecutionMode.BakeIsometric: IsometricTest.Run(exchange, commandLine); break;

            case ExecutionMode.DumpData:
                PerfTracker.BeginFrame();     // Don't need to show verbose startup logging while dumping
                var tf = new TextFormatter();
                exchange.Attach(tf);
                var parsedIds = commandLine.DumpIds?.Select(AssetId.Parse).ToArray();

                if ((commandLine.DumpFormats & DumpFormats.Json) != 0)
                {
                    DumpJson.Dump(baseDir, assets, commandLine.DumpAssetTypes, parsedIds);
                }

                if ((commandLine.DumpFormats & DumpFormats.Text) != 0)
                {
                    DumpText.Dump(assets, baseDir, tf, commandLine.DumpAssetTypes, parsedIds);
                }

                if ((commandLine.DumpFormats & DumpFormats.Png) != 0)
                {
                    var dumper = new DumpGraphics();
                    exchange.Attach(dumper);
                    dumper.Dump(baseDir, commandLine.DumpAssetTypes, commandLine.DumpFormats, parsedIds);
                }

                //if ((commandLine.DumpFormats & DumpFormats.Tiled) != 0)
                //    DumpTiled.Dump(baseDir, assets, commandLine.DumpAssetTypes, parsedIds);
                break;

            case ExecutionMode.Exit: break;
            }

            Console.WriteLine("Exiting");
            exchange.Dispose();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: vsafonkin/ualbion
        static void Main(string[] args)
        {
            PerfTracker.StartupEvent("Entered main");
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); // Required for code page 850 support in .NET Core
            PerfTracker.StartupEvent("Registered encodings");
            Task.Run(() => new LogEvent(LogEvent.Level.Verbose, "Preheat Event Metadata").ToString());

            var commandLine = new CommandLineOptions(args);

            if (commandLine.Mode == ExecutionMode.Exit)
            {
                return;
            }

            var baseDir = ConfigUtil.FindBasePath();

            if (baseDir == null)
            {
                throw new InvalidOperationException("No base directory could be found.");
            }
            PerfTracker.StartupEvent($"Found base directory {baseDir}");

            var setupAssetSystem = Task.Run(() => SetupAssetSystem(baseDir));

            PerfTracker.StartupEvent("Creating engine");
            using var engine = commandLine.NeedsEngine
                ? new VeldridEngine(commandLine.Backend, commandLine.UseRenderDoc)
                               .AddRenderer(new SkyboxRenderer())
                               .AddRenderer(new SpriteRenderer())
                               .AddRenderer(new ExtrudedTileMapRenderer())
                               .AddRenderer(new InfoOverlayRenderer())
                               .AddRenderer(new DebugGuiRenderer())
                : null;
            engine?.ChangeBackend();

            // PerfTracker.StartupEvent("Running asset tests...");
            // AssetTest(assets);
            // PerfTracker.StartupEvent("Asset tests done");

            PerfTracker.StartupEvent($"Running as {commandLine.Mode}");
            var(exchange, services) = setupAssetSystem.Result;

            // Auto-detect language
            var assets = exchange.Resolve <IAssetManager>();

            if (!assets.IsStringDefined((TextId)Base.SystemText.MainMenu_MainMenu))
            {
                foreach (var language in Enum.GetValues(typeof(GameLanguage)).Cast <GameLanguage>())
                {
                    exchange.Raise(new SetLanguageEvent(language), null);
                    if (assets.IsStringDefined((TextId)Base.SystemText.MainMenu_MainMenu))
                    {
                        break;
                    }
                }
            }

            switch (commandLine.Mode)
            {
            case ExecutionMode.Game:
            case ExecutionMode.GameWithSlavedAudio:
                Albion.RunGame(engine, exchange, services, baseDir, commandLine);
                break;

            case ExecutionMode.AudioSlave:
                exchange.Attach(new AudioManager(true));
                break;

            case ExecutionMode.Editor: break;     // TODO

            case ExecutionMode.SavedGameTests: SavedGameTests.RoundTripTest(baseDir); break;

            case ExecutionMode.DumpData:
                PerfTracker.BeginFrame();     // Don't need to show verbose startup logging while dumping
                var tf = new TextFormatter();
                exchange.Attach(tf);

                AssetId[] dumpIds = null;
                if (commandLine.DumpIds != null)
                {
                    dumpIds = commandLine.DumpIds.Select(AssetId.Parse).ToArray();
                }

                if ((commandLine.DumpFormats & DumpFormats.Json) != 0)
                {
                    DumpJson.Dump(baseDir, assets, commandLine.DumpAssetTypes, dumpIds);
                }

                if ((commandLine.DumpFormats & DumpFormats.Text) != 0)
                {
                    DumpText.Dump(assets, baseDir, tf, commandLine.DumpAssetTypes, dumpIds);
                }

                if ((commandLine.DumpFormats & DumpFormats.GraphicsMask) != 0)
                {
                    DumpGraphics.Dump(assets, baseDir, commandLine.DumpAssetTypes, commandLine.DumpFormats & DumpFormats.GraphicsMask, dumpIds);
                }

                if ((commandLine.DumpFormats & DumpFormats.Tiled) != 0)
                {
                    DumpTiled.Dump(baseDir, assets, commandLine.DumpAssetTypes, dumpIds);
                }
                break;

            case ExecutionMode.Exit: break;
            }

            Console.WriteLine("Exiting");
        }