Beispiel #1
0
        static void Main(string[] args)
        {
            SetProcessDPIAware();
            //Thread.Sleep(2000);

            Files.Initialize("basegame");

            // TODO: Load from arguments passed or somethin'
            //Files.SetGameFolder("testgame");
            Files.SetGameFolder("Blochs");

            AppDomain.CurrentDomain.AssemblyResolve += (S, E) => {
                string DllName = E.Name.Split(',')[0] + ".dll";

                string DllPath = Files.GetFilePath(DllName);
                if (!string.IsNullOrEmpty(DllPath))
                {
                    return(Assembly.LoadFile(DllPath));
                }

                return(null);
            };

            Console.IsOpen         = false;
            Engine.DedicatedServer = false;
            Engine.DrawFPSCounter  = true;
            Engine.TimeSinceLaunch = Stopwatch.StartNew();
            Engine.Running         = true;

            UpdateRate = TimeSpan.FromSeconds(1.0 / 60);
            RenderRate = TimeSpan.FromSeconds(1.0 / 120);

            Engine.Server = ModuleLoader.LoadModule(Engine.GameFolder, "Server");
            Engine.Server?.Open();

            // Update loop
            UpdateThread = new Thread(() => {
                Clock UpdateClk = new Clock();

                while (Engine.Running)
                {
                    UpdateClk.AtLeast(UpdateRate, (Dt) => Update(Dt));
                }
            });

            if (Engine.DedicatedServer)
            {
                UpdateThread.Start();
            }

            // Render loop
            if (!Engine.DedicatedServer)
            {
                ShaderProgram.OnProgramError += (Program, ErrorMsg) => {
                    Console.WriteLine(Console.DarkYellow + "Shader program error: \n{0}", ErrorMsg);
                };

                RenderWindow.InitRenderer();
                SpawnWindow();

                NanoVG.Initialize();
                Engine.RenderWindow.SetWindowSize(-1, -1);

                Engine.Camera            = new Camera();
                Engine.Camera.Projection = Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 2, Engine.RenderWindow.AspectRatio, 0.1f, 6000.0f);
                Engine.Camera.SetPosition(new Vector3(0, 0, -100));
                Camera.Push(Engine.Camera);

                ModuleBase Client = ModuleLoader.LoadModule(Engine.GameFolder, "Client");
                Client?.Open();
                Engine.Client = Client;

                ModuleBase UI = ModuleLoader.LoadModule(Engine.GameFolder, "UI");
                UI?.Open();
                Engine.UI = UI;

                Engine.RenderWindow.OnUpdate       += Update;
                Engine.RenderWindow.OnRenderClient += Render;
                Engine.RenderWindow.OnRenderUI     += RenderUI;
                Engine.RenderWindow.Run(60);
                Engine.Running = false;
            }
            else
            {
                // TODO: Spawn console
            }

            while (Engine.Running)
            {
                Thread.Sleep(10);
            }

            ModuleLoader.UnloadModule(Engine.Server);
            ModuleLoader.UnloadModule(Engine.Client);
            ModuleLoader.UnloadModule(Engine.UI);
            Environment.Exit(0);
        }