Ejemplo n.º 1
0
        static void RunGame()
        {
            InitConsole();

            FileWatcher.Init("content");
            Importers.RegisterAll(Reflect.GetExeAssembly());

            Engine.GUI = new libGUI();

            Engine.Window              = new RenderWindow(Engine.WindowWidth, Engine.WindowHeight, "libTech", Engine.WindowResizable);
            Engine.Window.OnMouseMove += Engine.GUI.OnMouseMove;
            Engine.Window.OnKey       += OnKey;
            Engine.Window.OnChar      += Engine.GUI.OnChar;

            Engine.GUI.Init(Engine.Window, new ShaderProgram(new ShaderStage(ShaderType.VertexShader, "content/shaders/gui.vert"), new ShaderStage(ShaderType.FragmentShader, "content/shaders/gui.frag")));

            GConsole.Init();
            GConsole.WriteLine("Running {0}", RenderAPI.Renderer, RenderAPI.Version);

            GConsole.Color = FishGfx.Color.Orange;
            foreach (var DllName in FailedToLoadDLLs)
            {
                GConsole.WriteLine("Failed to load '{0}'", DllName);
            }
            GConsole.Color = FishGfx.Color.White;

            // Graphics init
            Gfx.ShadersDirectory = "content/shaders";
            //Gfx.Line3D = DefaultShaders.Line3D;
            //Gfx.Point3D = DefaultShaders.Point3D;
            //Gfx.Default3D = DefaultShaders.DefaultColor3D;

            // Camera init
            Engine.Camera2D = new Camera();
            Engine.Camera2D.SetOrthogonal(0, 0, Engine.Window.WindowWidth, Engine.Window.WindowHeight);

            Engine.Camera3D = new Camera();
            Engine.Camera3D.SetPerspective(Engine.Window.WindowWidth, Engine.Window.WindowHeight);

            LoadGameDll(Engine.GamePath);

            float Dt = 0;

            while (!Engine.Window.ShouldClose)
            {
                Update(Dt);
                Draw(Dt);
                Thread.Sleep(0);
            }
        }
Ejemplo n.º 2
0
        static void RunGame()
        {
            TimeStopwatch = Stopwatch.StartNew();
            InitConsole();

            Engine.VFS = new VirtualFileSystem(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
            Engine.VFS.Mount("/content/", "./content");
            Engine.VFS.Mount("/materials/", "C:/Program Files (x86)/Steam/steamapps/common/GarrysMod/garrysmod/addons/quake_3_gmod_160207505/materials");

            string[] SourceGameDirs = Engine.SourceGameDirs.Value.Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries).Where(Pth => Directory.Exists(Pth)).ToArray();

            if (SourceGameDirs.Length > 0)
            {
                foreach (var GameDir in SourceGameDirs)
                {
                    Engine.VFS.GetSourceProvider().AddRoot(GameDir);
                }
            }

            if (Directory.Exists(Path.Combine(Engine.GamePath, "content")))
            {
                Engine.VFS.Mount("/content/", Path.Combine(Engine.GamePath, "content"));
            }

            List <string> ZipResources = new List <string>();

            ZipResources.AddRange(Engine.VFS.GetFiles("/content/").Where(P => Path.GetExtension(P) == ".pk3" || Path.GetExtension(P) == ".zip"));

            foreach (var ZipResource in ZipResources)
            {
                Engine.VFS.MountArchive("/content/", ZipResource);
            }

            FileWatcher.Init("content");
            Importers.RegisterAll(Reflect.GetExeAssembly());

            Engine.GUI = new NuklearGUI();

            Engine.Window              = new RenderWindow(Engine.WindowWidth, Engine.WindowHeight, "libTech", Engine.WindowResizable);
            Engine.Window.OnMouseMove += Engine.GUI.OnMouseMove;
            Engine.Window.OnKey       += OnKey;
            Engine.Window.OnChar      += Engine.GUI.OnChar;

            RenderDoc.Init();

            GConsole.Init();
            GConsole.WriteLine("Running {0}", RenderAPI.Renderer, RenderAPI.Version);

            string ExtensionsFile = "extensions.txt";

            if (File.Exists(ExtensionsFile))
            {
                File.Delete(ExtensionsFile);
            }

            File.WriteAllLines(ExtensionsFile, RenderAPI.Extensions);
            EngineRenderer.Init();

            Engine.GUI.Init(Engine.Window, new ShaderProgram(new ShaderStage(ShaderType.VertexShader, "content/shaders/gui.vert"), new ShaderStage(ShaderType.FragmentShader, "content/shaders/gui.frag")));
            Engine.UI = new libGUI(Engine.Window);

            DbgDraw.Init();
            Lua.Init();

            GConsole.Color = Color.Orange;
            foreach (var DllName in FailedToLoadDLLs)
            {
                GConsole.WriteLine("Failed to load '{0}'", DllName);
            }
            GConsole.Color = Color.White;

            // Graphics init
            Gfx.ShadersDirectory = "content/shaders";
            //Gfx.Line3D = DefaultShaders.Line3D;
            //Gfx.Point3D = DefaultShaders.Point3D;
            //Gfx.Default3D = DefaultShaders.DefaultColor3D;

            // Camera init
            Engine.Camera2D = new Camera();
            Engine.Camera2D.SetOrthogonal(0, 0, Engine.Window.WindowWidth, Engine.Window.WindowHeight);

            Engine.Camera3D = new Camera();
            Engine.Camera3D.SetPerspective(Engine.Window.WindowWidth, Engine.Window.WindowHeight, FarPlane: 16000);

            LoadGameDll(Engine.GamePath);

            Stopwatch SWatch = Stopwatch.StartNew();

            int MaxFPS = Engine.MaxFPS;

            if (MaxFPS <= 0)
            {
                MaxFPS = 900;
            }

            float FrameCap = 1.0f / MaxFPS;
            float Dt       = 1.0f / 60.0f;

            while (!Engine.Window.ShouldClose)
            {
                Engine.FrameTime.Push(Dt);

                Update(Dt);
                EngineRenderer.Draw(Dt);

                // TODO: Move frame cap somewhere else
                while ((SWatch.ElapsedMilliseconds / 1000.0f) < FrameCap)
                {
                    Thread.Sleep(0);
                }

                Dt = SWatch.ElapsedMilliseconds / 1000.0f;
                SWatch.Restart();
            }
        }