Ejemplo n.º 1
0
    static void Main(string[] args)
    {
#if DEBUG
        chdir("../../../");
#endif

        Window window = new Window();
        window.Create("application-02", (int)DisplayWidth, (int)DisplayHeight);

        GraphicsDevice.Instance.Create(window, FullScreen);

        SoundDevice.Instance.Create(window.Handle);

        if (ShowDebugInfo)
        {
            runner  = CommandRunner.Execute();
            monitor = GameSystemMonitor.Execute();
        }

        foreach (var file in Directory.GetFiles("res/mission/", "*.cs"))
        {
            var asm = ScriptCompiler.CompileAssemblyFromFile(new ScriptCompilerParameters()
            {
                BaseClassName      = "Script",
                BatchScriptStyle   = false,
                ClassName          = "Mission",
                GenerateExecutable = false,
                GenerateInMemory   = true,
                PythonScopeStyle   = false,
            }, file);
            Missions.MissionAssemblies.Add(Path.GetFileNameWithoutExtension(file), asm);
        }

        window.Updated += () =>
        {
            update();

            GraphicsDevice.Instance.Clear(ColorCode.Black);
#if true
            LoadingTask loadingTask = SceneManager.TryTransitScene();

            if (loadingTask.Finished)
            {
                Entity.BroadcastMessage(UpdateMessage);

                Entity.BroadcastMessage(RenderMessage);
                Entity.BroadcastMessage(TranslucentRenderMessage);
                Entity.BroadcastMessage(DrawMessage);
            }
            else
            {
                LoadingView.Draw(loadingTask);
            }
#endif
            GraphicsDevice.Instance.Present();

            if (pressed(KeyCode.Escape))
            {
                window.Close();
            }

            Entity.Update();
        };

        try
        {
            initialize();

            //SceneManager.FookScene(new MainScene());
            SceneManager.FookScene(new TitleScene());
            //SceneManager.FookScene(new MissionSelectScene());

            window.Start();
        }
        finally
        {
            Entity.Clear();

            ResourceManager.CleanUp();

            GC.Collect();

            finalize();

            GraphicsDevice.Instance.Dispose();
            SoundDevice.Instance.Dispose();

            if (ShowDebugInfo)
            {
                GameSystemMonitor.Shutdown(monitor);
                CommandRunner.Shutdown(runner);
            }
        }
    }
Ejemplo n.º 2
0
    static void Main(string[] args)
    {
        chdir("../../../");

        Window window = new Window();

        window.Create("application-03", (int)DisplayWidth, (int)DisplayHeight);

        GraphicsDevice.Instance.Create(window, FullScreen);
        SoundDevice.Instance.Create(window.Handle);

#if DEBUG
        var runner  = CommandRunner.Execute();
        var monitor = GameSystemMonitor.Execute();
#endif

        foreach (var file in Directory.GetFiles("res/mission/", "*.cs"))
        {
            var assembly = ScriptCompiler.CompileAssemblyFromFile(new ScriptCompilerParameters()
            {
                BaseClassName      = "GameScript",
                BatchScriptStyle   = false,
                ClassName          = "Mission",
                GenerateExecutable = false,
                GenerateInMemory   = true,
                PythonScopeStyle   = false,
            }, file);
            Missions.MissionAssemblies.Add(Path.GetFileNameWithoutExtension(file), assembly);
        }

        SceneManager.SetNextScene(new TitleScene());

        window.Updated += () =>
        {
            EngineScript.update();
            GameScript.update();

            GraphicsDeviceContext.Instance.Clear(ColorCode.Black);
            if (SceneManager.Running)
            {
                DrawLoadingStatus(SceneManager.Scene);
            }
            else
            {
                if (SceneManager.Scene != null)
                {
                    if (!SceneManager.Running)
                    {
                        SceneManager.NextScene();
                    }
                }
                else
                {
                    Entity.BroadcastMessage(UpdateMessage);
                    Entity.BroadcastMessage(RenderMessage);
                    Entity.BroadcastMessage(TranslucentRenderMessage);
                    Entity.BroadcastMessage(DrawMessage);
                }
            }
            GraphicsDeviceContext.Instance.Present();

            if (pressed(KeyCode.Escape))
            {
                window.Close();
            }

            Entity.Update();
        };

        try
        {
            EngineScript.initialize();
            GameScript.initialize();

            window.Start();
        }
        finally
        {
#if DEBUG
            GameSystemMonitor.Shutdown(monitor);
            CommandRunner.Shutdown(runner);
#endif

            Entity.Clear();

            ResourceManager.CleanUp();

            EngineScript.finalize();
            GameScript.finalize();

            GraphicsDeviceContext.Instance.Dispose();
            GraphicsDevice.Instance.Dispose();
            SoundDevice.Instance.Dispose();
        }
    }