Esempio n. 1
0
        public void Dispose()
        {
            if (userInput != null)
            {
                userInput.Dispose();
                userInput = null;
            }

            if (music != null)
            {
                music.Dispose();
                music = null;
            }

            if (sound != null)
            {
                sound.Dispose();
                sound = null;
            }

            if (renderer != null)
            {
                renderer.Dispose();
                renderer = null;
            }

            if (resource != null)
            {
                resource.Dispose();
                resource = null;
            }

            if (window != null)
            {
                window.Dispose();
                window = null;
            }
        }
Esempio n. 2
0
        public DoomApplication(CommandLineArgs args)
        {
            config = new Config(ConfigUtilities.GetConfigPath());

            try
            {
                config.video_screenwidth  = Math.Clamp(config.video_screenwidth, 320, 3200);
                config.video_screenheight = Math.Clamp(config.video_screenheight, 200, 2000);
                var videoMode = new VideoMode((uint)config.video_screenwidth, (uint)config.video_screenheight);
                var style     = Styles.Close | Styles.Titlebar;
                if (config.video_fullscreen)
                {
                    style = Styles.Fullscreen;
                }
                window = new RenderWindow(videoMode, ApplicationInfo.Title, style);
                window.Clear(new Color(64, 64, 64));
                window.Display();

                if (args.deh.Present)
                {
                    DeHackEd.ReadFiles(args.deh.Value);
                }

                resource = new CommonResource(GetWadPaths(args));

                renderer = new SfmlRenderer(config, window, resource);

                if (!args.nosound.Present && !args.nosfx.Present)
                {
                    sound = new SfmlSound(config, resource.Wad);
                }

                if (!args.nosound.Present && !args.nomusic.Present)
                {
                    music = ConfigUtilities.GetSfmlMusicInstance(config, resource.Wad);
                }

                userInput = new SfmlUserInput(config, window, !args.nomouse.Present);

                events = new List <DoomEvent>();

                options             = new GameOptions();
                options.GameVersion = resource.Wad.GameVersion;
                options.GameMode    = resource.Wad.GameMode;
                options.MissionPack = resource.Wad.MissionPack;
                options.Renderer    = renderer;
                options.Sound       = sound;
                options.Music       = music;
                options.UserInput   = userInput;

                menu = new DoomMenu(this);

                opening = new OpeningSequence(resource, options);

                cmds = new TicCmd[Player.MaxPlayerCount];
                for (var i = 0; i < Player.MaxPlayerCount; i++)
                {
                    cmds[i] = new TicCmd();
                }
                game = new DoomGame(resource, options);

                wipe   = new WipeEffect(renderer.WipeBandCount, renderer.WipeHeight);
                wiping = false;

                currentState = ApplicationState.None;
                nextState    = ApplicationState.Opening;
                needWipe     = false;

                sendPause = false;

                quit        = false;
                quitMessage = null;

                CheckGameArgs(args);

                window.Closed      += (sender, e) => window.Close();
                window.KeyPressed  += KeyPressed;
                window.KeyReleased += KeyReleased;

                if (!args.timedemo.Present)
                {
                    window.SetFramerateLimit(35);
                }

                mouseGrabbed = false;
            }
            catch (Exception e)
            {
                Dispose();
                ExceptionDispatchInfo.Throw(e);
            }
        }
        public DoomApplication(CommandLineArgs args, String[] configLines, HttpClient http, Stream wadStream,
                               IJSRuntime jsRuntime, IJSInProcessRuntime jSInProcessRuntime, WebAssemblyJSRuntime webAssemblyJSRuntime,
                               string wadUrl)
        {
            Http                 = http;
            WadStream            = wadStream;
            JsRuntime            = jsRuntime;
            JSInProcessRuntime   = jSInProcessRuntime;
            WebAssemblyJSRuntime = webAssemblyJSRuntime;
            configLines          = new string[] {
                "video_screenwidth=320",
                "video_screenHeight=200",
            };
            config = new Config(configLines);

            try
            {
                config.video_screenwidth  = Math.Clamp(config.video_screenwidth, 320, 3200);
                config.video_screenheight = Math.Clamp(config.video_screenheight, 200, 2000);
                var videoMode = VideoMode.CanvasMode;
                var style     = Styles.Close | Styles.Titlebar;
                if (config.video_fullscreen)
                {
                    style = Styles.Fullscreen;
                }
                window = new RenderWindow(videoMode, ApplicationInfo.Title, style);
                window.Clear(new Color(64, 64, 64));
                window.Display();

                if (args.deh.Present)
                {
                    DeHackEd.ReadFiles(args.deh.Value);
                }

                // resource = new CommonResource(GetWadPaths(args));
                resource = new CommonResource(new string[] { wadUrl });

                renderer = new SfmlRenderer(config, window, resource);

                if (!args.nosound.Present && !args.nosfx.Present)
                {
                    sound = new SfmlSound(config, resource.Wad);
                }

                if (!args.nosound.Present && !args.nomusic.Present)
                {
                    music = ConfigUtilities.GetSfmlMusicInstance(config, resource.Wad);
                }

                userInput = new SfmlUserInput(config, window, !args.nomouse.Present);



                options             = new GameOptions();
                options.GameVersion = resource.Wad.GameVersion;
                options.GameMode    = resource.Wad.GameMode;
                options.MissionPack = resource.Wad.MissionPack;
                options.Renderer    = renderer;
                options.Sound       = sound;
                options.Music       = music;
                options.UserInput   = userInput;

                menu = new DoomMenu(this);

                opening = new OpeningSequence(resource, options);

                cmds = new TicCmd[Player.MaxPlayerCount];
                for (var i = 0; i < Player.MaxPlayerCount; i++)
                {
                    cmds[i] = new TicCmd();
                }
                game = new DoomGame(resource, options);

                wipe   = new WipeEffect(renderer.WipeBandCount, renderer.WipeHeight);
                wiping = false;

                currentState = ApplicationState.None;
                nextState    = ApplicationState.Opening;
                needWipe     = false;

                sendPause = false;

                quit        = false;
                quitMessage = null;

                CheckGameArgs(args);
            }
            catch (Exception e)
            {
                Dispose();
                ExceptionDispatchInfo.Throw(e);
            }
        }