コード例 #1
0
ファイル: Program.cs プロジェクト: csinkers/ualbion
    static void Main(string[] args)
    {
#if DEBUG
        PerfTracker.IsTracing = true;
#endif
        PerfTracker.StartupEvent("Entered main");
        AssetSystem.LoadEvents();
        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)
        {
            using var converter = new AssetConverter(
                      AssetMapping.Global,
                      disk,
                      jsonUtil,
                      commandLine.ConvertFrom,
                      commandLine.ConvertTo);

            converter.Convert(
                commandLine.DumpIds,
                commandLine.DumpAssetTypes,
                commandLine.ConvertFilePattern);

            return;
        }

        var(exchange, services) = AssetSystem.SetupAsync(baseDir, AssetMapping.Global, disk, jsonUtil).Result;
        IRenderPass mainPass = null;
        if (commandLine.NeedsEngine)
        {
            mainPass = 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, mainPass, 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)
            {
                var dumper = new DumpJson();
                exchange.Attach(dumper);
                dumper.Dump(baseDir, commandLine.DumpAssetTypes, parsedIds);
                dumper.Remove();
            }

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

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

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

            //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 プロジェクト: IllidanS4/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");

            var commandLine = new CommandLineOptions(args);

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

            var baseDir = FormatUtil.FindBasePath();

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

            PerfTracker.StartupEvent($"Found base directory {baseDir}");
            PerfTracker.StartupEvent("Registering asset manager");
            var factory = new VeldridCoreFactory();

            using var locatorRegistry = new AssetLocatorRegistry()
                                        .AddAssetLocator(new StandardAssetLocator())
                                        .AddAssetLocator(new AssetConfigLocator())
                                        .AddAssetLocator(new CoreSpriteLocator())
                                        .AddAssetLocator(new MetaFontLocator(factory))
                                        .AddAssetLocator(new NewStringLocator())
                                        .AddAssetLocator(new SoundBankLocator())
                                        .AddAssetLocator(new SavedGameLocator())
                                        .AddAssetPostProcessor(new AlbionSpritePostProcessor())
                                        .AddAssetPostProcessor(new ImageSharpPostProcessor())
                                        .AddAssetPostProcessor(new InterlacedBitmapPostProcessor())
                                        .AddAssetPostProcessor(new InventoryPostProcessor())
            ;

            var assets   = new AssetManager();
            var services = new Container("Services",
                                         new StdioConsoleLogger(),
                                         new ClipboardManager(),
                                         new ImGuiConsoleLogger(),
                                         Settings.Load(baseDir), // Need to register settings first, as the AssetConfigLocator relies on it.
                                         locatorRegistry,
                                         assets);

            using var exchange = new EventExchange(new LogExchange())
                                 .Register <ICoreFactory>(factory)
                                 .Attach(services);

            Engine.GlobalExchange = exchange;

            PerfTracker.StartupEvent("Registered asset manager");
            PerfTracker.StartupEvent($"Running as {commandLine.Mode}");

            switch (commandLine.Mode)
            {
            case ExecutionMode.Game:
            case ExecutionMode.GameWithSlavedAudio:
                Albion.RunGame(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);
                DumpType dumpTypes = DumpType.All;
                if (commandLine.GameModeArgument != null)
                {
                    dumpTypes = 0;
                    foreach (var t in commandLine.GameModeArgument.Split(' ', StringSplitOptions.RemoveEmptyEntries))
                    {
                        dumpTypes |= Enum.Parse <DumpType>(t);
                    }
                }

                if ((dumpTypes & DumpType.Characters) != 0)
                {
                    Dump.CharacterSheets(assets, tf, baseDir);
                }
                if ((dumpTypes & DumpType.Chests) != 0)
                {
                    Dump.Chests(assets, baseDir);
                }
                if ((dumpTypes & DumpType.CoreSprites) != 0)
                {
                    Dump.CoreSprites(assets, baseDir);
                }
                if ((dumpTypes & DumpType.EventSets) != 0)
                {
                    Dump.EventSets(assets, baseDir);
                }
                if ((dumpTypes & DumpType.Items) != 0)
                {
                    Dump.ItemData(assets, baseDir);
                }
                if ((dumpTypes & DumpType.MapEvents) != 0)
                {
                    Dump.MapEvents(assets, baseDir);
                }
                if ((dumpTypes & DumpType.Maps) != 0)
                {
                    Dump.MapData(assets, tf, baseDir);
                }
                if ((dumpTypes & DumpType.Spells) != 0)
                {
                    Dump.Spells(assets, tf, baseDir);
                }
                if ((dumpTypes & DumpType.ThreeDMaps) != 0)
                {
                    Dump.ThreeDMapAndLabInfo(assets, baseDir);
                }
                break;

            case ExecutionMode.Exit: break;
            }
        }
コード例 #3
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();
        }
コード例 #4
0
        public void Run()
        {
            ChangeBackend();
            PerfTracker.StartupEvent("Set up backend");
            Sdl2Native.SDL_Init(SDLInitFlags.GameController);
            ImGui.StyleColorsClassic();
            Raise(new WindowResizedEvent(Window.Width, Window.Height));
            Raise(new BeginFrameEvent());

            var frameCounter = new FrameCounter();

            PerfTracker.StartupEvent("Startup done, rendering first frame");
            while (!_done)
            {
                ChangeBackend();

                PerfTracker.BeginFrame();
                double deltaSeconds = frameCounter.StartFrame();
                using (PerfTracker.FrameEvent("1 Raising begin frame"))
                    Raise(new BeginFrameEvent());

                InputSnapshot snapshot;
                using (PerfTracker.FrameEvent("2 Processing SDL events"))
                {
                    Sdl2Events.ProcessEvents();
                    snapshot = Window.PumpEvents();
                }

                if (!Window.Exists)
                {
                    break;
                }

                if (_pendingCursorUpdate.HasValue)
                {
                    using (PerfTracker.FrameEvent("3 Warping mouse"))
                    {
                        Sdl2Native.SDL_WarpMouseInWindow(
                            Window.SdlWindowHandle,
                            (int)_pendingCursorUpdate.Value.X,
                            (int)_pendingCursorUpdate.Value.Y);

                        _pendingCursorUpdate = null;
                    }
                }

                using (PerfTracker.FrameEvent("4 Raising input event"))
                    Raise(new InputEvent(deltaSeconds, snapshot, Window.MouseDelta));

                using (PerfTracker.FrameEvent("5 Performing update"))
                    Update((float)deltaSeconds);

                if (!Window.Exists)
                {
                    break;
                }

                using (PerfTracker.FrameEvent("6 Drawing"))
                    Draw();

                var flags = Resolve <IEngineSettings>().Flags;
                if (GraphicsDevice.SyncToVerticalBlank != flags.HasFlag(EngineFlags.VSync))
                {
                    GraphicsDevice.SyncToVerticalBlank = flags.HasFlag(EngineFlags.VSync);
                }

                using (PerfTracker.FrameEvent("7 Swap buffers"))
                {
                    CoreTrace.Log.Info("Engine", "Swapping buffers...");
                    GraphicsDevice.SwapBuffers();
                    CoreTrace.Log.Info("Engine", "Draw complete");
                }
            }

            DestroyAllObjects();
            GraphicsDevice.Dispose();
            Window.Close();
        }
コード例 #5
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");
        }