Пример #1
0
        }                    // Disable parameterless constructor

        public static Model LoadModel(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path", "Path must not be null");
            }

            var mdl = new Model();

            Scene scene;
            var   lmp = LumpManager.GetLumpFullPath(path);

            using (Stream stream = lmp.AsStream) {
                using (AssimpContext context = new AssimpContext()) {
                    LumpIOSystem ioSys = new LumpIOSystem();
                    context.SetIOSystem(ioSys);
                    scene = context.ImportFileFromStream(stream, PostProcessSteps.Triangulate | PostProcessSteps.FlipUVs);

                    if (scene == null || scene.SceneFlags.HasFlag(SceneFlags.Incomplete) || scene.RootNode == null)
                    {
                        throw new Core.FatalError(String.Format("Error loading model \"{0}\"", path));
                    }
                }
            }
            mdl.directory = Path.GetDirectoryName(path);

            mdl.meshes = new List <MeshData> (scene.MeshCount);
            mdl.ProcessNode(scene.RootNode, scene);

            return(mdl);
        }
Пример #2
0
        private static void InitPatches()
        {
            // Don't need to try running the loop if the list is null or there aren't any files in it.
            if (options.PatchFiles == null || options.PatchFiles.Count < 1)
            {
                return;
            }

            for (int i = 0; i < options.PatchFiles.Count; i++)
            {
                ILumpContainer container = null;
                string         file      = options.PatchFiles [i];

                if (File.Exists(file))
                {
                    if (ZipLumpContainer.CheckContainer(file))
                    {
                        container = new ZipLumpContainer(file);
                    }
                }

                if (container != null)
                {
                    GConsole.WriteLine(" Adding \"{0}\", {1} lumps", file, container.Count);
                    LumpManager.AddContainer(container);
                }
                else
                {
                    throw new FatalError(string.Format("Could not identify patch {0}. Stopping execution.", file));
                }
            }
        }
Пример #3
0
        private void OpenRead(String pathToFile, FileIOMode fileMode)
        {
            String fileName = Path.GetFileName(pathToFile);

            if (LumpManager.LumpExistsFullPath(pathToFile))
            {
                lmp    = LumpManager.GetLumpFullPath(pathToFile);
                stream = lmp.AsStream;
            }
        }
Пример #4
0
        public static void Run(string [] args)
        {
            long   ticDelta = 0, renderDelta = 0;
            double fpsTime;

            if (closing)
            {
                return;
            }

            if (!CommandLine.Parser.Default.ParseArguments(args, options))
            {
                GConsole.WriteLine("Fatal error: There was an error reading the argument list");
                Console.Read();
                return;
            }

            try {
                /*Data.UDMF.UDMFParser udmfParser = new Data.UDMF.UDMFParser ();
                 * udmfParser.Setup ();
                 *
                 * using (var reader = new StreamReader ("TEXTMAP.txt"))
                 *  udmfParser.Parse (reader);
                 *
                 * Console.ReadKey ();
                 * return;*/

                GConsole.WriteLine("Core: Loading engine.PK3");
                ZipLumpContainer container  = null;
                string           engPK3File = Path.GetFullPath(Path.Combine(Constants.ProgDir, @"engine.pk3"));

                if (File.Exists(engPK3File))
                {
                    if (ZipLumpContainer.CheckContainer(engPK3File))
                    {
                        container = new ZipLumpContainer(engPK3File);
                    }
                }

                if (container == null)
                {
                    throw new FatalError(String.Format("Could not load engine.PK3. Stopping execution."));
                }

                GConsole.WriteLine(" engine.PK3, {0} lumps", container.Count);
                LumpManager.AddContainer(container);

                GConsole.WriteLine("Core: Initializing patches");
                InitPatches();

                GConsole.WriteLine("Core: Generating fixed-point Sin/Cos/Atan LUTs");
                FixedMath.GenerateTables();

                GConsole.WriteLine("Core: Initializing video");
                RenderEngine = OpenTkRenderer.Default;
                RenderEngine.Initialize(800, 600, false);
                RenderEngine.OnFocusChange += Renderer_OnFocusChange;

                GConsole.WriteLine("Core: Initializing playsim");
                Ticker = new Ticker();
                Ticker.Initialize();

                GConsole.WriteLine("Core: Starting game loop");
                ticClock.Reset();
                ticClock.Start();
                renderClock.Reset();
                renderClock.Start();

                while (true)
                {
                    if (closing)
                    {
                        return;
                    }

                    if (ticClock.ElapsedMilliseconds >= Constants.MsecsPerTic)
                    {
                        ticDelta = ticClock.ElapsedMilliseconds;
                        ticClock.Restart();
                        Ticker.Update(ticDelta);
                        Input.ClearTotals();
                    }
                    Input.UpdateInput();

                    renderDelta = renderClock.ElapsedMilliseconds;
                    renderClock.Restart();

                    fpsClock.Restart();
                    RenderEngine.Render(renderDelta);
                    fpsTime = fpsClock.ElapsedMilliseconds;

                    if (RenderEngine.IsUsable())
                    {
                        RenderEngine.WindowTitle = String.Format("Frame time: {0} ms", fpsTime);
                    }
                }
            } catch (FatalError err) {
                DisposeResources();
                GConsole.WriteLine(err.Message);
                Console.ReadKey();
            } catch (VeryFatalError err) {
                DisposeResources();
                GConsole.WriteLine(err.Message);
                Console.ReadKey();
            }
        }