Example #1
0
            public void Save(DoomGame game, string path)
            {
                var options = game.World.Options;

                data[ptr++] = (byte)options.Skill;
                data[ptr++] = (byte)options.Episode;
                data[ptr++] = (byte)options.Map;
                for (var i = 0; i < Player.MaxPlayerCount; i++)
                {
                    data[ptr++] = options.Players[i].InGame ? (byte)1 : (byte)0;
                }

                data[ptr++] = (byte)(game.World.LevelTime >> 16);
                data[ptr++] = (byte)(game.World.LevelTime >> 8);
                data[ptr++] = (byte)(game.World.LevelTime);

                ArchivePlayers(game.World);
                ArchiveWorld(game.World);
                ArchiveThinkers(game.World);
                ArchiveSpecials(game.World);

                data[ptr++] = 0x1d;

                using (var writer = new FileStream(path, FileMode.Create, FileAccess.Write))
                {
                    writer.Write(data, 0, ptr);
                }
            }
Example #2
0
            public void Load(DoomGame game)
            {
                var options = game.World.Options;

                options.Skill   = (GameSkill)data[ptr++];
                options.Episode = data[ptr++];
                options.Map     = data[ptr++];
                for (var i = 0; i < Player.MaxPlayerCount; i++)
                {
                    options.Players[i].InGame = data[ptr++] != 0;
                }

                game.InitNew(options.Skill, options.Episode, options.Map);

                var a         = data[ptr++];
                var b         = data[ptr++];
                var c         = data[ptr++];
                var levelTime = (a << 16) + (b << 8) + c;

                UnArchivePlayers(game.World);
                UnArchiveWorld(game.World);
                UnArchiveThinkers(game.World);
                UnArchiveSpecials(game.World);

                if (data[ptr] != 0x1d)
                {
                    throw new Exception("Bad savegame!");
                }

                game.World.LevelTime = levelTime;

                options.Sound.SetListener(game.World.ConsolePlayer.Mobj);
            }
Example #3
0
        public static void Load(DoomGame game, string path)
        {
            var options = game.Options;

            game.InitNew(options.Skill, options.Episode, options.Map);

            var lg = new LoadGame(File.ReadAllBytes(path));

            lg.Load(game);
        }
Example #4
0
        //private Demo demo;

        public DoomApplication()
        {
            try
            {
                var style = Styles.Close | Styles.Titlebar;
                window = new RenderWindow(new VideoMode(640, 400), "Managed Doom", style);
                window.Clear(new Color(128, 128, 128));
                window.Display();

                resource = new CommonResource("DOOM2.WAD");
                renderer = new SfmlRenderer(window, resource, true);
                audio    = new SfmlAudio(resource.Wad);

                menu = new DoomMenu(this);

                state = ApplicationState.Opening;

                opening = new OpeningSequence();

                players = new Player[Player.MaxPlayerCount];
                cmds    = new TicCmd[Player.MaxPlayerCount];
                for (var i = 0; i < Player.MaxPlayerCount; i++)
                {
                    players[i] = new Player(i);
                    cmds[i]    = new TicCmd();
                }
                players[0].InGame = true;

                options          = new GameOptions();
                options.Skill    = GameSkill.Hard;
                options.GameMode = resource.Wad.GameMode;
                options.Episode  = 1;
                options.Map      = 1;

                //demo = new Demo("test.lmp");
                //options = demo.Options;

                game       = new DoomGame(players, resource, options);
                game.Audio = audio;

                events = new List <DoomEvent>();

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

                window.KeyPressed  += KeyPressed;
                window.KeyReleased += KeyReleased;

                window.SetFramerateLimit(35);
            }
            catch (Exception e)
            {
                ExceptionDispatchInfo.Capture(e).Throw();
            }
        }
Example #5
0
        public void Reset()
        {
            currentStage = 0;
            nextStage    = 0;

            demo = null;
            game = null;

            reset = true;

            StartTitleScreen();
        }
Example #6
0
        private void StartDemo(string lump)
        {
            state = OpeningSequenceState.Demo;

            demo = new Demo(resource.Wad.ReadLump(lump));
            demo.Options.GameVersion = options.GameVersion;
            demo.Options.GameMode    = options.GameMode;
            demo.Options.MissionPack = options.MissionPack;
            demo.Options.Renderer    = options.Renderer;
            demo.Options.Sound       = options.Sound;
            demo.Options.Music       = options.Music;

            game = new DoomGame(resource, demo.Options);
            game.DeferedInitNew();
        }
Example #7
0
        public DemoPlayback(CommonResource resource, GameOptions options, string demoName)
        {
            if (File.Exists(demoName))
            {
                demo = new Demo(demoName);
            }
            else if (File.Exists(demoName + ".lmp"))
            {
                demo = new Demo(demoName + ".lmp");
            }
            else
            {
                var lumpName = demoName.ToUpper();
                if (resource.Wad.GetLumpNumber(lumpName) == -1)
                {
                    throw new Exception("Demo '" + demoName + "' was not found!");
                }
                demo = new Demo(resource.Wad.ReadLump(lumpName));
            }

            demo.Options.GameVersion = options.GameVersion;
            demo.Options.GameMode    = options.GameMode;
            demo.Options.MissionPack = options.MissionPack;
            demo.Options.Renderer    = options.Renderer;
            demo.Options.Sound       = options.Sound;
            demo.Options.Music       = options.Music;

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

            game = new DoomGame(resource, demo.Options);
            game.DeferedInitNew();

            stopwatch = new Stopwatch();
        }
Example #8
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);
            }
        }
Example #10
0
        public World(CommonResource resorces, GameOptions options, DoomGame game)
        {
            this.options = options;
            this.game    = game;

            if (game != null)
            {
                random = game.Random;
            }
            else
            {
                random = new DoomRandom();
            }

            map = new Map(resorces, this);

            thinkers         = new Thinkers(this);
            specials         = new Specials(this);
            thingAllocation  = new ThingAllocation(this);
            thingMovement    = new ThingMovement(this);
            thingInteraction = new ThingInteraction(this);
            mapCollision     = new MapCollision(this);
            mapInteraction   = new MapInteraction(this);
            pathTraversal    = new PathTraversal(this);
            hitscan          = new Hitscan(this);
            visibilityCheck  = new VisibilityCheck(this);
            sectorAction     = new SectorAction(this);
            playerBehavior   = new PlayerBehavior(this);
            itemPickup       = new ItemPickup(this);
            weaponBehavior   = new WeaponBehavior(this);
            monsterBehavior  = new MonsterBehavior(this);
            lightingChange   = new LightingChange(this);
            statusBar        = new StatusBar(this);
            autoMap          = new AutoMap(this);
            cheat            = new Cheat(this);

            options.IntermissionInfo.TotalFrags = 0;
            options.IntermissionInfo.ParTime    = 180;

            for (var i = 0; i < Player.MaxPlayerCount; i++)
            {
                options.Players[i].KillCount   = 0;
                options.Players[i].SecretCount = 0;
                options.Players[i].ItemCount   = 0;
            }

            // Initial height of view will be set by player think.
            options.Players[options.ConsolePlayer].ViewZ = Fixed.Epsilon;

            totalKills   = 0;
            totalItems   = 0;
            totalSecrets = 0;

            LoadThings();

            // If deathmatch, randomly spawn the active players.
            if (options.Deathmatch != 0)
            {
                for (var i = 0; i < Player.MaxPlayerCount; i++)
                {
                    if (options.Players[i].InGame)
                    {
                        options.Players[i].Mobj = null;
                        thingAllocation.DeathMatchSpawnPlayer(i);
                    }
                }
            }

            specials.SpawnSpecials();

            levelTime    = 0;
            doneFirstTic = false;
            secretExit   = false;
            completed    = false;

            validCount = 0;

            displayPlayer = options.ConsolePlayer;

            dummy = new Mobj(this);

            options.Music.StartMusic(Map.GetMapBgm(options), true);
        }
Example #11
0
        public static void Save(DoomGame game, string description, string path)
        {
            var sg = new SaveGame(description);

            sg.Save(game, path);
        }
Example #12
0
        public Doom(CommandLineArgs args, Config config, GameContent content, IVideo video, ISound sound, IMusic music, IUserInput userInput)
        {
            video     = video ?? NullVideo.GetInstance();
            sound     = sound ?? NullSound.GetInstance();
            music     = music ?? NullMusic.GetInstance();
            userInput = userInput ?? NullUserInput.GetInstance();

            this.args      = args;
            this.config    = config;
            this.content   = content;
            this.video     = video;
            this.sound     = sound;
            this.music     = music;
            this.userInput = userInput;

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

            if (!args.nodeh.Present)
            {
                DeHackEd.ReadDeHackEdLump(content.Wad);
            }

            events = new List <DoomEvent>();

            options             = new GameOptions();
            options.GameVersion = content.Wad.GameVersion;
            options.GameMode    = content.Wad.GameMode;
            options.MissionPack = content.Wad.MissionPack;
            options.Video       = video;
            options.Sound       = sound;
            options.Music       = music;
            options.UserInput   = userInput;

            menu = new DoomMenu(this);

            opening = new OpeningSequence(content, options);

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

            wipeEffect = new WipeEffect(video.WipeBandCount, video.WipeHeight);
            wiping     = false;

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

            sendPause = false;

            quit        = false;
            quitMessage = null;

            mouseGrabbed = false;

            CheckGameArgs();
        }